cortico-world-self-awareness 0.6.1 → 0.7.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 CHANGED
@@ -1,5 +1,34 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.0
4
+
5
+ **这次把方向盘交出去了:怎么想、什么时候停,由她定。**
6
+
7
+ - **方式她自己挑**:每次把五种方式(回看/走神/打算/琢磨/综合)摆出来,插件只给一个建议——「这会儿更像走神」。
8
+ 她要在 `mode` 里写别的,就按她的来。接着上一条往下想时不摆菜单,只说「说新的一层」。
9
+ - **她可以叫停**:输出里写 `"rest": true`,就按她给的时长歇着——最短 2 小时、最长一天,没给时间默认 8 小时。
10
+ 以前间隔被夹在 15–360 分钟,等于**永远会被叫醒**,没有「这件事我想完了」的出口。
11
+ - **便签不再硬性 12 小时过期**:她说「明早再看」,原来隔 13 小时那张便签就没了。现在过期时间跟着她自己的间隔走
12
+ (最少 12 小时,最多 36 小时)。
13
+ - **想法记下当时的状态**:`mood` / `energy` / `phase`(深夜、清晨…)一起写进 `thoughts.jsonl`。
14
+ 以前心情和时段只喂给模型,回看时什么都看不到。时间线每条现在会标「深夜 · 精力 22」。
15
+ - **时间线**:叫停的那条标「她先搁着了」,右侧便笺显示「她说先搁着,X 再看」;
16
+ 便签内容改由服务端算好(过期的直接不给),不会再挂着三天前的话。
17
+ - **小修**:`carry` 只在她沿用了建议时才标;自己换了方式多半是换了件事,不该再说「接着上一条」。
18
+ - 测试 54 → 68 项。
19
+
20
+ ## 0.6.2
21
+
22
+ **时间线换了一张脸,顺便补上一个漏掉的模式。**
23
+
24
+ - **页面重做**:从原来的一列灰字,改成「深空意识舱」——深空蓝黑底、紫色思绪、青色状态,左边是思绪流,右边是留给下一次的便笺和接口诊断。
25
+ 思绪按今天/昨天/日期分组,可筛选;正文放大到 15px、行高 1.9,长时间看不再费眼。
26
+ - **补 `synthesize`(综合)**:0.4.0 加了第五种模式,但页面上的模式表只认四个——综合模式会原样显示英文 `synthesize`,筛选栏里也没有它。
27
+ 现在有中文名、有颜色、能筛选。
28
+ - **五种模式有说明了**:筛选栏下面加一行图例,写明「回看/走神/打算/琢磨/综合」各自在做什么,不用再翻文档猜。
29
+ - 接口检测仍放在右侧「系统信号」卡片里;10 秒限流单独显示「等一下」,不冒充故障。
30
+ - 测试 54 项不变,全部通过。
31
+
3
32
  ## 0.6.1
4
33
 
5
34
  把「测接口」做得能看见了。
package/README.md CHANGED
@@ -41,6 +41,10 @@
41
41
  她每想完一件事,可以给自己留一句「下次从哪儿接着想」和一个大致间隔(15 分钟到 6 小时)。
42
42
  下次思考时,那句话会原样递回到她眼前。她没留,才按上面的密度算。
43
43
 
44
+ **她也可以说不想了。** 写一个 `rest`,就按她给的时长歇着(最短 2 小时,最长一天;没给时间默认 8 小时),
45
+ 时间线上会标一句「她先搁着了」。这不是卡住,是她自己叫停。
46
+ 留的那句话也不再硬性 12 小时过期:她留得越久,便签存得越久(最多 36 小时)。
47
+
44
48
  于是会出现这种连续:
45
49
 
46
50
  ```
@@ -55,7 +59,7 @@
55
59
 
56
60
  ---
57
61
 
58
- ## 四种模式轮换
62
+ ## 五种方式,她自己挑
59
63
 
60
64
  | 模式 | 她在干什么 |
61
65
  |---|---|
@@ -63,8 +67,10 @@
63
67
  | `wonder` | 手上没做事,脑子飘走了 |
64
68
  | `plan` | 想接下来要做什么(不是任务清单) |
65
69
  | `doubt` | 有件事一直没想明白,再想一次 |
70
+ | `synthesize` | 把两件看着不相干的事连起来看 |
66
71
 
67
- 七成按顺序轮,三成随机跳——否则会变成「四个模式轮流打卡」。
72
+ **方式不是插件派的。** 每次会把五种摆出来,插件只给一个建议(「这会儿更像走神」),
73
+ 她自己要换就在 `mode` 里写。她要接着上一条往下想时,才不摆菜单,直接让她说新的一层。
68
74
 
69
75
  ---
70
76
 
@@ -115,7 +121,7 @@
115
121
  插件会开一个只在本机的小网页(默认 `http://127.0.0.1:7802`,被占用会自动往后找)。
116
122
  在 World 页点「看她的时间线」就能打开。
117
123
 
118
- - 按时间倒序,每条标:时间、模式(回看 / 走神 / 打算 / 琢磨)、重要度点
124
+ - 按时间倒序,每条标:时间、方式(回看 / 走神 / 打算 / 琢磨 / 综合)、时段、当时的精力、重要度点
119
125
  - 接着上次想下去的会单独标出来
120
126
  - 底部是「她对自己的看法」——几条碎念攒够重要度后自动收成的一句
121
127
  - 顶部:今天几次、花了多少 token、下次什么时候、现在是**在跑 / 睡着了 / 出错 / 已关闭**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cortico-world-self-awareness",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "type": "module",
5
5
  "description": "桌宠自己的内在时间线:没人说话的时候她也在想事情——想起旧事、走神、反复琢磨一件没想明白的。\n\n它只负责「想」:想到的写在本机一个文件里,不发消息,也不占对话的 token。配合「记忆核心」使用——你开口时,记忆核心会挑一条带进上下文,标明时间,并说清那不一定是你现在的想法。单独装也能跑,但那是一本她自己不会翻的日记。\n\n模型自选,OpenAI 兼容接口就行;默认一天最多 12 次,一次几分钱。\n\nQQ 交流群:745879632",
6
6
  "keywords": [
package/src/config.ts CHANGED
@@ -130,7 +130,7 @@ const RAW_GROUP: ConfigGroup = {
130
130
  'worlds.self-awareness.maxGapMin': {
131
131
  type: 'integer',
132
132
  title: '最长隔多久',
133
- description: '想到的东西多,就自动往这个上限靠;想得敷衍,就往上面那个下限靠。',
133
+ description: '想到的东西多,就自动往这个上限靠;想得敷衍,就往上面那个下限靠。她说「先搁着」时不受这里限制(可到一天)。',
134
134
  minimum: 2,
135
135
  maximum: 1440,
136
136
  default: 90,
package/src/pool.ts CHANGED
@@ -30,6 +30,12 @@ export interface Thought {
30
30
  nextIn?: number;
31
31
  /** 她给自己留的话:「明早再看看那个帖子」。下次会原样递回去。 */
32
32
  nextNote?: string;
33
+ /** 她说「先搁着」——不是按密度排的下一跳,是她自己叫停的。 */
34
+ rest?: boolean;
35
+ /** 写下这条时的状态,用来在时间线上回看「她当时是什么样子」。 */
36
+ mood?: number;
37
+ energy?: number;
38
+ phase?: string;
33
39
  }
34
40
 
35
41
  export interface Reflection {
@@ -103,6 +109,10 @@ export class ThoughtPool {
103
109
  ...(t.carry ? { carry: true } : {}),
104
110
  ...(t.nextIn ? { nextIn: t.nextIn } : {}),
105
111
  ...(t.nextNote ? { nextNote: t.nextNote } : {}),
112
+ ...(t.rest ? { rest: true } : {}),
113
+ ...(typeof t.mood === 'number' ? { mood: t.mood } : {}),
114
+ ...(typeof t.energy === 'number' ? { energy: t.energy } : {}),
115
+ ...(t.phase ? { phase: t.phase } : {}),
106
116
  };
107
117
  ensureDir(this.dir);
108
118
  // 先让 cache 落地再 append:否则 all() 会从文件里读回刚写的那条,push 之后就有了两份
@@ -183,12 +193,37 @@ export function clamp01(n: number): number {
183
193
  /** 她自己说的「多久之后再想」的允许范围。上下都留边:说 1 分钟太密,说三天就断了。 */
184
194
  export const NEXT_MIN_MINUTES = 15;
185
195
  export const NEXT_MAX_MINUTES = 360;
196
+ /** 说「先搁着」时允许拉得更长:至少两小时,最多一天。 */
197
+ export const REST_MIN_MINUTES = 120;
198
+ export const REST_MAX_MINUTES = 1440;
199
+ /** 她说了 rest 却没给间隔时的默认值:睡一觉再说。 */
200
+ export const REST_DEFAULT_MINUTES = 480;
186
201
 
187
202
  /** 把模型给的值收进合法范围;不是数字就当没写。 */
188
- export function clampNextIn(value: unknown): number | undefined {
203
+ export function clampNextIn(value: unknown, max = NEXT_MAX_MINUTES): number | undefined {
189
204
  const v = Number(value);
190
205
  if (!Number.isFinite(v) || v <= 0) return undefined;
191
- return Math.round(Math.max(NEXT_MIN_MINUTES, Math.min(NEXT_MAX_MINUTES, v)));
206
+ return Math.round(Math.max(NEXT_MIN_MINUTES, Math.min(max, v)));
207
+ }
208
+
209
+ /** 「先搁着」用的间隔:范围比平时宽。 */
210
+ export function clampRestIn(value: unknown): number | undefined {
211
+ const v = Number(value);
212
+ if (!Number.isFinite(v) || v <= 0) return undefined;
213
+ return Math.round(Math.max(REST_MIN_MINUTES, Math.min(REST_MAX_MINUTES, v)));
214
+ }
215
+
216
+ /**
217
+ * 她留的那句话能存多久。
218
+ * 以前是硬 12 小时——她说「明早再看」,隔了 13 小时那张便签就直接没了。
219
+ * 现在跟着她自己的 next 走:留的间隔越长,便签留得越久;仍留上限,免得半年前的便签被翻出来。
220
+ */
221
+ export const NOTE_TTL_MS = 12 * 3_600_000;
222
+ export const NOTE_TTL_MAX_MS = 36 * 3_600_000;
223
+
224
+ export function noteTtlMs(t: { nextIn?: number }): number {
225
+ const byHer = (Number(t.nextIn) || 0) * 60_000 + 3_600_000;
226
+ return Math.min(NOTE_TTL_MAX_MS, Math.max(NOTE_TTL_MS, byHer));
192
227
  }
193
228
 
194
229
  /** 累计重要度到这条线就该往上抽象一层了(写一条 reflection)。 */
package/src/think.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * 全部用「你就是她」的第二人称写提示词——用第三人称会写成分析报告。
6
6
  */
7
7
  import type { Thought, ThoughtMode } from './pool.ts';
8
- import { clampImportance, clampNextIn, density } from './pool.ts';
8
+ import { clampImportance, clampNextIn, clampRestIn, density } from './pool.ts';
9
9
  import { clip } from './time.ts';
10
10
 
11
11
  export interface ThinkContext {
@@ -39,21 +39,38 @@ ${persona ? `你是谁:${persona}\n` : ''}
39
39
  - 别汇报工作,别复述别人交给你做的事。独处时想的不是待办。
40
40
  - 想不通就想不通,可以停在半路。人独处时大部分念头都没有结论。
41
41
  - 不要提「用户」「对话」「模型」「AI」「记忆」「记录」「卡片」这些词。
42
- - 想完之后,留一句「下次从哪儿接着想」和大致的间隔写进 next;想完了就空着。
42
+ - 用什么方式想,你自己挑:回看 / 走神 / 打算 / 琢磨 / 综合。
43
+ - 想完之后,留一句「下次从哪儿接着想」和大致的间隔写进 next。
44
+ - 真的不想了、想搁着,就写 "rest":true,间隔可以长到一天。
43
45
 
44
46
  只输出一行 JSON,不要别的:
45
- {"thought":"你想到的那件事","importance":1,"next":{"in":60,"note":"留给自己的一句话"}}
47
+ {"thought":"你想到的那件事","importance":1,"mode":"wonder","next":{"in":60,"note":"留给自己的一句话"},"rest":false}
48
+ mode 只能填:reflect(回看以前的事)/ wonder(没缘由地走神)/ plan(打算接下来做什么)/ doubt(琢磨一件没想明白的)/ synthesize(把两件看着不相干的事连起来)。
46
49
  importance 是 1-10:这件事对你有多重要。10 = 你会一直想它。
47
- next 是你给自己留的:还会想,就定个时间(15–360 分钟)和一句「下次从哪儿接着想」。
50
+ next 是你给自己留的:还会想,就定个时间(15–360 分钟;写了 rest 可以到 1440)和一句「下次从哪儿接着想」。
48
51
  想完了、没什么可接的,就空着。`;
49
52
  }
50
53
 
54
+ const MODE_LABEL: Record<ThoughtMode, string> = {
55
+ reflect: '回看',
56
+ wonder: '走神',
57
+ plan: '打算',
58
+ doubt: '琢磨',
59
+ synthesize: '综合',
60
+ };
61
+
62
+ /** 把五种方式摆给她选,不是替她定。 */
63
+ const MODE_MENU = [
64
+ '· 回看:想起以前的一件事,回头看它',
65
+ '· 走神:手上没在做什么,脑子飘走了',
66
+ '· 打算:想自己接下来要做什么(不是待办清单)',
67
+ '· 琢磨:一件一直没想明白的事,再想一次',
68
+ '· 综合:把两件看着没关系的事连起来看',
69
+ ].join('\n');
70
+
51
71
  const MODE_ASK: Record<ThoughtMode, (ctx: ThinkContext) => string> = {
52
72
  reflect: (ctx) => {
53
73
  if (!ctx.focus) return '你想起了以前的一件事。现在回头看它,感觉和当时一样吗?';
54
- if (ctx.carry) {
55
- return `你上次想到「${ctx.focus}」,没想完。接着往下想——说新的一层,别把上次那句重说一遍。`;
56
- }
57
74
  return `你想起了这件事:「${ctx.focus}」。现在回头看它,感觉和当时一样吗?`;
58
75
  },
59
76
  wonder: () => '你手上没在做什么,脑子飘走了。飘到哪算哪,不用有理由。',
@@ -88,7 +105,17 @@ export function buildMessages(mode: ThoughtMode, ctx: ThinkContext): { role: str
88
105
  lines.push('(你最近没想过什么。)');
89
106
  }
90
107
  lines.push('');
91
- lines.push(MODE_ASK[mode](ctx));
108
+ if (ctx.carry && ctx.focus) {
109
+ // 接着上一条想:这时候别让她换题,除非她自己要换
110
+ lines.push(`上次你想到「${ctx.focus}」,没想完。接着往下想——说新的一层,别把上次那句重说一遍。`);
111
+ lines.push(`想换件事也行;换就换,mode 里写你这次想用的方式。`);
112
+ } else {
113
+ lines.push('这次没人跟你说话。想怎么想都行:');
114
+ lines.push(MODE_MENU);
115
+ if (ctx.focus) lines.push(`(手边现成的事:「${ctx.focus}」,想从这儿起头也行,不想用也行。)`);
116
+ lines.push(`这会儿更像「${MODE_LABEL[mode]}」:${MODE_ASK[mode](ctx)}`);
117
+ lines.push('你也可以换别的,mode 里写你选的。');
118
+ }
92
119
  return [
93
120
  { role: 'system', content: systemPrompt(ctx.persona) },
94
121
  { role: 'user', content: lines.join('\n') },
@@ -188,11 +215,28 @@ export interface ParsedThought {
188
215
  next?: { in?: number; note?: string };
189
216
  }
190
217
 
191
- /** 她给自己留的那句:范围收进 15–360 分钟,note 超过 40 字截断。都不合法就当没留。 */
192
- export function parseNext(value: unknown): { in?: number; note?: string } | undefined {
218
+ export interface ParsedThought {
219
+ text: string;
220
+ importance: number;
221
+ next?: { in?: number; note?: string };
222
+ /** 她自己挑的方式。没填就用插件建议的那个。 */
223
+ mode?: ThoughtMode;
224
+ /** 她说「先搁着」。 */
225
+ rest?: boolean;
226
+ }
227
+
228
+ const MODE_IDS: ThoughtMode[] = ['reflect', 'wonder', 'plan', 'doubt', 'synthesize'];
229
+
230
+ function asMode(value: unknown): ThoughtMode | undefined {
231
+ return typeof value === 'string' && (MODE_IDS as string[]).includes(value) ? (value as ThoughtMode) : undefined;
232
+ }
233
+
234
+ /** 她给自己留的那句:范围收进合法范围,note 超过 40 字截断。都不合法就当没留。 */
235
+ export function parseNext(value: unknown, rest = false): { in?: number; note?: string } | undefined {
193
236
  if (!value || typeof value !== 'object') return undefined;
194
237
  const o = value as { in?: unknown; note?: unknown };
195
- const inMin = clampNextIn(o.in);
238
+ // 说了 rest 就允许拉到一天,否则还是 15–360
239
+ const inMin = rest ? clampRestIn(o.in) : clampNextIn(o.in);
196
240
  const note = typeof o.note === 'string' && o.note.trim() ? clip(o.note.trim(), 40) : undefined;
197
241
  if (inMin === undefined && !note) return undefined;
198
242
  return { ...(inMin !== undefined ? { in: inMin } : {}), ...(note ? { note } : {}) };
@@ -203,11 +247,19 @@ export function parseThought(raw: string): ParsedThought {
203
247
 
204
248
  const tryJson = (s: string): ParsedThought | null => {
205
249
  try {
206
- const o = JSON.parse(s) as { thought?: unknown; text?: unknown; importance?: unknown; next?: unknown };
250
+ const o = JSON.parse(s) as { thought?: unknown; text?: unknown; importance?: unknown; next?: unknown; mode?: unknown; rest?: unknown };
207
251
  const text = String(o.thought ?? o.text ?? '').trim();
208
252
  if (!text) return null;
209
- const next = parseNext(o.next);
210
- return { text, importance: clampImportance(o.importance), ...(next ? { next } : {}) };
253
+ const rest = o.rest === true || o.rest === 'true';
254
+ const next = parseNext(o.next, rest);
255
+ const mode = asMode(o.mode);
256
+ return {
257
+ text,
258
+ importance: clampImportance(o.importance),
259
+ ...(next ? { next } : {}),
260
+ ...(mode ? { mode } : {}),
261
+ ...(rest ? { rest: true } : {}),
262
+ };
211
263
  } catch {
212
264
  return null;
213
265
  }
@@ -259,16 +311,19 @@ export async function thinkOnce(
259
311
  if (!res.ok || !res.text) return { ok: false, reason: res.reason ?? '调用失败' };
260
312
  const parsed = parseThought(res.text);
261
313
  if (!parsed.text) return { ok: false, reason: '解析后没有内容' };
314
+ // 她自己挑了方式就用她的;没挑就沿用插件建议的
315
+ const finalMode = parsed.mode ?? mode;
262
316
  return {
263
317
  ok: true,
264
318
  thought: {
265
- mode,
319
+ mode: finalMode,
266
320
  text: clip(parsed.text, 400),
267
321
  importance: parsed.importance,
268
322
  seeds,
269
323
  // 她自己留的那句要带出去,不然解析了也白解析
270
324
  ...(parsed.next?.in ? { nextIn: parsed.next.in } : {}),
271
325
  ...(parsed.next?.note ? { nextNote: parsed.next.note } : {}),
326
+ ...(parsed.rest ? { rest: true } : {}),
272
327
  promptTokens: res.promptTokens,
273
328
  outputTokens: res.outputTokens,
274
329
  },
package/src/world.ts CHANGED
@@ -24,6 +24,8 @@ import {
24
24
  density,
25
25
  loadBudget,
26
26
  nextGapMinutes,
27
+ noteTtlMs,
28
+ REST_DEFAULT_MINUTES,
27
29
  rollDay,
28
30
  saveBudget,
29
31
  type BudgetState,
@@ -327,7 +329,15 @@ export class SelfAwarenessWorld implements World {
327
329
 
328
330
  this.fails = 0;
329
331
  this.lastError = '';
330
- const thought = this.pool.add({ ...res.thought, carry: Boolean(carry) });
332
+ const thought = this.pool.add({
333
+ ...res.thought,
334
+ // 她还按建议往下接,才算「接着上一条」;自己换了方式,多半是换了件事
335
+ carry: Boolean(carry) && res.thought.mode === mode,
336
+ // 把「她当时是什么样子」一起存下来:时间线以后能回看,不只是知道她想了什么
337
+ ...(typeof core?.mood === 'number' ? { mood: Math.round(core.mood) } : {}),
338
+ ...(typeof core?.energy === 'number' ? { energy: Math.round(core.energy) } : {}),
339
+ phase: timeOfDay(now, this.tz()),
340
+ });
331
341
  this.lastSnapshot = { ts: thought.ts, text: thought.text, mode: thought.mode };
332
342
 
333
343
  this.budget.count += 1;
@@ -335,11 +345,13 @@ export class SelfAwarenessWorld implements World {
335
345
  this.budget.pendingImportance += thought.importance;
336
346
  this.budget.lastThoughtAt = thought.ts;
337
347
 
338
- // 下次隔多久:她自己说了就听她的,没说才按密度算
348
+ // 下次隔多久:她说「先搁着」就按她的长间隔,其余听她自己定的,没定才按密度算
339
349
  const herNext = Number(res.thought.nextIn);
340
350
  const gap = Number.isFinite(herNext) && herNext > 0
341
351
  ? herNext
342
- : nextGapMinutes(density(thought), Number(cfg.minGapMin) || 25, Number(cfg.maxGapMin) || 90);
352
+ : thought.rest
353
+ ? REST_DEFAULT_MINUTES
354
+ : nextGapMinutes(density(thought), Number(cfg.minGapMin) || 25, Number(cfg.maxGapMin) || 90);
343
355
  if (note) this.budget.lastNoteId = note.id;
344
356
  this.budget.nextDueAt = new Date(Date.now() + Math.round(gap * 60_000)).toISOString();
345
357
  saveBudget(this.dataDir, this.budget);
@@ -355,6 +367,7 @@ export class SelfAwarenessWorld implements World {
355
367
  importance: thought.importance,
356
368
  gapMin: Math.round(gap),
357
369
  byHer: Number.isFinite(herNext) && herNext > 0,
370
+ rest: Boolean(thought.rest),
358
371
  ms: Date.now() - started,
359
372
  });
360
373
  } catch {
@@ -435,12 +448,13 @@ export class SelfAwarenessWorld implements World {
435
448
  * 现在都第二天晚上了,再提就是翻旧账。用过的记在 budget.lastNoteId,不重复递。
436
449
  */
437
450
  private latestNote(now: number): { id: string; text: string } | null {
438
- const recent = this.pool.recent(6).reverse();
451
+ const recent = this.pool.recent(12).reverse();
439
452
  for (const t of recent) {
440
453
  if (!t.nextNote) continue;
441
454
  if (t.id === this.budget.lastNoteId) continue;
442
455
  const at = Date.parse(t.ts) || 0;
443
- if (!at || now - at > 12 * 3_600_000) continue;
456
+ // 便签能存多久,跟着她自己定的间隔走(以前硬 12 小时,"明早再看"会直接丢)
457
+ if (!at || now - at > noteTtlMs(t)) continue;
444
458
  return { id: t.id, text: t.nextNote };
445
459
  }
446
460
  return null;
@@ -688,6 +702,22 @@ export class SelfAwarenessWorld implements World {
688
702
  today: { count: this.budget.count, tokens: this.budget.tokens },
689
703
  limit: { count: Number(cfg.dailyLimit) || 0, tokens: Number(cfg.dailyTokenBudget) || 0 },
690
704
  nextDueAt: this.budget.nextDueAt ?? null,
705
+ // 她说「先搁着」的话,页面就别再写「等下一次思考」了——她是在歇,不是卡住了
706
+ resting: (() => {
707
+ const last = this.pool.recent(1)[0];
708
+ return last?.rest ? { at: last.ts, until: this.budget.nextDueAt ?? null } : null;
709
+ })(),
710
+ // 给页面用的「当前那张便签」:过期的不算,免得侧栏挂着三天前的话
711
+ note: (() => {
712
+ // 便签有效期现在能到 36 小时,往回多看几条,别因为条数少就漏了它
713
+ for (const t of this.pool.recent(12).reverse()) {
714
+ if (!t.nextNote) continue;
715
+ const at = Date.parse(t.ts) || 0;
716
+ if (!at || Date.now() - at > noteTtlMs(t)) continue;
717
+ return { text: t.nextNote, in: t.nextIn ?? null, at: t.ts, mode: t.mode };
718
+ }
719
+ return null;
720
+ })(),
691
721
  totalThoughts: this.pool.all().length,
692
722
  thoughts: this.pool
693
723
  .all()
@@ -702,6 +732,10 @@ export class SelfAwarenessWorld implements World {
702
732
  carry: Boolean(t.carry),
703
733
  nextNote: t.nextNote ?? null,
704
734
  nextIn: t.nextIn ?? null,
735
+ rest: Boolean(t.rest),
736
+ mood: typeof t.mood === 'number' ? t.mood : null,
737
+ energy: typeof t.energy === 'number' ? t.energy : null,
738
+ phase: t.phase ?? null,
705
739
  promptTokens: t.promptTokens ?? 0,
706
740
  outputTokens: t.outputTokens ?? 0,
707
741
  })),
package/webui/index.html CHANGED
@@ -5,267 +5,356 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1">
6
6
  <title>她的时间线 · 自我意识</title>
7
7
  <style>
8
- :root {
9
- --bg: #060911;
10
- --panel: rgba(120, 220, 214, 0.045);
11
- --line: rgba(120, 220, 214, 0.14);
12
- --text: #d9e6f2;
13
- --dim: rgba(150, 172, 200, 0.55);
14
- --faint: rgba(150, 172, 200, 0.32);
15
- --accent: #7fe3d4;
16
- --reflect: #7fe3d4;
17
- --wonder: #b9a7ff;
18
- --plan: #8cc4ff;
19
- --doubt: #ffc27f;
20
- }
21
- * { box-sizing: border-box; }
22
- body {
23
- margin: 0; background: var(--bg); color: var(--text);
24
- font: 14px/1.65 -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
25
- padding: 28px 20px 64px;
26
- }
27
- .wrap { max-width: 760px; margin: 0 auto; }
28
- header { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-bottom: 6px; }
29
- h1 { font-size: 17px; font-weight: 500; margin: 0; letter-spacing: .02em; }
30
- h1::before {
31
- content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
32
- background: var(--accent); box-shadow: 0 0 12px var(--accent); margin-right: 9px; vertical-align: 3px;
33
- }
34
- .sub { color: var(--faint); font-size: 12px; letter-spacing: .04em; }
35
- .stats {
36
- display: flex; gap: 22px; flex-wrap: wrap; margin: 18px 0 26px;
37
- padding: 14px 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel);
38
- }
39
- .stat { min-width: 78px; }
40
- .stat b { display: block; font-size: 19px; font-weight: 500; font-variant-numeric: tabular-nums; }
41
- .stat span { color: var(--dim); font-size: 11.5px; }
42
- .warn { color: #ffb3a7; }
43
- .topline { display: flex; align-items: stretch; gap: 12px; margin: 18px 0 10px; }
44
- .topline .stats { flex: 1; margin: 0; min-width: 0; }
45
- .probe-card {
46
- flex: none; width: 102px; display: flex; flex-direction: column;
47
- align-items: center; justify-content: center; gap: 9px;
48
- background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
49
- color: var(--dim); font: inherit; font-size: 12.5px; letter-spacing: .05em;
50
- cursor: pointer; padding: 0; transition: color .18s, border-color .18s, background .18s;
51
- }
52
- .probe-card:hover:not(:disabled) {
53
- color: var(--accent); border-color: rgba(127, 227, 212, .45); background: rgba(127, 227, 212, .06);
54
- }
55
- .probe-card:disabled { cursor: default; }
56
- .probe-card svg { width: 24px; height: 24px; display: block; }
57
- .probe-card.testing { color: var(--accent); border-color: rgba(127, 227, 212, .4); }
58
- .probe-card.testing svg { animation: pulse 1.1s ease-in-out infinite; }
59
- .probe-card.ok { color: var(--accent); border-color: rgba(127, 227, 212, .5); background: rgba(127, 227, 212, .07); }
60
- .probe-card.bad { color: #ffb3a7; border-color: rgba(255, 120, 100, .45); background: rgba(255, 90, 70, .06); }
61
- @keyframes pulse { 0%, 100% { opacity: .35; transform: scale(.94); } 50% { opacity: 1; transform: scale(1.06); } }
62
- .probe-msg {
63
- margin: 0 0 22px; padding: 9px 14px; border-radius: 8px; font-size: 12.5px;
64
- border: 1px solid var(--line); color: var(--dim); background: var(--panel);
65
- animation: fadein .25s ease-out;
66
- }
67
- .probe-msg.ok { color: var(--accent); border-color: rgba(127, 227, 212, .3); background: rgba(127, 227, 212, .05); }
68
- .probe-msg.bad { color: #ffb3a7; border-color: rgba(255, 120, 100, .3); background: rgba(255, 90, 70, .06); }
69
- @keyframes fadein { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }
70
- .err {
71
- margin: 0 0 20px; padding: 10px 14px; border-radius: 8px;
72
- border: 1px solid rgba(255, 120, 100, 0.3); background: rgba(255, 90, 70, 0.07);
73
- color: #ffb3a7; font-size: 12.5px;
74
- }
75
- h2 {
76
- font-size: 12px; font-weight: 500; color: var(--faint); letter-spacing: .16em;
77
- text-transform: none; margin: 30px 0 14px;
78
- }
79
- .list { position: relative; padding-left: 20px; min-height: 60px; }
80
- .list::before {
81
- content: ''; position: absolute; left: 4px; top: 6px; bottom: 0; width: 1px;
82
- background: linear-gradient(180deg, var(--line) 0%, var(--line) 70%, transparent);
83
- }
84
- .item { position: relative; padding: 0 0 20px; }
85
- .item::before {
86
- content: ''; position: absolute; left: -19px; top: 8px; width: 5px; height: 5px;
87
- border-radius: 50%; background: var(--accent); opacity: .75;
88
- }
89
- .item.reflect::before { background: var(--reflect); }
90
- .item.wonder::before { background: var(--wonder); }
91
- .item.plan::before { background: var(--plan); }
92
- .item.doubt::before { background: var(--doubt); }
93
- .meta { display: flex; align-items: center; gap: 10px; font-size: 11.5px; color: var(--faint); margin-bottom: 5px; }
94
- .mode { letter-spacing: .06em; }
95
- .item.reflect .mode { color: var(--reflect); }
96
- .item.wonder .mode { color: var(--wonder); }
97
- .item.plan .mode { color: var(--plan); }
98
- .item.doubt .mode { color: var(--doubt); }
99
- .dots { display: inline-flex; gap: 2px; }
100
- .dots i { width: 5px; height: 5px; border-radius: 50%; background: rgba(150, 172, 200, 0.18); }
101
- .dots i.on { background: currentColor; opacity: .85; }
102
- .text { white-space: pre-wrap; word-break: break-word; }
103
- .carry { color: var(--faint); font-size: 11px; margin-left: 4px; }
104
- .empty { color: var(--faint); padding: 26px 0; }
105
- .note-line {
106
- margin-top: 6px; padding-left: 10px; border-left: 1px solid rgba(201, 162, 255, 0.35);
107
- color: rgba(201, 162, 255, 0.75); font-size: 12px;
108
- }
109
- .refl { padding: 12px 16px; border-left: 2px solid var(--accent); background: var(--panel); border-radius: 0 8px 8px 0; margin-bottom: 12px; }
110
- .refl .meta { margin-bottom: 6px; }
111
- footer { margin-top: 40px; color: var(--faint); font-size: 11.5px; letter-spacing: .03em; }
112
- code { font-family: ui-monospace, Consolas, monospace; font-size: 11.5px; color: var(--dim); }
8
+ :root {
9
+ --bg: #080c14;
10
+ --bg-deep: #060910;
11
+ --surface: #0e1622;
12
+ --surface-2: #121d2c;
13
+ --surface-3: #172337;
14
+ --line: rgba(143, 183, 221, .18);
15
+ --line-soft: rgba(143, 183, 221, .1);
16
+ --text: #e7edf7;
17
+ --muted: #8b9ab0;
18
+ --faint: #56657b;
19
+ --cyan: #66e3d3;
20
+ --cyan-soft: rgba(102, 227, 211, .12);
21
+ --purple: #c9a2ff;
22
+ --purple-soft: rgba(201, 162, 255, .12);
23
+ --blue: #8cc4ff;
24
+ --amber: #f4c47c;
25
+ --rose: #f2a6c9;
26
+ --red: #ff9f9b;
27
+ --mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
28
+ }
29
+ * { box-sizing: border-box; }
30
+ html { background: var(--bg); }
31
+ body {
32
+ margin: 0; min-width: 320px; color: var(--text); background:
33
+ linear-gradient(rgba(102, 227, 211, .025) 1px, transparent 1px),
34
+ linear-gradient(90deg, rgba(102, 227, 211, .025) 1px, transparent 1px),
35
+ radial-gradient(circle at 75% 0%, rgba(108, 77, 170, .14), transparent 34rem),
36
+ var(--bg);
37
+ background-size: 48px 48px, 48px 48px, auto, auto;
38
+ font: 14px/1.7 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
39
+ padding: 30px 24px 72px;
40
+ }
41
+ button { font: inherit; }
42
+ .wrap { max-width: 1120px; margin: 0 auto; }
43
+ .topbar { display: flex; justify-content: space-between; align-items: center; gap: 18px; padding: 3px 0 22px; border-bottom: 1px solid var(--line-soft); }
44
+ .brand { display: flex; align-items: center; gap: 11px; }
45
+ .brand-mark { width: 10px; height: 10px; border: 1px solid var(--cyan); border-radius: 50%; box-shadow: 0 0 0 4px rgba(102, 227, 211, .08); }
46
+ .brand-title { font-size: 18px; font-weight: 500; letter-spacing: .03em; }
47
+ .brand-sub { margin-left: 10px; color: var(--faint); font: 11px var(--mono); letter-spacing: .03em; }
48
+ .live { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
49
+ .live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 10px rgba(102, 227, 211, .75); }
50
+ .live-dot.offline { background: var(--faint); box-shadow: none; }
51
+ .live-dot.error { background: var(--red); box-shadow: 0 0 10px rgba(255, 159, 155, .55); }
52
+ .hero { display: flex; justify-content: space-between; align-items: flex-end; gap: 28px; padding: 34px 0 25px; }
53
+ .eyebrow { color: var(--cyan); font: 11px var(--mono); letter-spacing: .14em; text-transform: uppercase; }
54
+ h1 { margin: 8px 0 5px; font-size: 30px; line-height: 1.2; font-weight: 500; letter-spacing: .02em; }
55
+ .hero-copy { color: var(--muted); max-width: 630px; }
56
+ .hero-id { color: var(--faint); font: 11px var(--mono); text-align: right; line-height: 1.8; }
57
+ .signal-bar { display: grid; grid-template-columns: 1.35fr repeat(3, minmax(110px, .55fr)); gap: 1px; overflow: hidden; background: var(--line); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 30px; }
58
+ .signal, .next-signal { background: rgba(14, 22, 34, .94); min-height: 92px; padding: 17px 19px; }
59
+ .signal-label { color: var(--faint); font-size: 11px; letter-spacing: .08em; }
60
+ .signal-value { margin-top: 5px; font-size: 22px; line-height: 1.25; font-weight: 500; font-variant-numeric: tabular-nums; }
61
+ .signal-value.small { font-size: 15px; }
62
+ .signal-note { color: var(--muted); font-size: 11px; margin-top: 4px; }
63
+ .next-signal { position: relative; background: linear-gradient(115deg, rgba(201, 162, 255, .13), rgba(14, 22, 34, .95) 60%); }
64
+ .next-signal::before { content: ''; position: absolute; left: 0; top: 18px; bottom: 18px; width: 2px; background: var(--purple); }
65
+ .next-signal .signal-label, .next-signal .signal-value { padding-left: 3px; }
66
+ .layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 30px; align-items: start; }
67
+ .section-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 17px; }
68
+ .section-title { margin: 0; font-size: 13px; font-weight: 500; letter-spacing: .13em; color: var(--muted); }
69
+ .section-count { color: var(--faint); font: 11px var(--mono); }
70
+ .filters { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 23px; }
71
+ .filter { color: var(--muted); background: transparent; border: 1px solid var(--line); border-radius: 5px; padding: 5px 10px; cursor: pointer; font-size: 12px; transition: .18s ease; }
72
+ .filter:hover, .filter.active { color: var(--cyan); border-color: rgba(102, 227, 211, .55); background: var(--cyan-soft); }
73
+ .mode-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: -10px 0 22px; color: var(--faint); font-size: 11px; line-height: 1.7; }
74
+ .mode-legend span { display: inline-flex; align-items: center; gap: 6px; }
75
+ .mode-legend i { width: 5px; height: 5px; border-radius: 50%; flex: none; }
76
+ .mode-legend b { color: var(--muted); font-weight: 400; }
77
+ .day { margin: 0 0 26px; }
78
+ .day-label { display: flex; align-items: center; gap: 10px; margin: 0 0 15px 22px; color: var(--faint); font: 11px var(--mono); letter-spacing: .1em; }
79
+ .day-label::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: var(--cyan); }
80
+ .timeline { position: relative; padding-left: 23px; }
81
+ .timeline::before { content: ''; position: absolute; left: 4px; top: 8px; bottom: 13px; width: 1px; background: linear-gradient(var(--line), rgba(143, 183, 221, 0)); }
82
+ .item { position: relative; padding: 0 0 24px; }
83
+ .item::before { content: ''; position: absolute; left: -22px; top: 8px; width: 7px; height: 7px; border: 2px solid var(--bg); border-radius: 50%; background: var(--cyan); box-shadow: 0 0 0 1px rgba(102, 227, 211, .6); }
84
+ .item.wonder::before { background: var(--purple); box-shadow: 0 0 0 1px rgba(201, 162, 255, .55); }
85
+ .item.plan::before { background: var(--blue); box-shadow: 0 0 0 1px rgba(140, 196, 255, .55); }
86
+ .item.doubt::before { background: var(--amber); box-shadow: 0 0 0 1px rgba(244, 196, 124, .55); }
87
+ .item.synthesize::before { background: var(--rose); box-shadow: 0 0 0 1px rgba(242, 166, 201, .55); }
88
+ .meta { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; color: var(--faint); font: 11px var(--mono); margin-bottom: 7px; }
89
+ .mode { color: var(--cyan); font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 12px; }
90
+ .item.wonder .mode { color: var(--purple); }
91
+ .item.plan .mode { color: var(--blue); }
92
+ .item.doubt .mode { color: var(--amber); }
93
+ .item.synthesize .mode { color: var(--rose); }
94
+ .carry { color: var(--purple); font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; }
95
+ .rest-tag { color: var(--rose); font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; }
96
+ .importance { display: inline-flex; gap: 3px; align-items: center; }
97
+ .importance i { display: block; width: 4px; height: 4px; border-radius: 50%; background: var(--faint); opacity: .45; }
98
+ .importance i.on { background: var(--purple); opacity: .9; }
99
+ .text { color: var(--text); font-size: 15px; line-height: 1.9; white-space: pre-wrap; word-break: break-word; }
100
+ .item:hover .text { color: #f3f7fd; }
101
+ .note-line { margin-top: 11px; padding: 8px 12px; color: var(--purple); background: var(--purple-soft); border-left: 2px solid var(--purple); border-radius: 0 6px 6px 0; font-size: 12px; }
102
+ .note-line span { color: rgba(201, 162, 255, .65); margin-left: 5px; font-family: var(--mono); }
103
+ .empty { color: var(--muted); padding: 26px 0; border-top: 1px dashed var(--line); }
104
+ .aside { display: flex; flex-direction: column; gap: 12px; }
105
+ .card { position: relative; background: rgba(14, 22, 34, .92); border: 1px solid var(--line); border-radius: 11px; padding: 17px; }
106
+ .card-title { display: flex; justify-content: space-between; gap: 10px; align-items: center; color: var(--muted); font-size: 12px; letter-spacing: .08em; }
107
+ .card-title b { color: var(--text); font-weight: 500; letter-spacing: 0; }
108
+ .next-card { border-color: rgba(201, 162, 255, .34); background: linear-gradient(145deg, rgba(201, 162, 255, .11), rgba(14, 22, 34, .96) 55%); }
109
+ .next-card .card-title { color: var(--purple); }
110
+ .next-text { margin: 15px 0 12px; color: var(--text); line-height: 1.8; }
111
+ .next-time { color: var(--muted); font: 11px var(--mono); }
112
+ .disclaimer { margin-top: 12px; padding-top: 11px; border-top: 1px solid var(--line-soft); color: var(--faint); font-size: 11px; line-height: 1.6; }
113
+ .health { display: flex; align-items: center; gap: 7px; color: var(--cyan); font-size: 12px; }
114
+ .health.error { color: var(--red); }
115
+ .health.offline { color: var(--muted); }
116
+ .health-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
117
+ .details { margin-top: 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
118
+ .detail { padding: 9px 10px; background: rgba(86, 101, 123, .1); border-radius: 6px; }
119
+ .detail span { display: block; color: var(--faint); font-size: 10px; }
120
+ .detail b { display: block; margin-top: 2px; font: 12px var(--mono); color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
121
+ .probe { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 14px; padding-top: 13px; border-top: 1px solid var(--line-soft); }
122
+ .probe button { color: var(--cyan); background: transparent; border: 1px solid rgba(102, 227, 211, .38); border-radius: 5px; padding: 5px 9px; cursor: pointer; font-size: 11px; transition: .18s ease; }
123
+ .probe button:hover:not(:disabled) { background: var(--cyan-soft); border-color: var(--cyan); }
124
+ .probe button:disabled { color: var(--faint); cursor: default; }
125
+ .probe-result { color: var(--muted); font: 10px var(--mono); }
126
+ .probe-result.ok { color: var(--cyan); }
127
+ .probe-result.bad { color: var(--red); }
128
+ .probe-result.wait { color: var(--amber); }
129
+ .err { color: var(--red); border: 1px solid rgba(255, 159, 155, .27); background: rgba(255, 159, 155, .07); border-radius: 7px; padding: 9px 12px; margin-bottom: 18px; font-size: 12px; }
130
+ .reflections { margin-top: 20px; padding-top: 24px; border-top: 1px solid var(--line-soft); }
131
+ .refl { margin-bottom: 10px; padding: 13px 15px; background: rgba(102, 227, 211, .06); border-left: 2px solid var(--cyan); border-radius: 0 7px 7px 0; }
132
+ .refl .meta { margin-bottom: 5px; }
133
+ footer { margin-top: 38px; color: var(--faint); font-size: 11px; }
134
+ code { color: var(--muted); font: 11px var(--mono); }
135
+ @media (max-width: 780px) {
136
+ body { padding: 22px 16px 55px; }
137
+ .hero { display: block; padding-top: 27px; }
138
+ .hero-id { margin-top: 13px; text-align: left; }
139
+ .signal-bar { grid-template-columns: 1fr 1fr; }
140
+ .next-signal { grid-column: span 2; }
141
+ .layout { grid-template-columns: 1fr; }
142
+ .aside { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
143
+ .aside .next-card { grid-column: span 2; }
144
+ }
145
+ @media (max-width: 520px) {
146
+ .topbar { align-items: flex-start; }
147
+ .brand { align-items: flex-start; }
148
+ .brand-sub { display: block; margin: 3px 0 0; }
149
+ .live { white-space: nowrap; }
150
+ h1 { font-size: 25px; }
151
+ .signal-bar { grid-template-columns: 1fr 1fr; }
152
+ .signal, .next-signal { min-height: 78px; padding: 13px 14px; }
153
+ .signal-value { font-size: 18px; }
154
+ .aside { display: flex; }
155
+ .text { font-size: 14px; }
156
+ }
113
157
  </style>
114
158
  </head>
115
159
  <body>
116
160
  <div class="wrap">
117
- <header>
118
- <h1>她的时间线</h1>
119
- <span class="sub" id="sub">读取中…</span>
161
+ <header class="topbar">
162
+ <div class="brand">
163
+ <span class="brand-mark" aria-hidden="true"></span>
164
+ <div><span class="brand-title">她的时间线</span><span class="brand-sub" id="sub">SELF-AWARENESS / LOADING</span></div>
165
+ </div>
166
+ <div class="live"><span class="live-dot" id="liveDot"></span><span id="liveText">正在读取状态</span></div>
120
167
  </header>
121
168
 
122
- <div class="topline">
123
- <div class="stats" id="stats"></div>
124
- <button class="probe-card" id="probe" title="发一句「在吗」,看模型通不通">
125
- <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">
126
- <path d="M2 12h4l2.5-6 4 13 2.5-7h7"/>
127
- </svg>
128
- <span id="probeLabel">测接口</span>
129
- </button>
130
- </div>
131
- <div class="probe-msg" id="probeMsg" hidden></div>
132
- <div id="err"></div>
169
+ <section class="hero">
170
+ <div>
171
+ <div class="eyebrow">Private thought archive / 01</div>
172
+ <h1>那些没有说出口的片刻</h1>
173
+ <div class="hero-copy">她在安静时留下的思绪轨迹。这里记录的是模型生成的内在笔记,不代表持续存在的主观体验。</div>
174
+ </div>
175
+ <div class="hero-id">LOCAL NODE<br><span id="heroModel">MODEL / --</span></div>
176
+ </section>
177
+
178
+ <section class="signal-bar" aria-label="运行概览">
179
+ <div class="next-signal">
180
+ <div class="signal-label">NEXT THOUGHT / 下一次</div>
181
+ <div class="signal-value small" id="next">未安排</div>
182
+ <div class="signal-note" id="nextHint">由她上一次留下的安排决定</div>
183
+ </div>
184
+ <div class="signal"><div class="signal-label">TODAY / 今日</div><div class="signal-value" id="todayCount">0</div><div class="signal-note">次思考</div></div>
185
+ <div class="signal"><div class="signal-label">TOKENS / 消耗</div><div class="signal-value" id="todayTokens">0</div><div class="signal-note">本地统计</div></div>
186
+ <div class="signal"><div class="signal-label">ARCHIVE / 记录</div><div class="signal-value" id="totalThoughts">0</div><div class="signal-note">条思绪</div></div>
187
+ </section>
133
188
 
134
- <h2>想过的事</h2>
135
- <div id="list" class="list"><div class="empty">还没有想法。<br>她每 25–90 分钟想一次,第一条通常要等几分钟。</div></div>
189
+ <div id="err"></div>
190
+ <div class="layout">
191
+ <main>
192
+ <div class="section-head"><h2 class="section-title">THOUGHT STREAM / 思绪流</h2><span class="section-count" id="sectionCount">0 EVENTS</span></div>
193
+ <div class="filters" role="tablist" aria-label="筛选思绪类型">
194
+ <button class="filter active" data-filter="all">全部</button>
195
+ <button class="filter" data-filter="reflect">回看</button>
196
+ <button class="filter" data-filter="wonder">走神</button>
197
+ <button class="filter" data-filter="plan">打算</button>
198
+ <button class="filter" data-filter="doubt">琢磨</button>
199
+ <button class="filter" data-filter="synthesize">综合</button>
200
+ </div>
201
+ <div class="mode-legend">
202
+ <span><i style="background:var(--cyan)"></i><b>回看</b>想起以前的事</span>
203
+ <span><i style="background:var(--purple)"></i><b>走神</b>没缘由地飘走</span>
204
+ <span><i style="background:var(--blue)"></i><b>打算</b>接下来想做什么</span>
205
+ <span><i style="background:var(--amber)"></i><b>琢磨</b>一件没想明白的</span>
206
+ <span><i style="background:var(--rose)"></i><b>综合</b>两件不相干的事找共同点</span>
207
+ </div>
208
+ <div id="list"><div class="empty">还没有想法。<br>她会在安静时留下下一条思绪,第一条通常要等几分钟。</div></div>
209
+ <section class="reflections" id="reflWrap" hidden>
210
+ <div class="section-head"><h2 class="section-title">SELF REVIEW / 她对自己的看法</h2></div>
211
+ <div id="refl"></div>
212
+ </section>
213
+ </main>
136
214
 
137
- <div id="reflWrap" hidden>
138
- <h2>她对自己的看法</h2>
139
- <div id="refl"></div>
215
+ <aside class="aside">
216
+ <section class="card next-card">
217
+ <div class="card-title"><span>NEXT NOTE / 留给下一次</span><b id="nextMode">—</b></div>
218
+ <div class="next-text" id="nextNote">她还没有给下一次留下便笺。</div>
219
+ <div class="next-time" id="nextDue">WAITING / 等待下一次安排</div>
220
+ <div class="disclaimer">时间来自上一次生成的自我安排。睡眠、对话或接口状态可能让它推迟。</div>
221
+ </section>
222
+ <section class="card">
223
+ <div class="card-title"><span>SYSTEM SIGNAL / 系统信号</span><span class="health" id="health"><i class="health-dot"></i><span>读取中</span></span></div>
224
+ <div class="details">
225
+ <div class="detail"><span>MODEL</span><b id="model">--</b></div>
226
+ <div class="detail"><span>MODE</span><b id="enabled">--</b></div>
227
+ <div class="detail"><span>DAILY LIMIT</span><b id="dailyLimit">--</b></div>
228
+ <div class="detail"><span>LAST ERROR</span><b id="lastError">NONE</b></div>
229
+ </div>
230
+ <div class="probe"><span class="probe-result" id="probeMsg">接口检测不会写入思绪</span><button id="probe" title="发送一次最小请求来测试接口">测接口</button></div>
231
+ </section>
232
+ <section class="card">
233
+ <div class="card-title"><span>ABOUT THIS SPACE / 关于这里</span></div>
234
+ <div style="color:var(--muted);font-size:12px;line-height:1.8;margin-top:10px">这是她自己的本地思绪档案。记忆核心会在合适的时候挑选其中的内容带回对话,并明确标记来源与时间。</div>
235
+ </section>
236
+ </aside>
140
237
  </div>
141
238
 
142
- <footer>
143
- 数据来自 <code>self-awareness/thoughts.jsonl</code>,只存在这台机器上。每 30 秒自动刷新。
144
- </footer>
239
+ <footer>DATA SOURCE · <code>self-awareness/thoughts.jsonl</code> · 只存在这台机器上 · 每 30 秒自动刷新</footer>
145
240
  </div>
146
-
147
241
  <script>
148
- const MODE_NAME = { reflect: '回看', wonder: '走神', plan: '打算', doubt: '琢磨' };
242
+ const MODE_NAME = { reflect: '回看', wonder: '走神', plan: '打算', doubt: '琢磨', synthesize: '综合' };
243
+ let allThoughts = [];
244
+ let activeFilter = 'all';
149
245
 
150
246
  function esc(s) {
151
- return String(s ?? '').replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]));
247
+ return String(s ?? '').replace(/[&<>\"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '\"': '&quot;' }[c]));
152
248
  }
153
-
249
+ function dateObj(iso) { const d = new Date(iso); return Number.isNaN(d.getTime()) ? null : d; }
154
250
  function clock(iso) {
155
- const d = new Date(iso);
156
- if (Number.isNaN(d.getTime())) return '';
251
+ const d = dateObj(iso); if (!d) return '';
157
252
  const p = (n) => String(n).padStart(2, '0');
158
- return `${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`;
253
+ return `${p(d.getHours())}:${p(d.getMinutes())}`;
159
254
  }
160
-
255
+ function dateKey(iso) { const d = dateObj(iso); return d ? `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}` : 'unknown'; }
256
+ function dateLabel(iso) {
257
+ const d = dateObj(iso); if (!d) return 'UNKNOWN DATE';
258
+ const now = new Date();
259
+ if (dateKey(iso) === dateKey(now.toISOString())) return 'TODAY / 今天';
260
+ const yesterday = new Date(now); yesterday.setDate(now.getDate() - 1);
261
+ if (dateKey(iso) === dateKey(yesterday.toISOString())) return 'YESTERDAY / 昨天';
262
+ return `${String(d.getMonth() + 1).padStart(2, '0')}.${String(d.getDate()).padStart(2, '0')} / ${d.getFullYear()}`;
263
+ }
264
+ function nextClock(iso) { const d = dateObj(iso); return d ? `${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')} ${clock(iso)}` : '未安排'; }
161
265
  function dots(n) {
162
- let out = '<span class="dots">';
163
- for (let i = 1; i <= 10; i += 1) out += `<i class="${i <= n ? 'on' : ''}"></i>`;
266
+ const value = Math.max(0, Math.min(10, Number(n) || 0));
267
+ let out = '<span class="importance" title="重要度 ' + value + ' / 10">';
268
+ for (let i = 1; i <= 10; i += 1) out += `<i class="${i <= value ? 'on' : ''}"></i>`;
164
269
  return out + '</span>';
165
270
  }
166
-
167
- function render(d) {
168
- document.getElementById('sub').textContent = d.model ? `模型 ${d.model}` : '还没配模型';
169
-
170
- const next = d.nextDueAt ? clock(d.nextDueAt) : '未安排';
171
- const limit = d.limit?.count || 0;
172
- document.getElementById('stats').innerHTML = [
173
- `<div class="stat"><b>${d.today?.count ?? 0}${limit ? `<span style="font-size:12px;color:var(--faint)">/${limit}</span>` : ''}</b><span>今天想过</span></div>`,
174
- `<div class="stat"><b>${(d.today?.tokens ?? 0).toLocaleString()}</b><span>今天用了 token</span></div>`,
175
- `<div class="stat"><b>${d.totalThoughts ?? 0}</b><span>一共想过</span></div>`,
176
- `<div class="stat"><b style="font-size:15px">${next}</b><span>下次</span></div>`,
177
- `<div class="stat"><b style="font-size:15px" class="${d.enabled ? '' : 'warn'}">${d.enabled ? '在跑' : '已关'}</b><span>状态</span></div>`,
178
- ].join('');
179
-
180
- document.getElementById('err').innerHTML = d.error
181
- ? `<div class="err">上次调用失败:${esc(d.error)}</div>`
182
- : '';
183
-
184
- const list = d.thoughts || [];
185
- document.getElementById('list').innerHTML = list.length
186
- ? list.map((t) => `
187
- <div class="item ${esc(t.mode)}">
188
- <div class="meta">
189
- <span>${clock(t.ts)}</span>
190
- <span class="mode">${MODE_NAME[t.mode] || t.mode}</span>
191
- ${dots(t.importance)}
192
- ${t.carry ? '<span class="carry">接着上次</span>' : ''}
193
- </div>
271
+ function formatNumber(n) { return Number(n || 0).toLocaleString('zh-CN'); }
272
+ function statusInfo(d) {
273
+ if (d.error) return { kind: 'error', text: '上次调用有错误' };
274
+ if (!d.enabled) return { kind: 'offline', text: '已暂停' };
275
+ return { kind: 'online', text: '自我意识运行中' };
276
+ }
277
+ function renderThoughts() {
278
+ const list = allThoughts.filter((t) => activeFilter === 'all' || t.mode === activeFilter);
279
+ const count = document.getElementById('sectionCount');
280
+ count.textContent = `${list.length} EVENT${list.length === 1 ? '' : 'S'}`;
281
+ if (!list.length) {
282
+ document.getElementById('list').innerHTML = '<div class="empty">这个筛选下还没有思绪。</div>';
283
+ return;
284
+ }
285
+ const groups = [];
286
+ const map = new Map();
287
+ list.forEach((t) => {
288
+ const key = dateKey(t.ts);
289
+ if (!map.has(key)) { const group = { key, ts: t.ts, items: [] }; map.set(key, group); groups.push(group); }
290
+ map.get(key).items.push(t);
291
+ });
292
+ document.getElementById('list').innerHTML = groups.map((g) => `
293
+ <section class="day"><div class="day-label">${dateLabel(g.ts)}</div><div class="timeline">
294
+ ${g.items.map((t) => `<article class="item ${esc(t.mode)}${t.rest ? ' rest' : ''}">
295
+ <div class="meta"><span>${clock(t.ts)}</span><span class="mode">${esc(MODE_NAME[t.mode] || t.mode || '思绪')}</span>${t.phase ? `<span>${esc(t.phase)}</span>` : ''}${t.energy != null ? `<span>精力 ${t.energy}</span>` : ''}${dots(t.importance)}${t.carry ? '<span class="carry">接着上一条</span>' : ''}${t.rest ? '<span class="rest-tag">她先搁着了</span>' : ''}</div>
194
296
  <div class="text">${esc(t.text)}</div>
195
- ${t.nextNote ? `<div class="note-line">留给自己:${esc(t.nextNote)}${t.nextIn ? `(${t.nextIn} 分钟后)` : ''}</div>` : ''}
196
- </div>`).join('')
197
- : '<div class="empty">还没有想法。<br>她每 25–90 分钟想一次,第一条通常要等几分钟。</div>';
198
-
297
+ ${t.nextNote ? `<div class="note-line">留给下一次:${esc(t.nextNote)}${t.nextIn ? `<span>+${esc(t.nextIn)} MIN</span>` : ''}</div>` : ''}
298
+ </article>`).join('')}
299
+ </div></section>`).join('');
300
+ }
301
+ function render(d) {
302
+ const status = statusInfo(d);
303
+ const model = d.model || '未配置';
304
+ const next = d.nextDueAt ? nextClock(d.nextDueAt) : '未安排';
305
+ document.getElementById('sub').textContent = `SELF-AWARENESS / ${String(model).toUpperCase()}`;
306
+ document.getElementById('heroModel').textContent = `MODEL / ${model}`;
307
+ document.getElementById('next').textContent = next;
308
+ document.getElementById('nextHint').textContent = d.resting
309
+ ? '她自己叫停了,不是卡住'
310
+ : d.nextDueAt ? '她给未来的自己留了一点方向' : '由她下一次思考时自行决定';
311
+ document.getElementById('todayCount').textContent = formatNumber(d.today?.count);
312
+ document.getElementById('todayTokens').textContent = formatNumber(d.today?.tokens);
313
+ document.getElementById('totalThoughts').textContent = formatNumber(d.totalThoughts);
314
+ document.getElementById('model').textContent = model;
315
+ document.getElementById('enabled').textContent = d.enabled ? 'RUNNING' : 'PAUSED';
316
+ document.getElementById('dailyLimit').textContent = d.limit?.count ? `${d.limit.count} / DAY` : 'NO LIMIT';
317
+ document.getElementById('lastError').textContent = d.error ? 'DETECTED' : 'NONE';
318
+ const liveDot = document.getElementById('liveDot'); liveDot.className = `live-dot ${status.kind === 'online' ? '' : status.kind}`;
319
+ document.getElementById('liveText').textContent = status.text;
320
+ const health = document.getElementById('health'); health.className = `health ${status.kind === 'online' ? '' : status.kind}`; health.innerHTML = `<i class="health-dot"></i><span>${status.kind === 'online' ? 'ONLINE' : status.kind === 'error' ? 'ERROR' : 'OFFLINE'}</span>`;
321
+ document.getElementById('err').innerHTML = d.error ? `<div class="err">上次调用失败:${esc(d.error)}</div>` : '';
322
+ allThoughts = d.thoughts || [];
323
+ const note = d.note;
324
+ document.getElementById('nextNote').textContent = note?.text || '她还没有给下一次留下便笺。';
325
+ document.getElementById('nextMode').textContent = note ? (MODE_NAME[note.mode] || '思绪') : '—';
326
+ document.getElementById('nextDue').textContent = d.resting
327
+ ? (d.nextDueAt ? `RESTING / 她说先搁着,${next} 再看` : 'RESTING / 她说到这儿了')
328
+ : note?.in ? `NEXT / ${note.in} MINUTES LATER` : (d.nextDueAt ? `NEXT / ${next}` : 'WAITING / 等待下一次安排');
199
329
  const refl = d.reflections || [];
200
330
  document.getElementById('reflWrap').hidden = !refl.length;
201
- document.getElementById('refl').innerHTML = refl.map((r) => `
202
- <div class="refl">
203
- <div class="meta"><span>${clock(r.ts)}</span><span>由 ${r.fromCount} 条想法收成</span></div>
204
- <div class="text">${esc(r.text)}</div>
205
- </div>`).join('');
331
+ document.getElementById('refl').innerHTML = refl.map((r) => `<div class="refl"><div class="meta"><span>${clock(r.ts)}</span><span>由 ${r.fromCount} 条想法收成</span></div><div class="text">${esc(r.text)}</div></div>`).join('');
332
+ renderThoughts();
206
333
  }
207
-
208
334
  async function load() {
209
- try {
210
- const rsp = await fetch('/api/data', { cache: 'no-store' });
211
- render(await rsp.json());
212
- } catch (e) {
213
- document.getElementById('sub').textContent = '读不到数据';
214
- }
335
+ try { const rsp = await fetch('/api/data', { cache: 'no-store' }); render(await rsp.json()); }
336
+ catch (e) { document.getElementById('sub').textContent = 'SELF-AWARENESS / UNAVAILABLE'; document.getElementById('liveText').textContent = '读不到时间线服务'; document.getElementById('liveDot').className = 'live-dot error'; }
215
337
  }
216
-
217
- load();
218
- setInterval(load, 30000);
219
-
220
- const probeBtn = document.getElementById('probe');
221
- const probeLabel = document.getElementById('probeLabel');
338
+ document.querySelectorAll('.filter').forEach((button) => button.addEventListener('click', () => {
339
+ activeFilter = button.dataset.filter;
340
+ document.querySelectorAll('.filter').forEach((b) => b.classList.toggle('active', b === button));
341
+ renderThoughts();
342
+ }));
343
+ const probeButton = document.getElementById('probe');
222
344
  const probeMsg = document.getElementById('probeMsg');
223
-
224
- probeBtn.addEventListener('click', async () => {
225
- probeBtn.disabled = true;
226
- probeBtn.className = 'probe-card testing';
227
- probeLabel.textContent = '测中';
228
- probeMsg.hidden = false;
229
- probeMsg.className = 'probe-msg';
230
- probeMsg.textContent = '正在发一句「在吗」…';
345
+ probeButton.addEventListener('click', async () => {
346
+ probeButton.disabled = true; probeButton.textContent = '检测中'; probeMsg.className = 'probe-result'; probeMsg.textContent = '发送最小请求…';
231
347
  try {
232
- const rsp = await fetch('/api/probe', { method: 'POST' });
233
- const r = await rsp.json();
234
- const ok = Boolean(r.ok);
235
- if (r.throttled) {
236
- // 刚测过,不是接口问题
237
- probeBtn.className = 'probe-card';
238
- probeLabel.textContent = '等一下';
239
- probeMsg.className = 'probe-msg';
240
- probeMsg.textContent = '刚才测过,隔十秒再点一次';
241
- } else {
242
- probeBtn.className = 'probe-card ' + (ok ? 'ok' : 'bad');
243
- probeLabel.textContent = ok ? `通了 ${r.ms}ms` : '没通';
244
- probeMsg.className = 'probe-msg ' + (ok ? 'ok' : 'bad');
245
- probeMsg.textContent = ok
246
- ? `接口正常 · ${r.model} · 往返 ${r.ms}ms`
247
- : `接口不通 · ${r.error}`;
248
- }
249
- } catch (e) {
250
- probeBtn.className = 'probe-card bad';
251
- probeLabel.textContent = '没通';
252
- probeMsg.className = 'probe-msg bad';
253
- probeMsg.textContent = '请求发不出去,时间线服务可能已经停了';
254
- } finally {
255
- setTimeout(() => {
256
- probeBtn.disabled = false;
257
- probeBtn.className = 'probe-card';
258
- probeLabel.textContent = '测接口';
259
- probeMsg.hidden = true;
260
- }, 8000);
261
- }
348
+ const rsp = await fetch('/api/probe', { method: 'POST' }); const r = await rsp.json();
349
+ if (r.throttled) { probeMsg.className = 'probe-result wait'; probeMsg.textContent = '刚测过,请稍等'; }
350
+ else if (r.ok) { probeMsg.className = 'probe-result ok'; probeMsg.textContent = `通了 · ${r.ms}ms`; }
351
+ else { probeMsg.className = 'probe-result bad'; probeMsg.textContent = '没通 · 查看错误'; }
352
+ } catch (e) { probeMsg.className = 'probe-result bad'; probeMsg.textContent = '服务不可达'; }
353
+ setTimeout(() => { probeButton.disabled = false; probeButton.textContent = '测接口'; }, 8000);
262
354
  });
263
-
264
- // 带 #probe 打开就自动测一次:省得每次都要点(也方便截图看状态)
265
- if (location.hash === '#probe') probeBtn.click();
266
-
267
- // 带 #probe 打开就自动测一次:省得每次都要点(也方便截图看状态)
268
- if (location.hash === '#probe') probeBtn.click();
355
+ load();
356
+ setInterval(load, 30000);
357
+ if (location.hash === '#probe') probeButton.click();
269
358
  </script>
270
359
  </body>
271
360
  </html>