coopani-world-life 0.7.2 → 0.9.0
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/CHANGELOG.md +27 -0
- package/package.json +1 -1
- package/src/bridge.ts +35 -8
- package/src/world.ts +95 -2
- package/web/panel.js +59 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# 变更记录
|
|
2
2
|
|
|
3
|
+
## 0.9.0
|
|
4
|
+
|
|
5
|
+
**灯的说明补全了 —— 灰的到底要不要管。**
|
|
6
|
+
|
|
7
|
+
原来每盏灯的 hint 只说了「现在什么状态」,没说「这算不算故障」。用户看到灰点,第一反应是「是不是坏了」,而灰的多数情况恰恰是「没启用,不用管」。
|
|
8
|
+
|
|
9
|
+
- 每盏灯的 hint 都补了「要不要管」和「怎么办」。
|
|
10
|
+
- **面板底部加了一块「扩展名旁边那三盏灯怎么看?」**(默认折叠)。那三盏灯是宿主画在扩展名旁边的,鼠标悬停能看到原因 —— 但**没人知道要悬停**。
|
|
11
|
+
- 说明三个颜色的含义:绿=上次是好的 / **灰=没启用,不是坏了** / 红=配了但用不了。
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## 0.8.0
|
|
15
|
+
|
|
16
|
+
**扩展名旁边加了三盏灯。**
|
|
17
|
+
|
|
18
|
+
| 灯 | 绿 | 灰 | 红 |
|
|
19
|
+
|---|---|---|---|
|
|
20
|
+
| **过日子** | 刚刚还在动 | —— | 已经 N 分钟没推进了 —— 她没在过日子,五条也不会再掉 |
|
|
21
|
+
| **本城** | 从你的服务器读到了 | 用内置的芦花塘(**没配,不是故障**) | 配了地址但读不到 |
|
|
22
|
+
| **旅行** | 知道她在哪 | 没装旅行扩展(**不是故障**) | 旅行那边 10 分钟没更新了 |
|
|
23
|
+
|
|
24
|
+
- 灰和红是两件事:**灰是「没启用」,红是「配好了但用不了」**。全标成红的,用户会去修一个没坏的东西。
|
|
25
|
+
- 「过日子」那盏最要紧:定时器挂掉、Core 被系统挂起的时候,面板上五个数字还是最后的样子,**看起来一切正常,其实她已经不动了**。
|
|
26
|
+
|
|
27
|
+
**顺带修了一个会让这盏灯点不出来的问题:** `readTown()` 原来把「没配地址」和「配了但连不上」都退成内置,面板上永远显示「内置」,看起来像你没配。现在两者分开(`builtin` / `failed`),红绿才有意义。
|
|
28
|
+
|
|
29
|
+
|
|
3
30
|
## 0.7.2
|
|
4
31
|
|
|
5
32
|
> **0.7.0 / 0.7.1 / 0.7.2 内容相同。** 0.7.0 发布后 registry 落库花了超过八分钟,
|
package/package.json
CHANGED
package/src/bridge.ts
CHANGED
|
@@ -89,8 +89,17 @@ export interface TownView {
|
|
|
89
89
|
rules: string[];
|
|
90
90
|
/** 服务器设过没有。false = 现在用的是内置默认。 */
|
|
91
91
|
custom: boolean;
|
|
92
|
-
/**
|
|
93
|
-
|
|
92
|
+
/**
|
|
93
|
+
* 从哪儿来的。
|
|
94
|
+
*
|
|
95
|
+
* **`builtin` 和 `failed` 必须分开** —— 两个都退成内置数据,但对用户意思完全不同:
|
|
96
|
+
* `builtin` 是「你没配,我在用默认」,不是故障(灰灯);
|
|
97
|
+
* `failed` 是「你配了但读不到」,是故障(红灯)。
|
|
98
|
+
* 混成一个,面板上就永远看不出「明明配了地址却一直是默认城名」。
|
|
99
|
+
*/
|
|
100
|
+
source: 'server' | 'builtin' | 'failed';
|
|
101
|
+
/** `failed` 时的一句话原因。给灯上的 hint 用。 */
|
|
102
|
+
problem?: string;
|
|
94
103
|
}
|
|
95
104
|
|
|
96
105
|
/**
|
|
@@ -157,7 +166,17 @@ export async function readTown(
|
|
|
157
166
|
signal: ctrl.signal,
|
|
158
167
|
headers: { accept: 'application/json' },
|
|
159
168
|
});
|
|
160
|
-
if (!res.ok)
|
|
169
|
+
if (!res.ok) {
|
|
170
|
+
/*
|
|
171
|
+
* 配了地址但服务端回非 200 —— **这是故障,不是「没配」**。
|
|
172
|
+
* 常见是 Worker 还是旧版(没有 `/town/info` 这个口),或者域名指错了。
|
|
173
|
+
*/
|
|
174
|
+
return {
|
|
175
|
+
...BUILTIN_TOWN,
|
|
176
|
+
source: 'failed',
|
|
177
|
+
problem: `服务器回了 ${res.status},先按内置的算(可能是那个服务器还是旧版,没有 /town/info)`,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
161
180
|
const j: any = await res.json();
|
|
162
181
|
const streets = Array.isArray(j?.streets) ? j.streets.filter((x: unknown) => typeof x === 'string') : [];
|
|
163
182
|
const rules = Array.isArray(j?.rules) ? j.rules.filter((x: unknown) => typeof x === 'string') : [];
|
|
@@ -172,12 +191,20 @@ export async function readTown(
|
|
|
172
191
|
};
|
|
173
192
|
} catch {
|
|
174
193
|
/*
|
|
175
|
-
* 超时、断网、证书错、返回不是 JSON
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
194
|
+
* 超时、断网、证书错、返回不是 JSON。
|
|
195
|
+
*
|
|
196
|
+
* **对她来说结果一样**(今天不知道城名改了没有),所以照样退内置、不抛。
|
|
197
|
+
* **但对用户不一样** —— 他明明配了地址,城名却一直显示「内置」,
|
|
198
|
+
* 而「内置」两个字看起来像「我没配」。所以要标成 `failed`,让灯上说清。
|
|
199
|
+
*
|
|
200
|
+
* 具体是哪种错(ECONNREFUSED / 证书 / JSON)**不往 hint 里塞** ——
|
|
201
|
+
* 那既不解释问题也不指向动作。
|
|
179
202
|
*/
|
|
180
|
-
return {
|
|
203
|
+
return {
|
|
204
|
+
...BUILTIN_TOWN,
|
|
205
|
+
source: 'failed',
|
|
206
|
+
problem: '连不上那个地址(超时或断网),先按内置的算',
|
|
207
|
+
};
|
|
181
208
|
} finally {
|
|
182
209
|
clearTimeout(timer);
|
|
183
210
|
}
|
package/src/world.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { statSync } from 'node:fs';
|
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import type {
|
|
5
|
-
Logger, ToolDef, World, WorldHost, WorldWebUiDecl, TriggerMode,
|
|
5
|
+
Logger, ToolDef, World, WorldHost, WorldWebUiDecl, WorldLamp, TriggerMode,
|
|
6
6
|
} from 'cortico/core/types.ts';
|
|
7
7
|
import { LIFE_ID, lifeConfigGroups, type LifeConfigSection } from './config.ts';
|
|
8
8
|
import {
|
|
@@ -34,7 +34,16 @@ export interface LifeWorldOptions {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
/** 版本号。envPrompt 里露出来,报障时第一个要确认的数。 */
|
|
37
|
-
const VERSION = '0.
|
|
37
|
+
const VERSION = '0.9.0';
|
|
38
|
+
|
|
39
|
+
/** 人话的时长:「3 分钟」「2 小时」。灯上的 hint 用,不要写 180000 毫秒。 */
|
|
40
|
+
function fmtSpan(ms: number): string {
|
|
41
|
+
const sec = Math.round(ms / 1000);
|
|
42
|
+
if (sec < 90) return `${sec} 秒`;
|
|
43
|
+
const min = Math.round(sec / 60);
|
|
44
|
+
if (min < 90) return `${min} 分钟`;
|
|
45
|
+
return `${(min / 60).toFixed(1)} 小时`;
|
|
46
|
+
}
|
|
38
47
|
|
|
39
48
|
export class LifeWorld implements World {
|
|
40
49
|
readonly id = LIFE_ID;
|
|
@@ -82,6 +91,15 @@ export class LifeWorld implements World {
|
|
|
82
91
|
* **不读内容**:内容归宿主的记忆系统管,生活层碰了就越界了(方案 §6.2)。
|
|
83
92
|
*/
|
|
84
93
|
private sessionMtime = 0;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 上一次 tick 跑起来的时刻(内存,不进存档)。
|
|
97
|
+
*
|
|
98
|
+
* 这一格是「**她还在过日子吗**」的唯一证据。盘上的 `state.updatedAt` 测不出来 ——
|
|
99
|
+
* 定时器挂了之后那个数就一直停在那儿,而面板上五条还是好好的,
|
|
100
|
+
* 看起来一切正常,其实她已经不动了。
|
|
101
|
+
*/
|
|
102
|
+
private lastTickAt = 0;
|
|
85
103
|
/**
|
|
86
104
|
* 基线立过没有。
|
|
87
105
|
*
|
|
@@ -108,6 +126,8 @@ export class LifeWorld implements World {
|
|
|
108
126
|
*/
|
|
109
127
|
this.sessionMtime = this.sessionStamp();
|
|
110
128
|
this.sessionBaselineSet = this.sessionMtime > 0;
|
|
129
|
+
/* 刚起来算活着 —— 否则第一分钟灯就是红的,白白吓人一次。 */
|
|
130
|
+
this.lastTickAt = Date.now();
|
|
111
131
|
this.restartTimer();
|
|
112
132
|
host.log.info(
|
|
113
133
|
`模拟鱼生已就绪:${this.town.name}(${this.town.source === 'server' ? '读服务器' : '内置'})`
|
|
@@ -174,6 +194,8 @@ export class LifeWorld implements World {
|
|
|
174
194
|
/* ---------------- 推进 ---------------- */
|
|
175
195
|
|
|
176
196
|
private async tick(): Promise<void> {
|
|
197
|
+
/* 先打点再干活:这一格记的是「定时器还活着」,不是「这一跳有活干」。 */
|
|
198
|
+
this.lastTickAt = Date.now();
|
|
177
199
|
const now = new Date();
|
|
178
200
|
|
|
179
201
|
/* 先把热改接上:周期变了重排定时器,地址变了重读城名。 */
|
|
@@ -969,9 +991,80 @@ export class LifeWorld implements World {
|
|
|
969
991
|
};
|
|
970
992
|
}
|
|
971
993
|
|
|
994
|
+
/**
|
|
995
|
+
* 扩展名旁边那三盏灯。
|
|
996
|
+
*
|
|
997
|
+
* ## 三态语义(照抄 journey 定下的,别自己发明)
|
|
998
|
+
*
|
|
999
|
+
* - **绿 `online`** = 上一次成功了
|
|
1000
|
+
* - **灰 `offline`** = 没启用。**这不是故障** —— 点成红的,用户会去修一个没坏的东西
|
|
1001
|
+
* - **红 `error`** = 配好了但用不了。**这一种不会自己好,正是最需要有人提醒的**
|
|
1002
|
+
*
|
|
1003
|
+
* ## 为什么第一盏是「过日子」
|
|
1004
|
+
*
|
|
1005
|
+
* 前两盏管外部依赖,第一盏管**她自己**。定时器挂掉、Core 被系统挂起、
|
|
1006
|
+
* `tickMs` 配成了一个荒唐的值 —— 这些情况下需求不再衰减,
|
|
1007
|
+
* 而面板上五个数字还是最后一次的样子,**看起来一切正常,其实她已经不动了**。
|
|
1008
|
+
* 这是整套东西里最安静的失败。
|
|
1009
|
+
*/
|
|
1010
|
+
private worldLamps(): WorldLamp[] {
|
|
1011
|
+
const now = new Date();
|
|
1012
|
+
const tickMs = Math.max(15_000, Number(this.cfg.tickMs) || 60_000);
|
|
1013
|
+
|
|
1014
|
+
/* ---- 过日子 ---- */
|
|
1015
|
+
const idleMs = Math.max(0, Date.now() - this.lastTickAt);
|
|
1016
|
+
const idleLimit = Math.max(3 * tickMs, 180_000);
|
|
1017
|
+
const alive: WorldLamp = idleMs <= idleLimit
|
|
1018
|
+
? { label: '过日子', state: 'online', hint: idleMs < 10_000 ? '刚刚还在动' : `上一次推进在 ${fmtSpan(idleMs)}前` }
|
|
1019
|
+
: {
|
|
1020
|
+
label: '过日子',
|
|
1021
|
+
state: 'error',
|
|
1022
|
+
hint: `已经 ${fmtSpan(idleMs)}没有推进了 —— 她没在过日子,五条也不会再掉。`
|
|
1023
|
+
+ '先看 Coopani 是不是被系统挂起了;还红就重启一次',
|
|
1024
|
+
};
|
|
1025
|
+
|
|
1026
|
+
/* ---- 本城 ---- */
|
|
1027
|
+
const host = (() => {
|
|
1028
|
+
try { return new URL(String(this.cfg.townUrl || '')).host; } catch { return ''; }
|
|
1029
|
+
})();
|
|
1030
|
+
const town: WorldLamp = this.town.source === 'server'
|
|
1031
|
+
? { label: '本城', state: 'online', hint: `从 ${host} 读的:${this.town.name}` }
|
|
1032
|
+
: this.town.source === 'failed'
|
|
1033
|
+
? {
|
|
1034
|
+
label: '本城',
|
|
1035
|
+
state: 'error',
|
|
1036
|
+
hint: `${this.town.problem || '配了地址但读不到'}。城名暂时用内置的,不影响她过日子。`
|
|
1037
|
+
+ '会自己重试;一直红就检查设置里那个网址拼对了没有',
|
|
1038
|
+
}
|
|
1039
|
+
: { label: '本城', state: 'offline', hint: `用内置的${this.town.name}。没配服务器就是这样,**不用管** —— 想改城名才去填那个网址` };
|
|
1040
|
+
|
|
1041
|
+
/* ---- 旅行 ---- */
|
|
1042
|
+
const j = readJourney(this.opts.dataDir, now);
|
|
1043
|
+
const staleLimitSec = 600;
|
|
1044
|
+
const travel: WorldLamp = !j.installed
|
|
1045
|
+
? { label: '旅行', state: 'offline', hint: '没装「大肥鱼环游世界」。不知道她在哪座城,但日子照过 —— **不用管**' }
|
|
1046
|
+
: j.staleSec > staleLimitSec
|
|
1047
|
+
? {
|
|
1048
|
+
label: '旅行',
|
|
1049
|
+
state: 'error',
|
|
1050
|
+
hint: `旅行那边 ${Math.round(j.staleSec / 60)} 分钟没更新了,她可能已经不在你以为的那座城。`
|
|
1051
|
+
+ '多半是那边停了或卡住,去它的面板看一眼',
|
|
1052
|
+
}
|
|
1053
|
+
: {
|
|
1054
|
+
label: '旅行',
|
|
1055
|
+
state: 'online',
|
|
1056
|
+
hint: j.phase === 'traveling'
|
|
1057
|
+
? `在路上,往${j.toName || '下一站'}去`
|
|
1058
|
+
: j.phase === 'staying' ? `在${j.cityName || '外地'}` : `在家${j.cityName ? `(${j.cityName})` : ''}`,
|
|
1059
|
+
};
|
|
1060
|
+
|
|
1061
|
+
return [alive, town, travel];
|
|
1062
|
+
}
|
|
1063
|
+
|
|
972
1064
|
webUi(): WorldWebUiDecl {
|
|
973
1065
|
return {
|
|
974
1066
|
label: '模拟鱼生',
|
|
1067
|
+
lamps: this.worldLamps(),
|
|
975
1068
|
panels: [
|
|
976
1069
|
{
|
|
977
1070
|
id: 'now',
|
package/web/panel.js
CHANGED
|
@@ -20,6 +20,14 @@ const TEXT = {
|
|
|
20
20
|
zh: {
|
|
21
21
|
loading: '读她的日子…',
|
|
22
22
|
empty: '还没读到。',
|
|
23
|
+
helpTitle: '扩展名旁边那三盏灯怎么看?',
|
|
24
|
+
helpOn: '绿',
|
|
25
|
+
helpOnDesc: '上一次是好的,正常。',
|
|
26
|
+
helpOff: '灰',
|
|
27
|
+
helpOffDesc: '没启用,不是坏了 —— 比如没装旅行扩展。不用管。',
|
|
28
|
+
helpErr: '红',
|
|
29
|
+
helpErrDesc: '配好了但用不了,要去处理。原因和怎么办,鼠标停在灯上能看到。',
|
|
30
|
+
helpHint: '三盏灯分别是:过日子(她还在正常流逝时间吗)、本城(城名从你的服务器读到了吗)、旅行(知道她在哪座城吗)。',
|
|
23
31
|
fbLead: '有 bug,或者想让她能干什么?',
|
|
24
32
|
fbBug: '复制诊断信息',
|
|
25
33
|
fbWant: '复制诊断信息(想加东西)',
|
|
@@ -81,6 +89,14 @@ const TEXT = {
|
|
|
81
89
|
en: {
|
|
82
90
|
loading: 'Reading her day…',
|
|
83
91
|
empty: 'Nothing yet.',
|
|
92
|
+
helpTitle: 'What do the three dots next to the extension name mean?',
|
|
93
|
+
helpOn: 'Green',
|
|
94
|
+
helpOnDesc: 'last time worked. Normal.',
|
|
95
|
+
helpOff: 'Grey',
|
|
96
|
+
helpOffDesc: 'not enabled — that is not a fault. Nothing to do.',
|
|
97
|
+
helpErr: 'Red',
|
|
98
|
+
helpErrDesc: 'configured but not working. Hover the dot for the reason and the fix.',
|
|
99
|
+
helpHint: 'The three are: daily life (is time still passing for her), town (did the name load from your server), travel (do we know what city she is in).',
|
|
84
100
|
fbLead: 'A bug, or something you want her to do?',
|
|
85
101
|
fbBug: 'Copy diagnostics',
|
|
86
102
|
fbWant: 'Copy diagnostics (feature request)',
|
|
@@ -247,6 +263,20 @@ function ensureStyle(root) {
|
|
|
247
263
|
.lf-move .dep { font-size: 12px; color: #6b7280; }
|
|
248
264
|
.lf-note-line { margin: 10px 0 0; font-size: 11.5px; color: #9ca3af; line-height: 1.7; }
|
|
249
265
|
|
|
266
|
+
/*
|
|
267
|
+
* 「灯怎么看」那一块。
|
|
268
|
+
*
|
|
269
|
+
* 灯在**扩展名旁边**(宿主画的),不在这个面板里 —— 所以用户在界面上看到灰点、
|
|
270
|
+
* 想知道是什么意思时,得有个地方能查。默认折叠:不占地方,但要找得到。
|
|
271
|
+
*/
|
|
272
|
+
.lf-help { margin-top: 12px; font-size: 12.5px; color: #374151; }
|
|
273
|
+
.lf-help summary { cursor: pointer; color: #2f6fed; font-size: 12.5px; padding: 4px 0; }
|
|
274
|
+
.lf-help summary:hover { text-decoration: underline; }
|
|
275
|
+
.lf-help ul { margin: 8px 0 0; padding-left: 18px; line-height: 1.9; }
|
|
276
|
+
.lf-help li b { color: #1b1e24; }
|
|
277
|
+
.lf-help .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%;
|
|
278
|
+
margin-right: 5px; vertical-align: middle; }
|
|
279
|
+
|
|
250
280
|
/*
|
|
251
281
|
* 底部反馈栏。
|
|
252
282
|
*
|
|
@@ -328,13 +358,14 @@ export default {
|
|
|
328
358
|
watches.append(el('h3', null, t(lang, 'watches')));
|
|
329
359
|
wants.append(el('h3', null, t(lang, 'wants')));
|
|
330
360
|
cols.append(habits, watches, wants, pendingCard, pledgeCard);
|
|
361
|
+
const helpBox = el('details', 'lf-help');
|
|
331
362
|
const fbBox = el('section', 'lf-fb');
|
|
332
363
|
const foot = el('div', 'lf-foot');
|
|
333
364
|
const reload = el('button', 'lf-btn', t(lang, 'reload'));
|
|
334
365
|
const msg = el('span', 'lf-msg', '');
|
|
335
366
|
foot.append(reload, msg);
|
|
336
367
|
|
|
337
|
-
app.append(head, sub, note, whoCard, vitalsCard, goalCard, moveCard, moodRow, cols, fbBox, foot);
|
|
368
|
+
app.append(head, sub, note, whoCard, vitalsCard, goalCard, moveCard, moodRow, cols, helpBox, fbBox, foot);
|
|
338
369
|
|
|
339
370
|
const drawVitals = (vitals, low) => {
|
|
340
371
|
vitalsCard.innerHTML = '';
|
|
@@ -691,6 +722,32 @@ export default {
|
|
|
691
722
|
fbBox.append(el('p', 'why', t(lang, 'fbWhy')));
|
|
692
723
|
};
|
|
693
724
|
|
|
725
|
+
/*
|
|
726
|
+
* 灯的说明。**只画一次** —— 它是静态的。
|
|
727
|
+
*
|
|
728
|
+
* 为什么需要这一块:那三盏灯是宿主画在扩展名旁边的,鼠标悬停能看到原因,
|
|
729
|
+
* 但**没人知道要悬停**。用户看到灰点,第一反应是「是不是坏了」,
|
|
730
|
+
* 而灰的多数情况恰恰是「没启用,不用管」。
|
|
731
|
+
*/
|
|
732
|
+
const drawHelp = () => {
|
|
733
|
+
helpBox.append(el('summary', null, t(lang, 'helpTitle')));
|
|
734
|
+
const ul = el('ul');
|
|
735
|
+
const item = (color, key, desc) => {
|
|
736
|
+
const li = el('li');
|
|
737
|
+
const dot = el('span', 'dot');
|
|
738
|
+
dot.style.background = color;
|
|
739
|
+
li.append(dot);
|
|
740
|
+
li.append(el('b', null, t(lang, key)));
|
|
741
|
+
li.append(document.createTextNode(' ' + t(lang, desc)));
|
|
742
|
+
return li;
|
|
743
|
+
};
|
|
744
|
+
ul.append(item('#2f855a', 'helpOn', 'helpOnDesc'));
|
|
745
|
+
ul.append(item('#9ca3af', 'helpOff', 'helpOffDesc'));
|
|
746
|
+
ul.append(item('#c0392b', 'helpErr', 'helpErrDesc'));
|
|
747
|
+
helpBox.append(ul);
|
|
748
|
+
helpBox.append(el('p', 'lf-muted', t(lang, 'helpHint')));
|
|
749
|
+
};
|
|
750
|
+
|
|
694
751
|
const load = () => ctx.invoke('snapshot').then(render).catch((e) => {
|
|
695
752
|
sub.textContent = t(lang, 'empty');
|
|
696
753
|
msg.textContent = (e && e.message) ? e.message : '读取失败';
|
|
@@ -725,6 +782,7 @@ export default {
|
|
|
725
782
|
.catch((e) => { msg.textContent = (e && e.message) || '失败'; });
|
|
726
783
|
});
|
|
727
784
|
|
|
785
|
+
drawHelp();
|
|
728
786
|
await load();
|
|
729
787
|
|
|
730
788
|
/*
|