11#!/usr/bin/env node
2- import { cpSync , existsSync , mkdirSync , writeFileSync } from "node:fs" ;
2+ import { cpSync , existsSync , mkdirSync , rmSync , writeFileSync } from "node:fs" ;
33import { dirname , resolve } from "node:path" ;
44import { fileURLToPath } from "node:url" ;
55
66const REPO_ROOT = resolve ( dirname ( fileURLToPath ( import . meta. url ) ) , "../.." ) ;
77const OUT_DIR = resolve ( REPO_ROOT , "out/agent-bonds-operator-bundle" ) ;
88
9- const FILES = [
9+ const REQUIRED_FILES = [
1010 "fixtures/agent-bonds/agent-bonds-v1.json" ,
1111 "fixtures/agent-bonds/replay-report.json" ,
1212 "fixtures/agent-bonds/economic-sim-report.json" ,
@@ -28,8 +28,6 @@ const FILES = [
2828 "schemas/flowmemory/agent-bonds-owner-inputs.schema.json" ,
2929 "infra/scripts/agent-bonds-public-launch-assemble.mjs" ,
3030 "infra/scripts/agent-bonds-owner-inputs-validate.mjs" ,
31- "devnet/local/agent-bonds-readiness/agent-bonds-readiness-report.json" ,
32- "devnet/local/agent-bonds-readiness/goal-audit-report.json" ,
3331 "docs/AGENT_BONDS_PUBLIC_LAUNCH_BOUNDARY.md" ,
3432 "docs/OPERATIONS/AGENT_BONDS_CAPPED_PILOT_RUNBOOK.md" ,
3533 "docs/OPERATIONS/AGENT_BONDS_MONITORING_AND_RECOVERY.md" ,
@@ -45,20 +43,53 @@ const FILES = [
4543 "docs/reviews/AGENT_BONDS_GOAL_COMPLETION_MATRIX.md" ,
4644] ;
4745
46+ const OPTIONAL_GENERATED_FILES = [
47+ "devnet/local/agent-bonds-readiness/agent-bonds-readiness-report.json" ,
48+ "devnet/local/agent-bonds-readiness/goal-audit-report.json" ,
49+ ] ;
50+
51+ function copyIntoBundle ( relativePath ) {
52+ const source = resolve ( REPO_ROOT , relativePath ) ;
53+ if ( ! existsSync ( source ) ) {
54+ return false ;
55+ }
56+ const destination = resolve ( OUT_DIR , relativePath ) ;
57+ mkdirSync ( dirname ( destination ) , { recursive : true } ) ;
58+ cpSync ( source , destination , { force : true } ) ;
59+ return true ;
60+ }
61+
4862function main ( ) {
4963 process . chdir ( REPO_ROOT ) ;
64+ rmSync ( OUT_DIR , { recursive : true , force : true } ) ;
5065 mkdirSync ( OUT_DIR , { recursive : true } ) ;
5166 const copied = [ ] ;
52- for ( const relativePath of FILES ) {
53- const source = resolve ( REPO_ROOT , relativePath ) ;
54- if ( ! existsSync ( source ) ) {
67+ const skippedOptional = [ ] ;
68+
69+ for ( const relativePath of REQUIRED_FILES ) {
70+ if ( ! copyIntoBundle ( relativePath ) ) {
5571 throw new Error ( `missing bundle file: ${ relativePath } ` ) ;
5672 }
57- const destination = resolve ( OUT_DIR , relativePath ) ;
58- mkdirSync ( dirname ( destination ) , { recursive : true } ) ;
59- cpSync ( source , destination , { force : true } ) ;
6073 copied . push ( relativePath ) ;
6174 }
75+
76+ for ( const relativePath of OPTIONAL_GENERATED_FILES ) {
77+ if ( copyIntoBundle ( relativePath ) ) {
78+ copied . push ( relativePath ) ;
79+ } else {
80+ skippedOptional . push ( relativePath ) ;
81+ }
82+ }
83+
84+ writeFileSync ( resolve ( OUT_DIR , "manifest.json" ) , `${ JSON . stringify ( {
85+ schema : "flowmemory.agent_bonds.operator_bundle_manifest.v1" ,
86+ requiredFiles : REQUIRED_FILES ,
87+ optionalGeneratedFiles : OPTIONAL_GENERATED_FILES . map ( ( path ) => ( {
88+ path,
89+ included : ! skippedOptional . includes ( path ) ,
90+ } ) ) ,
91+ } , null , 2 ) } \n`, "utf8" ) ;
92+
6293 writeFileSync ( resolve ( OUT_DIR , "README.txt" ) , [
6394 "FlowMemory Agent Bonds operator bundle" ,
6495 "" ,
@@ -71,7 +102,7 @@ function main() {
71102 "7. hand external reviewer the review packet" ,
72103 ""
73104 ] . join ( "\n" ) , "utf8" ) ;
74- console . log ( JSON . stringify ( { service : "flowmemory-agent-bonds-operator-bundle" , outDir : OUT_DIR , files : copied . length } , null , 2 ) ) ;
105+ console . log ( JSON . stringify ( { service : "flowmemory-agent-bonds-operator-bundle" , outDir : OUT_DIR , files : copied . length , skippedOptional } , null , 2 ) ) ;
75106}
76107
77108main ( ) ;
0 commit comments