diff --git a/package.json b/package.json index 1986c29..0bfda68 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tracememo", - "version": "2.5.2", + "version": "2.6.0", "packageManager": "pnpm@7.33.7", "description": "TraceMemo(迹忆)是一款本地优先、可追溯的 AI 微信知识与分析工作台。 原名 WechatExplorer,支持聊天记录搜索、知识库、微信群聊总结和 Agent 助手。", "keywords": [ diff --git a/scripts/after-pack.cjs b/scripts/after-pack.cjs index 2c80cf8..67a2881 100644 --- a/scripts/after-pack.cjs +++ b/scripts/after-pack.cjs @@ -186,7 +186,21 @@ function validateMacEditionResources(runtimeResources, edition, platform) { throw new Error(`Missing FFmpeg license/build notice: ${relative}`) } } + const ffmpegLicenseHashes = marker.ffmpegLicenseSha256 + if (!ffmpegLicenseHashes || typeof ffmpegLicenseHashes !== 'object') { + throw new Error('Mac build marker is missing FFmpeg license/source notice hashes') + } + for (const [relative, expected] of Object.entries(ffmpegLicenseHashes)) { + const notice = path.join(resources, relative) + if (!/^[a-f0-9]{64}$/.test(expected) || !existsSync(notice) || + createHash('sha256').update(readFileSync(notice)).digest('hex') !== expected) { + throw new Error(`Packaged FFmpeg license/source notice hash mismatch: ${relative}`) + } + } if (edition === 'native') { + if (!readFileSync(host).includes(Buffer.from('/license/status'))) { + throw new Error('Native Host does not implement GET /license/status') + } for (const binary of [helper, host, runtimeDylib]) { if (!readBinaryArchitectures(binary).includes('arm64')) { throw new Error(`Native binary lacks arm64 architecture: ${binary}`) diff --git a/scripts/build-macos-edition.cjs b/scripts/build-macos-edition.cjs index f5c0adf..3a26bfe 100644 --- a/scripts/build-macos-edition.cjs +++ b/scripts/build-macos-edition.cjs @@ -1,13 +1,15 @@ const fs = require('node:fs') const path = require('node:path') const { spawnSync } = require('node:child_process') -const { assertStagingTargetDoesNotExist, prepareEdition, validateStagedEdition } = require('./prepare-macos-edition.cjs') +const { + assertStagingTargetDoesNotExist, + prepareEdition, + resolveEditionRoots, + validateStagedEdition +} = require('./prepare-macos-edition.cjs') const ROOT = path.resolve(__dirname, '..') -const STAGE_ROOT = path.join(ROOT, 'build', 'mac-staging') -const OUTPUT_ROOT = path.join(ROOT, 'dist', 'mac') const EDITIONS = ['public', 'native'] -const CONFIG_ROOT = path.join(STAGE_ROOT, 'configs') const YAML = require('yaml') function run(args, env) { @@ -82,7 +84,7 @@ function createBuilderConfig({ edition, stageRoot, buildOutput, outputRoot, appV artifactName: edition === 'native' ? `TraceMemo-${appVersion}-mac-arm64-native.dmg` - : `TraceMemo-${appVersion}-mac-arm64-public.dmg` + : `TraceMemo-${appVersion}-mac-arm64-oss.dmg` }, npmRebuild: false } @@ -90,20 +92,22 @@ function createBuilderConfig({ edition, stageRoot, buildOutput, outputRoot, appV function buildEdition(edition, options = {}) { if (!EDITIONS.includes(edition)) throw new Error('Usage: build-macos-edition.cjs ') - const stageRoot = path.join(STAGE_ROOT, edition) - const outputRoot = path.join(OUTPUT_ROOT, edition) + const roots = resolveEditionRoots() + const stageRoot = path.join(roots.stageRoot, edition) + const outputRoot = path.join(roots.outputRoot, edition) + const configRoot = path.join(roots.stageRoot, 'configs') if (fs.existsSync(stageRoot) && !options.reuseStaging) { throw new Error(`Refusing to overwrite existing build staging: ${stageRoot}`) } if (fs.existsSync(outputRoot)) throw new Error(`Refusing to overwrite existing build output: ${outputRoot}`) - if (fs.existsSync(CONFIG_ROOT)) throw new Error(`Refusing to overwrite existing build config directory: ${CONFIG_ROOT}`) + if (fs.existsSync(configRoot)) throw new Error(`Refusing to overwrite existing build config directory: ${configRoot}`) const preparation = fs.existsSync(stageRoot) ? Promise.resolve(validateStagedEdition(edition)) : prepareEdition(edition) if (!preparation || typeof preparation.then !== 'function') throw new Error('Edition staging preparation did not return a Promise') return preparation.then(() => { const buildOutput = path.join(stageRoot, 'out') - const configPath = path.join(CONFIG_ROOT, `electron-builder-${edition}.yml`) + const configPath = path.join(configRoot, `electron-builder-${edition}.yml`) let ownsConfigRoot = false let buildSucceeded = false try { @@ -125,7 +129,7 @@ function buildEdition(edition, options = {}) { ], env ) - fs.mkdirSync(CONFIG_ROOT) + fs.mkdirSync(configRoot, { recursive: true }) ownsConfigRoot = true const config = createBuilderConfig({ edition, @@ -147,7 +151,7 @@ function buildEdition(edition, options = {}) { ) buildSucceeded = true } finally { - if (ownsConfigRoot) fs.rmSync(CONFIG_ROOT, { recursive: true, force: true }) + if (ownsConfigRoot) fs.rmSync(configRoot, { recursive: true, force: true }) if (!buildSucceeded && fs.existsSync(outputRoot)) { fs.rmSync(outputRoot, { recursive: true, force: true }) } diff --git a/scripts/prepare-macos-edition.cjs b/scripts/prepare-macos-edition.cjs index 5d6d3d8..ae75813 100644 --- a/scripts/prepare-macos-edition.cjs +++ b/scripts/prepare-macos-edition.cjs @@ -8,6 +8,12 @@ const { pipeline } = require('node:stream/promises') const { readBinaryArchitectures } = require('./binary-arch.cjs') const ROOT = path.resolve(__dirname, '..') +function resolveEditionRoots(projectRoot = ROOT, env = process.env) { + return { + stageRoot: path.resolve(env.TRACEMEMO_MAC_STAGE_ROOT || path.join(projectRoot, 'build', 'mac-staging')), + outputRoot: path.resolve(env.TRACEMEMO_MAC_OUTPUT_ROOT || path.join(projectRoot, 'dist', 'mac')) + } +} const WCDB_DIST_ROOT = resolveWcdbDistRoot() const NATIVE_DIST_ROOT = process.env.TRACEMEMO_NATIVE_DIST_ROOT || path.resolve(ROOT, '..', 'native-runtime-dist') @@ -121,6 +127,12 @@ function assertArm64(filePath, label) { } } +function validateLicenseStatusRoute(hostPath) { + if (!fs.readFileSync(hostPath).includes(Buffer.from('/license/status'))) { + throw new Error(`Native Host does not implement GET /license/status: ${hostPath}`) + } +} + function validateWcdbPair(apiPath, dependencyPath, profile) { if (!fs.existsSync(apiPath) || !fs.existsSync(dependencyPath)) { throw new Error(`Missing ${profile} WCDB library pair: ${apiPath}`) @@ -227,6 +239,7 @@ function validateNativeBundle(bundleRoot, files) { const runtimeDylib = bySuffix('/runtime/libtmwechat.dylib') const runtimeManifestPath = bySuffix('/runtime/runtime-manifest.json') const licenseDylib = bySuffix('/runtime/libtmlicense.dylib') + validateLicenseStatusRoute(host) validateWcdbPair(api, companion, 'native') for (const [binary, label] of [ [helper, 'WCDB helper'], @@ -312,9 +325,17 @@ function copyPublicResources(sourceResources, destination) { } function copyFfmpegLicenses(destination) { - const packageRoot = path.dirname(require.resolve('ffmpeg-static/package.json')) - for (const [sourceName, destinationRelative] of FFMPEG_LICENSE_FILES) { - const source = path.join(packageRoot, sourceName) + const suppliedLicenseRoot = String(process.env.TRACEMEMO_FFMPEG_LICENSE_DIR || '').trim() + const packageRoot = suppliedLicenseRoot || path.dirname(require.resolve('ffmpeg-static/package.json')) + const files = suppliedLicenseRoot + ? [ + ['LICENSE', 'LICENSE', 'licenses/ffmpeg-static/LICENSE'], + ['FFMPEG-LICENSE.txt', 'FFMPEG-LICENSE.txt', 'licenses/ffmpeg-static/FFMPEG-LICENSE.txt'], + ['FFMPEG-BUILD-INFO.txt', 'FFMPEG-BUILD-INFO.txt', 'licenses/ffmpeg-static/FFMPEG-BUILD-INFO.txt'] + ] + : FFMPEG_LICENSE_FILES.map(([source, relative]) => [source, source, relative]) + for (const [sourceName, inputName, destinationRelative] of files) { + const source = path.join(packageRoot, inputName) if (!fs.existsSync(source)) throw new Error(`Missing FFmpeg license/source notice: ${source}`) const target = path.join(destination, destinationRelative) fs.mkdirSync(path.dirname(target), { recursive: true }) @@ -389,8 +410,9 @@ function assertNoProtectedInputs(root) { async function prepareEdition(edition) { if (edition !== 'public' && edition !== 'native') throw new Error('Usage: prepare-macos-edition.cjs ') - const stageRoot = path.join(ROOT, 'build', 'mac-staging', edition) - const outputRoot = path.join(ROOT, 'dist', 'mac', edition) + const roots = resolveEditionRoots() + const stageRoot = path.join(roots.stageRoot, edition) + const outputRoot = path.join(roots.outputRoot, edition) assertStagingTargetDoesNotExist(stageRoot, outputRoot) const sourceResources = path.join(ROOT, 'resources') @@ -407,7 +429,13 @@ async function prepareEdition(edition) { const marker = { profile: edition, appVersion: require(path.join(ROOT, 'package.json')).version, - ffmpegSha256 + ffmpegSha256, + ffmpegLicenseSource: process.env.TRACEMEMO_FFMPEG_LICENSE_DIR + ? 'provided verified license files' + : 'ffmpeg-static package', + ffmpegLicenseSha256: Object.fromEntries( + FFMPEG_LICENSE_FILES.map(([, relative]) => [relative, sha256(path.join(stagedResources, relative))]) + ) } if (edition === 'public') { const api = path.join(WCDB_DIST_ROOT, 'libwcdb_api.dylib') @@ -470,7 +498,7 @@ async function prepareEdition(edition) { function validateStagedEdition(edition) { if (edition !== 'public' && edition !== 'native') throw new Error('Usage: validate staged edition ') - const resources = path.join(ROOT, 'build', 'mac-staging', edition, 'resources') + const resources = path.join(resolveEditionRoots().stageRoot, edition, 'resources') const markerPath = path.join(resources, 'tracememo-build.json') if (!fs.existsSync(markerPath)) throw new Error(`Missing staged edition marker: ${markerPath}`) const marker = JSON.parse(fs.readFileSync(markerPath, 'utf8')) @@ -487,6 +515,13 @@ function validateStagedEdition(edition) { throw new Error('Staged FFmpeg SHA-256 does not match the edition marker') } assertArm64(ffmpeg, 'Staged FFmpeg') + for (const [, relative] of FFMPEG_LICENSE_FILES) { + const licensePath = path.join(resources, relative) + const expected = marker.ffmpegLicenseSha256?.[relative] + if (!fs.existsSync(licensePath) || !/^[a-f0-9]{64}$/.test(expected || '') || sha256(licensePath) !== expected) { + throw new Error(`Staged FFmpeg license/source notice hash mismatch: ${relative}`) + } + } const api = path.join(resources, 'wcdb', 'macos', 'arm64', 'libwcdb_api.dylib') const companion = path.join(resources, 'wcdb', 'macos', 'arm64', 'libWCDB.dylib') validateWcdbPair(api, companion, edition) @@ -608,6 +643,8 @@ if (require.main === module) { } module.exports = { + resolveEditionRoots, + validateLicenseStatusRoute, assertNoProtectedInputs, assertStagingTargetDoesNotExist, copyPublicResources, diff --git a/src/renderer/src/features/settings/pages/PersonalWechatSendPage.tsx b/src/renderer/src/features/settings/pages/PersonalWechatSendPage.tsx index f818f03..a479e45 100644 --- a/src/renderer/src/features/settings/pages/PersonalWechatSendPage.tsx +++ b/src/renderer/src/features/settings/pages/PersonalWechatSendPage.tsx @@ -166,7 +166,7 @@ function summarizeDeviceId(deviceId: string): string { } /** 展示当前设备的授权状态,并提供刷新与复制设备 ID 的操作。 */ -export function MacProLicenseCard({ +export function MacNativeLicenseCard({ onNotice, onStatusChange }: { @@ -231,16 +231,16 @@ export function MacProLicenseCard({ } return ( -
-
+
+
发送能力授权 - + {macLicenseStatusLabel(license)}
-
-
+
+
本机设备 ID {license.deviceId ? summarizeDeviceId(license.deviceId) : '(尚未生成)'} @@ -257,16 +257,16 @@ export function MacProLicenseCard({
{license.deviceId && (!license.authorized || licenseStateConflictsWithExpiry(license)) ? ( -

{macLicenseStatusHint(license)}

+

{macLicenseStatusHint(license)}

) : null} {license.authorized && license.features.length > 0 ? ( -
+
{license.features.map((feature) => ( {macLicenseFeatureLabel[feature] || feature} ))}
) : null} -
+
授权到期 {formatMacLicenseDate(license.licenseExpiresAt)} @@ -274,7 +274,7 @@ export function MacProLicenseCard({ 最近检测 {formatMacLicenseDateTime(license.lastCheckedAt)}
-
+