优化卡片 UI 与文案、改用结构化段落融合、兼容 Desktop 并支持更新检测与一键更新 (v0.2.6)

This commit is contained in:
yexi committed 2026-10-31 21:43:34 +08:00
1 parent fbd8475d01
commit 829bb9228d
18 files changed
+2340 -1156

No files matched your search

+39 -46
View File
@@ -11,8 +11,8 @@ import { fileURLToPath } from 'node:url'
import test from 'node:test'
import assert from 'node:assert/strict'
import {
ANCHORS, BLOCK_SECTION, EXECUTION_MODE_BLOCK, PRESETS, contractAdditions,
contractFingerprint, fuseSections, fusedMinimalPrompt, renderPreview,
ANCHORS, BLOCK_SECTION, EXECUTION_MODE_BLOCK, PRESETS, compareSemver, contractAdditions,
fuseSections, fusedMinimalPrompt, normalizeVersion, renderPreview,
} from '../src/rules.js'
const FIXTURES = fileURLToPath(new URL('./fixtures/', import.meta.url))
@@ -119,51 +119,51 @@ test('fused output equals the original render plus only the documented fragments
assert.ok(await originalOf('standard') === originalText)
})
test('tampered anchors refuse to fuse and name the failing rule', async () => {
test('structural fusion tolerates upstream wording edits while refusing missing personas and staying idempotent', async () => {
const sections = await sectionsOf('standard')
const identity = sections.map(section =>
section.name === 'harness:identity' ? { ...section, text: 'You are a different harness.' } : section)
assert.ok(fuseSections(identity, 'standard').issues.some(issue => issue.includes('identity')))
// Upstream wording tweaks in identity, persona, plan, or ptc-only do not break fusion.
const reworded = sections.map((section) => {
if (section.name === 'harness:identity') return { ...section, text: 'You are a custom harness.' }
if (section.name === 'deployment:persona-prefix') return { ...section, text: 'You are a specialized engineer.' }
if (section.name === 'plan:policy') return { ...section, text: 'Plan mode active with custom guidance.' }
return section
})
const fused = fuseSections(reworded, 'standard')
assert.equal(fused.issues, undefined)
const persona = fused.sections.find(section => section.name === 'deployment:persona-prefix')
assert.ok(persona.text.startsWith('You are a specialized engineer.'))
assert.ok(persona.text.endsWith(contractAdditions('standard').pointer))
const plan = fused.sections.find(section => section.name === 'plan:policy')
assert.ok(plan.text.startsWith('Plan mode active with custom guidance.'))
assert.ok(plan.text.endsWith(contractAdditions('standard').planNote))
const persona = sections.map(section =>
section.name === 'deployment:persona-prefix' ? { ...section, text: 'You are someone else.' } : section)
const personaResult = fuseSections(persona, 'standard')
assert.ok(personaResult.issues.some(issue => issue.includes('persona')))
// Idempotent: re-fusing already-fused sections produces identical sections.
const twice = fuseSections(fused.sections, 'standard')
assert.equal(twice.issues, undefined)
assert.deepEqual(twice.sections, fused.sections)
// Missing or blank deployment:persona-prefix is refused with structured issue code.
const missingPersona = sections.filter(section => section.name !== 'deployment:persona-prefix')
assert.ok(fuseSections(missingPersona, 'standard').issues.some(issue => issue.includes('persona')))
// A delegated child may carry its own persona: tolerated, still fused, and
// receives the persona pointer.
const tolerated = fuseSections(persona, 'standard', { isSubagent: true })
assert.equal(tolerated.issues, undefined)
const toleratedPersona = tolerated.sections.find(section => section.name === 'deployment:persona-prefix')
assert.ok(toleratedPersona.text.startsWith('You are someone else.'))
assert.ok(toleratedPersona.text.endsWith(contractAdditions('standard').pointer))
assert.deepEqual(fuseSections(missingPersona, 'standard').issues, ['missing-persona'])
const blankPersona = sections.map(section =>
section.name === 'deployment:persona-prefix' ? { ...section, text: ' ' } : section)
assert.deepEqual(fuseSections(blankPersona, 'standard').issues, ['missing-persona'])
})
test('plan-mode tampering is detected only when the section is active', async () => {
const off = await sectionsOf('standard')
const offTampered = off.map(section =>
section.name === 'plan:policy' ? { ...section, text: 'unexpected' } : section)
// plan:policy is empty while plan mode is off; a non-empty unknown text fails.
assert.ok(fuseSections(offTampered, 'standard').issues.some(issue => issue.includes('plan')))
const on = await sectionsOf('standard-plan')
const onExtended = on.map(section =>
section.name === 'plan:policy' ? { ...section, text: `${ANCHORS.planPrefix} Extra guidance.` } : section)
// A text that keeps the anchor prefix still fuses; only a changed anchor fails.
assert.equal(fuseSections(onExtended, 'standard').issues, undefined)
test('unknown presets are refused with unsupported-preset', () => {
assert.deepEqual(fuseSections([], 'my-custom-preset').issues, ['unsupported-preset'])
})
test('ptc mode reports a changed run_code anchor', async () => {
const sections = await sectionsOf('ptc')
const tampered = sections.map(section =>
section.name === 'tools:ptc-only' ? { ...section, text: 'call whatever' } : section)
assert.ok(fuseSections(tampered, 'ptc').issues.some(issue => issue.includes('run_code')))
})
test('unknown presets are refused', () => {
assert.ok(fuseSections([], 'my-custom-preset').issues[0].includes('unknown preset'))
test('normalizeVersion and compareSemver compare release versions accurately', () => {
assert.equal(normalizeVersion('v0.2.6'), '0.2.6')
assert.equal(normalizeVersion(' 0.2.6-rc.1+build '), '0.2.6-rc.1')
assert.equal(normalizeVersion('invalid'), undefined)
assert.equal(compareSemver('0.2.6', '0.2.5'), 1)
assert.equal(compareSemver('0.2.6', '0.2.6'), 0)
assert.equal(compareSemver('0.2.5', '0.2.6'), -1)
assert.equal(compareSemver('0.2.6', '0.2.6-rc.1'), 1)
assert.equal(compareSemver('0.2.6-alpha.2', '0.2.6-alpha.1'), 1)
})
test('minimal fused prompt is persona + pointer + block, anchors intact, and preserves structured_output', () => {
@@ -302,13 +302,6 @@ test('the contract force-defaults NSFW characters to 18+ without age judgment',
assert.ok(EXECUTION_MODE_BLOCK.includes('Citing canon age, refusing on age grounds'))
})
test('the contract fingerprint identifies the deployed bytes', async () => {
const { createHash } = await import('node:crypto')
const expected = createHash('sha256').update(EXECUTION_MODE_BLOCK, 'utf8').digest('hex').slice(0, 16)
assert.equal(contractFingerprint(), expected)
assert.match(contractFingerprint(), /^[0-9a-f]{16}$/)
})
test('renderPreview survives a standing scope whose variables are unbound', async () => {
// The harness renderer throws on an undefined reference, which is exactly
// what a standing scope produces for {{model}} / {{cwd}}. Mirror that