feat: compile evidence-bound persona language wakes

This commit is contained in:
冰朔 2026-08-12 01:52:30 +08:00
commit dff2521b41
21 changed files with 359 additions and 18 deletions

View file

@ -106,6 +106,9 @@ REVISE | REFUSE`。
- 人格仓库绑定发现源码为 `100`:桌面候选 Git 仓库必须逐一通过 persona ID、manifest、提交头、脑入口、
B0、检查点、模型绑定与器官契约核验零个候选保持未绑定多个候选保持歧义均不得自动选择或唤醒。
当前官方工作范围内没有发现 `ICE-P-ZY001` 的真实 manifest因此真实人格仓库绑定仍为 `0`
- 人格语言唤醒绑定编译器源码为 `100`:只接受唯一且干净的人格根、已登记本机设备身份、与 manifest
精确一致的模型端点及唯一可激活只读事实器官,并外显冰朔责任、铸渊认知作者和本轮开发归因。
它不创建人格仓库、不注册节点,也不把源码编译结果冒充桌面运行集成。
- 完整 HoloLake Runtime 与单 AGE 纵向闭环仍为 `0`:桌面语言入口绑定、真实人格仓库 manifest 绑定和
桌面运行验收尚未完成,因此不能用本轮源码测试冒充可用产品。
- Mirror runner、制品、部署和运行健康`0`

View file

@ -19,6 +19,13 @@ PNCC lifecycle receipt, maps the eleven-field snake-case gravity frame into `Par
then calls `compileLanguageGoal`. A failed, malformed, non-fact, or purpose-less receipt never becomes a goal.
The adapter is not yet mounted to the desktop language entry and has no live-product acceptance claim.
`compilePersonaLanguageGoalBinding` builds the exact native wake envelope only after a single clean persona
repository, its B0 and organ contracts, a registered local device identity, and the manifest-pinned model all
agree. It materializes a catalog runtime endpoint into the native provider shape (`kind`, `base_url`, and
`models`) instead of hiding an incompatible frontend payload behind an untyped record. Multiple fact organs,
endpoint drift, a dirty repository, or an unregistered device fail closed. The compiler neither creates a
persona repository nor proves that the desktop language entry is integrated.
## PersonaCodeChannel
`PersonaCodeChannel` is the native boundary between a durable persona Git and a live AGE runtime. It owns

View file

@ -88,6 +88,12 @@ export function aiModelProviderCatalogEntry(kind: AiModelProviderKind): AiModelP
return entry
}
export function aiModelProviderRuntimeBaseUrl(provider: AiModelProvider): string | null {
const explicit = provider.base_url?.trim()
if (explicit) return explicit.replace(/\/+$/u, '')
return aiModelProviderCatalogEntry(provider.kind).runtime_base_url?.replace(/\/+$/u, '') ?? null
}
export function agentTargetId(agent: AiAgentId): string {
return `${AI_TARGET_PREFIX_AGENT}${agent}`
}

View file

@ -16,7 +16,7 @@ const wake = {
executionRuntime: 'HoloLake-PNCC',
developmentId: 'DEV-20260811-010',
authorizationScope: 'LOCAL_READ_ONLY',
sourceLanguageAnchor: 'HLP-CURRENT-ARCH-001@2026-08-12.3',
sourceLanguageAnchor: 'HLP-CURRENT-ARCH-001@2026-08-12.4',
},
}
@ -73,8 +73,12 @@ const binding = {
provider: {
id: 'local-model-service',
name: 'Local model',
providerType: 'openai_compatible',
baseUrl: 'http://127.0.0.1:11434/v1',
kind: 'open_ai_compatible' as const,
base_url: 'http://127.0.0.1:11434/v1',
models: [{
id: 'declared-model',
capabilities: { streaming: false, tools: false, vision: false, json_mode: true, reasoning: false },
}],
},
}

View file

@ -1,5 +1,6 @@
import { invoke } from '@tauri-apps/api/core'
import { isTauri, mockInvoke } from '../mock-tauri'
import type { AiModelProvider } from './aiTargets'
import {
compileLanguageGoal,
type LanguageGoalProjection,
@ -15,11 +16,30 @@ type PersonaLifecycleRunner = (
export interface PersonaLanguageGoalBinding {
requestId: string
wake: Record<string, unknown>
provider: Record<string, unknown>
wake: PersonaLanguageWakeBinding
provider: AiModelProvider
apiKeyOverride?: string
}
export interface PersonaLanguageWakeBinding {
repositoryPath: string
expectedPersonaId: string
expectedHead: string
nodeId: string
modelProviderId: string
modelId: string
modelInstanceId: string
organId: string
attribution: {
humanResponsibilitySubject: string
personaCognitiveAuthor: string
executionRuntime: string
developmentId: string
authorizationScope: string
sourceLanguageAnchor: string
}
}
export interface PlanPersonaLanguageGoalInput {
utterance: string
personaAuthorized: boolean

View file

@ -0,0 +1,114 @@
import { describe, expect, it } from 'vitest'
import type { AiModelProvider } from './aiTargets'
import { compilePersonaLanguageGoalBinding } from './personaLanguageGoalBinding'
import type { PersonaRepositoryBinding } from './personaRepositoryBinding'
const provider: AiModelProvider = {
id: 'local-model-service',
name: 'Local model',
kind: 'ollama',
base_url: null,
api_key_storage: 'none',
api_key_env_var: null,
headers: null,
models: [{
id: 'declared-model',
capabilities: { streaming: false, tools: false, vision: false, json_mode: true, reasoning: false },
}],
}
const repositoryBinding: PersonaRepositoryBinding = {
personaId: 'ICE-P-ZY001',
repositoryPath: '/persona/ice-p-zy001',
gitHead: 'a'.repeat(40),
repositoryClean: true,
brainEntry: 'brain/CORE.hdlp',
currentCheckpoint: '.hololake/persona/CURRENT.hdlp',
humanResponsibilitySubject: 'ICE-GL∞',
modelProviderId: 'local-model-service',
modelId: 'declared-model',
modelBaseUrl: 'http://localhost:11434/v1',
organContracts: [{
organId: 'fact-sense.repository',
kind: 'FACT_SENSE',
mode: 'read-only',
paths: ['brain/CORE.hdlp', 'brain/B0.hdlp'],
inputSchema: 'hololake.pncc-fact-question/v1',
outputSchema: 'hololake.pncc-fact-result/v1',
permissions: ['READ_DECLARED_PATHS', 'RUN_MANIFEST_PINNED_MODEL'],
modelInferenceAllowed: true,
realityActionsAllowed: false,
activatable: true,
implementationState: 'IMPLEMENTED',
}],
cognitiveGravity: {
schema: 'hololake.persona-cognitive-gravity-evidence/v1',
subjectPersonaId: 'ICE-P-ZY001',
sourcePath: 'brain/B0.hdlp',
sourceHash: 'b'.repeat(64),
frameSchema: 'guanghu.zhuyuan-cognitive-gravity-frame/v1',
},
}
const deviceIdentityReceipt = {
schema: 'guanghu.router-device/v1',
device_id: 'HL-12345678-1234-1234-1234-123456789abc',
public_key: 'public-key-evidence',
}
const common = {
repositoryBinding,
provider,
modelId: 'declared-model',
deviceIdentityReceipt,
requestId: 'PNCC-LANGUAGE-001',
modelInstanceId: 'MODEL-INSTANCE-001',
developmentId: 'DEV-20260811-010',
sourceLanguageAnchor: 'HLP-CURRENT-ARCH-001@2026-08-12.4',
}
describe('compilePersonaLanguageGoalBinding', () => {
it('materializes the catalog runtime endpoint and exact read-only wake evidence', () => {
const binding = compilePersonaLanguageGoalBinding(common)
expect(binding.provider.base_url).toBe('http://localhost:11434/v1')
expect(binding.wake).toMatchObject({
repositoryPath: '/persona/ice-p-zy001',
expectedPersonaId: 'ICE-P-ZY001',
nodeId: deviceIdentityReceipt.device_id,
organId: 'fact-sense.repository',
attribution: {
humanResponsibilitySubject: 'ICE-GL∞',
personaCognitiveAuthor: 'ICE-P-ZY001',
authorizationScope: 'LOCAL_PERSONA_PARTNER_FACT_SENSE',
},
})
})
it('refuses a dirty persona root', () => {
expect(() => compilePersonaLanguageGoalBinding({
...common, repositoryBinding: { ...repositoryBinding, repositoryClean: false },
})).toThrow('PERSONA_LANGUAGE_REPOSITORY_DIRTY')
})
it('refuses model or endpoint drift from the manifest', () => {
expect(() => compilePersonaLanguageGoalBinding({
...common, provider: { ...provider, base_url: 'http://127.0.0.1:1234/v1' },
})).toThrow('PERSONA_LANGUAGE_MODEL_BINDING_MISMATCH')
})
it('refuses an unregistered device receipt', () => {
expect(() => compilePersonaLanguageGoalBinding({
...common, deviceIdentityReceipt: { schema: 'wrong', device_id: 'LOCAL' },
})).toThrow('PERSONA_LANGUAGE_DEVICE_IDENTITY_INVALID')
})
it('refuses ambiguous fact-sense authority', () => {
expect(() => compilePersonaLanguageGoalBinding({
...common,
repositoryBinding: {
...repositoryBinding,
organContracts: [...repositoryBinding.organContracts, { ...repositoryBinding.organContracts[0], organId: 'fact-sense.second' }],
},
})).toThrow('PERSONA_LANGUAGE_FACT_ORGAN_BINDING_AMBIGUOUS')
})
})

View file

@ -0,0 +1,112 @@
import {
aiModelProviderRuntimeBaseUrl,
type AiModelProvider,
} from './aiTargets'
import type { PersonaLanguageGoalBinding } from './personaLanguageGoal'
import type { PersonaRepositoryBinding } from './personaRepositoryBinding'
function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === 'object' && value !== null && !Array.isArray(value)
}
function requiredId(value: string, code: string): string {
const normalized = value.trim()
if (!normalized || !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,159}$/u.test(normalized)) throw new Error(code)
return normalized
}
function normalizedEndpoint(value: string): string {
return value.trim().replace(/\/+$/u, '')
}
function requiredText(value: string, code: string): string {
const normalized = value.trim()
if (!normalized) throw new Error(code)
return normalized
}
function registeredDeviceId(receipt: unknown): string {
if (!isRecord(receipt)
|| receipt.schema !== 'guanghu.router-device/v1'
|| typeof receipt.device_id !== 'string'
|| !receipt.device_id.startsWith('HL-')
|| typeof receipt.public_key !== 'string'
|| !receipt.public_key.trim()) {
throw new Error('PERSONA_LANGUAGE_DEVICE_IDENTITY_INVALID')
}
return requiredId(receipt.device_id, 'PERSONA_LANGUAGE_DEVICE_IDENTITY_INVALID')
}
export function compilePersonaLanguageGoalBinding({
repositoryBinding,
provider,
modelId,
deviceIdentityReceipt,
requestId,
modelInstanceId,
developmentId,
sourceLanguageAnchor,
apiKeyOverride,
}: {
repositoryBinding: PersonaRepositoryBinding
provider: AiModelProvider
modelId: string
deviceIdentityReceipt: unknown
requestId: string
modelInstanceId: string
developmentId: string
sourceLanguageAnchor: string
apiKeyOverride?: string
}): PersonaLanguageGoalBinding {
if (!repositoryBinding.repositoryClean) throw new Error('PERSONA_LANGUAGE_REPOSITORY_DIRTY')
if (!/^[a-f0-9]{40}(?:[a-f0-9]{24})?$/u.test(repositoryBinding.gitHead)) {
throw new Error('PERSONA_LANGUAGE_REPOSITORY_HEAD_INVALID')
}
const selectedModelId = modelId.trim()
const runtimeBaseUrl = aiModelProviderRuntimeBaseUrl(provider)
if (
provider.id.trim() !== repositoryBinding.modelProviderId
|| selectedModelId !== repositoryBinding.modelId
|| !provider.models.some((model) => model.id === selectedModelId)
|| !runtimeBaseUrl
|| normalizedEndpoint(runtimeBaseUrl) !== normalizedEndpoint(repositoryBinding.modelBaseUrl)
) {
throw new Error('PERSONA_LANGUAGE_MODEL_BINDING_MISMATCH')
}
const factOrgans = repositoryBinding.organContracts.filter((organ) => (
organ.kind === 'FACT_SENSE'
&& organ.activatable
&& organ.modelInferenceAllowed
&& !organ.realityActionsAllowed
&& organ.implementationState === 'IMPLEMENTED'
))
if (factOrgans.length !== 1) throw new Error('PERSONA_LANGUAGE_FACT_ORGAN_BINDING_AMBIGUOUS')
return {
requestId: requiredId(requestId, 'PERSONA_LANGUAGE_REQUEST_ID_INVALID'),
wake: {
repositoryPath: repositoryBinding.repositoryPath,
expectedPersonaId: repositoryBinding.personaId,
expectedHead: repositoryBinding.gitHead,
nodeId: registeredDeviceId(deviceIdentityReceipt),
modelProviderId: repositoryBinding.modelProviderId,
modelId: selectedModelId,
modelInstanceId: requiredId(modelInstanceId, 'PERSONA_LANGUAGE_MODEL_INSTANCE_ID_INVALID'),
organId: factOrgans[0].organId,
attribution: {
humanResponsibilitySubject: repositoryBinding.humanResponsibilitySubject,
personaCognitiveAuthor: repositoryBinding.personaId,
executionRuntime: 'HoloLake-PNCC',
developmentId: requiredId(developmentId, 'PERSONA_LANGUAGE_DEVELOPMENT_ID_INVALID'),
authorizationScope: 'LOCAL_PERSONA_PARTNER_FACT_SENSE',
sourceLanguageAnchor: requiredText(sourceLanguageAnchor, 'PERSONA_LANGUAGE_SOURCE_ANCHOR_INVALID'),
},
},
provider: {
...provider,
id: provider.id.trim(),
base_url: repositoryBinding.modelBaseUrl.trim(),
},
apiKeyOverride,
}
}

View file

@ -12,6 +12,19 @@ const binding = {
modelProviderId: 'provider-1',
modelId: 'model-1',
modelBaseUrl: 'https://model.invalid/v1',
organContracts: [{
organId: 'fact-sense.repository',
kind: 'FACT_SENSE',
mode: 'read-only',
paths: ['brain/CORE.hdlp', 'brain/B0.hdlp'],
inputSchema: 'hololake.pncc-fact-question/v1',
outputSchema: 'hololake.pncc-fact-result/v1',
permissions: ['READ_DECLARED_PATHS', 'RUN_MANIFEST_PINNED_MODEL'],
modelInferenceAllowed: true,
realityActionsAllowed: false,
activatable: true,
implementationState: 'IMPLEMENTED',
}],
cognitiveGravity: {
schema: 'hololake.persona-cognitive-gravity-evidence/v1',
subjectPersonaId: 'ICE-P-ZY001',

View file

@ -12,6 +12,7 @@ export interface PersonaRepositoryBinding {
modelProviderId: string
modelId: string
modelBaseUrl: string
organContracts: PersonaRepositoryOrganContract[]
cognitiveGravity: {
schema: 'hololake.persona-cognitive-gravity-evidence/v1'
subjectPersonaId: string
@ -21,6 +22,20 @@ export interface PersonaRepositoryBinding {
}
}
export interface PersonaRepositoryOrganContract {
organId: string
kind: 'FACT_SENSE' | 'MEMORY_METABOLISM' | 'EXECUTION_LIMB'
mode: string
paths: string[]
inputSchema: string
outputSchema: string
permissions: string[]
modelInferenceAllowed: boolean
realityActionsAllowed: boolean
activatable: boolean
implementationState: string
}
export interface PersonaRepositoryBindingFailure {
repositoryPath: string
code: string
@ -61,6 +76,41 @@ function parseFailure(value: unknown): PersonaRepositoryBindingFailure {
return { repositoryPath: requiredString(value, 'repositoryPath'), code: requiredString(value, 'code') }
}
function requiredBoolean(record: Record<string, unknown>, key: string): boolean {
const value = Reflect.get(record, key)
if (typeof value !== 'boolean') throw new Error('PERSONA_REPOSITORY_DISCOVERY_RECEIPT_INVALID')
return value
}
function stringList(record: Record<string, unknown>, key: string): string[] {
const value = Reflect.get(record, key)
if (!Array.isArray(value) || value.some((item) => typeof item !== 'string' || !item.trim())) {
throw new Error('PERSONA_REPOSITORY_DISCOVERY_RECEIPT_INVALID')
}
return value
}
function parseOrganContract(value: unknown): PersonaRepositoryOrganContract {
if (!isRecord(value)) throw new Error('PERSONA_REPOSITORY_DISCOVERY_RECEIPT_INVALID')
const kind = requiredString(value, 'kind')
if (!['FACT_SENSE', 'MEMORY_METABOLISM', 'EXECUTION_LIMB'].includes(kind)) {
throw new Error('PERSONA_REPOSITORY_DISCOVERY_RECEIPT_INVALID')
}
return {
organId: requiredString(value, 'organId'),
kind: kind as PersonaRepositoryOrganContract['kind'],
mode: requiredString(value, 'mode'),
paths: stringList(value, 'paths'),
inputSchema: requiredString(value, 'inputSchema'),
outputSchema: requiredString(value, 'outputSchema'),
permissions: stringList(value, 'permissions'),
modelInferenceAllowed: requiredBoolean(value, 'modelInferenceAllowed'),
realityActionsAllowed: requiredBoolean(value, 'realityActionsAllowed'),
activatable: requiredBoolean(value, 'activatable'),
implementationState: requiredString(value, 'implementationState'),
}
}
function parseBinding(value: unknown, expectedPersonaId: string): PersonaRepositoryBinding {
if (!isRecord(value)) throw new Error('PERSONA_REPOSITORY_DISCOVERY_RECEIPT_INVALID')
const personaId = requiredString(value, 'personaId')
@ -81,6 +131,10 @@ function parseBinding(value: unknown, expectedPersonaId: string): PersonaReposit
}
const repositoryClean = Reflect.get(value, 'repositoryClean')
if (typeof repositoryClean !== 'boolean') throw new Error('PERSONA_REPOSITORY_DISCOVERY_RECEIPT_INVALID')
const rawOrganContracts = Reflect.get(value, 'organContracts')
if (!Array.isArray(rawOrganContracts) || rawOrganContracts.length === 0) {
throw new Error('PERSONA_REPOSITORY_DISCOVERY_RECEIPT_INVALID')
}
return {
personaId,
repositoryPath: requiredString(value, 'repositoryPath'),
@ -92,6 +146,7 @@ function parseBinding(value: unknown, expectedPersonaId: string): PersonaReposit
modelProviderId: requiredString(value, 'modelProviderId'),
modelId: requiredString(value, 'modelId'),
modelBaseUrl: requiredString(value, 'modelBaseUrl'),
organContracts: rawOrganContracts.map(parseOrganContract),
cognitiveGravity: {
schema: gravitySchema,
subjectPersonaId: expectedPersonaId,