Files
ycode/scripts/rea/algorithm-expert-metadata.mjs
T

20 lines
1.9 KiB
JavaScript

/** Current exact known metadata directories via formal REA CLI, never original FS directly. */
import fs from 'node:fs'
import path from 'node:path'
import {spawnSync} from 'node:child_process'
import crypto from 'node:crypto'
const retained=JSON.parse(fs.readFileSync('.tmp/rea-algorithm-locate.json','utf8'))
const results=[]
function cli(command,args){const r=spawnSync(process.execPath,['.tmp/rea-css-runtime/scripts/rea.mjs',command,...args],{encoding:'utf8',maxBuffer:4*1024*1024});if(r.status!==0)throw Error(r.stderr||r.stdout);return JSON.parse(r.stdout)}
for(const old of retained.metadata){
const root='C:/Users/Administrator/.workbuddy/plugins/'+path.posix.dirname(old.path)
try{
const inventory=cli('inspect-selected-directory-text-root',[root]);fs.writeFileSync(`.tmp/rea-algorithm-metadata-inventory-${inventory.evidence_id}.json`,JSON.stringify(inventory))
const evidence=cli('export-selected-directory-text',[root,inventory.normalized_result.root_sha256,JSON.stringify(['plugin.json'])])
const file=evidence.normalized_result.files[0];if(crypto.createHash('sha256').update(file.text).digest('hex')!==file.sha256)throw Error('SHA mismatch')
fs.writeFileSync(`.tmp/rea-algorithm-metadata-${evidence.evidence_id}.json`,JSON.stringify(evidence))
const p=JSON.parse(file.text);results.push({root,evidenceId:evidence.evidence_id,rootSha256:inventory.normalized_result.root_sha256,sha256:file.sha256,oldInventoryShaMatches:file.sha256===old.sha256,name:p.name,profession:p.profession,displayName:p.displayName,agentName:p.agentName,isTarget:/高级算法|小算|algorithm engineer|algorithm-engineer/i.test(JSON.stringify([p.name,p.profession,p.displayName,p.agentName]))})
}catch(error){results.push({root,error:String(error),status:'unknown'})}
}
fs.writeFileSync('.tmp/rea-algorithm-current-metadata.json',JSON.stringify({results},null,2));console.log(JSON.stringify({results},null,2))