import { StrictMode, useCallback, useEffect, useMemo, useRef, useState } from 'react' import { createRoot } from 'react-dom/client' import { invoke } from '@tauri-apps/api/core' import { splitFrontmatter, documentOutline, jumpToHeading, MarkdownDocument, markdownHtml } from './modules/knowledge-render' const TAG_TINTS = ['tag-lavender', 'tag-sky', 'tag-mint', 'tag-amber', 'tag-rose', 'tag-slate'] // 编号自动补齐:人只敲字母与数字,杠由系统按已登记文法自动出。 // ICE 系(ICE-GL∞ / ICE-P-ZY001)、GLS 系(GLS-LA-20260720-003);认不出的文法只在字母数字交界处补杠。 function formatGateNumber(raw: string): string { const up = raw.toUpperCase() if (up.startsWith('ICE')) { const rest = up.slice(3) if (!rest) return 'ICE' if (rest.startsWith('P')) { const body = rest.slice(1) return body ? `ICE-P-${body}` : 'ICE-P' } return `ICE-${rest}` } if (up.startsWith('TCS')) { const rest = up.slice(3) if (!rest) return 'TCS' if (rest.startsWith('GL')) { const body = rest.slice(2) return body ? `TCS-GL-${body}` : 'TCS-GL' } return `TCS-${rest}` } if (up.startsWith('GLS')) { const rest = up.slice(3) if (!rest) return 'GLS' const letters = rest.match(/^[A-Z]*/)?.[0] ?? '' const digits = rest.slice(letters.length) if (!digits) return `GLS-${letters}` const d1 = digits.slice(0, 8) const d2 = digits.slice(8, 11) return `GLS-${letters}-${d1}${d2 ? `-${d2}` : ''}` } return up.replace(/([A-Z]+)([0-9])/g, '$1-$2').replace(/([0-9]+)([A-Z])/g, '$1-$2') } function tagTint(tag: string) { let hash = 0 for (const char of tag) hash = (hash * 31 + (char.codePointAt(0) || 0)) % 997 return TAG_TINTS[hash % TAG_TINTS.length] } import './design-tokens.css' import './styles.css' type ThemeId = 'night' | 'dawn' | 'nebula' | 'candle' | 'clear' type ViewId = 'overview' | 'knowledge' | 'code' | 'receipts' | 'system' type WorldStage = 'domain' | 'channel' | 'tool' type KnowledgeSource = 'native' | 'legacy' interface HomeStatus { directLocalBrokerState: string directConnectionCount: number resumableSessionCount: number codeRepositoryMountCount: number pnccReceiptCount: number updateState: string releaseRecoveryState: string mcpRole: string } interface PersonalChannelIdentity { humanSubjectId: string; displayName: string; channelId: string; createdAtUnixMs: number } interface LoginSession { username: string; host: string; domain: string; signedInAtUnixMs: number } interface LoginReceipt { username: string; email: string; host: string; domain: string } interface UserPnccChannelSnapshot { state: string repositoryId: string channelId: string userNumber: string domain: string accountUsername: string accountHost: string localPath: string branch: string gitHead: string repositoryClean: boolean createdAtUnixMs: number gitEngine: string humanProjection: string forgejoAdapterState: string remoteRepositoryUrl?: string personaBindingClaimed: boolean authority: string } interface PersonalChannelEvent { sequence: number; eventId: string; kind: string; summary: string; occurredAtUnixMs: number; receiptId: string; receiptHash: string } interface PersonalChannelSnapshot { state: string; identity?: PersonalChannelIdentity; recentEvents: PersonalChannelEvent[]; integrity: { state: string; eventCount: number; receiptCount: number } } interface KnowledgeDocumentSummary { source: KnowledgeSource path: string title: string updatedAtUnixMs: number sizeBytes: number contentSha256: string duplicateCount: number } interface KnowledgeSnapshot { state: string nativeRoot: string legacyAvailable: boolean legacyRoot?: string documents: KnowledgeDocumentSummary[] rawDocumentCount: number uniqueDocumentCount: number duplicateDocumentCount: number truncated: boolean } interface KnowledgeDocument { source: KnowledgeSource path: string title: string body: string updatedAtUnixMs: number contentSha256: string writable: boolean } interface KnowledgeSearchResult { source: KnowledgeSource; path: string; title: string; snippet: string } interface KnowledgeImportResult { state: string sourceName: string importedDocuments: number importedAssets: number existingDocuments: number conflicts: number skipped: number firstDocument?: string gitCommit: string snapshot: KnowledgeSnapshot } interface KnowledgeSaveResult { state: string; gitCommit: string; document: KnowledgeDocument } interface CodeChannelEntry { channelId: string; name: string; sourceKind: string; localPath: string; remoteUrl?: string; gitHead: string; branch: string; repositoryClean: boolean; registeredAtUnixMs: number } interface CodeChannelSnapshot { state: string; channels: CodeChannelEntry[]; authority: string } interface CodeTreeEntry { path: string; name: string; kind: 'directory' | 'file'; sizeBytes: number } interface CodeTreeSnapshot { channelId: string; path: string; entries: CodeTreeEntry[]; truncated: boolean } interface CodeFileProjection { channelId: string; path: string; format: string; source: string; humanMarkdown: string; sizeBytes: number } interface ReceiptEvent { sequence: number; kind: string; observedAtUnixMs: number; eventHash: string } interface ReceiptProjection { events: ReceiptEvent[] } interface DiscoveryTicketReceipt { laneId: string; clientInstanceId: string; discoveryTicket: string } interface NearbyAiDiscoverySnapshot { state: string serviceName: string transport: string languageProtocol: string automaticSameDeviceDiscovery: boolean largeInvitationCopyRequired: boolean genericAiVisitor: string guanghuPersona: string localNetworkDiscovery: string authority: string } interface ReleaseCandidate { candidateId: string; confirmationToken: string; currentVersion: string; version: string; notes: string; features: string[]; fixes: string[]; dataMigrationRequired: boolean } interface ReleaseCheckReceipt { candidate?: ReleaseCandidate } interface ZeroPointSnapshot { route: string binding: string userNumber: string resolvedName: string resolvedDomain: string lastValidCheck: number graceDeadline: number protocol: { gracePeriodDays: number; lighthouseAnchorUrl: string; lighthouseResolveUrl: string; coreChannelSource: string; origin: string } syncNote: string } function domainDisplayName(domain: string): string { const names: Record = { FIFTH_DOMAIN: '第五域 · 光湖本源域', MAIN_DOMAIN: '光湖主域', BRANCH_DOMAIN: '光湖分域', ZERO_DOMAIN: '光湖零域', ZERO_SENSE_DOMAIN: '光湖零感域', } return names[domain] || '已登记光湖域' } function protocolOriginDisplayName(origin: string): string { return origin.startsWith('FACTORY_DEFAULT') ? '内置默认协议(签名发布通道尚未配置)' : origin } interface ServerPnccProjection { schema: string state: string personaId: string humanResponsibilitySubject: string nodeId: string bootId: string gitHead: string carrierBindingState: string personaCarrierBound: boolean modelInferenceStarted: boolean realityExecutionAllowed: boolean primaryLeaseHeld: boolean eventCount: number eventChainHead: string observedAtUnixMs: number transport: string repositoryContentExposed: boolean writeAuthority: boolean } interface EnterprisePersonaRelationship { persona_id: string species: string display_name?: string relation?: string } interface EnterpriseEntry { status: string canonical_id: string subject: { id: string; name: string; domain: string } work_entry: { domain: string; channel: string } repository_binding: { host: string; username: string; repository: string; private: boolean } persona_relationships: EnterprisePersonaRelationship[] persona_identity_governance: string registry_version: string relationship_confirmation?: { decision: string; observed_at: string; receipt_hash: string } | null responsibility_receipt?: { decision: string; observed_at: string; receipt_hash: string; responsibility_version: string } | null } interface EnterpriseEntryEnvelope { ok: boolean; entry: EnterpriseEntry } const previewStatus: HomeStatus = { directLocalBrokerState: 'UNVERIFIED', directConnectionCount: 0, resumableSessionCount: 0, codeRepositoryMountCount: 0, pnccReceiptCount: 0, updateState: 'UNPROVISIONED_FAIL_CLOSED', releaseRecoveryState: 'NONE', mcpRole: 'DISCOVERY_RECOVERY_COMPATIBILITY_ONLY' } const previewPersonal: PersonalChannelSnapshot = { state: 'UNAVAILABLE', recentEvents: [], integrity: { state: 'UNKNOWN', eventCount: 0, receiptCount: 0 } } const previewKnowledge: KnowledgeSnapshot = { state: 'UNAVAILABLE', nativeRoot: '', legacyAvailable: false, documents: [], rawDocumentCount: 0, uniqueDocumentCount: 0, duplicateDocumentCount: 0, truncated: false } const previewCode: CodeChannelSnapshot = { state: 'UNAVAILABLE', channels: [], authority: 'LOCAL_SOURCE_ACCESS_ONLY_NO_PUSH_OR_DEPLOY_AUTHORITY' } const themes: Array<{ id: ThemeId; name: string }> = [ { id: 'night', name: '夜湖星光' }, { id: 'dawn', name: '晨湖曦光' }, { id: 'nebula', name: '星云紫夜' }, { id: 'candle', name: '烛畔暖湖' }, { id: 'clear', name: '清浅澄湖' }, ] const viewLabels: Record = { overview: '个人频道', knowledge: '知识空间', code: '人格代码频道', receipts: '运行回执', system: '系统详情' } const domainGates = [ { domain: 'BRANCH_DOMAIN', className: 'd-sub', title: '光湖分域', gate: 'GATE 02 · 已接入', detail: '花尔 TCS-GL-0005∞ · 爆米花 PER-BMH001 · 私有工作仓库已登记' }, { domain: 'MAIN_DOMAIN', className: 'd-main', title: '光湖主域', gate: 'GATE 01 · 已接入', detail: 'Awen TCS-GL-0016∞ · 天枢 PER-AW-ARCH-001 · 私有工作仓库已登记' }, { domain: 'ZERO_DOMAIN', className: 'd-zero', title: '光湖零域', gate: 'GATE 03 · 已接入', detail: '页页 TCS-GL-0006∞ · 页骨 PER-YG001 · 私有工作仓库已登记' }, { domain: 'ZERO_SENSE_DOMAIN', className: 'd-zs', title: '光湖零感域', gate: 'GATE 04 · 已接入', detail: '肥猫 + 烬舟 / 桔子 + 熹微 · 双主控 · 两个独立私有仓库' }, { domain: 'FIFTH_DOMAIN', className: 'd-fifth', title: '第五域 · 光湖本源域', gate: 'GATE 05 · 已接入', detail: '冰朔 ICE-GL∞ · 私人域 · 永恒湖心系统' }, ] const starPoints = [ [14, 8, 3, 4.6], [26, 13, 2, 6], [41, 6, 2.5, 5.2], [64, 16, 2, 6.8], [80, 7, 3.5, 7], [90, 20, 1.5, 5.4], [8, 22, 2, 5.6], [93, 11, 2.5, 6.4], ] const glintPoints = Array.from({ length: 58 }, (_, index) => ({ left: (index * 37 + 11) % 100, top: ((index * index * 13 + 17) % 100), size: 1.4 + (index % 4) * .55, warm: index % 5 === 0 || (index > 19 && index < 39 && index % 3 === 0), duration: 2.8 + (index % 7) * .57, delay: (index % 11) * .43, })) function LakeAtmosphere() { return <>