dsh-dot-life 0.10.16 → 0.10.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/docs/phone.md +2 -2
- package/lib/client.js +2 -2
- package/package.json +1 -1
- package/src/dot/core.js +1 -1
- package/src/phone/phone.js +60 -13
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ One plugin, six components (living next to other dsh plugins: see 「与其他
|
|
|
17
17
|
|
|
18
18
|
```bash
|
|
19
19
|
dsh plugin --profile desktop add dsh-dot-life @xmanrui/dsh-im # npm; or github:Kevinwu901113/dsh-dot for the source
|
|
20
|
-
# then, in dsh: /phone accept (Android SDK license → the phone installs itself)
|
|
20
|
+
# then, in dsh: /phone accept (Android SDK license → the phone installs itself; /phone accept 32 for 32 GB of storage)
|
|
21
21
|
# /interlude preset 6QA0-1PD6 (a persona from the HDSI hub; pick your own on typ0.space)
|
|
22
22
|
```
|
|
23
23
|
|
|
@@ -65,7 +65,7 @@ Web 版:`dsh plugin --profile web add dsh-dot-life`。从源码装:把包名
|
|
|
65
65
|
|
|
66
66
|
### 三、第一次设置
|
|
67
67
|
|
|
68
|
-
1. **手机**:在 dsh 里发 `/phone accept
|
|
68
|
+
1. **手机**:在 dsh 里发 `/phone accept`(默认给手机 16 GB 存储;要别的大小发 `/phone accept 32` 这样,手机建好后不能再改)——接受 [Android SDK 许可](https://developer.android.com/studio/terms)后插件开始下载(约 2 GB,进度在 `~/.dsh/dsh-phone.log`),装完自动开机,桌面上出现一个手机窗口。`/phone` 看状态。
|
|
69
69
|
2. **装 App、登录**:在手机窗口里像用真手机一样操作:从官网下 APK 用 `adb install`(`~/.dsh/phone/platform-tools/adb`),或者让她自己装(`mobile_install_app` 会弹审批)。登录、验证码、人脸都由你在窗口里亲手过——她遇到会停下来叫你。**用小号。** 各平台的条款都不允许自动化,封了就封了。
|
|
70
70
|
3. **人设**:`/interlude preset <分享码>` 从 [typ0.space](https://typ0.space) 导入一份 HDSI 预设,或者把 `examples/canon.minase-style.json` 放到 `~/dot/interlude/canon.json`。
|
|
71
71
|
4. **她在手机上看什么**:profile 的 `cordis.patch.yml` 里给 `dot-interlude` 加 `phoneApps: { xiaoheihe.cn: com.max.xiaoheihe, bilibili.com: tv.danmaku.bili }`——这些站她永远用手机上的 App 去看,只读、无审批、每天有上限。
|
package/docs/phone.md
CHANGED
|
@@ -5,7 +5,7 @@ An Android phone the plugin installs and runs for the character, exposed to the
|
|
|
5
5
|
## 它做什么
|
|
6
6
|
|
|
7
7
|
1. **安装**(第一次):接受 [Android SDK 许可](https://developer.android.com/studio/terms)后(`/phone accept`,或配置 `acceptLicense: true`,或 `~/.dsh/dsh-phone.json` 里 `{"acceptLicense": true}`),从 `dl.google.com/android/repository` 读索引,下载 stable 通道的 emulator、platform-tools 和 `system-images;android-<api>;google_apis;<abi>`(约 1.7 GB),解压到 `~/.dsh/phone/`。`google_apis` 镜像没有 Play 商店——检测面最小,App 用 APK 装。
|
|
8
|
-
2. **AVD**:`~/.dsh/phone/avd/dot.avd/config.ini` 由插件写(Pixel 6 尺寸、1080×2400、3 GB
|
|
8
|
+
2. **AVD**:`~/.dsh/phone/avd/dot.avd/config.ini` 由插件写(Pixel 6 尺寸、1080×2400、3 GB 内存、数据分区默认 16 GB、不带 Play)。数据分区大小在手机建好之前选:`/phone accept <GB>` 或 `/phone size <GB>`(8–256);建好后模拟器不会扩大已有分区,`/phone size` 只显示当前大小。想改尺寸或内存,改配置后删掉这个目录重建(手机里的数据会没)。
|
|
9
9
|
3. **开机**:`emulator -avd dot -port 5554 -no-boot-anim -gpu auto`,等 `sys.boot_completed`,然后常亮屏幕、关动画、解锁。上一次 dsh 留下的还在跑的模拟器会被直接接管,不会开两个。模拟器自己退出会在 `restartDelayMs` 后重开。
|
|
10
10
|
4. **MCP**:开机后以 stdio 挂一个 mobile-mcp(随插件一起安装,`ANDROID_HOME` 指向 `~/.dsh/phone`,`ANDROID_SERIAL=emulator-5554`),工具名 `mcp__dot-phone__mobile_*`:列设备、截图、列屏幕元素(带坐标)、点、滑、长按、输入、按键、打开/关闭 App、装卸 App、开 URL。
|
|
11
11
|
5. **提示**:手机就绪后系统提示里多一段 `phone:device`,告诉模型设备号和用法(先看元素再点;验证码、人脸停下来叫用户)。
|
|
@@ -20,7 +20,7 @@ An Android phone the plugin installs and runs for the character, exposed to the
|
|
|
20
20
|
| `home` | `~/.dsh/phone` | SDK 三件套和 AVD 所在 |
|
|
21
21
|
| `api` / `tag` / `abi` | `35` / `google_apis` / 跟随宿主 CPU | 系统镜像;Apple silicon 用 `arm64-v8a`,x86 用 `x86_64` |
|
|
22
22
|
| `avd` / `device` | `dot` / `pixel_6` | AVD 名和机型 |
|
|
23
|
-
| `ramMb` / `dataGb` | `3072` / `
|
|
23
|
+
| `ramMb` / `dataGb` | `3072` / `16` | 内存、数据分区(`dataGb` 也可用 `/phone accept <GB>` / `/phone size <GB>` 在建手机前设) |
|
|
24
24
|
| `port` | `5554` | 控制台端口;adb 序列号 `emulator-<port>` |
|
|
25
25
|
| `window` / `DSH_DOT_PHONE_WINDOW=off` | `true` | 显示模拟器窗口 |
|
|
26
26
|
| `liveView` | `true` | 在 dsh 的 web server 上挂实时画面页(`/dsh-dot/phone/`);`false` 关闭 |
|
package/lib/client.js
CHANGED
|
@@ -422,7 +422,7 @@ window.__ModuleLoader__.load({
|
|
|
422
422
|
phoneDescription: "查看并操作 agent 的手机",
|
|
423
423
|
phoneToggle: "手机画面",
|
|
424
424
|
phoneChecking: "正在连接手机…",
|
|
425
|
-
phoneOffline: "手机还没有就绪(第一次要先在对话里发 /phone accept,下载约 2 GB
|
|
425
|
+
phoneOffline: "手机还没有就绪(第一次要先在对话里发 /phone accept,下载约 2 GB;默认给手机 16 GB 存储,想要别的大小发 /phone accept 32 这样,建好后不能再改)。",
|
|
426
426
|
dotTitle: "dot",
|
|
427
427
|
dotOpen: "dot",
|
|
428
428
|
dotDescription: "她现在在干什么、今天做了什么、记得什么",
|
|
@@ -448,7 +448,7 @@ window.__ModuleLoader__.load({
|
|
|
448
448
|
phoneDescription: "View and control the agent's phone",
|
|
449
449
|
phoneToggle: "Phone screen",
|
|
450
450
|
phoneChecking: "Connecting to the phone…",
|
|
451
|
-
phoneOffline: "The phone is not ready yet (first time: send /phone accept in a chat; it downloads about 2 GB).",
|
|
451
|
+
phoneOffline: "The phone is not ready yet (first time: send /phone accept in a chat; it downloads about 2 GB. The phone gets 16 GB of storage; for another size send e.g. /phone accept 32 — it cannot be changed later).",
|
|
452
452
|
dotTitle: "dot",
|
|
453
453
|
dotOpen: "dot",
|
|
454
454
|
dotDescription: "What she is doing now, today, and what she remembers",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-dot-life",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.18",
|
|
4
4
|
"description": "dot — a character who lives on her own phone, for DeepSeek Harness (dsh): an Android phone the plugin installs and runs, her own QQ, memory and a diary from real events, a life between conversations (幕间, after HDS-Interlude), an optional microVM computer with approval gates. One plugin, six components.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "AGPL-3.0-only",
|
package/src/dot/core.js
CHANGED
|
@@ -523,7 +523,7 @@ export function apply(ctx, config = {}) {
|
|
|
523
523
|
phoneCheckNow = phoneCheck;
|
|
524
524
|
ctx.inject(['dshPhone'], (c) => c.effect(() => c.dshPhone.onStatus?.((s) => {
|
|
525
525
|
if (s.state === 'error') void im.send(`⚠️ dot: 手机出错\n${s.error ?? '未知错误'}\n日志:~/.dsh/dsh-phone.log`, 'plain');
|
|
526
|
-
if (s.state === 'needs-license') void im.send('📱 dot: 手机还没装好——需要先接受 Android SDK 许可。在 dsh 里发 /phone accept
|
|
526
|
+
if (s.state === 'needs-license') void im.send('📱 dot: 手机还没装好——需要先接受 Android SDK 许可。在 dsh 里发 /phone accept(默认 16 GB 存储,要别的大小发 /phone accept 32 这样,建好后不能改)。', 'plain');
|
|
527
527
|
}) ?? (() => {}), 'dsh-dot: phone status'));
|
|
528
528
|
|
|
529
529
|
// /dot
|
package/src/phone/phone.js
CHANGED
|
@@ -35,7 +35,7 @@ export const defaults = {
|
|
|
35
35
|
avd: 'dot', // AVD name; also the phone's name
|
|
36
36
|
device: 'pixel_6', // hw.device.name
|
|
37
37
|
ramMb: 3072,
|
|
38
|
-
dataGb:
|
|
38
|
+
dataGb: 16, // her storage (/data), fixed when the phone is created: /phone accept <GB> or /phone size <GB> before that
|
|
39
39
|
port: 5554, // console port; the adb serial is emulator-<port>
|
|
40
40
|
window: true, // show the emulator window (the phone's live view); false = headless
|
|
41
41
|
gpu: 'auto',
|
|
@@ -217,6 +217,8 @@ export function apply(ctx, config = {}, deps = {}) {
|
|
|
217
217
|
const cfg = { ...defaults, ...settings, ...Object.fromEntries(Object.entries(config).filter(([, v]) => v !== undefined && v !== '' && !(Array.isArray(v) && !v.length))) };
|
|
218
218
|
// The license, once accepted (settings file), stays accepted whatever the patch's default says.
|
|
219
219
|
cfg.acceptLicense = Boolean(cfg.acceptLicense || settings.acceptLicense);
|
|
220
|
+
// The storage size the owner chose (/phone size, /phone accept <GB>) wins over the patch's.
|
|
221
|
+
if (settings.dataGb) cfg.dataGb = settings.dataGb;
|
|
220
222
|
const logger = withFileLog(ctx.logger('dsh-dot/phone'));
|
|
221
223
|
const fetchImpl = deps.fetch ?? globalThis.fetch;
|
|
222
224
|
const spawnImpl = deps.spawn ?? spawn;
|
|
@@ -233,7 +235,9 @@ export function apply(ctx, config = {}, deps = {}) {
|
|
|
233
235
|
avdHome: join(home, 'avd'),
|
|
234
236
|
downloads: join(home, 'downloads'),
|
|
235
237
|
};
|
|
236
|
-
|
|
238
|
+
// The console port is claimed at start (see claimPort): another emulator may already sit on cfg.port.
|
|
239
|
+
let port = cfg.port;
|
|
240
|
+
let serial = `emulator-${port}`;
|
|
237
241
|
const audit = createAudit(auditFile());
|
|
238
242
|
|
|
239
243
|
const phone = {
|
|
@@ -325,6 +329,20 @@ export function apply(ctx, config = {}, deps = {}) {
|
|
|
325
329
|
},
|
|
326
330
|
logger,
|
|
327
331
|
});
|
|
332
|
+
/** The size of her storage: what the existing phone was built with, or what a new one will get. */
|
|
333
|
+
phone.storage = () => {
|
|
334
|
+
const ini = join(paths.avdHome, `${cfg.avd}.avd`, 'config.ini');
|
|
335
|
+
const built = existsSync(ini) ? /^disk\.dataPartition\.size=(\d+)G$/m.exec(readFileSync(ini, 'utf8'))?.[1] : undefined;
|
|
336
|
+
return built ? { gb: Number(built), fixed: true } : { gb: cfg.dataGb, fixed: false };
|
|
337
|
+
};
|
|
338
|
+
/** Choose the storage size before the phone is created (8–256 GB). Throws once it exists. */
|
|
339
|
+
phone.setStorage = (gb) => {
|
|
340
|
+
const n = Number(gb);
|
|
341
|
+
if (!Number.isInteger(n) || n < 8 || n > 256) throw new Error('storage size: a whole number of GB from 8 to 256');
|
|
342
|
+
const st = phone.storage();
|
|
343
|
+
if (st.fixed) throw new Error(`her phone already exists with ${st.gb} GB; the size is fixed when a phone is created (an Android emulator does not grow an existing data partition)`);
|
|
344
|
+
cfg.dataGb = n; writeSettings({ dataGb: n }); audit({ kind: 'storage', gb: n });
|
|
345
|
+
};
|
|
328
346
|
phone.accept = () => { cfg.acceptLicense = true; writeSettings({ acceptLicense: true }); audit({ kind: 'license', accepted: true }); if (phone.state === 'needs-license' || phone.state === 'error') void start(); };
|
|
329
347
|
|
|
330
348
|
const installed = () => existsSync(paths.emulator) && existsSync(paths.adb) && existsSync(join(paths.sysdir, 'system.img'));
|
|
@@ -332,7 +350,7 @@ export function apply(ctx, config = {}, deps = {}) {
|
|
|
332
350
|
async function ensureSdk() {
|
|
333
351
|
if (installed()) return;
|
|
334
352
|
if (!cfg.acceptLicense) {
|
|
335
|
-
setState('needs-license', `the Android SDK license (${LICENSE_URL}) has not been accepted — reply /phone accept to install the phone`);
|
|
353
|
+
setState('needs-license', `the Android SDK license (${LICENSE_URL}) has not been accepted — reply /phone accept to install the phone (storage ${cfg.dataGb} GB; /phone accept <GB> to choose another size — it cannot grow later)`);
|
|
336
354
|
throw new Error('license not accepted');
|
|
337
355
|
}
|
|
338
356
|
setState('downloading');
|
|
@@ -441,20 +459,41 @@ export function apply(ctx, config = {}, deps = {}) {
|
|
|
441
459
|
});
|
|
442
460
|
logger.info(`${PHONE_TOOL_PREFIX}* mounted (mobile-mcp over adb)`);
|
|
443
461
|
}
|
|
444
|
-
/**
|
|
445
|
-
async function
|
|
446
|
-
try { const { stdout } = await exec(paths.adb, ['devices'], { env: env(), timeout: 10_000 }); return
|
|
462
|
+
/** Console ports of every emulator adb lists. MuMu, LDPlayer, BlueStacks and other AVDs show up as emulator-<port> too. */
|
|
463
|
+
async function listedPorts() {
|
|
464
|
+
try { const { stdout } = await exec(paths.adb, ['devices'], { env: env(), timeout: 10_000 }); return [...String(stdout).matchAll(/^emulator-(\d+)\s+\S+/gm)].map((m) => Number(m[1])); } catch { return []; }
|
|
465
|
+
}
|
|
466
|
+
/** The AVD behind emulator-<p>, from its console; '' for anything that is not an Android emulator console (MuMu and the like). */
|
|
467
|
+
async function avdNameAt(p) {
|
|
468
|
+
try { const { stdout } = await exec(paths.adb, ['-s', `emulator-${p}`, 'emu', 'avd', 'name'], { env: env(), timeout: 5_000 }); return String(stdout).split(/\r?\n/)[0].trim(); } catch { return ''; }
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Her AVD if it is already up (left from a previous dsh run): attach. Otherwise the first console port
|
|
472
|
+
* from cfg.port that nothing listed is using. Never attach to an emulator just because it holds the port:
|
|
473
|
+
* that is the user's own emulator, and settle() would rewrite its settings.
|
|
474
|
+
*/
|
|
475
|
+
async function claimPort() {
|
|
476
|
+
const listed = await listedPorts();
|
|
477
|
+
for (const p of listed) if ((await avdNameAt(p)) === cfg.avd) return { port: p, attach: true };
|
|
478
|
+
for (let p = cfg.port; p <= 5584; p += 2) if (!listed.includes(p)) return { port: p, attach: false };
|
|
479
|
+
throw new Error('no free emulator port: adb lists an emulator on every console port 5554–5584');
|
|
447
480
|
}
|
|
481
|
+
const setPort = (p) => { port = p; serial = `emulator-${p}`; phone.serial = serial; };
|
|
482
|
+
/** Is her emulator (on the claimed port) still listed by adb? */
|
|
483
|
+
async function alreadyRunning() { return (await listedPorts()).includes(port); }
|
|
448
484
|
async function start() {
|
|
449
485
|
try {
|
|
450
486
|
await ensureSdk();
|
|
451
487
|
ensureAvd();
|
|
452
488
|
setState('booting');
|
|
453
|
-
|
|
454
|
-
|
|
489
|
+
const claim = child ? { port, attach: true } : await claimPort();
|
|
490
|
+
if (claim.port !== cfg.port && !claim.attach) logger.warn(`emulator-${cfg.port} belongs to another emulator; hers takes console port ${claim.port}`);
|
|
491
|
+
setPort(claim.port);
|
|
492
|
+
if (claim.attach) {
|
|
493
|
+
logger.info(`${serial} is already running (AVD ${cfg.avd}); attaching`);
|
|
455
494
|
} else {
|
|
456
495
|
ensureCameraScene();
|
|
457
|
-
const args = ['-avd', cfg.avd, '-port', String(
|
|
496
|
+
const args = ['-avd', cfg.avd, '-port', String(port), '-no-boot-anim', '-gpu', cfg.gpu, '-netdelay', 'none', '-netspeed', 'full', ...(cfg.locale ? ['-change-locale', cfg.locale] : []), ...(cfg.timezone ? ['-timezone', cfg.timezone] : []), ...(cfg.window ? [] : ['-no-window'])];
|
|
458
497
|
// The phone outlives dsh (see the lifecycle effect), so it must not hold dsh's event loop:
|
|
459
498
|
// no pipes back to us (output goes to emulator.log), its own process group, and unref'd.
|
|
460
499
|
// A piped, referenced child kept the Host alive after shutdown until the desktop updater
|
|
@@ -532,12 +571,20 @@ export function apply(ctx, config = {}, deps = {}) {
|
|
|
532
571
|
ctx.inject(['commands'], (scope) => {
|
|
533
572
|
scope.effect(() => scope.commands.register({
|
|
534
573
|
name: 'phone',
|
|
535
|
-
description: 'the phone: status; "accept" accepts the Android SDK license and installs it; "restart" reboots the emulator; "screenshot" saves the screen to the phone home',
|
|
536
|
-
input: { hint: '[accept | retry | restart | screenshot | notifications | notify [mute|wake <pkg>]]' },
|
|
574
|
+
description: 'the phone: status; "accept [GB]" accepts the Android SDK license and installs it (with that much storage, default 16); "size <GB>" sets the storage of a phone not yet created; "restart" reboots the emulator; "screenshot" saves the screen to the phone home',
|
|
575
|
+
input: { hint: '[accept [GB] | size <GB> | retry | restart | screenshot | notifications | notify [mute|wake <pkg>]]' },
|
|
537
576
|
handler: async ({ rawInput }) => {
|
|
538
577
|
const arg = String(rawInput ?? '').trim();
|
|
539
578
|
let extra = '';
|
|
540
|
-
|
|
579
|
+
const [verb0, arg1] = arg.split(/\s+/);
|
|
580
|
+
if (verb0 === 'accept') {
|
|
581
|
+
try { if (arg1) phone.setStorage(arg1); } catch (err) { return { kind: 'success', text: `phone: ${err.message}` }; }
|
|
582
|
+
phone.accept(); extra = `\nlicense accepted; installing/booting now with ${phone.storage().gb} GB of storage (watch ~/.dsh/dsh-phone.log)`;
|
|
583
|
+
}
|
|
584
|
+
else if (verb0 === 'size') {
|
|
585
|
+
if (!arg1) { const st = phone.storage(); extra = `\nstorage: ${st.gb} GB${st.fixed ? ' (fixed: the phone exists)' : ' (used when the phone is created)'}`; }
|
|
586
|
+
else { try { phone.setStorage(arg1); extra = `\nstorage set to ${arg1} GB for when the phone is created`; } catch (err) { extra = `\n${err.message}`; } }
|
|
587
|
+
}
|
|
541
588
|
else if (arg === 'retry') { if (phone.state === 'error') { void start(); extra = '\nretrying'; } else extra = `\nnothing to retry (state ${phone.state})`; }
|
|
542
589
|
else if (arg === 'restart') { await phone.restart(); extra = '\nrestarting'; }
|
|
543
590
|
else if (arg === 'screenshot' && phone.isReady) { const file = join(home, 'last.png'); writeFileSync(file, await phone.screenshot()); extra = `\nsaved ${file}`; }
|
|
@@ -549,7 +596,7 @@ export function apply(ctx, config = {}, deps = {}) {
|
|
|
549
596
|
extra += `\nnotifications wake her from every app except: ${pol.muted.length ? pol.muted.join(', ') : '(none muted)'}\napps seen: ${pol.apps.length ? pol.apps.map((a) => `${a.pkg} ×${a.count} (${a.policy})`).join(', ') : '(none yet)'}\n/phone notify mute <pkg> · /phone notify wake <pkg>`;
|
|
550
597
|
}
|
|
551
598
|
const s = phone.status();
|
|
552
|
-
return { kind: 'success', text: `phone: ${s.state}${s.error ? ` — ${s.error}` : ''}\nserial: ${serial} · Android API ${cfg.api} (${abi}) · ${cfg.window ? 'window' : 'headless'} · home: ${home}\nlive view: ${phone.publicLiveViewUrl ?? phone.liveViewUrl ?? 'off'}\
|
|
599
|
+
return { kind: 'success', text: `phone: ${s.state}${s.error ? ` — ${s.error}` : ''}\nserial: ${serial} · Android API ${cfg.api} (${abi}) · ${cfg.window ? 'window' : 'headless'} · home: ${home}\nlive view: ${phone.publicLiveViewUrl ?? phone.liveViewUrl ?? 'off'}\nstorage: ${phone.storage().gb} GB · license: ${cfg.acceptLicense ? 'accepted' : `not accepted (${LICENSE_URL})`} · mcp: ${mcpFork ? 'mounted' : 'not mounted'}${extra}` };
|
|
553
600
|
},
|
|
554
601
|
}), 'dsh-dot/phone: /phone command');
|
|
555
602
|
});
|