mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-11-01 06:47:29 +00:00
## ① 全面改名 HomeAgent → HologramAgent
仓库已改名,但代码与文档里仍有大量旧名。本次按"用户能看到的优先"全量替换:
- 用户可见:登录页标题/页脚、默认人格第一句、CLI 状态输出、启动日志、
plugin_install 的工具描述、AI 图片插件的 User-Agent
- 文档与脚本:README、assets/docs、docs/zh、deploy/*.sh、.github/workflows
- 鸿蒙工程:cmd/ohos/HomeAgent → cmd/ohos/HologramAgent(git mv)
目录内的 module/app 描述同步;**证书路径原样保留**
(default_HomeAgent_xxx.cer/p7b/p12 是签名材料的实际文件名,改了会找不到证书)
- 插件元数据:plugin.json 的 author
★ 必须保持原样的两处(改了会坏):
· legacySeededPromptSignature = "你是 HomeAgent 的看板娘「小宅」…"
—— 那是识别历史播种人格卡的**原文锚点**,改了就识别不出旧数据
· 公开 SDK 的 ProxyAuthHomeAgent = "homeagent"
—— 那是 SDK 契约里的值,属独立仓库,本仓不改
## ② 修 21 处乱码(U+FFFD)
这些是历史编辑留下的编码破坏,全在注释里,例如:
「赌注重下���遍」→「赌注重下一遍」
「「不��滤」」 →「「不过滤」」
「**待��退场**」→「**待退场**」
★ 保留 providers/chineseclip/tokenizer.go 里的 2 处:那是**故意**用
U+FFFD 演示"非法 UTF-8 字节被归一成 U+FFFD",不是乱码。
## ③ 提示词技术内容下沉(用户:技术性内容应该收敛到 skill 与 -help 中)
实测系统提示词 2309 字,其中两段几乎全是**模型无法据以行动的实现细节**:
【工具执行顺序】1272 字(ParallelSafe 声明、批内降级、batchRunnable 判据…)
【三层记忆】 1069 字(L1/L2/L3 编号、消费式删除、向量空间、指纹…)
收敛后 **2309 → 1723 字(-25%)**,保留的全是"模型据此做什么不同的事":
工具顺序:默认并行 / 不要依赖先后 / 同通道保序 / 写类工具可能串行
三层记忆:时序里能看最近 / doc_query 把历史事件按原始时间戳插回时序 /
关系用 memory_recall / 成文知识用 knowledge_search
判断口径写进判据:新加一段提示词前先问"模型会据此做什么不同的事",
答不上来就该进 skill 或工具描述。
## 判据
prompt_memory_test.go 新增 2 条:
- TestSystemPromptHasNoImplementationJargon
黑名单:ParallelSafe / batchRunnable / 消费式 / DenseCosine / fingerprint /
向量空间 / 批内降级 / 自激
- TestSystemPromptStaysCompact:上限 2000 字(当前 1723)
变异:把 "ParallelSafe 声明、批内降级" 加回工具顺序段 ⇒ 第一条立刻红。
## 验证
- go build ./... / go vet ./... 干净
- go test ./... -count=1:58 包 0 失败
- make check-client-versions:客户端与内核版本一致
333 lines
12 KiB
Plaintext
333 lines
12 KiB
Plaintext
/**
|
||
* Static Markdown → ArkUI renderer for COMPLETE (non-streaming) chat messages.
|
||
*
|
||
* Parses once in aboutToAppear, builds a component tree with no timers — instant rendering.
|
||
* Uses Span children inside Text for inline bold/italic/code/link formatting.
|
||
*
|
||
* 解析规则在 common/MarkdownParser.ets(已抽出,见那里);
|
||
* 本文件只负责把 MdBlock 渲染成 ArkUI 组件树。
|
||
*/
|
||
|
||
import { ThemePalette, DARK_PALETTE, LIGHT_PALETTE } from '../common/Constants';
|
||
import { RADIUS_SM } from '../common/Constants';
|
||
import { MdBlock, MdSpan, parseBlocks, parseInline } from '../common/MarkdownParser';
|
||
|
||
@Component
|
||
export struct StaticMarkdownView {
|
||
@Prop content: string = '';
|
||
@Prop isDark: boolean = true;
|
||
private blocks: MdBlock[] = [];
|
||
|
||
aboutToAppear(): void {
|
||
this.blocks = parseBlocks(this.content);
|
||
}
|
||
|
||
private palette(): ThemePalette {
|
||
return this.isDark ? DARK_PALETTE : LIGHT_PALETTE;
|
||
}
|
||
|
||
private headingSize(level: number): number {
|
||
if (level === 1) {
|
||
return 22;
|
||
}
|
||
if (level === 2) {
|
||
return 19;
|
||
}
|
||
if (level === 3) {
|
||
return 17;
|
||
}
|
||
if (level === 4) {
|
||
return 15.5;
|
||
}
|
||
return 14;
|
||
}
|
||
|
||
// ── Block builders ─────────────────────────────────────────────────────────
|
||
|
||
@Builder
|
||
ParaBlock(text: string) {
|
||
Column({ space: 1 }) {
|
||
ForEach(this.splitNewlines(text), (ln: string, idx: number) => {
|
||
// Render inline spans inside this line
|
||
Text() {
|
||
ForEach(parseInline(ln), (sp: MdSpan, si: number) => {
|
||
Span(sp.text)
|
||
.fontSize(15)
|
||
.fontColor(sp.link === true ? this.palette().accent : sp.code === true ? this.palette().preText : this.palette().msgBubbleText)
|
||
.fontWeight(sp.bold === true ? FontWeight.Bold : FontWeight.Normal)
|
||
.fontStyle(sp.italic === true ? FontStyle.Italic : FontStyle.Normal)
|
||
.fontFamily(sp.code === true ? 'monospace' : '-')
|
||
.backgroundColor(sp.code === true ? this.palette().preBg : Color.Transparent)
|
||
.borderRadius(3)
|
||
.padding(sp.code === true ? { left: 3, right: 3, top: 1, bottom: 1 } : {})
|
||
.decoration(sp.link === true ? { type: TextDecorationType.Underline } : undefined)
|
||
}, (sp: MdSpan, si: number) => idx.toString() + '_' + si.toString())
|
||
}
|
||
.fontSize(15)
|
||
.lineHeight(24)
|
||
.fontColor(this.palette().msgBubbleText)
|
||
.width('100%')
|
||
.wordBreak(WordBreak.BREAK_ALL)
|
||
.textAlign(TextAlign.Start)
|
||
}, (ln: string, idx: number) => 'p' + idx.toString())
|
||
}
|
||
.width('100%')
|
||
.margin({ top: 2, bottom: 4 })
|
||
}
|
||
|
||
@Builder
|
||
HeadingBlock(block: MdBlock) {
|
||
Text(block.text ?? '')
|
||
.fontSize(this.headingSize(block.level ?? 1))
|
||
.fontWeight(FontWeight.Bold)
|
||
.fontColor(this.palette().textPrimary)
|
||
.lineHeight(this.headingSize(block.level ?? 1) + 8)
|
||
.width('100%')
|
||
.margin({ top: 6, bottom: 4 })
|
||
}
|
||
|
||
@Builder
|
||
CodeBlock(block: MdBlock) {
|
||
Column() {
|
||
Row() {
|
||
Text(block.lang !== undefined && block.lang.length > 0 ? block.lang : 'code')
|
||
.fontSize(10)
|
||
.fontColor(this.palette().textMuted)
|
||
.fontFamily('monospace')
|
||
Blank()
|
||
}
|
||
.width('100%')
|
||
.padding({ left: 10, right: 10, top: 5, bottom: 5 })
|
||
.backgroundColor(this.palette().bgHover)
|
||
|
||
// Code body
|
||
Column() {
|
||
ForEach(block.codeLines ?? [], (ln: string, idx: number) => {
|
||
Text(ln.length > 0 ? ln : ' ')
|
||
.fontSize(12.5)
|
||
.lineHeight(19)
|
||
.fontFamily('monospace')
|
||
.fontColor(this.palette().preText)
|
||
.width('100%')
|
||
.textAlign(TextAlign.Start)
|
||
.wordBreak(WordBreak.BREAK_ALL)
|
||
}, (ln: string, idx: number) => 'c' + idx.toString())
|
||
}
|
||
.width('100%')
|
||
.padding({ left: 10, right: 10, top: 8, bottom: 8 })
|
||
}
|
||
.width('100%')
|
||
.borderRadius(RADIUS_SM)
|
||
.backgroundColor(this.palette().preBg)
|
||
.border({ width: 1, color: this.palette().kvBorder })
|
||
.clip(true)
|
||
.margin({ top: 4, bottom: 6 })
|
||
}
|
||
|
||
@Builder
|
||
ListBlock(block: MdBlock) {
|
||
Column({ space: 2 }) {
|
||
ForEach(block.items ?? [], (item: string, idx: number) => {
|
||
Row({ space: 6 }) {
|
||
Text('•')
|
||
.fontSize(15)
|
||
.fontColor(this.palette().accent)
|
||
.fontWeight(FontWeight.Bold)
|
||
.margin({ top: 1 })
|
||
Text() {
|
||
ForEach(parseInline(item), (sp: MdSpan, si: number) => {
|
||
Span(sp.text)
|
||
.fontSize(15)
|
||
.fontColor(sp.code === true ? this.palette().preText : this.palette().msgBubbleText)
|
||
.fontWeight(sp.bold === true ? FontWeight.Bold : FontWeight.Normal)
|
||
.fontStyle(sp.italic === true ? FontStyle.Italic : FontStyle.Normal)
|
||
.fontFamily(sp.code === true ? 'monospace' : '-')
|
||
.backgroundColor(sp.code === true ? this.palette().preBg : Color.Transparent)
|
||
.borderRadius(3)
|
||
.padding(sp.code === true ? { left: 3, right: 3, top: 1, bottom: 1 } : {})
|
||
}, (sp: MdSpan, si: number) => 'li' + idx.toString() + '_' + si.toString())
|
||
}
|
||
.fontSize(15)
|
||
.lineHeight(23)
|
||
.fontColor(this.palette().msgBubbleText)
|
||
.layoutWeight(1)
|
||
.wordBreak(WordBreak.BREAK_ALL)
|
||
.width('100%')
|
||
}
|
||
.width('100%')
|
||
.alignItems(VerticalAlign.Top)
|
||
}, (item: string, idx: number) => idx.toString())
|
||
}
|
||
.width('100%')
|
||
.margin({ top: 2, bottom: 4 })
|
||
}
|
||
|
||
@Builder
|
||
OlBlock(block: MdBlock) {
|
||
Column({ space: 2 }) {
|
||
ForEach(block.items ?? [], (item: string, idx: number) => {
|
||
Row({ space: 6 }) {
|
||
Text((idx + 1).toString() + '.')
|
||
.fontSize(15)
|
||
.fontColor(this.palette().accent)
|
||
.fontWeight(FontWeight.Medium)
|
||
.margin({ top: 1 })
|
||
Text() {
|
||
ForEach(parseInline(item), (sp: MdSpan, si: number) => {
|
||
Span(sp.text)
|
||
.fontSize(15)
|
||
.fontColor(sp.code === true ? this.palette().preText : this.palette().msgBubbleText)
|
||
.fontWeight(sp.bold === true ? FontWeight.Bold : FontWeight.Normal)
|
||
.fontStyle(sp.italic === true ? FontStyle.Italic : FontStyle.Normal)
|
||
.fontFamily(sp.code === true ? 'monospace' : '-')
|
||
.backgroundColor(sp.code === true ? this.palette().preBg : Color.Transparent)
|
||
.borderRadius(3)
|
||
.padding(sp.code === true ? { left: 3, right: 3, top: 1, bottom: 1 } : {})
|
||
}, (sp: MdSpan, si: number) => 'oli' + idx.toString() + '_' + si.toString())
|
||
}
|
||
.fontSize(15)
|
||
.lineHeight(23)
|
||
.fontColor(this.palette().msgBubbleText)
|
||
.layoutWeight(1)
|
||
.wordBreak(WordBreak.BREAK_ALL)
|
||
.width('100%')
|
||
}
|
||
.width('100%')
|
||
.alignItems(VerticalAlign.Top)
|
||
}, (item: string, idx: number) => idx.toString())
|
||
}
|
||
.width('100%')
|
||
.margin({ top: 2, bottom: 4 })
|
||
}
|
||
|
||
@Builder
|
||
BlockquoteBlock(text: string) {
|
||
Column() {
|
||
ForEach(this.splitNewlines(text), (ln: string, idx: number) => {
|
||
Text() {
|
||
ForEach(parseInline(ln), (sp: MdSpan, si: number) => {
|
||
Span(sp.text)
|
||
.fontSize(14)
|
||
.fontColor(this.palette().textTertiary)
|
||
.fontStyle(sp.italic === true ? FontStyle.Italic : FontStyle.Normal)
|
||
.fontWeight(sp.bold === true ? FontWeight.Bold : FontWeight.Normal)
|
||
}, (sp: MdSpan, si: number) => 'bq' + idx.toString() + '_' + si.toString())
|
||
}
|
||
.fontSize(14)
|
||
.lineHeight(22)
|
||
.width('100%')
|
||
.wordBreak(WordBreak.BREAK_ALL)
|
||
}, (ln: string, idx: number) => 'bq' + idx.toString())
|
||
}
|
||
.width('100%')
|
||
.padding({ left: 10, right: 10, top: 6, bottom: 6 })
|
||
.margin({ top: 3, bottom: 5 })
|
||
.borderRadius({ topLeft: 0, topRight: 6, bottomRight: 6, bottomLeft: 0 })
|
||
.backgroundColor(this.palette().bgHover)
|
||
.border({
|
||
width: { left: 3, top: 0, right: 0, bottom: 0 },
|
||
color: { left: this.palette().accent, top: Color.Transparent, right: Color.Transparent, bottom: Color.Transparent },
|
||
})
|
||
}
|
||
|
||
@Builder
|
||
HrBlock() {
|
||
Row()
|
||
.width('100%')
|
||
.height(1)
|
||
.backgroundColor(this.palette().kvBorder)
|
||
.margin({ top: 6, bottom: 6 })
|
||
}
|
||
|
||
@Builder
|
||
TableBlock(block: MdBlock) {
|
||
Column() {
|
||
// Header
|
||
Row() {
|
||
ForEach(block.headers ?? [], (h: string, hi: number) => {
|
||
Text() {
|
||
ForEach(parseInline(h), (sp: MdSpan, si: number) => {
|
||
Span(sp.text)
|
||
.fontSize(12.5)
|
||
.fontWeight(FontWeight.Medium)
|
||
.fontColor(this.palette().textPrimary)
|
||
}, (sp: MdSpan, si: number) => 'th' + hi.toString() + '_' + si.toString())
|
||
}
|
||
.fontSize(12.5)
|
||
.fontColor(this.palette().textPrimary)
|
||
.layoutWeight(1)
|
||
.padding({ left: 6, right: 6, top: 5, bottom: 5 })
|
||
}, (h: string, hi: number) => 'th' + hi.toString())
|
||
}
|
||
.width('100%')
|
||
.backgroundColor(this.palette().bgHover)
|
||
|
||
// Body
|
||
ForEach(block.rows ?? [], (row: string[], ri: number) => {
|
||
Row() {
|
||
ForEach(row, (cell: string, ci: number) => {
|
||
Text() {
|
||
ForEach(parseInline(cell), (sp: MdSpan, si: number) => {
|
||
Span(sp.text)
|
||
.fontSize(12.5)
|
||
.fontColor(this.palette().msgBubbleText)
|
||
.fontFamily(sp.code === true ? 'monospace' : '-')
|
||
.backgroundColor(sp.code === true ? this.palette().preBg : Color.Transparent)
|
||
}, (sp: MdSpan, si: number) => 'td' + ri.toString() + '_' + ci.toString() + '_' + si.toString())
|
||
}
|
||
.fontSize(12.5)
|
||
.fontColor(this.palette().msgBubbleText)
|
||
.layoutWeight(1)
|
||
.padding({ left: 6, right: 6, top: 4, bottom: 4 })
|
||
.wordBreak(WordBreak.BREAK_ALL)
|
||
.width('100%')
|
||
}, (cell: string, ci: number) => 'td' + ri.toString() + '_' + ci.toString())
|
||
}
|
||
.width('100%')
|
||
}, (row: string[], ri: number) => 'tr' + ri.toString())
|
||
}
|
||
.width('100%')
|
||
.borderRadius(RADIUS_SM)
|
||
.border({ width: 1, color: this.palette().kvBorder })
|
||
.clip(true)
|
||
.margin({ top: 4, bottom: 6 })
|
||
}
|
||
|
||
// ── Helpers ────────────────────────────────────────────────────────────────
|
||
|
||
private splitNewlines(text: string): string[] {
|
||
if (text.length === 0) {
|
||
return [];
|
||
}
|
||
return text.split('\n');
|
||
}
|
||
|
||
// ── Build ──────────────────────────────────────────────────────────────────
|
||
|
||
build() {
|
||
Column() {
|
||
ForEach(this.blocks, (b: MdBlock, idx: number) => {
|
||
if (b.type === 'code') {
|
||
this.CodeBlock(b)
|
||
} else if (b.type === 'heading') {
|
||
this.HeadingBlock(b)
|
||
} else if (b.type === 'list') {
|
||
this.ListBlock(b)
|
||
} else if (b.type === 'ol') {
|
||
this.OlBlock(b)
|
||
} else if (b.type === 'blockquote') {
|
||
this.BlockquoteBlock(b.text ?? '')
|
||
} else if (b.type === 'hr') {
|
||
this.HrBlock()
|
||
} else if (b.type === 'table') {
|
||
this.TableBlock(b)
|
||
} else {
|
||
this.ParaBlock(b.text ?? '')
|
||
}
|
||
}, (b: MdBlock, idx: number) => idx.toString() + b.type + ((b.text ?? '').substring(0, 12)))
|
||
}
|
||
.width('100%')
|
||
.alignItems(HorizontalAlign.Start)
|
||
}
|
||
}
|