luckytri 1.0.0 → 1.0.2

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 (139) hide show
  1. package/.github/SECURITY.md +4 -4
  2. package/README.en.md +252 -250
  3. package/README.md +252 -250
  4. package/bin/luckytri.js +5 -1
  5. package/docs/en/CHANGELOG.md +8 -0
  6. package/docs/en/connect.md +18 -18
  7. package/docs/en/guide.md +202 -216
  8. package/docs/en/npm-release.md +25 -25
  9. package/docs/zh/CHANGELOG.md +8 -0
  10. package/docs/zh/connect.md +17 -17
  11. package/docs/zh/guide.md +202 -216
  12. package/docs/zh/npm-release.md +33 -33
  13. package/package.json +110 -108
  14. package/plugins/sdk/index.d.ts +155 -155
  15. package/plugins/sdk/testing.js +58 -58
  16. package/plugins/weather/index.js +82 -82
  17. package/plugins/weather/luckytri-plugin.json +29 -29
  18. package/public/app/assets/ChatsPage-BhlJHseG.js +3 -0
  19. package/public/app/assets/Empty-DP6WMGHi.js +2 -0
  20. package/public/app/assets/Field-CtbdqaiB.js +1 -0
  21. package/public/app/assets/HeartPage-32BeTPn2.js +1 -0
  22. package/public/app/assets/LifePage-CxSm0XKI.js +1 -0
  23. package/public/app/assets/MemoryPage-BeKBcPCY.js +1 -0
  24. package/public/app/assets/NaturePage-NEPYl2HS.js +3 -0
  25. package/public/app/assets/PeoplePage-DxtpekwM.js +1 -0
  26. package/public/app/assets/PluginsPage-CVVQwEBI.css +1 -0
  27. package/public/app/assets/PluginsPage-DksEZbUU.js +2 -0
  28. package/public/app/assets/{SystemPage-CAMPoYqM.css → SystemPage-BkRu0Rvx.css} +1 -1
  29. package/public/app/assets/SystemPage-BvzJlHuY.js +1 -0
  30. package/public/app/assets/TimePage-7-awH5XL.js +3 -0
  31. package/public/app/assets/index-4rItIkD-.js +4 -0
  32. package/public/app/assets/{index-YDz1ree1.css → index-DY4e15Kh.css} +1 -1
  33. package/public/app/assets/{knowledge-DG0e0uKw.js → knowledge-C6_HvoyB.js} +1 -1
  34. package/public/app/assets/media-SMfTT-yc.js +1 -0
  35. package/public/app/index.html +3 -3
  36. package/public/guide.en.html +72 -99
  37. package/public/guide.html +44 -86
  38. package/public/tutorial.en.md +25 -39
  39. package/public/tutorial.md +25 -39
  40. package/scripts/backup.js +311 -311
  41. package/scripts/browser.js +41 -41
  42. package/scripts/import-data.js +128 -0
  43. package/scripts/launch.js +101 -94
  44. package/scripts/plugin.js +150 -150
  45. package/scripts/reset-password.js +22 -0
  46. package/scripts/runtime.js +25 -25
  47. package/scripts/service.js +56 -47
  48. package/scripts/setup.js +50 -50
  49. package/scripts/start-server.js +41 -41
  50. package/scripts/stop.js +36 -36
  51. package/server/app.js +112 -96
  52. package/server/auth.js +217 -0
  53. package/server/channels/contract.js +57 -57
  54. package/server/channels/hub.js +165 -165
  55. package/server/channels/index.js +28 -25
  56. package/server/channels/onebot/index.js +335 -336
  57. package/server/channels/onebot/token.js +22 -3
  58. package/server/core/capabilities.js +208 -208
  59. package/server/core/events.js +64 -60
  60. package/server/core/image-preprocessor.js +208 -208
  61. package/server/core/model-manager.js +1213 -1213
  62. package/server/core/net-guard.js +49 -49
  63. package/server/core/orchestrator.js +569 -569
  64. package/server/core/perceivers.js +91 -91
  65. package/server/core/persona-manager.js +243 -243
  66. package/server/core/repository.js +293 -293
  67. package/server/core/response-validator.js +508 -508
  68. package/server/core/turn-processor.js +630 -630
  69. package/server/core/turn.js +236 -236
  70. package/server/core/vision-manager.js +633 -633
  71. package/server/i18n/errors.js +548 -497
  72. package/server/i18n/labels.js +649 -653
  73. package/server/index.js +151 -102
  74. package/server/knowledge/manager.js +386 -386
  75. package/server/knowledge/schema.js +12 -8
  76. package/server/local-access.js +32 -0
  77. package/server/mind/anticipations.js +507 -507
  78. package/server/mind/api.js +703 -703
  79. package/server/mind/budget.js +152 -152
  80. package/server/mind/context-selection.js +61 -61
  81. package/server/mind/day-planner.js +324 -324
  82. package/server/mind/evidence.js +148 -148
  83. package/server/mind/index.js +445 -445
  84. package/server/mind/life/diary.js +786 -786
  85. package/server/mind/life/index.js +1049 -1049
  86. package/server/mind/observations.js +84 -84
  87. package/server/mind/own-day.js +324 -324
  88. package/server/mind/own-voice.js +318 -318
  89. package/server/mind/senses.js +53 -53
  90. package/server/mind/time/activity-clock.js +196 -196
  91. package/server/mind/time/availability.js +69 -69
  92. package/server/mind/time/commitment-review.js +198 -198
  93. package/server/mind/time/executor.js +512 -512
  94. package/server/mind/time/experiences.js +128 -128
  95. package/server/mind/time/games.js +562 -562
  96. package/server/mind/time/index.js +739 -739
  97. package/server/mind/time/intent.js +166 -166
  98. package/server/mind/time/kinds.js +171 -171
  99. package/server/mind/time/plugin-activity.js +207 -207
  100. package/server/mind/time/tasks.js +587 -587
  101. package/server/mind/util.js +110 -110
  102. package/server/mind/view.js +273 -273
  103. package/server/paths.js +102 -102
  104. package/server/plugins/api.js +204 -204
  105. package/server/plugins/host.js +967 -967
  106. package/server/plugins/install.js +295 -295
  107. package/server/plugins/manifest.js +201 -201
  108. package/server/plugins/permissions.js +42 -42
  109. package/server/plugins/runner/guard.mjs +36 -36
  110. package/server/plugins/runner/worker.mjs +250 -250
  111. package/server/plugins/schema.js +91 -91
  112. package/server/plugins/zip.js +112 -112
  113. package/server/startup-lock.js +118 -118
  114. package/server/storage/archive.js +242 -241
  115. package/server/storage/backup-cleanup-worker.js +8 -8
  116. package/server/storage/backup-cleanup.js +415 -414
  117. package/server/storage/backup-lock.js +76 -76
  118. package/server/storage/backup-scheduler.js +131 -131
  119. package/server/storage/data-package.js +298 -0
  120. package/server/storage/data-transfer-api.js +50 -0
  121. package/server/storage/data-transfer-worker.js +18 -0
  122. package/server/storage/data-transfer.js +415 -0
  123. package/server/storage/store.js +202 -199
  124. package/server/studio/readiness.js +181 -190
  125. package/server/studio/settings.js +236 -236
  126. package/public/app/assets/ChatsPage-C-FcRapR.js +0 -3
  127. package/public/app/assets/Empty-CpP5kQHH.js +0 -2
  128. package/public/app/assets/Field-D4gY-INU.js +0 -1
  129. package/public/app/assets/HeartPage-CPy_thQd.js +0 -1
  130. package/public/app/assets/LifePage-CxWvwmSf.js +0 -1
  131. package/public/app/assets/MemoryPage-DC4rhQ68.js +0 -1
  132. package/public/app/assets/NaturePage-IvYw04Zq.js +0 -3
  133. package/public/app/assets/PeoplePage-Cqefm9-q.js +0 -1
  134. package/public/app/assets/PluginsPage-DKSaKvXb.js +0 -2
  135. package/public/app/assets/PluginsPage-HyBe5D8w.css +0 -1
  136. package/public/app/assets/SystemPage-CJmtJkrK.js +0 -1
  137. package/public/app/assets/TimePage-Cw44inM4.js +0 -3
  138. package/public/app/assets/index-BheRW-1t.js +0 -4
  139. package/public/app/assets/media-BzPDBm7e.js +0 -1
@@ -1,53 +1,53 @@
1
- import { text } from "./util.js";
2
-
3
- const LIMIT = 4;
4
- const LINE = 80;
5
-
6
- // What the world is telling her right now: weather, a song, a room.
7
- // Kept in memory, never written into who she is. A private line stays out of
8
- // group conversations.
9
- export class Senses {
10
- constructor() {
11
- this.rows = new Map();
12
- }
13
- set(pluginId, key, sense, now = Date.now()) {
14
- const id = `${pluginId}:${String(key || "now").slice(0, 40)}`;
15
- const line = text(sense?.text, LINE);
16
- if (!line) {
17
- this.rows.delete(id);
18
- return;
19
- }
20
- const ttl = Number(sense?.ttlMinutes);
21
- this.rows.set(id, {
22
- pluginId,
23
- text: line,
24
- discretion: sense?.discretion === "private" ? "private" : "open",
25
- until:
26
- Number.isFinite(ttl) && ttl > 0 ? now + Math.min(ttl, 1440) * 60000 : 0,
27
- });
28
- }
29
- clear(pluginId, key) {
30
- if (key == null) {
31
- for (const [id, row] of this.rows)
32
- if (row.pluginId === pluginId) this.rows.delete(id);
33
- return;
34
- }
35
- this.rows.delete(`${pluginId}:${String(key).slice(0, 40)}`);
36
- }
37
- clearPlugin(pluginId) {
38
- this.clear(pluginId, null);
39
- }
40
- lines({ kind = "group", now = Date.now() } = {}) {
41
- const out = [];
42
- for (const [id, row] of this.rows) {
43
- if (row.until && row.until <= now) {
44
- this.rows.delete(id);
45
- continue;
46
- }
47
- if (kind === "group" && row.discretion === "private") continue;
48
- out.push(row.text);
49
- if (out.length >= LIMIT) break;
50
- }
51
- return out;
52
- }
53
- }
1
+ import { text } from "./util.js";
2
+
3
+ const LIMIT = 4;
4
+ const LINE = 80;
5
+
6
+ // What the world is telling her right now: weather, a song, a room.
7
+ // Kept in memory, never written into who she is. A private line stays out of
8
+ // group conversations.
9
+ export class Senses {
10
+ constructor() {
11
+ this.rows = new Map();
12
+ }
13
+ set(pluginId, key, sense, now = Date.now()) {
14
+ const id = `${pluginId}:${String(key || "now").slice(0, 40)}`;
15
+ const line = text(sense?.text, LINE);
16
+ if (!line) {
17
+ this.rows.delete(id);
18
+ return;
19
+ }
20
+ const ttl = Number(sense?.ttlMinutes);
21
+ this.rows.set(id, {
22
+ pluginId,
23
+ text: line,
24
+ discretion: sense?.discretion === "private" ? "private" : "open",
25
+ until:
26
+ Number.isFinite(ttl) && ttl > 0 ? now + Math.min(ttl, 1440) * 60000 : 0,
27
+ });
28
+ }
29
+ clear(pluginId, key) {
30
+ if (key == null) {
31
+ for (const [id, row] of this.rows)
32
+ if (row.pluginId === pluginId) this.rows.delete(id);
33
+ return;
34
+ }
35
+ this.rows.delete(`${pluginId}:${String(key).slice(0, 40)}`);
36
+ }
37
+ clearPlugin(pluginId) {
38
+ this.clear(pluginId, null);
39
+ }
40
+ lines({ kind = "group", now = Date.now() } = {}) {
41
+ const out = [];
42
+ for (const [id, row] of this.rows) {
43
+ if (row.until && row.until <= now) {
44
+ this.rows.delete(id);
45
+ continue;
46
+ }
47
+ if (kind === "group" && row.discretion === "private") continue;
48
+ out.push(row.text);
49
+ if (out.length >= LIMIT) break;
50
+ }
51
+ return out;
52
+ }
53
+ }
@@ -1,196 +1,196 @@
1
- import { text } from "../util.js";
2
- import { activityMinutes } from "./kinds.js";
3
- const MINUTE = 60000;
4
- export function activityEstimate(activity, hint, speed = 1.25) {
5
- const fallback = activityMinutes(activity),
6
- proposed = Number(hint?.minutes);
7
- const referenceMinutes =
8
- Number.isFinite(proposed) && proposed >= 5 && proposed <= 240
9
- ? proposed
10
- : fallback[0];
11
- const pace =
12
- Number.isFinite(speed) && speed >= 1 && speed <= 2 ? speed : 1.25;
13
- return {
14
- referenceMinutes,
15
- plannedMs: Math.ceil((referenceMinutes * MINUTE) / pace),
16
- speed: pace,
17
- basis: text(hint?.basis, 240) || fallback[1],
18
- scope: "本段",
19
- chapterMinutes:
20
- Number.isFinite(hint?.chapterMinutes) &&
21
- hint.chapterMinutes >= referenceMinutes &&
22
- hint.chapterMinutes <= 6000
23
- ? hint.chapterMinutes
24
- : null,
25
- };
26
- }
27
- export class ActivityClock {
28
- constructor(time) {
29
- this.time = time;
30
- this.db = time.db;
31
- }
32
- committed(id) {
33
- return this.db
34
- .prepare(
35
- "SELECT COALESCE(SUM(engaged_ms),0) n FROM mind_time_spans WHERE task_id=?",
36
- )
37
- .get(id).n;
38
- }
39
- record(span, ms) {
40
- if (ms > 0)
41
- this.db
42
- .prepare(
43
- "INSERT OR IGNORE INTO mind_time_activity_ticks(span_id,started,ended) VALUES(?,?,?)",
44
- )
45
- .run(span.id, span.updated, span.updated + ms);
46
- }
47
- today(spanId, start, now) {
48
- return this.db
49
- .prepare(
50
- "SELECT COALESCE(SUM(MAX(0,MIN(ended,?)-MAX(started,?))),0) n FROM mind_time_activity_ticks WHERE span_id=? AND ended>? AND started<?",
51
- )
52
- .get(now, start, spanId, start, now).n;
53
- }
54
- credit(task, delta) {
55
- const clock = task.checkpoint?.activityClock;
56
- if (
57
- !clock ||
58
- clock.phase !== "engaged" ||
59
- task.lease ||
60
- task.state !== "doing"
61
- )
62
- return 0;
63
- return Math.max(
64
- 0,
65
- Math.min(
66
- delta,
67
- Math.round(
68
- clock.plannedMs - (this.committed(task.id) - clock.baselineMs),
69
- ),
70
- ),
71
- );
72
- }
73
- elapsed(task, now = this.time.now()) {
74
- const total = this.committed(task.id),
75
- span = this.db
76
- .prepare(
77
- "SELECT updated FROM mind_time_spans WHERE task_id=? AND ended IS NULL",
78
- )
79
- .get(task.id);
80
- return (
81
- total +
82
- (span
83
- ? this.credit(task, Math.max(0, Math.min(MINUTE, now - span.updated)))
84
- : 0)
85
- );
86
- }
87
- plan(task, hint, now) {
88
- const estimate = activityEstimate(
89
- task.activity,
90
- hint,
91
- this.time.settings().paceSpeed,
92
- );
93
- if (task.checkpoint.schedule?.chosenAt) {
94
- const used =
95
- this.db
96
- .prepare(
97
- "SELECT engaged_ms FROM mind_time_spans WHERE task_id=? AND ended IS NULL",
98
- )
99
- .get(task.id)?.engaged_ms || 0;
100
- estimate.plannedMs = Math.min(
101
- estimate.plannedMs,
102
- Math.max(MINUTE, this.time.focusMs(task) - used),
103
- );
104
- }
105
- return {
106
- version: 1,
107
- phase: "engaged",
108
- ...estimate,
109
- baselineMs: this.committed(task.id),
110
- started: now,
111
- };
112
- }
113
- view(task, now = this.time.now()) {
114
- const clock = task.checkpoint?.activityClock;
115
- if (!clock)
116
- return {
117
- phase:
118
- !this.time.fixtureImmediate &&
119
- this.time.operationElapsed(task.id, now) > 0
120
- ? "legacy"
121
- : "unstarted",
122
- elapsedMs: this.time.fixtureImmediate
123
- ? this.time.operationElapsed(task.id, now)
124
- : null,
125
- plannedMs: null,
126
- };
127
- const elapsedMs = this.elapsed(task, now),
128
- stepMs = Math.max(0, elapsedMs - clock.baselineMs);
129
- return {
130
- phase: clock.phase,
131
- elapsedMs,
132
- stepMs,
133
- plannedMs: clock.plannedMs,
134
- remainingMs: Math.max(0, Math.round(clock.plannedMs - stepMs)),
135
- progress: clock.plannedMs > 0 ? Math.min(1, stepMs / clock.plannedMs) : 0,
136
- referenceMinutes: clock.referenceMinutes,
137
- speed: clock.speed,
138
- basis: clock.basis,
139
- chapterMinutes: clock.chapterMinutes,
140
- };
141
- }
142
- remaining(task, now) {
143
- return this.view(task, now).remainingMs || 0;
144
- }
145
- release(task, checkpoint, now) {
146
- const slot = checkpoint.schedule,
147
- clock = checkpoint.activityClock;
148
- if (
149
- task.activity !== "game" &&
150
- slot?.chosenAt &&
151
- clock.phase === "engaged"
152
- ) {
153
- const base = Math.max(clock.baselineMs, slot.baselineMs || 0);
154
- const remainingAtStart = Math.max(
155
- 0,
156
- clock.plannedMs - (base - clock.baselineMs),
157
- );
158
- const quota = Math.max(
159
- MINUTE,
160
- this.time.focusMs(task) - Math.max(0, base - (slot.baselineMs || 0)),
161
- );
162
- if (remainingAtStart > quota)
163
- checkpoint = {
164
- ...checkpoint,
165
- activityClock: {
166
- ...clock,
167
- originalEstimateMs: clock.originalEstimateMs || clock.plannedMs,
168
- baselineMs: base,
169
- plannedMs: quota,
170
- },
171
- };
172
- }
173
- this.db
174
- .prepare(
175
- "UPDATE mind_time_spans SET updated=? WHERE task_id=? AND ended IS NULL",
176
- )
177
- .run(now, task.id);
178
- const rest = this.time.focusMs(task),
179
- remaining = Math.max(
180
- 0,
181
- Math.round(
182
- checkpoint.activityClock.plannedMs -
183
- (this.committed(task.id) - checkpoint.activityClock.baselineMs),
184
- ),
185
- );
186
- this.db
187
- .prepare(
188
- "UPDATE mind_time_tasks SET checkpoint=?,next_step=?,lease=NULL,lease_at=NULL,revision=revision+1 WHERE id=?",
189
- )
190
- .run(
191
- JSON.stringify(checkpoint),
192
- now + Math.min(rest, remaining),
193
- task.id,
194
- );
195
- }
196
- }
1
+ import { text } from "../util.js";
2
+ import { activityMinutes } from "./kinds.js";
3
+ const MINUTE = 60000;
4
+ export function activityEstimate(activity, hint, speed = 1.25) {
5
+ const fallback = activityMinutes(activity),
6
+ proposed = Number(hint?.minutes);
7
+ const referenceMinutes =
8
+ Number.isFinite(proposed) && proposed >= 5 && proposed <= 240
9
+ ? proposed
10
+ : fallback[0];
11
+ const pace =
12
+ Number.isFinite(speed) && speed >= 1 && speed <= 2 ? speed : 1.25;
13
+ return {
14
+ referenceMinutes,
15
+ plannedMs: Math.ceil((referenceMinutes * MINUTE) / pace),
16
+ speed: pace,
17
+ basis: text(hint?.basis, 240) || fallback[1],
18
+ scope: "本段",
19
+ chapterMinutes:
20
+ Number.isFinite(hint?.chapterMinutes) &&
21
+ hint.chapterMinutes >= referenceMinutes &&
22
+ hint.chapterMinutes <= 6000
23
+ ? hint.chapterMinutes
24
+ : null,
25
+ };
26
+ }
27
+ export class ActivityClock {
28
+ constructor(time) {
29
+ this.time = time;
30
+ this.db = time.db;
31
+ }
32
+ committed(id) {
33
+ return this.db
34
+ .prepare(
35
+ "SELECT COALESCE(SUM(engaged_ms),0) n FROM mind_time_spans WHERE task_id=?",
36
+ )
37
+ .get(id).n;
38
+ }
39
+ record(span, ms) {
40
+ if (ms > 0)
41
+ this.db
42
+ .prepare(
43
+ "INSERT OR IGNORE INTO mind_time_activity_ticks(span_id,started,ended) VALUES(?,?,?)",
44
+ )
45
+ .run(span.id, span.updated, span.updated + ms);
46
+ }
47
+ today(spanId, start, now) {
48
+ return this.db
49
+ .prepare(
50
+ "SELECT COALESCE(SUM(MAX(0,MIN(ended,?)-MAX(started,?))),0) n FROM mind_time_activity_ticks WHERE span_id=? AND ended>? AND started<?",
51
+ )
52
+ .get(now, start, spanId, start, now).n;
53
+ }
54
+ credit(task, delta) {
55
+ const clock = task.checkpoint?.activityClock;
56
+ if (
57
+ !clock ||
58
+ clock.phase !== "engaged" ||
59
+ task.lease ||
60
+ task.state !== "doing"
61
+ )
62
+ return 0;
63
+ return Math.max(
64
+ 0,
65
+ Math.min(
66
+ delta,
67
+ Math.round(
68
+ clock.plannedMs - (this.committed(task.id) - clock.baselineMs),
69
+ ),
70
+ ),
71
+ );
72
+ }
73
+ elapsed(task, now = this.time.now()) {
74
+ const total = this.committed(task.id),
75
+ span = this.db
76
+ .prepare(
77
+ "SELECT updated FROM mind_time_spans WHERE task_id=? AND ended IS NULL",
78
+ )
79
+ .get(task.id);
80
+ return (
81
+ total +
82
+ (span
83
+ ? this.credit(task, Math.max(0, Math.min(MINUTE, now - span.updated)))
84
+ : 0)
85
+ );
86
+ }
87
+ plan(task, hint, now) {
88
+ const estimate = activityEstimate(
89
+ task.activity,
90
+ hint,
91
+ this.time.settings().paceSpeed,
92
+ );
93
+ if (task.checkpoint.schedule?.chosenAt) {
94
+ const used =
95
+ this.db
96
+ .prepare(
97
+ "SELECT engaged_ms FROM mind_time_spans WHERE task_id=? AND ended IS NULL",
98
+ )
99
+ .get(task.id)?.engaged_ms || 0;
100
+ estimate.plannedMs = Math.min(
101
+ estimate.plannedMs,
102
+ Math.max(MINUTE, this.time.focusMs(task) - used),
103
+ );
104
+ }
105
+ return {
106
+ version: 1,
107
+ phase: "engaged",
108
+ ...estimate,
109
+ baselineMs: this.committed(task.id),
110
+ started: now,
111
+ };
112
+ }
113
+ view(task, now = this.time.now()) {
114
+ const clock = task.checkpoint?.activityClock;
115
+ if (!clock)
116
+ return {
117
+ phase:
118
+ !this.time.fixtureImmediate &&
119
+ this.time.operationElapsed(task.id, now) > 0
120
+ ? "legacy"
121
+ : "unstarted",
122
+ elapsedMs: this.time.fixtureImmediate
123
+ ? this.time.operationElapsed(task.id, now)
124
+ : null,
125
+ plannedMs: null,
126
+ };
127
+ const elapsedMs = this.elapsed(task, now),
128
+ stepMs = Math.max(0, elapsedMs - clock.baselineMs);
129
+ return {
130
+ phase: clock.phase,
131
+ elapsedMs,
132
+ stepMs,
133
+ plannedMs: clock.plannedMs,
134
+ remainingMs: Math.max(0, Math.round(clock.plannedMs - stepMs)),
135
+ progress: clock.plannedMs > 0 ? Math.min(1, stepMs / clock.plannedMs) : 0,
136
+ referenceMinutes: clock.referenceMinutes,
137
+ speed: clock.speed,
138
+ basis: clock.basis,
139
+ chapterMinutes: clock.chapterMinutes,
140
+ };
141
+ }
142
+ remaining(task, now) {
143
+ return this.view(task, now).remainingMs || 0;
144
+ }
145
+ release(task, checkpoint, now) {
146
+ const slot = checkpoint.schedule,
147
+ clock = checkpoint.activityClock;
148
+ if (
149
+ task.activity !== "game" &&
150
+ slot?.chosenAt &&
151
+ clock.phase === "engaged"
152
+ ) {
153
+ const base = Math.max(clock.baselineMs, slot.baselineMs || 0);
154
+ const remainingAtStart = Math.max(
155
+ 0,
156
+ clock.plannedMs - (base - clock.baselineMs),
157
+ );
158
+ const quota = Math.max(
159
+ MINUTE,
160
+ this.time.focusMs(task) - Math.max(0, base - (slot.baselineMs || 0)),
161
+ );
162
+ if (remainingAtStart > quota)
163
+ checkpoint = {
164
+ ...checkpoint,
165
+ activityClock: {
166
+ ...clock,
167
+ originalEstimateMs: clock.originalEstimateMs || clock.plannedMs,
168
+ baselineMs: base,
169
+ plannedMs: quota,
170
+ },
171
+ };
172
+ }
173
+ this.db
174
+ .prepare(
175
+ "UPDATE mind_time_spans SET updated=? WHERE task_id=? AND ended IS NULL",
176
+ )
177
+ .run(now, task.id);
178
+ const rest = this.time.focusMs(task),
179
+ remaining = Math.max(
180
+ 0,
181
+ Math.round(
182
+ checkpoint.activityClock.plannedMs -
183
+ (this.committed(task.id) - checkpoint.activityClock.baselineMs),
184
+ ),
185
+ );
186
+ this.db
187
+ .prepare(
188
+ "UPDATE mind_time_tasks SET checkpoint=?,next_step=?,lease=NULL,lease_at=NULL,revision=revision+1 WHERE id=?",
189
+ )
190
+ .run(
191
+ JSON.stringify(checkpoint),
192
+ now + Math.min(rest, remaining),
193
+ task.id,
194
+ );
195
+ }
196
+ }
@@ -1,69 +1,69 @@
1
- import { gameTopic } from "./intent.js";
2
- import { isExecutable, needsEnergy } from "./kinds.js";
3
- export function unsupportedAction(task) {
4
- return task.activity === "unknown" &&
5
- /点.{0,8}外卖|下单|购买|实拍|拍照给|尝.{0,6}(?:味道|好吃)/.test(task.title)
6
- ? "除了她此刻真正能做的事,没有下单或实拍的执行能力,需要调整这条约定;仍未兑现"
7
- : "";
8
- }
9
- export function gameName(time, task) {
10
- return (
11
- task.checkpoint.topic ||
12
- gameTopic(task.title) ||
13
- (task.project_id && time.works.project(task.project_id)?.bible?.topic) ||
14
- ""
15
- );
16
- }
17
- export function executionBlock(time, task, now) {
18
- const life = time.search.life;
19
- const unsupported = unsupportedAction(task);
20
- if (unsupported) return unsupported;
21
- if (task.activity === "unknown" || !isExecutable(task.activity))
22
- return task.activity === "unknown"
23
- ? "需要把行动内容想具体"
24
- : "所需插件已停用";
25
- if (!time.allowed(task, now)) return "来源已经撤销";
26
- if (task.depends_on && time.tasks.get(task.depends_on)?.state !== "done")
27
- return "等待前一件事完成";
28
- if (
29
- task.checkpoint.pendingStep?.chunk &&
30
- !time.db
31
- .prepare("SELECT 1 FROM core_chunks WHERE id=?")
32
- .get(task.checkpoint.pendingStep.chunk.id)
33
- )
34
- return "书架这段内容已不可用";
35
- if (life?.closed) return "实例已停止";
36
- if (life && (!life.settings().solitude || life.repo.store.settings().demo))
37
- return "自己的活动目前关闭";
38
- if (
39
- task.session_id &&
40
- life &&
41
- !life.chat.enabled(task.session_id, { simulated: false })
42
- )
43
- return "来源会话目前未启用";
44
- if (!task.checkpoint.pendingStep && !time.mind.budget.allows("inner", now))
45
- return "今日独处预算不足";
46
- if (needsEnergy(task.activity) && time.mind.affect.state(now).energy < 0.18)
47
- return "精力较低,先恢复一会儿再投入";
48
- if (
49
- task.activity === "read" &&
50
- !task.checkpoint.pendingStep?.chunk &&
51
- !time.mind.reading.unreadCount()
52
- )
53
- return "书架没有可读资料";
54
- if (task.activity === "game") {
55
- if (!gameName(time, task)) return "需要自己选定要玩的游戏";
56
- if (!task.checkpoint.sourceIds?.length) {
57
- const why = time.search.ready(now);
58
- if (why) return why;
59
- }
60
- }
61
- if (life && !task.checkpoint.pendingStep) {
62
- try {
63
- life.profile();
64
- } catch {
65
- return "等待可用模型";
66
- }
67
- }
68
- return "";
69
- }
1
+ import { gameTopic } from "./intent.js";
2
+ import { isExecutable, needsEnergy } from "./kinds.js";
3
+ export function unsupportedAction(task) {
4
+ return task.activity === "unknown" &&
5
+ /点.{0,8}外卖|下单|购买|实拍|拍照给|尝.{0,6}(?:味道|好吃)/.test(task.title)
6
+ ? "除了她此刻真正能做的事,没有下单或实拍的执行能力,需要调整这条约定;仍未兑现"
7
+ : "";
8
+ }
9
+ export function gameName(time, task) {
10
+ return (
11
+ task.checkpoint.topic ||
12
+ gameTopic(task.title) ||
13
+ (task.project_id && time.works.project(task.project_id)?.bible?.topic) ||
14
+ ""
15
+ );
16
+ }
17
+ export function executionBlock(time, task, now) {
18
+ const life = time.search.life;
19
+ const unsupported = unsupportedAction(task);
20
+ if (unsupported) return unsupported;
21
+ if (task.activity === "unknown" || !isExecutable(task.activity))
22
+ return task.activity === "unknown"
23
+ ? "需要把行动内容想具体"
24
+ : "所需插件已停用";
25
+ if (!time.allowed(task, now)) return "来源已经撤销";
26
+ if (task.depends_on && time.tasks.get(task.depends_on)?.state !== "done")
27
+ return "等待前一件事完成";
28
+ if (
29
+ task.checkpoint.pendingStep?.chunk &&
30
+ !time.db
31
+ .prepare("SELECT 1 FROM core_chunks WHERE id=?")
32
+ .get(task.checkpoint.pendingStep.chunk.id)
33
+ )
34
+ return "书架这段内容已不可用";
35
+ if (life?.closed) return "实例已停止";
36
+ if (life && (!life.settings().solitude || life.repo.store.settings().demo))
37
+ return "自己的活动目前关闭";
38
+ if (
39
+ task.session_id &&
40
+ life &&
41
+ !life.chat.enabled(task.session_id, { simulated: false })
42
+ )
43
+ return "来源会话目前未启用";
44
+ if (!task.checkpoint.pendingStep && !time.mind.budget.allows("inner", now))
45
+ return "今日独处预算不足";
46
+ if (needsEnergy(task.activity) && time.mind.affect.state(now).energy < 0.18)
47
+ return "精力较低,先恢复一会儿再投入";
48
+ if (
49
+ task.activity === "read" &&
50
+ !task.checkpoint.pendingStep?.chunk &&
51
+ !time.mind.reading.unreadCount()
52
+ )
53
+ return "书架没有可读资料";
54
+ if (task.activity === "game") {
55
+ if (!gameName(time, task)) return "需要自己选定要玩的游戏";
56
+ if (!task.checkpoint.sourceIds?.length) {
57
+ const why = time.search.ready(now);
58
+ if (why) return why;
59
+ }
60
+ }
61
+ if (life && !task.checkpoint.pendingStep) {
62
+ try {
63
+ life.profile();
64
+ } catch {
65
+ return "等待可用模型";
66
+ }
67
+ }
68
+ return "";
69
+ }