@coreframe/scripts 0.2.11 → 0.2.12
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 +4 -4
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 _,createProjectPostgresDatabaseAdapter as v,createProjectSqliteDatabaseAdapter as y,ensureLocalDb as b,filterPendingMigrations as x,formatDbErrorMessage as S,formatMigrationList as C,formatMigrationScanFailures as w,migrateHeldMigrations as T,migrateLocalDb as E,readAppliedMigrationNames as D,resetLocalDb as ee,runDrizzleKitCommand as O,scanDeployMigrationFiles as k,seedLocalDb as te,setupLocalDb as ne,startProjectPostgres as A,startProjectTurso as re,stopProjectPostgres as ie}from"@coreframe/db";import{checkFlutterClient as j,ensureFlutterDevAssetDirectories as ae,flutterPlatforms as M,generateFlutterNativeBridge as oe,prepareFlutterClient as N,prepareFlutterDevOutput as se,productionApiOrigin as P,runFlutterAcceptance as ce}from"@coreframe/flutter-tools";import F,{dirname as I,isAbsolute as le,join as L,posix as ue,resolve as R,sep as de}from"node:path";import z from"nano-spawn";import*as B from"@clack/prompts";import{addAsset as fe,buildAssets as pe,checkAssets as me,printAssetResult as he,publishAssets as ge}from"@coreframe/assets";import{assertAssetCredentialProfile as _e,configureAssetCredentials as ve,createB2PrivateObjectStore as ye}from"@coreframe/object-storage";import{access as be,chmod as xe,copyFile as Se,cp as Ce,link as we,mkdir as V,mkdtemp as Te,readFile as H,readdir as Ee,realpath as De,rename as Oe,rm as U,stat as ke,unlink as Ae,writeFile as W}from"node:fs/promises";import{homedir as je,networkInterfaces as Me,tmpdir as Ne}from"node:os";import{importProjectDependency as Pe,importProjectModule as Fe,normalizeWorkerEnvironment as Ie,readProjectConfig as Le,wranglerEnvironmentNames as Re}from"@coreframe/config";import{createHash as ze,randomUUID as G}from"node:crypto";import K from"node:process";import{spawnSync as q}from"node:child_process";import{chmodSync as Be,existsSync as J,lstatSync as Ve,mkdirSync as He,mkdtempSync as Ue,readFileSync as Y,readlinkSync as We,rmSync as Ge,symlinkSync as Ke,writeFileSync as qe}from"node:fs";import{parse as Je,stringify as Ye}from"yaml";import{accessTokenSigningSecretName as Xe,clearAppliedPendingWorkerSecrets as Ze,deployEnvironments as Qe,discardPendingWorkerSecret as $e,discoverStagingUrl as et,inspectWorkerEnvironment as tt,materializePrimaryWorkerConfig as nt,materializePrimaryWorkerTypeConfig as rt,parseDeclaredWorkerSecretEnv as it,parseTauriReleasePlatform as at,prepareAccessTokenSigningSecret as ot,prepareTauriRelease as st,queueWorkerSecret as ct,queueWorkerSecrets as lt,readDeclaredWorkerSecrets as ut,readPackageJson as dt,readPendingWorkerSecretSnapshot as ft,reassignStagingHostname as pt,releaseName as mt,resolveDeployConfig as ht,resolveReleaseVersion as gt,resolveTauriReleasePlan as _t,restoreTauriReleaseMetadata as vt,rotateAccessTokenSigningSecret as yt,runAfterWorkerDeploy as bt,runPostDeployChecks as xt,tauriReleasePlatforms as St,uploadTauriReleaseToB2 as Ct,validateTauriReleasePlan as wt,validateWorkerEnvironmentForDeploy as Tt,verifyAccessTokenSigningSecret as Et,writePackageVersion as Dt,writeTauriReleaseMetadata as Ot}from"@coreframe/deploy";import{connectDevSupervisor as kt,createDevStartupTiming as At,devHttpsCertEnv as jt,devHttpsKeyEnv as Mt,isManagedDevCheckout as Nt,isPrimaryCheckout as Pt,prepareDevHttps as Ft,stopDevSupervisor as It}from"@coreframe/dev";import{inspect as Lt,parseEnv as Rt}from"node:util";import{once as zt}from"node:events";import{finished as Bt}from"node:stream/promises";import{codexTaskEnv as Vt}from"@coreframe/dev-contracts/codex-task";import{managedDevEnv as Ht}from"@coreframe/dev-contracts/managed-dev";import{createPrefixStream as Ut,supervise as Wt}from"procband";import{createConnection as Gt,createServer as Kt}from"node:net";import{setTimeout as qt}from"node:timers/promises";import{determineAgent as Jt}from"@vercel/detect-agent";import{runPreview as Yt}from"@coreframe/preview";const Xt=[`web`,...M];function Zt(e=`web`,{apiOrigin:t,cwd:n=process.cwd(),simulator:r=!1}={}){if(nn(e,r),e===`web`)return[an(`pnpm`,[`build`],n,{COREFRAME_PLATFORM:`web`})];let i=P(t);return[{kind:`prepare`,platform:e},an(`flutter`,Qt(e,i,{simulator:r}),R(n,`src-flutter`),{COREFRAME_API_ORIGIN:i})]}function Qt(e,t,{noCodesign:n=e===`macos`,simulator:r=!1}={}){nn(e,r);let i=P(t);return[`build`,e===`android`?`apk`:e,`--release`,...r?[`--simulator`]:[],...n?[`--no-codesign`]:[],`--dart-define=COREFRAME_API_ORIGIN=${i}`]}function $t(e){let t=R(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 en(e,{simulator:t=!1}={}){let n=R(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 tn({apiOrigin:e,cwd:t=process.cwd(),environment:n=process.env,platform:r=`web`,simulator:i=!1,prepareClient:a=N,runCommand:o=rn}={}){nn(r,i);let s={...n};delete s.COREFRAME_PLATFORM,delete s.TAURI_ENV_PLATFORM;let c=r===`web`?void 0:P(e??n.COREFRAME_API_ORIGIN);for(let e of Zt(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($t(t)):r===`ios`&&console.log(en(t,{simulator:i}))}function nn(e,t){if(t&&e!==`ios`)throw Error(`The --simulator flag is only supported for the iOS build target.`)}async function rn(e,t,{cwd:n,env:r}){await z(e,t,{cwd:n,env:r,stdio:`inherit`})}function an(e,t,n,r){return{kind:`command`,command:e,args:t,cwd:n,...r===void 0?{}:{environment:r}}}const on=r(f,{displayName:`origin`,description:`Exact production HTTPS API origin embedded in a packaged Flutter client.`,async from(e){return P(e)}}),sn=n({name:`build`,description:`Build the web client or a release Flutter app. Tauri is not built.`,args:{platform:u({type:l(s(Xt)),displayName:`platform`,description:`Build target: web, iOS, Android, or macOS. Defaults to web.`}),apiOrigin:c({long:`api-origin`,type:l(on),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})=>tn({apiOrigin:e,platform:t,simulator:n})}),cn=/^[a-f0-9]{64}$/,ln=/^[a-f0-9]{40}$/,un=/^[A-Za-z0-9][A-Za-z0-9._-]*$/;function dn(e){if(!cn.test(e))throw Error(`Invalid SHA-256 digest "${e}".`);return e}function fn(e){if(!ln.test(e))throw Error(`Invalid full Git revision "${e}".`);return e}function pn(e,t){if(!un.test(e))throw Error(`${t} must contain only letters, numbers, dots, underscores, or hyphens.`);return e}function mn(e){return`projects/${pn(e,`Project ID`)}/i18n/v1`}function hn(e,t){return dn(t),`${mn(e)}/objects/sha256/${t.slice(0,2)}/${t}`}function gn(e,t){return fn(t),`${mn(e)}/commits/${t}.json`}function _n(e,t){return vn(t),`${mn(e)}/releases/${encodeURIComponent(t)}.json`}function vn(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=R(e),r=R(n,t);if(r!==n&&!r.startsWith(`${n}${de}`))throw Error(`Unsafe i18n artifact path "${t}".`);return r}function Z(e,t,n){return`${e.directory}/${t}/${n}.json`}function yn(e,t,n){return`${e.directory}/${t}/${n}.mjs`}async function bn(e){await z(`pnpm`,[`exec`,`lingui`,`extract`],{cwd:e,stdio:`inherit`})}async function xn({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 En(o),c=Object.fromEntries(Object.entries(s).filter(([,e])=>!e.obsolete)),l=L(r,`${n}-${a}.json`);await V(I(l),{recursive:!0}),await Se(o,l),i.push({path:o,backup:l}),await Dn(o,c)}await z(`pnpm`,[`exec`,`lingui`,`compile`,...n?[`--strict`]:[]],{cwd:t,stdio:`inherit`})}finally{try{for(let{path:e,backup:t}of i)await Se(t,e)}finally{for(let n of e.locales)for(let r of e.catalogs)await U(X(t,yn(e,n,r)),{force:!0})}}}async function Sn({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 En(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)=>Mn(e).localeCompare(Mn(t)))}async function Cn({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 On(await kn({args:e.generator.args??[],command:e.generator.command,cwd:t,env:r,input:JSON.stringify(i)}))}async function wn({config:e,cwd:t,missing:n,response:r}){let i=new Map(n.map(e=>[Mn(e),e])),a=new Map;for(let e of r.translations){let t=Mn(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 Pe(`@lingui/message-utils/compileMessage`,t);for(let e of n){let t=a.get(Mn(e));An({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 En(i),s=!1;for(let[e,t]of Object.entries(o)){let i=a.get(Mn({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 Dn(i,o)}}async function Tn({config:e,cwd:t}){let n=await Sn({config:e,cwd:t});if(n.length>0)throw Error(`I18n catalogs remain incomplete: ${n.length} translations are missing.`);let r=await Pe(`@lingui/message-utils/compileMessage`,t);for(let n of e.locales)if(n!==e.sourceLocale)for(let i of e.catalogs){let a=await En(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}.`);An({compileMessage:r,id:e,locale:n,source:t.message,translation:t.translation})}}}async function En(e){let t=JSON.parse(await H(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 Dn(e,t){await V(I(e),{recursive:!0});let n=`${e}.${process.pid}.tmp`;await W(n,`${JSON.stringify(t,null,2)}\n`),await Oe(n,e)}function On(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 kn({args:e,command:t,cwd:n,env:r,input:i}){return z(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 An({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=jn(a),c=jn(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 jn(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 Mn(e){return`${e.locale}\0${e.catalog}\0${e.id}`}function Nn(e){return ze(`sha256`).update(e).digest(`hex`)}async function Pn(e){return Nn(await H(e))}function Fn(e){return Buffer.from(`${JSON.stringify(e,null,2)}\n`)}async function In({bucket:e,digest:t,projectId:n,source:r,store:i}){if(dn(t),await Pn(r)!==t)throw Error(`I18n object source does not match declared SHA-256 digest ${t}.`);let a=hn(n,t);await i.has(e,a)||await i.upload(e,a,r,`application/octet-stream`);let o=`${r}.${process.pid}.${G()}.verify`;try{if(await i.download(e,a,o),await Pn(o)!==t)throw Error(`Existing immutable i18n object ${a} failed integrity verification.`)}finally{await U(o,{force:!0})}}async function Ln({bucket:e,key:t,reference:n,store:r,temporaryDirectory:i}){let a=Fn(n),o=L(i,`reference-${G()}.json`);if(await r.has(e,t))try{if(await r.download(e,t,o),!(await H(o)).equals(a))throw Error(`Immutable i18n reference ${t} already resolves to different snapshot data.`);return}finally{await U(o,{force:!0})}await W(o,a,{flag:`wx`});try{await r.upload(e,t,o,`application/json`)}finally{await U(o,{force:!0})}let s=L(i,`reference-${G()}.verify.json`);try{if(await r.download(e,t,s),!(await H(s)).equals(a))throw Error(`Uploaded immutable i18n reference ${t} failed verification.`)}finally{await U(s,{force:!0})}}async function Rn({bucket:e,manifest:t,projectId:n,store:r,temporaryDirectory:i}){let a=Fn(t),o=Nn(a),s=L(i,`manifest-${o}.json`);await W(s,a,{flag:`wx`});try{await In({bucket:e,digest:o,projectId:n,source:s,store:r})}finally{await U(s,{force:!0})}return o}async function zn({bucket:e,key:t,store:n,temporaryDirectory:r}){if(!await n.has(e,t))return;let i=L(r,`reference-${G()}.json`);try{await n.download(e,t,i);let r=JSON.parse(await H(i,`utf8`));if(r.version!==1||typeof r.revision!=`string`||typeof r.snapshot!=`string`)throw Error(`Invalid i18n reference at ${t}.`);return fn(r.revision),dn(r.snapshot),r}finally{await U(i,{force:!0})}}async function Bn({bucket:e,projectId:t,revision:n,store:r,temporaryDirectory:i}){let a=await zn({bucket:e,key:gn(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 Vn({bucket:e,projectId:t,reference:n,store:r,tag:i,temporaryDirectory:a}){await Ln({bucket:e,key:gn(t,n.revision),reference:n,store:r,temporaryDirectory:a}),i&&await Ln({bucket:e,key:_n(t,i),reference:n,store:r,temporaryDirectory:a})}async function Hn({bucket:e,cacheRoot:t,digest:n,projectId:r,store:i,target:a}){dn(n);let o=L(R(t),`v1`,`sha256`,n.slice(0,2),n);if(await Wn(o,n)===!1){await V(I(o),{recursive:!0});let t=`${o}.${process.pid}.${G()}.tmp`;try{if(await i.download(e,hn(r,n),t),await Pn(t)!==n)throw Error(`Downloaded i18n object failed SHA-256 verification: ${n}.`);await U(o,{force:!0}),await Oe(t,o)}finally{await U(t,{force:!0})}}await V(I(a),{recursive:!0});let s=`${a}.${process.pid}.${G()}.tmp`;try{if(await Se(o,s),await Pn(s)!==n)throw Error(`Cached i18n object failed SHA-256 verification: ${n}.`);await U(a,{force:!0}),await Oe(s,a)}finally{await U(s,{force:!0})}}async function Un({bucket:e,cacheRoot:t,digest:n,projectId:r,store:i,temporaryDirectory:a}){let o=L(a,`manifest-${n}.json`);await Hn({bucket:e,cacheRoot:t,digest:n,projectId:r,store:i,target:o});let s=JSON.parse(await H(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}.`);fn(s.revision),s.baseline!==void 0&&dn(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}.`);dn(e.digest)}return s}async function Wn(e,t){try{return(await ke(e)).isFile()&&await Pn(e)===t}catch{return!1}}async function Gn({cwd:e=process.cwd(),env:t=process.env}={}){if((await Le({cwd:e})).i18n){if(t.COREFRAME_I18N_RELEASE_REVISION){await Jn({cwd:e,env:t,revision:t.COREFRAME_I18N_RELEASE_REVISION});return}await bn(e)}}async function Kn({cwd:e=process.cwd(),projectConfig:t}={}){let n=t??await Le({cwd:e});if(!n.i18n)return;let r=Yn(n.i18n),i=X(e,r.directory);try{if(!(await ke(i)).isDirectory())throw Error(`I18n catalog path is not a directory: ${i}.`)}catch(t){if(t.code!==`ENOENT`)throw t;await bn(e);return}for(let t of r.locales)for(let n of r.catalogs)try{if(!(await ke(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 bn(e);return}}async function qn({cwd:e=process.cwd(),env:t=process.env,store:n,tag:r}){vn(r);let i=await Xn({cwd:e,env:t,store:n});await ir(e);let a=await rr(e);await ar(e,r,a);let o=await Te(L(Ne(),`coreframe-i18n-prepare-`));try{let n=await Bn({bucket:i.assets.sourceBucket,projectId:i.assets.projectId,revision:a,store:i.store,temporaryDirectory:o});if(n){let e=await Un({bucket:i.assets.sourceBucket,cacheRoot:i.cacheRoot,digest:n.snapshot,projectId:i.assets.projectId,store:i.store,temporaryDirectory:o});return nr(i,e,a),await Qn(i,e),await Vn({bucket:i.assets.sourceBucket,projectId:i.assets.projectId,reference:n,store:i.store,tag:r,temporaryDirectory:o}),{reused:!0,snapshot:n.snapshot}}return await tr(i,o,async()=>{let n=await Zn(i,a,o);n||await er(i),await bn(e);let s=await Sn({config:i.config,cwd:e}),c=await Cn({config:i.config,cwd:e,env:t,messages:s});await wn({config:i.config,cwd:e,missing:s,response:c}),await Tn({config:i.config,cwd:e}),await xn({config:i.config,cwd:e,strict:!0,temporaryDirectory:o});let l=await $n(i),u={...n?{baseline:n}:{},catalogs:i.config.catalogs,files:l,generator:s.length>0?i.config.generator?.id??`unconfigured`:`none`,linguiVersion:await or(e),locales:i.config.locales,projectId:i.assets.projectId,revision:a,sourceLocale:i.config.sourceLocale,version:1},d=await Rn({bucket:i.assets.sourceBucket,manifest:u,projectId:i.assets.projectId,store:i.store,temporaryDirectory:o});return await Vn({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 U(o,{force:!0,recursive:!0})}}async function Jn({cwd:e=process.cwd(),env:t=process.env,revision:n,store:r}={}){let i=await Le({cwd:e});if(!i.i18n)return;let a=await Xn({cwd:e,env:t,store:r,projectConfig:i}),o=fn(n??await rr(e)),s=await Te(L(Ne(),`coreframe-i18n-materialize-`));try{let e=await Bn({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 Un({bucket:a.assets.sourceBucket,cacheRoot:a.cacheRoot,digest:e.snapshot,projectId:a.assets.projectId,store:a.store,temporaryDirectory:s});return nr(a,t,o),await Qn(a,t),{revision:o,snapshot:e.snapshot}}finally{await U(s,{force:!0,recursive:!0})}}function Yn(e){let t=pn(e.sourceLocale,`Source locale`),n=[...new Set(e.locales.map(e=>pn(e,`Locale`)))],r=[...new Set(e.catalogs.map(e=>pn(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 Xn({cwd:e=process.cwd(),env:t=process.env,projectConfig:n,store:r}){let i=n??await Le({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:R(e,`.coreframe`,`i18n`,`cache`),config:Yn(i.i18n),cwd:R(e),env:t,store:r??ye({config:a,env:t})}}async function Zn(e,t,n){let{stdout:r}=await z(`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 Bn({bucket:e.assets.sourceBucket,projectId:e.assets.projectId,revision:fn(t),store:e.store,temporaryDirectory:n});if(!r)continue;let i=await Un({bucket:e.assets.sourceBucket,cacheRoot:e.cacheRoot,digest:r.snapshot,projectId:e.assets.projectId,store:e.store,temporaryDirectory:n});return nr(e,i,t),await Qn(e,i),r.snapshot}}async function Qn(e,t){for(let n of t.files)if(await Hn({bucket:e.assets.sourceBucket,cacheRoot:e.cacheRoot,digest:n.digest,projectId:e.assets.projectId,store:e.store,target:X(e.cwd,n.path)}),(await ke(X(e.cwd,n.path))).size!==n.size)throw Error(`Materialized i18n artifact size does not match manifest: ${n.path}.`)}async function $n(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 Pn(a);await In({bucket:e.assets.sourceBucket,digest:o,projectId:e.assets.projectId,source:a,store:e.store}),t.push({digest:o,path:i,size:(await ke(a)).size})}return t.sort((e,t)=>e.path.localeCompare(t.path))}async function er(e){let{stdout:t}=await z(`git`,[`rev-parse`,`--show-prefix`],{cwd:e.cwd,stdin:`ignore`}),n=t.trim(),{stdout:r}=await z(`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 Pe(`@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 z(`git`,[`show`,`${i}:${s}`],{cwd:e.cwd,stdin:`ignore`});await Dn(X(e.cwd,Z(e.config,t,r)),a.parse(n)),o=!0}catch{}}return o}async function tr(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 be(o)}catch{continue}let s=L(t,`previous-catalogs`,a);await V(I(s),{recursive:!0}),await Oe(o,s),r.push({backup:s,path:o})}try{let e=await n();return await U(L(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 U(X(e.cwd,Z(e.config,t,n)),{force:!0});for(let{backup:e,path:t}of r)await V(I(t),{recursive:!0}),await Oe(e,t);throw t}}function nr(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 rr(e){let{stdout:t}=await z(`git`,[`rev-parse`,`HEAD`],{cwd:e,stdin:`ignore`});return fn(t.trim())}async function ir(e){let{stdout:t}=await z(`git`,[`status`,`--porcelain`],{cwd:e,stdin:`ignore`});if(t.trim())throw Error(`Tagged i18n preparation requires a clean Git tree.`)}async function ar(e,t,n){let{stdout:r}=await z(`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 or(e){let{stdout:t}=await z(`pnpm`,[`exec`,`lingui`,`--version`],{cwd:e,stdin:`ignore`});return t.trim()}const sr=[`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(` `),cr=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}}),lr=r(f,{displayName:`profile`,async from(e){return _e(e)}}),ur=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}}),dr=r(f,{displayName:`origin`,description:`Exact production HTTPS API origin embedded in the packaged Flutter client.`,async from(e){return P(e)}}),fr=p({name:`assets`,cmds:{configure:n({name:`configure`,description:`Store a Backblaze B2 private build-object key in the operating system credential store. ${sr}`,args:{profile:u({type:lr,displayName:`profile`,description:`Credential profile named by coreframe.config.ts.`})},handler:async({profile:e})=>{B.note(sr,`Required B2 key access`);let t=await B.text({message:`Backblaze B2 application key ID`,validate:e=>e?.trim()?void 0:`The application key ID is required.`});if(B.isCancel(t))throw Error(`Asset credential configuration was cancelled.`);let n=await B.password({message:`Backblaze B2 application key`,validate:e=>e?void 0:`The application key is required.`});if(B.isCancel(n))throw Error(`Asset credential configuration was cancelled.`);await ve({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(ur),description:`Place the asset in a named, lazily loaded pack.`}),variantWidths:c({long:`widths`,type:l(cr),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})=>he(await fe({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(ur),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})=>he(await pe({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(ur),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 me({fix:e,pack:n});he(r,t),r.ok||(process.exitCode=1)}}),publish:n({name:`publish`,args:{pack:c({long:`pack`,type:l(ur),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 ge({pack:t});he(n,e),n.ok||(process.exitCode=1)}}),status:n({name:`status`,args:{pack:c({long:`pack`,type:l(ur),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 me({pack:t});he(n,e),n.ok||(process.exitCode=1)}})}}),pr=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:dr,description:`Defaults to COREFRAME_API_ORIGIN.`})},handler:({apiOrigin:e})=>ce({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})=>oe({check:e})}),prepare:n({name:`prepare`,description:`Build and package the React client for one Flutter platform.`,args:{platform:u({type:s(M),displayName:`platform`,description:`Flutter platform whose packaged client should be prepared.`}),apiOrigin:c({long:`api-origin`,env:`COREFRAME_API_ORIGIN`,type:dr,description:`Defaults to COREFRAME_API_ORIGIN.`})},handler:({apiOrigin:e,platform:t})=>N({apiOrigin:e,platform:t})}),check:n({name:`check`,description:`Reject missing, stale, modified, or incorrectly targeted Flutter assets.`,args:{platform:u({type:s(M),displayName:`platform`,description:`Flutter platform whose packaged client should be checked.`}),apiOrigin:c({long:`api-origin`,env:`COREFRAME_API_ORIGIN`,type:dr,description:`Defaults to COREFRAME_API_ORIGIN.`})},handler:({apiOrigin:e,platform:t})=>j({apiOrigin:e,platform:t})})}}),mr=p({name:`i18n`,cmds:{build:n({name:`build`,description:`Extract source messages or materialize an exact release catalog snapshot.`,args:{},handler:async()=>{await Gn()}}),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 Jn({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 qn({tag:e});console.log(`${t.reused?`Reused`:`Published`} i18n snapshot ${t.snapshot}.`)}})}}),hr=K.platform===`win32`?`react-router.cmd`:`react-router`,gr=K.platform===`win32`?`panda.cmd`:`panda`;async function _r(e=K.cwd()){await br(e),await yr(e,[`typegen`])}async function vr(e=K.cwd(),t=K.env,n){if((t.COREFRAME_PLATFORM??t.TAURI_ENV_PLATFORM??`web`)!==`web`)return;let r=F.resolve(e,`.coreframe/dashboard-build`),i=F.join(r,`client`),a=F.resolve(e,`dist/client/__dashboard`);await U(r,{force:!0,recursive:!0}),await xr(e,gr,[`build`],t),await yr(e,[`build`,...n?[`--mode`,n]:[]],t),await U(a,{force:!0,recursive:!0}),await V(F.dirname(a),{recursive:!0}),await Ce(i,a,{recursive:!0})}async function yr(e,t,n=K.env){await xr(e,hr,t,n)}async function br(e){await U(F.resolve(e,`dashboard/.react-router`),{force:!0,recursive:!0})}async function xr(e,t,n,r=K.env){await z(t,n,{cwd:F.resolve(e,`dashboard`),env:{...r,PATH:F.resolve(e,`node_modules/.bin`)+F.delimiter+(r.PATH??r.Path??``)},stdio:`inherit`})}const Sr=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})=>vr(void 0,void 0,e)}),typegen:n({name:`typegen`,args:{},handler:()=>_r()})}}),Cr=/^[a-z0-9]+(?:-[a-z0-9]+)*$/u;function wr(e,t){let n=Er(e,t);if(!Dr(n)||!Or(n,[`description`,`requires`,`routes`,`verifier`])||!Ar(n.description)||n.requires!==void 0&&(!Array.isArray(n.requires)||!n.requires.every(Ar))||n.verifier!==void 0&&!Ar(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=>Tr(e));if(new Set(r).size!==r.length)throw Error(`${t} contains duplicate recipe requirements.`);let i=n.routes.map((e,n)=>{if(!Dr(e)||!kr(e,[`path`,`router`,`when`])||!Ar(e.path)||!Ar(e.router)||!Ar(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 Tr(e){if(!Cr.test(e))throw Error(`Recipe names use lowercase letters, numbers, and single hyphens.`);return e}function Er(e,t){try{return Je(e)}catch(e){throw Error(`Could not parse ${t}.`,{cause:e})}}function Dr(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Or(e,t){return Object.keys(e).every(e=>t.includes(e))}function kr(e,t){let n=Object.keys(e).sort();return n.length===t.length&&n.every((e,n)=>e===t[n])}function Ar(e){return typeof e==`string`&&e.length>0}const jr=`https://github.com/airlock-labs/coreframe.git`;function Mr(e,t){return q(`git`,e,{cwd:t,encoding:`utf8`})}function Nr(e,t){let n=Mr(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 Pr(e,t){let n=Mr([`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 Fr({cwd:e=process.cwd(),fetch:t=!0,remote:n=`template`}={}){if(n.length===0)throw Error(`Remote name must not be empty.`);Nr([`rev-parse`,`--show-toplevel`],e);let r=Pr(n,e);if(r===null)Nr([`remote`,`add`,n,jr],e),console.log(`Added ${n} remote: ${jr}`);else if(r===jr)console.log(`${n} remote already points at ${jr}`);else throw Error(`${n} remote points at ${r}, not ${jr}.\nChoose the intended template source before continuing, then update or rename the remote manually.`);t&&(Nr([`fetch`,n,`--tags`,`--prune`],e),console.log(`Fetched ${n}.`))}const Ir=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/u;function Lr(e){return Ir.test(e)?`v${e}`:e}function Rr(e){return`${Lr(e)}:template`}function zr(e,t){return`${Rr(e)}/${t}`}function Br({cwd:e=process.cwd(),fetch:t=!0,remote:n=`template`,target:r}={}){let i=Wr(e),a=Jr(i,[`rev-parse`,`--show-toplevel`]),o=Lr(r??Gr(i));return Fr({cwd:a,fetch:t,remote:n}),{projectRoot:i,ref:o,repositoryRoot:a}}function Vr(e,t,n){return Hr(e,t,n).toString(`utf8`)}function Hr(e,t,n){let r=`${t}:${n}`,i=q(`git`,[`show`,r],{cwd:e,encoding:`buffer`});if(i.status!==0)throw Error(`Could not read ${r}. ${Yr([`show`,r],i)}`);return i.stdout}function Ur(e,t,n){let r=q(`git`,[`ls-tree`,`-r`,`--name-only`,`-z`,t,`--`,n],{cwd:e,encoding:`buffer`});if(r.status!==0)throw Error(Yr([`ls-tree`,t,n],r));return r.stdout.toString(`utf8`).split(`\0`).filter(Boolean)}function Wr(e){let t=R(e);for(;;){let e=L(t,`package.json`),n=qr(e);if(n!==void 0&&Kr(n,e).engines?.coreframe)return t;let r=I(t);if(r===t)throw Error(`Could not find a package.json with engines.coreframe.`);t=r}}function Gr(e){let t=L(e,`package.json`),n=qr(t);if(n===void 0)throw Error(`Required file package.json does not exist.`);let r=Kr(n,t).engines?.coreframe;if(!r)throw Error(`package.json must declare an exact engines.coreframe recipe baseline.`);return r}function Kr(e,t){try{return JSON.parse(e)}catch(e){throw Error(`Could not parse ${t}.`,{cause:e})}}function qr(e){try{return Y(e,`utf8`)}catch(e){if(Xr(e)&&e.code===`ENOENT`)return;throw e}}function Jr(e,t){let n=q(`git`,t,{cwd:e,encoding:`utf8`});if(n.status!==0)throw Error(Yr(t,n));return n.stdout.trim()}function Yr(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 Xr(e){return e instanceof Error&&`code`in e}const Zr=[{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:ei},{path:`src/api/client/app-origin.ts`,requirement:`allow the Flutter shell to provide its exact API origin`,test:e=>$r(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=>$r(e,[`appendFlutterAuthOrigins`,`appendFlutterAuthOrigins([], development)`])},{path:`src/api/worker/middleware/auth.ts`,requirement:`broker Flutter access tokens and accept only Flutter bearer origins`,test:e=>$r(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=>$r(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=>$r(e,[`configureShellQueryFocus`,`authSessionHint`])},{path:`src/web/entry.client.tsx`,requirement:`load the package-owned Flutter development tools only for non-browser development`,test:e=>$r(e,[`@coreframe/vite/flutter-devtools`,`import.meta.env.PLATFORM !== "web"`])}];function Qr(e){let t=[];for(let n of Zr){let r=L(e,n.path);if(!J(r)){t.push(`${n.path} is missing; it must ${n.requirement}.`);continue}let i=Y(r,`utf8`);n.test(i)||t.push(`${n.path} must ${n.requirement}.`)}return t}function $r(e,t){return t.every(t=>e.includes(t))}function ei(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 ti=[{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`)}],ni=[`CoreframeTemplateProject7A91C`,`coreframe-template-project-7a91c`,`coreframe_template_project_7a91c`,`com.example.coreframetemplateproject7a91c`];function ri(e){let t=[];for(let n of ti){let r=L(e,n.path);if(!J(r)){t.push(`${n.path} is missing; it must ${n.requirement}.`);continue}let i=Y(r,`utf8`);n.test(i)||t.push(`${n.path} must ${n.requirement}.`)}let n=L(e,`src-tauri/tauri.conf.json`);J(n)?ii(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=L(e,n);J(r)&&ni.some(e=>Y(r,`utf8`).includes(e))&&t.push(`${n} must replace the Coreframe template identity sentinel.`)}return t}function ii(e,t){let n;try{n=JSON.parse(Y(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 ai({name:e,...t}){let n=Br(t),r=`recipes/${e}/recipe.yaml`,i=ci(wr(Vr(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 tn({apiOrigin:e,cwd:t=process.cwd(),environment:n=process.env,platform:r=`web`,simulator:i=!1,prepareClient:a=N,runCommand:o=rn}={}){nn(r,i);let s={...n};delete s.COREFRAME_PLATFORM,delete s.TAURI_ENV_PLATFORM;let c=r===`web`?void 0:P(e??n.COREFRAME_API_ORIGIN);for(let e of Zt(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($t(t)):r===`ios`&&console.log(en(t,{simulator:i}))}function nn(e,t){if(t&&e!==`ios`)throw Error(`The --simulator flag is only supported for the iOS build target.`)}async function rn(e,t,{cwd:n,env:r}){await z(e,t,{cwd:n,env:r,stdio:`inherit`})}function an(e,t,n,r){return{kind:`command`,command:e,args:t,cwd:n,...r===void 0?{}:{environment:r}}}const on=r(f,{displayName:`origin`,description:`Exact production HTTPS API origin embedded in a packaged Flutter client.`,async from(e){return P(e)}}),sn=n({name:`build`,description:`Build the web client or a release Flutter app. Tauri is not built.`,args:{platform:u({type:l(s(Xt)),displayName:`platform`,description:`Build target: web, iOS, Android, or macOS. Defaults to web.`}),apiOrigin:c({long:`api-origin`,type:l(on),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})=>tn({apiOrigin:e,platform:t,simulator:n})}),cn=/^[a-f0-9]{64}$/,ln=/^[a-f0-9]{40}$/,un=/^[A-Za-z0-9][A-Za-z0-9._-]*$/;function dn(e){if(!cn.test(e))throw Error(`Invalid SHA-256 digest "${e}".`);return e}function fn(e){if(!ln.test(e))throw Error(`Invalid full Git revision "${e}".`);return e}function pn(e,t){if(!un.test(e))throw Error(`${t} must contain only letters, numbers, dots, underscores, or hyphens.`);return e}function mn(e){return`projects/${pn(e,`Project ID`)}/i18n/v1`}function hn(e,t){return dn(t),`${mn(e)}/objects/sha256/${t.slice(0,2)}/${t}`}function gn(e,t){return fn(t),`${mn(e)}/commits/${t}.json`}function _n(e,t){return vn(t),`${mn(e)}/releases/${encodeURIComponent(t)}.json`}function vn(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=R(e),r=R(n,t);if(r!==n&&!r.startsWith(`${n}${de}`))throw Error(`Unsafe i18n artifact path "${t}".`);return r}function Z(e,t,n){return`${e.directory}/${t}/${n}.json`}function yn(e,t,n){return`${e.directory}/${t}/${n}.mjs`}async function bn(e){await z(`pnpm`,[`exec`,`lingui`,`extract`],{cwd:e,stdio:`inherit`})}async function xn({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 En(o),c=Object.fromEntries(Object.entries(s).filter(([,e])=>!e.obsolete)),l=L(r,`${n}-${a}.json`);await V(I(l),{recursive:!0}),await Se(o,l),i.push({path:o,backup:l}),await Dn(o,c)}await z(`pnpm`,[`exec`,`lingui`,`compile`,...n?[`--strict`]:[]],{cwd:t,stdio:`inherit`})}finally{try{for(let{path:e,backup:t}of i)await Se(t,e)}finally{for(let n of e.locales)for(let r of e.catalogs)await U(X(t,yn(e,n,r)),{force:!0})}}}async function Sn({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 En(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)=>Mn(e).localeCompare(Mn(t)))}async function Cn({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 On(await kn({args:e.generator.args??[],command:e.generator.command,cwd:t,env:r,input:JSON.stringify(i)}))}async function wn({config:e,cwd:t,missing:n,response:r}){let i=new Map(n.map(e=>[Mn(e),e])),a=new Map;for(let e of r.translations){let t=Mn(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 Pe(`@lingui/message-utils/compileMessage`,t);for(let e of n){let t=a.get(Mn(e));An({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 En(i),s=!1;for(let[e,t]of Object.entries(o)){let i=a.get(Mn({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 Dn(i,o)}}async function Tn({config:e,cwd:t}){let n=await Sn({config:e,cwd:t});if(n.length>0)throw Error(`I18n catalogs remain incomplete: ${n.length} translations are missing.`);let r=await Pe(`@lingui/message-utils/compileMessage`,t);for(let n of e.locales)if(n!==e.sourceLocale)for(let i of e.catalogs){let a=await En(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}.`);An({compileMessage:r,id:e,locale:n,source:t.message,translation:t.translation})}}}async function En(e){let t=JSON.parse(await H(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 Dn(e,t){await V(I(e),{recursive:!0});let n=`${e}.${process.pid}.tmp`;await W(n,`${JSON.stringify(t,null,2)}\n`),await Oe(n,e)}function On(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 kn({args:e,command:t,cwd:n,env:r,input:i}){return z(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 An({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=jn(a),c=jn(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 jn(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 Mn(e){return`${e.locale}\0${e.catalog}\0${e.id}`}function Nn(e){return ze(`sha256`).update(e).digest(`hex`)}async function Pn(e){return Nn(await H(e))}function Fn(e){return Buffer.from(`${JSON.stringify(e,null,2)}\n`)}async function In({bucket:e,digest:t,projectId:n,source:r,store:i}){if(dn(t),await Pn(r)!==t)throw Error(`I18n object source does not match declared SHA-256 digest ${t}.`);let a=hn(n,t);await i.has(e,a)||await i.upload(e,a,r,`application/octet-stream`);let o=`${r}.${process.pid}.${G()}.verify`;try{if(await i.download(e,a,o),await Pn(o)!==t)throw Error(`Existing immutable i18n object ${a} failed integrity verification.`)}finally{await U(o,{force:!0})}}async function Ln({bucket:e,key:t,reference:n,store:r,temporaryDirectory:i}){let a=Fn(n),o=L(i,`reference-${G()}.json`);if(await r.has(e,t))try{if(await r.download(e,t,o),!(await H(o)).equals(a))throw Error(`Immutable i18n reference ${t} already resolves to different snapshot data.`);return}finally{await U(o,{force:!0})}await W(o,a,{flag:`wx`});try{await r.upload(e,t,o,`application/json`)}finally{await U(o,{force:!0})}let s=L(i,`reference-${G()}.verify.json`);try{if(await r.download(e,t,s),!(await H(s)).equals(a))throw Error(`Uploaded immutable i18n reference ${t} failed verification.`)}finally{await U(s,{force:!0})}}async function Rn({bucket:e,manifest:t,projectId:n,store:r,temporaryDirectory:i}){let a=Fn(t),o=Nn(a),s=L(i,`manifest-${o}.json`);await W(s,a,{flag:`wx`});try{await In({bucket:e,digest:o,projectId:n,source:s,store:r})}finally{await U(s,{force:!0})}return o}async function zn({bucket:e,key:t,store:n,temporaryDirectory:r}){if(!await n.has(e,t))return;let i=L(r,`reference-${G()}.json`);try{await n.download(e,t,i);let r=JSON.parse(await H(i,`utf8`));if(r.version!==1||typeof r.revision!=`string`||typeof r.snapshot!=`string`)throw Error(`Invalid i18n reference at ${t}.`);return fn(r.revision),dn(r.snapshot),r}finally{await U(i,{force:!0})}}async function Bn({bucket:e,projectId:t,revision:n,store:r,temporaryDirectory:i}){let a=await zn({bucket:e,key:gn(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 Vn({bucket:e,projectId:t,reference:n,store:r,tag:i,temporaryDirectory:a}){await Ln({bucket:e,key:gn(t,n.revision),reference:n,store:r,temporaryDirectory:a}),i&&await Ln({bucket:e,key:_n(t,i),reference:n,store:r,temporaryDirectory:a})}async function Hn({bucket:e,cacheRoot:t,digest:n,projectId:r,store:i,target:a}){dn(n);let o=L(R(t),`v1`,`sha256`,n.slice(0,2),n);if(await Wn(o,n)===!1){await V(I(o),{recursive:!0});let t=`${o}.${process.pid}.${G()}.tmp`;try{if(await i.download(e,hn(r,n),t),await Pn(t)!==n)throw Error(`Downloaded i18n object failed SHA-256 verification: ${n}.`);await U(o,{force:!0}),await Oe(t,o)}finally{await U(t,{force:!0})}}await V(I(a),{recursive:!0});let s=`${a}.${process.pid}.${G()}.tmp`;try{if(await Se(o,s),await Pn(s)!==n)throw Error(`Cached i18n object failed SHA-256 verification: ${n}.`);await U(a,{force:!0}),await Oe(s,a)}finally{await U(s,{force:!0})}}async function Un({bucket:e,cacheRoot:t,digest:n,projectId:r,store:i,temporaryDirectory:a}){let o=L(a,`manifest-${n}.json`);await Hn({bucket:e,cacheRoot:t,digest:n,projectId:r,store:i,target:o});let s=JSON.parse(await H(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}.`);fn(s.revision),s.baseline!==void 0&&dn(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}.`);dn(e.digest)}return s}async function Wn(e,t){try{return(await ke(e)).isFile()&&await Pn(e)===t}catch{return!1}}async function Gn({cwd:e=process.cwd(),env:t=process.env}={}){if((await Le({cwd:e})).i18n){if(t.COREFRAME_I18N_RELEASE_REVISION){await Jn({cwd:e,env:t,revision:t.COREFRAME_I18N_RELEASE_REVISION});return}await bn(e)}}async function Kn({cwd:e=process.cwd(),projectConfig:t}={}){let n=t??await Le({cwd:e});if(!n.i18n)return;let r=Yn(n.i18n),i=X(e,r.directory);try{if(!(await ke(i)).isDirectory())throw Error(`I18n catalog path is not a directory: ${i}.`)}catch(t){if(t.code!==`ENOENT`)throw t;await bn(e);return}for(let t of r.locales)for(let n of r.catalogs)try{if(!(await ke(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 bn(e);return}}async function qn({cwd:e=process.cwd(),env:t=process.env,store:n,tag:r}){vn(r);let i=await Xn({cwd:e,env:t,store:n});await ir(e);let a=await rr(e);await ar(e,r,a);let o=await Te(L(Ne(),`coreframe-i18n-prepare-`));try{let n=await Bn({bucket:i.assets.sourceBucket,projectId:i.assets.projectId,revision:a,store:i.store,temporaryDirectory:o});if(n){let e=await Un({bucket:i.assets.sourceBucket,cacheRoot:i.cacheRoot,digest:n.snapshot,projectId:i.assets.projectId,store:i.store,temporaryDirectory:o});return nr(i,e,a),await Qn(i,e),await Vn({bucket:i.assets.sourceBucket,projectId:i.assets.projectId,reference:n,store:i.store,tag:r,temporaryDirectory:o}),{reused:!0,snapshot:n.snapshot}}return await tr(i,o,async()=>{let n=await Zn(i,a,o);n||await er(i),await bn(e);let s=await Sn({config:i.config,cwd:e}),c=await Cn({config:i.config,cwd:e,env:t,messages:s});await wn({config:i.config,cwd:e,missing:s,response:c}),await Tn({config:i.config,cwd:e}),await xn({config:i.config,cwd:e,strict:!0,temporaryDirectory:o});let l=await $n(i),u={...n?{baseline:n}:{},catalogs:i.config.catalogs,files:l,generator:s.length>0?i.config.generator?.id??`unconfigured`:`none`,linguiVersion:await or(e),locales:i.config.locales,projectId:i.assets.projectId,revision:a,sourceLocale:i.config.sourceLocale,version:1},d=await Rn({bucket:i.assets.sourceBucket,manifest:u,projectId:i.assets.projectId,store:i.store,temporaryDirectory:o});return await Vn({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 U(o,{force:!0,recursive:!0})}}async function Jn({cwd:e=process.cwd(),env:t=process.env,revision:n,store:r}={}){let i=await Le({cwd:e});if(!i.i18n)return;let a=await Xn({cwd:e,env:t,store:r,projectConfig:i}),o=fn(n??await rr(e)),s=await Te(L(Ne(),`coreframe-i18n-materialize-`));try{let e=await Bn({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 Un({bucket:a.assets.sourceBucket,cacheRoot:a.cacheRoot,digest:e.snapshot,projectId:a.assets.projectId,store:a.store,temporaryDirectory:s});return nr(a,t,o),await Qn(a,t),{revision:o,snapshot:e.snapshot}}finally{await U(s,{force:!0,recursive:!0})}}function Yn(e){let t=pn(e.sourceLocale,`Source locale`),n=[...new Set(e.locales.map(e=>pn(e,`Locale`)))],r=[...new Set(e.catalogs.map(e=>pn(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 Xn({cwd:e=process.cwd(),env:t=process.env,projectConfig:n,store:r}){let i=n??await Le({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:R(e,`.coreframe`,`i18n`,`cache`),config:Yn(i.i18n),cwd:R(e),env:t,store:r??ye({config:a,env:t})}}async function Zn(e,t,n){let{stdout:r}=await z(`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 Bn({bucket:e.assets.sourceBucket,projectId:e.assets.projectId,revision:fn(t),store:e.store,temporaryDirectory:n});if(!r)continue;let i=await Un({bucket:e.assets.sourceBucket,cacheRoot:e.cacheRoot,digest:r.snapshot,projectId:e.assets.projectId,store:e.store,temporaryDirectory:n});return nr(e,i,t),await Qn(e,i),r.snapshot}}async function Qn(e,t){for(let n of t.files)if(await Hn({bucket:e.assets.sourceBucket,cacheRoot:e.cacheRoot,digest:n.digest,projectId:e.assets.projectId,store:e.store,target:X(e.cwd,n.path)}),(await ke(X(e.cwd,n.path))).size!==n.size)throw Error(`Materialized i18n artifact size does not match manifest: ${n.path}.`)}async function $n(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 Pn(a);await In({bucket:e.assets.sourceBucket,digest:o,projectId:e.assets.projectId,source:a,store:e.store}),t.push({digest:o,path:i,size:(await ke(a)).size})}return t.sort((e,t)=>e.path.localeCompare(t.path))}async function er(e){let{stdout:t}=await z(`git`,[`rev-parse`,`--show-prefix`],{cwd:e.cwd,stdin:`ignore`}),n=t.trim(),{stdout:r}=await z(`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 Pe(`@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 z(`git`,[`show`,`${i}:${s}`],{cwd:e.cwd,stdin:`ignore`});await Dn(X(e.cwd,Z(e.config,t,r)),a.parse(n)),o=!0}catch{}}return o}async function tr(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 be(o)}catch{continue}let s=L(t,`previous-catalogs`,a);await V(I(s),{recursive:!0}),await Oe(o,s),r.push({backup:s,path:o})}try{let e=await n();return await U(L(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 U(X(e.cwd,Z(e.config,t,n)),{force:!0});for(let{backup:e,path:t}of r)await V(I(t),{recursive:!0}),await Oe(e,t);throw t}}function nr(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 rr(e){let{stdout:t}=await z(`git`,[`rev-parse`,`HEAD`],{cwd:e,stdin:`ignore`});return fn(t.trim())}async function ir(e){let{stdout:t}=await z(`git`,[`status`,`--porcelain`],{cwd:e,stdin:`ignore`});if(t.trim())throw Error(`Tagged i18n preparation requires a clean Git tree.`)}async function ar(e,t,n){let{stdout:r}=await z(`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 or(e){let{stdout:t}=await z(`pnpm`,[`exec`,`lingui`,`--version`],{cwd:e,stdin:`ignore`});return t.trim()}const sr=[`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(` `),cr=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}}),lr=r(f,{displayName:`profile`,async from(e){return _e(e)}}),ur=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}}),dr=r(f,{displayName:`origin`,description:`Exact production HTTPS API origin embedded in the packaged Flutter client.`,async from(e){return P(e)}}),fr=p({name:`assets`,cmds:{configure:n({name:`configure`,description:`Store a Backblaze B2 private build-object key in the operating system credential store. ${sr}`,args:{profile:u({type:lr,displayName:`profile`,description:`Credential profile named by coreframe.config.ts.`})},handler:async({profile:e})=>{B.note(sr,`Required B2 key access`);let t=await B.text({message:`Backblaze B2 application key ID`,validate:e=>e?.trim()?void 0:`The application key ID is required.`});if(B.isCancel(t))throw Error(`Asset credential configuration was cancelled.`);let n=await B.password({message:`Backblaze B2 application key`,validate:e=>e?void 0:`The application key is required.`});if(B.isCancel(n))throw Error(`Asset credential configuration was cancelled.`);await ve({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(ur),description:`Place the asset in a named, lazily loaded pack.`}),variantWidths:c({long:`widths`,type:l(cr),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})=>he(await fe({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(ur),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})=>he(await pe({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(ur),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 me({fix:e,pack:n});he(r,t),r.ok||(process.exitCode=1)}}),publish:n({name:`publish`,args:{pack:c({long:`pack`,type:l(ur),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 ge({pack:t});he(n,e),n.ok||(process.exitCode=1)}}),status:n({name:`status`,args:{pack:c({long:`pack`,type:l(ur),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 me({pack:t});he(n,e),n.ok||(process.exitCode=1)}})}}),pr=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:dr,description:`Defaults to COREFRAME_API_ORIGIN.`})},handler:({apiOrigin:e})=>ce({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})=>oe({check:e})}),prepare:n({name:`prepare`,description:`Build and package the React client for one Flutter platform.`,args:{platform:u({type:s(M),displayName:`platform`,description:`Flutter platform whose packaged client should be prepared.`}),apiOrigin:c({long:`api-origin`,env:`COREFRAME_API_ORIGIN`,type:dr,description:`Defaults to COREFRAME_API_ORIGIN.`})},handler:({apiOrigin:e,platform:t})=>N({apiOrigin:e,platform:t})}),check:n({name:`check`,description:`Reject missing, stale, modified, or incorrectly targeted Flutter assets.`,args:{platform:u({type:s(M),displayName:`platform`,description:`Flutter platform whose packaged client should be checked.`}),apiOrigin:c({long:`api-origin`,env:`COREFRAME_API_ORIGIN`,type:dr,description:`Defaults to COREFRAME_API_ORIGIN.`})},handler:({apiOrigin:e,platform:t})=>j({apiOrigin:e,platform:t})})}}),mr=p({name:`i18n`,cmds:{build:n({name:`build`,description:`Extract source messages or materialize an exact release catalog snapshot.`,args:{},handler:async()=>{await Gn()}}),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 Jn({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 qn({tag:e});console.log(`${t.reused?`Reused`:`Published`} i18n snapshot ${t.snapshot}.`)}})}}),hr=K.platform===`win32`?`react-router.cmd`:`react-router`,gr=K.platform===`win32`?`panda.cmd`:`panda`;async function _r(e=K.cwd()){await br(e),await yr(e,[`typegen`])}async function vr(e=K.cwd(),t=K.env,n){if((t.COREFRAME_PLATFORM??t.TAURI_ENV_PLATFORM??`web`)!==`web`)return;let r=F.resolve(e,`.coreframe/dashboard-build`),i=F.join(r,`client`),a=F.resolve(e,`dist/client/__dashboard`);await U(r,{force:!0,recursive:!0}),await xr(e,gr,[`build`],t),await yr(e,[`build`,...n?[`--mode`,n]:[]],t),await U(a,{force:!0,recursive:!0}),await V(F.dirname(a),{recursive:!0}),await Ce(i,a,{recursive:!0})}async function yr(e,t,n=K.env){await xr(e,hr,t,n)}async function br(e){await U(F.resolve(e,`dashboard/.react-router`),{force:!0,recursive:!0})}async function xr(e,t,n,r=K.env){await z(t,n,{cwd:F.resolve(e,`dashboard`),env:{...r,PATH:F.resolve(e,`node_modules/.bin`)+F.delimiter+(r.PATH??r.Path??``)},stdio:`inherit`})}const Sr=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})=>vr(void 0,void 0,e)}),typegen:n({name:`typegen`,args:{},handler:()=>_r()})}}),Cr=/^[a-z0-9]+(?:-[a-z0-9]+)*$/u;function wr(e,t){let n=Er(e,t);if(!Dr(n)||!Or(n,[`description`,`requires`,`routes`,`verifier`])||!Ar(n.description)||n.requires!==void 0&&(!Array.isArray(n.requires)||!n.requires.every(Ar))||n.verifier!==void 0&&!Ar(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=>Tr(e));if(new Set(r).size!==r.length)throw Error(`${t} contains duplicate recipe requirements.`);let i=n.routes.map((e,n)=>{if(!Dr(e)||!kr(e,[`path`,`router`,`when`])||!Ar(e.path)||!Ar(e.router)||!Ar(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 Tr(e){if(!Cr.test(e))throw Error(`Recipe names use lowercase letters, numbers, and single hyphens.`);return e}function Er(e,t){try{return Je(e)}catch(e){throw Error(`Could not parse ${t}.`,{cause:e})}}function Dr(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Or(e,t){return Object.keys(e).every(e=>t.includes(e))}function kr(e,t){let n=Object.keys(e).sort();return n.length===t.length&&n.every((e,n)=>e===t[n])}function Ar(e){return typeof e==`string`&&e.length>0}const jr=`https://github.com/airlock-labs/coreframe.git`;function Mr(e,t){return q(`git`,e,{cwd:t,encoding:`utf8`})}function Nr(e,t){let n=Mr(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 Pr(e,t){let n=Mr([`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 Fr({cwd:e=process.cwd(),fetch:t=!0,remote:n=`template`}={}){if(n.length===0)throw Error(`Remote name must not be empty.`);Nr([`rev-parse`,`--show-toplevel`],e);let r=Pr(n,e);if(r===null)Nr([`remote`,`add`,n,jr],e),console.log(`Added ${n} remote: ${jr}`);else if(r===jr)console.log(`${n} remote already points at ${jr}`);else throw Error(`${n} remote points at ${r}, not ${jr}.\nChoose the intended template source before continuing, then update or rename the remote manually.`);t&&(Nr([`fetch`,n,`--tags`,`--prune`],e),console.log(`Fetched ${n}.`))}const Ir=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/u;function Lr(e){return Ir.test(e)?`v${e}`:e}function Rr(e){return`${Lr(e)}:template`}function zr(e,t){return`${Rr(e)}/${t}`}function Br({cwd:e=process.cwd(),fetch:t=!0,remote:n=`template`,target:r}={}){let i=Wr(e),a=Jr(i,[`rev-parse`,`--show-toplevel`]),o=Lr(r??Gr(i));return Fr({cwd:a,fetch:t,remote:n}),{projectRoot:i,ref:o,repositoryRoot:a}}function Vr(e,t,n){return Hr(e,t,n).toString(`utf8`)}function Hr(e,t,n){let r=`${t}:${n}`,i=q(`git`,[`show`,r],{cwd:e,encoding:`buffer`});if(i.status!==0)throw Error(`Could not read ${r}. ${Yr([`show`,r],i)}`);return i.stdout}function Ur(e,t,n){let r=q(`git`,[`ls-tree`,`-r`,`--name-only`,`-z`,t,`--`,n],{cwd:e,encoding:`buffer`});if(r.status!==0)throw Error(Yr([`ls-tree`,t,n],r));return r.stdout.toString(`utf8`).split(`\0`).filter(Boolean)}function Wr(e){let t=R(e);for(;;){let e=L(t,`package.json`),n=qr(e);if(n!==void 0&&Kr(n,e).engines?.coreframe)return t;let r=I(t);if(r===t)throw Error(`Could not find a package.json with engines.coreframe.`);t=r}}function Gr(e){let t=L(e,`package.json`),n=qr(t);if(n===void 0)throw Error(`Required file package.json does not exist.`);let r=Kr(n,t).engines?.coreframe;if(!r)throw Error(`package.json must declare an exact engines.coreframe recipe baseline.`);return r}function Kr(e,t){try{return JSON.parse(e)}catch(e){throw Error(`Could not parse ${t}.`,{cause:e})}}function qr(e){try{return Y(e,`utf8`)}catch(e){if(Xr(e)&&e.code===`ENOENT`)return;throw e}}function Jr(e,t){let n=q(`git`,t,{cwd:e,encoding:`utf8`});if(n.status!==0)throw Error(Yr(t,n));return n.stdout.trim()}function Yr(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 Xr(e){return e instanceof Error&&`code`in e}const Zr=[{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:ei},{path:`src/api/client/app-origin.ts`,requirement:`allow the Flutter shell to provide its exact API origin`,test:e=>$r(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=>$r(e,[`appendFlutterAuthOrigins`,`appendFlutterAuthOrigins([], development)`])},{path:`src/api/worker/middleware/auth.ts`,requirement:`broker Flutter access tokens and accept Flutter bearer origins`,test:e=>$r(e,[`createFlutterAccessTokenResponse`,`isFlutterAuthOrigin(origin, import.meta.env.DEV)`,`readFlutterBearerToken(request, import.meta.env.DEV, developmentOrigin)`,`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=>$r(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=>$r(e,[`configureShellQueryFocus`,`authSessionHint`])},{path:`src/web/entry.client.tsx`,requirement:`load the package-owned Flutter development tools only for non-browser development`,test:e=>$r(e,[`@coreframe/vite/flutter-devtools`,`import.meta.env.PLATFORM !== "web"`])}];function Qr(e){let t=[];for(let n of Zr){let r=L(e,n.path);if(!J(r)){t.push(`${n.path} is missing; it must ${n.requirement}.`);continue}let i=Y(r,`utf8`);n.test(i)||t.push(`${n.path} must ${n.requirement}.`)}return t}function $r(e,t){return t.every(t=>e.includes(t))}function ei(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 ti=[{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`)}],ni=[`CoreframeTemplateProject7A91C`,`coreframe-template-project-7a91c`,`coreframe_template_project_7a91c`,`com.example.coreframetemplateproject7a91c`];function ri(e){let t=[];for(let n of ti){let r=L(e,n.path);if(!J(r)){t.push(`${n.path} is missing; it must ${n.requirement}.`);continue}let i=Y(r,`utf8`);n.test(i)||t.push(`${n.path} must ${n.requirement}.`)}let n=L(e,`src-tauri/tauri.conf.json`);J(n)?ii(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=L(e,n);J(r)&&ni.some(e=>Y(r,`utf8`).includes(e))&&t.push(`${n} must replace the Coreframe template identity sentinel.`)}return t}function ii(e,t){let n;try{n=JSON.parse(Y(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 ai({name:e,...t}){let n=Br(t),r=`recipes/${e}/recipe.yaml`,i=ci(wr(Vr(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 oi(e){console.log(`Verified Coreframe recipe ${e.name} from ${e.ref}.`)}function si(e,t){for(let n of e){let e=`recipes/${n}/recipe.yaml`,r=ci(wr(Vr(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 ci(e,t){if(!e)throw Error(`Required recipe does not declare a verifier.`);if(e===`tauri`)return ri(t);if(e===`flutter`)return Qr(t);throw Error(`Unknown recipe verifier ${JSON.stringify(e)}.`)}function li({cwd:e=process.cwd(),fetch:t=!0,name:n,remote:r=`template`,target:i}){Tr(n);let a=Br({cwd:e,fetch:t,remote:r,target:i}),{projectRoot:o,ref:s,repositoryRoot:c}=a,l=`recipes/${n}`,u=`${l}/recipe.yaml`,d=wr(Vr(c,s,u),u);si(d.requires,a);let f=Vr(c,s,`${l}/RECIPE.md`),p=Ur(c,s,`${l}/files`),m=Ur(c,s,`${l}/patches`),h=Ur(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(gi(t,`Recipe file ${e}`),t.startsWith(`.agents/`))throw Error(`Recipe file ${e} must be stored in the recipe's .agents directory.`);g.set(t,Hr(c,s,e)),_.set(t,e)}for(let e of h){let t=e.slice(`${l}/`.length);if(pi(t,`Recipe asset ${e}`),g.has(t))throw Error(`Recipe declares ${t} as both a file and an agent asset.`);g.set(t,Hr(c,s,e)),_.set(t,e)}for(let e of m){let t=_i(e,l);if(g.has(t))throw Error(`Recipe declares ${t} as both a file and a patch.`);let n=Hr(c,s,e);vi(n.toString(`utf8`),t,e),hi(o,t),yi(o,n,!1)?(v.push({contents:n,destinationPath:t}),x.push(t)):yi(o,n,!0)?S.push(t):b.push({destination:t,source:e})}let w=new Map;for(let[e,t]of g){let r=Si(hi(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(pi(e.router,`Recipe route router`),mi(e.path,`Recipe route path`),g.has(e.router))throw Error(`Recipe cannot replace its destination router ${e.router}.`);if(!g.has(e.path)&&!J(hi(o,e.path)))throw Error(`Recipe route target ${e.path} does not exist.`);let t=T.get(e.router)??di(Ci(hi(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=Ci(hi(o,e),e),r=Ye(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=hi(o,e);He(I(n),{recursive:!0}),qe(n,t)}return v.length>0&&bi(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 ui(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 di(e,t){let n=fi(e,t);if(!wi(n)||!Ti(n,[`routes`,`rules`])||!Array.isArray(n.rules)||!n.rules.every(Ei)||!Array.isArray(n.routes))throw Error(`${t} must contain only string rules and a routes array.`);let r=n.routes.map((e,n)=>{if(!wi(e)||!Ti(e,[`path`,`when`])||!Ei(e.path)||!Ei(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 fi(e,t){try{return Je(e)}catch(e){throw Error(`Could not parse ${t}.`,{cause:e})}}function pi(e,t){if(!e.startsWith(`.agents/`))throw Error(`${t} must be a normalized project-relative path beneath .agents/.`);gi(e,t)}function mi(e,t){if(gi(e,t),!/(?:^|\/)\.agents\/rules\/.+\.md$/u.test(e))throw Error(`${t} must point to a Markdown rule beneath an .agents/rules directory.`)}function hi(e,t){gi(t,`Recipe destination`);let n=L(e,t),r=e;for(let e of t.split(`/`))if(r=L(r,e),J(r)&&Ve(r).isSymbolicLink())throw Error(`Recipe destination ${t} crosses symbolic link ${r}.`);return n}function gi(e,t){if(e.length===0||le(e)||e===`..`||e.startsWith(`../`)||e.includes(`\\`)||ue.normalize(e)!==e)throw Error(`${t} must be a normalized project-relative path.`)}function _i(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 gi(r,`Recipe patch ${e}`),r}function vi(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 yi(e,t,n){let r=[`apply`,`--check`,`--whitespace=nowarn`];return n&&r.push(`--reverse`),r.push(`-`),q(`git`,r,{cwd:e,input:t}).status===0}function bi(e,t){let n=q(`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 xi(e){return Si(e)?.toString(`utf8`)}function Si(e){try{return Y(e)}catch(e){if(Di(e)&&e.code===`ENOENT`)return;throw e}}function Ci(e,t){let n=xi(e);if(n===void 0)throw Error(`Required file ${t} does not exist.`);return n}function wi(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Ti(e,t){let n=Object.keys(e).sort();return n.length===t.length&&n.every((e,n)=>e===t[n])}function Ei(e){return typeof e==`string`&&e.length>0}function Di(e){return e instanceof Error&&`code`in e}function Oi(e={}){let{ref:t,repositoryRoot:n}=Br(e),r=Ur(n,t,`recipes`).filter(e=>/^recipes\/[^/]+\/recipe\.yaml$/u.test(e)).map(e=>{let r=e.split(`/`)[1];return Tr(r),{description:wr(Vr(n,t,e),e).description,name:r}});return r.sort((e,t)=>e.name.localeCompare(t.name)),{recipes:r,ref:t}}function ki(e){console.log(`Coreframe recipes at ${e.ref}:`);for(let t of e.recipes)console.log(`${t.name} — ${t.description}`)}const Ai=`.agents/skills/coreframe-upgrade/SKILL.md`;function ji(e,t={}){return q(`git`,e,t)}function Mi(e){return e.stderr.toString(`utf8`).trim()||e.stdout.toString(`utf8`).trim()}function Ni(e,t){let n=zr(e,t),r=ji([`show`,n],{encoding:`utf8`});if(r.status!==0){let e=Mi(r);throw Error(`Could not read ${n}.${e?` ${e}`:``}`)}return r.stdout.toString()}function Pi(){let e=ji([`rev-parse`,`--show-toplevel`],{encoding:`utf8`});if(e.status!==0){let t=Mi(e);throw Error(`Could not find git repository root.${t?` ${t}`:``}`)}return e.stdout.toString().trim()}function Fi(e,t){let n=Ue(L(Ne(),`coreframe-upgrade-skill-`)),r=L(n,`SKILL.md`);try{qe(r,t);let n=Mi(ji([`--no-pager`,`diff`,`--no-index`,`--color=never`,`--`,e,r]));n&&console.log(n)}finally{Ge(n,{force:!0,recursive:!0})}}function Ii({apply:e,target:t}){let n=L(Pi(),Ai),r=Lr(t);if(!J(n))throw Error(`Local ${Ai} does not exist.`);let i=Y(n,`utf8`),a=Ni(t,Ai);return i===a?(console.log(`Coreframe upgrade skill matches ${r}:template/${Ai}.`),0):e?(qe(n,a),console.error(`Updated ${Ai} from ${r}:template. Reread it before continuing the upgrade.`),20):(console.error(`Coreframe upgrade skill differs from ${r}:template/${Ai}.`),console.error(`Run again with --apply to update it, then reread ${Ai} before continuing.`),Fi(n,a),20)}const Li=[{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`}],Ri=new Set([`100644`,`100755`,`120000`]);function zi(e,t={}){return q(`git`,e,t)}function Bi(e){let t=zi(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 Vi(e){let t=zi(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 Hi(){return Bi([`rev-parse`,`--show-toplevel`]).trim()}function Ui(e){let t=L(e,`package.json`);if(!J(t))throw Error(`Missing --base <git-ref>, and package.json does not exist.`);let n=JSON.parse(Y(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 Wi(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 Gi(e,t){let n=Wi(Vi([`diff`,`--name-status`,`-z`,`--no-renames`,Rr(e),Rr(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 Ki(e,t){let n=Vi([`ls-tree`,`-z`,Rr(e),`--`,t]);if(n.length===0)return null;let r=Wi(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 qi(e){return Vi([`cat-file`,`blob`,e.object])}function Ji(e,t){let n=R(e,t),r=e.endsWith(de)?e:`${e}${de}`;if(n!==e&&!n.startsWith(r))throw Error(`Refusing to access path outside repository: ${t}`);return n}function Yi(e){try{return Ve(e),!0}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return!1;throw e}}function Xi(e){return(e.mode&73)!=0}function Zi(e){return e===null||e.type===`blob`&&Ri.has(e.mode)}function Qi(e){return Li.find(t=>t.matches(e))?.reason}function $i(e,t,n){let r=Ji(e,t);if(n===null)return{matches:!Yi(r)};if(!Zi(n))return{matches:!1,reason:`unsupported template entry mode ${n.mode} ${n.type}`};let i;try{i=Ve(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=qi(n);return n.mode===`120000`?i.isSymbolicLink()?{matches:Buffer.from(We(r),`utf8`).equals(a)}:{matches:!1,reason:`worktree path is not a symlink`}:i.isFile()?(n.mode===`100755`?Xi(i):!Xi(i))?{matches:Y(r).equals(a)}:{matches:!1,reason:`worktree executable bit differs from template`}:{matches:!1,reason:`worktree path is not a regular file`}}function ea(e){Yi(e)&&Ge(e,{force:!0,recursive:!1})}function ta(e,t,n){let r=Ji(e,t);if(n===null){ea(r);return}if(He(I(r),{recursive:!0}),n.mode===`120000`){ea(r),Ke(qi(n).toString(`utf8`),r);return}let i=Yi(r)?Ve(r):null;i&&!i.isFile()&&ea(r),qe(r,qi(n)),Be(r,n.mode===`100755`?493:420)}function na(e,t){return e===null&&t!==null?`add`:e!==null&&t===null?`delete`:`update`}function ra(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 ia(e){let t=Hi(),n=Lr(e.base??Ui(t)),r=Lr(e.target),i=Gi(n,r),a=[],o=[],s=[],c=[];for(let e of i){let i=Qi(e.path);if(i){o.push({action:`ignored`,path:e.path,reason:i});continue}let l=Ki(n,e.path),u=Ki(r,e.path),d=na(l,u);if(!Zi(l)||!Zi(u)){s.push({action:d,path:e.path,reason:`unsupported template entry type`});continue}if($i(t,e.path,u).matches){c.push({action:`unchanged`,path:e.path});continue}let f=$i(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)ta(t,e.path,e.targetEntry??null);console.log(`Coreframe template fast-forward: ${n} -> ${r}`),console.log(``),ra(e.apply?`Applied clean template updates`:`Would apply clean template updates`,a),ra(`Ignored downstream-owned paths`,o),ra(`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 aa=[`dependencies`,`devDependencies`];function oa(e){let t=q(`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 sa(e,t){try{return JSON.parse(e)}catch(e){throw Error(`Could not parse ${t}: ${e instanceof Error?e.message:e}`)}}function ca(e,t){let n=`${Lr(e)}:${t}`;return sa(oa([`show`,n]),n)}function la(e){return e.startsWith(`@coreframe/`)}function ua(e){return e.startsWith(`file:`)||e.startsWith(`link:`)||e.startsWith(`workspace:`)}function da(e){return e.startsWith(`file:`)||e.startsWith(`link:`)}function fa(e,t){let n=e.indexOf(`:`),r=e.slice(n+1),i=ue.normalize(ue.join(`template`,r,`package.json`));if(r.length===0||ue.isAbsolute(r)||i===`..`||i.startsWith(`../`))throw Error(`Invalid local template dependency for ${t}: ${e}`);return i}function pa(e){let t=ca(e,`template/package.json`),n=[],r=new Set;for(let i of aa)for(let[a,o]of Object.entries(t[i]??{})){if(!la(a)||!da(o))continue;if(r.has(a))throw Error(`Target template declares ${a} more than once.`);let t=fa(o,a),s=ca(e,t);if(s.name!==a||typeof s.version!=`string`)throw Error(`${Lr(e)}:${t} must declare ${a} with a version.`);n.push({group:i,name:a,spec:`^${s.version}`}),r.add(a)}return n}function ma(e,t){for(let n of aa){let r=e[n]?.[t];if(r)return{group:n,spec:r}}}function ha(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.12",
|
|
4
4
|
"description": "Coreframe project workflow CLI and automation scripts",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,14 +29,14 @@
|
|
|
29
29
|
"procband": "^0.3.8",
|
|
30
30
|
"yaml": "^2.9.0",
|
|
31
31
|
"@coreframe/db": "^0.1.5",
|
|
32
|
-
"@coreframe/config": "^0.1.4",
|
|
33
32
|
"@coreframe/deploy": "^0.1.4",
|
|
34
33
|
"@coreframe/dev": "^0.1.7",
|
|
34
|
+
"@coreframe/assets": "^0.1.7",
|
|
35
35
|
"@coreframe/dev-contracts": "^0.1.3",
|
|
36
|
+
"@coreframe/config": "^0.1.4",
|
|
36
37
|
"@coreframe/flutter-tools": "^0.1.9",
|
|
37
38
|
"@coreframe/object-storage": "^0.1.1",
|
|
38
|
-
"@coreframe/preview": "^0.1.3"
|
|
39
|
-
"@coreframe/assets": "^0.1.7"
|
|
39
|
+
"@coreframe/preview": "^0.1.3"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/node": "^26.1.0",
|