cortico-world-memory-core 0.24.0 → 0.26.1
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 +46 -0
- package/ENV_PROMPT.md +2 -2
- package/package.json +2 -2
- package/src/config.ts +63 -4
- package/src/definition.ts +54 -53
- package/src/recall.ts +114 -8
- package/src/site.ts +435 -435
- package/src/store.ts +11 -0
- package/src/tools.ts +22 -2
- package/src/world.ts +206 -11
- package/webui/app.js +7 -1
- package/webui/next.css +21 -13
package/src/store.ts
CHANGED
|
@@ -28,6 +28,8 @@ export interface Card {
|
|
|
28
28
|
dueAt?: string;
|
|
29
29
|
done?: boolean;
|
|
30
30
|
remindedAt?: string;
|
|
31
|
+
/** 已经主动提醒过几次(到 remindMaxTimes 就停,只留体检页)。 */
|
|
32
|
+
remindCount?: number;
|
|
31
33
|
/** 缺省视为 active:老数据没有这个字段,读的时候补上。 */
|
|
32
34
|
status?: CardStatus;
|
|
33
35
|
retiredAt?: string;
|
|
@@ -91,6 +93,11 @@ export interface CoreState {
|
|
|
91
93
|
lastSelfThoughtId?: string;
|
|
92
94
|
/** 自我意识写下的「想说话」已经用来开过口了,别重复。 */
|
|
93
95
|
lastUrgeId?: string;
|
|
96
|
+
/** 任意一条承诺的最近提醒时间:用来控制两条之间的最小间隔。 */
|
|
97
|
+
lastRemindAt?: string;
|
|
98
|
+
/** 承诺提醒的每日计数(跨天清零)。 */
|
|
99
|
+
remindDay?: string;
|
|
100
|
+
remindCountToday?: number;
|
|
94
101
|
/** 已经收成卡片的想法 id(只留最近 100 个,够防重复了)。 */
|
|
95
102
|
absorbedThoughtIds?: string[];
|
|
96
103
|
rawWatermark?: number;
|
|
@@ -196,6 +203,9 @@ export function demoteTech(kind: CardKind, text: string): CardKind {
|
|
|
196
203
|
}
|
|
197
204
|
|
|
198
205
|
export class CardStore {
|
|
206
|
+
/** 每次落盘 +1。召回索引缓存用它判断「库变没变」,比逐张比对便宜。 */
|
|
207
|
+
revision = 0;
|
|
208
|
+
|
|
199
209
|
private cards: Card[] = [];
|
|
200
210
|
private readonly file: string;
|
|
201
211
|
private readonly backupDir: string;
|
|
@@ -777,6 +787,7 @@ export class CardStore {
|
|
|
777
787
|
}
|
|
778
788
|
|
|
779
789
|
save(force = false): void {
|
|
790
|
+
this.revision += 1;
|
|
780
791
|
if (!this.dirty && !force) return;
|
|
781
792
|
this.dirty = false;
|
|
782
793
|
this.backupOnceADay();
|
package/src/tools.ts
CHANGED
|
@@ -20,7 +20,9 @@ export const TOOL_SPECS: ToolSpec[] = [
|
|
|
20
20
|
'写一条记忆。kind:fact=关于对方的事实,self=关于你自己的,'
|
|
21
21
|
+ 'episode=你自己经历过的(有画面有情绪的事,一天 3-5 条正常),'
|
|
22
22
|
+ 'promise=答应过的事(必须写 dueAt),note=临时信息和技术操作。'
|
|
23
|
-
+ '一条只写一件事,40-80 字。旧记录用 closes 关掉。'
|
|
23
|
+
+ '一条只写一件事,40-80 字。旧记录用 closes 关掉。'
|
|
24
|
+
+ '对方明确说「记一下 / 记住 / 别忘了」时必须调用,按语义选 kind;'
|
|
25
|
+
+ '编号只在对方问起时给。',
|
|
24
26
|
parameters: obj(
|
|
25
27
|
{
|
|
26
28
|
kind: {
|
|
@@ -30,7 +32,7 @@ export const TOOL_SPECS: ToolSpec[] = [
|
|
|
30
32
|
},
|
|
31
33
|
text: { type: 'string', description: '内容,40-80 字' },
|
|
32
34
|
weight: { type: 'number', description: '0-1,0.3 琐事 / 0.8 重要' },
|
|
33
|
-
tags: { type: 'array', items: { type: 'string' }
|
|
35
|
+
tags: { type: 'array', items: { type: 'string' } },
|
|
34
36
|
dueAt: { type: 'string', description: 'promise 用:ISO 或 YYYY-MM-DD HH:MM;没有截止时间写 none' },
|
|
35
37
|
closes: { type: 'string', description: '要关掉的旧 id' },
|
|
36
38
|
},
|
|
@@ -38,6 +40,24 @@ export const TOOL_SPECS: ToolSpec[] = [
|
|
|
38
40
|
),
|
|
39
41
|
tags: ['write'],
|
|
40
42
|
},
|
|
43
|
+
{
|
|
44
|
+
name: 'mcore_update',
|
|
45
|
+
description:
|
|
46
|
+
'改一条已有记忆(行首 8 位)。改正文走改口:新卡接替、旧卡留档;其余字段原地改。',
|
|
47
|
+
parameters: obj(
|
|
48
|
+
{
|
|
49
|
+
id: { type: 'string', description: '行首 8 位即可' },
|
|
50
|
+
text: { type: 'string', description: '新正文;不改不传' },
|
|
51
|
+
kind: { type: 'string', enum: ['fact', 'self', 'episode', 'promise', 'note'] },
|
|
52
|
+
weight: { type: 'number' },
|
|
53
|
+
tags: { type: 'array', items: { type: 'string' } },
|
|
54
|
+
dueAt: { type: 'string', description: 'promise 用;none 清空' },
|
|
55
|
+
done: { type: 'boolean', description: '做完' },
|
|
56
|
+
},
|
|
57
|
+
['id'],
|
|
58
|
+
),
|
|
59
|
+
tags: ['write'],
|
|
60
|
+
},
|
|
41
61
|
{
|
|
42
62
|
name: 'mcore_recall',
|
|
43
63
|
description:
|
package/src/world.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* 2) 不每轮推送状态,只有 contextEveryMin>0 才推,默认 0;
|
|
8
8
|
* 3) 主动开口有「对方最近说过话」这道闸,避免对着空房间调用模型。
|
|
9
9
|
*/
|
|
10
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
10
|
+
import { appendFileSync, existsSync, readFileSync } from 'node:fs';
|
|
11
11
|
import { fileURLToPath } from 'node:url';
|
|
12
12
|
import { join } from 'node:path';
|
|
13
13
|
import { randomUUID } from 'node:crypto';
|
|
@@ -657,6 +657,18 @@ export class MemoryCoreWorld implements World {
|
|
|
657
657
|
overdue: open.filter((c) => c.dueAt && Date.parse(c.dueAt) <= now).length,
|
|
658
658
|
noDue: open.filter((c) => !c.dueAt).length,
|
|
659
659
|
repeating: this.promiseRepeat(),
|
|
660
|
+
repeatMin: Math.max(1, Number(this.cfg().remindRepeatMin) || 180),
|
|
661
|
+
dueList: open
|
|
662
|
+
.filter((c) => c.dueAt && Date.parse(c.dueAt) <= now)
|
|
663
|
+
.sort((a, b) => Date.parse(a.dueAt ?? '') - Date.parse(b.dueAt ?? ''))
|
|
664
|
+
.slice(0, 5)
|
|
665
|
+
.map((c) => ({
|
|
666
|
+
id: c.id.slice(0, 8),
|
|
667
|
+
text: clip(c.text, 60),
|
|
668
|
+
dueAt: c.dueAt ?? '',
|
|
669
|
+
lateMin: Math.max(0, Math.round((now - Date.parse(c.dueAt ?? '')) / 60_000)),
|
|
670
|
+
remindCount: Number(c.remindCount) || 0,
|
|
671
|
+
})),
|
|
660
672
|
},
|
|
661
673
|
raw: { lines: this.raw.size, archivedDays: rawStats.days, archivedLines: this.raw.archiveLines() },
|
|
662
674
|
backup: this.store.backupInfo(),
|
|
@@ -767,15 +779,94 @@ export class MemoryCoreWorld implements World {
|
|
|
767
779
|
private async dispatch(name: string, args: Record<string, unknown>): Promise<string> {
|
|
768
780
|
try {
|
|
769
781
|
if (name === 'mcore_write') return this.handleWrite(args);
|
|
782
|
+
if (name === 'mcore_update') return this.handleUpdate(args);
|
|
770
783
|
if (name === 'mcore_recall') return this.handleRecall(args);
|
|
771
784
|
if (name === 'mcore_state') return this.handleState(args);
|
|
772
785
|
if (name === 'mcore_plan') return this.handlePlan(args);
|
|
773
786
|
return `未知工具:${name}`;
|
|
774
787
|
} catch (error) {
|
|
775
|
-
|
|
788
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
789
|
+
try {
|
|
790
|
+
this.host?.log?.warn?.('[memory-core] 工具失败', { tool: name, error: msg });
|
|
791
|
+
} catch {
|
|
792
|
+
// ignore
|
|
793
|
+
}
|
|
794
|
+
return `执行失败:${msg}`;
|
|
776
795
|
}
|
|
777
796
|
}
|
|
778
797
|
|
|
798
|
+
private handleUpdate(args: Record<string, unknown>): string {
|
|
799
|
+
if (!this.cfg().memoryEnabled) return '记忆已关闭(设置页里可以打开)。';
|
|
800
|
+
const id = str(args.id, 60).trim();
|
|
801
|
+
if (!id) return 'id 不能为空(传行首 8 位就够)。';
|
|
802
|
+
const card = this.findCard(id);
|
|
803
|
+
if (!card) return `找不到这条记忆:${id}`;
|
|
804
|
+
if (card.status === 'retired') return '这条已经退休(或被新卡替代)了,改它不会生效;要恢复请先在界面上恢复。';
|
|
805
|
+
|
|
806
|
+
const has = (k: string) => Object.prototype.hasOwnProperty.call(args, k);
|
|
807
|
+
const text = has('text') ? str(args.text, 500).trim() : undefined;
|
|
808
|
+
const kindRaw = has('kind') ? String(args.kind ?? '') : '';
|
|
809
|
+
if (kindRaw && !CARD_KINDS.includes(kindRaw as CardKind)) {
|
|
810
|
+
return 'kind 只能是 fact / self / episode / promise / note。';
|
|
811
|
+
}
|
|
812
|
+
const kind = (kindRaw || card.kind) as CardKind;
|
|
813
|
+
const weight = has('weight') ? num(args.weight, card.weight, 0, 1) : card.weight;
|
|
814
|
+
const tags = has('tags')
|
|
815
|
+
? (Array.isArray(args.tags) ? (args.tags as unknown[]).map((t) => String(t).slice(0, 20)).filter(Boolean).slice(0, 8) : [])
|
|
816
|
+
: card.tags;
|
|
817
|
+
const dueProvided = has('dueAt');
|
|
818
|
+
const dueRaw = dueProvided ? str(args.dueAt, 40).trim() : '';
|
|
819
|
+
const undated = /^(none|null|无|没有|无截止)$/i.test(dueRaw);
|
|
820
|
+
const dueAt = dueProvided ? (undated || !dueRaw ? undefined : dueRaw.replace(' ', 'T')) : card.dueAt;
|
|
821
|
+
if (kind === 'promise' && !dueAt) {
|
|
822
|
+
return '承诺要有截止时间。不知道具体时间就问一句;确实没有就传 dueAt:"none"。';
|
|
823
|
+
}
|
|
824
|
+
const doneProvided = typeof args.done === 'boolean';
|
|
825
|
+
const done = doneProvided ? Boolean(args.done) : card.done;
|
|
826
|
+
|
|
827
|
+
// 正文变了:写新卡接替,旧卡留档(不抹掉「当时是怎么记的」)
|
|
828
|
+
if (text && text !== card.text) {
|
|
829
|
+
const res = this.store.add({
|
|
830
|
+
kind,
|
|
831
|
+
text,
|
|
832
|
+
weight,
|
|
833
|
+
tags: [...tags],
|
|
834
|
+
dueAt,
|
|
835
|
+
source: 'tool',
|
|
836
|
+
origin: 'tool',
|
|
837
|
+
...(card.src ? { src: card.src } : {}),
|
|
838
|
+
});
|
|
839
|
+
if (card.kind === 'promise') this.store.close(card.id);
|
|
840
|
+
this.store.supersede(card.id, res.card);
|
|
841
|
+
try {
|
|
842
|
+
this.host?.log?.info?.('[memory-core] 改口', { from: card.id.slice(0, 8), to: res.card.id.slice(0, 8) });
|
|
843
|
+
} catch {
|
|
844
|
+
// ignore
|
|
845
|
+
}
|
|
846
|
+
return `已改口:${card.id.slice(0, 8)} → ${res.card.id.slice(0, 8)}。旧的那条留在库里可回溯。`;
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
const patch: Partial<typeof card> = {};
|
|
850
|
+
if (kind !== card.kind) patch.kind = kind;
|
|
851
|
+
if (weight !== card.weight) patch.weight = weight;
|
|
852
|
+
if (has('tags')) patch.tags = [...tags];
|
|
853
|
+
if (dueProvided) patch.dueAt = dueAt;
|
|
854
|
+
if (doneProvided) patch.done = done;
|
|
855
|
+
// 截止时间或完成状态变了:提醒重新计数,别拿旧的「已提醒 6 次」把它压死
|
|
856
|
+
if (dueProvided || doneProvided) {
|
|
857
|
+
patch.remindedAt = undefined;
|
|
858
|
+
patch.remindCount = 0;
|
|
859
|
+
}
|
|
860
|
+
if (!Object.keys(patch).length) return '没有要改的字段(正文相同、元数据也没变)。';
|
|
861
|
+
this.store.update(card.id, patch);
|
|
862
|
+
try {
|
|
863
|
+
this.host?.log?.info?.('[memory-core] 改', { id: card.id.slice(0, 8), fields: Object.keys(patch) });
|
|
864
|
+
} catch {
|
|
865
|
+
// ignore
|
|
866
|
+
}
|
|
867
|
+
return `已改:${card.id.slice(0, 8)}…(${Object.keys(patch).filter((k) => k !== 'remindedAt' && k !== 'remindCount').join('、') || '提醒状态'})`;
|
|
868
|
+
}
|
|
869
|
+
|
|
779
870
|
private handleWrite(args: Record<string, unknown>): string {
|
|
780
871
|
if (!this.cfg().memoryEnabled) return '记忆已关闭(设置页里可以打开)。';
|
|
781
872
|
const kind = String(args.kind ?? '') as CardKind;
|
|
@@ -833,7 +924,18 @@ export class MemoryCoreWorld implements World {
|
|
|
833
924
|
pile = `\n(提醒:「${top.word}」这个话题已经有 ${top.count} 条了。同一次事别再记一遍——真要合并就写一条新的、用 closes 把旧的收起来;如果它其实是条长期规矩,写成 fact。)`;
|
|
834
925
|
}
|
|
835
926
|
}
|
|
836
|
-
|
|
927
|
+
try {
|
|
928
|
+
this.host?.log?.info?.('[memory-core] 写入', {
|
|
929
|
+
id: res.card.id.slice(0, 8),
|
|
930
|
+
kind,
|
|
931
|
+
chars: text.length,
|
|
932
|
+
merged: res.merged,
|
|
933
|
+
...(closes ? { closes } : {}),
|
|
934
|
+
});
|
|
935
|
+
} catch {
|
|
936
|
+
// 日志失败不影响写入
|
|
937
|
+
}
|
|
938
|
+
return `已记下(${kind}${res.merged ? ',与已有记录合并' : ''} · ${res.card.id.slice(0, 8)})${extra}。共 ${this.store.stats().total} 条。${pile}`;
|
|
837
939
|
}
|
|
838
940
|
|
|
839
941
|
/**
|
|
@@ -876,6 +978,25 @@ export class MemoryCoreWorld implements World {
|
|
|
876
978
|
return this.store.find(prefix) ?? this.store.all().find((c) => c.id.startsWith(prefix)) ?? undefined;
|
|
877
979
|
}
|
|
878
980
|
|
|
981
|
+
private missNote = { q: '', at: 0 };
|
|
982
|
+
|
|
983
|
+
/** 搜不到时记一笔,之后按真实缺口补同义词,不靠拍脑袋。 */
|
|
984
|
+
private logMiss(query: string, kind?: string): void {
|
|
985
|
+
const q = query.trim().slice(0, 80);
|
|
986
|
+
if (!q) return;
|
|
987
|
+
if (this.missNote.q === q && Date.now() - this.missNote.at < 10 * 60_000) return;
|
|
988
|
+
this.missNote = { q, at: Date.now() };
|
|
989
|
+
try {
|
|
990
|
+
appendFileSync(
|
|
991
|
+
join(this.dataDir, 'misses.jsonl'),
|
|
992
|
+
`${JSON.stringify({ ts: new Date().toISOString(), query: q, kind: kind ?? null })}\n`,
|
|
993
|
+
'utf8',
|
|
994
|
+
);
|
|
995
|
+
} catch {
|
|
996
|
+
// 记不上不影响召回
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
|
|
879
1000
|
private handleRecall(args: Record<string, unknown>): string {
|
|
880
1001
|
if (!this.cfg().memoryEnabled) return '记忆已关闭(设置页里可以打开)。';
|
|
881
1002
|
const idArg = str(args.id, 60);
|
|
@@ -927,6 +1048,8 @@ export class MemoryCoreWorld implements World {
|
|
|
927
1048
|
days: num(args.days, 0, 0, 3650) || undefined,
|
|
928
1049
|
limit,
|
|
929
1050
|
useAging: this.cfg().recallUseAging !== false,
|
|
1051
|
+
synonyms: this.cfg().synonyms,
|
|
1052
|
+
cacheKey: String(this.store.revision),
|
|
930
1053
|
});
|
|
931
1054
|
const cards = ranked.map((x) => x.card);
|
|
932
1055
|
const strongIds = new Set(ranked.filter((x) => x.tier === 'strong').map((x) => x.card.id));
|
|
@@ -952,15 +1075,24 @@ export class MemoryCoreWorld implements World {
|
|
|
952
1075
|
if (withSrc.length) push('(↩ 是写它时最近的那句原话;卡片本身是改写的)');
|
|
953
1076
|
if (cards.some((c) => c.coldAt)) push('(❄ 是很久没被想起的旧记忆,仅供参考)');
|
|
954
1077
|
|
|
1078
|
+
const hitMap = new Map(ranked.map((x) => [x.card.id, x.matched]));
|
|
955
1079
|
const cardLine = (card: (typeof cards)[number]) => {
|
|
956
1080
|
const tag = card.kind === 'fact' ? '' : `(${card.kind})`;
|
|
957
1081
|
const when = card.src ? formatLocal(card.src.ts, tz).slice(5, 10) : '';
|
|
958
1082
|
const mark = when ? ` ↩${when}` : '';
|
|
959
1083
|
const cold = card.coldAt ? '❄' : '';
|
|
1084
|
+
// 解释一下为什么它被召回:模型能判断是字面对上,还是同义词补进来的
|
|
1085
|
+
const hit = mode === 'search' ? hitMap.get(card.id) ?? [] : [];
|
|
1086
|
+
const why = hit.length ? ` 〔${hit.join('+')}〕` : '';
|
|
960
1087
|
// 行首这 8 位就是 id:改口/作废时要用它传给 mcore_write 的 closes
|
|
961
|
-
return `· ${card.id.slice(0, 8)} ${cold}${formatLocal(card.createdAt, tz).slice(5)} ${clip(card.text, 110)}${tag}${mark}`;
|
|
1088
|
+
return `· ${card.id.slice(0, 8)} ${cold}${formatLocal(card.createdAt, tz).slice(5)} ${clip(card.text, 110)}${tag}${mark}${why}`;
|
|
962
1089
|
};
|
|
963
1090
|
|
|
1091
|
+
// 漏检记录:本地留一份,用来补同义词表;同一条查询 10 分钟内只记一次
|
|
1092
|
+
if (mode === 'search' && query && !ranked.some((x) => x.tier === 'strong')) {
|
|
1093
|
+
this.logMiss(query, str(args.kind, 20) || undefined);
|
|
1094
|
+
}
|
|
1095
|
+
|
|
964
1096
|
// 搜出来的分两档:真对得上的,和只是靠权重/新鲜度浮上来的。
|
|
965
1097
|
// 不分档的话,模型会把「有点像」当成「就是」,这也是它编故事的起点。
|
|
966
1098
|
if (mode === 'search' && query && cards.length) {
|
|
@@ -1435,6 +1567,8 @@ export class MemoryCoreWorld implements World {
|
|
|
1435
1567
|
useAging: cfg.recallUseAging !== false,
|
|
1436
1568
|
requireHit: true,
|
|
1437
1569
|
minBigrams: 1,
|
|
1570
|
+
synonyms: cfg.synonyms,
|
|
1571
|
+
cacheKey: String(this.store.revision),
|
|
1438
1572
|
})
|
|
1439
1573
|
.map((x) => ({ card: x.card, adj: x.score * (kindBias[x.card.kind] ?? 1) }))
|
|
1440
1574
|
.sort((a, b) => b.adj - a.adj)
|
|
@@ -1652,18 +1786,79 @@ export class MemoryCoreWorld implements World {
|
|
|
1652
1786
|
return best ? { id: best.id, text: best.text, ts: best.ts } : null;
|
|
1653
1787
|
}
|
|
1654
1788
|
|
|
1789
|
+
/**
|
|
1790
|
+
* 承诺到期提醒(策略 A:只登记,不硬打扰)。
|
|
1791
|
+
*
|
|
1792
|
+
* 和旧版的区别:
|
|
1793
|
+
* - 不再因为「对方最近没说话」就整条丢掉——不写 remindedAt,下次还会再看;
|
|
1794
|
+
* - 加了可打扰时段、全局间隔、每日上限、单条次数上限;
|
|
1795
|
+
* - 免打扰 / 睡眠期间不推,也不标记,等时段过了再提。
|
|
1796
|
+
*/
|
|
1655
1797
|
private async maybeRemind(now: Date): Promise<void> {
|
|
1656
|
-
const
|
|
1798
|
+
const cfg = this.cfg();
|
|
1799
|
+
const nowMs = now.getTime();
|
|
1800
|
+
const maxTimes = Math.max(1, Number(cfg.remindMaxTimes) || 6);
|
|
1801
|
+
const repeatMin = Math.max(1, Number(cfg.remindRepeatMin) || 180);
|
|
1802
|
+
|
|
1803
|
+
const due = this.store
|
|
1804
|
+
.active()
|
|
1805
|
+
.filter((c) => c.kind === 'promise' && !c.done && c.dueAt)
|
|
1806
|
+
.filter((c) => {
|
|
1807
|
+
const at = Date.parse(c.dueAt ?? '');
|
|
1808
|
+
return Number.isFinite(at) && at <= nowMs;
|
|
1809
|
+
})
|
|
1810
|
+
.filter((c) => (Number(c.remindCount) || 0) < maxTimes)
|
|
1811
|
+
.filter((c) => {
|
|
1812
|
+
if (!c.remindedAt) return true;
|
|
1813
|
+
const last = Date.parse(c.remindedAt);
|
|
1814
|
+
return !Number.isFinite(last) || nowMs - last >= repeatMin * 60_000;
|
|
1815
|
+
})
|
|
1816
|
+
.sort((a, b) => Date.parse(a.dueAt ?? '') - Date.parse(b.dueAt ?? ''));
|
|
1657
1817
|
if (!due.length) return;
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1818
|
+
|
|
1819
|
+
const p = localParts(now, this.tz());
|
|
1820
|
+
if (this.state.sleeping || inWindow(p.minutes, cfg.sleepStart, cfg.sleepEnd)) return;
|
|
1821
|
+
if (inWindow(p.minutes, cfg.quietStart, cfg.quietEnd)) return;
|
|
1822
|
+
if (!inWindow(p.minutes, cfg.remindWindowStart, cfg.remindWindowEnd)) return;
|
|
1823
|
+
|
|
1824
|
+
// 每日上限:跨天清零
|
|
1825
|
+
if (this.state.remindDay !== p.date) {
|
|
1826
|
+
this.state.remindDay = p.date;
|
|
1827
|
+
this.state.remindCountToday = 0;
|
|
1828
|
+
}
|
|
1829
|
+
const dailyCap = Number(cfg.remindDailyCap) || 0;
|
|
1830
|
+
if (dailyCap > 0 && Number(this.state.remindCountToday ?? 0) >= dailyCap) return;
|
|
1831
|
+
|
|
1832
|
+
// 全局间隔:几条同时到期,也只一条一条来
|
|
1833
|
+
const gapMin = Math.max(0, Number(cfg.remindMinGapMin) || 0);
|
|
1834
|
+
if (gapMin > 0 && this.state.lastRemindAt) {
|
|
1835
|
+
const last = Date.parse(this.state.lastRemindAt);
|
|
1836
|
+
if (Number.isFinite(last) && nowMs - last < gapMin * 60_000) return;
|
|
1662
1837
|
}
|
|
1838
|
+
|
|
1839
|
+
const lastUser = this.probeLastUser(nowMs);
|
|
1840
|
+
const recentHours = Number(cfg.requireRecentUserHours) || 0;
|
|
1841
|
+
const silent = recentHours > 0 && (!lastUser || nowMs - lastUser > recentHours * 3_600_000);
|
|
1842
|
+
if (silent) {
|
|
1843
|
+
// 策略 A:默认不推,但也不标记——等对方出现再说
|
|
1844
|
+
if (!cfg.remindWithoutUser) return;
|
|
1845
|
+
const overdueH = (nowMs - Date.parse(due[0].dueAt ?? '')) / 3_600_000;
|
|
1846
|
+
if (overdueH < (Number(cfg.remindForceAfterHours) || 6)) return;
|
|
1847
|
+
}
|
|
1848
|
+
|
|
1663
1849
|
const card = due[0];
|
|
1664
|
-
const
|
|
1850
|
+
const dueAt = Date.parse(card.dueAt ?? '');
|
|
1851
|
+
const late = Number.isFinite(dueAt) ? humanSpan(nowMs - dueAt) : '';
|
|
1852
|
+
const text = `(答应过的事到点了:${clip(card.text, 80)}${late ? ` · 已经过了 ${late}` : ''}。`
|
|
1853
|
+
+ '先确认做到没有;没做到就直说,别绕。)';
|
|
1854
|
+
const ok = await this.push('mcore.due', text, 'flush');
|
|
1665
1855
|
if (!ok) return;
|
|
1666
|
-
|
|
1856
|
+
|
|
1857
|
+
const count = (Number(card.remindCount) || 0) + 1;
|
|
1858
|
+
this.store.update(card.id, { remindedAt: now.toISOString(), remindCount: count });
|
|
1859
|
+
this.state.lastRemindAt = now.toISOString();
|
|
1860
|
+
this.state.remindCountToday = Number(this.state.remindCountToday ?? 0) + 1;
|
|
1861
|
+
this.save();
|
|
1667
1862
|
}
|
|
1668
1863
|
|
|
1669
1864
|
private async maybeProactive(now: Date): Promise<void> {
|
package/webui/app.js
CHANGED
|
@@ -2726,8 +2726,14 @@ function renderHealth() {
|
|
|
2726
2726
|
<span>未完成 <b>${h.promises.open}</b></span>
|
|
2727
2727
|
<span class="${h.promises.overdue ? 'warn' : ''}">已过时间 <b>${h.promises.overdue}</b></span>
|
|
2728
2728
|
<span class="${h.promises.noDue ? 'warn' : ''}">没有截止时间 <b>${h.promises.noDue}</b></span>
|
|
2729
|
-
<span class="dim">${h.promises.
|
|
2729
|
+
<span class="dim">${h.promises.repeatMin ? `没回应时每 ${h.promises.repeatMin} 分钟再提` : '只提醒一次'}</span>
|
|
2730
2730
|
${h.promises.noDue ? '<button class="btn tiny" id="h-fix-promises">去补时间</button>' : ''}
|
|
2731
|
+
${(h.promises.dueList || []).length
|
|
2732
|
+
? `<div class="due-list">${(h.promises.dueList || []).map((d) => {
|
|
2733
|
+
const late = d.lateMin >= 1440 ? `${Math.floor(d.lateMin / 1440)} 天` : d.lateMin >= 60 ? `${Math.floor(d.lateMin / 60)} 小时` : `${d.lateMin} 分钟`;
|
|
2734
|
+
return `<div class="due-item"><span class="due-late">晚 ${late}</span><span class="due-text">${esc(d.text)}</span><span class="due-count">提醒 ${d.remindCount} 次</span></div>`;
|
|
2735
|
+
}).join('')}</div>`
|
|
2736
|
+
: ''}
|
|
2731
2737
|
</div>
|
|
2732
2738
|
</section>
|
|
2733
2739
|
|
package/webui/next.css
CHANGED
|
@@ -641,16 +641,24 @@ html[data-mode="light"] .next-brand-copy strong { color: #172532; text-shadow: 1
|
|
|
641
641
|
html[data-mode="light"] .next-rail h3::before,
|
|
642
642
|
html[data-mode="light"] #insp-body h3::before,
|
|
643
643
|
html[data-mode="light"] .h-block h3::before { color: #8a6a00; }
|
|
644
|
-
|
|
645
|
-
/* 浅色:侧栏筛选块、状态卡、HUD、搜索聚焦、次级按钮原来都是硬编码深底 */
|
|
646
|
-
html[data-mode="light"] .chip { background: #fff; border-color: var(--line-2); }
|
|
647
|
-
html[data-mode="light"] .chip:hover,
|
|
648
|
-
html[data-mode="light"] .chip.on { background: var(--sheet-3); border-color: var(--line-strong); }
|
|
649
|
-
html[data-mode="light"] .status-card { background: #fff; }
|
|
650
|
-
html[data-mode="light"] .legend,
|
|
651
|
-
html[data-mode="light"] .hud-actions { background: rgba(255, 255, 255, .9); }
|
|
652
|
-
html[data-mode="light"] .next-search:focus-within { background: #fff; border-color: rgba(22, 143, 131, .5); box-shadow: 0 0 0 1px rgba(22, 143, 131, .16); }
|
|
653
|
-
html[data-mode="light"] .btn:not(.primary) { background: #fff; }
|
|
654
|
-
html[data-mode="light"] .btn:not(.primary):hover { background: var(--sheet-2); }
|
|
655
|
-
html[data-mode="light"] .rail-sign { display: none; }
|
|
656
|
-
html[data-mode="light"] .card-text { background: #fff; }
|
|
644
|
+
|
|
645
|
+
/* 浅色:侧栏筛选块、状态卡、HUD、搜索聚焦、次级按钮原来都是硬编码深底 */
|
|
646
|
+
html[data-mode="light"] .chip { background: #fff; border-color: var(--line-2); }
|
|
647
|
+
html[data-mode="light"] .chip:hover,
|
|
648
|
+
html[data-mode="light"] .chip.on { background: var(--sheet-3); border-color: var(--line-strong); }
|
|
649
|
+
html[data-mode="light"] .status-card { background: #fff; }
|
|
650
|
+
html[data-mode="light"] .legend,
|
|
651
|
+
html[data-mode="light"] .hud-actions { background: rgba(255, 255, 255, .9); }
|
|
652
|
+
html[data-mode="light"] .next-search:focus-within { background: #fff; border-color: rgba(22, 143, 131, .5); box-shadow: 0 0 0 1px rgba(22, 143, 131, .16); }
|
|
653
|
+
html[data-mode="light"] .btn:not(.primary) { background: #fff; }
|
|
654
|
+
html[data-mode="light"] .btn:not(.primary):hover { background: var(--sheet-2); }
|
|
655
|
+
html[data-mode="light"] .rail-sign { display: none; }
|
|
656
|
+
html[data-mode="light"] .card-text { background: #fff; }
|
|
657
|
+
|
|
658
|
+
/* 体检页:已到期的承诺,别再只给一个数字 */
|
|
659
|
+
.due-list { flex: 1 0 100%; width: 100%; margin-top: 4px; display: grid; gap: 4px; }
|
|
660
|
+
.due-item { display: flex; align-items: baseline; gap: 8px; font-size: 11.5px; color: var(--ink-soft); }
|
|
661
|
+
.due-late { flex: none; color: var(--acid); font: 10px var(--mono); letter-spacing: .04em; }
|
|
662
|
+
.due-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
663
|
+
.due-count { flex: none; color: var(--faint); font: 10px var(--mono); }
|
|
664
|
+
html[data-mode="light"] .due-late { color: #8a6a00; }
|