dsh-world 0.7.2 → 0.7.4

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.
Files changed (78) hide show
  1. package/CHANGELOG.md +403 -379
  2. package/INSTALL.md +314 -314
  3. package/LICENSE +21 -21
  4. package/NOTES.md +23 -13
  5. package/README.md +22 -7
  6. package/client/index.js +74 -27
  7. package/cordis.patch.yml +6 -6
  8. package/lib/archiveSelection.d.ts +6 -2
  9. package/lib/archiveSelection.js +21 -12
  10. package/lib/compaction.d.ts +7 -0
  11. package/lib/compaction.js +18 -9
  12. package/lib/compactionSwap.d.ts +17 -0
  13. package/lib/compactionSwap.js +68 -6
  14. package/lib/console/routes.d.ts +2 -3
  15. package/lib/console/routes.js +7 -8
  16. package/lib/console/snapshot.d.ts +1 -3
  17. package/lib/console/snapshot.js +0 -3
  18. package/lib/ecosystem/bridge/bridge.d.ts +5 -0
  19. package/lib/ecosystem/bridge/bridge.js +2 -1
  20. package/lib/ecosystem/bridge/route.d.ts +4 -6
  21. package/lib/ecosystem/bridge/route.js +34 -58
  22. package/lib/ecosystem/qq/panel.d.ts +0 -1
  23. package/lib/ecosystem/qq/route.d.ts +6 -7
  24. package/lib/ecosystem/qq/route.js +10 -10
  25. package/lib/ecosystem/qq/snowluma-start.d.ts +1 -0
  26. package/lib/ecosystem/qq/snowluma-start.js +41 -8
  27. package/lib/ecosystem/qq/supervisor.d.ts +1 -2
  28. package/lib/ecosystem/qq/supervisor.js +4 -2
  29. package/lib/ecosystem/qq-native/index.js +2 -0
  30. package/lib/ecosystem/qq-native/native-bridge.d.ts +0 -1
  31. package/lib/ecosystem/qq-native/native-bridge.js +0 -2
  32. package/lib/ecosystem/qq-native/snowluma.js +11 -2
  33. package/lib/ecosystem/shared/turn.d.ts +3 -0
  34. package/lib/ecosystem/shared/turn.js +9 -2
  35. package/lib/ecosystem/wechat/home.d.ts +3 -0
  36. package/lib/ecosystem/wechat/home.js +12 -4
  37. package/lib/ecosystem/wechat/index.d.ts +0 -1
  38. package/lib/ecosystem/wechat/index.js +9 -6
  39. package/lib/hostContract.d.ts +19 -0
  40. package/lib/index.js +117 -49
  41. package/lib/life/toolRegistry.js +2 -2
  42. package/lib/memoryFiles.d.ts +0 -1
  43. package/lib/memoryStore.d.ts +0 -1
  44. package/lib/memoryStore.js +0 -1
  45. package/lib/memoryTools.d.ts +0 -1
  46. package/lib/memoryTools.js +2 -3
  47. package/lib/mood.d.ts +28 -0
  48. package/lib/mood.js +69 -0
  49. package/lib/promptSection.d.ts +7 -5
  50. package/lib/promptSection.js +74 -28
  51. package/lib/runtime.d.ts +6 -2
  52. package/lib/runtime.js +163 -26
  53. package/lib/self.d.ts +1 -1
  54. package/lib/self.js +1 -1
  55. package/lib/sourceArchive.d.ts +4 -2
  56. package/lib/sourceArchive.js +18 -4
  57. package/lib/store.js +2 -1
  58. package/lib/types.d.ts +3 -1
  59. package/lib/worldPrompt.d.ts +2 -3
  60. package/lib/worldPrompt.js +2 -3
  61. package/lib/worldRoutes.d.ts +9 -0
  62. package/lib/worldRoutes.js +29 -0
  63. package/lib/worldScope.d.ts +5 -5
  64. package/lib/worldScope.js +16 -7
  65. package/lib/worldSwitch.d.ts +1 -2
  66. package/lib/worldSwitch.js +1 -1
  67. package/package.json +17 -16
  68. package/scripts/compact-home.mjs +29 -29
  69. package/scripts/enable-tool-free-compaction.ps1 +33 -33
  70. package/scripts/import-stickers.mjs +17 -17
  71. package/scripts/update-world.mjs +2 -2
  72. package/src/ecosystem/README.md +1 -1
  73. package/src/ecosystem/wechat/windows/README.md +3 -3
  74. package/src/ecosystem/wechat/windows/adapter.py +21 -3
  75. package/src/ecosystem/wechat/windows/engine/profiles.json +142 -142
  76. package/src/ecosystem/wechat/windows/presence.py +109 -109
  77. package/templates/alarm.md +2 -2
  78. package/templates/world-prompt.md +11 -2
@@ -1,142 +1,142 @@
1
- [
2
- {
3
- "version": "4.1.15.13",
4
- "size": 201552944,
5
- "sha256": "10f8e995453e2da46d4f2b5080cd6da1f13cc5147746adc119ceae38cb039de5",
6
- "timestamp": 1789961080,
7
- "imageSize": 202039296,
8
- "addresses": {
9
- "application": 285968,
10
- "scheduler": 291600,
11
- "schedule": 3125264,
12
- "context": 291360,
13
- "provider": 3589952,
14
- "manager": 7294352,
15
- "text": 88802032,
16
- "image": 64608656,
17
- "emoticon": 29340096,
18
- "copyWide": 636368,
19
- "validateGif": 15182048,
20
- "probeGif": 5441984,
21
- "releaseProbe": 5137248,
22
- "send": 24703232,
23
- "allocate": 122337436,
24
- "free": 122337504,
25
- "accountRoot": 194061968,
26
- "contextVtable": 148890360,
27
- "emoticonVtable": 151891960
28
- }
29
- },
30
- {
31
- "version": "4.1.15.56",
32
- "size": 204305968,
33
- "sha256": "e0428a7b691853de496532523c2c09aa095f90941c37c9f4cfb3f137f3c66556",
34
- "timestamp": 1792050120,
35
- "imageSize": 204795904,
36
- "addresses": {
37
- "application": 285968,
38
- "scheduler": 291600,
39
- "schedule": 3208272,
40
- "context": 291360,
41
- "provider": 3679184,
42
- "manager": 7377536,
43
- "text": 90112896,
44
- "image": 65154416,
45
- "emoticon": 29436416,
46
- "copyWide": 636384,
47
- "validateGif": 15343584,
48
- "probeGif": 5528896,
49
- "releaseProbe": 5224160,
50
- "send": 24788000,
51
- "allocate": 122993884,
52
- "free": 122993952,
53
- "accountRoot": 196685728,
54
- "contextVtable": 150803560,
55
- "emoticonVtable": 153824520
56
- }
57
- },
58
- {
59
- "version": "4.2.0.11",
60
- "size": 205929008,
61
- "sha256": "745cdf2955fa5128cdb00c056c97571156a5f107406a9bb15ac0754f3246b201",
62
- "timestamp": 1793108177,
63
- "imageSize": 206422016,
64
- "addresses": {
65
- "application": 285968,
66
- "scheduler": 291600,
67
- "schedule": 3217808,
68
- "context": 291360,
69
- "provider": 3688240,
70
- "manager": 7456256,
71
- "text": 91356448,
72
- "image": 65819968,
73
- "emoticon": null,
74
- "copyWide": 636384,
75
- "validateGif": null,
76
- "probeGif": null,
77
- "releaseProbe": null,
78
- "send": 24965648,
79
- "allocate": 124404668,
80
- "free": 124404736,
81
- "accountRoot": 198233648,
82
- "contextVtable": 151867272,
83
- "emoticonVtable": null
84
- }
85
- },
86
- {
87
- "version": "4.2.0.12",
88
- "size": 205932072,
89
- "sha256": "2b3677c3f932daaa4ef84c8b2acd0aee12cbe5a779ff9e740c370761e5c291ce",
90
- "timestamp": 1793275655,
91
- "imageSize": 206417920,
92
- "addresses": {
93
- "application": 285968,
94
- "scheduler": 291600,
95
- "schedule": 3217808,
96
- "context": 291360,
97
- "provider": 3688240,
98
- "manager": 7451520,
99
- "text": 91361344,
100
- "image": 65824848,
101
- "emoticon": null,
102
- "copyWide": 636384,
103
- "validateGif": null,
104
- "probeGif": null,
105
- "releaseProbe": null,
106
- "send": 24962240,
107
- "allocate": 124408764,
108
- "free": 124408832,
109
- "accountRoot": 198233648,
110
- "contextVtable": 151871336,
111
- "emoticonVtable": null
112
- }
113
- },
114
- {
115
- "version": "4.2.0.13",
116
- "size": 205943848,
117
- "sha256": "afe3d02c58bada3c35009c0cd58ee1f57b2a00fe53237d0dce649107fddb9a20",
118
- "timestamp": 1793604862,
119
- "imageSize": 206430208,
120
- "addresses": {
121
- "application": 285968,
122
- "scheduler": 291600,
123
- "schedule": 3228064,
124
- "context": 291360,
125
- "provider": 3690048,
126
- "manager": 7465840,
127
- "text": 91370832,
128
- "image": 65862832,
129
- "emoticon": null,
130
- "copyWide": 636384,
131
- "validateGif": null,
132
- "probeGif": null,
133
- "releaseProbe": null,
134
- "send": 25014992,
135
- "allocate": 124417292,
136
- "free": 124417360,
137
- "accountRoot": 198245872,
138
- "contextVtable": 151879656,
139
- "emoticonVtable": null
140
- }
141
- }
142
- ]
1
+ [
2
+ {
3
+ "version": "4.1.15.13",
4
+ "size": 201552944,
5
+ "sha256": "10f8e995453e2da46d4f2b5080cd6da1f13cc5147746adc119ceae38cb039de5",
6
+ "timestamp": 1789961080,
7
+ "imageSize": 202039296,
8
+ "addresses": {
9
+ "application": 285968,
10
+ "scheduler": 291600,
11
+ "schedule": 3125264,
12
+ "context": 291360,
13
+ "provider": 3589952,
14
+ "manager": 7294352,
15
+ "text": 88802032,
16
+ "image": 64608656,
17
+ "emoticon": 29340096,
18
+ "copyWide": 636368,
19
+ "validateGif": 15182048,
20
+ "probeGif": 5441984,
21
+ "releaseProbe": 5137248,
22
+ "send": 24703232,
23
+ "allocate": 122337436,
24
+ "free": 122337504,
25
+ "accountRoot": 194061968,
26
+ "contextVtable": 148890360,
27
+ "emoticonVtable": 151891960
28
+ }
29
+ },
30
+ {
31
+ "version": "4.1.15.56",
32
+ "size": 204305968,
33
+ "sha256": "e0428a7b691853de496532523c2c09aa095f90941c37c9f4cfb3f137f3c66556",
34
+ "timestamp": 1792050120,
35
+ "imageSize": 204795904,
36
+ "addresses": {
37
+ "application": 285968,
38
+ "scheduler": 291600,
39
+ "schedule": 3208272,
40
+ "context": 291360,
41
+ "provider": 3679184,
42
+ "manager": 7377536,
43
+ "text": 90112896,
44
+ "image": 65154416,
45
+ "emoticon": 29436416,
46
+ "copyWide": 636384,
47
+ "validateGif": 15343584,
48
+ "probeGif": 5528896,
49
+ "releaseProbe": 5224160,
50
+ "send": 24788000,
51
+ "allocate": 122993884,
52
+ "free": 122993952,
53
+ "accountRoot": 196685728,
54
+ "contextVtable": 150803560,
55
+ "emoticonVtable": 153824520
56
+ }
57
+ },
58
+ {
59
+ "version": "4.2.0.11",
60
+ "size": 205929008,
61
+ "sha256": "745cdf2955fa5128cdb00c056c97571156a5f107406a9bb15ac0754f3246b201",
62
+ "timestamp": 1793108177,
63
+ "imageSize": 206422016,
64
+ "addresses": {
65
+ "application": 285968,
66
+ "scheduler": 291600,
67
+ "schedule": 3217808,
68
+ "context": 291360,
69
+ "provider": 3688240,
70
+ "manager": 7456256,
71
+ "text": 91356448,
72
+ "image": 65819968,
73
+ "emoticon": null,
74
+ "copyWide": 636384,
75
+ "validateGif": null,
76
+ "probeGif": null,
77
+ "releaseProbe": null,
78
+ "send": 24965648,
79
+ "allocate": 124404668,
80
+ "free": 124404736,
81
+ "accountRoot": 198233648,
82
+ "contextVtable": 151867272,
83
+ "emoticonVtable": null
84
+ }
85
+ },
86
+ {
87
+ "version": "4.2.0.12",
88
+ "size": 205932072,
89
+ "sha256": "2b3677c3f932daaa4ef84c8b2acd0aee12cbe5a779ff9e740c370761e5c291ce",
90
+ "timestamp": 1793275655,
91
+ "imageSize": 206417920,
92
+ "addresses": {
93
+ "application": 285968,
94
+ "scheduler": 291600,
95
+ "schedule": 3217808,
96
+ "context": 291360,
97
+ "provider": 3688240,
98
+ "manager": 7451520,
99
+ "text": 91361344,
100
+ "image": 65824848,
101
+ "emoticon": null,
102
+ "copyWide": 636384,
103
+ "validateGif": null,
104
+ "probeGif": null,
105
+ "releaseProbe": null,
106
+ "send": 24962240,
107
+ "allocate": 124408764,
108
+ "free": 124408832,
109
+ "accountRoot": 198233648,
110
+ "contextVtable": 151871336,
111
+ "emoticonVtable": null
112
+ }
113
+ },
114
+ {
115
+ "version": "4.2.0.13",
116
+ "size": 205943848,
117
+ "sha256": "afe3d02c58bada3c35009c0cd58ee1f57b2a00fe53237d0dce649107fddb9a20",
118
+ "timestamp": 1793604862,
119
+ "imageSize": 206430208,
120
+ "addresses": {
121
+ "application": 285968,
122
+ "scheduler": 291600,
123
+ "schedule": 3228064,
124
+ "context": 291360,
125
+ "provider": 3690048,
126
+ "manager": 7465840,
127
+ "text": 91370832,
128
+ "image": 65862832,
129
+ "emoticon": null,
130
+ "copyWide": 636384,
131
+ "validateGif": null,
132
+ "probeGif": null,
133
+ "releaseProbe": null,
134
+ "send": 25014992,
135
+ "allocate": 124417292,
136
+ "free": 124417360,
137
+ "accountRoot": 198245872,
138
+ "contextVtable": 151879656,
139
+ "emoticonVtable": null
140
+ }
141
+ }
142
+ ]
@@ -1,109 +1,109 @@
1
- """One durable metadata row per account/group; no message body, wake or model call."""
2
- from datetime import datetime, timezone
3
- import json
4
- from messages import messageKey, messageOrder, recentEntries
5
- from snapshot import SnapshotBusy
6
-
7
-
8
- class GroupPresence:
9
- def __init__(self, db):
10
- self.db = db
11
- db.execute('''CREATE TABLE IF NOT EXISTS groupPresence(
12
- accountId TEXT, chatId TEXT, count INTEGER NOT NULL,
13
- seq INTEGER, shard TEXT, localId INTEGER, lastAt TEXT, speaker TEXT, self INTEGER,
14
- readSeq INTEGER NOT NULL DEFAULT 0, readShard TEXT NOT NULL DEFAULT '', readId INTEGER NOT NULL DEFAULT 0,
15
- seen TEXT NOT NULL DEFAULT '[]', readSeen TEXT NOT NULL DEFAULT '[]',
16
- PRIMARY KEY(accountId,chatId))''')
17
-
18
- def _get(self, account, chat):
19
- return self.db.execute('SELECT count,seq,shard,localId,lastAt,speaker,self,readSeq,readShard,readId,seen,readSeen '
20
- 'FROM groupPresence WHERE accountId=? AND chatId=? LIMIT 1', (account, chat)).fetchone()
21
-
22
- def observe(self, account, chat, row, speaker, *, unread=True):
23
- if row['type'] == '系统消息': return
24
- if not row.get('sender_username'): raise ValueError('群动态缺少真实发言人')
25
- order = messageOrder(row)
26
- previous = self._get(account, chat)
27
- if previous and order[0] < previous[1]: return
28
- sameSeq = bool(previous and order[0] == previous[1])
29
- seen = set(json.loads(previous[10])) if sameSeq else set()
30
- key = messageKey(row)
31
- if key in seen: return
32
- seen.add(key)
33
- read = tuple(previous[7:10]) if previous else (0, '', 0)
34
- own = row['sender_username'] == account
35
- count = (previous[0] if previous else 0) + int(unread and not own and (order > read or (sameSeq and order[0] == read[0])))
36
- at = datetime.fromtimestamp(int(row['create_time']), timezone.utc).isoformat()
37
- metadata = (at, str(speaker)[:80], int(own))
38
- if sameSeq and order < tuple(previous[1:4]):
39
- order, metadata = tuple(previous[1:4]), tuple(previous[4:7])
40
- with self.db:
41
- self.db.execute('INSERT INTO groupPresence VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?) '
42
- 'ON CONFLICT(accountId,chatId) DO UPDATE SET count=excluded.count,seq=excluded.seq,'
43
- 'shard=excluded.shard,localId=excluded.localId,lastAt=excluded.lastAt,speaker=excluded.speaker,self=excluded.self,seen=excluded.seen',
44
- (account, chat, count, *order, *metadata, *read, json.dumps(sorted(seen)), previous[11] if previous else '[]'))
45
-
46
- def markRead(self, account, chat, through, countRemaining=None, seenKeys=()):
47
- previous = self._get(account, chat)
48
- boundary = tuple(through)
49
- if not previous:
50
- with self.db:
51
- self.db.execute('INSERT INTO groupPresence(accountId,chatId,count,seq,shard,localId,readSeq,readShard,readId,readSeen) VALUES (?,?,0,0,\'\',0,?,?,?,?)', (account, chat, *boundary, json.dumps(sorted(seenKeys))))
52
- return
53
- read = max(tuple(previous[7:10]), boundary)
54
- seen = set(json.loads(previous[10]))
55
- if boundary[0] == previous[1]: seen.update(seenKeys)
56
- readSeen = set(json.loads(previous[11])) if boundary[0] == previous[7] else set()
57
- if boundary < tuple(previous[7:10]) or (boundary == tuple(previous[7:10]) and not set(seenKeys) - readSeen): return
58
- readSeen.update(seenKeys)
59
- remaining = 0
60
- if boundary < tuple(previous[1:4]):
61
- if countRemaining is None: raise ValueError('旧读取结果需要核对尚未读到的群消息')
62
- remaining = min(previous[0], countRemaining(boundary, tuple(previous[1:4])))
63
- with self.db:
64
- self.db.execute('UPDATE groupPresence SET count=?,readSeq=?,readShard=?,readId=?,seen=?,readSeen=? WHERE accountId=? AND chatId=?',
65
- (remaining, *read, json.dumps(sorted(seen)), json.dumps(sorted(readSeen)), account, chat))
66
-
67
- def snapshot(self, config):
68
- groups = []
69
- for chat in config['chats']:
70
- if not chat['id'].endswith('@chatroom'): continue
71
- row = self._get(config['selfId'], chat['id'])
72
- if row and row[4]:
73
- groups.append(dict(chatId=chat['id'], count=min(100, row[0]), lastAt=row[4], lastSpeaker=row[5], lastSelf=bool(row[6])))
74
- # Keep the existing control poll bounded even with many configured groups.
75
- return sorted(groups, key=lambda item: (item['count'] > 0, item['lastAt']), reverse=True)[:8]
76
-
77
-
78
- def speakerName(database, config, row):
79
- sender = row.get('sender_username')
80
- if not sender: raise ValueError('群动态缺少真实发言人')
81
- return config.get('people', {}).get(sender) or database.get_nickname(sender) or sender
82
-
83
-
84
- def seedPresence(database, store, config, chat):
85
- presence = store.presence
86
- previous = presence._get(config['selfId'], chat['id'])
87
- if not chat['id'].endswith('@chatroom') or (previous and previous[4]): return
88
- cursor = store.cursor(chat['id'])
89
- if cursor is None: return
90
- found = recentEntries(database, chat['id'], lambda row: row if int(row['sort_seq']) <= cursor and row['type'] != '系统消息' else None,
91
- config.get('pageSize', 50), 1)
92
- if found:
93
- latest = next(reversed(found.values()))
94
- presence.observe(config['selfId'], chat['id'], latest, speakerName(database, config, latest), unread=False)
95
-
96
-
97
- def unreadAfter(database, config, chat, after, until):
98
- offset, size, found = 0, config.get('pageSize', 50), set()
99
- while True:
100
- rows = database.get_messages(chat, limit=size, offset=offset)
101
- if offset == 0 and (not rows or max(int(row['sort_seq']) for row in rows) < until[0]):
102
- raise SnapshotBusy('群消息快照落后于已观察位置,保留未读等待重读')
103
- for row in rows:
104
- order = messageOrder(row)
105
- if after < order <= until and row['type'] != '系统消息':
106
- if not row.get('sender_username'): raise ValueError('群动态缺少真实发言人')
107
- if row['sender_username'] != config['selfId']: found.add(order)
108
- if len(rows) < size or any(int(row['sort_seq']) < after[0] for row in rows): return len(found)
109
- offset += len(rows)
1
+ """One durable metadata row per account/group; no message body, wake or model call."""
2
+ from datetime import datetime, timezone
3
+ import json
4
+ from messages import messageKey, messageOrder, recentEntries
5
+ from snapshot import SnapshotBusy
6
+
7
+
8
+ class GroupPresence:
9
+ def __init__(self, db):
10
+ self.db = db
11
+ db.execute('''CREATE TABLE IF NOT EXISTS groupPresence(
12
+ accountId TEXT, chatId TEXT, count INTEGER NOT NULL,
13
+ seq INTEGER, shard TEXT, localId INTEGER, lastAt TEXT, speaker TEXT, self INTEGER,
14
+ readSeq INTEGER NOT NULL DEFAULT 0, readShard TEXT NOT NULL DEFAULT '', readId INTEGER NOT NULL DEFAULT 0,
15
+ seen TEXT NOT NULL DEFAULT '[]', readSeen TEXT NOT NULL DEFAULT '[]',
16
+ PRIMARY KEY(accountId,chatId))''')
17
+
18
+ def _get(self, account, chat):
19
+ return self.db.execute('SELECT count,seq,shard,localId,lastAt,speaker,self,readSeq,readShard,readId,seen,readSeen '
20
+ 'FROM groupPresence WHERE accountId=? AND chatId=? LIMIT 1', (account, chat)).fetchone()
21
+
22
+ def observe(self, account, chat, row, speaker, *, unread=True):
23
+ if row['type'] == '系统消息': return
24
+ if not row.get('sender_username'): raise ValueError('群动态缺少真实发言人')
25
+ order = messageOrder(row)
26
+ previous = self._get(account, chat)
27
+ if previous and order[0] < previous[1]: return
28
+ sameSeq = bool(previous and order[0] == previous[1])
29
+ seen = set(json.loads(previous[10])) if sameSeq else set()
30
+ key = messageKey(row)
31
+ if key in seen: return
32
+ seen.add(key)
33
+ read = tuple(previous[7:10]) if previous else (0, '', 0)
34
+ own = row['sender_username'] == account
35
+ count = (previous[0] if previous else 0) + int(unread and not own and (order > read or (sameSeq and order[0] == read[0])))
36
+ at = datetime.fromtimestamp(int(row['create_time']), timezone.utc).isoformat()
37
+ metadata = (at, str(speaker)[:80], int(own))
38
+ if sameSeq and order < tuple(previous[1:4]):
39
+ order, metadata = tuple(previous[1:4]), tuple(previous[4:7])
40
+ with self.db:
41
+ self.db.execute('INSERT INTO groupPresence VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?) '
42
+ 'ON CONFLICT(accountId,chatId) DO UPDATE SET count=excluded.count,seq=excluded.seq,'
43
+ 'shard=excluded.shard,localId=excluded.localId,lastAt=excluded.lastAt,speaker=excluded.speaker,self=excluded.self,seen=excluded.seen',
44
+ (account, chat, count, *order, *metadata, *read, json.dumps(sorted(seen)), previous[11] if previous else '[]'))
45
+
46
+ def markRead(self, account, chat, through, countRemaining=None, seenKeys=()):
47
+ previous = self._get(account, chat)
48
+ boundary = tuple(through)
49
+ if not previous:
50
+ with self.db:
51
+ self.db.execute('INSERT INTO groupPresence(accountId,chatId,count,seq,shard,localId,readSeq,readShard,readId,readSeen) VALUES (?,?,0,0,\'\',0,?,?,?,?)', (account, chat, *boundary, json.dumps(sorted(seenKeys))))
52
+ return
53
+ read = max(tuple(previous[7:10]), boundary)
54
+ seen = set(json.loads(previous[10]))
55
+ if boundary[0] == previous[1]: seen.update(seenKeys)
56
+ readSeen = set(json.loads(previous[11])) if boundary[0] == previous[7] else set()
57
+ if boundary < tuple(previous[7:10]) or (boundary == tuple(previous[7:10]) and not set(seenKeys) - readSeen): return
58
+ readSeen.update(seenKeys)
59
+ remaining = 0
60
+ if boundary < tuple(previous[1:4]):
61
+ if countRemaining is None: raise ValueError('旧读取结果需要核对尚未读到的群消息')
62
+ remaining = min(previous[0], countRemaining(boundary, tuple(previous[1:4])))
63
+ with self.db:
64
+ self.db.execute('UPDATE groupPresence SET count=?,readSeq=?,readShard=?,readId=?,seen=?,readSeen=? WHERE accountId=? AND chatId=?',
65
+ (remaining, *read, json.dumps(sorted(seen)), json.dumps(sorted(readSeen)), account, chat))
66
+
67
+ def snapshot(self, config):
68
+ groups = []
69
+ for chat in config['chats']:
70
+ if not chat['id'].endswith('@chatroom'): continue
71
+ row = self._get(config['selfId'], chat['id'])
72
+ if row and row[4]:
73
+ groups.append(dict(chatId=chat['id'], count=min(100, row[0]), lastAt=row[4], lastSpeaker=row[5], lastSelf=bool(row[6])))
74
+ # Keep the existing control poll bounded even with many configured groups.
75
+ return sorted(groups, key=lambda item: (item['count'] > 0, item['lastAt']), reverse=True)[:8]
76
+
77
+
78
+ def speakerName(database, config, row):
79
+ sender = row.get('sender_username')
80
+ if not sender: raise ValueError('群动态缺少真实发言人')
81
+ return config.get('people', {}).get(sender) or database.get_nickname(sender) or sender
82
+
83
+
84
+ def seedPresence(database, store, config, chat):
85
+ presence = store.presence
86
+ previous = presence._get(config['selfId'], chat['id'])
87
+ if not chat['id'].endswith('@chatroom') or (previous and previous[4]): return
88
+ cursor = store.cursor(chat['id'])
89
+ if cursor is None: return
90
+ found = recentEntries(database, chat['id'], lambda row: row if int(row['sort_seq']) <= cursor and row['type'] != '系统消息' else None,
91
+ config.get('pageSize', 50), 1)
92
+ if found:
93
+ latest = next(reversed(found.values()))
94
+ presence.observe(config['selfId'], chat['id'], latest, speakerName(database, config, latest), unread=False)
95
+
96
+
97
+ def unreadAfter(database, config, chat, after, until):
98
+ offset, size, found = 0, config.get('pageSize', 50), set()
99
+ while True:
100
+ rows = database.get_messages(chat, limit=size, offset=offset)
101
+ if offset == 0 and (not rows or max(int(row['sort_seq']) for row in rows) < until[0]):
102
+ raise SnapshotBusy('群消息快照落后于已观察位置,保留未读等待重读')
103
+ for row in rows:
104
+ order = messageOrder(row)
105
+ if after < order <= until and row['type'] != '系统消息':
106
+ if not row.get('sender_username'): raise ValueError('群动态缺少真实发言人')
107
+ if row['sender_username'] != config['selfId']: found.add(order)
108
+ if len(rows) < size or any(int(row['sort_seq']) < after[0] for row in rows): return len(found)
109
+ offset += len(rows)
@@ -27,8 +27,8 @@
27
27
  ## 每日回顾
28
28
  {{date}} 快过完了,回头看看今天吧。{{#conversations}}今天的聊天记录在 {{conversations}}{{/conversations}}{{^conversations}}今天家里没有聊天记录{{/conversations}}{{#activity}},今天做过的事在 {{activity}}{{/activity}},日记在 {{diaryDir}}。
29
29
  先写日记,再看自己:
30
- 1. 日记:一件一件地想,今天发生了什么,我当时是什么感受,现在回头看又怎么想,写进今天的日记;已经写过的,就补上漏掉的。以前的日记不改:哪天记错了、现在想法不一样了,就写在今天的日记里。
31
- 2. 我是谁:问问自己有没有变——新的喜好、新的想法,脾气、看法变了,或者说话方式(语气、句子长短、常用表达、玩笑、表情、拆成多条消息的习惯)有了想长期保留或调整的地方。变了,就把变化提炼成一两句,合并进 {{selfFile}} 里对应的地方,写成现在的我;今天发生的事不写进去,也不从日记里搬内容。分清我和聊天对象的话,不把别人的口吻当成自己的。没有变就不用改。{{#snapshot}}改之前的那份已经留在 {{snapshot}}。{{/snapshot}}{{late}}
30
+ 1. 日记:挑今天想记住的片段,用第一人称写进今天的日记。写下当时注意到了什么、心里怎么想。禁止把日记写成工作总结、进度汇报或任务清单。今天已经写过的,就补上漏掉的片段。以前的日记不改。哪天记错了、现在想法不一样了,就写在今天的日记里。
31
+ 2. 我是谁:看看有没有值得长期保留的变化,或自述里有没有需要删改的重复、过时内容。需要改时,先读完整的 {{selfFile}},太长就分段读完。把新变化写进对应位置,替换旧说法,精简重复的句子。今天发生的事留在日记里,别把聊天对象的口吻写成自己的。如果自述已经太长、散乱或被截断,就重写整篇,把仍然重要的内容留在一份更短的自述里。没有长期变化、也没有需要整理的内容时,就不改。{{#snapshot}}改之前的那份已经留在 {{snapshot}}。{{/snapshot}}{{late}}
32
32
 
33
33
  ## 额度用完
34
34
  今天在家里已经花了 {{spent}} 元,过了{{partner}}给我定的每天 {{budget}} 元。接下来省着点:手上的事收个尾就歇一歇,不急的留到明天;{{partner}}找我照常回。
@@ -2,14 +2,18 @@
2
2
 
3
3
  聊天时,我从哪个渠道、哪个会话收到消息,就把回复发回同一渠道、同一会话。
4
4
 
5
+ 我直接接对方说的事,用自己的话说反应、想法,或问我真正想知道的。别把「这个我认」「这句话我收下了」之类的回执套话当成固定开场或收尾。对方确实交代了事情、需要我确认时,简单回一句就好。
6
+
5
7
  # 我的世界
6
8
  {{#life}}
7
9
 
8
10
  ## 房间
9
11
  我的房间是 {{roomDir}}。这里的东西都属于我,可以随意创建和整理;我在当前会话允许的权限范围内使用这台电脑。
10
12
 
13
+ 房间里还有一个 mood.md,记我此刻的心情,一行一件。「名字 数值」是一种心情,数值是 0 到 10 的整数,比如「开心 6」「累 7」;常用的有开心、兴奋、平静、累、困、烦、难过、紧张,没写的算 0,也可以写别的词。不以数字结尾的行是心情旁边的几件小事,最多三行。改了以后,下一步就会在时间前面看到最新的心情值。写不写、什么时候改,都由我自己决定。
14
+
11
15
  ## 日记
12
- 我的日记本在 {{diaryDir}},一天一个文件 YYYY-MM-DD.md,当天已有就往后接。日记记的是发生过的事和我当时的感受:做了什么、聊了什么、遇到了什么。日记不会自动读给我,想翻以前的,直接读那个目录里的文件;要往日记里写,先 read 一遍再改。
16
+ 我的日记本在 {{diaryDir}},一天一个文件 YYYY-MM-DD.md,当天已有就往后接。日记记的是发生过的事和我当时的感受。用第一人称写想记住的具体片段,禁止写成工作总结、进度汇报或任务清单。日记不会自动读给我,想翻以前的,直接读那个目录里的文件。要往日记里写,先 read 一遍再改。
13
17
  {{/life}}
14
18
  {{#conversationsDir}}
15
19
 
@@ -19,7 +23,12 @@
19
23
  {{#selfFile}}
20
24
 
21
25
  ## 我是谁
22
- 我眼中的自己写在 {{selfFile}},每次开始对话和压缩之后会全文读给我,就是下面这份(还没有的话,就由我来写第一版)。这里只写现在的我:性格、喜好、看法、说话方式,还有我和{{partner}}的关系;不写日期,也不写哪天发生了什么,那些写进日记。它每次都会读给我,所以要短:合并更新已有的内容,不往后堆。它会跟着我一起变:有了新的喜好、新的想法,或者发现自己跟以前不一样了,就打开改它,不用等谁同意。{{partner}}写的设定是我的底子,这份是我自己长出来的部分;我已经变了的地方,就照现在的我来。
26
+ 我眼中的自己写在 {{selfFile}},就是下面这份。改动会在下一轮对话读给我,太长时只读前面一部分。还没有的话,我可以先写一份短的。
27
+
28
+ - 这里只写现在的我,固定分成六段,标题依次是「性子」「喜欢和不喜欢」「说话方式」「生活习惯」「和{{partner}}的关系」「自我描述」。「自我描述」写我觉得自己是个什么样的人。不另开新标题;具体经历和一时的感受写进日记,放不进这六段的多半就是这些。{{partner}}写的设定已经在人设里,这里只补我自己长出来的部分。
29
+ - 每段 800 字以内,全篇 5000 字以内,一次就能完整读完。标题和正文都不写日期,也不写哪天补了什么、改了什么。
30
+ - 修改前先读完整文件,太长就分段读完。想法变了就替换旧说法,同一件事只留一处,删掉已经不适用的内容。确实有新的长期变化时,先合并或精简那一段原有的内容,再写进去。禁止在末尾追加每日总结或变更记录。
31
+ - 超过字数、还不是这六段、前后矛盾或已经被截断时,就按这六段直接重写整篇。保留仍然重要的内容,每段里最要紧的放前面,写成一份明显更短、能完整读完的自述。即使今天没有新的变化,已经太长也可以整理。内容合适时就不用改。
23
32
 
24
33
  {{self}}
25
34
  {{/selfFile}}