mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-11-06 17:27:31 +00:00
refactor: 全面改名为 HologramAgent + 提示词技术内容下沉到 skill/工具描述 + 修 21 处乱码
## ① 全面改名 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:客户端与内核版本一致
This commit is contained in:
421
cmd/ohos/HologramAgent/entry/src/main/ets/pages/Index.ets
Normal file
421
cmd/ohos/HologramAgent/entry/src/main/ets/pages/Index.ets
Normal file
@ -0,0 +1,421 @@
|
||||
import { ChatPage } from './ChatPage';
|
||||
import { PluginsPage } from './PluginsPage';
|
||||
import { DevicePage } from './DevicePage';
|
||||
import { SettingsPage } from './SettingsPage';
|
||||
import { connStore } from '../common/ConnStore';
|
||||
import { apiClient } from '../common/ApiClient';
|
||||
import { navBar } from '../common/NavBarController';
|
||||
import { handleBackPress } from '../common/NavStackRegistry';
|
||||
import { ConnectionConfig } from '../model/Model';
|
||||
import { ThemePalette, DARK_PALETTE, LIGHT_PALETTE, WIDE_MIN_WIDTH, WIDE_NAV_BAR_WIDTH, K_HAS_CONN, K_REQUESTED_TAB, K_SETTINGS_SUB } from '../common/Constants';
|
||||
import { ANIM_NORMAL, ANIM_SLOW } from '../common/Constants';
|
||||
import { MotionBase } from '../components/MotionBase';
|
||||
import { GradientBackground } from '../components/GradientBackground';
|
||||
import { ScreensuePage } from '../components/ScreensuePage';
|
||||
import { registerScreensueHandler } from '../common/BridgeRouter';
|
||||
import { markForegroundBridgeUIReady } from '../common/DeviceBridgeSession';
|
||||
import { snapshotComponentId } from '../common/BridgeCaps';
|
||||
import { ScreensuePayload } from '../common/ScreensueHtml';
|
||||
import { window, display } from '@kit.ArkUI';
|
||||
import { common } from '@kit.AbilityKit';
|
||||
|
||||
interface TabItem {
|
||||
icon: Resource;
|
||||
label: string;
|
||||
pageId: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 底部导航单项:矢量图标 + 文字。
|
||||
* active 必须 @Prop 才能在父组件 currentTab 变化时刷新高亮。
|
||||
*/
|
||||
@Component
|
||||
export struct RailTab {
|
||||
icon: Resource = $r('app.media.ic_tab_chat');
|
||||
@Prop label: string = '';
|
||||
@Prop active: boolean = false;
|
||||
@Prop accent: string = '';
|
||||
@Prop muted: string = '';
|
||||
|
||||
build() {
|
||||
// 底部导航按压反馈:交给 MotionBase 统一(flexWeight 由外层调用点的
|
||||
// .layoutWeight(1) 负责,这里内部只需撑满自己那一格)。
|
||||
MotionBase({ pressEnabled: true }) {
|
||||
Column({ space: 3 }) {
|
||||
Image(this.icon)
|
||||
.width(22)
|
||||
.height(22)
|
||||
.fillColor(this.active ? this.accent : this.muted)
|
||||
// 选中态的颜色迁移必须写在子节点上:父容器的 .animation()
|
||||
// 只驱动它自己的属性,不会下传给 Image / Text。
|
||||
.animation({ duration: ANIM_NORMAL, curve: Curve.EaseOut })
|
||||
.draggable(false)
|
||||
|
||||
Text(this.label)
|
||||
.fontSize(10)
|
||||
// fontWeight 不可插值,切换时仍是跳变,只对颜色做过渡
|
||||
.fontWeight(this.active ? FontWeight.Medium : FontWeight.Normal)
|
||||
.fontColor(this.active ? this.accent : this.muted)
|
||||
.animation({ duration: ANIM_NORMAL, curve: Curve.EaseOut })
|
||||
.maxLines(1)
|
||||
}
|
||||
.justifyContent(FlexAlign.Center)
|
||||
.alignItems(HorizontalAlign.Center)
|
||||
.width('100%')
|
||||
.height(48)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct Index {
|
||||
@Watch('onTabChanged') @State currentTab: number = 0;
|
||||
@StorageProp('navVisible') private navVisible: boolean = true;
|
||||
/** 二级页面打开时锁住 Swiper 横滑,避免误切换主 Tab */
|
||||
@StorageProp('subPageOpen') private subPageOpen: boolean = false;
|
||||
/** 宽屏(>=600vp):一级界面在左、二级界面在右,导航栏跟随左侧一级界面 */
|
||||
@StorageProp('isWideScreen') private isWide: boolean = false;
|
||||
@State screensueVisible: boolean = false;
|
||||
@State screensueText: string = '';
|
||||
@State screensueCountdown: number = 0;
|
||||
/** 状态栏避让高度(vp),从窗口 avoid area 动态获取;默认 44 兜底 */
|
||||
@State topInset: number = 44;
|
||||
/** 底部手势条高度(vp) */
|
||||
@State bottomGesture: number = 16;
|
||||
@StorageProp('themeIsDark') @Watch('onThemeChanged') private isDark: boolean = true;
|
||||
/** 外部请求切换主 Tab(未连接时聊天空态的“去设置连接”用) */
|
||||
@StorageProp(K_REQUESTED_TAB) @Watch('onRequestedTab') private requestedTab: number = -1;
|
||||
private swiper: SwiperController = new SwiperController();
|
||||
private screensueTimer: number = -1;
|
||||
private snapshotBuilder: CustomBuilder = (): void => { }; // 由 @Builder 传入的实际锚点
|
||||
|
||||
// 「状态」Tab 已删除:运行状态并入设置页(顶部摘要卡 + 二级明细页),
|
||||
// 底部导航只保留四项,胶囊内每项更宽、点按更好命中。
|
||||
private tabs: TabItem[] = [
|
||||
{ icon: $r('app.media.ic_tab_chat'), label: '聊天', pageId: 'chat' },
|
||||
{ icon: $r('app.media.ic_tab_plugins'), label: '插件', pageId: 'plugins' },
|
||||
{ icon: $r('app.media.ic_tab_devices'), label: '设备', pageId: 'devices' },
|
||||
{ icon: $r('app.media.ic_tab_settings'), label: '设置', pageId: 'settings' },
|
||||
];
|
||||
|
||||
aboutToAppear(): void {
|
||||
const cur: ConnectionConfig | null = connStore.getCurrentConnection();
|
||||
if (cur !== null) {
|
||||
apiClient.setConnection(cur);
|
||||
}
|
||||
// 后端连接状态广播:聊天空态根据它决定是否显示“去设置连接”。
|
||||
// Index.aboutToAppear 在 EntryAbility 等 connStore.init 之后才跑,
|
||||
// 所以此处读到的连接状态就是真实的启动态。
|
||||
AppStorage.setOrCreate<boolean>(K_HAS_CONN, apiClient.hasConnection());
|
||||
AppStorage.setOrCreate<number>(K_REQUESTED_TAB, -1);
|
||||
AppStorage.setOrCreate<string>(K_SETTINGS_SUB, '');
|
||||
// 种子化自定义背景图状态到 AppStorage,GradientBackground 响应读取
|
||||
const st = connStore.getSettings();
|
||||
AppStorage.setOrCreate<string>('bgImage', st.bgImage ?? '');
|
||||
AppStorage.setOrCreate<number>('bgOpacity', st.bgOpacity ?? 0.25);
|
||||
AppStorage.setOrCreate<boolean>('navVisible', true);
|
||||
AppStorage.setOrCreate<boolean>('subPageOpen', false);
|
||||
AppStorage.setOrCreate<boolean>('isWideScreen', false);
|
||||
// 启动时按当前主题刷新一次系统栏(EntryAbility 已设过,这里兜底对齐)
|
||||
this.syncSystemBar();
|
||||
// 动态读取状态栏/导航栏避让区,实现真正的沉浸式布局(替换硬编码 top:44)
|
||||
this.resolveSafeArea();
|
||||
// 根 UI 只负责 screensue 呈现;命令路由由前台全局设备桥安装。
|
||||
registerScreensueHandler((payload: ScreensuePayload) => {
|
||||
this.showScreensue(payload);
|
||||
});
|
||||
markForegroundBridgeUIReady(getContext(this) as common.UIAbilityContext);
|
||||
}
|
||||
|
||||
/** agent 下发的 screensue 内容展示(窄屏整页、宽屏右栏;0=常驻)。 */
|
||||
private showScreensue(payload: ScreensuePayload): void {
|
||||
this.screensueText = payload.content;
|
||||
this.screensueCountdown = payload.duration;
|
||||
this.screensueVisible = true;
|
||||
if (this.screensueTimer >= 0) {
|
||||
clearInterval(this.screensueTimer);
|
||||
this.screensueTimer = -1;
|
||||
}
|
||||
if (payload.duration > 0) {
|
||||
this.screensueTimer = setInterval(() => {
|
||||
if (this.screensueCountdown <= 1) {
|
||||
clearInterval(this.screensueTimer);
|
||||
this.screensueTimer = -1;
|
||||
this.screensueVisible = false;
|
||||
} else {
|
||||
this.screensueCountdown = this.screensueCountdown - 1;
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
private closeScreensue(): void {
|
||||
if (this.screensueTimer >= 0) {
|
||||
clearInterval(this.screensueTimer);
|
||||
this.screensueTimer = -1;
|
||||
}
|
||||
this.screensueVisible = false;
|
||||
}
|
||||
|
||||
/** 主题翻转时同步系统栏前景/背景色,避免浅色页面配黑状态栏。 */
|
||||
private onThemeChanged(): void {
|
||||
this.syncSystemBar();
|
||||
}
|
||||
|
||||
/** 通过窗口 avoid area 计算状态栏与底部手势区高度(vp),失败时保留默认值。 */
|
||||
private resolveSafeArea(): void {
|
||||
try {
|
||||
const ctx = getContext(this) as common.UIAbilityContext;
|
||||
window.getLastWindow(ctx).then((win: window.Window) => {
|
||||
const prop = win.getWindowProperties();
|
||||
const isLayoutFull = prop.isLayoutFullScreen === true;
|
||||
if (!isLayoutFull) {
|
||||
return; // 非全屏模式下系统自动避让
|
||||
}
|
||||
const density = display.getDefaultDisplaySync().densityPixels > 0
|
||||
? display.getDefaultDisplaySync().densityPixels : 3;
|
||||
const topArea = win.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM);
|
||||
const bottomArea = win.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR);
|
||||
if (topArea.topRect.height > 0) {
|
||||
this.topInset = Math.ceil(topArea.topRect.height / density);
|
||||
}
|
||||
// 底部手势条:有值时取其高度的一半作为悬浮导航的下边距基准,最小 8 最大 24
|
||||
if (bottomArea.bottomRect.height > 0) {
|
||||
const h: number = Math.ceil(bottomArea.bottomRect.height / density);
|
||||
this.bottomGesture = Math.min(24, Math.max(8, h));
|
||||
} else {
|
||||
this.bottomGesture = 16;
|
||||
}
|
||||
}).catch(() => {
|
||||
// ignore, keep defaults
|
||||
});
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
AppStorage.set<number>('currentTab', 0);
|
||||
}
|
||||
|
||||
private onTabChanged(): void {
|
||||
AppStorage.set<number>('currentTab', this.currentTab);
|
||||
}
|
||||
|
||||
/**
|
||||
* 响应外部切 Tab 请求(聊天空态的“去设置连接”)。
|
||||
*
|
||||
* 为什么不能直接改 AppStorage 的 currentTab:Index 的 currentTab 是
|
||||
* @State,Swiper.index() 只认它;外部写 AppStorage 不会驱动 Swiper。
|
||||
* 所以用独立请求键 + @Watch 把请求转成自己的状态变更。
|
||||
*/
|
||||
private onRequestedTab(): void {
|
||||
const t: number = this.requestedTab;
|
||||
AppStorage.set<number>(K_REQUESTED_TAB, -1);
|
||||
if (t < 0 || t >= this.tabs.length) {
|
||||
return;
|
||||
}
|
||||
this.currentTab = t;
|
||||
navBar.setVisible(true);
|
||||
}
|
||||
|
||||
private syncSystemBar(): void {
|
||||
const dark: boolean = this.isDark;
|
||||
const bg: string = dark ? '#000000' : '#F1F3F5';
|
||||
const fg: string = dark ? '#FFFFFF' : '#191919';
|
||||
try {
|
||||
window.getLastWindow(getContext(this) as common.UIAbilityContext).then((win: window.Window) => {
|
||||
win.setWindowSystemBarProperties({
|
||||
statusBarColor: bg,
|
||||
statusBarContentColor: fg,
|
||||
navigationBarColor: bg,
|
||||
});
|
||||
win.setWindowBackgroundColor(bg);
|
||||
}).catch(() => {
|
||||
// ignore
|
||||
});
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
private palette(): ThemePalette {
|
||||
// 引用 this.isDark 建立响应式依赖:主题切换时整个组件树重渲染
|
||||
return this.isDark ? DARK_PALETTE : LIGHT_PALETTE;
|
||||
}
|
||||
|
||||
/** 宽屏判定:窗口宽度 >= 600vp(与 Navigation Auto 模式的分栏阈值一致) */
|
||||
private updateWideScreen(w: number): void {
|
||||
const wide: boolean = w >= WIDE_MIN_WIDTH;
|
||||
if (wide !== this.isWide) {
|
||||
AppStorage.set<boolean>('isWideScreen', wide);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一的返回处理:把返回事件精确派发给【当前 Tab】的那个 Navigation 栈。
|
||||
*
|
||||
* 四个页面各自持有 Navigation(宽屏需要"左一级右二级"),它们在 Swiper 里
|
||||
* 同时存活,系统返回落到哪个栈并不确定 —— 这就是"有的页面无法使用返回手势"
|
||||
* 的根因。这里按 currentTab 显式选栈,行为对所有页面一致。
|
||||
*/
|
||||
onBackPress(): boolean {
|
||||
if (this.screensueVisible) {
|
||||
this.closeScreensue();
|
||||
return true;
|
||||
}
|
||||
return handleBackPress(this.currentTab, this.isWide);
|
||||
}
|
||||
|
||||
build() {
|
||||
// alignContent Bottom:悬浮导航停靠底部,而不是被 Stack 居中。
|
||||
// 导航胶囊用左右 6% padding 保持"宽度占 88% 居中"的原样视觉;
|
||||
// 宽屏下胶囊自然被限制在左侧一级界面栏内,不会横跨二级界面。
|
||||
Stack({ alignContent: Alignment.Bottom }) {
|
||||
// 渐变氛围背景
|
||||
GradientBackground()
|
||||
|
||||
// 页面内容:Swiper 支持左右滑动切换;$$ 双向同步索引
|
||||
Swiper(this.swiper) {
|
||||
ChatPage()
|
||||
PluginsPage()
|
||||
DevicePage()
|
||||
SettingsPage()
|
||||
}
|
||||
.index(this.currentTab)
|
||||
.indicator(false)
|
||||
.loop(false)
|
||||
.duration(300)
|
||||
.curve(Curve.FastOutSlowIn)
|
||||
.vertical(false)
|
||||
.cachedCount(2)
|
||||
.disableSwipe(this.subPageOpen)
|
||||
.onChange((idx: number) => {
|
||||
this.currentTab = idx;
|
||||
navBar.setVisible(true);
|
||||
})
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
// top 让出状态栏;bottom:所有页面统一为0,导航栏浮在内容之上
|
||||
.padding({
|
||||
top: this.topInset,
|
||||
bottom: 0
|
||||
})
|
||||
|
||||
// 悬浮气态玻璃底部导航(三层:半透明底 -> 高光渐变 -> 内容)
|
||||
// 外层 Row 负责水平定位:窄屏居中;宽屏靠左,只落在一级界面栏范围内。
|
||||
Row() {
|
||||
Stack() {
|
||||
// 层1:玻璃底 —— 半透明背景(无 backdropBlur 以避免矩形模糊伪影)
|
||||
Column()
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
.backgroundColor(this.palette().navBarBg)
|
||||
|
||||
// 层2:玻璃高光渐变,模拟光从上方照射的质感
|
||||
Row()
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
.linearGradient({
|
||||
direction: GradientDirection.Top,
|
||||
colors: [
|
||||
[this.palette().navBarGradientStart, 0.0],
|
||||
[this.palette().navBarGradientEnd, 1.0],
|
||||
],
|
||||
})
|
||||
|
||||
// 层3:导航项
|
||||
Row({ space: 2 }) {
|
||||
ForEach(this.tabs, (tab: TabItem, index: number) => {
|
||||
RailTab({
|
||||
icon: tab.icon,
|
||||
label: tab.label,
|
||||
active: this.currentTab === index,
|
||||
accent: this.palette().accent,
|
||||
muted: this.palette().textMuted,
|
||||
})
|
||||
.layoutWeight(1)
|
||||
.onClick(() => {
|
||||
this.currentTab = index;
|
||||
navBar.setVisible(true);
|
||||
})
|
||||
}, (item: TabItem, index: number) => item.pageId + index.toString())
|
||||
}
|
||||
.width('100%')
|
||||
.height(62)
|
||||
.padding({ left: 14, right: 14 })
|
||||
.alignItems(VerticalAlign.Center)
|
||||
}
|
||||
// 宽屏:胶囊宽度锁在左侧一级界面栏内(左右各留 24vp 余量)
|
||||
.width(this.isWide ? WIDE_NAV_BAR_WIDTH - 48 : '88%')
|
||||
.height(62)
|
||||
.borderRadius(28)
|
||||
.clip(true)
|
||||
.border({
|
||||
width: { left: 1, top: 1, right: 1, bottom: 1 },
|
||||
color: this.palette().navBarBorder,
|
||||
})
|
||||
.shadow({
|
||||
radius: 24,
|
||||
color: this.palette().shadow,
|
||||
offsetY: 8,
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
.height(62)
|
||||
.padding({ left: this.isWide ? 24 : 0 })
|
||||
.justifyContent(this.isWide ? FlexAlign.Start : FlexAlign.Center)
|
||||
.margin({ bottom: this.bottomGesture + 6 })
|
||||
// 所有页面滑动时隐藏导航栏
|
||||
.translate({ y: !this.navVisible ? 130 : 0 })
|
||||
.opacity(!this.navVisible ? 0 : 1)
|
||||
.animation({ duration: ANIM_SLOW, curve: Curve.EaseOut })
|
||||
// 导航栏本身不吃触摸空白区,避免遮住下层内容点击
|
||||
.hitTestBehavior(HitTestMode.Transparent)
|
||||
|
||||
// screensue 是前台内容页:窄屏覆盖整页;宽屏仅覆盖右侧内容栏,
|
||||
// 左侧一级页面与主导航保持可见、可操作。
|
||||
if (this.screensueVisible) {
|
||||
if (this.isWide) {
|
||||
Row() {
|
||||
Column()
|
||||
.width(WIDE_NAV_BAR_WIDTH)
|
||||
.height('100%')
|
||||
.hitTestBehavior(HitTestMode.None)
|
||||
|
||||
ScreensuePage({
|
||||
pushedText: this.screensueText,
|
||||
countdown: this.screensueCountdown,
|
||||
onClose: () => {
|
||||
this.closeScreensue();
|
||||
},
|
||||
})
|
||||
.layoutWeight(1)
|
||||
.height('100%')
|
||||
.padding({ top: this.topInset })
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
.hitTestBehavior(HitTestMode.Transparent)
|
||||
} else {
|
||||
ScreensuePage({
|
||||
pushedText: this.screensueText,
|
||||
countdown: this.screensueCountdown,
|
||||
onClose: () => {
|
||||
this.closeScreensue();
|
||||
},
|
||||
})
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
.padding({ top: this.topInset })
|
||||
}
|
||||
}
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
.id(snapshotComponentId())
|
||||
// 实时跟随窗口宽度:平板旋转、折叠展开、分屏、自由窗口拖拽都会回调,
|
||||
// 比启动时查一次 display 更可靠(不会漏掉运行中的尺寸变化)。
|
||||
.onAreaChange((oldValue: Area, newValue: Area) => {
|
||||
this.updateWideScreen(newValue.width as number);
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user