luckytri 1.0.0 → 1.0.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.
Files changed (133) 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 +192 -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 +192 -216
  12. package/docs/zh/npm-release.md +33 -33
  13. package/package.json +109 -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-B9Odvzfz.js +3 -0
  19. package/public/app/assets/Empty-SkA8PyMo.js +2 -0
  20. package/public/app/assets/Field-BjLhi8pL.js +1 -0
  21. package/public/app/assets/HeartPage-CscKqMsr.js +1 -0
  22. package/public/app/assets/LifePage-BHCmBHlH.js +1 -0
  23. package/public/app/assets/MemoryPage-Bhs2xa1k.js +1 -0
  24. package/public/app/assets/NaturePage-CaPIar_5.js +3 -0
  25. package/public/app/assets/PeoplePage-CuwSSVeX.js +1 -0
  26. package/public/app/assets/PluginsPage-BhVm1SUi.js +2 -0
  27. package/public/app/assets/PluginsPage-CVVQwEBI.css +1 -0
  28. package/public/app/assets/{SystemPage-CAMPoYqM.css → SystemPage-5yYqyUgR.css} +1 -1
  29. package/public/app/assets/SystemPage-Chm5fiGP.js +1 -0
  30. package/public/app/assets/TimePage-BUm4eUzB.js +3 -0
  31. package/public/app/assets/index-BIAdfObg.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-DNDLyN9m.js} +1 -1
  34. package/public/app/assets/media-CKVAvML2.js +1 -0
  35. package/public/app/index.html +3 -3
  36. package/public/guide.en.html +32 -99
  37. package/public/guide.html +21 -86
  38. package/public/tutorial.en.md +15 -39
  39. package/public/tutorial.md +15 -39
  40. package/scripts/backup.js +311 -311
  41. package/scripts/browser.js +41 -41
  42. package/scripts/launch.js +101 -94
  43. package/scripts/plugin.js +150 -150
  44. package/scripts/reset-password.js +22 -0
  45. package/scripts/runtime.js +25 -25
  46. package/scripts/service.js +56 -47
  47. package/scripts/setup.js +50 -50
  48. package/scripts/start-server.js +41 -41
  49. package/scripts/stop.js +36 -36
  50. package/server/app.js +110 -96
  51. package/server/auth.js +217 -0
  52. package/server/channels/contract.js +57 -57
  53. package/server/channels/hub.js +165 -165
  54. package/server/channels/index.js +28 -25
  55. package/server/channels/onebot/index.js +335 -336
  56. package/server/channels/onebot/token.js +22 -3
  57. package/server/core/capabilities.js +208 -208
  58. package/server/core/events.js +64 -60
  59. package/server/core/image-preprocessor.js +208 -208
  60. package/server/core/model-manager.js +1213 -1213
  61. package/server/core/net-guard.js +49 -49
  62. package/server/core/orchestrator.js +569 -569
  63. package/server/core/perceivers.js +91 -91
  64. package/server/core/persona-manager.js +243 -243
  65. package/server/core/repository.js +293 -293
  66. package/server/core/response-validator.js +508 -508
  67. package/server/core/turn-processor.js +630 -630
  68. package/server/core/turn.js +236 -236
  69. package/server/core/vision-manager.js +633 -633
  70. package/server/i18n/errors.js +512 -497
  71. package/server/i18n/labels.js +649 -653
  72. package/server/index.js +107 -102
  73. package/server/knowledge/manager.js +386 -386
  74. package/server/local-access.js +32 -0
  75. package/server/mind/anticipations.js +507 -507
  76. package/server/mind/api.js +703 -703
  77. package/server/mind/budget.js +152 -152
  78. package/server/mind/context-selection.js +61 -61
  79. package/server/mind/day-planner.js +324 -324
  80. package/server/mind/evidence.js +148 -148
  81. package/server/mind/index.js +445 -445
  82. package/server/mind/life/diary.js +786 -786
  83. package/server/mind/life/index.js +1049 -1049
  84. package/server/mind/observations.js +84 -84
  85. package/server/mind/own-day.js +324 -324
  86. package/server/mind/own-voice.js +318 -318
  87. package/server/mind/senses.js +53 -53
  88. package/server/mind/time/activity-clock.js +196 -196
  89. package/server/mind/time/availability.js +69 -69
  90. package/server/mind/time/commitment-review.js +198 -198
  91. package/server/mind/time/executor.js +512 -512
  92. package/server/mind/time/experiences.js +128 -128
  93. package/server/mind/time/games.js +562 -562
  94. package/server/mind/time/index.js +739 -739
  95. package/server/mind/time/intent.js +166 -166
  96. package/server/mind/time/kinds.js +171 -171
  97. package/server/mind/time/plugin-activity.js +207 -207
  98. package/server/mind/time/tasks.js +587 -587
  99. package/server/mind/util.js +110 -110
  100. package/server/mind/view.js +273 -273
  101. package/server/paths.js +102 -102
  102. package/server/plugins/api.js +204 -204
  103. package/server/plugins/host.js +967 -967
  104. package/server/plugins/install.js +295 -295
  105. package/server/plugins/manifest.js +201 -201
  106. package/server/plugins/permissions.js +42 -42
  107. package/server/plugins/runner/guard.mjs +36 -36
  108. package/server/plugins/runner/worker.mjs +250 -250
  109. package/server/plugins/schema.js +91 -91
  110. package/server/plugins/zip.js +112 -112
  111. package/server/startup-lock.js +118 -118
  112. package/server/storage/archive.js +241 -241
  113. package/server/storage/backup-cleanup-worker.js +8 -8
  114. package/server/storage/backup-cleanup.js +414 -414
  115. package/server/storage/backup-lock.js +76 -76
  116. package/server/storage/backup-scheduler.js +131 -131
  117. package/server/storage/store.js +199 -199
  118. package/server/studio/readiness.js +181 -190
  119. package/server/studio/settings.js +236 -236
  120. package/public/app/assets/ChatsPage-C-FcRapR.js +0 -3
  121. package/public/app/assets/Empty-CpP5kQHH.js +0 -2
  122. package/public/app/assets/Field-D4gY-INU.js +0 -1
  123. package/public/app/assets/HeartPage-CPy_thQd.js +0 -1
  124. package/public/app/assets/LifePage-CxWvwmSf.js +0 -1
  125. package/public/app/assets/MemoryPage-DC4rhQ68.js +0 -1
  126. package/public/app/assets/NaturePage-IvYw04Zq.js +0 -3
  127. package/public/app/assets/PeoplePage-Cqefm9-q.js +0 -1
  128. package/public/app/assets/PluginsPage-DKSaKvXb.js +0 -2
  129. package/public/app/assets/PluginsPage-HyBe5D8w.css +0 -1
  130. package/public/app/assets/SystemPage-CJmtJkrK.js +0 -1
  131. package/public/app/assets/TimePage-Cw44inM4.js +0 -3
  132. package/public/app/assets/index-BheRW-1t.js +0 -4
  133. 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
+ }