mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-11-06 09:17:31 +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:客户端与内核版本一致
308 lines
11 KiB
Plaintext
308 lines
11 KiB
Plaintext
import { deviceBridge } from '../common/DeviceBridge';
|
||
import { connStore } from '../common/ConnStore';
|
||
import { apiClient } from '../common/ApiClient';
|
||
import { handleNavOnScroll } from '../common/NavBarController';
|
||
import { registerNavStack, unregisterNavStack } from '../common/NavStackRegistry';
|
||
import { DeviceInfo } from '../model/Model';
|
||
import { ThemePalette, DARK_PALETTE, LIGHT_PALETTE, WIDE_NAV_BAR_WIDTH,
|
||
WIDE_MIN_CONTENT, ANIM_NORMAL, ANIM_ENTER } from '../common/Constants';
|
||
import { deviceGatewayUrl } from '../common/DeviceBridgeSession';
|
||
import { DeviceRootEntries } from '../components/DeviceRootEntries';
|
||
import { DeviceLocalPane, DeviceCapsPane, DeviceGatewayPane, DeviceListPane } from '../components/DevicePanes';
|
||
import { PageTopBar, NavFloatOverlay, NavFloatRow, FloatIconButton } from '../components/PageTopBar';
|
||
import { markSubPageOpen, subPageParam } from '../components/SubPage';
|
||
import { parseOnlineDevices, resolveDeviceId, SUB_CAPS, SUB_GATEWAY, SUB_LIST,
|
||
SUB_LOCAL, SUB_NONE } from '../common/DeviceModel';
|
||
|
||
/**
|
||
* 设备页:只做"页面壳"。
|
||
*
|
||
* 拆分后的分工(拆分前这里是 560 行的单文件):
|
||
* - 一级入口列表(本机/通道两组) → components/DeviceRootEntries.ets
|
||
* - 四个二级页面内容(本机/能力/通道/列表)→ components/DevicePanes.ets
|
||
* - device_id 兜底与在线设备解析 → common/DeviceModel.ets(路由 id 也在那)
|
||
* 本文件保留:导航栈与二级页分发、授权开关、toast、设备列表拉取与生命周期。
|
||
*/
|
||
@Component
|
||
export struct DevicePage {
|
||
@StorageProp('themeIsDark') private isDark: boolean = true;
|
||
@StorageProp('navVisible') private navVisible: boolean = true;
|
||
@StorageProp('currentTab') private currentTab: number = 0;
|
||
/** 宽屏:左边一级界面(含底部导航栏),右边二级界面 */
|
||
@StorageProp('isWideScreen') private isWide: boolean = false;
|
||
/** 当前右栏展示的二级页面 id,用于宽屏下高亮左侧入口行 */
|
||
@State activeSub: string = SUB_NONE;
|
||
@StorageProp('deviceBridgeConnected') private bridgeConnected: boolean = false;
|
||
@State bridgeUrl: string = '';
|
||
@State bridgeToken: string = '';
|
||
@State deviceId: string = '';
|
||
@State authorized: boolean = false;
|
||
@State devices: DeviceInfo[] = [];
|
||
@State loadingDevices: boolean = false;
|
||
@State toastMsg: string = '';
|
||
@State toastIsError: boolean = false;
|
||
/** 二级页面导航栈:系统返回手势/三键返回直接作用于它 */
|
||
private navStack: NavPathStack = new NavPathStack();
|
||
|
||
aboutToAppear(): void {
|
||
// id 判定顺序:桥里的 id 优先于持久化的 id,都没有才生成并落盘
|
||
this.deviceId = resolveDeviceId(deviceBridge.getDeviceId());
|
||
this.authorized = connStore.getDeviceAuth();
|
||
// Gateway URL derives from current connection
|
||
const cur = connStore.getCurrentConnection();
|
||
if (cur !== null) {
|
||
this.bridgeUrl = deviceGatewayUrl(cur.url);
|
||
this.bridgeToken = cur.apiKey;
|
||
}
|
||
this.refreshDevices();
|
||
// 登记导航栈:返回手势由 Index.onBackPress 按当前 Tab 精确派发过来
|
||
registerNavStack(2, this.navStack, () => {
|
||
this.activeSub = SUB_NONE;
|
||
});
|
||
}
|
||
|
||
aboutToDisappear(): void {
|
||
unregisterNavStack(2);
|
||
}
|
||
|
||
private palette(): ThemePalette {
|
||
return this.isDark ? DARK_PALETTE : LIGHT_PALETTE;
|
||
}
|
||
|
||
/**
|
||
* 打开二级页面。
|
||
*
|
||
* 窄屏(Stack 模式):push 一层,整屏覆盖,系统侧滑返回可退。
|
||
* 宽屏(Split 模式):左栏一级列表常驻,右栏只应有一页,
|
||
* 所以用 replace 换页而不是叠栈 —— 否则返回手势要一层层退回去。
|
||
*/
|
||
private openSub(id: string): void {
|
||
this.getUIContext().animateTo({ duration: ANIM_NORMAL, curve: Curve.EaseOut }, () => {
|
||
this.activeSub = id;
|
||
});
|
||
if (this.isWide && this.navStack.size() > 0) {
|
||
this.navStack.replacePathByName(id, subPageParam(id), false);
|
||
} else {
|
||
this.navStack.pushPathByName(id, subPageParam(id), true);
|
||
}
|
||
}
|
||
|
||
/** 二级页面返回键:宽屏下左栏常驻可见,SubPageLayer 已隐藏返回键 */
|
||
private closeSub(): void {
|
||
this.navStack.pop();
|
||
this.getUIContext().animateTo({ duration: ANIM_NORMAL, curve: Curve.EaseOut }, () => {
|
||
this.activeSub = SUB_NONE;
|
||
});
|
||
}
|
||
|
||
/** Toggle local authorization flag; hello 同步到网关。 */
|
||
private toggleAuthorized(on: boolean): void {
|
||
this.authorized = on;
|
||
try {
|
||
connStore.saveDeviceAuth(on);
|
||
} catch (e) {
|
||
// ignore persist failure
|
||
}
|
||
deviceBridge.updateAuthorized(on);
|
||
this.showToast(on ? '已授权,agent 可下发能力命令' : '已取消授权', false);
|
||
}
|
||
|
||
private showToast(msg: string, isError: boolean): void {
|
||
// 颜色标记必须在动画闭包外先落定,否则第一帧用的还是上一条 toast 的配色
|
||
this.toastIsError = isError;
|
||
this.getUIContext().animateTo({ duration: ANIM_NORMAL, curve: Curve.EaseOut }, () => {
|
||
this.toastMsg = msg;
|
||
});
|
||
setTimeout(() => {
|
||
this.getUIContext().animateTo({ duration: ANIM_NORMAL, curve: Curve.EaseOut }, () => {
|
||
this.toastMsg = '';
|
||
});
|
||
}, 2500);
|
||
}
|
||
|
||
/** 拉取网关在线设备列表(经 webui 反代)。 */
|
||
private async refreshDevices(): Promise<void> {
|
||
this.loadingDevices = true;
|
||
try {
|
||
// apiClient 已自动前置 /api/v1,这里只写其后的部分,
|
||
// 否则会拼成 /api/v1/api/v1/device/online 并 404。
|
||
const resp = await apiClient.get('/device/online');
|
||
if (resp.status >= 200 && resp.status < 300) {
|
||
const parsed: Record<string, Object> = JSON.parse(resp.body) as Record<string, Object>;
|
||
const list: DeviceInfo[] = parseOnlineDevices(parsed);
|
||
this.getUIContext().animateTo({ duration: ANIM_ENTER, curve: Curve.EaseOut }, () => {
|
||
this.devices = list;
|
||
});
|
||
} else {
|
||
this.devices = [];
|
||
}
|
||
} catch (e) {
|
||
// 网络失败保持静默,不打扰用户
|
||
}
|
||
this.loadingDevices = false;
|
||
}
|
||
|
||
build() {
|
||
// Navigation 提供真实导航栈:系统侧滑返回 / 三键返回都会自动 pop
|
||
Navigation(this.navStack) {
|
||
Stack({ alignContent: Alignment.Bottom }) {
|
||
Column() {
|
||
Scroll() {
|
||
Column() {
|
||
DeviceRootEntries({
|
||
activeSub: this.activeSub,
|
||
deviceId: this.deviceId,
|
||
bridgeConnected: this.bridgeConnected,
|
||
bridgeUrl: this.bridgeUrl,
|
||
loadingDevices: this.loadingDevices,
|
||
deviceCount: this.devices.length,
|
||
onOpen: (id: string) => {
|
||
this.openSub(id);
|
||
},
|
||
})
|
||
}
|
||
.width('100%')
|
||
.padding({ left: 16, right: 16, top: 76, bottom: 174 })
|
||
}
|
||
.width('100%')
|
||
.height('100%')
|
||
.scrollBar(BarState.Off)
|
||
.align(Alignment.Top)
|
||
.onDidScroll((xOffset: number, yOffset: number, state: ScrollState) => {
|
||
handleNavOnScroll(state);
|
||
})
|
||
}
|
||
.width('100%')
|
||
.height('100%')
|
||
|
||
PageTopBar({ title: '设备' })
|
||
|
||
// 一级悬浮区:只留刷新(网关状态徽标按用户要求去掉,
|
||
// 状态已经在页面内的网关卡片里如实展示)
|
||
NavFloatOverlay({ tab: 2 }) {
|
||
NavFloatRow() {
|
||
FloatIconButton({
|
||
icon: $r('app.media.ic_refresh'),
|
||
onTap: () => {
|
||
this.refreshDevices();
|
||
},
|
||
})
|
||
}
|
||
}
|
||
|
||
this.Toast()
|
||
}
|
||
.width('100%')
|
||
.height('100%')
|
||
.backgroundColor(Color.Transparent)
|
||
}
|
||
.navDestination(this.SubDestination)
|
||
// 宽屏(>=600vp)用 Split:navBar(一级列表 + 底部悬浮导航栏)常驻左栏,
|
||
// NavDestination(二级页面)渲染在右栏,两栏同时可见。
|
||
.mode(this.isWide ? NavigationMode.Split : NavigationMode.Stack)
|
||
.navBarPosition(NavBarPosition.Start)
|
||
.navBarWidth(WIDE_NAV_BAR_WIDTH)
|
||
.minContentWidth(WIDE_MIN_CONTENT)
|
||
.hideTitleBar(true)
|
||
.hideToolBar(true)
|
||
.hideBackButton(true)
|
||
.width('100%')
|
||
.height('100%')
|
||
// Split 模式下 navBar 常驻,此回调不再触发;宽屏一律锁住主 Tab 横滑
|
||
.onNavBarStateChange((isVisible: boolean) => {
|
||
markSubPageOpen(this.isWide || !isVisible);
|
||
})
|
||
// 模式初始化与切换:Split 右栏不能空白,自动填入默认二级页面;
|
||
// 退回 Stack 时清栈,否则会残留一个整屏覆盖的二级页面。
|
||
.onNavigationModeChange((mode: NavigationMode) => {
|
||
if (mode === NavigationMode.Split) {
|
||
markSubPageOpen(true);
|
||
if (this.navStack.size() === 0) {
|
||
this.openSub(SUB_LOCAL);
|
||
}
|
||
} else {
|
||
this.navStack.clear(false);
|
||
this.getUIContext().animateTo({ duration: ANIM_NORMAL, curve: Curve.EaseOut }, () => {
|
||
this.activeSub = SUB_NONE;
|
||
});
|
||
markSubPageOpen(false);
|
||
}
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 二级页面路由表。
|
||
* 每个面板自带 SubPageLayer 外壳(标题/所属 Tab/返回/刷新),这里只做分发。
|
||
*/
|
||
@Builder
|
||
SubDestination(name: string, param: object) {
|
||
NavDestination() {
|
||
if (name === SUB_LOCAL) {
|
||
DeviceLocalPane({
|
||
deviceId: this.deviceId,
|
||
authorized: this.authorized,
|
||
onBack: () => {
|
||
this.closeSub();
|
||
},
|
||
onToggleAuth: (on: boolean) => {
|
||
this.toggleAuthorized(on);
|
||
},
|
||
})
|
||
} else if (name === SUB_CAPS) {
|
||
DeviceCapsPane({
|
||
onBack: () => {
|
||
this.closeSub();
|
||
},
|
||
})
|
||
} else if (name === SUB_GATEWAY) {
|
||
DeviceGatewayPane({
|
||
bridgeUrl: this.bridgeUrl,
|
||
bridgeToken: this.bridgeToken,
|
||
bridgeConnected: this.bridgeConnected,
|
||
onBack: () => {
|
||
this.closeSub();
|
||
},
|
||
onRefresh: () => {
|
||
this.refreshDevices();
|
||
},
|
||
})
|
||
} else if (name === SUB_LIST) {
|
||
DeviceListPane({
|
||
devices: this.devices,
|
||
onBack: () => {
|
||
this.closeSub();
|
||
},
|
||
onRefresh: () => {
|
||
this.refreshDevices();
|
||
},
|
||
})
|
||
}
|
||
}
|
||
.hideTitleBar(true)
|
||
.backgroundColor(Color.Transparent)
|
||
}
|
||
|
||
@Builder
|
||
Toast() {
|
||
if (this.toastMsg.length > 0) {
|
||
Row() {
|
||
Text(this.toastMsg)
|
||
.fontSize(13)
|
||
.fontColor(this.toastIsError ? this.palette().toastErrorText : this.palette().toastText)
|
||
.padding({ left: 20, right: 20, top: 10, bottom: 10 })
|
||
.borderRadius(RADIUS_MD)
|
||
.backgroundColor(this.toastIsError ? this.palette().toastErrorBg : this.palette().toastBg)
|
||
}
|
||
.width('100%')
|
||
.justifyContent(FlexAlign.End)
|
||
.padding({ right: 20 })
|
||
.margin({ bottom: 166 })
|
||
.transition(TransitionEffect.OPACITY
|
||
.combine(TransitionEffect.translate({ y: 12 }))
|
||
.animation({ duration: ANIM_NORMAL, curve: Curve.EaseOut }))
|
||
}
|
||
}
|
||
}
|
||
|
||
const RADIUS_MD: number = 10;
|