feat: add aipod spec Artificer assembly

This commit is contained in:
Codex
2026-06-10 17:46:45 +08:00
parent 45df61bd02
commit 6989dc18ef
22 changed files with 2103 additions and 56 deletions
+59 -3
View File
@@ -14,12 +14,14 @@ function jsonHelp() {
"tran <provider> argv <command...>",
"tran <provider> script -- '<shell script>'",
"tran <provider>:/absolute/workspace script -- '<shell script>'",
"tran <provider>:/absolute/workspace apply-patch < patch.diff",
"tran <provider>:k3s kubectl <args...>",
"tran <provider>:k3s script -- '<shell script>'",
"tran <provider>:k3s:<namespace>:<workload>[:container] argv <command...>",
"tran <provider>:k3s:<namespace>:<workload>[:container] script -- '<shell script>'",
"tran <provider>:k3s:<namespace>:<workload>[:container] apply-patch < patch.diff",
],
unsupported: ["apply-patch", "upload", "download", "Windows win/ps/cmd routes"],
unsupported: ["upload", "download", "Windows win/ps/cmd routes"],
valuesPrinted: false,
};
}
@@ -87,6 +89,54 @@ async function readStdinText() {
return Buffer.concat(chunks).toString("utf8");
}
async function readApplyPatchHelperSource() {
const helperPath = new URL("./apply_patch", import.meta.url);
try {
const text = await Bun.file(helperPath).text();
if (!text.startsWith("#!")) fail("infra-failed", "adjacent apply_patch helper is not executable script shaped", { helper: "tools/apply_patch" });
return text;
} catch (error) {
fail("infra-failed", "adjacent apply_patch helper is required for runner-side tran apply-patch", { helper: "tools/apply_patch", error: error instanceof Error ? error.message : String(error) });
}
}
function applyPatchToolArgs(args) {
const supported = new Set(["--allow-loose", "--help", "-h"]);
for (const arg of args) {
if (!supported.has(arg)) fail("schema-invalid", `unsupported apply-patch option: ${arg}`, { supported: [...supported].sort() });
}
return args;
}
function base64Text(value) {
return Buffer.from(value, "utf8").toString("base64").replace(/.{1,76}/g, "$&\n").trimEnd();
}
async function applyPatchRemoteScript(args) {
const toolArgs = applyPatchToolArgs(args);
const [helperSource, patchText] = await Promise.all([readApplyPatchHelperSource(), readStdinText()]);
if (patchText.trim().length === 0) fail("schema-invalid", "apply-patch requires patch text on stdin");
const helperMarker = "__AGENTRUN_TRAN_APPLY_PATCH_HELPER__";
const patchMarker = "__AGENTRUN_TRAN_APPLY_PATCH_BODY__";
const toolArgText = toolArgs.length > 0 ? ` ${shellArgv(toolArgs)}` : "";
return [
"set -eu",
"helper=$(mktemp \"${TMPDIR:-/tmp}/agentrun-apply-patch.XXXXXX\") || exit 1",
"patch_file=$(mktemp \"${TMPDIR:-/tmp}/agentrun-apply-patch-body.XXXXXX\") || exit 1",
"cleanup() { rm -f \"$helper\" \"$patch_file\"; }",
"trap cleanup EXIT HUP INT TERM",
"decode_b64() { base64 -d; }",
`decode_b64 > \"$helper\" <<'${helperMarker}'`,
base64Text(helperSource),
helperMarker,
`decode_b64 > \"$patch_file\" <<'${patchMarker}'`,
base64Text(patchText),
patchMarker,
"chmod 700 \"$helper\"",
`\"$helper\"${toolArgText} < \"$patch_file\"`,
].join("\n");
}
async function scriptCommand(args) {
if (args[0] === "--") {
const rest = args.slice(1);
@@ -101,7 +151,8 @@ async function scriptCommand(args) {
async function hostCommand(route, args) {
if (args.length === 0) return { command: null, cwd: route.workspace, tty: true };
const op = args[0];
if (op === "apply-patch" || op === "upload" || op === "download") {
if (op === "apply-patch") return { command: await applyPatchRemoteScript(args.slice(1)), cwd: route.workspace, tty: false };
if (op === "upload" || op === "download") {
fail("unsupported-operation", `AgentRun tran does not support ${op}; use host/source controlled tools outside the runner for that operation`, { operation: op });
}
if (op === "script" || op === "shell") return { command: await scriptCommand(args.slice(1)), cwd: route.workspace, tty: false };
@@ -121,10 +172,11 @@ function k3sExecPrefix(route) {
async function k3sCommand(route, args) {
const op = args[0] || "kubectl";
if (op === "apply-patch" || op === "upload" || op === "download") {
if (op === "upload" || op === "download") {
fail("unsupported-operation", `AgentRun tran does not support ${op}; use host/source controlled tools outside the runner for that operation`, { operation: op });
}
if (!route.resource) {
if (op === "apply-patch") fail("schema-invalid", "k3s apply-patch requires namespace and workload route", { route: route.raw });
if (op === "kubectl") return { command: shellArgv(["env", "KUBECONFIG=/etc/rancher/k3s/k3s.yaml", "kubectl", ...args.slice(1)]), cwd: null, tty: false };
if (op === "script" || op === "shell") {
const script = await scriptCommand(args.slice(1));
@@ -133,6 +185,10 @@ async function k3sCommand(route, args) {
if (op === "argv") return { command: shellArgv(["env", "KUBECONFIG=/etc/rancher/k3s/k3s.yaml", ...args.slice(1)]), cwd: null, tty: false };
return { command: shellArgv(["env", "KUBECONFIG=/etc/rancher/k3s/k3s.yaml", ...args]), cwd: null, tty: false };
}
if (op === "apply-patch") {
const script = await applyPatchRemoteScript(args.slice(1));
return { command: shellArgv([...k3sExecPrefix(route), "sh", "-lc", script]), cwd: null, tty: false };
}
if (op === "script" || op === "shell") {
const script = await scriptCommand(args.slice(1));
return { command: shellArgv([...k3sExecPrefix(route), "sh", "-lc", script]), cwd: null, tty: false };