From dc8ef79f772fd2ee0f1c5f69fb4f2ce3243a4e2b Mon Sep 17 00:00:00 2001 From: Eve Date: Fri, 24 Apr 2026 12:16:55 +0800 Subject: [PATCH] chore: add approved-plan dispatch binding skeleton --- scripts/approved_plan_dispatch_binding.mjs | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100755 scripts/approved_plan_dispatch_binding.mjs diff --git a/scripts/approved_plan_dispatch_binding.mjs b/scripts/approved_plan_dispatch_binding.mjs new file mode 100755 index 0000000..bacc97f --- /dev/null +++ b/scripts/approved_plan_dispatch_binding.mjs @@ -0,0 +1,82 @@ +#!/usr/bin/env node +import fs from 'node:fs'; + +function parseArgs(argv) { + let inputPath = null; + let compact = false; + + for (let i = 0; i < argv.length; i += 1) { + const arg = argv[i]; + + if (arg === '--input') { + inputPath = argv[i + 1] ?? null; + i += 1; + continue; + } + + if (arg.startsWith('--input=')) { + inputPath = arg.slice('--input='.length); + continue; + } + + if (arg === '--compact') { + compact = true; + continue; + } + } + + return { inputPath, compact }; +} + +function readInput(inputPath) { + if (!inputPath) { + return { + ok: false, + error: 'missing_required_input', + }; + } + + try { + const raw = fs.readFileSync(inputPath, 'utf8'); + return { + ok: true, + bytes: Buffer.byteLength(raw, 'utf8'), + }; + } catch (error) { + return { + ok: false, + error: error instanceof Error ? error.message : String(error), + }; + } +} + +const { inputPath, compact } = parseArgs(process.argv.slice(2)); +const input = readInput(inputPath); + +const response = { + ok: input.ok, + status: input.ok ? 'placeholder_receipt' : 'input_error', + binding: 'approved_plan_dispatch', + compact, + inputPath, + receipt: input.ok + ? { + placeholder: true, + planId: null, + currentTask: null, + nextDerivedAction: null, + dispatchedAt: null, + } + : null, + input: input.ok + ? { + ok: true, + bytes: input.bytes, + } + : { + ok: false, + error: input.error, + }, +}; + +process.stdout.write(`${JSON.stringify(response)}\n`);