wishforge-ide/scripts/meta-evolution-tick.mjs
eust-w b47a07e8d2 chore: baseline snapshot of the Codex-delivered code before review
Imports the previously untracked working tree as-is so that the review
changes that follow (requirements -> design -> implementation) can be
reviewed as diffs and reverted if needed. No content changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 13:18:04 +08:00

20 lines
2.1 KiB
JavaScript

#!/usr/bin/env node
// One explicitly requested tick. This entrypoint never installs a schedule or invokes a model directly.
const args=process.argv.slice(2);
if(args.length===1&&args[0]==='--help'){
console.log('Usage: node scripts/meta-evolution-tick.mjs --tick\nRequires WF_SYSTEM_TENANT, WF_META_TICK_TOKEN and WF_META_CONTROL_PLANE_URL (or WF_CONTROL_PLANE_URL). Configure system project/provider/budget server-side.');
}else if(args.length!==1||args[0]!=='--tick'){
console.error('Exactly one --tick flag is required. No background loop is created.');process.exitCode=1;
}else{
try{process.loadEnvFile('.env.local');}catch{}
const tenant=process.env.WF_SYSTEM_TENANT,token=process.env.WF_META_TICK_TOKEN,base=process.env.WF_META_CONTROL_PLANE_URL??process.env.WF_CONTROL_PLANE_URL;
if(!tenant||!token||!base)console.log(JSON.stringify({status:'unconfigured',reason:'Configure the system tenant, dedicated operator tick credential and control-plane URL; no task was submitted'}));
else try{
const url=new URL(base);
if(url.username||url.password||url.hash||url.search||(url.protocol!=='https:'&&!['127.0.0.1','localhost','[::1]'].includes(url.hostname)))throw new Error('Secure control-plane endpoint required');
const response=await fetch(new URL('/v1/evolution/tick',url),{method:'POST',headers:{authorization:`Bearer ${token}`,'x-wishforge-tenant':tenant,'content-type':'application/json'},body:'{}',redirect:'error',signal:AbortSignal.timeout(30000)});
if(!response.ok){console.error(JSON.stringify({status:'failed',reason:`Control plane returned HTTP ${response.status}; credentials and response details are not printed`}));process.exitCode=1;}
else {const payload=await response.json();const value=payload.data??payload;console.log(JSON.stringify({status:value.status,reason:value.reason,metaTaskId:value.metaTaskId,runId:value.runId,wishId:value.wishId,baselineBundle:value.baselineBundle,scope:value.scope}));}
}catch{console.error(JSON.stringify({status:'failed',reason:'Meta-loop request was not confirmed; retry the explicit tick after checking connectivity. The service deduplicates the source/baseline/scope operation.'}));process.exitCode=1;}
}