#!/usr/bin/env node 'use strict'; // BADA 내장 OpenWork의 Cloud 연결 UI만 제거하는 재적용 가능한 상류 번들 패치. // 번들 갱신 시 앵커가 달라지면 저장 전에 실패한다. 공급자/MCP 데이터·로컬 인증 동작은 변경하지 않는다. const fs = require('node:fs'); const path = require('node:path'); const bundlePath = path.join(__dirname, '../src/openwork/web/assets/app-gBkV9Fau.js'); const indexPath = path.join(__dirname, '../src/openwork/web/index.html'); const cacheVersion = 'r281'; const marker = '/* BADA_LOCAL_CLOUD_UI_REMOVED */'; const patches = [ ['기본 Cloud 로그인 버튼', 'cloudSignin:!0,welcomePage:!0', 'cloudSignin:!1,welcomePage:!0'], ['저장된 셸 설정의 Cloud 로그인 복원 방지', 'return{...KS,...t}}catch{return KS}', 'return{...KS,...t,cloudSignin:!1}}catch{return KS}'], ['데스크톱·모바일 계정 메뉴 렌더 제외', 'function kZt(e){const t=ho()', 'function kZt(e){return null;const t=ho()'], ['Dashboard·Automations·Calendar·Library Cloud 가입 배너', 'function s9(e){return a.jsxs("div",{"data-testid":e.testId', 'function s9(e){return null;return a.jsxs("div",{"data-testid":e.testId'], ['설정 사이드바 Cloud 그룹', 'const HWe=["cloud-account","usage"];', 'const HWe=[];'], ['설정 홈 Cloud 카드', ',{tab:"cloud-account",icon:fu,title:"Cloud",desc:"OpenWork Cloud account and organization."}', ''], ['명령 팔레트 Cloud 로그인', ',{id:"cloud.sign_in",title:"Sign in to OpenWork Cloud",keywords:["login","account","organization","org","den","cloud"],group:ud,action:()=>{e.onClose(),e.onOpenSettings("/settings/cloud-account")}}', ''], ['Cloud 설정 직접 경로 및 과거 경로 우회', 'const[n,s]=t.split("/");switch(n){case"general":', 'const[n,s]=t.split("/");if(["cloud-account","cloud-providers","usage","den","cloud-workers"].includes(n))return{tab:"general",redirectPath:"general"};switch(n){case"general":'], ['AI 공급자 화면의 Cloud 조직 연결 패널', 'onOpenDen:b,onOpenModelConnections:y}){const{activeOrganization:S', 'onOpenDen:b,onOpenModelConnections:y}){return null;const{activeOrganization:S'], ['Library Cloud 계정 CTA 전달 차단', 'onOpenCloudAccount:()=>t(O?Jh(O,"cloud-account"):"/settings/cloud-account"),busy:H', 'onOpenCloudAccount:void 0,busy:H'], ['Library Cloud 가입 배너 및 잠긴 홍보 카드', 'onlyNeedsSignIn:j,signedOut:Fe,onSignUp:e.onOpenCloudAccount', 'onlyNeedsSignIn:j,signedOut:!1,onSignUp:void 0'], ['온보딩 Cloud 모델 가입 CTA', 'a.jsx(hxn,{showOpenWorkModels:u,onOpenWorkModels:', 'a.jsx(hxn,{showOpenWorkModels:!1,onOpenWorkModels:'], ]; try { let source = fs.readFileSync(bundlePath, 'utf8'); let html = fs.readFileSync(indexPath, 'utf8'); const alreadyPatched = source.includes(marker); // 모든 앵커를 메모리에서 검증한 뒤 저장하여 버전 불일치에 따른 부분 패치를 방지한다. for (const [label, before, after] of patches) { const count = source.split(before).length - 1; if (count === 0 && alreadyPatched && (after === '' || source.includes(after))) continue; if (count !== 1) throw new Error(`${label}: 예상 앵커 1개, 실제 ${count}개`); source = source.replace(before, after); } // 상류 해시 파일명은 유지하므로 번들·테마의 URL 버전을 바꿔 기존 Chromium 캐시와 분리한다. for (const asset of ['assets/app-gBkV9Fau.js', 'bada-ocean-theme.css']) { const escaped = asset.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); const anchor = new RegExp(`"\\./${escaped}(?:\\?bada-local-ui=[a-z0-9-]+)?"`, 'g'); const count = [...html.matchAll(anchor)].length; if (count !== 1) throw new Error(`${asset}: HTML 자산 앵커 1개 필요, 실제 ${count}개`); html = html.replace(anchor, `"./${asset}?bada-local-ui=${cacheVersion}"`); } fs.writeFileSync(bundlePath, alreadyPatched ? source : `${source}\n${marker}\n`, 'utf8'); fs.writeFileSync(indexPath, html, 'utf8'); console.log('[openwork-local-ui] Cloud 연결 UI 패치 적용 완료'); } catch (error) { console.error('[openwork-local-ui] 패치 실패:', error.message); process.exitCode = 1; }