@coreframe/scripts 0.2.8 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/coreframe.js +1 -1
- package/package.json +5 -5
package/dist/coreframe.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import*as e from"@alloc/cmd-ts";import{array as t,command as n,extendType as r,flag as i,multioption as a,number as o,oneOf as s,option as c,optional as l,positional as u,rest as d,string as f,subcommands as p}from"@alloc/cmd-ts";import{ProjectPostgresAlreadyRunningError as m,checkDeployMigrations as h,checkSchemaPush as g,collectDeployMigrationFiles as _,createProjectDeployDatabase as v,ensureLocalDb as y,filterPendingMigrations as b,formatDbErrorMessage as x,formatMigrationList as S,formatMigrationScanFailures as C,migrateHeldMigrations as w,migrateLocalDb as T,readAppliedMigrationNames as E,resetLocalDb as ee,runDrizzleKitCommand as te,scanDeployMigrationFiles as D,seedLocalDb as O,setupLocalDb as ne,startProjectPostgres as re,stopProjectPostgres as k}from"@coreframe/db";import{checkFlutterClient as A,ensureFlutterDevAssetDirectories as ie,flutterPlatforms as j,generateFlutterNativeBridge as ae,prepareFlutterClient as M,prepareFlutterDevOutput as oe,productionApiOrigin as N,runFlutterAcceptance as se}from"@coreframe/flutter-tools";import P,{dirname as F,isAbsolute as ce,join as I,posix as le,resolve as L,sep as ue}from"node:path";import R from"nano-spawn";import*as z from"@clack/prompts";import{addAsset as de,buildAssets as fe,checkAssets as pe,printAssetResult as me,publishAssets as he}from"@coreframe/assets";import{assertAssetCredentialProfile as ge,configureAssetCredentials as _e,createB2PrivateObjectStore as ve}from"@coreframe/object-storage";import{access as ye,chmod as be,copyFile as xe,cp as Se,link as Ce,mkdir as B,mkdtemp as we,readFile as V,readdir as Te,realpath as Ee,rename as De,rm as H,stat as Oe,unlink as ke,writeFile as U}from"node:fs/promises";import{homedir as Ae,networkInterfaces as je,tmpdir as Me}from"node:os";import{importProjectDependency as Ne,importProjectModule as Pe,normalizeWorkerEnvironment as Fe,readProjectConfig as Ie,wranglerEnvironmentNames as Le}from"@coreframe/config";import{createHash as Re,randomUUID as W}from"node:crypto";import G from"node:process";import{spawnSync as K}from"node:child_process";import{chmodSync as ze,existsSync as q,lstatSync as Be,mkdirSync as Ve,mkdtempSync as He,readFileSync as J,readlinkSync as Ue,rmSync as We,symlinkSync as Ge,writeFileSync as Ke}from"node:fs";import{parse as qe,stringify as Je}from"yaml";import{accessTokenSigningSecretName as Ye,clearAppliedPendingWorkerSecrets as Xe,deployEnvironments as Ze,discardPendingWorkerSecret as Qe,discoverStagingUrl as $e,inspectWorkerEnvironment as et,materializePrimaryWorkerConfig as tt,materializePrimaryWorkerTypeConfig as nt,parseDeclaredWorkerSecretEnv as rt,parseTauriReleasePlatform as it,prepareAccessTokenSigningSecret as at,prepareTauriRelease as ot,queueWorkerSecret as st,queueWorkerSecrets as ct,readDeclaredWorkerSecrets as lt,readPackageJson as ut,readPendingWorkerSecretSnapshot as dt,reassignStagingHostname as ft,releaseName as pt,resolveDeployConfig as mt,resolveReleaseVersion as ht,resolveTauriReleasePlan as gt,restoreTauriReleaseMetadata as _t,rotateAccessTokenSigningSecret as vt,runAfterWorkerDeploy as yt,runPostDeployChecks as bt,tauriReleasePlatforms as xt,uploadTauriReleaseToB2 as St,validateTauriReleasePlan as Ct,validateWorkerEnvironmentForDeploy as wt,verifyAccessTokenSigningSecret as Tt,writePackageVersion as Et,writeTauriReleaseMetadata as Dt}from"@coreframe/deploy";import{connectDevSupervisor as Ot,createDevStartupTiming as kt,devHttpsCertEnv as At,devHttpsKeyEnv as jt,isManagedDevCheckout as Mt,isPrimaryCheckout as Nt,prepareDevHttps as Pt,stopDevSupervisor as Ft}from"@coreframe/dev";import{inspect as It,parseEnv as Lt}from"node:util";import{once as Rt}from"node:events";import{finished as zt}from"node:stream/promises";import{codexTaskEnv as Bt}from"@coreframe/dev-contracts/codex-task";import{managedDevEnv as Vt}from"@coreframe/dev-contracts/managed-dev";import{createPrefixStream as Y,supervise as Ht}from"procband";import{createConnection as Ut,createServer as Wt}from"node:net";import{setTimeout as Gt}from"node:timers/promises";import{determineAgent as Kt}from"@vercel/detect-agent";import{runPreview as qt}from"@coreframe/preview";const Jt=[`web`,...j];function Yt(e=`web`,{apiOrigin:t,cwd:n=process.cwd(),simulator:r=!1}={}){if(en(e,r),e===`web`)return[nn(`pnpm`,[`build`],n,{COREFRAME_PLATFORM:`web`})];let i=N(t);return[{kind:`prepare`,platform:e},nn(`flutter`,Xt(e,i,{simulator:r}),L(n,`src-flutter`),{COREFRAME_API_ORIGIN:i})]}function Xt(e,t,{noCodesign:n=e===`macos`,simulator:r=!1}={}){en(e,r);let i=N(t);return[`build`,e===`android`?`apk`:e,`--release`,...r?[`--simulator`]:[],...n?[`--no-codesign`]:[],`--dart-define=COREFRAME_API_ORIGIN=${i}`]}function Zt(e){let t=L(e,`src-flutter/build/app/outputs/flutter-apk/app-release.apk`),n=JSON.stringify(t);return[`Android release build succeeded.`,``,`Install it on a connected Android device:`,` 1. Enable Developer options and USB debugging, connect the device, and accept the authorization prompt.`,` 2. Verify the device is visible:`,` adb devices`,` 3. Install or update the APK:`,` adb install -r ${n}`,``,`If multiple devices are connected, use:`,` adb -s <device-id> install -r ${n}`].join(`
|
|
3
3
|
`)}function Qt(e,{simulator:t=!1}={}){let n=L(e,`src-flutter/build/ios/${t?`iphonesimulator`:`iphoneos`}/Runner.app`),r=JSON.stringify(n);return t?[`iOS Simulator release build succeeded.`,``,`Install it on a booted iOS Simulator:`,` 1. Verify available simulators:`,` xcrun simctl list devices`,` 2. Install the app:`,` xcrun simctl install booted ${r}`,``,"If multiple simulators are available, replace `booted` with the simulator UDID."].join(`
|
|
4
4
|
`):[`iOS release build succeeded.`,``,`Install it on a connected iOS device:`,` 1. Enable Developer Mode, connect the device, and trust this Mac if prompted.`,` 2. Verify the device is visible:`,` xcrun devicectl list devices`,` 3. Install the signed app:`,` xcrun devicectl device install app --device <device-id> ${r}`,``,`If multiple devices are connected, use the device UDID shown by devicectl.`].join(`
|
|
5
|
-
`)}async function $t({apiOrigin:e,cwd:t=process.cwd(),environment:n=process.env,platform:r=`web`,simulator:i=!1,prepareClient:a=M,runCommand:o=tn}={}){en(r,i);let s={...n};delete s.COREFRAME_PLATFORM,delete s.TAURI_ENV_PLATFORM;let c=r===`web`?void 0:N(e??n.COREFRAME_API_ORIGIN);for(let e of Yt(r,{apiOrigin:c,cwd:t,simulator:i})){if(e.kind===`prepare`){if(!c)throw Error(`A production API origin is required for the Flutter ${e.platform} build.`);await a({apiOrigin:c,cwd:t,environment:s,platform:e.platform});continue}await o(e.command,e.args,{cwd:e.cwd,env:{...s,...e.environment}})}r===`android`?console.log(Zt(t)):r===`ios`&&console.log(Qt(t,{simulator:i}))}function en(e,t){if(t&&e!==`ios`)throw Error(`The --simulator flag is only supported for the iOS build target.`)}async function tn(e,t,{cwd:n,env:r}){await R(e,t,{cwd:n,env:r,stdio:`inherit`})}function nn(e,t,n,r){return{kind:`command`,command:e,args:t,cwd:n,...r===void 0?{}:{environment:r}}}const rn=r(f,{displayName:`origin`,description:`Exact production HTTPS API origin embedded in a packaged Flutter client.`,async from(e){return N(e)}}),an=n({name:`build`,description:`Build the web client or a release Flutter app. Tauri is not built.`,args:{platform:u({type:l(s(Jt)),displayName:`platform`,description:`Build target: web, iOS, Android, or macOS. Defaults to web.`}),apiOrigin:c({long:`api-origin`,type:l(rn),description:`Exact production HTTPS API origin for a Flutter build. Defaults to COREFRAME_API_ORIGIN.`}),simulator:i({long:`simulator`,description:`Build iOS for the simulator instead of a physical device.`,defaultValue:()=>!1})},handler:({apiOrigin:e,platform:t,simulator:n})=>$t({apiOrigin:e,platform:t,simulator:n})}),on=/^[a-f0-9]{64}$/,sn=/^[a-f0-9]{40}$/,cn=/^[A-Za-z0-9][A-Za-z0-9._-]*$/;function ln(e){if(!on.test(e))throw Error(`Invalid SHA-256 digest "${e}".`);return e}function un(e){if(!sn.test(e))throw Error(`Invalid full Git revision "${e}".`);return e}function dn(e,t){if(!cn.test(e))throw Error(`${t} must contain only letters, numbers, dots, underscores, or hyphens.`);return e}function fn(e){return`projects/${dn(e,`Project ID`)}/i18n/v1`}function pn(e,t){return ln(t),`${fn(e)}/objects/sha256/${t.slice(0,2)}/${t}`}function mn(e,t){return un(t),`${fn(e)}/commits/${t}.json`}function hn(e,t){return gn(t),`${fn(e)}/releases/${encodeURIComponent(t)}.json`}function gn(e){if(!e.startsWith(`v`)||e.length<2||e.length>128||/\s/.test(e)||e.includes(`..`))throw Error(`Release tag "${e}" must be a valid v-prefixed tag.`);return e}function X(e,t){if(!t||t.startsWith(`/`)||t.includes(`\0`))throw Error(`Unsafe i18n artifact path "${t}".`);let n=L(e),r=L(n,t);if(r!==n&&!r.startsWith(`${n}${ue}`))throw Error(`Unsafe i18n artifact path "${t}".`);return r}function Z(e,t,n){return`${e.directory}/${t}/${n}.json`}function _n(e,t,n){return`${e.directory}/${t}/${n}.mjs`}async function vn(e){await R(`pnpm`,[`exec`,`lingui`,`extract`],{cwd:e,stdio:`inherit`})}async function yn({config:e,cwd:t,strict:n,temporaryDirectory:r}){let i=[];try{for(let n of e.locales)for(let a of e.catalogs){let o=X(t,Z(e,n,a)),s=await wn(o),c=Object.fromEntries(Object.entries(s).filter(([,e])=>!e.obsolete)),l=I(r,`${n}-${a}.json`);await B(F(l),{recursive:!0}),await xe(o,l),i.push({path:o,backup:l}),await Tn(o,c)}await R(`pnpm`,[`exec`,`lingui`,`compile`,...n?[`--strict`]:[]],{cwd:t,stdio:`inherit`})}finally{try{for(let{path:e,backup:t}of i)await xe(t,e)}finally{for(let n of e.locales)for(let r of e.catalogs)await H(X(t,_n(e,n,r)),{force:!0})}}}async function bn({config:e,cwd:t}){let n=[];for(let r of e.locales)if(r!==e.sourceLocale)for(let i of e.catalogs){let a=await wn(X(t,Z(e,r,i)));for(let[e,t]of Object.entries(a)){if(t.obsolete||t.translation?.trim())continue;let a=t.message;if(typeof a!=`string`||!a)throw Error(`Missing source message metadata for ${r}:${e}.`);n.push({catalog:i,comments:t.comments?.filter(e=>typeof e==`string`)??[],context:t.context,id:e,locale:r,message:a,origins:t.origin?.map(([e,t])=>t?`${e}:${t}`:e)??[],placeholders:Object.keys(t.placeholders??{}).sort()})}}return n.sort((e,t)=>An(e).localeCompare(An(t)))}async function xn({config:e,cwd:t,messages:n,env:r=process.env}){if(n.length===0)return{translations:[],version:1};if(!e.generator)throw Error(`I18n preparation found ${n.length} missing translations, but no generator is configured.`);let i={messages:n,sourceLocale:e.sourceLocale,version:1};return En(await Dn({args:e.generator.args??[],command:e.generator.command,cwd:t,env:r,input:JSON.stringify(i)}))}async function Sn({config:e,cwd:t,missing:n,response:r}){let i=new Map(n.map(e=>[An(e),e])),a=new Map;for(let e of r.translations){let t=An(e);if(!i.has(t))throw Error(`Translation generator returned unexpected entry ${e.locale}:${e.catalog}:${e.id}.`);if(a.has(t))throw Error(`Translation generator returned duplicate entry ${e.locale}:${e.catalog}:${e.id}.`);if(!e.translation.trim())throw Error(`Translation generator returned an empty entry ${e.locale}:${e.id}.`);a.set(t,e.translation)}let o=[...i.keys()].filter(e=>!a.has(e));if(o.length>0)throw Error(`Translation generator omitted ${o.length} required entries.`);let s=await Ne(`@lingui/message-utils/compileMessage`,t);for(let e of n){let t=a.get(An(e));On({compileMessage:s,id:e.id,locale:e.locale,source:e.message,translation:t})}for(let n of e.locales)if(n!==e.sourceLocale)for(let r of e.catalogs){let i=X(t,Z(e,n,r)),o=await wn(i),s=!1;for(let[e,t]of Object.entries(o)){let i=a.get(An({catalog:r,id:e,locale:n}));if(i!==void 0){if(t.translation?.trim())throw Error(`Refusing to overwrite preserved translation ${n}:${e}.`);t.translation=i,s=!0}}s&&await Tn(i,o)}}async function Cn({config:e,cwd:t}){let n=await bn({config:e,cwd:t});if(n.length>0)throw Error(`I18n catalogs remain incomplete: ${n.length} translations are missing.`);let r=await Ne(`@lingui/message-utils/compileMessage`,t);for(let n of e.locales)if(n!==e.sourceLocale)for(let i of e.catalogs){let a=await wn(X(t,Z(e,n,i)));for(let[e,t]of Object.entries(a))if(!t.obsolete){if(typeof t.message!=`string`||typeof t.translation!=`string`)throw Error(`Incomplete source metadata for active translation ${n}:${e}.`);On({compileMessage:r,id:e,locale:n,source:t.message,translation:t.translation})}}}async function wn(e){let t=JSON.parse(await V(e,`utf8`));if(!t||typeof t!=`object`||Array.isArray(t))throw Error(`Lingui rich JSON catalog must be an object: ${e}.`);for(let[n,r]of Object.entries(t)){if(!r||typeof r!=`object`||Array.isArray(r))throw Error(`Invalid Lingui rich JSON message ${n} in ${e}.`);let t=r;if(t.translation!==void 0&&typeof t.translation!=`string`)throw Error(`Invalid translation value for ${n} in ${e}.`);if(t.message!==void 0&&t.message!==null&&typeof t.message!=`string`)throw Error(`Invalid source message value for ${n} in ${e}.`);if(t.context!==void 0&&typeof t.context!=`string`)throw Error(`Invalid context value for ${n} in ${e}.`);if(t.obsolete!==void 0&&typeof t.obsolete!=`boolean`)throw Error(`Invalid obsolete marker for ${n} in ${e}.`);if(t.comments!==void 0&&(!Array.isArray(t.comments)||t.comments.some(e=>typeof e!=`string`)))throw Error(`Invalid comments for ${n} in ${e}.`);if(t.origin!==void 0&&(!Array.isArray(t.origin)||t.origin.some(e=>!Array.isArray(e)||typeof e[0]!=`string`||e[1]!==void 0&&typeof e[1]!=`number`)))throw Error(`Invalid origins for ${n} in ${e}.`);if(t.placeholders!==void 0&&(!t.placeholders||typeof t.placeholders!=`object`||Array.isArray(t.placeholders)))throw Error(`Invalid placeholders for ${n} in ${e}.`)}return t}async function Tn(e,t){await B(F(e),{recursive:!0});let n=`${e}.${process.pid}.tmp`;await U(n,`${JSON.stringify(t,null,2)}\n`),await De(n,e)}function En(e){let t;try{t=JSON.parse(e)}catch{throw Error(`Translation generator returned invalid JSON.`)}if(!t||typeof t!=`object`||t.version!==1||!Array.isArray(t.translations))throw Error(`Translation generator returned an invalid response envelope.`);for(let e of t.translations)if(!e||typeof e!=`object`||typeof e.id!=`string`||typeof e.catalog!=`string`||typeof e.locale!=`string`||typeof e.translation!=`string`)throw Error(`Translation generator returned an invalid translation entry.`);return t}function Dn({args:e,command:t,cwd:n,env:r,input:i}){return R(t,e,{cwd:n,env:r,stdio:[{string:i},`pipe`,`ignore`]}).then(({stdout:e})=>{if(Buffer.byteLength(e)>10*1024*1024)throw Error(`Translation generator output exceeded 10 MiB.`);return e}).catch(()=>{throw Error(`Translation generator exited unsuccessfully.`)})}function On({compileMessage:e,id:t,locale:n,source:r,translation:i}){let a,o;try{a=e.compileMessageOrThrow(r),o=e.compileMessageOrThrow(i)}catch{throw Error(`Translation ${n}:${t} is not valid ICU MessageFormat.`)}let s=kn(a),c=kn(o);if(s.length!==c.length||s.some((e,t)=>e!==c[t]))throw Error(`Translation ${n}:${t} does not preserve source ICU placeholders.`)}function kn(e){let t=[];function n(e){for(let r of e){if(typeof r==`string`)continue;let[e,i=`argument`,a]=r;if(t.push(`${e}:${i}`),a&&typeof a==`object`&&!Array.isArray(a))for(let e of Object.values(a))Array.isArray(e)&&n(e)}}return n(e),t.sort()}function An(e){return`${e.locale}\0${e.catalog}\0${e.id}`}function jn(e){return Re(`sha256`).update(e).digest(`hex`)}async function Mn(e){return jn(await V(e))}function Nn(e){return Buffer.from(`${JSON.stringify(e,null,2)}\n`)}async function Pn({bucket:e,digest:t,projectId:n,source:r,store:i}){if(ln(t),await Mn(r)!==t)throw Error(`I18n object source does not match declared SHA-256 digest ${t}.`);let a=pn(n,t);await i.has(e,a)||await i.upload(e,a,r,`application/octet-stream`);let o=`${r}.${process.pid}.${W()}.verify`;try{if(await i.download(e,a,o),await Mn(o)!==t)throw Error(`Existing immutable i18n object ${a} failed integrity verification.`)}finally{await H(o,{force:!0})}}async function Fn({bucket:e,key:t,reference:n,store:r,temporaryDirectory:i}){let a=Nn(n),o=I(i,`reference-${W()}.json`);if(await r.has(e,t))try{if(await r.download(e,t,o),!(await V(o)).equals(a))throw Error(`Immutable i18n reference ${t} already resolves to different snapshot data.`);return}finally{await H(o,{force:!0})}await U(o,a,{flag:`wx`});try{await r.upload(e,t,o,`application/json`)}finally{await H(o,{force:!0})}let s=I(i,`reference-${W()}.verify.json`);try{if(await r.download(e,t,s),!(await V(s)).equals(a))throw Error(`Uploaded immutable i18n reference ${t} failed verification.`)}finally{await H(s,{force:!0})}}async function In({bucket:e,manifest:t,projectId:n,store:r,temporaryDirectory:i}){let a=Nn(t),o=jn(a),s=I(i,`manifest-${o}.json`);await U(s,a,{flag:`wx`});try{await Pn({bucket:e,digest:o,projectId:n,source:s,store:r})}finally{await H(s,{force:!0})}return o}async function Ln({bucket:e,key:t,store:n,temporaryDirectory:r}){if(!await n.has(e,t))return;let i=I(r,`reference-${W()}.json`);try{await n.download(e,t,i);let r=JSON.parse(await V(i,`utf8`));if(r.version!==1||typeof r.revision!=`string`||typeof r.snapshot!=`string`)throw Error(`Invalid i18n reference at ${t}.`);return un(r.revision),ln(r.snapshot),r}finally{await H(i,{force:!0})}}async function Rn({bucket:e,projectId:t,revision:n,store:r,temporaryDirectory:i}){let a=await Ln({bucket:e,key:mn(t,n),store:r,temporaryDirectory:i});if(a&&a.revision!==n)throw Error(`I18n commit reference does not match requested revision ${n}.`);return a}async function zn({bucket:e,projectId:t,reference:n,store:r,tag:i,temporaryDirectory:a}){await Fn({bucket:e,key:mn(t,n.revision),reference:n,store:r,temporaryDirectory:a}),i&&await Fn({bucket:e,key:hn(t,i),reference:n,store:r,temporaryDirectory:a})}async function Bn({bucket:e,cacheRoot:t,digest:n,projectId:r,store:i,target:a}){ln(n);let o=I(L(t),`v1`,`sha256`,n.slice(0,2),n);if(await Hn(o,n)===!1){await B(F(o),{recursive:!0});let t=`${o}.${process.pid}.${W()}.tmp`;try{if(await i.download(e,pn(r,n),t),await Mn(t)!==n)throw Error(`Downloaded i18n object failed SHA-256 verification: ${n}.`);await H(o,{force:!0}),await De(t,o)}finally{await H(t,{force:!0})}}await B(F(a),{recursive:!0});let s=`${a}.${process.pid}.${W()}.tmp`;try{if(await xe(o,s),await Mn(s)!==n)throw Error(`Cached i18n object failed SHA-256 verification: ${n}.`);await H(a,{force:!0}),await De(s,a)}finally{await H(s,{force:!0})}}async function Vn({bucket:e,cacheRoot:t,digest:n,projectId:r,store:i,temporaryDirectory:a}){let o=I(a,`manifest-${n}.json`);await Bn({bucket:e,cacheRoot:t,digest:n,projectId:r,store:i,target:o});let s=JSON.parse(await V(o,`utf8`));if(s.version!==1||s.projectId!==r||typeof s.revision!=`string`||!Array.isArray(s.files)||!Array.isArray(s.catalogs)||s.catalogs.some(e=>typeof e!=`string`)||!Array.isArray(s.locales)||s.locales.some(e=>typeof e!=`string`)||typeof s.sourceLocale!=`string`||typeof s.generator!=`string`||typeof s.linguiVersion!=`string`)throw Error(`Invalid i18n snapshot manifest ${n}.`);un(s.revision),s.baseline!==void 0&&ln(s.baseline);for(let e of s.files){if(!e||typeof e!=`object`||typeof e.path!=`string`||typeof e.digest!=`string`||typeof e.size!=`number`)throw Error(`Invalid file entry in i18n snapshot manifest ${n}.`);ln(e.digest)}return s}async function Hn(e,t){try{return(await Oe(e)).isFile()&&await Mn(e)===t}catch{return!1}}async function Un({cwd:e=process.cwd(),env:t=process.env}={}){if((await Ie({cwd:e})).i18n){if(t.COREFRAME_I18N_RELEASE_REVISION){await Kn({cwd:e,env:t,revision:t.COREFRAME_I18N_RELEASE_REVISION});return}await vn(e)}}async function Wn({cwd:e=process.cwd(),projectConfig:t}={}){let n=t??await Ie({cwd:e});if(!n.i18n)return;let r=qn(n.i18n),i=X(e,r.directory);try{if(!(await Oe(i)).isDirectory())throw Error(`I18n catalog path is not a directory: ${i}.`)}catch(t){if(t.code!==`ENOENT`)throw t;await vn(e);return}for(let t of r.locales)for(let n of r.catalogs)try{if(!(await Oe(X(e,Z(r,t,n)))).isFile())throw Error(`I18n catalog path is not a file: ${t}/${n}.json.`)}catch(t){if(t.code!==`ENOENT`)throw t;await vn(e);return}}async function Gn({cwd:e=process.cwd(),env:t=process.env,store:n,tag:r}){gn(r);let i=await Jn({cwd:e,env:t,store:n});await nr(e);let a=await tr(e);await rr(e,r,a);let o=await we(I(Me(),`coreframe-i18n-prepare-`));try{let n=await Rn({bucket:i.assets.sourceBucket,projectId:i.assets.projectId,revision:a,store:i.store,temporaryDirectory:o});if(n){let e=await Vn({bucket:i.assets.sourceBucket,cacheRoot:i.cacheRoot,digest:n.snapshot,projectId:i.assets.projectId,store:i.store,temporaryDirectory:o});return er(i,e,a),await Xn(i,e),await zn({bucket:i.assets.sourceBucket,projectId:i.assets.projectId,reference:n,store:i.store,tag:r,temporaryDirectory:o}),{reused:!0,snapshot:n.snapshot}}return await $n(i,o,async()=>{let n=await Yn(i,a,o);n||await Qn(i),await vn(e);let s=await bn({config:i.config,cwd:e}),c=await xn({config:i.config,cwd:e,env:t,messages:s});await Sn({config:i.config,cwd:e,missing:s,response:c}),await Cn({config:i.config,cwd:e}),await yn({config:i.config,cwd:e,strict:!0,temporaryDirectory:o});let l=await Zn(i),u={...n?{baseline:n}:{},catalogs:i.config.catalogs,files:l,generator:s.length>0?i.config.generator?.id??`unconfigured`:`none`,linguiVersion:await ir(e),locales:i.config.locales,projectId:i.assets.projectId,revision:a,sourceLocale:i.config.sourceLocale,version:1},d=await In({bucket:i.assets.sourceBucket,manifest:u,projectId:i.assets.projectId,store:i.store,temporaryDirectory:o});return await zn({bucket:i.assets.sourceBucket,projectId:i.assets.projectId,reference:{revision:a,snapshot:d,version:1},store:i.store,tag:r,temporaryDirectory:o}),{reused:!1,snapshot:d}})}finally{await H(o,{force:!0,recursive:!0})}}async function Kn({cwd:e=process.cwd(),env:t=process.env,revision:n,store:r}={}){let i=await Ie({cwd:e});if(!i.i18n)return;let a=await Jn({cwd:e,env:t,store:r,projectConfig:i}),o=un(n??await tr(e)),s=await we(I(Me(),`coreframe-i18n-materialize-`));try{let e=await Rn({bucket:a.assets.sourceBucket,projectId:a.assets.projectId,revision:o,store:a.store,temporaryDirectory:s});if(!e)throw Error(`No prepared i18n snapshot exists for commit ${o}. Push a v* tag for this commit and wait for the translation gate.`);let t=await Vn({bucket:a.assets.sourceBucket,cacheRoot:a.cacheRoot,digest:e.snapshot,projectId:a.assets.projectId,store:a.store,temporaryDirectory:s});return er(a,t,o),await Xn(a,t),{revision:o,snapshot:e.snapshot}}finally{await H(s,{force:!0,recursive:!0})}}function qn(e){let t=dn(e.sourceLocale,`Source locale`),n=[...new Set(e.locales.map(e=>dn(e,`Locale`)))],r=[...new Set(e.catalogs.map(e=>dn(e,`Catalog`)))];if(n.length===0||!n.includes(t))throw Error(`I18n locales must include the source locale.`);if(r.length===0)throw Error(`I18n configuration requires at least one catalog.`);if(e.generator&&(!e.generator.command.trim()||!e.generator.id.trim()))throw Error(`I18n generator command and ID must be non-empty.`);return{catalogs:r,directory:e.directory??`locales`,generator:e.generator,locales:n,sourceLocale:t}}async function Jn({cwd:e=process.cwd(),env:t=process.env,projectConfig:n,store:r}){let i=n??await Ie({cwd:e});if(!i.i18n)throw Error(`Missing i18n configuration in coreframe.config.ts.`);if(!i.assets)throw Error(`I18n snapshots require the existing private build bucket configured under assets.`);let a=i.assets;return{assets:a,cacheRoot:L(e,`.coreframe`,`i18n`,`cache`),config:qn(i.i18n),cwd:L(e),env:t,store:r??ve({config:a,env:t})}}async function Yn(e,t,n){let{stdout:r}=await R(`git`,[`rev-list`,`--first-parent`,`--skip=1`,t],{cwd:e.cwd,stdin:`ignore`});for(let t of r.split(/\r?\n/).filter(Boolean)){let r=await Rn({bucket:e.assets.sourceBucket,projectId:e.assets.projectId,revision:un(t),store:e.store,temporaryDirectory:n});if(!r)continue;let i=await Vn({bucket:e.assets.sourceBucket,cacheRoot:e.cacheRoot,digest:r.snapshot,projectId:e.assets.projectId,store:e.store,temporaryDirectory:n});return er(e,i,t),await Xn(e,i),r.snapshot}}async function Xn(e,t){for(let n of t.files)if(await Bn({bucket:e.assets.sourceBucket,cacheRoot:e.cacheRoot,digest:n.digest,projectId:e.assets.projectId,store:e.store,target:X(e.cwd,n.path)}),(await Oe(X(e.cwd,n.path))).size!==n.size)throw Error(`Materialized i18n artifact size does not match manifest: ${n.path}.`)}async function Zn(e){let t=[];for(let n of e.config.locales)for(let r of e.config.catalogs){let i=Z(e.config,n,r),a=X(e.cwd,i),o=await Mn(a);await Pn({bucket:e.assets.sourceBucket,digest:o,projectId:e.assets.projectId,source:a,store:e.store}),t.push({digest:o,path:i,size:(await Oe(a)).size})}return t.sort((e,t)=>e.path.localeCompare(t.path))}async function Qn(e){let{stdout:t}=await R(`git`,[`rev-parse`,`--show-prefix`],{cwd:e.cwd,stdin:`ignore`}),n=t.trim(),{stdout:r}=await R(`git`,[`log`,`-1`,`--format=%H`,`--diff-filter=AM`,`--`,`:(top)${`${n}${e.config.directory}/${e.config.sourceLocale}/${e.config.catalogs[0]}.po`}`],{cwd:e.cwd,stdin:`ignore`}),i=r.trim();if(!i)return!1;let a=(await Ne(`@lingui/format-po`,e.cwd)).formatter({lineNumbers:!1}),o=!1;for(let t of e.config.locales)for(let r of e.config.catalogs){let s=`${n}${`${e.config.directory}/${t}/${r}.po`}`;try{let{stdout:n}=await R(`git`,[`show`,`${i}:${s}`],{cwd:e.cwd,stdin:`ignore`});await Tn(X(e.cwd,Z(e.config,t,r)),a.parse(n)),o=!0}catch{}}return o}async function $n(e,t,n){let r=[];for(let n of e.config.locales)for(let i of e.config.catalogs){let a=Z(e.config,n,i),o=X(e.cwd,a);try{await ye(o)}catch{continue}let s=I(t,`previous-catalogs`,a);await B(F(s),{recursive:!0}),await De(o,s),r.push({backup:s,path:o})}try{let e=await n();return await H(I(t,`previous-catalogs`),{force:!0,recursive:!0}),e}catch(t){for(let t of e.config.locales)for(let n of e.config.catalogs)await H(X(e.cwd,Z(e.config,t,n)),{force:!0});for(let{backup:e,path:t}of r)await B(F(t),{recursive:!0}),await De(e,t);throw t}}function er(e,t,n){if(t.revision!==n||t.projectId!==e.assets.projectId||t.sourceLocale!==e.config.sourceLocale||JSON.stringify(t.locales)!==JSON.stringify(e.config.locales)||JSON.stringify(t.catalogs)!==JSON.stringify(e.config.catalogs))throw Error(`I18n snapshot does not match commit or project configuration.`);let r=e.config.locales.flatMap(t=>e.config.catalogs.map(n=>Z(e.config,t,n))),i=t.files.map(e=>e.path);if(new Set(i).size!==i.length||JSON.stringify(i.sort())!==JSON.stringify(r.sort()))throw Error(`I18n snapshot has an incomplete or unexpected artifact set.`)}async function tr(e){let{stdout:t}=await R(`git`,[`rev-parse`,`HEAD`],{cwd:e,stdin:`ignore`});return un(t.trim())}async function nr(e){let{stdout:t}=await R(`git`,[`status`,`--porcelain`],{cwd:e,stdin:`ignore`});if(t.trim())throw Error(`Tagged i18n preparation requires a clean Git tree.`)}async function rr(e,t,n){let{stdout:r}=await R(`git`,[`rev-parse`,`${t}^{commit}`],{cwd:e,stdin:`ignore`});if(r.trim()!==n)throw Error(`Release tag ${t} does not point to checked-out commit ${n}.`)}async function ir(e){let{stdout:t}=await R(`pnpm`,[`exec`,`lingui`,`--version`],{cwd:e,stdin:`ignore`});return t.trim()}const ar=[`Use a B2 Multi-Bucket Application Key restricted to the configured private build-object and public generated-assets buckets.`,`Required capabilities: listAllBucketNames, readFiles, and writeFiles.`,`Deletion, bucket-management, and key-management capabilities are not needed.`].join(` `),or=r(f,{displayName:`widths`,description:`Comma-separated responsive variant widths.`,async from(e){let t=e.split(`,`).map(e=>Number(e));if(t.length===0||t.some(e=>!Number.isInteger(e)||e<=0)||t.some((e,n)=>n>0&&e<=t[n-1]))throw Error(`Widths must be positive, unique, strictly ascending integers.`);return t}}),sr=r(f,{displayName:`profile`,async from(e){return ge(e)}}),cr=r(f,{displayName:`pack`,description:`Asset pack name, such as training-videos.`,async from(e){if(!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(e))throw Error(`Asset pack names must use lowercase hyphen-separated segments.`);return e}}),lr=r(f,{displayName:`origin`,description:`Exact production HTTPS API origin embedded in the packaged Flutter client.`,async from(e){return N(e)}}),ur=p({name:`assets`,cmds:{configure:n({name:`configure`,description:`Store a Backblaze B2 private build-object key in the operating system credential store. ${ar}`,args:{profile:u({type:sr,displayName:`profile`,description:`Credential profile named by coreframe.config.ts.`})},handler:async({profile:e})=>{z.note(ar,`Required B2 key access`);let t=await z.text({message:`Backblaze B2 application key ID`,validate:e=>e?.trim()?void 0:`The application key ID is required.`});if(z.isCancel(t))throw Error(`Asset credential configuration was cancelled.`);let n=await z.password({message:`Backblaze B2 application key`,validate:e=>e?void 0:`The application key is required.`});if(z.isCancel(n))throw Error(`Asset credential configuration was cancelled.`);await _e({applicationKey:n,applicationKeyId:t.trim(),profile:e}),console.log(`Stored Coreframe asset credential profile "${e}".`)}}),add:n({name:`add`,args:{file:u({type:f,displayName:`file`,description:`Source raster image, SVG, MP3, MP4, or Lottie JSON to add to the asset library.`}),id:c({long:`id`,type:f,description:`Logical asset ID, such as blog/my-post/hero.`}),alt:c({long:`alt`,type:l(f),description:`Required alt text for raster image and SVG assets.`}),pack:c({long:`pack`,type:l(cr),description:`Place the asset in a named, lazily loaded pack.`}),variantWidths:c({long:`widths`,type:l(or),description:`Generate exactly these raster-image widths instead of the default ladder.`}),json:i({long:`json`,description:`Print machine-readable JSON.`,defaultValue:()=>!1})},handler:async({alt:e,file:t,id:n,json:r,pack:i,variantWidths:a})=>me(await de({alt:e,file:t,id:n,pack:i,variantWidths:a}),r)}),build:n({name:`build`,args:{id:c({long:`id`,type:l(f),description:`Build only one logical asset ID.`}),pack:c({long:`pack`,type:l(cr),description:`Build only one named asset pack.`}),json:i({long:`json`,description:`Print machine-readable JSON.`,defaultValue:()=>!1})},handler:async({id:e,json:t,pack:n})=>me(await fe({id:e,pack:n}),t)}),check:n({name:`check`,args:{fix:i({long:`fix`,description:`Migrate asset state and build missing generated output when possible.`,defaultValue:()=>!1}),pack:c({long:`pack`,type:l(cr),description:`Check only one named asset pack.`}),json:i({long:`json`,description:`Print machine-readable JSON.`,defaultValue:()=>!1})},handler:async({fix:e,json:t,pack:n})=>{let r=await pe({fix:e,pack:n});me(r,t),r.ok||(process.exitCode=1)}}),publish:n({name:`publish`,args:{pack:c({long:`pack`,type:l(cr),description:`Publish only one named asset pack.`}),json:i({long:`json`,description:`Print machine-readable JSON.`,defaultValue:()=>!1})},handler:async({json:e,pack:t})=>{let n=await he({pack:t});me(n,e),n.ok||(process.exitCode=1)}}),status:n({name:`status`,args:{pack:c({long:`pack`,type:l(cr),description:`Report status for only one named asset pack.`}),json:i({long:`json`,description:`Print machine-readable JSON.`,defaultValue:()=>!1})},handler:async({json:e,pack:t})=>{let n=await pe({pack:t});me(n,e),n.ok||(process.exitCode=1)}})}}),dr=p({name:`flutter`,cmds:{acceptance:n({name:`acceptance`,description:`Run the complete packaged Flutter conformance gate on macOS.`,args:{apiOrigin:c({long:`api-origin`,env:`COREFRAME_API_ORIGIN`,type:lr,description:`Defaults to COREFRAME_API_ORIGIN.`})},handler:({apiOrigin:e})=>se({environment:{...process.env,COREFRAME_API_ORIGIN:e}})}),codegen:n({name:`codegen`,description:`Generate Flutter bridge contracts and Panda-backed Mix theme tokens.`,args:{check:i({long:`check`,description:`Fail when generated Flutter artifacts are missing or stale.`,defaultValue:()=>!1})},handler:({check:e})=>ae({check:e})}),prepare:n({name:`prepare`,description:`Build and package the React client for one Flutter platform.`,args:{platform:u({type:s(j),displayName:`platform`,description:`Flutter platform whose packaged client should be prepared.`}),apiOrigin:c({long:`api-origin`,env:`COREFRAME_API_ORIGIN`,type:lr,description:`Defaults to COREFRAME_API_ORIGIN.`})},handler:({apiOrigin:e,platform:t})=>M({apiOrigin:e,platform:t})}),check:n({name:`check`,description:`Reject missing, stale, modified, or incorrectly targeted Flutter assets.`,args:{platform:u({type:s(j),displayName:`platform`,description:`Flutter platform whose packaged client should be checked.`}),apiOrigin:c({long:`api-origin`,env:`COREFRAME_API_ORIGIN`,type:lr,description:`Defaults to COREFRAME_API_ORIGIN.`})},handler:({apiOrigin:e,platform:t})=>A({apiOrigin:e,platform:t})})}}),fr=p({name:`i18n`,cmds:{build:n({name:`build`,description:`Extract source messages or materialize an exact release catalog snapshot.`,args:{},handler:async()=>{await Un()}}),materialize:n({name:`materialize`,description:`Materialize the immutable i18n snapshot for an exact commit.`,args:{revision:c({long:`revision`,type:l(f),description:`Full commit SHA. Defaults to the checked-out commit.`})},handler:async({revision:e})=>{let t=await Kn({revision:e});t&&console.log(`Materialized i18n snapshot ${t.snapshot}.`)}}),prepare:n({name:`prepare`,description:`Fill missing translations, strictly compile, and publish an immutable tagged snapshot.`,args:{tag:c({long:`tag`,type:f,description:`Pushed v* release tag that points to the checked-out commit.`})},handler:async({tag:e})=>{let t=await Gn({tag:e});console.log(`${t.reused?`Reused`:`Published`} i18n snapshot ${t.snapshot}.`)}})}}),pr=G.platform===`win32`?`react-router.cmd`:`react-router`,mr=G.platform===`win32`?`panda.cmd`:`panda`;async function hr(e=G.cwd()){await vr(e),await _r(e,[`typegen`])}async function gr(e=G.cwd(),t=G.env,n){if((t.COREFRAME_PLATFORM??t.TAURI_ENV_PLATFORM??`web`)!==`web`)return;let r=P.resolve(e,`.coreframe/dashboard-build`),i=P.join(r,`client`),a=P.resolve(e,`dist/client/__dashboard`);await H(r,{force:!0,recursive:!0}),await yr(e,mr,[`build`],t),await _r(e,[`build`,...n?[`--mode`,n]:[]],t),await H(a,{force:!0,recursive:!0}),await B(P.dirname(a),{recursive:!0}),await Se(i,a,{recursive:!0})}async function _r(e,t,n=G.env){await yr(e,pr,t,n)}async function vr(e){await H(P.resolve(e,`dashboard/.react-router`),{force:!0,recursive:!0})}async function yr(e,t,n,r=G.env){await R(t,n,{cwd:P.resolve(e,`dashboard`),env:{...r,PATH:P.resolve(e,`node_modules/.bin`)+P.delimiter+(r.PATH??r.Path??``)},stdio:`inherit`})}const br=p({name:`dashboard`,cmds:{build:n({name:`build`,args:{mode:c({long:`mode`,type:l(f),description:`Vite environment mode used for the dashboard build.`})},handler:({mode:e})=>gr(void 0,void 0,e)}),typegen:n({name:`typegen`,args:{},handler:()=>hr()})}}),xr=/^[a-z0-9]+(?:-[a-z0-9]+)*$/u;function Sr(e,t){let n=wr(e,t);if(!Tr(n)||!Er(n,[`description`,`requires`,`routes`,`verifier`])||!Or(n.description)||n.requires!==void 0&&(!Array.isArray(n.requires)||!n.requires.every(Or))||n.verifier!==void 0&&!Or(n.verifier)||!Array.isArray(n.routes))throw Error(`${t} must contain a description string, routes array, and optional requires and verifier fields.`);let r=(n.requires??[]).map(e=>Cr(e));if(new Set(r).size!==r.length)throw Error(`${t} contains duplicate recipe requirements.`);let i=n.routes.map((e,n)=>{if(!Tr(e)||!Dr(e,[`path`,`router`,`when`])||!Or(e.path)||!Or(e.router)||!Or(e.when))throw Error(`${t} route ${n+1} must contain router, path, and when strings.`);return{path:e.path,router:e.router,when:e.when}}),a=i.map(e=>`${e.router}\0${e.path}`);if(new Set(a).size!==a.length)throw Error(`${t} contains a duplicate router and path pair.`);return{description:n.description,requires:r,routes:i,verifier:n.verifier}}function Cr(e){if(!xr.test(e))throw Error(`Recipe names use lowercase letters, numbers, and single hyphens.`);return e}function wr(e,t){try{return qe(e)}catch(e){throw Error(`Could not parse ${t}.`,{cause:e})}}function Tr(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Er(e,t){return Object.keys(e).every(e=>t.includes(e))}function Dr(e,t){let n=Object.keys(e).sort();return n.length===t.length&&n.every((e,n)=>e===t[n])}function Or(e){return typeof e==`string`&&e.length>0}const kr=`https://github.com/airlock-labs/coreframe.git`;function Ar(e,t){return K(`git`,e,{cwd:t,encoding:`utf8`})}function jr(e,t){let n=Ar(e,t);if(n.status!==0){let t=n.stderr.trim()||n.stdout.trim();throw Error(`Git command failed: git ${e.join(` `)}${t?`\n${t}`:``}`)}return n.stdout}function Mr(e,t){let n=Ar([`remote`,`get-url`,e],t);if(n.status===2)return null;if(n.status!==0){let t=n.stderr.trim()||n.stdout.trim();throw Error(`Could not inspect remote ${e}.${t?`\n${t}`:``}`)}return n.stdout.trim()}function Nr({cwd:e=process.cwd(),fetch:t=!0,remote:n=`template`}={}){if(n.length===0)throw Error(`Remote name must not be empty.`);jr([`rev-parse`,`--show-toplevel`],e);let r=Mr(n,e);if(r===null)jr([`remote`,`add`,n,kr],e),console.log(`Added ${n} remote: ${kr}`);else if(r===kr)console.log(`${n} remote already points at ${kr}`);else throw Error(`${n} remote points at ${r}, not ${kr}.\nChoose the intended template source before continuing, then update or rename the remote manually.`);t&&(jr([`fetch`,n,`--tags`,`--prune`],e),console.log(`Fetched ${n}.`))}const Pr=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/u;function Fr(e){return Pr.test(e)?`v${e}`:e}function Ir(e){return`${Fr(e)}:template`}function Lr(e,t){return`${Ir(e)}/${t}`}function Rr({cwd:e=process.cwd(),fetch:t=!0,remote:n=`template`,target:r}={}){let i=Hr(e),a=Kr(i,[`rev-parse`,`--show-toplevel`]),o=Fr(r??Ur(i));return Nr({cwd:a,fetch:t,remote:n}),{projectRoot:i,ref:o,repositoryRoot:a}}function zr(e,t,n){return Br(e,t,n).toString(`utf8`)}function Br(e,t,n){let r=`${t}:${n}`,i=K(`git`,[`show`,r],{cwd:e,encoding:`buffer`});if(i.status!==0)throw Error(`Could not read ${r}. ${qr([`show`,r],i)}`);return i.stdout}function Vr(e,t,n){let r=K(`git`,[`ls-tree`,`-r`,`--name-only`,`-z`,t,`--`,n],{cwd:e,encoding:`buffer`});if(r.status!==0)throw Error(qr([`ls-tree`,t,n],r));return r.stdout.toString(`utf8`).split(`\0`).filter(Boolean)}function Hr(e){let t=L(e);for(;;){let e=I(t,`package.json`),n=Gr(e);if(n!==void 0&&Wr(n,e).engines?.coreframe)return t;let r=F(t);if(r===t)throw Error(`Could not find a package.json with engines.coreframe.`);t=r}}function Ur(e){let t=I(e,`package.json`),n=Gr(t);if(n===void 0)throw Error(`Required file package.json does not exist.`);let r=Wr(n,t).engines?.coreframe;if(!r)throw Error(`package.json must declare an exact engines.coreframe recipe baseline.`);return r}function Wr(e,t){try{return JSON.parse(e)}catch(e){throw Error(`Could not parse ${t}.`,{cause:e})}}function Gr(e){try{return J(e,`utf8`)}catch(e){if(Jr(e)&&e.code===`ENOENT`)return;throw e}}function Kr(e,t){let n=K(`git`,t,{cwd:e,encoding:`utf8`});if(n.status!==0)throw Error(qr(t,n));return n.stdout.trim()}function qr(e,t){let n=t.stderr.toString(`utf8`).trim()||t.stdout.toString(`utf8`).trim();return`Git command failed: git ${e.join(` `)}${n?`\n${n}`:``}`}function Jr(e){return e instanceof Error&&`code`in e}const Yr=[{path:`package.json`,requirement:`retain the Coreframe Flutter JavaScript runtime used by src-flutter`,test:e=>e.includes(`"@coreframe/flutter-js"`)},{path:`coreframe.config.ts`,requirement:`enable web and at least one Flutter development platform`,test:Qr},{path:`src/api/client/app-origin.ts`,requirement:`allow the Flutter shell to provide its exact API origin`,test:e=>Zr(e,[`@coreframe/flutter-js/client`,`resolveAppOrigin`,`browserOrigin: location?.origin`])},{path:`src/api/worker/auth-config.ts`,requirement:`trust the exact Flutter authentication origins`,test:e=>Zr(e,[`appendFlutterAuthOrigins`,`appendFlutterAuthOrigins([], development)`])},{path:`src/api/worker/middleware/auth.ts`,requirement:`broker Flutter access tokens and accept only Flutter bearer origins`,test:e=>Zr(e,[`createFlutterAccessTokenResponse`,`isFlutterAuthOrigin(origin, import.meta.env.DEV)`,`readFlutterBearerToken`,`native && ctx.request.method !== "GET"`])&&!e.includes(`isNativeOrigin`)},{path:`src/api/worker/middleware/flutter-cors.ts`,requirement:`provide the Flutter packaged-origin CORS boundary`,test:e=>Zr(e,[`applyFlutterCors`,`handleFlutterCorsPreflight`,`flutterCorsMiddleware`])},{path:`src/api/worker/middleware/index.ts`,requirement:`apply Flutter CORS to ordinary Worker responses`,test:e=>e.includes(`flutterCorsMiddleware`)},{path:`src/web/app/flutter-shell/application.ts`,requirement:`configure the Flutter shell's app-owned query and session hooks`,test:e=>Zr(e,[`configureShellQueryFocus`,`authSessionHint`])},{path:`src/web/dev/flutter-devtools.ts`,requirement:`install the Flutter development tools bridge`,test:e=>e.includes(`installFlutterDevTools`)},{path:`src/web/entry.client.tsx`,requirement:`load Flutter development tools only for non-browser development`,test:e=>Zr(e,[`./dev/flutter-devtools.ts`,`import.meta.env.PLATFORM !== "web"`])}];function Xr(e){let t=[];for(let n of Yr){let r=I(e,n.path);if(!q(r)){t.push(`${n.path} is missing; it must ${n.requirement}.`);continue}let i=J(r,`utf8`);n.test(i)||t.push(`${n.path} must ${n.requirement}.`)}return t}function Zr(e,t){return t.every(t=>e.includes(t))}function Qr(e){let t=e.match(/\bplatforms\s*:\s*\[([\s\S]*?)\]/)?.[1];if(!t)return!1;let n=new Set([...t.matchAll(/(["'`])([^"'`]*)\1/g)].map(e=>e[2]));return n.has(`web`)&&[`ios`,`android`,`macos`].some(e=>n.has(e))}const $r=[{path:`package.json`,requirement:`declare the Tauri CLI, plugin-log, and Coreframe Tauri runtime packages`,test:e=>Q(e,[`"@tauri-apps/cli"`,`"@tauri-apps/plugin-log"`,`"@coreframe/tauri-js"`,`"@coreframe/tauri-plugin-auth-session"`])},{path:`src-tauri/Cargo.toml`,requirement:`declare Tauri, plugin-log, and Coreframe auth-session Rust dependencies`,test:e=>Q(e,[`tauri-build`,`tauri-plugin-log`,`coreframe-tauri-plugin-auth-session`])},{path:`src-tauri/src/main.rs`,requirement:`launch the project-owned Tauri Rust library`,test:e=>e.includes(`::run();`)},{path:`src-tauri/src/lib.rs`,requirement:`register plugin-log and the Coreframe auth-session broker`,test:e=>Q(e,[`tauri_plugin_log::Builder`,`coreframe_tauri_plugin_auth_session::init`,`VITE_APP_ORIGIN`])},{path:`src-tauri/build.rs`,requirement:`forward VITE_APP_ORIGIN and TAURI_DEV_HOST into the Rust build`,test:e=>Q(e,[`VITE_APP_ORIGIN`,`TAURI_DEV_HOST`])},{path:`src-tauri/capabilities/default.json`,requirement:`grant log and auth-session permissions to the main window`,test:e=>Q(e,[`"windows": ["main"]`,`"log:default"`,`"coreframe-tauri-plugin-auth-session:default"`])},{path:`vite.config.ts`,requirement:`define the Tauri runtime and platform environment and fixed native dev server`,test:e=>Q(e,[`env.host === "tauri"`,`"import.meta.env.TAURI"`,`"import.meta.env.PLATFORM"`,`TAURI_DEV_HOST`,`strictPort: true`])},{path:`src/vite-env.d.ts`,requirement:`type the Tauri runtime, platform, development origin, and packaged app origin`,test:e=>Q(e,[`PLATFORM: import("@coreframe/lib/shell").ShellPlatform`,`TAURI: boolean`,`TAURI_DEV_ORIGIN`,`VITE_APP_ORIGIN`])},{path:`react-router.config.ts`,requirement:`skip service-worker generation for non-browser hosts`,test:e=>Q(e,[`resolveCoreframeHost`,`resolveCoreframeHost() === "browser"`])},{path:`src/api/client/app-origin.ts`,requirement:`resolve browser and packaged application origins through the Tauri runtime`,test:e=>Q(e,[`@coreframe/tauri-js/client`,`browserOrigin: location?.origin`,`development: import.meta.env.DEV`,`packagedAppOrigin: import.meta.env.VITE_APP_ORIGIN`,`tauri: import.meta.env.TAURI`,`tauriDevelopmentOrigin: import.meta.env.TAURI_DEV_ORIGIN`])&&!e.includes(`resolveAppOrigin(import.meta.env`)},{path:`src/api/client/auth-fetch.ts`,requirement:`call the selected framework authentication composition`,test:e=>Q(e,[`createAuthenticatedFetch`,`refreshAccess`,`sessionHint: authSessionHint`])},{path:`src/api/client/auth-session-hint.ts`,requirement:`keep native session hints in memory until the credential broker revalidates`,test:e=>Q(e,[`import.meta.env.PLATFORM !== "web"`,`persistence: browserPersistence`,`return false`])},{path:`src/api/client/tauri-auth.ts`,requirement:`compose native API and Better Auth transports behind the virtual auth contract`,test:e=>Q(e,[`createAuthenticatedFetch`,`createTauriAuthenticatedFetch`,`authSessionHint: options.sessionHint`,`mintAccessToken`,`createAuthClient`,`createAuthFetch`,`onSessionChange: options.onSessionChange`])},{path:`src/web/auth/client.ts`,requirement:`call the selected framework Better Auth composition`,test:e=>Q(e,[`createAuthClient as createCoreframeAuthClient`,`createCoreframeAuthClient`,`authFetch`,`customFetchImpl`])},{path:`src/api/worker/middleware/auth.ts`,requirement:`mint and accept bearer access tokens only across the fixed native origin boundary`,test:e=>Q(e,[`appendTauriAppOrigins`,`createTauriAccessTokenResponse`,`isTauriAppOrigin`,`readTauriBearerToken`])},{path:`src/api/worker/fetch.ts`,requirement:`apply native CORS at every Worker response boundary`,test:e=>Q(e,[`handleTauriCorsPreflight`,`applyTauriCors`])},{path:`coreframe.config.ts`,requirement:`enable web and desktop development platforms`,test:e=>Q(e,[`platforms: ["web", "desktop"]`])&&!e.includes(`"ios"`)&&!e.includes(`"android"`)},{path:`src/web/entry.client.tsx`,requirement:`attach native development logs and skip service-worker registration in Tauri`,test:e=>Q(e,[`import "./dev/tauri-log.ts"`,`import.meta.env.TAURI`])},{path:`.env.example`,requirement:`document the packaged VITE_APP_ORIGIN build value`,test:e=>e.includes(`VITE_APP_ORIGIN`)},{path:`.gitignore`,requirement:`ignore the Tauri Cargo target directory`,test:e=>e.includes(`src-tauri/target`)},{path:`.oxfmtrc.json`,requirement:`ignore generated Tauri schemas and target output`,test:e=>Q(e,[`src-tauri/gen/schemas`,`src-tauri/target`])},{path:`src-tauri/AGENTS.md`,requirement:`route native work to owner-local rules and documentation`,test:e=>Q(e,[`.agents/rules/tauri.md`,`docs/authentication.md`,`docs/deployment.md`])},{path:`src-tauri/.agents/rules/tauri.md`,requirement:`install the owner-local durable Tauri native-boundary rule`,test:e=>Q(e,[`## Native Boundary`,`## Security`,`## Documentation`])},{path:`.agents/rules/integrations.yaml`,requirement:`route cross-boundary Tauri work to the owner-local native rule`,test:e=>e.includes(`src-tauri/.agents/rules/tauri.md`)},{path:`src-tauri/docs/authentication.md`,requirement:`document the native credential broker and bearer-token boundary`,test:e=>Q(e,[`@coreframe/tauri-js`,`@coreframe/tauri-plugin-auth-session`,`VITE_APP_ORIGIN`])},{path:`src-tauri/docs/development.md`,requirement:`document native development asset delivery and Leylines scopes`,test:e=>Q(e,[`dev.tauri`,`browser.tauri`,`managed asset`])},{path:`src-tauri/docs/deployment.md`,requirement:`document native release topology, signing, token recovery, and provider setup`,test:e=>Q(e,[`VITE_APP_ORIGIN`,`native-auth`,`access-token signing-secret`])},{path:`src-tauri/docs/privacy-security.md`,requirement:`record the shipped Tauri remote API and secure-storage boundary`,test:e=>Q(e,[`## Remote API Boundary`,`platform secure storage`])},{path:`.github/workflows/tauri-release-artifacts.yml`,requirement:`provide a desktop-only Tauri release-artifact workflow`,test:e=>Q(e,[`Build Tauri Release Artifacts`,`pnpm exec tauri`])&&!e.toLowerCase().includes(`ios`)&&!e.toLowerCase().includes(`android`)}],ei=[`CoreframeTemplateProject7A91C`,`coreframe-template-project-7a91c`,`coreframe_template_project_7a91c`,`com.example.coreframetemplateproject7a91c`];function ti(e){let t=[];for(let n of $r){let r=I(e,n.path);if(!q(r)){t.push(`${n.path} is missing; it must ${n.requirement}.`);continue}let i=J(r,`utf8`);n.test(i)||t.push(`${n.path} must ${n.requirement}.`)}let n=I(e,`src-tauri/tauri.conf.json`);q(n)?ni(n,t):t.push(`src-tauri/tauri.conf.json is missing.`);for(let n of[`src-tauri/Cargo.toml`,`src-tauri/src/main.rs`,`src-tauri/tauri.conf.json`]){let r=I(e,n);q(r)&&ei.some(e=>J(r,`utf8`).includes(e))&&t.push(`${n} must replace the Coreframe template identity sentinel.`)}return t}function ni(e,t){let n;try{n=JSON.parse(J(e,`utf8`))}catch{t.push(`src-tauri/tauri.conf.json must contain valid JSON.`);return}(typeof n.identifier!=`string`||!/^[a-z0-9]+(?:\.[a-z0-9]+){2,}$/.test(n.identifier)||n.identifier.startsWith(`com.example.`))&&t.push(`src-tauri/tauri.conf.json must use an organization-owned reverse-domain identifier.`)}function Q(e,t){return t.every(t=>e.includes(t))}function ri({name:e,...t}){let n=Rr(t),r=`recipes/${e}/recipe.yaml`,i=oi(Sr(zr(n.repositoryRoot,n.ref,r),r).verifier,n.projectRoot);if(i.length>0)throw Error(`Recipe ${e} verification failed:\n${i.map(e=>`- ${e}`).join(`
|
|
5
|
+
`)}async function $t({apiOrigin:e,cwd:t=process.cwd(),environment:n=process.env,platform:r=`web`,simulator:i=!1,prepareClient:a=M,runCommand:o=tn}={}){en(r,i);let s={...n};delete s.COREFRAME_PLATFORM,delete s.TAURI_ENV_PLATFORM;let c=r===`web`?void 0:N(e??n.COREFRAME_API_ORIGIN);for(let e of Yt(r,{apiOrigin:c,cwd:t,simulator:i})){if(e.kind===`prepare`){if(!c)throw Error(`A production API origin is required for the Flutter ${e.platform} build.`);await a({apiOrigin:c,cwd:t,environment:s,platform:e.platform});continue}await o(e.command,e.args,{cwd:e.cwd,env:{...s,...e.environment}})}r===`android`?console.log(Zt(t)):r===`ios`&&console.log(Qt(t,{simulator:i}))}function en(e,t){if(t&&e!==`ios`)throw Error(`The --simulator flag is only supported for the iOS build target.`)}async function tn(e,t,{cwd:n,env:r}){await R(e,t,{cwd:n,env:r,stdio:`inherit`})}function nn(e,t,n,r){return{kind:`command`,command:e,args:t,cwd:n,...r===void 0?{}:{environment:r}}}const rn=r(f,{displayName:`origin`,description:`Exact production HTTPS API origin embedded in a packaged Flutter client.`,async from(e){return N(e)}}),an=n({name:`build`,description:`Build the web client or a release Flutter app. Tauri is not built.`,args:{platform:u({type:l(s(Jt)),displayName:`platform`,description:`Build target: web, iOS, Android, or macOS. Defaults to web.`}),apiOrigin:c({long:`api-origin`,type:l(rn),description:`Exact production HTTPS API origin for a Flutter build. Defaults to COREFRAME_API_ORIGIN.`}),simulator:i({long:`simulator`,description:`Build iOS for the simulator instead of a physical device.`,defaultValue:()=>!1})},handler:({apiOrigin:e,platform:t,simulator:n})=>$t({apiOrigin:e,platform:t,simulator:n})}),on=/^[a-f0-9]{64}$/,sn=/^[a-f0-9]{40}$/,cn=/^[A-Za-z0-9][A-Za-z0-9._-]*$/;function ln(e){if(!on.test(e))throw Error(`Invalid SHA-256 digest "${e}".`);return e}function un(e){if(!sn.test(e))throw Error(`Invalid full Git revision "${e}".`);return e}function dn(e,t){if(!cn.test(e))throw Error(`${t} must contain only letters, numbers, dots, underscores, or hyphens.`);return e}function fn(e){return`projects/${dn(e,`Project ID`)}/i18n/v1`}function pn(e,t){return ln(t),`${fn(e)}/objects/sha256/${t.slice(0,2)}/${t}`}function mn(e,t){return un(t),`${fn(e)}/commits/${t}.json`}function hn(e,t){return gn(t),`${fn(e)}/releases/${encodeURIComponent(t)}.json`}function gn(e){if(!e.startsWith(`v`)||e.length<2||e.length>128||/\s/.test(e)||e.includes(`..`))throw Error(`Release tag "${e}" must be a valid v-prefixed tag.`);return e}function X(e,t){if(!t||t.startsWith(`/`)||t.includes(`\0`))throw Error(`Unsafe i18n artifact path "${t}".`);let n=L(e),r=L(n,t);if(r!==n&&!r.startsWith(`${n}${ue}`))throw Error(`Unsafe i18n artifact path "${t}".`);return r}function Z(e,t,n){return`${e.directory}/${t}/${n}.json`}function _n(e,t,n){return`${e.directory}/${t}/${n}.mjs`}async function vn(e){await R(`pnpm`,[`exec`,`lingui`,`extract`],{cwd:e,stdio:`inherit`})}async function yn({config:e,cwd:t,strict:n,temporaryDirectory:r}){let i=[];try{for(let n of e.locales)for(let a of e.catalogs){let o=X(t,Z(e,n,a)),s=await wn(o),c=Object.fromEntries(Object.entries(s).filter(([,e])=>!e.obsolete)),l=I(r,`${n}-${a}.json`);await B(F(l),{recursive:!0}),await xe(o,l),i.push({path:o,backup:l}),await Tn(o,c)}await R(`pnpm`,[`exec`,`lingui`,`compile`,...n?[`--strict`]:[]],{cwd:t,stdio:`inherit`})}finally{try{for(let{path:e,backup:t}of i)await xe(t,e)}finally{for(let n of e.locales)for(let r of e.catalogs)await H(X(t,_n(e,n,r)),{force:!0})}}}async function bn({config:e,cwd:t}){let n=[];for(let r of e.locales)if(r!==e.sourceLocale)for(let i of e.catalogs){let a=await wn(X(t,Z(e,r,i)));for(let[e,t]of Object.entries(a)){if(t.obsolete||t.translation?.trim())continue;let a=t.message;if(typeof a!=`string`||!a)throw Error(`Missing source message metadata for ${r}:${e}.`);n.push({catalog:i,comments:t.comments?.filter(e=>typeof e==`string`)??[],context:t.context,id:e,locale:r,message:a,origins:t.origin?.map(([e,t])=>t?`${e}:${t}`:e)??[],placeholders:Object.keys(t.placeholders??{}).sort()})}}return n.sort((e,t)=>An(e).localeCompare(An(t)))}async function xn({config:e,cwd:t,messages:n,env:r=process.env}){if(n.length===0)return{translations:[],version:1};if(!e.generator)throw Error(`I18n preparation found ${n.length} missing translations, but no generator is configured.`);let i={messages:n,sourceLocale:e.sourceLocale,version:1};return En(await Dn({args:e.generator.args??[],command:e.generator.command,cwd:t,env:r,input:JSON.stringify(i)}))}async function Sn({config:e,cwd:t,missing:n,response:r}){let i=new Map(n.map(e=>[An(e),e])),a=new Map;for(let e of r.translations){let t=An(e);if(!i.has(t))throw Error(`Translation generator returned unexpected entry ${e.locale}:${e.catalog}:${e.id}.`);if(a.has(t))throw Error(`Translation generator returned duplicate entry ${e.locale}:${e.catalog}:${e.id}.`);if(!e.translation.trim())throw Error(`Translation generator returned an empty entry ${e.locale}:${e.id}.`);a.set(t,e.translation)}let o=[...i.keys()].filter(e=>!a.has(e));if(o.length>0)throw Error(`Translation generator omitted ${o.length} required entries.`);let s=await Ne(`@lingui/message-utils/compileMessage`,t);for(let e of n){let t=a.get(An(e));On({compileMessage:s,id:e.id,locale:e.locale,source:e.message,translation:t})}for(let n of e.locales)if(n!==e.sourceLocale)for(let r of e.catalogs){let i=X(t,Z(e,n,r)),o=await wn(i),s=!1;for(let[e,t]of Object.entries(o)){let i=a.get(An({catalog:r,id:e,locale:n}));if(i!==void 0){if(t.translation?.trim())throw Error(`Refusing to overwrite preserved translation ${n}:${e}.`);t.translation=i,s=!0}}s&&await Tn(i,o)}}async function Cn({config:e,cwd:t}){let n=await bn({config:e,cwd:t});if(n.length>0)throw Error(`I18n catalogs remain incomplete: ${n.length} translations are missing.`);let r=await Ne(`@lingui/message-utils/compileMessage`,t);for(let n of e.locales)if(n!==e.sourceLocale)for(let i of e.catalogs){let a=await wn(X(t,Z(e,n,i)));for(let[e,t]of Object.entries(a))if(!t.obsolete){if(typeof t.message!=`string`||typeof t.translation!=`string`)throw Error(`Incomplete source metadata for active translation ${n}:${e}.`);On({compileMessage:r,id:e,locale:n,source:t.message,translation:t.translation})}}}async function wn(e){let t=JSON.parse(await V(e,`utf8`));if(!t||typeof t!=`object`||Array.isArray(t))throw Error(`Lingui rich JSON catalog must be an object: ${e}.`);for(let[n,r]of Object.entries(t)){if(!r||typeof r!=`object`||Array.isArray(r))throw Error(`Invalid Lingui rich JSON message ${n} in ${e}.`);let t=r;if(t.translation!==void 0&&typeof t.translation!=`string`)throw Error(`Invalid translation value for ${n} in ${e}.`);if(t.message!==void 0&&t.message!==null&&typeof t.message!=`string`)throw Error(`Invalid source message value for ${n} in ${e}.`);if(t.context!==void 0&&typeof t.context!=`string`)throw Error(`Invalid context value for ${n} in ${e}.`);if(t.obsolete!==void 0&&typeof t.obsolete!=`boolean`)throw Error(`Invalid obsolete marker for ${n} in ${e}.`);if(t.comments!==void 0&&(!Array.isArray(t.comments)||t.comments.some(e=>typeof e!=`string`)))throw Error(`Invalid comments for ${n} in ${e}.`);if(t.origin!==void 0&&(!Array.isArray(t.origin)||t.origin.some(e=>!Array.isArray(e)||typeof e[0]!=`string`||e[1]!==void 0&&typeof e[1]!=`number`)))throw Error(`Invalid origins for ${n} in ${e}.`);if(t.placeholders!==void 0&&(!t.placeholders||typeof t.placeholders!=`object`||Array.isArray(t.placeholders)))throw Error(`Invalid placeholders for ${n} in ${e}.`)}return t}async function Tn(e,t){await B(F(e),{recursive:!0});let n=`${e}.${process.pid}.tmp`;await U(n,`${JSON.stringify(t,null,2)}\n`),await De(n,e)}function En(e){let t;try{t=JSON.parse(e)}catch{throw Error(`Translation generator returned invalid JSON.`)}if(!t||typeof t!=`object`||t.version!==1||!Array.isArray(t.translations))throw Error(`Translation generator returned an invalid response envelope.`);for(let e of t.translations)if(!e||typeof e!=`object`||typeof e.id!=`string`||typeof e.catalog!=`string`||typeof e.locale!=`string`||typeof e.translation!=`string`)throw Error(`Translation generator returned an invalid translation entry.`);return t}function Dn({args:e,command:t,cwd:n,env:r,input:i}){return R(t,e,{cwd:n,env:r,stdio:[{string:i},`pipe`,`ignore`]}).then(({stdout:e})=>{if(Buffer.byteLength(e)>10*1024*1024)throw Error(`Translation generator output exceeded 10 MiB.`);return e}).catch(()=>{throw Error(`Translation generator exited unsuccessfully.`)})}function On({compileMessage:e,id:t,locale:n,source:r,translation:i}){let a,o;try{a=e.compileMessageOrThrow(r),o=e.compileMessageOrThrow(i)}catch{throw Error(`Translation ${n}:${t} is not valid ICU MessageFormat.`)}let s=kn(a),c=kn(o);if(s.length!==c.length||s.some((e,t)=>e!==c[t]))throw Error(`Translation ${n}:${t} does not preserve source ICU placeholders.`)}function kn(e){let t=[];function n(e){for(let r of e){if(typeof r==`string`)continue;let[e,i=`argument`,a]=r;if(t.push(`${e}:${i}`),a&&typeof a==`object`&&!Array.isArray(a))for(let e of Object.values(a))Array.isArray(e)&&n(e)}}return n(e),t.sort()}function An(e){return`${e.locale}\0${e.catalog}\0${e.id}`}function jn(e){return Re(`sha256`).update(e).digest(`hex`)}async function Mn(e){return jn(await V(e))}function Nn(e){return Buffer.from(`${JSON.stringify(e,null,2)}\n`)}async function Pn({bucket:e,digest:t,projectId:n,source:r,store:i}){if(ln(t),await Mn(r)!==t)throw Error(`I18n object source does not match declared SHA-256 digest ${t}.`);let a=pn(n,t);await i.has(e,a)||await i.upload(e,a,r,`application/octet-stream`);let o=`${r}.${process.pid}.${W()}.verify`;try{if(await i.download(e,a,o),await Mn(o)!==t)throw Error(`Existing immutable i18n object ${a} failed integrity verification.`)}finally{await H(o,{force:!0})}}async function Fn({bucket:e,key:t,reference:n,store:r,temporaryDirectory:i}){let a=Nn(n),o=I(i,`reference-${W()}.json`);if(await r.has(e,t))try{if(await r.download(e,t,o),!(await V(o)).equals(a))throw Error(`Immutable i18n reference ${t} already resolves to different snapshot data.`);return}finally{await H(o,{force:!0})}await U(o,a,{flag:`wx`});try{await r.upload(e,t,o,`application/json`)}finally{await H(o,{force:!0})}let s=I(i,`reference-${W()}.verify.json`);try{if(await r.download(e,t,s),!(await V(s)).equals(a))throw Error(`Uploaded immutable i18n reference ${t} failed verification.`)}finally{await H(s,{force:!0})}}async function In({bucket:e,manifest:t,projectId:n,store:r,temporaryDirectory:i}){let a=Nn(t),o=jn(a),s=I(i,`manifest-${o}.json`);await U(s,a,{flag:`wx`});try{await Pn({bucket:e,digest:o,projectId:n,source:s,store:r})}finally{await H(s,{force:!0})}return o}async function Ln({bucket:e,key:t,store:n,temporaryDirectory:r}){if(!await n.has(e,t))return;let i=I(r,`reference-${W()}.json`);try{await n.download(e,t,i);let r=JSON.parse(await V(i,`utf8`));if(r.version!==1||typeof r.revision!=`string`||typeof r.snapshot!=`string`)throw Error(`Invalid i18n reference at ${t}.`);return un(r.revision),ln(r.snapshot),r}finally{await H(i,{force:!0})}}async function Rn({bucket:e,projectId:t,revision:n,store:r,temporaryDirectory:i}){let a=await Ln({bucket:e,key:mn(t,n),store:r,temporaryDirectory:i});if(a&&a.revision!==n)throw Error(`I18n commit reference does not match requested revision ${n}.`);return a}async function zn({bucket:e,projectId:t,reference:n,store:r,tag:i,temporaryDirectory:a}){await Fn({bucket:e,key:mn(t,n.revision),reference:n,store:r,temporaryDirectory:a}),i&&await Fn({bucket:e,key:hn(t,i),reference:n,store:r,temporaryDirectory:a})}async function Bn({bucket:e,cacheRoot:t,digest:n,projectId:r,store:i,target:a}){ln(n);let o=I(L(t),`v1`,`sha256`,n.slice(0,2),n);if(await Hn(o,n)===!1){await B(F(o),{recursive:!0});let t=`${o}.${process.pid}.${W()}.tmp`;try{if(await i.download(e,pn(r,n),t),await Mn(t)!==n)throw Error(`Downloaded i18n object failed SHA-256 verification: ${n}.`);await H(o,{force:!0}),await De(t,o)}finally{await H(t,{force:!0})}}await B(F(a),{recursive:!0});let s=`${a}.${process.pid}.${W()}.tmp`;try{if(await xe(o,s),await Mn(s)!==n)throw Error(`Cached i18n object failed SHA-256 verification: ${n}.`);await H(a,{force:!0}),await De(s,a)}finally{await H(s,{force:!0})}}async function Vn({bucket:e,cacheRoot:t,digest:n,projectId:r,store:i,temporaryDirectory:a}){let o=I(a,`manifest-${n}.json`);await Bn({bucket:e,cacheRoot:t,digest:n,projectId:r,store:i,target:o});let s=JSON.parse(await V(o,`utf8`));if(s.version!==1||s.projectId!==r||typeof s.revision!=`string`||!Array.isArray(s.files)||!Array.isArray(s.catalogs)||s.catalogs.some(e=>typeof e!=`string`)||!Array.isArray(s.locales)||s.locales.some(e=>typeof e!=`string`)||typeof s.sourceLocale!=`string`||typeof s.generator!=`string`||typeof s.linguiVersion!=`string`)throw Error(`Invalid i18n snapshot manifest ${n}.`);un(s.revision),s.baseline!==void 0&&ln(s.baseline);for(let e of s.files){if(!e||typeof e!=`object`||typeof e.path!=`string`||typeof e.digest!=`string`||typeof e.size!=`number`)throw Error(`Invalid file entry in i18n snapshot manifest ${n}.`);ln(e.digest)}return s}async function Hn(e,t){try{return(await Oe(e)).isFile()&&await Mn(e)===t}catch{return!1}}async function Un({cwd:e=process.cwd(),env:t=process.env}={}){if((await Ie({cwd:e})).i18n){if(t.COREFRAME_I18N_RELEASE_REVISION){await Kn({cwd:e,env:t,revision:t.COREFRAME_I18N_RELEASE_REVISION});return}await vn(e)}}async function Wn({cwd:e=process.cwd(),projectConfig:t}={}){let n=t??await Ie({cwd:e});if(!n.i18n)return;let r=qn(n.i18n),i=X(e,r.directory);try{if(!(await Oe(i)).isDirectory())throw Error(`I18n catalog path is not a directory: ${i}.`)}catch(t){if(t.code!==`ENOENT`)throw t;await vn(e);return}for(let t of r.locales)for(let n of r.catalogs)try{if(!(await Oe(X(e,Z(r,t,n)))).isFile())throw Error(`I18n catalog path is not a file: ${t}/${n}.json.`)}catch(t){if(t.code!==`ENOENT`)throw t;await vn(e);return}}async function Gn({cwd:e=process.cwd(),env:t=process.env,store:n,tag:r}){gn(r);let i=await Jn({cwd:e,env:t,store:n});await nr(e);let a=await tr(e);await rr(e,r,a);let o=await we(I(Me(),`coreframe-i18n-prepare-`));try{let n=await Rn({bucket:i.assets.sourceBucket,projectId:i.assets.projectId,revision:a,store:i.store,temporaryDirectory:o});if(n){let e=await Vn({bucket:i.assets.sourceBucket,cacheRoot:i.cacheRoot,digest:n.snapshot,projectId:i.assets.projectId,store:i.store,temporaryDirectory:o});return er(i,e,a),await Xn(i,e),await zn({bucket:i.assets.sourceBucket,projectId:i.assets.projectId,reference:n,store:i.store,tag:r,temporaryDirectory:o}),{reused:!0,snapshot:n.snapshot}}return await $n(i,o,async()=>{let n=await Yn(i,a,o);n||await Qn(i),await vn(e);let s=await bn({config:i.config,cwd:e}),c=await xn({config:i.config,cwd:e,env:t,messages:s});await Sn({config:i.config,cwd:e,missing:s,response:c}),await Cn({config:i.config,cwd:e}),await yn({config:i.config,cwd:e,strict:!0,temporaryDirectory:o});let l=await Zn(i),u={...n?{baseline:n}:{},catalogs:i.config.catalogs,files:l,generator:s.length>0?i.config.generator?.id??`unconfigured`:`none`,linguiVersion:await ir(e),locales:i.config.locales,projectId:i.assets.projectId,revision:a,sourceLocale:i.config.sourceLocale,version:1},d=await In({bucket:i.assets.sourceBucket,manifest:u,projectId:i.assets.projectId,store:i.store,temporaryDirectory:o});return await zn({bucket:i.assets.sourceBucket,projectId:i.assets.projectId,reference:{revision:a,snapshot:d,version:1},store:i.store,tag:r,temporaryDirectory:o}),{reused:!1,snapshot:d}})}finally{await H(o,{force:!0,recursive:!0})}}async function Kn({cwd:e=process.cwd(),env:t=process.env,revision:n,store:r}={}){let i=await Ie({cwd:e});if(!i.i18n)return;let a=await Jn({cwd:e,env:t,store:r,projectConfig:i}),o=un(n??await tr(e)),s=await we(I(Me(),`coreframe-i18n-materialize-`));try{let e=await Rn({bucket:a.assets.sourceBucket,projectId:a.assets.projectId,revision:o,store:a.store,temporaryDirectory:s});if(!e)throw Error(`No prepared i18n snapshot exists for commit ${o}. Push a v* tag for this commit and wait for the translation gate.`);let t=await Vn({bucket:a.assets.sourceBucket,cacheRoot:a.cacheRoot,digest:e.snapshot,projectId:a.assets.projectId,store:a.store,temporaryDirectory:s});return er(a,t,o),await Xn(a,t),{revision:o,snapshot:e.snapshot}}finally{await H(s,{force:!0,recursive:!0})}}function qn(e){let t=dn(e.sourceLocale,`Source locale`),n=[...new Set(e.locales.map(e=>dn(e,`Locale`)))],r=[...new Set(e.catalogs.map(e=>dn(e,`Catalog`)))];if(n.length===0||!n.includes(t))throw Error(`I18n locales must include the source locale.`);if(r.length===0)throw Error(`I18n configuration requires at least one catalog.`);if(e.generator&&(!e.generator.command.trim()||!e.generator.id.trim()))throw Error(`I18n generator command and ID must be non-empty.`);return{catalogs:r,directory:e.directory??`locales`,generator:e.generator,locales:n,sourceLocale:t}}async function Jn({cwd:e=process.cwd(),env:t=process.env,projectConfig:n,store:r}){let i=n??await Ie({cwd:e});if(!i.i18n)throw Error(`Missing i18n configuration in coreframe.config.ts.`);if(!i.assets)throw Error(`I18n snapshots require the existing private build bucket configured under assets.`);let a=i.assets;return{assets:a,cacheRoot:L(e,`.coreframe`,`i18n`,`cache`),config:qn(i.i18n),cwd:L(e),env:t,store:r??ve({config:a,env:t})}}async function Yn(e,t,n){let{stdout:r}=await R(`git`,[`rev-list`,`--first-parent`,`--skip=1`,t],{cwd:e.cwd,stdin:`ignore`});for(let t of r.split(/\r?\n/).filter(Boolean)){let r=await Rn({bucket:e.assets.sourceBucket,projectId:e.assets.projectId,revision:un(t),store:e.store,temporaryDirectory:n});if(!r)continue;let i=await Vn({bucket:e.assets.sourceBucket,cacheRoot:e.cacheRoot,digest:r.snapshot,projectId:e.assets.projectId,store:e.store,temporaryDirectory:n});return er(e,i,t),await Xn(e,i),r.snapshot}}async function Xn(e,t){for(let n of t.files)if(await Bn({bucket:e.assets.sourceBucket,cacheRoot:e.cacheRoot,digest:n.digest,projectId:e.assets.projectId,store:e.store,target:X(e.cwd,n.path)}),(await Oe(X(e.cwd,n.path))).size!==n.size)throw Error(`Materialized i18n artifact size does not match manifest: ${n.path}.`)}async function Zn(e){let t=[];for(let n of e.config.locales)for(let r of e.config.catalogs){let i=Z(e.config,n,r),a=X(e.cwd,i),o=await Mn(a);await Pn({bucket:e.assets.sourceBucket,digest:o,projectId:e.assets.projectId,source:a,store:e.store}),t.push({digest:o,path:i,size:(await Oe(a)).size})}return t.sort((e,t)=>e.path.localeCompare(t.path))}async function Qn(e){let{stdout:t}=await R(`git`,[`rev-parse`,`--show-prefix`],{cwd:e.cwd,stdin:`ignore`}),n=t.trim(),{stdout:r}=await R(`git`,[`log`,`-1`,`--format=%H`,`--diff-filter=AM`,`--`,`:(top)${`${n}${e.config.directory}/${e.config.sourceLocale}/${e.config.catalogs[0]}.po`}`],{cwd:e.cwd,stdin:`ignore`}),i=r.trim();if(!i)return!1;let a=(await Ne(`@lingui/format-po`,e.cwd)).formatter({lineNumbers:!1}),o=!1;for(let t of e.config.locales)for(let r of e.config.catalogs){let s=`${n}${`${e.config.directory}/${t}/${r}.po`}`;try{let{stdout:n}=await R(`git`,[`show`,`${i}:${s}`],{cwd:e.cwd,stdin:`ignore`});await Tn(X(e.cwd,Z(e.config,t,r)),a.parse(n)),o=!0}catch{}}return o}async function $n(e,t,n){let r=[];for(let n of e.config.locales)for(let i of e.config.catalogs){let a=Z(e.config,n,i),o=X(e.cwd,a);try{await ye(o)}catch{continue}let s=I(t,`previous-catalogs`,a);await B(F(s),{recursive:!0}),await De(o,s),r.push({backup:s,path:o})}try{let e=await n();return await H(I(t,`previous-catalogs`),{force:!0,recursive:!0}),e}catch(t){for(let t of e.config.locales)for(let n of e.config.catalogs)await H(X(e.cwd,Z(e.config,t,n)),{force:!0});for(let{backup:e,path:t}of r)await B(F(t),{recursive:!0}),await De(e,t);throw t}}function er(e,t,n){if(t.revision!==n||t.projectId!==e.assets.projectId||t.sourceLocale!==e.config.sourceLocale||JSON.stringify(t.locales)!==JSON.stringify(e.config.locales)||JSON.stringify(t.catalogs)!==JSON.stringify(e.config.catalogs))throw Error(`I18n snapshot does not match commit or project configuration.`);let r=e.config.locales.flatMap(t=>e.config.catalogs.map(n=>Z(e.config,t,n))),i=t.files.map(e=>e.path);if(new Set(i).size!==i.length||JSON.stringify(i.sort())!==JSON.stringify(r.sort()))throw Error(`I18n snapshot has an incomplete or unexpected artifact set.`)}async function tr(e){let{stdout:t}=await R(`git`,[`rev-parse`,`HEAD`],{cwd:e,stdin:`ignore`});return un(t.trim())}async function nr(e){let{stdout:t}=await R(`git`,[`status`,`--porcelain`],{cwd:e,stdin:`ignore`});if(t.trim())throw Error(`Tagged i18n preparation requires a clean Git tree.`)}async function rr(e,t,n){let{stdout:r}=await R(`git`,[`rev-parse`,`${t}^{commit}`],{cwd:e,stdin:`ignore`});if(r.trim()!==n)throw Error(`Release tag ${t} does not point to checked-out commit ${n}.`)}async function ir(e){let{stdout:t}=await R(`pnpm`,[`exec`,`lingui`,`--version`],{cwd:e,stdin:`ignore`});return t.trim()}const ar=[`Use a B2 Multi-Bucket Application Key restricted to the configured private build-object and public generated-assets buckets.`,`Required capabilities: listAllBucketNames, readFiles, and writeFiles.`,`Deletion, bucket-management, and key-management capabilities are not needed.`].join(` `),or=r(f,{displayName:`widths`,description:`Comma-separated responsive variant widths.`,async from(e){let t=e.split(`,`).map(e=>Number(e));if(t.length===0||t.some(e=>!Number.isInteger(e)||e<=0)||t.some((e,n)=>n>0&&e<=t[n-1]))throw Error(`Widths must be positive, unique, strictly ascending integers.`);return t}}),sr=r(f,{displayName:`profile`,async from(e){return ge(e)}}),cr=r(f,{displayName:`pack`,description:`Asset pack name, such as training-videos.`,async from(e){if(!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(e))throw Error(`Asset pack names must use lowercase hyphen-separated segments.`);return e}}),lr=r(f,{displayName:`origin`,description:`Exact production HTTPS API origin embedded in the packaged Flutter client.`,async from(e){return N(e)}}),ur=p({name:`assets`,cmds:{configure:n({name:`configure`,description:`Store a Backblaze B2 private build-object key in the operating system credential store. ${ar}`,args:{profile:u({type:sr,displayName:`profile`,description:`Credential profile named by coreframe.config.ts.`})},handler:async({profile:e})=>{z.note(ar,`Required B2 key access`);let t=await z.text({message:`Backblaze B2 application key ID`,validate:e=>e?.trim()?void 0:`The application key ID is required.`});if(z.isCancel(t))throw Error(`Asset credential configuration was cancelled.`);let n=await z.password({message:`Backblaze B2 application key`,validate:e=>e?void 0:`The application key is required.`});if(z.isCancel(n))throw Error(`Asset credential configuration was cancelled.`);await _e({applicationKey:n,applicationKeyId:t.trim(),profile:e}),console.log(`Stored Coreframe asset credential profile "${e}".`)}}),add:n({name:`add`,args:{file:u({type:f,displayName:`file`,description:`Source raster image, SVG, MP3, MP4, or Lottie JSON to add to the asset library.`}),id:c({long:`id`,type:f,description:`Logical asset ID, such as blog/my-post/hero.`}),alt:c({long:`alt`,type:l(f),description:`Required alt text for raster image and SVG assets.`}),pack:c({long:`pack`,type:l(cr),description:`Place the asset in a named, lazily loaded pack.`}),variantWidths:c({long:`widths`,type:l(or),description:`Generate exactly these raster-image widths instead of the default ladder.`}),json:i({long:`json`,description:`Print machine-readable JSON.`,defaultValue:()=>!1})},handler:async({alt:e,file:t,id:n,json:r,pack:i,variantWidths:a})=>me(await de({alt:e,file:t,id:n,pack:i,variantWidths:a}),r)}),build:n({name:`build`,args:{id:c({long:`id`,type:l(f),description:`Build only one logical asset ID.`}),pack:c({long:`pack`,type:l(cr),description:`Build only one named asset pack.`}),json:i({long:`json`,description:`Print machine-readable JSON.`,defaultValue:()=>!1})},handler:async({id:e,json:t,pack:n})=>me(await fe({id:e,pack:n}),t)}),check:n({name:`check`,args:{fix:i({long:`fix`,description:`Migrate asset state and build missing generated output when possible.`,defaultValue:()=>!1}),pack:c({long:`pack`,type:l(cr),description:`Check only one named asset pack.`}),json:i({long:`json`,description:`Print machine-readable JSON.`,defaultValue:()=>!1})},handler:async({fix:e,json:t,pack:n})=>{let r=await pe({fix:e,pack:n});me(r,t),r.ok||(process.exitCode=1)}}),publish:n({name:`publish`,args:{pack:c({long:`pack`,type:l(cr),description:`Publish only one named asset pack.`}),json:i({long:`json`,description:`Print machine-readable JSON.`,defaultValue:()=>!1})},handler:async({json:e,pack:t})=>{let n=await he({pack:t});me(n,e),n.ok||(process.exitCode=1)}}),status:n({name:`status`,args:{pack:c({long:`pack`,type:l(cr),description:`Report status for only one named asset pack.`}),json:i({long:`json`,description:`Print machine-readable JSON.`,defaultValue:()=>!1})},handler:async({json:e,pack:t})=>{let n=await pe({pack:t});me(n,e),n.ok||(process.exitCode=1)}})}}),dr=p({name:`flutter`,cmds:{acceptance:n({name:`acceptance`,description:`Run the complete packaged Flutter conformance gate on macOS.`,args:{apiOrigin:c({long:`api-origin`,env:`COREFRAME_API_ORIGIN`,type:lr,description:`Defaults to COREFRAME_API_ORIGIN.`})},handler:({apiOrigin:e})=>se({environment:{...process.env,COREFRAME_API_ORIGIN:e}})}),codegen:n({name:`codegen`,description:`Generate Flutter bridge contracts and Panda-backed Mix theme tokens.`,args:{check:i({long:`check`,description:`Fail when generated Flutter artifacts are missing or stale.`,defaultValue:()=>!1})},handler:({check:e})=>ae({check:e})}),prepare:n({name:`prepare`,description:`Build and package the React client for one Flutter platform.`,args:{platform:u({type:s(j),displayName:`platform`,description:`Flutter platform whose packaged client should be prepared.`}),apiOrigin:c({long:`api-origin`,env:`COREFRAME_API_ORIGIN`,type:lr,description:`Defaults to COREFRAME_API_ORIGIN.`})},handler:({apiOrigin:e,platform:t})=>M({apiOrigin:e,platform:t})}),check:n({name:`check`,description:`Reject missing, stale, modified, or incorrectly targeted Flutter assets.`,args:{platform:u({type:s(j),displayName:`platform`,description:`Flutter platform whose packaged client should be checked.`}),apiOrigin:c({long:`api-origin`,env:`COREFRAME_API_ORIGIN`,type:lr,description:`Defaults to COREFRAME_API_ORIGIN.`})},handler:({apiOrigin:e,platform:t})=>A({apiOrigin:e,platform:t})})}}),fr=p({name:`i18n`,cmds:{build:n({name:`build`,description:`Extract source messages or materialize an exact release catalog snapshot.`,args:{},handler:async()=>{await Un()}}),materialize:n({name:`materialize`,description:`Materialize the immutable i18n snapshot for an exact commit.`,args:{revision:c({long:`revision`,type:l(f),description:`Full commit SHA. Defaults to the checked-out commit.`})},handler:async({revision:e})=>{let t=await Kn({revision:e});t&&console.log(`Materialized i18n snapshot ${t.snapshot}.`)}}),prepare:n({name:`prepare`,description:`Fill missing translations, strictly compile, and publish an immutable tagged snapshot.`,args:{tag:c({long:`tag`,type:f,description:`Pushed v* release tag that points to the checked-out commit.`})},handler:async({tag:e})=>{let t=await Gn({tag:e});console.log(`${t.reused?`Reused`:`Published`} i18n snapshot ${t.snapshot}.`)}})}}),pr=G.platform===`win32`?`react-router.cmd`:`react-router`,mr=G.platform===`win32`?`panda.cmd`:`panda`;async function hr(e=G.cwd()){await vr(e),await _r(e,[`typegen`])}async function gr(e=G.cwd(),t=G.env,n){if((t.COREFRAME_PLATFORM??t.TAURI_ENV_PLATFORM??`web`)!==`web`)return;let r=P.resolve(e,`.coreframe/dashboard-build`),i=P.join(r,`client`),a=P.resolve(e,`dist/client/__dashboard`);await H(r,{force:!0,recursive:!0}),await yr(e,mr,[`build`],t),await _r(e,[`build`,...n?[`--mode`,n]:[]],t),await H(a,{force:!0,recursive:!0}),await B(P.dirname(a),{recursive:!0}),await Se(i,a,{recursive:!0})}async function _r(e,t,n=G.env){await yr(e,pr,t,n)}async function vr(e){await H(P.resolve(e,`dashboard/.react-router`),{force:!0,recursive:!0})}async function yr(e,t,n,r=G.env){await R(t,n,{cwd:P.resolve(e,`dashboard`),env:{...r,PATH:P.resolve(e,`node_modules/.bin`)+P.delimiter+(r.PATH??r.Path??``)},stdio:`inherit`})}const br=p({name:`dashboard`,cmds:{build:n({name:`build`,args:{mode:c({long:`mode`,type:l(f),description:`Vite environment mode used for the dashboard build.`})},handler:({mode:e})=>gr(void 0,void 0,e)}),typegen:n({name:`typegen`,args:{},handler:()=>hr()})}}),xr=/^[a-z0-9]+(?:-[a-z0-9]+)*$/u;function Sr(e,t){let n=wr(e,t);if(!Tr(n)||!Er(n,[`description`,`requires`,`routes`,`verifier`])||!Or(n.description)||n.requires!==void 0&&(!Array.isArray(n.requires)||!n.requires.every(Or))||n.verifier!==void 0&&!Or(n.verifier)||!Array.isArray(n.routes))throw Error(`${t} must contain a description string, routes array, and optional requires and verifier fields.`);let r=(n.requires??[]).map(e=>Cr(e));if(new Set(r).size!==r.length)throw Error(`${t} contains duplicate recipe requirements.`);let i=n.routes.map((e,n)=>{if(!Tr(e)||!Dr(e,[`path`,`router`,`when`])||!Or(e.path)||!Or(e.router)||!Or(e.when))throw Error(`${t} route ${n+1} must contain router, path, and when strings.`);return{path:e.path,router:e.router,when:e.when}}),a=i.map(e=>`${e.router}\0${e.path}`);if(new Set(a).size!==a.length)throw Error(`${t} contains a duplicate router and path pair.`);return{description:n.description,requires:r,routes:i,verifier:n.verifier}}function Cr(e){if(!xr.test(e))throw Error(`Recipe names use lowercase letters, numbers, and single hyphens.`);return e}function wr(e,t){try{return qe(e)}catch(e){throw Error(`Could not parse ${t}.`,{cause:e})}}function Tr(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Er(e,t){return Object.keys(e).every(e=>t.includes(e))}function Dr(e,t){let n=Object.keys(e).sort();return n.length===t.length&&n.every((e,n)=>e===t[n])}function Or(e){return typeof e==`string`&&e.length>0}const kr=`https://github.com/airlock-labs/coreframe.git`;function Ar(e,t){return K(`git`,e,{cwd:t,encoding:`utf8`})}function jr(e,t){let n=Ar(e,t);if(n.status!==0){let t=n.stderr.trim()||n.stdout.trim();throw Error(`Git command failed: git ${e.join(` `)}${t?`\n${t}`:``}`)}return n.stdout}function Mr(e,t){let n=Ar([`remote`,`get-url`,e],t);if(n.status===2)return null;if(n.status!==0){let t=n.stderr.trim()||n.stdout.trim();throw Error(`Could not inspect remote ${e}.${t?`\n${t}`:``}`)}return n.stdout.trim()}function Nr({cwd:e=process.cwd(),fetch:t=!0,remote:n=`template`}={}){if(n.length===0)throw Error(`Remote name must not be empty.`);jr([`rev-parse`,`--show-toplevel`],e);let r=Mr(n,e);if(r===null)jr([`remote`,`add`,n,kr],e),console.log(`Added ${n} remote: ${kr}`);else if(r===kr)console.log(`${n} remote already points at ${kr}`);else throw Error(`${n} remote points at ${r}, not ${kr}.\nChoose the intended template source before continuing, then update or rename the remote manually.`);t&&(jr([`fetch`,n,`--tags`,`--prune`],e),console.log(`Fetched ${n}.`))}const Pr=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/u;function Fr(e){return Pr.test(e)?`v${e}`:e}function Ir(e){return`${Fr(e)}:template`}function Lr(e,t){return`${Ir(e)}/${t}`}function Rr({cwd:e=process.cwd(),fetch:t=!0,remote:n=`template`,target:r}={}){let i=Hr(e),a=Kr(i,[`rev-parse`,`--show-toplevel`]),o=Fr(r??Ur(i));return Nr({cwd:a,fetch:t,remote:n}),{projectRoot:i,ref:o,repositoryRoot:a}}function zr(e,t,n){return Br(e,t,n).toString(`utf8`)}function Br(e,t,n){let r=`${t}:${n}`,i=K(`git`,[`show`,r],{cwd:e,encoding:`buffer`});if(i.status!==0)throw Error(`Could not read ${r}. ${qr([`show`,r],i)}`);return i.stdout}function Vr(e,t,n){let r=K(`git`,[`ls-tree`,`-r`,`--name-only`,`-z`,t,`--`,n],{cwd:e,encoding:`buffer`});if(r.status!==0)throw Error(qr([`ls-tree`,t,n],r));return r.stdout.toString(`utf8`).split(`\0`).filter(Boolean)}function Hr(e){let t=L(e);for(;;){let e=I(t,`package.json`),n=Gr(e);if(n!==void 0&&Wr(n,e).engines?.coreframe)return t;let r=F(t);if(r===t)throw Error(`Could not find a package.json with engines.coreframe.`);t=r}}function Ur(e){let t=I(e,`package.json`),n=Gr(t);if(n===void 0)throw Error(`Required file package.json does not exist.`);let r=Wr(n,t).engines?.coreframe;if(!r)throw Error(`package.json must declare an exact engines.coreframe recipe baseline.`);return r}function Wr(e,t){try{return JSON.parse(e)}catch(e){throw Error(`Could not parse ${t}.`,{cause:e})}}function Gr(e){try{return J(e,`utf8`)}catch(e){if(Jr(e)&&e.code===`ENOENT`)return;throw e}}function Kr(e,t){let n=K(`git`,t,{cwd:e,encoding:`utf8`});if(n.status!==0)throw Error(qr(t,n));return n.stdout.trim()}function qr(e,t){let n=t.stderr.toString(`utf8`).trim()||t.stdout.toString(`utf8`).trim();return`Git command failed: git ${e.join(` `)}${n?`\n${n}`:``}`}function Jr(e){return e instanceof Error&&`code`in e}const Yr=[{path:`package.json`,requirement:`retain the Coreframe Flutter JavaScript runtime used by src-flutter`,test:e=>e.includes(`"@coreframe/flutter-js"`)},{path:`coreframe.config.ts`,requirement:`enable web and at least one Flutter development platform`,test:Qr},{path:`src/api/client/app-origin.ts`,requirement:`allow the Flutter shell to provide its exact API origin`,test:e=>Zr(e,[`@coreframe/flutter-js/client`,`resolveAppOrigin`,`browserOrigin: location?.origin`])},{path:`src/api/worker/auth-config.ts`,requirement:`trust the exact Flutter authentication origins`,test:e=>Zr(e,[`appendFlutterAuthOrigins`,`appendFlutterAuthOrigins([], development)`])},{path:`src/api/worker/middleware/auth.ts`,requirement:`broker Flutter access tokens and accept only Flutter bearer origins`,test:e=>Zr(e,[`createFlutterAccessTokenResponse`,`isFlutterAuthOrigin(origin, import.meta.env.DEV)`,`readFlutterBearerToken`,`native && ctx.request.method !== "GET"`])&&!e.includes(`isNativeOrigin`)},{path:`src/api/worker/middleware/flutter-cors.ts`,requirement:`provide the Flutter packaged-origin CORS boundary`,test:e=>Zr(e,[`applyFlutterCors`,`handleFlutterCorsPreflight`,`flutterCorsMiddleware`])},{path:`src/api/worker/middleware/index.ts`,requirement:`apply Flutter CORS to ordinary Worker responses`,test:e=>e.includes(`flutterCorsMiddleware`)},{path:`src/web/app/flutter-shell/application.ts`,requirement:`configure the Flutter shell's app-owned query and session hooks`,test:e=>Zr(e,[`configureShellQueryFocus`,`authSessionHint`])},{path:`src/web/entry.client.tsx`,requirement:`load the package-owned Flutter development tools only for non-browser development`,test:e=>Zr(e,[`@coreframe/vite/flutter-devtools`,`import.meta.env.PLATFORM !== "web"`])}];function Xr(e){let t=[];for(let n of Yr){let r=I(e,n.path);if(!q(r)){t.push(`${n.path} is missing; it must ${n.requirement}.`);continue}let i=J(r,`utf8`);n.test(i)||t.push(`${n.path} must ${n.requirement}.`)}return t}function Zr(e,t){return t.every(t=>e.includes(t))}function Qr(e){let t=e.match(/\bplatforms\s*:\s*\[([\s\S]*?)\]/)?.[1];if(!t)return!1;let n=new Set([...t.matchAll(/(["'`])([^"'`]*)\1/g)].map(e=>e[2]));return n.has(`web`)&&[`ios`,`android`,`macos`].some(e=>n.has(e))}const $r=[{path:`package.json`,requirement:`declare the Tauri CLI, plugin-log, and Coreframe Tauri runtime packages`,test:e=>Q(e,[`"@tauri-apps/cli"`,`"@tauri-apps/plugin-log"`,`"@coreframe/tauri-js"`,`"@coreframe/tauri-plugin-auth-session"`])},{path:`src-tauri/Cargo.toml`,requirement:`declare Tauri, plugin-log, and Coreframe auth-session Rust dependencies`,test:e=>Q(e,[`tauri-build`,`tauri-plugin-log`,`coreframe-tauri-plugin-auth-session`])},{path:`src-tauri/src/main.rs`,requirement:`launch the project-owned Tauri Rust library`,test:e=>e.includes(`::run();`)},{path:`src-tauri/src/lib.rs`,requirement:`register plugin-log and the Coreframe auth-session broker`,test:e=>Q(e,[`tauri_plugin_log::Builder`,`coreframe_tauri_plugin_auth_session::init`,`VITE_APP_ORIGIN`])},{path:`src-tauri/build.rs`,requirement:`forward VITE_APP_ORIGIN and TAURI_DEV_HOST into the Rust build`,test:e=>Q(e,[`VITE_APP_ORIGIN`,`TAURI_DEV_HOST`])},{path:`src-tauri/capabilities/default.json`,requirement:`grant log and auth-session permissions to the main window`,test:e=>Q(e,[`"windows": ["main"]`,`"log:default"`,`"coreframe-tauri-plugin-auth-session:default"`])},{path:`vite.config.ts`,requirement:`define the Tauri runtime and platform environment and fixed native dev server`,test:e=>Q(e,[`env.host === "tauri"`,`"import.meta.env.TAURI"`,`"import.meta.env.PLATFORM"`,`TAURI_DEV_HOST`,`strictPort: true`])},{path:`src/vite-env.d.ts`,requirement:`type the Tauri runtime, platform, development origin, and packaged app origin`,test:e=>Q(e,[`PLATFORM: import("@coreframe/lib/shell").ShellPlatform`,`TAURI: boolean`,`TAURI_DEV_ORIGIN`,`VITE_APP_ORIGIN`])},{path:`react-router.config.ts`,requirement:`skip service-worker generation for non-browser hosts`,test:e=>Q(e,[`resolveCoreframeHost`,`resolveCoreframeHost() === "browser"`])},{path:`src/api/client/app-origin.ts`,requirement:`resolve browser and packaged application origins through the Tauri runtime`,test:e=>Q(e,[`@coreframe/tauri-js/client`,`browserOrigin: location?.origin`,`development: import.meta.env.DEV`,`packagedAppOrigin: import.meta.env.VITE_APP_ORIGIN`,`tauri: import.meta.env.TAURI`,`tauriDevelopmentOrigin: import.meta.env.TAURI_DEV_ORIGIN`])&&!e.includes(`resolveAppOrigin(import.meta.env`)},{path:`src/api/client/auth-fetch.ts`,requirement:`call the selected framework authentication composition`,test:e=>Q(e,[`createAuthenticatedFetch`,`refreshAccess`,`sessionHint: authSessionHint`])},{path:`src/api/client/auth-session-hint.ts`,requirement:`keep native session hints in memory until the credential broker revalidates`,test:e=>Q(e,[`import.meta.env.PLATFORM !== "web"`,`persistence: browserPersistence`,`return false`])},{path:`src/api/client/tauri-auth.ts`,requirement:`compose native API and Better Auth transports behind the virtual auth contract`,test:e=>Q(e,[`createAuthenticatedFetch`,`createTauriAuthenticatedFetch`,`authSessionHint: options.sessionHint`,`mintAccessToken`,`createAuthClient`,`createAuthFetch`,`onSessionChange: options.onSessionChange`])},{path:`src/web/auth/client.ts`,requirement:`call the selected framework Better Auth composition`,test:e=>Q(e,[`createAuthClient as createCoreframeAuthClient`,`createCoreframeAuthClient`,`authFetch`,`customFetchImpl`])},{path:`src/api/worker/middleware/auth.ts`,requirement:`mint and accept bearer access tokens only across the fixed native origin boundary`,test:e=>Q(e,[`appendTauriAppOrigins`,`createTauriAccessTokenResponse`,`isTauriAppOrigin`,`readTauriBearerToken`])},{path:`src/api/worker/fetch.ts`,requirement:`apply native CORS at every Worker response boundary`,test:e=>Q(e,[`handleTauriCorsPreflight`,`applyTauriCors`])},{path:`coreframe.config.ts`,requirement:`enable web and desktop development platforms`,test:e=>Q(e,[`platforms: ["web", "desktop"]`])&&!e.includes(`"ios"`)&&!e.includes(`"android"`)},{path:`src/web/entry.client.tsx`,requirement:`attach native development logs and skip service-worker registration in Tauri`,test:e=>Q(e,[`import "./dev/tauri-log.ts"`,`import.meta.env.TAURI`])},{path:`.env.example`,requirement:`document the packaged VITE_APP_ORIGIN build value`,test:e=>e.includes(`VITE_APP_ORIGIN`)},{path:`.gitignore`,requirement:`ignore the Tauri Cargo target directory`,test:e=>e.includes(`src-tauri/target`)},{path:`.oxfmtrc.json`,requirement:`ignore generated Tauri schemas and target output`,test:e=>Q(e,[`src-tauri/gen/schemas`,`src-tauri/target`])},{path:`src-tauri/AGENTS.md`,requirement:`route native work to owner-local rules and documentation`,test:e=>Q(e,[`.agents/rules/tauri.md`,`docs/authentication.md`,`docs/deployment.md`])},{path:`src-tauri/.agents/rules/tauri.md`,requirement:`install the owner-local durable Tauri native-boundary rule`,test:e=>Q(e,[`## Native Boundary`,`## Security`,`## Documentation`])},{path:`.agents/rules/integrations.yaml`,requirement:`route cross-boundary Tauri work to the owner-local native rule`,test:e=>e.includes(`src-tauri/.agents/rules/tauri.md`)},{path:`src-tauri/docs/authentication.md`,requirement:`document the native credential broker and bearer-token boundary`,test:e=>Q(e,[`@coreframe/tauri-js`,`@coreframe/tauri-plugin-auth-session`,`VITE_APP_ORIGIN`])},{path:`src-tauri/docs/development.md`,requirement:`document native development asset delivery and Leylines scopes`,test:e=>Q(e,[`dev.tauri`,`browser.tauri`,`managed asset`])},{path:`src-tauri/docs/deployment.md`,requirement:`document native release topology, signing, token recovery, and provider setup`,test:e=>Q(e,[`VITE_APP_ORIGIN`,`native-auth`,`access-token signing-secret`])},{path:`src-tauri/docs/privacy-security.md`,requirement:`record the shipped Tauri remote API and secure-storage boundary`,test:e=>Q(e,[`## Remote API Boundary`,`platform secure storage`])},{path:`.github/workflows/tauri-release-artifacts.yml`,requirement:`provide a desktop-only Tauri release-artifact workflow`,test:e=>Q(e,[`Build Tauri Release Artifacts`,`pnpm exec tauri`])&&!e.toLowerCase().includes(`ios`)&&!e.toLowerCase().includes(`android`)}],ei=[`CoreframeTemplateProject7A91C`,`coreframe-template-project-7a91c`,`coreframe_template_project_7a91c`,`com.example.coreframetemplateproject7a91c`];function ti(e){let t=[];for(let n of $r){let r=I(e,n.path);if(!q(r)){t.push(`${n.path} is missing; it must ${n.requirement}.`);continue}let i=J(r,`utf8`);n.test(i)||t.push(`${n.path} must ${n.requirement}.`)}let n=I(e,`src-tauri/tauri.conf.json`);q(n)?ni(n,t):t.push(`src-tauri/tauri.conf.json is missing.`);for(let n of[`src-tauri/Cargo.toml`,`src-tauri/src/main.rs`,`src-tauri/tauri.conf.json`]){let r=I(e,n);q(r)&&ei.some(e=>J(r,`utf8`).includes(e))&&t.push(`${n} must replace the Coreframe template identity sentinel.`)}return t}function ni(e,t){let n;try{n=JSON.parse(J(e,`utf8`))}catch{t.push(`src-tauri/tauri.conf.json must contain valid JSON.`);return}(typeof n.identifier!=`string`||!/^[a-z0-9]+(?:\.[a-z0-9]+){2,}$/.test(n.identifier)||n.identifier.startsWith(`com.example.`))&&t.push(`src-tauri/tauri.conf.json must use an organization-owned reverse-domain identifier.`)}function Q(e,t){return t.every(t=>e.includes(t))}function ri({name:e,...t}){let n=Rr(t),r=`recipes/${e}/recipe.yaml`,i=oi(Sr(zr(n.repositoryRoot,n.ref,r),r).verifier,n.projectRoot);if(i.length>0)throw Error(`Recipe ${e} verification failed:\n${i.map(e=>`- ${e}`).join(`
|
|
6
6
|
`)}`);return{name:e,ref:n.ref}}function ii(e){console.log(`Verified Coreframe recipe ${e.name} from ${e.ref}.`)}function ai(e,t){for(let n of e){let e=`recipes/${n}/recipe.yaml`,r=oi(Sr(zr(t.repositoryRoot,t.ref,e),e).verifier,t.projectRoot);if(r.length>0)throw Error(`Recipe ${n} is required but is not fully applied:\n${r.map(e=>`- ${e}`).join(`
|
|
7
7
|
`)}\nApply and verify ${n} before continuing.`)}}function oi(e,t){if(!e)throw Error(`Required recipe does not declare a verifier.`);if(e===`tauri`)return ti(t);if(e===`flutter`)return Xr(t);throw Error(`Unknown recipe verifier ${JSON.stringify(e)}.`)}function si({cwd:e=process.cwd(),fetch:t=!0,name:n,remote:r=`template`,target:i}){Cr(n);let a=Rr({cwd:e,fetch:t,remote:r,target:i}),{projectRoot:o,ref:s,repositoryRoot:c}=a,l=`recipes/${n}`,u=`${l}/recipe.yaml`,d=Sr(zr(c,s,u),u);ai(d.requires,a);let f=zr(c,s,`${l}/RECIPE.md`),p=Vr(c,s,`${l}/files`),m=Vr(c,s,`${l}/patches`),h=Vr(c,s,`${l}/.agents`),g=new Map,_=new Map,v=[],y=[],b=[],x=[],S=[],C=[];for(let e of p){let t=e.slice(`${l}/files/`.length);if(mi(t,`Recipe file ${e}`),t.startsWith(`.agents/`))throw Error(`Recipe file ${e} must be stored in the recipe's .agents directory.`);g.set(t,Br(c,s,e)),_.set(t,e)}for(let e of h){let t=e.slice(`${l}/`.length);if(di(t,`Recipe asset ${e}`),g.has(t))throw Error(`Recipe declares ${t} as both a file and an agent asset.`);g.set(t,Br(c,s,e)),_.set(t,e)}for(let e of m){let t=hi(e,l);if(g.has(t))throw Error(`Recipe declares ${t} as both a file and a patch.`);let n=Br(c,s,e);gi(n.toString(`utf8`),t,e),pi(o,t),_i(o,n,!1)?(v.push({contents:n,destinationPath:t}),x.push(t)):_i(o,n,!0)?S.push(t):b.push({destination:t,source:e})}let w=new Map;for(let[e,t]of g){let r=bi(pi(o,e));if(r===void 0)w.set(e,t),y.push(e);else if(r.equals(t))S.push(e);else if(e.startsWith(`.agents/`))throw Error(`Recipe ${n} cannot replace modified ${e}. Reconcile that agent asset manually.`);else b.push({destination:e,source:_.get(e)})}let T=new Map;for(let e of d.routes){if(di(e.router,`Recipe route router`),fi(e.path,`Recipe route path`),g.has(e.router))throw Error(`Recipe cannot replace its destination router ${e.router}.`);if(!g.has(e.path)&&!q(pi(o,e.path)))throw Error(`Recipe route target ${e.path} does not exist.`);let t=T.get(e.router)??li(xi(pi(o,e.router),e.router),e.router);T.set(e.router,t);let r=t.routes.find(t=>t.path===e.path);if(r){if(r.when!==e.when)throw Error(`Recipe ${n} route ${e.path} conflicts with the existing trigger in ${e.router}.`);continue}t.routes.push({path:e.path,when:e.when})}for(let[e,t]of T){t.routes.sort((e,t)=>e.path<t.path?-1:+(e.path>t.path));let n=xi(pi(o,e),e),r=Je(t,{lineWidth:0});r===n?S.push(e):(w.set(e,r),C.push(e))}for(let{destinationPath:e}of v)if(w.has(e))throw Error(`Recipe cannot both write and patch ${e}.`);for(let[e,t]of w){let n=pi(o,e);Ve(F(n),{recursive:!0}),Ke(n,t)}return v.length>0&&vi(o,v.map(({contents:e})=>e)),{created:y.sort(),instructions:f,mergeRequired:b.sort((e,t)=>e.destination.localeCompare(t.destination)),name:n,patched:x.sort(),ref:s,unchanged:[...new Set(S)].sort(),updated:C.sort()}}function ci(e){console.log(`Prepared Coreframe recipe ${e.name} from ${e.ref}.`);for(let t of e.created)console.log(`created: ${t}`);for(let t of e.updated)console.log(`updated: ${t}`);for(let t of e.patched)console.log(`patched: ${t}`);for(let t of e.mergeRequired)console.log(`merge-required: ${t.destination} (source: ${e.ref}:${t.source})`);for(let t of e.unchanged)console.log(`unchanged: ${t}`);console.log(`\nContinue by following ${e.ref}:recipes/${e.name}/RECIPE.md:\n`),console.log(e.instructions.trimEnd())}function li(e,t){let n=ui(e,t);if(!Si(n)||!Ci(n,[`routes`,`rules`])||!Array.isArray(n.rules)||!n.rules.every(wi)||!Array.isArray(n.routes))throw Error(`${t} must contain only string rules and a routes array.`);let r=n.routes.map((e,n)=>{if(!Si(e)||!Ci(e,[`path`,`when`])||!wi(e.path)||!wi(e.when))throw Error(`${t} route ${n+1} must contain path and when strings.`);return{path:e.path,when:e.when}}),i=r.map(e=>e.path);if(new Set(i).size!==i.length)throw Error(`${t} contains duplicate route paths.`);return{rules:n.rules,routes:r}}function ui(e,t){try{return qe(e)}catch(e){throw Error(`Could not parse ${t}.`,{cause:e})}}function di(e,t){if(!e.startsWith(`.agents/`))throw Error(`${t} must be a normalized project-relative path beneath .agents/.`);mi(e,t)}function fi(e,t){if(mi(e,t),!/(?:^|\/)\.agents\/rules\/.+\.md$/u.test(e))throw Error(`${t} must point to a Markdown rule beneath an .agents/rules directory.`)}function pi(e,t){mi(t,`Recipe destination`);let n=I(e,t),r=e;for(let e of t.split(`/`))if(r=I(r,e),q(r)&&Be(r).isSymbolicLink())throw Error(`Recipe destination ${t} crosses symbolic link ${r}.`);return n}function mi(e,t){if(e.length===0||ce(e)||e===`..`||e.startsWith(`../`)||e.includes(`\\`)||le.normalize(e)!==e)throw Error(`${t} must be a normalized project-relative path.`)}function hi(e,t){let n=e.slice(`${t}/patches/`.length);if(!n.endsWith(`.patch`))throw Error(`Recipe patch ${e} must use a .patch suffix.`);let r=n.slice(0,-6);return mi(r,`Recipe patch ${e}`),r}function gi(e,t,n){let r=e.match(/^diff --git .+$/gmu)??[],i=e.match(/^--- .+$/gmu)??[],a=e.match(/^\+\+\+ .+$/gmu)??[];if(r.length!==1||r[0]!==`diff --git a/${t} b/${t}`||i.length!==1||a.length!==1||i[0]!==`--- a/${t}`||a[0]!==`+++ b/${t}`||/^(?:deleted file mode |GIT binary patch$|new file mode |rename from |rename to )/mu.test(e))throw Error(`Recipe patch ${n} must modify only ${t}.`)}function _i(e,t,n){let r=[`apply`,`--check`,`--whitespace=nowarn`];return n&&r.push(`--reverse`),r.push(`-`),K(`git`,r,{cwd:e,input:t}).status===0}function vi(e,t){let n=K(`git`,[`apply`,`--whitespace=nowarn`,`-`],{cwd:e,input:Buffer.concat(t.flatMap(e=>[e,Buffer.from(e.at(-1)===10?``:`
|
|
8
8
|
`)])),encoding:`utf8`});if(n.status!==0){let e=n.stderr.trim()||n.stdout.trim();throw Error(`Could not apply recipe patches.${e?`\n${e}`:``}`)}}function yi(e){return bi(e)?.toString(`utf8`)}function bi(e){try{return J(e)}catch(e){if(Ti(e)&&e.code===`ENOENT`)return;throw e}}function xi(e,t){let n=yi(e);if(n===void 0)throw Error(`Required file ${t} does not exist.`);return n}function Si(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Ci(e,t){let n=Object.keys(e).sort();return n.length===t.length&&n.every((e,n)=>e===t[n])}function wi(e){return typeof e==`string`&&e.length>0}function Ti(e){return e instanceof Error&&`code`in e}function Ei(e={}){let{ref:t,repositoryRoot:n}=Rr(e),r=Vr(n,t,`recipes`).filter(e=>/^recipes\/[^/]+\/recipe\.yaml$/u.test(e)).map(e=>{let r=e.split(`/`)[1];return Cr(r),{description:Sr(zr(n,t,e),e).description,name:r}});return r.sort((e,t)=>e.name.localeCompare(t.name)),{recipes:r,ref:t}}function Di(e){console.log(`Coreframe recipes at ${e.ref}:`);for(let t of e.recipes)console.log(`${t.name} — ${t.description}`)}const Oi=`.agents/skills/coreframe-upgrade/SKILL.md`;function ki(e,t={}){return K(`git`,e,t)}function Ai(e){return e.stderr.toString(`utf8`).trim()||e.stdout.toString(`utf8`).trim()}function ji(e,t){let n=Lr(e,t),r=ki([`show`,n],{encoding:`utf8`});if(r.status!==0){let e=Ai(r);throw Error(`Could not read ${n}.${e?` ${e}`:``}`)}return r.stdout.toString()}function Mi(){let e=ki([`rev-parse`,`--show-toplevel`],{encoding:`utf8`});if(e.status!==0){let t=Ai(e);throw Error(`Could not find git repository root.${t?` ${t}`:``}`)}return e.stdout.toString().trim()}function Ni(e,t){let n=He(I(Me(),`coreframe-upgrade-skill-`)),r=I(n,`SKILL.md`);try{Ke(r,t);let n=Ai(ki([`--no-pager`,`diff`,`--no-index`,`--color=never`,`--`,e,r]));n&&console.log(n)}finally{We(n,{force:!0,recursive:!0})}}function Pi({apply:e,target:t}){let n=I(Mi(),Oi),r=Fr(t);if(!q(n))throw Error(`Local ${Oi} does not exist.`);let i=J(n,`utf8`),a=ji(t,Oi);return i===a?(console.log(`Coreframe upgrade skill matches ${r}:template/${Oi}.`),0):e?(Ke(n,a),console.error(`Updated ${Oi} from ${r}:template. Reread it before continuing the upgrade.`),20):(console.error(`Coreframe upgrade skill differs from ${r}:template/${Oi}.`),console.error(`Run again with --apply to update it, then reread ${Oi} before continuing.`),Ni(n,a),20)}const Fi=[{matches:e=>e===`drizzle`||e.startsWith(`drizzle/`),reason:`project-owned migration history`},{matches:e=>e===`drizzle-hold`||e.startsWith(`drizzle-hold/`),reason:`project-owned migration history`},{matches:e=>e===`src/web/routes.ts`||e.startsWith(`src/web/app/routes/`),reason:`downstream-owned demonstration routes`},{matches:e=>e===`pnpm-lock.yaml`||e===`src-tauri/Cargo.lock`,reason:`downstream-owned dependency lockfile`}],Ii=new Set([`100644`,`100755`,`120000`]);function Li(e,t={}){return K(`git`,e,t)}function Ri(e){let t=Li(e,{encoding:`utf8`});if(t.status!==0){let n=t.stderr.toString().trim()||t.stdout.toString().trim();throw Error(`Git command failed: git ${e.join(` `)}${n?`\n${n}`:``}`)}return t.stdout.toString()}function zi(e){let t=Li(e);if(t.status!==0){let n=t.stderr.toString(`utf8`).trim()||t.stdout.toString(`utf8`).trim();throw Error(`Git command failed: git ${e.join(` `)}${n?`\n${n}`:``}`)}return t.stdout}function Bi(){return Ri([`rev-parse`,`--show-toplevel`]).trim()}function Vi(e){let t=I(e,`package.json`);if(!q(t))throw Error(`Missing --base <git-ref>, and package.json does not exist.`);let n=JSON.parse(J(t,`utf8`)).engines?.coreframe;if(typeof n!=`string`||n.length===0)throw Error(`Missing --base <git-ref>, and package.json engines.coreframe is not set.`);return n}function Hi(e){let t=[],n=0;for(let r=0;r<e.length;r+=1)e[r]===0&&(t.push(e.subarray(n,r).toString(`utf8`)),n=r+1);return t.filter(e=>e.length>0)}function Ui(e,t){let n=Hi(zi([`diff`,`--name-status`,`-z`,`--no-renames`,Ir(e),Ir(t),`--`])),r=[];for(let e=0;e<n.length;e+=2){let t=n[e],i=n[e+1];if(!t||!i)throw Error(`Could not parse git diff --name-status output.`);r.push({path:i,status:t})}return r}function Wi(e,t){let n=zi([`ls-tree`,`-z`,Ir(e),`--`,t]);if(n.length===0)return null;let r=Hi(n)[0],i=r.indexOf(` `);if(i===-1)throw Error(`Could not parse git ls-tree output for ${e}:${t}.`);let[a,o,s]=r.slice(0,i).split(` `);if(!a||!o||!s)throw Error(`Could not parse git ls-tree metadata for ${e}:${t}.`);return{mode:a,object:s,path:t,type:o}}function Gi(e){return zi([`cat-file`,`blob`,e.object])}function Ki(e,t){let n=L(e,t),r=e.endsWith(ue)?e:`${e}${ue}`;if(n!==e&&!n.startsWith(r))throw Error(`Refusing to access path outside repository: ${t}`);return n}function qi(e){try{return Be(e),!0}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return!1;throw e}}function Ji(e){return(e.mode&73)!=0}function Yi(e){return e===null||e.type===`blob`&&Ii.has(e.mode)}function Xi(e){return Fi.find(t=>t.matches(e))?.reason}function Zi(e,t,n){let r=Ki(e,t);if(n===null)return{matches:!qi(r)};if(!Yi(n))return{matches:!1,reason:`unsupported template entry mode ${n.mode} ${n.type}`};let i;try{i=Be(r)}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return{matches:!1,reason:`path is missing from worktree`};throw e}let a=Gi(n);return n.mode===`120000`?i.isSymbolicLink()?{matches:Buffer.from(Ue(r),`utf8`).equals(a)}:{matches:!1,reason:`worktree path is not a symlink`}:i.isFile()?(n.mode===`100755`?Ji(i):!Ji(i))?{matches:J(r).equals(a)}:{matches:!1,reason:`worktree executable bit differs from template`}:{matches:!1,reason:`worktree path is not a regular file`}}function Qi(e){qi(e)&&We(e,{force:!0,recursive:!1})}function $i(e,t,n){let r=Ki(e,t);if(n===null){Qi(r);return}if(Ve(F(r),{recursive:!0}),n.mode===`120000`){Qi(r),Ge(Gi(n).toString(`utf8`),r);return}let i=qi(r)?Be(r):null;i&&!i.isFile()&&Qi(r),Ke(r,Gi(n)),ze(r,n.mode===`100755`?493:420)}function ea(e,t){return e===null&&t!==null?`add`:e!==null&&t===null?`delete`:`update`}function ta(e,t){if(t.length!==0){console.log(`${e}:`);for(let e of t){let t=e.reason?` (${e.reason})`:``;console.log(` ${e.action}: ${e.path}${t}`)}console.log(``)}}function na(e){let t=Bi(),n=Fr(e.base??Vi(t)),r=Fr(e.target),i=Ui(n,r),a=[],o=[],s=[],c=[];for(let e of i){let i=Xi(e.path);if(i){o.push({action:`ignored`,path:e.path,reason:i});continue}let l=Wi(n,e.path),u=Wi(r,e.path),d=ea(l,u);if(!Yi(l)||!Yi(u)){s.push({action:d,path:e.path,reason:`unsupported template entry type`});continue}if(Zi(t,e.path,u).matches){c.push({action:`unchanged`,path:e.path});continue}let f=Zi(t,e.path,l);if(!f.matches){s.push({action:d,path:e.path,reason:f.reason??`downstream differs from base template`});continue}a.push({action:d,path:e.path,targetEntry:u})}if(e.apply)for(let e of a)$i(t,e.path,e.targetEntry??null);console.log(`Coreframe template fast-forward: ${n} -> ${r}`),console.log(``),ta(e.apply?`Applied clean template updates`:`Would apply clean template updates`,a),ta(`Ignored downstream-owned paths`,o),ta(`Skipped for agent review`,s),c.length>0&&console.log(`${c.length} changed template path(s) already matched the target state.`),i.length===0&&console.log(`No template file changes found in the requested range.`),!e.apply&&a.length>0&&(console.log(``),console.log(`Run with --apply to write the ${a.length} clean update(s).`))}const ra=[`dependencies`,`devDependencies`];function ia(e){let t=K(`git`,e,{encoding:`utf8`});if(t.status!==0){let n=t.stderr.trim()||t.stdout.trim();throw Error(`Git command failed: git ${e.join(` `)}${n?`\n${n}`:``}`)}return t.stdout}function aa(e,t){try{return JSON.parse(e)}catch(e){throw Error(`Could not parse ${t}: ${e instanceof Error?e.message:e}`)}}function oa(e,t){let n=`${Fr(e)}:${t}`;return aa(ia([`show`,n]),n)}function sa(e){return e.startsWith(`@coreframe/`)}function ca(e){return e.startsWith(`file:`)||e.startsWith(`link:`)||e.startsWith(`workspace:`)}function la(e){return e.startsWith(`file:`)||e.startsWith(`link:`)}function ua(e,t){let n=e.indexOf(`:`),r=e.slice(n+1),i=le.normalize(le.join(`template`,r,`package.json`));if(r.length===0||le.isAbsolute(r)||i===`..`||i.startsWith(`../`))throw Error(`Invalid local template dependency for ${t}: ${e}`);return i}function da(e){let t=oa(e,`template/package.json`),n=[],r=new Set;for(let i of ra)for(let[a,o]of Object.entries(t[i]??{})){if(!sa(a)||!la(o))continue;if(r.has(a))throw Error(`Target template declares ${a} more than once.`);let t=ua(o,a),s=oa(e,t);if(s.name!==a||typeof s.version!=`string`)throw Error(`${Fr(e)}:${t} must declare ${a} with a version.`);n.push({group:i,name:a,spec:`^${s.version}`}),r.add(a)}return n}function fa(e,t){for(let n of ra){let r=e[n]?.[t];if(r)return{group:n,spec:r}}}function pa(e,t,n){let r=t.match(/\n([\t ]+)"/u)?.[1]??` `,i=t.endsWith(`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coreframe/scripts",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9",
|
|
4
4
|
"description": "Coreframe project workflow CLI and automation scripts",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -28,15 +28,15 @@
|
|
|
28
28
|
"nano-spawn": "^2.1.0",
|
|
29
29
|
"procband": "^0.3.8",
|
|
30
30
|
"yaml": "^2.9.0",
|
|
31
|
+
"@coreframe/db": "^0.1.3",
|
|
31
32
|
"@coreframe/deploy": "^0.1.3",
|
|
32
|
-
"@coreframe/assets": "^0.1.6",
|
|
33
33
|
"@coreframe/dev": "^0.1.5",
|
|
34
|
-
"@coreframe/config": "^0.1.3",
|
|
35
34
|
"@coreframe/dev-contracts": "^0.1.2",
|
|
36
35
|
"@coreframe/flutter-tools": "^0.1.7",
|
|
36
|
+
"@coreframe/assets": "^0.1.6",
|
|
37
37
|
"@coreframe/object-storage": "^0.1.1",
|
|
38
|
-
"@coreframe/
|
|
39
|
-
"@coreframe/
|
|
38
|
+
"@coreframe/config": "^0.1.3",
|
|
39
|
+
"@coreframe/preview": "^0.1.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/node": "^26.1.0",
|