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.
- package/.github/SECURITY.md +4 -4
- package/README.en.md +252 -250
- package/README.md +252 -250
- package/bin/luckytri.js +5 -1
- package/docs/en/CHANGELOG.md +8 -0
- package/docs/en/connect.md +18 -18
- package/docs/en/guide.md +202 -216
- package/docs/en/npm-release.md +25 -25
- package/docs/zh/CHANGELOG.md +8 -0
- package/docs/zh/connect.md +17 -17
- package/docs/zh/guide.md +202 -216
- package/docs/zh/npm-release.md +33 -33
- package/package.json +110 -108
- package/plugins/sdk/index.d.ts +155 -155
- package/plugins/sdk/testing.js +58 -58
- package/plugins/weather/index.js +82 -82
- package/plugins/weather/luckytri-plugin.json +29 -29
- package/public/app/assets/ChatsPage-BhlJHseG.js +3 -0
- package/public/app/assets/Empty-DP6WMGHi.js +2 -0
- package/public/app/assets/Field-CtbdqaiB.js +1 -0
- package/public/app/assets/HeartPage-32BeTPn2.js +1 -0
- package/public/app/assets/LifePage-CxSm0XKI.js +1 -0
- package/public/app/assets/MemoryPage-BeKBcPCY.js +1 -0
- package/public/app/assets/NaturePage-NEPYl2HS.js +3 -0
- package/public/app/assets/PeoplePage-DxtpekwM.js +1 -0
- package/public/app/assets/PluginsPage-CVVQwEBI.css +1 -0
- package/public/app/assets/PluginsPage-DksEZbUU.js +2 -0
- package/public/app/assets/{SystemPage-CAMPoYqM.css → SystemPage-BkRu0Rvx.css} +1 -1
- package/public/app/assets/SystemPage-BvzJlHuY.js +1 -0
- package/public/app/assets/TimePage-7-awH5XL.js +3 -0
- package/public/app/assets/index-4rItIkD-.js +4 -0
- package/public/app/assets/{index-YDz1ree1.css → index-DY4e15Kh.css} +1 -1
- package/public/app/assets/{knowledge-DG0e0uKw.js → knowledge-C6_HvoyB.js} +1 -1
- package/public/app/assets/media-SMfTT-yc.js +1 -0
- package/public/app/index.html +3 -3
- package/public/guide.en.html +72 -99
- package/public/guide.html +44 -86
- package/public/tutorial.en.md +25 -39
- package/public/tutorial.md +25 -39
- package/scripts/backup.js +311 -311
- package/scripts/browser.js +41 -41
- package/scripts/import-data.js +128 -0
- package/scripts/launch.js +101 -94
- package/scripts/plugin.js +150 -150
- package/scripts/reset-password.js +22 -0
- package/scripts/runtime.js +25 -25
- package/scripts/service.js +56 -47
- package/scripts/setup.js +50 -50
- package/scripts/start-server.js +41 -41
- package/scripts/stop.js +36 -36
- package/server/app.js +112 -96
- package/server/auth.js +217 -0
- package/server/channels/contract.js +57 -57
- package/server/channels/hub.js +165 -165
- package/server/channels/index.js +28 -25
- package/server/channels/onebot/index.js +335 -336
- package/server/channels/onebot/token.js +22 -3
- package/server/core/capabilities.js +208 -208
- package/server/core/events.js +64 -60
- package/server/core/image-preprocessor.js +208 -208
- package/server/core/model-manager.js +1213 -1213
- package/server/core/net-guard.js +49 -49
- package/server/core/orchestrator.js +569 -569
- package/server/core/perceivers.js +91 -91
- package/server/core/persona-manager.js +243 -243
- package/server/core/repository.js +293 -293
- package/server/core/response-validator.js +508 -508
- package/server/core/turn-processor.js +630 -630
- package/server/core/turn.js +236 -236
- package/server/core/vision-manager.js +633 -633
- package/server/i18n/errors.js +548 -497
- package/server/i18n/labels.js +649 -653
- package/server/index.js +151 -102
- package/server/knowledge/manager.js +386 -386
- package/server/knowledge/schema.js +12 -8
- package/server/local-access.js +32 -0
- package/server/mind/anticipations.js +507 -507
- package/server/mind/api.js +703 -703
- package/server/mind/budget.js +152 -152
- package/server/mind/context-selection.js +61 -61
- package/server/mind/day-planner.js +324 -324
- package/server/mind/evidence.js +148 -148
- package/server/mind/index.js +445 -445
- package/server/mind/life/diary.js +786 -786
- package/server/mind/life/index.js +1049 -1049
- package/server/mind/observations.js +84 -84
- package/server/mind/own-day.js +324 -324
- package/server/mind/own-voice.js +318 -318
- package/server/mind/senses.js +53 -53
- package/server/mind/time/activity-clock.js +196 -196
- package/server/mind/time/availability.js +69 -69
- package/server/mind/time/commitment-review.js +198 -198
- package/server/mind/time/executor.js +512 -512
- package/server/mind/time/experiences.js +128 -128
- package/server/mind/time/games.js +562 -562
- package/server/mind/time/index.js +739 -739
- package/server/mind/time/intent.js +166 -166
- package/server/mind/time/kinds.js +171 -171
- package/server/mind/time/plugin-activity.js +207 -207
- package/server/mind/time/tasks.js +587 -587
- package/server/mind/util.js +110 -110
- package/server/mind/view.js +273 -273
- package/server/paths.js +102 -102
- package/server/plugins/api.js +204 -204
- package/server/plugins/host.js +967 -967
- package/server/plugins/install.js +295 -295
- package/server/plugins/manifest.js +201 -201
- package/server/plugins/permissions.js +42 -42
- package/server/plugins/runner/guard.mjs +36 -36
- package/server/plugins/runner/worker.mjs +250 -250
- package/server/plugins/schema.js +91 -91
- package/server/plugins/zip.js +112 -112
- package/server/startup-lock.js +118 -118
- package/server/storage/archive.js +242 -241
- package/server/storage/backup-cleanup-worker.js +8 -8
- package/server/storage/backup-cleanup.js +415 -414
- package/server/storage/backup-lock.js +76 -76
- package/server/storage/backup-scheduler.js +131 -131
- package/server/storage/data-package.js +298 -0
- package/server/storage/data-transfer-api.js +50 -0
- package/server/storage/data-transfer-worker.js +18 -0
- package/server/storage/data-transfer.js +415 -0
- package/server/storage/store.js +202 -199
- package/server/studio/readiness.js +181 -190
- package/server/studio/settings.js +236 -236
- package/public/app/assets/ChatsPage-C-FcRapR.js +0 -3
- package/public/app/assets/Empty-CpP5kQHH.js +0 -2
- package/public/app/assets/Field-D4gY-INU.js +0 -1
- package/public/app/assets/HeartPage-CPy_thQd.js +0 -1
- package/public/app/assets/LifePage-CxWvwmSf.js +0 -1
- package/public/app/assets/MemoryPage-DC4rhQ68.js +0 -1
- package/public/app/assets/NaturePage-IvYw04Zq.js +0 -3
- package/public/app/assets/PeoplePage-Cqefm9-q.js +0 -1
- package/public/app/assets/PluginsPage-DKSaKvXb.js +0 -2
- package/public/app/assets/PluginsPage-HyBe5D8w.css +0 -1
- package/public/app/assets/SystemPage-CJmtJkrK.js +0 -1
- package/public/app/assets/TimePage-Cw44inM4.js +0 -3
- package/public/app/assets/index-BheRW-1t.js +0 -4
- package/public/app/assets/media-BzPDBm7e.js +0 -1
package/server/mind/senses.js
CHANGED
|
@@ -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
|
+
}
|