fix: improve egress and job diagnostics (#969)
Co-authored-by: Codex <codex@noreply.local>
This commit is contained in:
+42
-11
@@ -1,8 +1,10 @@
|
||||
// SPEC: PJ2026-01060509 出站诊断 draft-2026-06-26-p8-egress-job-friction.
|
||||
// UniDesk CLI dispatcher with bounded server lifecycle and job drill-down output.
|
||||
import { readConfig } from "./src/config";
|
||||
import { debugDispatch, debugHealth, debugSshPool, debugTask, isDebugDispatchCommand, type DebugDispatchCommand } from "./src/debug";
|
||||
import { isRebuildableService, isRestartableService, rebuildService, restartService, stackLogs, stackStatus, startStack, stopStack, unsupportedRebuildService, unsupportedRestartService } from "./src/docker";
|
||||
import { emitError, emitJson, emitText, isRenderedCliResult } from "./src/output";
|
||||
import { cancelJob, jobWithTail, listJobs, listJobsSummary, readJob, renderJobStatusSummary, runJob } from "./src/jobs";
|
||||
import { cancelJob, jobWithTail, listJobs, listJobsSummary, readJob, renderJobLaunchSummary, renderJobStatusSummary, runJob } from "./src/jobs";
|
||||
import { checkHelp, parseCheckOptions, runChecks, runRecoveryGuardrailsCheck } from "./src/check";
|
||||
import { runSsh } from "./src/ssh";
|
||||
import { autoRemoteCiPublishUserServiceDryRunPlan, extractRemoteCliOptions, runRemoteCli } from "./src/remote";
|
||||
@@ -193,6 +195,23 @@ function latestJobId(): string {
|
||||
return jobs[0].id;
|
||||
}
|
||||
|
||||
function wantsFullDisclosure(): boolean {
|
||||
return args.includes("--full") || args.includes("--raw");
|
||||
}
|
||||
|
||||
function emitServerLifecycleResult(result: unknown, ok = true): void {
|
||||
if (!wantsFullDisclosure()) {
|
||||
const rendered = renderJobLaunchSummary(commandName, result);
|
||||
if (rendered !== null) {
|
||||
emitText(rendered.renderedText, rendered.command || commandName);
|
||||
if (!rendered.ok) process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
emitJson(commandName, result, ok);
|
||||
if (!ok) process.exitCode = 1;
|
||||
}
|
||||
|
||||
async function main(): Promise<void> {
|
||||
if (remoteOptions.host !== null) {
|
||||
process.exitCode = await runRemoteCli(remoteOptions, readConfig());
|
||||
@@ -444,12 +463,11 @@ async function main(): Promise<void> {
|
||||
if (sub === "start") {
|
||||
const result = startStack(config);
|
||||
const ok = (result as { ok?: unknown }).ok !== false;
|
||||
emitJson(commandName, result, ok);
|
||||
if (!ok) process.exitCode = 1;
|
||||
emitServerLifecycleResult(result, ok);
|
||||
return;
|
||||
}
|
||||
if (sub === "stop") {
|
||||
emitJson(commandName, stopStack(config));
|
||||
emitServerLifecycleResult(stopStack(config));
|
||||
return;
|
||||
}
|
||||
if (sub === "status") {
|
||||
@@ -484,7 +502,7 @@ async function main(): Promise<void> {
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
emitJson(commandName, rebuildService(config, third));
|
||||
emitServerLifecycleResult(rebuildService(config, third));
|
||||
return;
|
||||
}
|
||||
if (sub === "restart") {
|
||||
@@ -494,7 +512,7 @@ async function main(): Promise<void> {
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
emitJson(commandName, restartService(config, third));
|
||||
emitServerLifecycleResult(restartService(config, third));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -564,22 +582,35 @@ async function main(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
if (top === "job") {
|
||||
if (sub === "list") {
|
||||
if (top === "job" || top === "jobs") {
|
||||
const jobSub = sub === "get" || sub === "read" ? "status" : sub;
|
||||
if (jobSub === "list" || jobSub === undefined || isHelpToken(jobSub)) {
|
||||
if (jobSub === undefined || isHelpToken(jobSub)) {
|
||||
emitJson(commandName, {
|
||||
command: "job|jobs list|status|get|read|cancel",
|
||||
aliases: ["jobs list", "jobs get <jobId|latest>", "jobs read <jobId|latest>"],
|
||||
usage: [
|
||||
"bun scripts/cli.ts job list [--limit N] [--include-command]",
|
||||
"bun scripts/cli.ts job status <jobId|latest> [--tail-bytes N] [--full|--raw]",
|
||||
"bun scripts/cli.ts jobs get <jobId|latest>",
|
||||
],
|
||||
});
|
||||
return;
|
||||
}
|
||||
emitJson(commandName, listJobsSummary({ limit: boundedNumberOption("--limit", 50, 500), includeCommand: args.includes("--include-command") }));
|
||||
return;
|
||||
}
|
||||
if (sub === "status") {
|
||||
if (jobSub === "status") {
|
||||
const id = third === "latest" || third === undefined ? latestJobId() : third;
|
||||
const job = jobWithTail(readJob(id), boundedNumberOption("--tail-bytes", 12000, 500_000));
|
||||
if (args.includes("--full") || args.includes("--raw")) {
|
||||
if (wantsFullDisclosure()) {
|
||||
emitJson(commandName, { job });
|
||||
return;
|
||||
}
|
||||
emitText(renderJobStatusSummary(job).renderedText, commandName);
|
||||
return;
|
||||
}
|
||||
if (sub === "cancel") {
|
||||
if (jobSub === "cancel") {
|
||||
if (!third) throw new Error("job cancel requires job id");
|
||||
emitJson(commandName, cancelJob(third));
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user