@tdk-landscape/tdk-cli-core 1.3.105 → 1.3.107
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/CHANGELOG.md +1 -0
- package/cli/dist/cli.js +4 -0
- package/cli/dist/commands/completion.js +17 -1
- package/cli/dist/commands/doctor.js +2 -1
- package/cli/dist/commands/logs.js +85 -0
- package/cli/dist/commands/mcp.js +24 -0
- package/cli/dist/commands/projects.js +37 -6
- package/cli/dist/commands/resources.js +3 -2
- package/cli/dist/commands/stacks.js +30 -3
- package/cli/dist/commands/status.js +18 -0
- package/cli/dist/commands/ui.js +14 -21
- package/cli/dist/commands/up.js +102 -34
- package/cli/dist/mcp/server.js +100 -0
- package/cli/dist/mcp/tools.js +273 -0
- package/cli/dist/utils/discovery-context.js +9 -3
- package/cli/dist/utils/doctor-wiring.js +88 -0
- package/cli/dist/utils/services.js +65 -7
- package/cli/dist/utils/status-message.js +22 -0
- package/cli/dist/utils/tilt-logs.js +62 -0
- package/cli/dist/utils/tilt-startup.js +35 -0
- package/cli/dist/utils/up-only.js +29 -0
- package/cli/dist/utils/up-readiness.js +82 -15
- package/cli/package.json +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,7 @@ Notable changes to the `tdk` CLI. Versions match [npm](https://www.npmjs.com/pac
|
|
|
4
4
|
|
|
5
5
|
## Unreleased
|
|
6
6
|
|
|
7
|
+
- `tdk doctor` warns when a backend or worker applies database migrations from its own start-up (a `start`/`dev` script, a Dockerfile `CMD`/`ENTRYPOINT`, a shell entrypoint or its source: Prisma, Drizzle, Knex, TypeORM, MikroORM, Sequelize, dbmate, Atlas, Alembic). It is a warning, not a failure: such services work, but migrations belong in a `migrator` resource that runs once before the services that depend on it. `migrator` and bring-your-own resources are not checked.
|
|
7
8
|
- Go services can opt in to a live development loop with `"dev": { "liveReload": true }` in `service.json`: edits are copied into the running container and recompiled without an image rebuild, while `go.mod`, `go.sum` and the generated Dockerfile still rebuild the image. The watcher compiles into a staging binary while the old build keeps serving and swaps only on success, so a compile error shows in the Tilt log and the last good build keeps answering (Air, tried first, stopped the app before compiling and left it down for the whole compile; in 2 of 6 edits a Traefik health check then returned 503 for 10 s). Measured on one loaded Mac: median edit-to-ready 1.63 s for the scaffold. The default Go image (`golang:1.23`) now sets `GOTOOLCHAIN=auto`, so a `go.mod` that needs a newer Go, such as Gin 1.12 (`go 1.25`), downloads that toolchain instead of stopping with `requires go >= 1.25`. Offline or air-gapped builds of a go.mod newer than 1.23 still fail, but now at the toolchain download rather than at the version check. `scripts/e2e/go-dev-loop.sh` checks all of this through a real `tdk up`. Refs #369.
|
|
8
9
|
- `tdk up` keeps each smoke step's status and response body under `.tdk/smoke/<service>/<step>/` (`latest.json` and `body.txt`, body capped at 64 KiB), plus `last-success.json` and `last-success-body.txt` that a later failure never overwrites, so a regression can be diffed against the last good response. The failure line ends with the record path, and `tdk project` gitignores `.tdk/smoke/`. A new `smoke-e2e` workflow runs `scripts/verify-smoke.sh` and uploads the records. Before its first step a smoke check now waits for the service's health path (`healthCheckPath`, default `/health` for backends) with GETs until it answers something other than a connection error, 404 or 5xx, so a write is no longer the first request to hit a service that is still building; write retry rules are unchanged.
|
|
9
10
|
- Add an opt-in Python backend: `tdk resource <name> --type backend --language python` scaffolds a FastAPI service (`pyproject.toml`, `src/main.py`, a pytest smoke test) and TDK generates its Docker image (`python:3.12-slim`, with `test` and `production` stages). The choice is saved as `language` in `service.json` only when you pass the flag; omitting it keeps the existing Bun + Hono output byte for byte. Unknown ids and `--language` on non-backend types fail before any file is written. A runnable example is in `examples/one-backend-python`, and the provider contract is in `docs/backend-language-providers.md`. Node.js is not included.
|
package/cli/dist/cli.js
CHANGED
|
@@ -9,7 +9,9 @@ import { downCommand } from "./commands/down.js";
|
|
|
9
9
|
import { ejectCommand } from "./commands/eject.js";
|
|
10
10
|
import { showHelp } from "./commands/help.js";
|
|
11
11
|
import { importCommand } from "./commands/import.js";
|
|
12
|
+
import { logsCommand } from "./commands/logs.js";
|
|
12
13
|
import { maintainersCommand } from "./commands/maintainers.js";
|
|
14
|
+
import { mcpCommand } from "./commands/mcp.js";
|
|
13
15
|
import { networksCommand } from "./commands/networks.js";
|
|
14
16
|
import { projectCommand } from "./commands/project.js";
|
|
15
17
|
import { projectsCommand } from "./commands/projects.js";
|
|
@@ -46,6 +48,8 @@ program.addCommand(resourcesCommand);
|
|
|
46
48
|
program.addCommand(projectsCommand);
|
|
47
49
|
program.addCommand(upCommand);
|
|
48
50
|
program.addCommand(downCommand);
|
|
51
|
+
program.addCommand(mcpCommand);
|
|
52
|
+
program.addCommand(logsCommand);
|
|
49
53
|
program.addCommand(ejectCommand);
|
|
50
54
|
program.addCommand(importCommand);
|
|
51
55
|
program.addCommand(statusCommand);
|
|
@@ -11,7 +11,7 @@ _tdk_completions() {
|
|
|
11
11
|
prev="\${COMP_WORDS[COMP_CWORD-1]}"
|
|
12
12
|
|
|
13
13
|
# Main commands
|
|
14
|
-
local commands="project projects stack stacks resource resources up down status ui doctor runtime version completion help upgrade"
|
|
14
|
+
local commands="project projects stack stacks resource resources up down status ui doctor runtime version completion help upgrade mcp logs eject import config maintainers networks traefik"
|
|
15
15
|
|
|
16
16
|
# Options for specific commands
|
|
17
17
|
case "\${prev}" in
|
|
@@ -142,6 +142,14 @@ _tdk_commands() {
|
|
|
142
142
|
'version:Show version'
|
|
143
143
|
'upgrade:Upgrade TDK CLI'
|
|
144
144
|
'completion:Generate shell completions'
|
|
145
|
+
'mcp:Run a Model Context Protocol server over stdio for coding agents'
|
|
146
|
+
'logs:Print a bounded snapshot of recent logs from the running stack'
|
|
147
|
+
'eject:Take ownership of the generated Tilt and Docker files'
|
|
148
|
+
'import:Import the services a directory describes (runs tdk-import)'
|
|
149
|
+
'config:Manage project configuration and regenerate master files'
|
|
150
|
+
'maintainers:Maintainer file checks'
|
|
151
|
+
'networks:Show Traefik-routed URLs for all services'
|
|
152
|
+
'traefik:Show Traefik-routed URLs for all services'
|
|
145
153
|
'help:Show help'
|
|
146
154
|
)
|
|
147
155
|
_describe -t commands 'tdk command' commands
|
|
@@ -187,6 +195,14 @@ complete -c tdk -n '__fish_use_subcommand' -a 'runtime' -d 'Inspect packaged run
|
|
|
187
195
|
complete -c tdk -n '__fish_use_subcommand' -a 'version' -d 'Show version'
|
|
188
196
|
complete -c tdk -n '__fish_use_subcommand' -a 'upgrade' -d 'Upgrade TDK CLI'
|
|
189
197
|
complete -c tdk -n '__fish_use_subcommand' -a 'completion' -d 'Generate shell completions'
|
|
198
|
+
complete -c tdk -n '__fish_use_subcommand' -a 'mcp' -d 'Run a Model Context Protocol server over stdio for coding agents'
|
|
199
|
+
complete -c tdk -n '__fish_use_subcommand' -a 'logs' -d 'Print a bounded snapshot of recent logs from the running stack'
|
|
200
|
+
complete -c tdk -n '__fish_use_subcommand' -a 'eject' -d 'Take ownership of the generated Tilt and Docker files'
|
|
201
|
+
complete -c tdk -n '__fish_use_subcommand' -a 'import' -d 'Import the services a directory describes (runs tdk-import)'
|
|
202
|
+
complete -c tdk -n '__fish_use_subcommand' -a 'config' -d 'Manage project configuration and regenerate master files'
|
|
203
|
+
complete -c tdk -n '__fish_use_subcommand' -a 'maintainers' -d 'Maintainer file checks'
|
|
204
|
+
complete -c tdk -n '__fish_use_subcommand' -a 'networks' -d 'Show Traefik-routed URLs for all services'
|
|
205
|
+
complete -c tdk -n '__fish_use_subcommand' -a 'traefik' -d 'Show Traefik-routed URLs for all services'
|
|
190
206
|
complete -c tdk -n '__fish_use_subcommand' -a 'help' -d 'Show help'
|
|
191
207
|
|
|
192
208
|
# Global options
|
|
@@ -9,7 +9,7 @@ import { MASTER_CONFIG_FILES, REQUIRED_PACKAGE_SCRIPTS } from "../utils/constant
|
|
|
9
9
|
import { isPathDiscovered, readDiscoveryPaths } from "../utils/discovery-paths.js";
|
|
10
10
|
import { collectDoctorChecks, createDoctorReport, getDoctorExitCode, } from "../utils/doctor-report.js";
|
|
11
11
|
import { checkHealthRoutes, checkIngressPorts, checkPrivateNpmRegistry, checkTiltResourceHealth, projectConfigEnablesVerdaccio, summarizeServiceProbes, } from "../utils/doctor-runtime.js";
|
|
12
|
-
import { checkDockerNetworkCapacity, checkFrontendBackendUrls, checkNatsBroker, checkResourcePackageJson, checkServiceUrlPorts, checkTiltInstances, } from "../utils/doctor-wiring.js";
|
|
12
|
+
import { checkDockerNetworkCapacity, checkFrontendBackendUrls, checkMigrationsInApi, checkNatsBroker, checkResourcePackageJson, checkServiceUrlPorts, checkTiltInstances, } from "../utils/doctor-wiring.js";
|
|
13
13
|
import { validateEnvFile } from "../utils/env-validator.js";
|
|
14
14
|
import { execAsync, isExecTimeout } from "../utils/exec-async.js";
|
|
15
15
|
import { formatCount } from "../utils/formatting.js";
|
|
@@ -1106,6 +1106,7 @@ export const doctorCommand = new Command("doctor")
|
|
|
1106
1106
|
() => checkServiceUrlPorts(),
|
|
1107
1107
|
() => checkFrontendBackendUrls(),
|
|
1108
1108
|
() => checkNatsBroker(),
|
|
1109
|
+
() => checkMigrationsInApi(),
|
|
1109
1110
|
() => checkTiltInstances(),
|
|
1110
1111
|
checkEnvironmentVariables,
|
|
1111
1112
|
// Preflight: Verdaccio down causes ImageBuild bun install ConnectionRefused.
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { STANDARD_PORTS } from "../utils/constants.js";
|
|
3
|
+
import { runCommand, showErrorAndExit } from "../utils/errors.js";
|
|
4
|
+
import { createMachineEnvelope } from "../utils/machine-output.js";
|
|
5
|
+
import { isTiltAvailable, runTilt } from "../utils/tilt.js";
|
|
6
|
+
import { DEFAULT_LOG_TAIL, isTiltConnectionFailure, isValidPort, isValidSince, isValidTail, MAX_LOG_TAIL, parseTiltLogLines, } from "../utils/tilt-logs.js";
|
|
7
|
+
/** Resource names Tilt knows about, or null when they cannot be listed (the logs call then reports the real error). */
|
|
8
|
+
async function tiltResourceNames(port) {
|
|
9
|
+
try {
|
|
10
|
+
const result = await runTilt("get", ["uiresources", "-o", "json", "--port", port], {
|
|
11
|
+
inheritStdio: false,
|
|
12
|
+
});
|
|
13
|
+
if (result.exitCode !== 0)
|
|
14
|
+
return null;
|
|
15
|
+
const items = JSON.parse(result.stdout)
|
|
16
|
+
.items;
|
|
17
|
+
return (items ?? []).flatMap((item) => (item.metadata?.name ? [item.metadata.name] : []));
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export const logsCommand = new Command("logs")
|
|
24
|
+
.description("Print a bounded snapshot of recent logs from the running stack")
|
|
25
|
+
.option("-s, --service <names...>", "Only these services (Tilt resource names)")
|
|
26
|
+
.option("--tail <n>", "Number of most recent lines to return", String(DEFAULT_LOG_TAIL))
|
|
27
|
+
.option("--since <duration>", "Only logs newer than this duration, for example 30s, 5m, 1h")
|
|
28
|
+
.option("--port <n>", "Tilt UI port (default: TILT_PORT or 10350)")
|
|
29
|
+
.option("--json", "Output one JSON object and exit", false)
|
|
30
|
+
.action(async (options) => {
|
|
31
|
+
const fail = (code, message, exitCode = 1) => {
|
|
32
|
+
if (options.json) {
|
|
33
|
+
console.log(JSON.stringify(createMachineEnvelope(null, [{ code, message }])));
|
|
34
|
+
console.error(message);
|
|
35
|
+
process.exit(exitCode);
|
|
36
|
+
}
|
|
37
|
+
return showErrorAndExit(message, exitCode);
|
|
38
|
+
};
|
|
39
|
+
if (!isValidTail(options.tail))
|
|
40
|
+
fail("USAGE", `--tail must be an integer from 1 to ${MAX_LOG_TAIL}`, 2);
|
|
41
|
+
if (options.since !== undefined && !isValidSince(options.since)) {
|
|
42
|
+
fail("USAGE", "--since must be a duration such as 30s, 5m or 1h", 2);
|
|
43
|
+
}
|
|
44
|
+
const portText = options.port ?? process.env.TILT_PORT ?? String(STANDARD_PORTS.tiltUi);
|
|
45
|
+
if (!isValidPort(portText))
|
|
46
|
+
fail("USAGE", "--port must be a valid port number", 2);
|
|
47
|
+
const tail = Number(options.tail);
|
|
48
|
+
const services = options.service ?? [];
|
|
49
|
+
const action = async () => {
|
|
50
|
+
if (!(await isTiltAvailable())) {
|
|
51
|
+
fail("TILT_MISSING", "Tilt is not installed. Run: tdk doctor");
|
|
52
|
+
}
|
|
53
|
+
if (services.length > 0) {
|
|
54
|
+
const known = await tiltResourceNames(portText);
|
|
55
|
+
const unknown = services.filter((name) => known && !known.includes(name));
|
|
56
|
+
if (unknown.length > 0) {
|
|
57
|
+
fail("UNKNOWN_SERVICE", `Unknown service ${unknown.join(", ")}. Valid names: ${(known ?? []).join(", ")}`, 2);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const args = ["--port", portText, "--tail", String(tail)];
|
|
61
|
+
if (options.since !== undefined)
|
|
62
|
+
args.push("--since", options.since);
|
|
63
|
+
if (options.json)
|
|
64
|
+
args.push("--json");
|
|
65
|
+
// `--` so a service name that starts with "-" is never read as a Tilt flag.
|
|
66
|
+
if (services.length > 0)
|
|
67
|
+
args.push("--", ...services);
|
|
68
|
+
const result = await runTilt("logs", args, { inheritStdio: false });
|
|
69
|
+
if (result.exitCode !== 0) {
|
|
70
|
+
const detail = result.stderr.trim();
|
|
71
|
+
if (!detail || isTiltConnectionFailure(detail)) {
|
|
72
|
+
fail("TILT_NOT_RUNNING", `Could not reach Tilt on port ${portText}: ${detail || "is the stack running? Start it with: tdk up"}`);
|
|
73
|
+
}
|
|
74
|
+
fail("TILT_LOGS_FAILED", `tilt logs failed: ${detail}`);
|
|
75
|
+
}
|
|
76
|
+
if (!options.json) {
|
|
77
|
+
process.stdout.write(result.stdout);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const lines = parseTiltLogLines(result.stdout, tail);
|
|
81
|
+
console.log(JSON.stringify(createMachineEnvelope({ services, tail, since: options.since ?? null, lines })));
|
|
82
|
+
};
|
|
83
|
+
await runCommand(action);
|
|
84
|
+
});
|
|
85
|
+
//# sourceMappingURL=logs.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createInterface } from "node:readline";
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import { createMcpServer } from "../mcp/server.js";
|
|
4
|
+
import { createTdkTools } from "../mcp/tools.js";
|
|
5
|
+
import { getPackageVersion } from "../utils/paths.js";
|
|
6
|
+
export const mcpCommand = new Command("mcp")
|
|
7
|
+
.description("Run a Model Context Protocol server over stdio for coding agents")
|
|
8
|
+
.action(async () => {
|
|
9
|
+
const server = createMcpServer(createTdkTools(), { name: "tdk", version: getPackageVersion() });
|
|
10
|
+
// Stdout is the protocol channel. Nothing else may write to it; diagnostics go to stderr.
|
|
11
|
+
const lines = createInterface({ input: process.stdin });
|
|
12
|
+
const pending = new Set();
|
|
13
|
+
lines.on("line", (line) => {
|
|
14
|
+
const task = server.handleLine(line).then((response) => {
|
|
15
|
+
if (response)
|
|
16
|
+
process.stdout.write(`${response}\n`);
|
|
17
|
+
});
|
|
18
|
+
pending.add(task);
|
|
19
|
+
void task.finally(() => pending.delete(task));
|
|
20
|
+
});
|
|
21
|
+
await new Promise((resolve) => lines.once("close", resolve));
|
|
22
|
+
await Promise.allSettled(pending);
|
|
23
|
+
});
|
|
24
|
+
//# sourceMappingURL=mcp.js.map
|
|
@@ -4,21 +4,42 @@ import chalk from "chalk";
|
|
|
4
4
|
import { Command } from "commander";
|
|
5
5
|
import { MASTER_CONFIG_FILES } from "../utils/constants.js";
|
|
6
6
|
import { createDiscoveryContext } from "../utils/discovery-context.js";
|
|
7
|
-
import { requireProjectRoot, runCommand } from "../utils/errors.js";
|
|
7
|
+
import { errorFactories, requireProjectRoot, runCommand } from "../utils/errors.js";
|
|
8
8
|
import { formatCount } from "../utils/formatting.js";
|
|
9
|
+
import { createMachineEnvelope, writeMachineError } from "../utils/machine-output.js";
|
|
10
|
+
import { findProjectRoot } from "../utils/paths.js";
|
|
9
11
|
export const projectsCommand = new Command("projects")
|
|
10
12
|
.description("Show project information and configuration status")
|
|
11
13
|
.alias("info")
|
|
12
14
|
.option("--check", "Check if project is properly configured", false)
|
|
15
|
+
.option("--json", "Output a versioned JSON response")
|
|
13
16
|
.action(async (options) => {
|
|
14
|
-
|
|
15
|
-
const projectRoot = requireProjectRoot();
|
|
17
|
+
const action = async () => {
|
|
18
|
+
const projectRoot = options.json ? findProjectRoot() : requireProjectRoot();
|
|
19
|
+
if (!projectRoot) {
|
|
20
|
+
throw errorFactories.notInProject();
|
|
21
|
+
}
|
|
22
|
+
const outDir = join(projectRoot, ".tdk", ".tdk-out");
|
|
23
|
+
const missing = MASTER_CONFIG_FILES.filter((file) => !existsSync(join(outDir, file)));
|
|
24
|
+
if (options.json) {
|
|
25
|
+
const discovery = createDiscoveryContext();
|
|
26
|
+
console.log(JSON.stringify(createMachineEnvelope({
|
|
27
|
+
projectRoot,
|
|
28
|
+
configured: missing.length === 0,
|
|
29
|
+
missingFiles: missing,
|
|
30
|
+
resources: discovery.resources.length,
|
|
31
|
+
stacks: discovery.stackNames,
|
|
32
|
+
unassignedResources: discovery.unassignedResources.length,
|
|
33
|
+
}), null, 2));
|
|
34
|
+
if (options.check) {
|
|
35
|
+
process.exitCode = missing.length === 0 ? 0 : 1;
|
|
36
|
+
}
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
16
39
|
console.log(chalk.blue("Project Information\n"));
|
|
17
40
|
console.log(chalk.bold("Project Root:"));
|
|
18
41
|
console.log(chalk.gray(` ${projectRoot}`));
|
|
19
42
|
console.log();
|
|
20
|
-
const outDir = join(projectRoot, ".tdk", ".tdk-out");
|
|
21
|
-
const missing = MASTER_CONFIG_FILES.filter((file) => !existsSync(join(outDir, file)));
|
|
22
43
|
console.log(chalk.bold("Master Configuration:"));
|
|
23
44
|
if (missing.length === 0) {
|
|
24
45
|
for (const file of MASTER_CONFIG_FILES) {
|
|
@@ -66,6 +87,16 @@ export const projectsCommand = new Command("projects")
|
|
|
66
87
|
if (options.check) {
|
|
67
88
|
process.exit(missing.length === 0 ? 0 : 1);
|
|
68
89
|
}
|
|
69
|
-
}
|
|
90
|
+
};
|
|
91
|
+
if (options.json) {
|
|
92
|
+
try {
|
|
93
|
+
await action();
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
writeMachineError(error);
|
|
97
|
+
}
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
await runCommand(action);
|
|
70
101
|
});
|
|
71
102
|
//# sourceMappingURL=projects.js.map
|
|
@@ -23,6 +23,7 @@ export const resourcesCommand = new Command("resources")
|
|
|
23
23
|
requireProjectRoot();
|
|
24
24
|
}
|
|
25
25
|
const discovery = createDiscoveryContext();
|
|
26
|
+
const withoutStackFilter = options.noStack || options.stack === false;
|
|
26
27
|
let resources = discovery.resources;
|
|
27
28
|
if (options.stack) {
|
|
28
29
|
resources = discovery.resourcesByStack.get(options.stack) || [];
|
|
@@ -31,7 +32,7 @@ export const resourcesCommand = new Command("resources")
|
|
|
31
32
|
return;
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
|
-
if (
|
|
35
|
+
if (withoutStackFilter) {
|
|
35
36
|
resources = discovery.unassignedResources;
|
|
36
37
|
if (resources.length === 0 && !options.json) {
|
|
37
38
|
showAllSatisfyCondition("resources", "assigned to a stack");
|
|
@@ -85,7 +86,7 @@ export const resourcesCommand = new Command("resources")
|
|
|
85
86
|
const withoutStackCount = options.stack
|
|
86
87
|
? resources.filter((r) => !r.stack).length
|
|
87
88
|
: discovery.unassignedResources.length;
|
|
88
|
-
if (withoutStackCount > 0 && !
|
|
89
|
+
if (withoutStackCount > 0 && !withoutStackFilter && !options.stack) {
|
|
89
90
|
console.log(chalk.yellow(`\n${formatCount(withoutStackCount, "resource")} not assigned to any stack.`));
|
|
90
91
|
showDetail('Run "tdk resources --no-stack" to see them, or "tdk stack" to assign them.');
|
|
91
92
|
}
|
|
@@ -3,19 +3,36 @@ import { Command } from "commander";
|
|
|
3
3
|
import { createDiscoveryContext } from "../utils/discovery-context.js";
|
|
4
4
|
import { runCommand } from "../utils/errors.js";
|
|
5
5
|
import { formatCount, showDetail, showEmptyState, showStep } from "../utils/formatting.js";
|
|
6
|
+
import { createMachineEnvelope, writeMachineError } from "../utils/machine-output.js";
|
|
7
|
+
import { findProjectRoot } from "../utils/paths.js";
|
|
6
8
|
export const stacksCommand = new Command("stacks")
|
|
7
9
|
.description("List all stacks and their resources")
|
|
8
10
|
.alias("ls") // Keep 'tdk ls' as shorthand
|
|
9
11
|
.option("-v, --verbose", "Show detailed information about each stack", false)
|
|
10
12
|
.option("--services", "Include list of services in each stack", false)
|
|
13
|
+
.option("--json", "Output a versioned JSON stack report", false)
|
|
11
14
|
.action(async (options) => {
|
|
12
|
-
|
|
15
|
+
const action = async () => {
|
|
16
|
+
if (options.json && !findProjectRoot()) {
|
|
17
|
+
writeMachineError(new Error("Could not find project root (no .tdk/project.json found)"));
|
|
18
|
+
}
|
|
13
19
|
const discovery = createDiscoveryContext();
|
|
20
|
+
const verbose = options.verbose || stacksCommand.parent?.opts().verbose === true;
|
|
21
|
+
if (options.json) {
|
|
22
|
+
const stacks = discovery.stacks.map((stack) => ({
|
|
23
|
+
name: stack.name,
|
|
24
|
+
resourceCount: stack.resourceCount,
|
|
25
|
+
...(verbose ? { description: stack.description } : {}),
|
|
26
|
+
...(options.services ? { services: stack.resources.map((service) => service.name) } : {}),
|
|
27
|
+
}));
|
|
28
|
+
console.log(JSON.stringify(createMachineEnvelope({ stacks })));
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
14
31
|
if (discovery.stackNames.length === 0) {
|
|
15
32
|
showEmptyState("stacks");
|
|
16
33
|
return;
|
|
17
34
|
}
|
|
18
|
-
if (
|
|
35
|
+
if (verbose || options.services) {
|
|
19
36
|
showStep(`Found ${formatCount(discovery.stacks.length, "stack")}:\n`);
|
|
20
37
|
for (const stack of discovery.stacks) {
|
|
21
38
|
console.log(chalk.bold(`${stack.name}`));
|
|
@@ -38,6 +55,16 @@ export const stacksCommand = new Command("stacks")
|
|
|
38
55
|
}
|
|
39
56
|
showDetail("\nRun with --verbose for more details, or --services to see all services in each stack.", 0);
|
|
40
57
|
}
|
|
41
|
-
}
|
|
58
|
+
};
|
|
59
|
+
if (options.json) {
|
|
60
|
+
try {
|
|
61
|
+
await action();
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
writeMachineError(error);
|
|
65
|
+
}
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
await runCommand(action);
|
|
42
69
|
});
|
|
43
70
|
//# sourceMappingURL=stacks.js.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import { Command } from "commander";
|
|
3
3
|
import { createDiscoveryContext } from "../utils/discovery-context.js";
|
|
4
|
+
import { getDeferredResourceNames } from "../utils/doctor-runtime.js";
|
|
4
5
|
import { runCommand } from "../utils/errors.js";
|
|
5
6
|
import { formatCount, showDetail, showStep } from "../utils/formatting.js";
|
|
6
7
|
import { getHostPortPlan } from "../utils/host-port-config.js";
|
|
@@ -8,6 +9,7 @@ import { createMachineEnvelope, writeMachineError } from "../utils/machine-outpu
|
|
|
8
9
|
import { findProjectRoot } from "../utils/paths.js";
|
|
9
10
|
import { buildServicePorts, buildStackPorts } from "../utils/status-ports.js";
|
|
10
11
|
import { getTiltfilePath, isTiltAvailable, runTilt } from "../utils/tilt.js";
|
|
12
|
+
import { evaluateTiltReadiness, tiltGetUiResources } from "../utils/up-readiness.js";
|
|
11
13
|
export const statusCommand = new Command("status")
|
|
12
14
|
.description("Show status of resources and stacks")
|
|
13
15
|
.option("--json", "Output a versioned JSON status report", false)
|
|
@@ -53,6 +55,21 @@ export const statusCommand = new Command("status")
|
|
|
53
55
|
queryError = result.stderr || "Could not retrieve Tilt resource status";
|
|
54
56
|
}
|
|
55
57
|
}
|
|
58
|
+
// A single look at the running Tilt, so a caller that started `tdk up` detached can poll for readiness. Null when no
|
|
59
|
+
// Tilt answers or its output cannot be read.
|
|
60
|
+
let readiness = null;
|
|
61
|
+
if (options.json && tiltAvailable) {
|
|
62
|
+
const port = Number.parseInt(process.env.TILT_PORT ?? "", 10);
|
|
63
|
+
const text = await tiltGetUiResources(Number.isInteger(port) ? port : 10350);
|
|
64
|
+
if (text) {
|
|
65
|
+
try {
|
|
66
|
+
readiness = evaluateTiltReadiness(text, getDeferredResourceNames()).result;
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
readiness = null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
56
73
|
if (options.json) {
|
|
57
74
|
let portPlan = null;
|
|
58
75
|
try {
|
|
@@ -68,6 +85,7 @@ export const statusCommand = new Command("status")
|
|
|
68
85
|
available: tiltAvailable,
|
|
69
86
|
resourcesQueried: options.tilt && tiltAvailable,
|
|
70
87
|
resources: tiltResources,
|
|
88
|
+
readiness,
|
|
71
89
|
},
|
|
72
90
|
resources: discovery.resources.map((resource) => ({
|
|
73
91
|
name: resource.name,
|
package/cli/dist/commands/ui.js
CHANGED
|
@@ -6,6 +6,7 @@ import { DetailPanel, FileTree, ResourceSelectInput, ResourceTable, TabBar, } fr
|
|
|
6
6
|
import { errorFactories, requireProjectRoot } from "../utils/errors.js";
|
|
7
7
|
import { findProjectRoot } from "../utils/paths.js";
|
|
8
8
|
import { clearMetadataCache, discoverResources, discoverStacks, getResourceMetadata, getStackMetadata, } from "../utils/services.js";
|
|
9
|
+
import { createStatusMessageController } from "../utils/status-message.js";
|
|
9
10
|
import { isTiltAvailable } from "../utils/tilt.js";
|
|
10
11
|
// biome-ignore lint/correctness/noUnusedFunctionParameters: reserved callback prop kept in the component API
|
|
11
12
|
const HelpPanel = ({ onClose }) => (_jsxs(Box, { borderStyle: "single", borderColor: "cyan", paddingX: 2, paddingY: 1, flexDirection: "column", width: 60, children: [_jsx(Text, { bold: true, color: "cyan", children: "Keyboard Shortcuts" }), _jsxs(Box, { marginY: 1, flexDirection: "column", children: [_jsx(Text, { bold: true, underline: true, children: "Navigation" }), _jsx(Text, { children: " \u2191/\u2193 Navigate list items" }), _jsx(Text, { children: " Enter Select item / Open detail" }), _jsx(Text, { children: " Space Toggle expand (tree view)" }), _jsx(Text, { children: " Tab Next tab" }), _jsx(Text, { children: " 1-5 Direct tab access" }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { bold: true, underline: true, children: "Actions" }) }), _jsx(Text, { children: " m Toggle mouse support" }), _jsx(Text, { children: " t Toggle tooltips" }), _jsx(Text, { children: " e Toggle enabled/disabled services" }), _jsx(Text, { children: " r Refresh data" }), _jsx(Text, { children: " / Search/filter" }), _jsx(Text, { children: " ? Show this help" }), _jsx(Text, { children: " q Quit \u2502 Esc Back" })] }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { color: "gray", dimColor: true, children: "Press any key to close..." }) })] }));
|
|
@@ -32,6 +33,8 @@ const TUIApp = () => {
|
|
|
32
33
|
const [error, setError] = useState(null);
|
|
33
34
|
const [showTooltips, setShowTooltips] = useState(true);
|
|
34
35
|
const [showEnabledOnly, setShowEnabledOnly] = useState(true);
|
|
36
|
+
const statusMessage = useMemo(() => createStatusMessageController(setMessage), []);
|
|
37
|
+
useEffect(() => () => statusMessage.dispose(), [statusMessage]);
|
|
35
38
|
const projectRoot = findProjectRoot() || "unknown";
|
|
36
39
|
const [{ stacks, services }, setDiscovered] = useState({ stacks: [], services: [] });
|
|
37
40
|
// Re-read service.json files from disk. An empty project is not an error:
|
|
@@ -158,14 +161,12 @@ const TUIApp = () => {
|
|
|
158
161
|
if (activeTab === "overview") {
|
|
159
162
|
setSelectedStack(item.value);
|
|
160
163
|
setSelectedService(null);
|
|
161
|
-
|
|
162
|
-
setTimeout(() => setMessage(""), 2000);
|
|
164
|
+
statusMessage.show(`Selected stack: ${item.value}`, 2000);
|
|
163
165
|
}
|
|
164
166
|
else if (activeTab === "resources") {
|
|
165
167
|
if (selectedStack && !selectedService) {
|
|
166
168
|
setSelectedService(item.value);
|
|
167
|
-
|
|
168
|
-
setTimeout(() => setMessage(""), 2000);
|
|
169
|
+
statusMessage.show(`Selected service: ${item.value}`, 2000);
|
|
169
170
|
}
|
|
170
171
|
else {
|
|
171
172
|
setSelectedStack(item.value);
|
|
@@ -175,21 +176,18 @@ const TUIApp = () => {
|
|
|
175
176
|
else if (activeTab === "files") {
|
|
176
177
|
if (selectedService) {
|
|
177
178
|
setSelectedFile(item.value);
|
|
178
|
-
|
|
179
|
-
setTimeout(() => setMessage(""), 2000);
|
|
179
|
+
statusMessage.show(`Selected file: ${item.label}`, 2000);
|
|
180
180
|
}
|
|
181
181
|
else {
|
|
182
182
|
setSelectedService(item.value);
|
|
183
|
-
|
|
184
|
-
setTimeout(() => setMessage(""), 2000);
|
|
183
|
+
statusMessage.show(`Selected service: ${item.value}`, 2000);
|
|
185
184
|
}
|
|
186
185
|
}
|
|
187
186
|
else if (activeTab === "config") {
|
|
188
187
|
setSelectedService(item.value);
|
|
189
|
-
|
|
190
|
-
setTimeout(() => setMessage(""), 2000);
|
|
188
|
+
statusMessage.show(`Viewing config for: ${item.value}`, 2000);
|
|
191
189
|
}
|
|
192
|
-
}, [activeTab, selectedStack, selectedService]);
|
|
190
|
+
}, [activeTab, selectedStack, selectedService, statusMessage]);
|
|
193
191
|
useEffect(() => {
|
|
194
192
|
setRawMode(true);
|
|
195
193
|
stdout.write("\x1b[?1000h");
|
|
@@ -297,8 +295,7 @@ const TUIApp = () => {
|
|
|
297
295
|
setSelectedStack(null);
|
|
298
296
|
return;
|
|
299
297
|
}
|
|
300
|
-
|
|
301
|
-
setTimeout(() => setMessage(""), 2000);
|
|
298
|
+
statusMessage.show("Press q to quit", 2000);
|
|
302
299
|
return;
|
|
303
300
|
}
|
|
304
301
|
if (input === "?") {
|
|
@@ -307,8 +304,7 @@ const TUIApp = () => {
|
|
|
307
304
|
}
|
|
308
305
|
if (input === "r") {
|
|
309
306
|
if (refresh()) {
|
|
310
|
-
|
|
311
|
-
setTimeout(() => setMessage(""), 1500);
|
|
307
|
+
statusMessage.show("Data refreshed", 1500);
|
|
312
308
|
}
|
|
313
309
|
return;
|
|
314
310
|
}
|
|
@@ -321,28 +317,25 @@ const TUIApp = () => {
|
|
|
321
317
|
if (input === "m") {
|
|
322
318
|
setMouseEnabled((prev) => {
|
|
323
319
|
const newState = !prev;
|
|
324
|
-
|
|
320
|
+
statusMessage.show(newState ? "Mouse support enabled" : "Mouse support disabled");
|
|
325
321
|
return newState;
|
|
326
322
|
});
|
|
327
|
-
setTimeout(() => setMessage(""), 1500);
|
|
328
323
|
return;
|
|
329
324
|
}
|
|
330
325
|
if (input === "t") {
|
|
331
326
|
setShowTooltips((prev) => {
|
|
332
327
|
const newState = !prev;
|
|
333
|
-
|
|
328
|
+
statusMessage.show(newState ? "Tooltips enabled" : "Tooltips disabled");
|
|
334
329
|
return newState;
|
|
335
330
|
});
|
|
336
|
-
setTimeout(() => setMessage(""), 1500);
|
|
337
331
|
return;
|
|
338
332
|
}
|
|
339
333
|
if (input === "e") {
|
|
340
334
|
setShowEnabledOnly((prev) => {
|
|
341
335
|
const newState = !prev;
|
|
342
|
-
|
|
336
|
+
statusMessage.show(newState ? "Showing enabled services only" : "Showing all services (including disabled)", 1500);
|
|
343
337
|
return newState;
|
|
344
338
|
});
|
|
345
|
-
setTimeout(() => setMessage(""), 1500);
|
|
346
339
|
return;
|
|
347
340
|
}
|
|
348
341
|
if (key.tab) {
|