|
| 1 | +#!/usr/bin/env node |
| 2 | +import fs from 'node:fs'; |
| 3 | +import path from 'node:path'; |
| 4 | +import { fileURLToPath } from 'node:url'; |
| 5 | + |
| 6 | +const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 7 | +const DEFAULT_POLICY = path.join(__dirname, 'policy.example.json'); |
| 8 | +const DEFAULT_BASE_URL = 'https://agoragentic.com'; |
| 9 | + |
| 10 | +const REQUIRED_SECTIONS = [ |
| 11 | + 'agent_manifest', |
| 12 | + 'context_policy', |
| 13 | + 'tool_policy', |
| 14 | + 'budget_policy', |
| 15 | + 'approval_policy', |
| 16 | + 'memory_policy', |
| 17 | + 'swarm_policy', |
| 18 | + 'deployment_policy', |
| 19 | +]; |
| 20 | + |
| 21 | +function parseArgs(argv) { |
| 22 | + const args = { |
| 23 | + policy: DEFAULT_POLICY, |
| 24 | + output: null, |
| 25 | + baseUrl: DEFAULT_BASE_URL, |
| 26 | + }; |
| 27 | + |
| 28 | + for (let i = 0; i < argv.length; i += 1) { |
| 29 | + const arg = argv[i]; |
| 30 | + if (arg === '--policy') args.policy = argv[++i]; |
| 31 | + else if (arg === '--output') args.output = argv[++i]; |
| 32 | + else if (arg === '--base-url') args.baseUrl = argv[++i]; |
| 33 | + else if (arg === '--help' || arg === '-h') { |
| 34 | + printHelp(); |
| 35 | + process.exit(0); |
| 36 | + } else { |
| 37 | + throw new Error(`Unknown argument: ${arg}`); |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + return args; |
| 42 | +} |
| 43 | + |
| 44 | +function printHelp() { |
| 45 | + console.log(`Usage: |
| 46 | + node micro-ecf/export-agent-os-harness.mjs --policy micro-ecf/policy.example.json --output ./agent-os-harness.packet.json |
| 47 | +
|
| 48 | +Options: |
| 49 | + --policy <path> Micro ECF policy JSON. Defaults to micro-ecf/policy.example.json. |
| 50 | + --output <path> Write packet to a file. Defaults to stdout. |
| 51 | + --base-url <url> Agoragentic base URL. Defaults to https://agoragentic.com. |
| 52 | +`); |
| 53 | +} |
| 54 | + |
| 55 | +function readPolicy(policyPath) { |
| 56 | + const resolved = path.resolve(policyPath); |
| 57 | + const policy = JSON.parse(fs.readFileSync(resolved, 'utf8')); |
| 58 | + validatePolicy(policy); |
| 59 | + return { policy, resolved }; |
| 60 | +} |
| 61 | + |
| 62 | +function validatePolicy(policy) { |
| 63 | + for (const section of REQUIRED_SECTIONS) { |
| 64 | + if (!policy[section] || typeof policy[section] !== 'object' || Array.isArray(policy[section])) { |
| 65 | + throw new Error(`Missing required object section: ${section}`); |
| 66 | + } |
| 67 | + } |
| 68 | + if (!policy.agent_manifest.name) throw new Error('agent_manifest.name is required'); |
| 69 | + if (!policy.agent_manifest.primary_goal) throw new Error('agent_manifest.primary_goal is required'); |
| 70 | +} |
| 71 | + |
| 72 | +function buildHarnessPacket(policy, { baseUrl, policyPath }) { |
| 73 | + const deploymentPolicy = policy.deployment_policy || {}; |
| 74 | + const budgetPolicy = policy.budget_policy || {}; |
| 75 | + const agent = policy.agent_manifest || {}; |
| 76 | + const source = deploymentPolicy.source || {}; |
| 77 | + const hostingTarget = deploymentPolicy.hosting_target || 'self_hosted_http'; |
| 78 | + |
| 79 | + const packet = { |
| 80 | + schema: 'agoragentic.agent-os.harness.v1', |
| 81 | + generated_at: new Date().toISOString(), |
| 82 | + generated_from: { |
| 83 | + source: 'micro-ecf/export-agent-os-harness.mjs', |
| 84 | + policy_path: policyPath, |
| 85 | + canonical_contract: `${baseUrl.replace(/\/$/, '')}/agent-os-harness.json`, |
| 86 | + }, |
| 87 | + agent_manifest: agent, |
| 88 | + context_policy: policy.context_policy, |
| 89 | + tool_policy: policy.tool_policy, |
| 90 | + budget_policy: budgetPolicy, |
| 91 | + approval_policy: policy.approval_policy, |
| 92 | + memory_policy: policy.memory_policy, |
| 93 | + swarm_policy: policy.swarm_policy, |
| 94 | + deployment_policy: deploymentPolicy, |
| 95 | + public_boundary: { |
| 96 | + no_spend_export: true, |
| 97 | + hosted_billing: false, |
| 98 | + cloud_provisioning: false, |
| 99 | + marketplace_publication: false, |
| 100 | + hosted_runtime_secrets: false, |
| 101 | + requires_agent_os_preview_before_deployment: true, |
| 102 | + requires_treasury_funding_before_autonomous_spend: true, |
| 103 | + }, |
| 104 | + agent_os_export: { |
| 105 | + catalog_endpoint: 'GET /api/hosting/agent-os/catalog', |
| 106 | + preview_endpoint: 'POST /api/hosting/agent-os/preview', |
| 107 | + deployment_endpoint: 'POST /api/hosting/agent-os/deployments', |
| 108 | + treasury_endpoint: 'GET /api/hosting/agent-os/deployments/{deployment_id}/treasury', |
| 109 | + workspace_surface: '/agent-os/workspaces/', |
| 110 | + marketplace_router: 'POST /api/execute', |
| 111 | + x402_edge: 'POST https://x402.agoragentic.com/v1/{slug}', |
| 112 | + }, |
| 113 | + agent_os_preview_request: { |
| 114 | + name: agent.name, |
| 115 | + hosting_target: hostingTarget, |
| 116 | + template_id: hostingTarget === 'platform_hosted_syrin' ? 'syrin_creator_demo' : 'self_hosted_router_advocate', |
| 117 | + runtime_lane: hostingTarget === 'platform_hosted_syrin' ? 'shared_platform_runtime' : 'customer_managed_http_runtime', |
| 118 | + exposure_mode: deploymentPolicy.exposure_mode || 'private_only', |
| 119 | + source: { |
| 120 | + type: source.type || 'repository', |
| 121 | + ref: source.ref || '', |
| 122 | + }, |
| 123 | + goals: { |
| 124 | + primary_goal: agent.primary_goal, |
| 125 | + budget: { |
| 126 | + max_daily_usdc: budgetPolicy.max_daily_spend_usdc || 0, |
| 127 | + approval_required_above_usdc: budgetPolicy.approval_required_above_usdc || 0, |
| 128 | + recommended_start_reserve_usdc: budgetPolicy.recommended_start_reserve_usdc || 0, |
| 129 | + }, |
| 130 | + }, |
| 131 | + safety_policy: { |
| 132 | + first_proof_required: deploymentPolicy.first_proof_required !== false, |
| 133 | + context_policy: policy.context_policy, |
| 134 | + tool_policy: policy.tool_policy, |
| 135 | + approval_policy: policy.approval_policy, |
| 136 | + memory_policy: policy.memory_policy, |
| 137 | + swarm_policy: policy.swarm_policy, |
| 138 | + }, |
| 139 | + deployment_packet: { |
| 140 | + schema: 'agoragentic.micro-ecf.export.v1', |
| 141 | + source: 'public_micro_ecf', |
| 142 | + harness_schema: 'agoragentic.agent-os.harness.v1', |
| 143 | + }, |
| 144 | + }, |
| 145 | + }; |
| 146 | + |
| 147 | + return packet; |
| 148 | +} |
| 149 | + |
| 150 | +function main() { |
| 151 | + const args = parseArgs(process.argv.slice(2)); |
| 152 | + const { policy, resolved } = readPolicy(args.policy); |
| 153 | + const packet = buildHarnessPacket(policy, { |
| 154 | + baseUrl: args.baseUrl, |
| 155 | + policyPath: path.relative(process.cwd(), resolved).replace(/\\/g, '/'), |
| 156 | + }); |
| 157 | + const json = `${JSON.stringify(packet, null, 2)}\n`; |
| 158 | + |
| 159 | + if (args.output) { |
| 160 | + const outputPath = path.resolve(args.output); |
| 161 | + fs.mkdirSync(path.dirname(outputPath), { recursive: true }); |
| 162 | + fs.writeFileSync(outputPath, json); |
| 163 | + console.log(JSON.stringify({ ok: true, output: outputPath }, null, 2)); |
| 164 | + } else { |
| 165 | + process.stdout.write(json); |
| 166 | + } |
| 167 | +} |
| 168 | + |
| 169 | +try { |
| 170 | + main(); |
| 171 | +} catch (err) { |
| 172 | + console.error(JSON.stringify({ ok: false, error: err.message }, null, 2)); |
| 173 | + process.exit(1); |
| 174 | +} |
0 commit comments