fix: add agentrun argo refresh command

This commit is contained in:
Codex
2026-06-01 14:47:58 +00:00
parent 2845db3365
commit 9a9cdb7fdc
4 changed files with 94 additions and 7 deletions
+89 -4
View File
@@ -7,15 +7,20 @@ const sourceBranch = "v0.1";
const runtimeNamespace = "agentrun-v01";
const ciNamespace = "agentrun-ci";
const pipelineName = "agentrun-v01-ci-image-publish";
const argoNamespace = "argocd";
const argoApplication = "agentrun-g14-v01";
const gitopsBranch = "v0.1-gitops";
export function agentRunHelp(): unknown {
return {
command: "agentrun v01 control-plane status|trigger-current",
command: "agentrun v01 control-plane status|trigger-current|refresh",
output: "json",
usage: [
"bun scripts/cli.ts agentrun v01 control-plane status",
"bun scripts/cli.ts agentrun v01 control-plane trigger-current --dry-run",
"bun scripts/cli.ts agentrun v01 control-plane trigger-current --confirm",
"bun scripts/cli.ts agentrun v01 control-plane refresh --dry-run",
"bun scripts/cli.ts agentrun v01 control-plane refresh --confirm",
],
description: "Operate AgentRun v0.1 Tekton/Argo control plane through G14 routes; trigger-current is short-return and status is read-only.",
};
@@ -26,6 +31,7 @@ export async function runAgentRunCommand(config: UniDeskConfig, args: string[]):
if (lane !== "v01" || group !== "control-plane") return unsupported(args);
if (action === "status") return await status(config);
if (action === "trigger-current") return await triggerCurrent(config, parseTriggerOptions(args.slice(3)));
if (action === "refresh") return await refresh(config, parseConfirmOptions(args.slice(3)));
return unsupported(args);
}
@@ -34,7 +40,17 @@ interface TriggerOptions {
dryRun: boolean;
}
interface ConfirmOptions {
confirm: boolean;
dryRun: boolean;
}
function parseTriggerOptions(args: string[]): TriggerOptions {
return parseConfirmOptions(args);
}
function parseConfirmOptions(args: string[]): ConfirmOptions {
if (args.includes("--confirm") && args.includes("--dry-run")) throw new Error("accepts only one of --confirm or --dry-run");
return {
confirm: args.includes("--confirm"),
dryRun: args.includes("--dry-run") || !args.includes("--confirm"),
@@ -49,20 +65,34 @@ async function status(config: UniDeskConfig): Promise<Record<string, unknown>> {
"git rev-parse HEAD",
"printf 'originV01='",
"git rev-parse origin/v0.1 2>/dev/null || true",
"printf 'gitopsLatest='",
`git ls-remote origin ${gitopsBranch} 2>/dev/null | awk '{print $1}' || true`,
"git status --short --branch",
].join("\n")]);
const sourceCommit = matchLine(source.stdout, "sourceCommit=");
const gitopsLatest = matchLine(source.stdout, "gitopsLatest=");
const pipelineRun = sourceCommit ? pipelineRunName(sourceCommit) : null;
const k3s = await capture(config, g14K3sRoute, ["script", "--", statusScript(pipelineRun)]);
const argo = parseArgoStatus(k3s.stdout);
return {
ok: source.exitCode === 0 && k3s.exitCode === 0,
command: "agentrun v01 control-plane status",
lane: "v0.1",
sourceCommit,
gitopsLatest,
expectedPipelineRun: pipelineRun,
source: compactCapture(source),
runtime: compactCapture(k3s),
next: { triggerCurrent: "bun scripts/cli.ts agentrun v01 control-plane trigger-current --confirm" },
runtimeAlignment: {
argoRevision: argo.revision,
argoSyncStatus: argo.syncStatus,
argoHealthStatus: argo.healthStatus,
syncedToGitopsLatest: Boolean(gitopsLatest && argo.revision === gitopsLatest),
},
next: {
triggerCurrent: "bun scripts/cli.ts agentrun v01 control-plane trigger-current --confirm",
refresh: "bun scripts/cli.ts agentrun v01 control-plane refresh --confirm",
},
};
}
@@ -112,6 +142,41 @@ async function triggerCurrent(config: UniDeskConfig, options: TriggerOptions): P
};
}
async function refresh(config: UniDeskConfig, options: ConfirmOptions): Promise<Record<string, unknown>> {
const source = await capture(config, g14SourceRoute, ["script", "--", [
"cd /root/agentrun-v01",
"printf 'gitopsLatest='",
`git ls-remote origin ${gitopsBranch} 2>/dev/null | awk '{print $1}' || true`,
].join("\n")]);
const gitopsLatest = matchLine(source.stdout, "gitopsLatest=");
const plan = {
lane: "v0.1",
argoNamespace,
argoApplication,
gitopsBranch,
gitopsLatest,
};
if (options.dryRun || !options.confirm) {
return {
ok: true,
command: "agentrun v01 control-plane refresh",
dryRun: true,
plan,
next: { confirm: "bun scripts/cli.ts agentrun v01 control-plane refresh --confirm" },
};
}
const refreshed = await capture(config, g14K3sRoute, ["script", "--", refreshScript()]);
return {
ok: source.exitCode === 0 && refreshed.exitCode === 0,
command: "agentrun v01 control-plane refresh",
dryRun: false,
plan,
source: compactCapture(source),
refreshed: compactCapture(refreshed),
next: { status: "bun scripts/cli.ts agentrun v01 control-plane status" },
};
}
function statusScript(pipelineRun: string | null): string {
const pr = pipelineRun ?? "";
return [
@@ -131,12 +196,20 @@ function statusScript(pipelineRun: string | null): string {
"printf 'recentPipelineRuns\\n'",
`kubectl -n ${ciNamespace} get pipelinerun --sort-by=.metadata.creationTimestamp -o 'custom-columns=NAME:.metadata.name,STATUS:.status.conditions[0].status,REASON:.status.conditions[0].reason,CREATED:.metadata.creationTimestamp' --no-headers 2>/dev/null | tail -n 5 || true`,
"printf 'argo\\n'",
"kubectl -n argocd get application agentrun-g14-v01 -o 'jsonpath={.status.sync.revision}{\"\\t\"}{.status.sync.status}{\"\\t\"}{.status.health.status}{\"\\n\"}' 2>/dev/null || true",
`kubectl -n ${argoNamespace} get application ${argoApplication} -o 'jsonpath={.status.sync.revision}{"\\t"}{.status.sync.status}{"\\t"}{.status.health.status}{"\\n"}' 2>/dev/null || true`,
"printf 'workloads\\n'",
`kubectl -n ${runtimeNamespace} get deploy,sts,pod -o wide 2>/dev/null || true`,
].join("\n");
}
function refreshScript(): string {
return [
"set -eu",
`kubectl -n ${argoNamespace} annotate application ${argoApplication} argocd.argoproj.io/refresh=hard --overwrite`,
`kubectl -n ${argoNamespace} get application ${argoApplication} -o 'jsonpath={.status.sync.revision}{"\\t"}{.status.sync.status}{"\\t"}{.status.health.status}{"\\n"}' 2>/dev/null || true`,
].join("\n");
}
function triggerScript(sourceCommit: string, pipelineRun: string): string {
return [
"set -eu",
@@ -215,6 +288,18 @@ function matchLine(text: string, prefix: string): string | null {
return line ? line.slice(prefix.length).trim() || null : null;
}
function parseArgoStatus(text: string): { revision: string | null; syncStatus: string | null; healthStatus: string | null } {
const lines = text.split(/\r?\n/u);
const index = lines.findIndex((line) => line.trim() === "argo");
if (index < 0) return { revision: null, syncStatus: null, healthStatus: null };
const [revision, syncStatus, healthStatus] = (lines[index + 1] ?? "").split("\t");
return {
revision: revision?.trim() || null,
syncStatus: syncStatus?.trim() || null,
healthStatus: healthStatus?.trim() || null,
};
}
function isGitSha(value: string): boolean {
return /^[0-9a-f]{40}$/u.test(value);
}
@@ -232,6 +317,6 @@ function unsupported(args: string[]): Record<string, unknown> {
ok: false,
command: `agentrun ${args.join(" ")}`.trim(),
degradedReason: "unsupported-command",
message: "supported commands: agentrun v01 control-plane status|trigger-current",
message: "supported commands: agentrun v01 control-plane status|trigger-current|refresh",
};
}
+1 -1
View File
@@ -59,7 +59,7 @@ export function rootHelp(): unknown {
{ command: "gh preflight|auth|issue|pr", description: "Run safe GitHub issue and PR CRUD/lifecycle operations through REST with body-file update replace/append, comment delete, token diagnostics, PR closeout preflight, hard delete unsupported, and guarded PR merge." },
{ command: "commander contract|plan --dry-run|smoke --dry-run|approval request --dry-run|prompt-lint --kind gpt55-pr", description: "Host Codex commander skeleton contract, no-daemon smoke plan, dry-run approval preview, and advisory GPT-5.5 PR prompt boundary lint without live bridges, message sends, or submit gating." },
{ command: "hwlab g14 monitor-prs | hwlab g14 control-plane status|apply|trigger-current|runtime-migration|cleanup-runs|cleanup-released-pvs | hwlab g14 git-mirror status|apply|sync|flush | hwlab g14 tools-image status|build", description: "Start the G14 PR monitor, run bounded v0.2 Tekton/Argo control-plane, manual PipelineRun trigger, runtime migration, CI workspace retention, manual devops-infra git mirror/relay maintenance, or fixed HWLAB CI tools image actions through UniDesk G14 routes; long confirmed trigger/sync/flush actions return async jobs by default." },
{ command: "agentrun v01 control-plane status|trigger-current", description: "Run bounded AgentRun v0.1 Tekton/Argo status and manual PipelineRun trigger operations through UniDesk G14 routes." },
{ command: "agentrun v01 control-plane status|trigger-current|refresh", description: "Run bounded AgentRun v0.1 Tekton/Argo status, manual PipelineRun trigger, and Argo refresh operations through UniDesk G14 routes." },
{ command: "hwlab cd audit --env dev | hwlab cd status --env dev | hwlab cd apply --env dev --dry-run", description: "Legacy D601 HWLAB DEV CD wrapper kept for explicit old-path diagnostics; current HWLAB rollout uses G14 GitOps." },
{ command: "code-agent-sandbox", description: "Independent Code Agent Sandbox service skeleton for adapter, mode, and credential-boundary diagnostics." },
{ command: "schedule list|get|runs|run|retry-run|delete", description: "Manage backend-core scheduled tasks and run history; schedule run <id> supports --wait-ms N and retry-run reuses the failed run's schedule." },