@prover-coder-ai/docker-git 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.jscpd.json +16 -0
- package/.package.json.release.bak +109 -0
- package/CHANGELOG.md +31 -0
- package/README.md +173 -0
- package/biome.json +34 -0
- package/dist/main.js +847 -0
- package/dist/main.js.map +1 -0
- package/dist/src/app/main.js +15 -0
- package/dist/src/app/program.js +61 -0
- package/dist/src/docker-git/cli/input.js +21 -0
- package/dist/src/docker-git/cli/parser-attach.js +19 -0
- package/dist/src/docker-git/cli/parser-auth.js +70 -0
- package/dist/src/docker-git/cli/parser-clone.js +40 -0
- package/dist/src/docker-git/cli/parser-create.js +1 -0
- package/dist/src/docker-git/cli/parser-options.js +101 -0
- package/dist/src/docker-git/cli/parser-panes.js +19 -0
- package/dist/src/docker-git/cli/parser-sessions.js +69 -0
- package/dist/src/docker-git/cli/parser-shared.js +26 -0
- package/dist/src/docker-git/cli/parser-state.js +62 -0
- package/dist/src/docker-git/cli/parser.js +42 -0
- package/dist/src/docker-git/cli/read-command.js +17 -0
- package/dist/src/docker-git/cli/usage.js +99 -0
- package/dist/src/docker-git/main.js +15 -0
- package/dist/src/docker-git/menu-actions.js +115 -0
- package/dist/src/docker-git/menu-create.js +203 -0
- package/dist/src/docker-git/menu-input.js +2 -0
- package/dist/src/docker-git/menu-menu.js +46 -0
- package/dist/src/docker-git/menu-render.js +151 -0
- package/dist/src/docker-git/menu-select.js +131 -0
- package/dist/src/docker-git/menu-shared.js +111 -0
- package/dist/src/docker-git/menu-types.js +19 -0
- package/dist/src/docker-git/menu.js +237 -0
- package/dist/src/docker-git/program.js +38 -0
- package/dist/src/docker-git/tmux.js +176 -0
- package/eslint.config.mts +305 -0
- package/eslint.effect-ts-check.config.mjs +220 -0
- package/linter.config.json +33 -0
- package/package.json +63 -0
- package/src/app/main.ts +18 -0
- package/src/app/program.ts +75 -0
- package/src/docker-git/cli/input.ts +29 -0
- package/src/docker-git/cli/parser-attach.ts +22 -0
- package/src/docker-git/cli/parser-auth.ts +124 -0
- package/src/docker-git/cli/parser-clone.ts +55 -0
- package/src/docker-git/cli/parser-create.ts +3 -0
- package/src/docker-git/cli/parser-options.ts +152 -0
- package/src/docker-git/cli/parser-panes.ts +22 -0
- package/src/docker-git/cli/parser-sessions.ts +101 -0
- package/src/docker-git/cli/parser-shared.ts +51 -0
- package/src/docker-git/cli/parser-state.ts +86 -0
- package/src/docker-git/cli/parser.ts +73 -0
- package/src/docker-git/cli/read-command.ts +26 -0
- package/src/docker-git/cli/usage.ts +112 -0
- package/src/docker-git/main.ts +18 -0
- package/src/docker-git/menu-actions.ts +246 -0
- package/src/docker-git/menu-create.ts +320 -0
- package/src/docker-git/menu-input.ts +2 -0
- package/src/docker-git/menu-menu.ts +58 -0
- package/src/docker-git/menu-render.ts +327 -0
- package/src/docker-git/menu-select.ts +250 -0
- package/src/docker-git/menu-shared.ts +141 -0
- package/src/docker-git/menu-types.ts +94 -0
- package/src/docker-git/menu.ts +339 -0
- package/src/docker-git/program.ts +134 -0
- package/src/docker-git/tmux.ts +292 -0
- package/tests/app/main.test.ts +60 -0
- package/tests/docker-git/entrypoint-auth.test.ts +29 -0
- package/tests/docker-git/parser.test.ts +172 -0
- package/tsconfig.build.json +8 -0
- package/tsconfig.json +20 -0
- package/vite.config.ts +32 -0
- package/vitest.config.ts +85 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Either, Match } from "effect"
|
|
2
|
+
|
|
3
|
+
import type { Command, ParseError } from "@effect-template/lib/core/domain"
|
|
4
|
+
|
|
5
|
+
import { parseRawOptions } from "./parser-options.js"
|
|
6
|
+
|
|
7
|
+
const invalidStateAction = (value: string): ParseError => ({
|
|
8
|
+
_tag: "InvalidOption",
|
|
9
|
+
option: "state",
|
|
10
|
+
reason: `unknown action: ${value}`
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
const unexpectedArgs = (value: string): Either.Either<Command, ParseError> =>
|
|
14
|
+
Either.left({ _tag: "UnexpectedArgument", value })
|
|
15
|
+
|
|
16
|
+
const parseStateInit = (args: ReadonlyArray<string>): Either.Either<Command, ParseError> =>
|
|
17
|
+
Either.flatMap(parseRawOptions(args), (raw) => {
|
|
18
|
+
const repoUrl = raw.repoUrl?.trim()
|
|
19
|
+
if (!repoUrl || repoUrl.length === 0) {
|
|
20
|
+
return Either.left({ _tag: "MissingRequiredOption", option: "--repo-url" })
|
|
21
|
+
}
|
|
22
|
+
return Either.right({
|
|
23
|
+
_tag: "StateInit",
|
|
24
|
+
repoUrl,
|
|
25
|
+
repoRef: raw.repoRef?.trim() && raw.repoRef.trim().length > 0 ? raw.repoRef.trim() : "main"
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
const parseStateCommit = (args: ReadonlyArray<string>): Either.Either<Command, ParseError> =>
|
|
30
|
+
Either.flatMap(parseRawOptions(args), (raw) => {
|
|
31
|
+
const message = raw.message?.trim()
|
|
32
|
+
if (!message || message.length === 0) {
|
|
33
|
+
return Either.left({ _tag: "MissingRequiredOption", option: "--message" })
|
|
34
|
+
}
|
|
35
|
+
return Either.right({ _tag: "StateCommit", message })
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
const parseStateSync = (args: ReadonlyArray<string>): Either.Either<Command, ParseError> =>
|
|
39
|
+
Either.map(parseRawOptions(args), (raw) => {
|
|
40
|
+
const message = raw.message?.trim()
|
|
41
|
+
return { _tag: "StateSync", message: message && message.length > 0 ? message : null }
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
export const parseState = (args: ReadonlyArray<string>): Either.Either<Command, ParseError> => {
|
|
45
|
+
const action = args[0]?.trim()
|
|
46
|
+
if (!action || action.length === 0) {
|
|
47
|
+
return Either.left({ _tag: "MissingRequiredOption", option: "state <action>" })
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const rest = args.slice(1)
|
|
51
|
+
|
|
52
|
+
return Match.value(action).pipe(
|
|
53
|
+
Match.when("path", () => {
|
|
54
|
+
if (rest.length > 0) {
|
|
55
|
+
return unexpectedArgs(rest[0] ?? "")
|
|
56
|
+
}
|
|
57
|
+
const command: Command = { _tag: "StatePath" }
|
|
58
|
+
return Either.right(command)
|
|
59
|
+
}),
|
|
60
|
+
Match.when("init", () => parseStateInit(rest)),
|
|
61
|
+
Match.when("pull", () => {
|
|
62
|
+
if (rest.length > 0) {
|
|
63
|
+
return unexpectedArgs(rest[0] ?? "")
|
|
64
|
+
}
|
|
65
|
+
const command: Command = { _tag: "StatePull" }
|
|
66
|
+
return Either.right(command)
|
|
67
|
+
}),
|
|
68
|
+
Match.when("push", () => {
|
|
69
|
+
if (rest.length > 0) {
|
|
70
|
+
return unexpectedArgs(rest[0] ?? "")
|
|
71
|
+
}
|
|
72
|
+
const command: Command = { _tag: "StatePush" }
|
|
73
|
+
return Either.right(command)
|
|
74
|
+
}),
|
|
75
|
+
Match.when("status", () => {
|
|
76
|
+
if (rest.length > 0) {
|
|
77
|
+
return unexpectedArgs(rest[0] ?? "")
|
|
78
|
+
}
|
|
79
|
+
const command: Command = { _tag: "StateStatus" }
|
|
80
|
+
return Either.right(command)
|
|
81
|
+
}),
|
|
82
|
+
Match.when("commit", () => parseStateCommit(rest)),
|
|
83
|
+
Match.when("sync", () => parseStateSync(rest)),
|
|
84
|
+
Match.orElse(() => Either.left(invalidStateAction(action)))
|
|
85
|
+
)
|
|
86
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Either, Match } from "effect"
|
|
2
|
+
|
|
3
|
+
import { type Command, type ParseError } from "@effect-template/lib/core/domain"
|
|
4
|
+
|
|
5
|
+
import { parseAttach } from "./parser-attach.js"
|
|
6
|
+
import { parseAuth } from "./parser-auth.js"
|
|
7
|
+
import { parseClone } from "./parser-clone.js"
|
|
8
|
+
import { buildCreateCommand } from "./parser-create.js"
|
|
9
|
+
import { parseRawOptions } from "./parser-options.js"
|
|
10
|
+
import { parsePanes } from "./parser-panes.js"
|
|
11
|
+
import { parseSessions } from "./parser-sessions.js"
|
|
12
|
+
import { parseState } from "./parser-state.js"
|
|
13
|
+
import { usageText } from "./usage.js"
|
|
14
|
+
|
|
15
|
+
const isHelpFlag = (token: string): boolean => token === "--help" || token === "-h"
|
|
16
|
+
|
|
17
|
+
const helpCommand: Command = { _tag: "Help", message: usageText }
|
|
18
|
+
const menuCommand: Command = { _tag: "Menu" }
|
|
19
|
+
const statusCommand: Command = { _tag: "Status" }
|
|
20
|
+
const downAllCommand: Command = { _tag: "DownAll" }
|
|
21
|
+
|
|
22
|
+
const parseCreate = (args: ReadonlyArray<string>): Either.Either<Command, ParseError> =>
|
|
23
|
+
Either.flatMap(parseRawOptions(args), buildCreateCommand)
|
|
24
|
+
|
|
25
|
+
// CHANGE: parse CLI arguments into a typed command
|
|
26
|
+
// WHY: enforce deterministic, pure parsing before any effects run
|
|
27
|
+
// QUOTE(ТЗ): "Надо написать CLI команду с помощью которой мы будем создавать докер образы"
|
|
28
|
+
// REF: user-request-2026-01-07
|
|
29
|
+
// SOURCE: n/a
|
|
30
|
+
// FORMAT THEOREM: forall argv: parse(argv) = cmd -> deterministic(cmd)
|
|
31
|
+
// PURITY: CORE
|
|
32
|
+
// EFFECT: Effect<Command, ParseError, never>
|
|
33
|
+
// INVARIANT: parse does not perform IO and returns the same result for same argv
|
|
34
|
+
// COMPLEXITY: O(n) where n = |argv|
|
|
35
|
+
export const parseArgs = (args: ReadonlyArray<string>): Either.Either<Command, ParseError> => {
|
|
36
|
+
if (args.length === 0) {
|
|
37
|
+
return Either.right(menuCommand)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (args.some((arg) => isHelpFlag(arg))) {
|
|
41
|
+
return Either.right(helpCommand)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const command = args[0]
|
|
45
|
+
const rest = args.slice(1)
|
|
46
|
+
const unknownCommandError: ParseError = {
|
|
47
|
+
_tag: "UnknownCommand",
|
|
48
|
+
command: command ?? ""
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return Match.value(command).pipe(
|
|
52
|
+
Match.when("create", () => parseCreate(rest)),
|
|
53
|
+
Match.when("init", () => parseCreate(rest)),
|
|
54
|
+
Match.when("clone", () => parseClone(rest)),
|
|
55
|
+
Match.when("attach", () => parseAttach(rest)),
|
|
56
|
+
Match.when("tmux", () => parseAttach(rest)),
|
|
57
|
+
Match.when("panes", () => parsePanes(rest)),
|
|
58
|
+
Match.when("terms", () => parsePanes(rest)),
|
|
59
|
+
Match.when("terminals", () => parsePanes(rest)),
|
|
60
|
+
Match.when("sessions", () => parseSessions(rest)),
|
|
61
|
+
Match.when("help", () => Either.right(helpCommand)),
|
|
62
|
+
Match.when("ps", () => Either.right(statusCommand)),
|
|
63
|
+
Match.when("status", () => Either.right(statusCommand)),
|
|
64
|
+
Match.when("down-all", () => Either.right(downAllCommand)),
|
|
65
|
+
Match.when("stop-all", () => Either.right(downAllCommand)),
|
|
66
|
+
Match.when("kill-all", () => Either.right(downAllCommand)),
|
|
67
|
+
Match.when("menu", () => Either.right(menuCommand)),
|
|
68
|
+
Match.when("ui", () => Either.right(menuCommand)),
|
|
69
|
+
Match.when("auth", () => parseAuth(rest)),
|
|
70
|
+
Match.when("state", () => parseState(rest)),
|
|
71
|
+
Match.orElse(() => Either.left(unknownCommandError))
|
|
72
|
+
)
|
|
73
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Effect, Either, pipe } from "effect"
|
|
2
|
+
|
|
3
|
+
import { type Command, type ParseError } from "@effect-template/lib/core/domain"
|
|
4
|
+
|
|
5
|
+
import { parseArgs } from "./parser.js"
|
|
6
|
+
|
|
7
|
+
// CHANGE: read and parse CLI arguments from process.argv
|
|
8
|
+
// WHY: keep IO at the boundary and delegate parsing to CORE
|
|
9
|
+
// QUOTE(ТЗ): "Надо написать CLI команду"
|
|
10
|
+
// REF: user-request-2026-01-07
|
|
11
|
+
// SOURCE: n/a
|
|
12
|
+
// FORMAT THEOREM: forall argv: read(argv) -> parse(argv)
|
|
13
|
+
// PURITY: SHELL
|
|
14
|
+
// EFFECT: Effect<Command, ParseError, never>
|
|
15
|
+
// INVARIANT: errors are typed as ParseError
|
|
16
|
+
// COMPLEXITY: O(n) where n = |argv|
|
|
17
|
+
export const readCommand: Effect.Effect<Command, ParseError> = pipe(
|
|
18
|
+
Effect.sync(() => process.argv.slice(2)),
|
|
19
|
+
Effect.map((args) => parseArgs(args)),
|
|
20
|
+
Effect.flatMap((result) =>
|
|
21
|
+
Either.match(result, {
|
|
22
|
+
onLeft: (error) => Effect.fail(error),
|
|
23
|
+
onRight: (command) => Effect.succeed(command)
|
|
24
|
+
})
|
|
25
|
+
)
|
|
26
|
+
)
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Match } from "effect"
|
|
2
|
+
|
|
3
|
+
import type { ParseError } from "@effect-template/lib/core/domain"
|
|
4
|
+
|
|
5
|
+
export const usageText = `docker-git menu
|
|
6
|
+
docker-git create --repo-url <url> [options]
|
|
7
|
+
docker-git clone <url> [options]
|
|
8
|
+
docker-git attach [<url>] [options]
|
|
9
|
+
docker-git panes [<url>] [options]
|
|
10
|
+
docker-git sessions [list] [<url>] [options]
|
|
11
|
+
docker-git sessions kill <pid> [<url>] [options]
|
|
12
|
+
docker-git sessions logs <pid> [<url>] [options]
|
|
13
|
+
docker-git ps
|
|
14
|
+
docker-git down-all
|
|
15
|
+
docker-git auth <provider> <action> [options]
|
|
16
|
+
docker-git state <action> [options]
|
|
17
|
+
|
|
18
|
+
Commands:
|
|
19
|
+
menu Interactive menu (default when no args)
|
|
20
|
+
create, init Generate docker development environment
|
|
21
|
+
clone Create + run container and clone repo
|
|
22
|
+
attach, tmux Open tmux workspace for a docker-git project
|
|
23
|
+
panes, terms List tmux panes for a docker-git project
|
|
24
|
+
sessions List/kill/log container terminal processes
|
|
25
|
+
ps, status Show docker compose status for all docker-git projects
|
|
26
|
+
down-all Stop all docker-git containers (docker compose down)
|
|
27
|
+
auth Manage GitHub/Codex auth for docker-git
|
|
28
|
+
state Manage docker-git state directory via git (sync across machines)
|
|
29
|
+
|
|
30
|
+
Options:
|
|
31
|
+
--repo-ref <ref> Git ref/branch (default: main)
|
|
32
|
+
--branch, -b <ref> Alias for --repo-ref
|
|
33
|
+
--target-dir <path> Target dir inside container (create default: /home/dev/app, clone default: /home/dev/<org>/<repo>[/issue-<id>|/pr-<id>])
|
|
34
|
+
--ssh-port <port> Local SSH port (default: 2222)
|
|
35
|
+
--ssh-user <user> SSH user inside container (default: dev)
|
|
36
|
+
--container-name <name> Docker container name (default: dg-<repo>)
|
|
37
|
+
--service-name <name> Compose service name (default: dg-<repo>)
|
|
38
|
+
--volume-name <name> Docker volume name (default: dg-<repo>-home)
|
|
39
|
+
--secrets-root <path> Host root for shared secrets (default: n/a)
|
|
40
|
+
--authorized-keys <path> Host path to authorized_keys (default: <projectsRoot>/authorized_keys)
|
|
41
|
+
--env-global <path> Host path to shared env file (default: <projectsRoot>/.orch/env/global.env)
|
|
42
|
+
--env-project <path> Host path to project env file (default: ./.orch/env/project.env)
|
|
43
|
+
--codex-auth <path> Host path for Codex auth cache (default: <projectsRoot>/.orch/auth/codex)
|
|
44
|
+
--codex-home <path> Container path for Codex auth (default: /home/dev/.codex)
|
|
45
|
+
--out-dir <path> Output directory (default: <projectsRoot>/<org>/<repo>[/issue-<id>|/pr-<id>])
|
|
46
|
+
--project-dir <path> Project directory for attach (default: .)
|
|
47
|
+
--lines <n> Tail last N lines for sessions logs (default: 200)
|
|
48
|
+
--include-default Show default/system processes in sessions list
|
|
49
|
+
--up | --no-up Run docker compose up after init (default: --up)
|
|
50
|
+
--mcp-playwright | --no-mcp-playwright Enable Playwright MCP + Chromium sidecar (default: --no-mcp-playwright)
|
|
51
|
+
--force Overwrite existing files and wipe compose volumes (docker compose down -v)
|
|
52
|
+
--force-env Reset project env defaults only (keep workspace volume/data)
|
|
53
|
+
-h, --help Show this help
|
|
54
|
+
|
|
55
|
+
Container runtime env (set via .orch/env/project.env):
|
|
56
|
+
CODEX_SHARE_AUTH=1|0 Share Codex auth.json across projects (default: 1)
|
|
57
|
+
CODEX_AUTO_UPDATE=1|0 Auto-update Codex CLI on container start (default: 1)
|
|
58
|
+
DOCKER_GIT_ZSH_AUTOSUGGEST=1|0 Enable zsh-autosuggestions (default: 1)
|
|
59
|
+
DOCKER_GIT_ZSH_AUTOSUGGEST_STYLE=... zsh-autosuggestions highlight style (default: fg=8,italic)
|
|
60
|
+
DOCKER_GIT_ZSH_AUTOSUGGEST_STRATEGY=... Suggestion sources (default: history completion)
|
|
61
|
+
MCP_PLAYWRIGHT_ISOLATED=1|0 Isolated browser contexts (recommended for many Codex; default: 1)
|
|
62
|
+
MCP_PLAYWRIGHT_CDP_ENDPOINT=http://... Override CDP endpoint (default: http://dg-<repo>-browser:9223)
|
|
63
|
+
|
|
64
|
+
Auth providers:
|
|
65
|
+
github, gh GitHub CLI auth (tokens saved to env file)
|
|
66
|
+
codex Codex CLI auth (stored under .orch/auth/codex)
|
|
67
|
+
|
|
68
|
+
Auth actions:
|
|
69
|
+
login Run login flow and store credentials
|
|
70
|
+
status Show current auth status
|
|
71
|
+
logout Remove stored credentials
|
|
72
|
+
|
|
73
|
+
Auth options:
|
|
74
|
+
--label <label> Account label (default: default)
|
|
75
|
+
--token <token> GitHub token override (login only)
|
|
76
|
+
--scopes <scopes> GitHub scopes (login only, default: repo,workflow,read:org)
|
|
77
|
+
--env-global <path> Env file path for GitHub tokens (default: <projectsRoot>/.orch/env/global.env)
|
|
78
|
+
--codex-auth <path> Codex auth root path (default: <projectsRoot>/.orch/auth/codex)
|
|
79
|
+
|
|
80
|
+
State actions:
|
|
81
|
+
state path Print current projects root (default: ~/.docker-git; override via DOCKER_GIT_PROJECTS_ROOT)
|
|
82
|
+
state init --repo-url <url> [-b] Init / bind state dir to a git remote (use a private repo)
|
|
83
|
+
state status Show git status for the state dir
|
|
84
|
+
state pull git pull (state dir)
|
|
85
|
+
state commit -m <message> Commit all changes in the state dir
|
|
86
|
+
state sync [-m <message>] Commit (if needed) + fetch/rebase + push (state dir); on conflict pushes a PR branch
|
|
87
|
+
state push git push (state dir)
|
|
88
|
+
|
|
89
|
+
State options:
|
|
90
|
+
--message, -m <message> Commit message for state commit
|
|
91
|
+
`
|
|
92
|
+
|
|
93
|
+
// CHANGE: normalize parse errors into user-facing messages
|
|
94
|
+
// WHY: keep formatting deterministic and centralized
|
|
95
|
+
// QUOTE(ТЗ): "Надо написать CLI команду"
|
|
96
|
+
// REF: user-request-2026-01-07
|
|
97
|
+
// SOURCE: n/a
|
|
98
|
+
// FORMAT THEOREM: forall e: format(e) = s -> deterministic(s)
|
|
99
|
+
// PURITY: CORE
|
|
100
|
+
// EFFECT: Effect<string, never, never>
|
|
101
|
+
// INVARIANT: each ParseError maps to exactly one message
|
|
102
|
+
// COMPLEXITY: O(1)
|
|
103
|
+
export const formatParseError = (error: ParseError): string =>
|
|
104
|
+
Match.value(error).pipe(
|
|
105
|
+
Match.when({ _tag: "UnknownCommand" }, ({ command }) => `Unknown command: ${command}`),
|
|
106
|
+
Match.when({ _tag: "UnknownOption" }, ({ option }) => `Unknown option: ${option}`),
|
|
107
|
+
Match.when({ _tag: "MissingOptionValue" }, ({ option }) => `Missing value for option: ${option}`),
|
|
108
|
+
Match.when({ _tag: "MissingRequiredOption" }, ({ option }) => `Missing required option: ${option}`),
|
|
109
|
+
Match.when({ _tag: "InvalidOption" }, ({ option, reason }) => `Invalid option ${option}: ${reason}`),
|
|
110
|
+
Match.when({ _tag: "UnexpectedArgument" }, ({ value }) => `Unexpected argument: ${value}`),
|
|
111
|
+
Match.exhaustive
|
|
112
|
+
)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { NodeContext, NodeRuntime } from "@effect/platform-node"
|
|
2
|
+
import { Effect } from "effect"
|
|
3
|
+
|
|
4
|
+
import { program } from "./program.js"
|
|
5
|
+
|
|
6
|
+
// CHANGE: run docker-git CLI through the Node runtime
|
|
7
|
+
// WHY: ensure platform services (FS, Path, Command) are available in app CLI
|
|
8
|
+
// QUOTE(ТЗ): "CLI (отображение, фронт) это app"
|
|
9
|
+
// REF: user-request-2026-01-28-cli-move
|
|
10
|
+
// SOURCE: n/a
|
|
11
|
+
// FORMAT THEOREM: forall env: runMain(program, env) -> exit
|
|
12
|
+
// PURITY: SHELL
|
|
13
|
+
// EFFECT: Effect<void, unknown, NodeContext>
|
|
14
|
+
// INVARIANT: program runs with NodeContext.layer
|
|
15
|
+
// COMPLEXITY: O(n)
|
|
16
|
+
const main = Effect.provide(program, NodeContext.layer)
|
|
17
|
+
|
|
18
|
+
NodeRuntime.runMain(main)
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { type MenuAction, type ProjectConfig } from "@effect-template/lib/core/domain"
|
|
2
|
+
import { readProjectConfig } from "@effect-template/lib/shell/config"
|
|
3
|
+
import { runDockerComposeDown, runDockerComposeLogs, runDockerComposePs } from "@effect-template/lib/shell/docker"
|
|
4
|
+
import type { AppError } from "@effect-template/lib/usecases/errors"
|
|
5
|
+
import { renderError } from "@effect-template/lib/usecases/errors"
|
|
6
|
+
import {
|
|
7
|
+
downAllDockerGitProjects,
|
|
8
|
+
listProjectItems,
|
|
9
|
+
listRunningProjectItems
|
|
10
|
+
} from "@effect-template/lib/usecases/projects"
|
|
11
|
+
import { runDockerComposeUpWithPortCheck } from "@effect-template/lib/usecases/projects-up"
|
|
12
|
+
import { Effect, Match, pipe } from "effect"
|
|
13
|
+
|
|
14
|
+
import { startCreateView } from "./menu-create.js"
|
|
15
|
+
import { loadSelectView } from "./menu-select.js"
|
|
16
|
+
import { resumeTui, suspendTui } from "./menu-shared.js"
|
|
17
|
+
import { type MenuEnv, type MenuRunner, type MenuState, type ViewState } from "./menu-types.js"
|
|
18
|
+
|
|
19
|
+
// CHANGE: keep menu actions and input parsing in a dedicated module
|
|
20
|
+
// WHY: reduce cognitive complexity in the TUI entry
|
|
21
|
+
// QUOTE(ТЗ): "TUI? Красивый, удобный"
|
|
22
|
+
// REF: user-request-2026-02-01-tui
|
|
23
|
+
// SOURCE: n/a
|
|
24
|
+
// FORMAT THEOREM: forall a: action(a) -> effect(a)
|
|
25
|
+
// PURITY: SHELL
|
|
26
|
+
// EFFECT: Effect<void, AppError, MenuEnv>
|
|
27
|
+
// INVARIANT: menu selection runs exactly one action
|
|
28
|
+
// COMPLEXITY: O(1) per keypress
|
|
29
|
+
|
|
30
|
+
const continueOutcome = (state: MenuState): { readonly _tag: "Continue"; readonly state: MenuState } => ({
|
|
31
|
+
_tag: "Continue",
|
|
32
|
+
state
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
const quitOutcome: { readonly _tag: "Quit" } = { _tag: "Quit" }
|
|
36
|
+
|
|
37
|
+
export type MenuContext = {
|
|
38
|
+
readonly state: MenuState
|
|
39
|
+
readonly runner: MenuRunner
|
|
40
|
+
readonly exit: () => void
|
|
41
|
+
readonly setView: (view: ViewState) => void
|
|
42
|
+
readonly setMessage: (message: string | null) => void
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type MenuSelectionContext = MenuContext & {
|
|
46
|
+
readonly selected: number
|
|
47
|
+
readonly setSelected: (update: (value: number) => number) => void
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const actionLabel = (action: MenuAction): string =>
|
|
51
|
+
Match.value(action).pipe(
|
|
52
|
+
Match.when({ _tag: "Up" }, () => "docker compose up"),
|
|
53
|
+
Match.when({ _tag: "Status" }, () => "docker compose ps"),
|
|
54
|
+
Match.when({ _tag: "Logs" }, () => "docker compose logs"),
|
|
55
|
+
Match.when({ _tag: "Down" }, () => "docker compose down"),
|
|
56
|
+
Match.when({ _tag: "DownAll" }, () => "docker compose down (all projects)"),
|
|
57
|
+
Match.orElse(() => "action")
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
const runWithSuspendedTui = (
|
|
61
|
+
effect: Effect.Effect<void, AppError, MenuEnv>,
|
|
62
|
+
context: MenuContext,
|
|
63
|
+
label: string
|
|
64
|
+
) => {
|
|
65
|
+
context.runner.runEffect(
|
|
66
|
+
pipe(
|
|
67
|
+
Effect.sync(() => {
|
|
68
|
+
context.setMessage(`${label}...`)
|
|
69
|
+
suspendTui()
|
|
70
|
+
}),
|
|
71
|
+
Effect.zipRight(effect),
|
|
72
|
+
Effect.tap(() =>
|
|
73
|
+
Effect.sync(() => {
|
|
74
|
+
context.setMessage(`${label} finished.`)
|
|
75
|
+
})
|
|
76
|
+
),
|
|
77
|
+
Effect.ensuring(
|
|
78
|
+
Effect.sync(() => {
|
|
79
|
+
resumeTui()
|
|
80
|
+
})
|
|
81
|
+
),
|
|
82
|
+
Effect.asVoid
|
|
83
|
+
)
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const requireActiveProject = (context: MenuContext): boolean => {
|
|
88
|
+
if (context.state.activeDir) {
|
|
89
|
+
return true
|
|
90
|
+
}
|
|
91
|
+
context.setMessage(
|
|
92
|
+
"No active project. Use Create or paste a repo URL to set one before running this action."
|
|
93
|
+
)
|
|
94
|
+
return false
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const handleMissingConfig = (
|
|
98
|
+
state: MenuState,
|
|
99
|
+
setMessage: (message: string | null) => void,
|
|
100
|
+
error: AppError
|
|
101
|
+
) =>
|
|
102
|
+
pipe(
|
|
103
|
+
Effect.sync(() => {
|
|
104
|
+
setMessage(renderError(error))
|
|
105
|
+
}),
|
|
106
|
+
Effect.as(continueOutcome(state))
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
const withProjectConfig = <R>(
|
|
110
|
+
state: MenuState,
|
|
111
|
+
setMessage: (message: string | null) => void,
|
|
112
|
+
f: (config: ProjectConfig) => Effect.Effect<void, AppError, R>
|
|
113
|
+
) =>
|
|
114
|
+
pipe(
|
|
115
|
+
readProjectConfig(state.activeDir ?? state.cwd),
|
|
116
|
+
Effect.matchEffect({
|
|
117
|
+
onFailure: (error) =>
|
|
118
|
+
error._tag === "ConfigNotFoundError" || error._tag === "ConfigDecodeError"
|
|
119
|
+
? handleMissingConfig(state, setMessage, error)
|
|
120
|
+
: Effect.fail(error),
|
|
121
|
+
onSuccess: (config) =>
|
|
122
|
+
pipe(
|
|
123
|
+
f(config),
|
|
124
|
+
Effect.as(continueOutcome(state))
|
|
125
|
+
)
|
|
126
|
+
})
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
const handleMenuAction = (
|
|
130
|
+
state: MenuState,
|
|
131
|
+
setMessage: (message: string | null) => void,
|
|
132
|
+
action: MenuAction
|
|
133
|
+
): Effect.Effect<
|
|
134
|
+
{ readonly _tag: "Continue"; readonly state: MenuState } | { readonly _tag: "Quit" },
|
|
135
|
+
AppError,
|
|
136
|
+
MenuEnv
|
|
137
|
+
> =>
|
|
138
|
+
Match.value(action).pipe(
|
|
139
|
+
Match.when({ _tag: "Quit" }, () => Effect.succeed(quitOutcome)),
|
|
140
|
+
Match.when({ _tag: "Create" }, () => Effect.succeed(continueOutcome(state))),
|
|
141
|
+
Match.when({ _tag: "Select" }, () => Effect.succeed(continueOutcome(state))),
|
|
142
|
+
Match.when({ _tag: "Info" }, () => Effect.succeed(continueOutcome(state))),
|
|
143
|
+
Match.when({ _tag: "Delete" }, () => Effect.succeed(continueOutcome(state))),
|
|
144
|
+
Match.when({ _tag: "Up" }, () =>
|
|
145
|
+
withProjectConfig(state, setMessage, () =>
|
|
146
|
+
runDockerComposeUpWithPortCheck(state.activeDir ?? state.cwd).pipe(Effect.asVoid))),
|
|
147
|
+
Match.when({ _tag: "Status" }, () =>
|
|
148
|
+
withProjectConfig(state, setMessage, () =>
|
|
149
|
+
runDockerComposePs(state.activeDir ?? state.cwd))),
|
|
150
|
+
Match.when({ _tag: "Logs" }, () =>
|
|
151
|
+
withProjectConfig(state, setMessage, () =>
|
|
152
|
+
runDockerComposeLogs(state.activeDir ?? state.cwd))),
|
|
153
|
+
Match.when({ _tag: "Down" }, () =>
|
|
154
|
+
withProjectConfig(state, setMessage, () =>
|
|
155
|
+
runDockerComposeDown(state.activeDir ?? state.cwd))),
|
|
156
|
+
Match.when({ _tag: "DownAll" }, () =>
|
|
157
|
+
pipe(
|
|
158
|
+
downAllDockerGitProjects,
|
|
159
|
+
Effect.as(continueOutcome(state))
|
|
160
|
+
)),
|
|
161
|
+
Match.exhaustive
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
const runCreateAction = (context: MenuContext) => {
|
|
165
|
+
startCreateView(context.setView, context.setMessage)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const runSelectAction = (context: MenuContext) => {
|
|
169
|
+
context.setMessage(null)
|
|
170
|
+
context.runner.runEffect(loadSelectView(listProjectItems, "Connect", context))
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const runDownAllAction = (context: MenuContext) => {
|
|
174
|
+
context.setMessage(null)
|
|
175
|
+
runWithSuspendedTui(downAllDockerGitProjects, context, "Stopping all docker-git containers")
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const runDownAction = (context: MenuContext, action: MenuAction) => {
|
|
179
|
+
context.setMessage(null)
|
|
180
|
+
if (context.state.activeDir === null) {
|
|
181
|
+
context.runner.runEffect(loadSelectView(listRunningProjectItems, "Down", context))
|
|
182
|
+
return
|
|
183
|
+
}
|
|
184
|
+
runComposeAction(action, context)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const runInfoAction = (context: MenuContext) => {
|
|
188
|
+
context.setMessage(null)
|
|
189
|
+
context.runner.runEffect(loadSelectView(listProjectItems, "Info", context))
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const runDeleteAction = (context: MenuContext) => {
|
|
193
|
+
context.setMessage(null)
|
|
194
|
+
context.runner.runEffect(loadSelectView(listProjectItems, "Delete", context))
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const runComposeAction = (action: MenuAction, context: MenuContext) => {
|
|
198
|
+
if (!requireActiveProject(context)) {
|
|
199
|
+
return
|
|
200
|
+
}
|
|
201
|
+
const effect = pipe(handleMenuAction(context.state, context.setMessage, action), Effect.asVoid)
|
|
202
|
+
runWithSuspendedTui(effect, context, actionLabel(action))
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const runQuitAction = (context: MenuContext, action: MenuAction) => {
|
|
206
|
+
context.runner.runEffect(
|
|
207
|
+
pipe(handleMenuAction(context.state, context.setMessage, action), Effect.asVoid)
|
|
208
|
+
)
|
|
209
|
+
context.exit()
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export const handleMenuActionSelection = (action: MenuAction, context: MenuContext) => {
|
|
213
|
+
Match.value(action).pipe(
|
|
214
|
+
Match.when({ _tag: "Create" }, () => {
|
|
215
|
+
runCreateAction(context)
|
|
216
|
+
}),
|
|
217
|
+
Match.when({ _tag: "Select" }, () => {
|
|
218
|
+
runSelectAction(context)
|
|
219
|
+
}),
|
|
220
|
+
Match.when({ _tag: "Info" }, () => {
|
|
221
|
+
runInfoAction(context)
|
|
222
|
+
}),
|
|
223
|
+
Match.when({ _tag: "Delete" }, () => {
|
|
224
|
+
runDeleteAction(context)
|
|
225
|
+
}),
|
|
226
|
+
Match.when({ _tag: "Up" }, (selected) => {
|
|
227
|
+
runComposeAction(selected, context)
|
|
228
|
+
}),
|
|
229
|
+
Match.when({ _tag: "Status" }, (selected) => {
|
|
230
|
+
runComposeAction(selected, context)
|
|
231
|
+
}),
|
|
232
|
+
Match.when({ _tag: "Logs" }, (selected) => {
|
|
233
|
+
runComposeAction(selected, context)
|
|
234
|
+
}),
|
|
235
|
+
Match.when({ _tag: "Down" }, (selected) => {
|
|
236
|
+
runDownAction(context, selected)
|
|
237
|
+
}),
|
|
238
|
+
Match.when({ _tag: "DownAll" }, () => {
|
|
239
|
+
runDownAllAction(context)
|
|
240
|
+
}),
|
|
241
|
+
Match.when({ _tag: "Quit" }, (selected) => {
|
|
242
|
+
runQuitAction(context, selected)
|
|
243
|
+
}),
|
|
244
|
+
Match.exhaustive
|
|
245
|
+
)
|
|
246
|
+
}
|