luckytri 1.0.0
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 +71 -0
- package/LICENSE +21 -0
- package/README.en.md +250 -0
- package/README.md +250 -0
- package/bin/luckytri.js +107 -0
- package/docs/brand/banner.png +0 -0
- package/docs/brand/palette.png +0 -0
- package/docs/brand/portrait.png +0 -0
- package/docs/en/CHANGELOG.md +113 -0
- package/docs/en/architecture.md +152 -0
- package/docs/en/chat-style.md +62 -0
- package/docs/en/connect.md +63 -0
- package/docs/en/guide.md +216 -0
- package/docs/en/her-life.md +189 -0
- package/docs/en/npm-release.md +25 -0
- package/docs/en/plugins.md +82 -0
- package/docs/en/recovery.md +28 -0
- package/docs/en/time.md +71 -0
- package/docs/en/webui.md +73 -0
- package/docs/zh/CHANGELOG.md +113 -0
- package/docs/zh/architecture.md +152 -0
- package/docs/zh/chat-style.md +62 -0
- package/docs/zh/connect.md +63 -0
- package/docs/zh/guide.md +216 -0
- package/docs/zh/her-life.md +189 -0
- package/docs/zh/npm-release.md +33 -0
- package/docs/zh/plugins.md +82 -0
- package/docs/zh/recovery.md +28 -0
- package/docs/zh/time.md +71 -0
- package/docs/zh/webui.md +73 -0
- package/package.json +108 -0
- package/plugins/sdk/index.d.ts +155 -0
- package/plugins/sdk/testing.js +58 -0
- package/plugins/weather/index.js +82 -0
- package/plugins/weather/luckytri-plugin.json +29 -0
- package/public/app/assets/ChatsPage-C-FcRapR.js +3 -0
- package/public/app/assets/ChatsPage-DfyPCS9N.css +1 -0
- package/public/app/assets/Empty-CpP5kQHH.js +2 -0
- package/public/app/assets/Empty-DmUB2-Bk.css +1 -0
- package/public/app/assets/Field-D4gY-INU.js +1 -0
- package/public/app/assets/HeartPage-Bft9wZp5.css +1 -0
- package/public/app/assets/HeartPage-CPy_thQd.js +1 -0
- package/public/app/assets/LifePage-BUi5euBF.css +1 -0
- package/public/app/assets/LifePage-CxWvwmSf.js +1 -0
- package/public/app/assets/MemoryPage-DC4rhQ68.js +1 -0
- package/public/app/assets/MemoryPage-cZvXfkXb.css +1 -0
- package/public/app/assets/NaturePage-CTXHCE2D.css +1 -0
- package/public/app/assets/NaturePage-IvYw04Zq.js +3 -0
- package/public/app/assets/PeoplePage-BmUxkrOU.css +1 -0
- package/public/app/assets/PeoplePage-Cqefm9-q.js +1 -0
- package/public/app/assets/PluginsPage-DKSaKvXb.js +2 -0
- package/public/app/assets/PluginsPage-HyBe5D8w.css +1 -0
- package/public/app/assets/SystemPage-CAMPoYqM.css +1 -0
- package/public/app/assets/SystemPage-CJmtJkrK.js +1 -0
- package/public/app/assets/TimePage-BOms_n4I.css +1 -0
- package/public/app/assets/TimePage-Cw44inM4.js +3 -0
- package/public/app/assets/formatters-ZmW_xFHw.js +1 -0
- package/public/app/assets/index-BheRW-1t.js +4 -0
- package/public/app/assets/index-YDz1ree1.css +1 -0
- package/public/app/assets/knowledge-DG0e0uKw.js +1 -0
- package/public/app/assets/liquid-garden-IMoHBwzc.png +0 -0
- package/public/app/assets/luckytri-home-95QKeMtc.png +0 -0
- package/public/app/assets/media-BzPDBm7e.js +1 -0
- package/public/app/index.html +27 -0
- package/public/guide.en.html +1053 -0
- package/public/guide.html +893 -0
- package/public/plugin-kit/v1/bridge.js +30 -0
- package/public/plugin-kit/v1/kit.css +14 -0
- package/public/tutorial.en.md +214 -0
- package/public/tutorial.md +214 -0
- package/scripts/backup.js +311 -0
- package/scripts/browser.js +41 -0
- package/scripts/launch.js +94 -0
- package/scripts/plugin.js +150 -0
- package/scripts/proxy-config.js +167 -0
- package/scripts/recover.js +26 -0
- package/scripts/runtime.js +25 -0
- package/scripts/service.js +47 -0
- package/scripts/setup.js +50 -0
- package/scripts/start-server.js +41 -0
- package/scripts/stop.js +36 -0
- package/server/app.js +96 -0
- package/server/channels/adapters.js +27 -0
- package/server/channels/contract.js +57 -0
- package/server/channels/hub.js +165 -0
- package/server/channels/index.js +25 -0
- package/server/channels/onebot/adapter.js +288 -0
- package/server/channels/onebot/index.js +336 -0
- package/server/channels/onebot/token.js +3 -0
- package/server/channels/qqbot/adapter.js +253 -0
- package/server/channels/qqbot/api.js +199 -0
- package/server/channels/qqbot/credentials.js +11 -0
- package/server/channels/qqbot/gateway.js +274 -0
- package/server/channels/qqbot/index.js +389 -0
- package/server/channels/segments.js +40 -0
- package/server/channels/session-key.js +153 -0
- package/server/channels/state.js +42 -0
- package/server/core/api.js +564 -0
- package/server/core/capabilities.js +208 -0
- package/server/core/context-builder.js +288 -0
- package/server/core/context-compactor.js +454 -0
- package/server/core/conversation-cues.js +325 -0
- package/server/core/conversation-manager.js +87 -0
- package/server/core/events.js +60 -0
- package/server/core/feedback.js +8 -0
- package/server/core/group-style.js +72 -0
- package/server/core/image-preprocessor.js +208 -0
- package/server/core/initiative-context.js +66 -0
- package/server/core/input-budget.js +32 -0
- package/server/core/local-demo.js +98 -0
- package/server/core/message-manager.js +118 -0
- package/server/core/message-scheduler.js +78 -0
- package/server/core/model-json.js +190 -0
- package/server/core/model-manager.js +1213 -0
- package/server/core/model-presets.js +900 -0
- package/server/core/name-call.js +29 -0
- package/server/core/net-guard.js +49 -0
- package/server/core/network.js +157 -0
- package/server/core/orchestrator.js +569 -0
- package/server/core/perceivers.js +91 -0
- package/server/core/person-name.js +22 -0
- package/server/core/persona-manager.js +243 -0
- package/server/core/reply-delivery.js +393 -0
- package/server/core/reply-target-resolver.js +50 -0
- package/server/core/repository.js +293 -0
- package/server/core/response-generator.js +50 -0
- package/server/core/response-validator.js +508 -0
- package/server/core/retired-prompts.js +51 -0
- package/server/core/sessions.js +109 -0
- package/server/core/speaker-names.js +92 -0
- package/server/core/topic-tracker.js +65 -0
- package/server/core/turn-processor.js +630 -0
- package/server/core/turn.js +236 -0
- package/server/core/vision-manager.js +633 -0
- package/server/http.js +18 -0
- package/server/i18n/decisions.js +206 -0
- package/server/i18n/errors.js +497 -0
- package/server/i18n/index.js +144 -0
- package/server/i18n/labels.js +653 -0
- package/server/i18n/models.js +111 -0
- package/server/index.js +102 -0
- package/server/knowledge/api.js +342 -0
- package/server/knowledge/embedding-profile.js +114 -0
- package/server/knowledge/index.js +13 -0
- package/server/knowledge/manager.js +386 -0
- package/server/knowledge/retrieval.js +93 -0
- package/server/knowledge/schema.js +154 -0
- package/server/knowledge/vector-index.js +90 -0
- package/server/mind/affect.js +265 -0
- package/server/mind/anticipations.js +507 -0
- package/server/mind/api.js +703 -0
- package/server/mind/attention.js +200 -0
- package/server/mind/bonds.js +558 -0
- package/server/mind/budget.js +152 -0
- package/server/mind/clock.js +83 -0
- package/server/mind/context-selection.js +61 -0
- package/server/mind/continuity.js +562 -0
- package/server/mind/conversation-origin.js +175 -0
- package/server/mind/day-planner.js +324 -0
- package/server/mind/days.js +210 -0
- package/server/mind/evidence-read.js +45 -0
- package/server/mind/evidence.js +148 -0
- package/server/mind/faces.js +138 -0
- package/server/mind/guard.js +60 -0
- package/server/mind/index.js +445 -0
- package/server/mind/initiative.js +333 -0
- package/server/mind/life/activities.js +21 -0
- package/server/mind/life/context.js +309 -0
- package/server/mind/life/diary.js +786 -0
- package/server/mind/life/growth.js +252 -0
- package/server/mind/life/index.js +1049 -0
- package/server/mind/life/presence.js +305 -0
- package/server/mind/meetings.js +1069 -0
- package/server/mind/memory-policy.js +48 -0
- package/server/mind/memory.js +888 -0
- package/server/mind/nature.js +262 -0
- package/server/mind/novelty.js +19 -0
- package/server/mind/observations.js +84 -0
- package/server/mind/own-day.js +324 -0
- package/server/mind/own-voice.js +318 -0
- package/server/mind/periods.js +118 -0
- package/server/mind/reading.js +120 -0
- package/server/mind/salience.js +201 -0
- package/server/mind/schema.js +562 -0
- package/server/mind/self.js +484 -0
- package/server/mind/senses.js +53 -0
- package/server/mind/thoughts.js +274 -0
- package/server/mind/time/activity-clock.js +196 -0
- package/server/mind/time/agenda.js +242 -0
- package/server/mind/time/api.js +200 -0
- package/server/mind/time/attention.js +34 -0
- package/server/mind/time/availability.js +69 -0
- package/server/mind/time/commitment-review.js +198 -0
- package/server/mind/time/delivery-links.js +130 -0
- package/server/mind/time/executor.js +512 -0
- package/server/mind/time/experiences.js +128 -0
- package/server/mind/time/games.js +562 -0
- package/server/mind/time/index.js +739 -0
- package/server/mind/time/intent.js +166 -0
- package/server/mind/time/kinds.js +171 -0
- package/server/mind/time/model-material.js +77 -0
- package/server/mind/time/plugin-activity.js +207 -0
- package/server/mind/time/presentation.js +51 -0
- package/server/mind/time/schedule.js +83 -0
- package/server/mind/time/schema.js +84 -0
- package/server/mind/time/search.js +383 -0
- package/server/mind/time/sharing.js +472 -0
- package/server/mind/time/task-links.js +311 -0
- package/server/mind/time/tasks.js +587 -0
- package/server/mind/time/works.js +432 -0
- package/server/mind/traits.js +191 -0
- package/server/mind/util.js +110 -0
- package/server/mind/view.js +273 -0
- package/server/paths.js +102 -0
- package/server/plugins/api.js +204 -0
- package/server/plugins/host.js +967 -0
- package/server/plugins/install.js +295 -0
- package/server/plugins/manifest.js +201 -0
- package/server/plugins/permissions.js +42 -0
- package/server/plugins/runner/guard.mjs +36 -0
- package/server/plugins/runner/worker.mjs +250 -0
- package/server/plugins/schema.js +91 -0
- package/server/plugins/zip.js +112 -0
- package/server/startup-lock.js +118 -0
- package/server/storage/archive.js +241 -0
- package/server/storage/backup-cleanup-worker.js +8 -0
- package/server/storage/backup-cleanup.js +414 -0
- package/server/storage/backup-lock.js +76 -0
- package/server/storage/backup-scheduler.js +131 -0
- package/server/storage/store.js +199 -0
- package/server/studio/display-names.js +138 -0
- package/server/studio/management.js +102 -0
- package/server/studio/readiness.js +190 -0
- package/server/studio/settings.js +236 -0
- package/server/version.js +10 -0
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import { evidence, parse, text } from "../util.js";
|
|
2
|
+
import { taskIntent } from "./intent.js";
|
|
3
|
+
import { deadlineAt } from "./schedule.js";
|
|
4
|
+
|
|
5
|
+
export class TaskLinks {
|
|
6
|
+
constructor(tasks) {
|
|
7
|
+
this.tasks = tasks;
|
|
8
|
+
this.time = tasks.time;
|
|
9
|
+
this.db = tasks.db;
|
|
10
|
+
for (const row of this.db
|
|
11
|
+
.prepare("SELECT id,sources FROM mind_time_tasks")
|
|
12
|
+
.all())
|
|
13
|
+
for (const ref of parse(row.sources, []))
|
|
14
|
+
this.db
|
|
15
|
+
.prepare(
|
|
16
|
+
"INSERT OR IGNORE INTO mind_time_task_aliases(kind,alias_id,task_id,created) VALUES ('source',?,?,0)",
|
|
17
|
+
)
|
|
18
|
+
.run(row.id + ":" + ref, row.id);
|
|
19
|
+
for (const task of this.db
|
|
20
|
+
.prepare("SELECT * FROM mind_time_tasks WHERE intent_key IS NULL")
|
|
21
|
+
.all()) {
|
|
22
|
+
const refs = parse(task.sources, []),
|
|
23
|
+
intent = taskIntent(this.db, { ...task, sources: refs });
|
|
24
|
+
this.db
|
|
25
|
+
.prepare("UPDATE mind_time_tasks SET intent_key=? WHERE id=?")
|
|
26
|
+
.run(intent.key, task.id);
|
|
27
|
+
}
|
|
28
|
+
for (const row of this.db
|
|
29
|
+
.prepare(
|
|
30
|
+
"SELECT t.id,t.due_at FROM mind_time_tasks t JOIN mind_anticipations a ON a.id=t.anticipation_id WHERE a.due_precision='day' AND t.due_at=a.due_at",
|
|
31
|
+
)
|
|
32
|
+
.all())
|
|
33
|
+
this.db
|
|
34
|
+
.prepare(
|
|
35
|
+
"UPDATE mind_time_tasks SET due_at=?,due_precision='day' WHERE id=?",
|
|
36
|
+
)
|
|
37
|
+
.run(deadlineAt(row.due_at, "day", this.time.mind.timeZone()), row.id);
|
|
38
|
+
}
|
|
39
|
+
canonical(id) {
|
|
40
|
+
const seen = new Set();
|
|
41
|
+
while (id && !seen.has(id)) {
|
|
42
|
+
seen.add(id);
|
|
43
|
+
const alias = this.db
|
|
44
|
+
.prepare(
|
|
45
|
+
"SELECT task_id FROM mind_time_task_aliases WHERE kind='task' AND alias_id=?",
|
|
46
|
+
)
|
|
47
|
+
.get(id);
|
|
48
|
+
if (!alias || alias.task_id === id) return id;
|
|
49
|
+
id = alias.task_id;
|
|
50
|
+
}
|
|
51
|
+
return id;
|
|
52
|
+
}
|
|
53
|
+
find(input) {
|
|
54
|
+
const intent = taskIntent(this.db, input);
|
|
55
|
+
if (!intent.key) return null;
|
|
56
|
+
const row = this.db
|
|
57
|
+
.prepare(
|
|
58
|
+
"SELECT id FROM mind_time_tasks WHERE intent_key=? AND json_extract(checkpoint,'$.mergedInto') IS NULL ORDER BY CASE state WHEN 'abandoned' THEN 2 WHEN 'done' THEN 1 ELSE 0 END,created LIMIT 1",
|
|
59
|
+
)
|
|
60
|
+
.get(intent.key);
|
|
61
|
+
return row ? this.tasks.get(row.id) : null;
|
|
62
|
+
}
|
|
63
|
+
link(kind, alias, id, now = this.time.now()) {
|
|
64
|
+
if (alias)
|
|
65
|
+
this.db
|
|
66
|
+
.prepare(
|
|
67
|
+
"INSERT INTO mind_time_task_aliases(kind,alias_id,task_id,created) VALUES (?,?,?,?) ON CONFLICT(kind,alias_id) DO UPDATE SET task_id=excluded.task_id",
|
|
68
|
+
)
|
|
69
|
+
.run(kind, alias, id, now);
|
|
70
|
+
}
|
|
71
|
+
byAnticipation(id) {
|
|
72
|
+
return (
|
|
73
|
+
this.db
|
|
74
|
+
.prepare(
|
|
75
|
+
"SELECT task_id id FROM mind_time_task_aliases WHERE kind='anticipation' AND alias_id=?",
|
|
76
|
+
)
|
|
77
|
+
.get(id) ||
|
|
78
|
+
this.db
|
|
79
|
+
.prepare("SELECT id FROM mind_time_tasks WHERE anticipation_id=?")
|
|
80
|
+
.get(id)
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
anticipations(task) {
|
|
84
|
+
return [
|
|
85
|
+
...new Set(
|
|
86
|
+
[
|
|
87
|
+
task.anticipation_id,
|
|
88
|
+
...this.db
|
|
89
|
+
.prepare(
|
|
90
|
+
"SELECT alias_id FROM mind_time_task_aliases WHERE kind='anticipation' AND task_id=?",
|
|
91
|
+
)
|
|
92
|
+
.all(task.id)
|
|
93
|
+
.map((a) => a.alias_id),
|
|
94
|
+
].filter(Boolean),
|
|
95
|
+
),
|
|
96
|
+
];
|
|
97
|
+
}
|
|
98
|
+
close(task, reason, now = this.time.now()) {
|
|
99
|
+
for (const id of this.anticipations(task))
|
|
100
|
+
this.time.mind.anticipations.close(id, {
|
|
101
|
+
status: "let_go",
|
|
102
|
+
note: reason,
|
|
103
|
+
sources: task.sources,
|
|
104
|
+
time: now,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
mergeSource(
|
|
108
|
+
task,
|
|
109
|
+
{
|
|
110
|
+
sources = [],
|
|
111
|
+
kind,
|
|
112
|
+
subject,
|
|
113
|
+
dueAt,
|
|
114
|
+
duePrecision = "time",
|
|
115
|
+
anticipationId,
|
|
116
|
+
origin = "capture",
|
|
117
|
+
},
|
|
118
|
+
now,
|
|
119
|
+
) {
|
|
120
|
+
const fresh = evidence(sources).filter(
|
|
121
|
+
(s) =>
|
|
122
|
+
!task.sources.includes(s) &&
|
|
123
|
+
!this.db
|
|
124
|
+
.prepare(
|
|
125
|
+
"SELECT 1 FROM mind_time_task_aliases WHERE kind='source' AND alias_id=?",
|
|
126
|
+
)
|
|
127
|
+
.get(task.id + ":" + s),
|
|
128
|
+
),
|
|
129
|
+
all = evidence([...task.sources, ...sources]);
|
|
130
|
+
if (anticipationId) this.link("anticipation", anticipationId, task.id, now);
|
|
131
|
+
if (!fresh.length) return;
|
|
132
|
+
for (const ref of fresh)
|
|
133
|
+
this.link("source", task.id + ":" + ref, task.id, now);
|
|
134
|
+
const inputDue = deadlineAt(dueAt, duePrecision, this.time.mind.timeZone());
|
|
135
|
+
const closed = ["done", "abandoned"].includes(task.state),
|
|
136
|
+
contract = task.checkpoint.contract;
|
|
137
|
+
const changesDeadline =
|
|
138
|
+
!closed && !contract?.originalGoal && inputDue !== null;
|
|
139
|
+
this.db
|
|
140
|
+
.prepare(
|
|
141
|
+
"UPDATE mind_time_tasks SET sources=?,updated=?,kind=?,subject=COALESCE(subject,?),due_at=?,due_precision=? WHERE id=?",
|
|
142
|
+
)
|
|
143
|
+
.run(
|
|
144
|
+
JSON.stringify(all),
|
|
145
|
+
now,
|
|
146
|
+
kind === "promise" && !contract?.originalGoal ? "promise" : task.kind,
|
|
147
|
+
subject ? String(subject) : null,
|
|
148
|
+
changesDeadline ? inputDue : task.due_at,
|
|
149
|
+
changesDeadline ? duePrecision : task.due_precision,
|
|
150
|
+
task.id,
|
|
151
|
+
);
|
|
152
|
+
this.time.event(
|
|
153
|
+
task.id,
|
|
154
|
+
closed ? "source-linked" : "reaffirmed",
|
|
155
|
+
closed
|
|
156
|
+
? "归回原事项,保留已完成或已放下的决定"
|
|
157
|
+
: "同一未完成事项补充来源,不新建待办",
|
|
158
|
+
{
|
|
159
|
+
sources: fresh,
|
|
160
|
+
origin,
|
|
161
|
+
deadlineChanged: changesDeadline,
|
|
162
|
+
previousDue: task.due_at,
|
|
163
|
+
},
|
|
164
|
+
now,
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
consolidate(
|
|
168
|
+
ids,
|
|
169
|
+
{ restore = false, title, why, kind, subject, contract, schedule } = {},
|
|
170
|
+
now = this.time.now(),
|
|
171
|
+
) {
|
|
172
|
+
const rows = [...new Set(ids)]
|
|
173
|
+
.map((id) => this.tasks.get(this.canonical(id)))
|
|
174
|
+
.filter(Boolean);
|
|
175
|
+
if (!rows.length) throw Error("没有可整理的任务");
|
|
176
|
+
const unique = [...new Map(rows.map((row) => [row.id, row])).values()];
|
|
177
|
+
const keys = new Set(unique.map((t) => t.intent_key));
|
|
178
|
+
if (unique.length > 1 && (keys.size !== 1 || keys.has(null)))
|
|
179
|
+
throw Error("任务目标或权限范围不同,不能合并");
|
|
180
|
+
const leader = [...unique].sort(
|
|
181
|
+
(a, b) =>
|
|
182
|
+
Number(!!b.work_id) - Number(!!a.work_id) ||
|
|
183
|
+
Number(b.kind === "promise") - Number(a.kind === "promise") ||
|
|
184
|
+
a.created - b.created,
|
|
185
|
+
)[0];
|
|
186
|
+
if (restore && leader.state === "done")
|
|
187
|
+
throw Error("已有成果的任务不能改成未执行");
|
|
188
|
+
this.db.exec("SAVEPOINT consolidate_tasks");
|
|
189
|
+
try {
|
|
190
|
+
const refs = evidence(unique.flatMap((t) => t.sources));
|
|
191
|
+
const checkpoint = {
|
|
192
|
+
...leader.checkpoint,
|
|
193
|
+
originalTask: leader.checkpoint.originalTask || {
|
|
194
|
+
title: leader.title,
|
|
195
|
+
why: leader.why,
|
|
196
|
+
kind: leader.kind,
|
|
197
|
+
state: leader.state,
|
|
198
|
+
readyAt: leader.ready_at,
|
|
199
|
+
dueAt: leader.due_at,
|
|
200
|
+
sources: leader.sources,
|
|
201
|
+
},
|
|
202
|
+
...(kind === "suggestion" && restore
|
|
203
|
+
? {
|
|
204
|
+
suggestion: {
|
|
205
|
+
origin: "admin",
|
|
206
|
+
action: "reference-plan",
|
|
207
|
+
idea: title,
|
|
208
|
+
accepted: null,
|
|
209
|
+
},
|
|
210
|
+
}
|
|
211
|
+
: {}),
|
|
212
|
+
mergedHistory: [
|
|
213
|
+
...new Set([
|
|
214
|
+
...(leader.checkpoint.mergedHistory || []),
|
|
215
|
+
...unique.filter((t) => t.id !== leader.id).map((t) => t.id),
|
|
216
|
+
]),
|
|
217
|
+
],
|
|
218
|
+
previousDeadlines: unique.map((t) => ({
|
|
219
|
+
task: t.id,
|
|
220
|
+
at: t.due_at,
|
|
221
|
+
precision: t.due_precision,
|
|
222
|
+
})),
|
|
223
|
+
...(contract ? { contract } : {}),
|
|
224
|
+
...(schedule ? { schedule } : {}),
|
|
225
|
+
};
|
|
226
|
+
for (const task of unique) {
|
|
227
|
+
this.time.stopSpan(task, now);
|
|
228
|
+
for (const a of this.anticipations(task)) {
|
|
229
|
+
this.link("anticipation", a, leader.id, now);
|
|
230
|
+
this.time.mind.anticipations.close(a, {
|
|
231
|
+
status: "let_go",
|
|
232
|
+
note: "重复事项已整理为一个执行计划;原约定未因此兑现",
|
|
233
|
+
sources: task.sources,
|
|
234
|
+
time: now,
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
this.link("task", task.id, leader.id, now);
|
|
238
|
+
if (task.id !== leader.id) {
|
|
239
|
+
this.db
|
|
240
|
+
.prepare(
|
|
241
|
+
"UPDATE mind_time_tasks SET state='abandoned',updated=?,wait_reason=?,lease=NULL,lease_at=NULL,revision=revision+1,checkpoint=? WHERE id=?",
|
|
242
|
+
)
|
|
243
|
+
.run(
|
|
244
|
+
now,
|
|
245
|
+
"重复事项已合并,原记录保留",
|
|
246
|
+
JSON.stringify({ ...task.checkpoint, mergedInto: leader.id }),
|
|
247
|
+
task.id,
|
|
248
|
+
);
|
|
249
|
+
this.time.event(
|
|
250
|
+
task.id,
|
|
251
|
+
"merged",
|
|
252
|
+
"归入唯一事项,保留原文与时间",
|
|
253
|
+
{ taskId: leader.id },
|
|
254
|
+
now,
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
const proposed = schedule?.proposedAt || now,
|
|
259
|
+
wait =
|
|
260
|
+
contract?.mode === "reference" ? this.time.search.ready(now) : "";
|
|
261
|
+
const state = restore
|
|
262
|
+
? wait
|
|
263
|
+
? "waiting"
|
|
264
|
+
: proposed > now
|
|
265
|
+
? "scheduled"
|
|
266
|
+
: "todo"
|
|
267
|
+
: leader.state;
|
|
268
|
+
this.db
|
|
269
|
+
.prepare(
|
|
270
|
+
"UPDATE mind_time_tasks SET title=?,why=?,kind=?,subject=?,sources=?,checkpoint=?,state=?,ready_at=?,next_step=?,due_at=?,due_precision=?,updated=?,wait_reason=?,lease=NULL,lease_at=NULL,revision=revision+1 WHERE id=?",
|
|
271
|
+
)
|
|
272
|
+
.run(
|
|
273
|
+
text(title || leader.title, 240),
|
|
274
|
+
text(why || leader.why, 300),
|
|
275
|
+
kind || leader.kind,
|
|
276
|
+
subject || leader.subject,
|
|
277
|
+
JSON.stringify(refs),
|
|
278
|
+
JSON.stringify(checkpoint),
|
|
279
|
+
state,
|
|
280
|
+
restore ? proposed : leader.ready_at,
|
|
281
|
+
restore ? proposed : leader.next_step,
|
|
282
|
+
restore ? null : leader.due_at,
|
|
283
|
+
restore ? "none" : leader.due_precision,
|
|
284
|
+
now,
|
|
285
|
+
restore ? wait : leader.wait_reason,
|
|
286
|
+
leader.id,
|
|
287
|
+
);
|
|
288
|
+
if (title) {
|
|
289
|
+
const updated = this.tasks.get(leader.id),
|
|
290
|
+
intent = taskIntent(this.db, updated);
|
|
291
|
+
this.db
|
|
292
|
+
.prepare("UPDATE mind_time_tasks SET intent_key=? WHERE id=?")
|
|
293
|
+
.run(intent.key, leader.id);
|
|
294
|
+
}
|
|
295
|
+
this.time.event(
|
|
296
|
+
leader.id,
|
|
297
|
+
"consolidated",
|
|
298
|
+
restore
|
|
299
|
+
? "根据管理台明确请求重新整理并安排"
|
|
300
|
+
: "合并重复来源,保留任务决定",
|
|
301
|
+
{ from: unique.map((t) => t.id), restore, schedule, contract },
|
|
302
|
+
now,
|
|
303
|
+
);
|
|
304
|
+
this.db.exec("RELEASE consolidate_tasks");
|
|
305
|
+
return this.tasks.get(leader.id);
|
|
306
|
+
} catch (error) {
|
|
307
|
+
this.db.exec("ROLLBACK TO consolidate_tasks; RELEASE consolidate_tasks");
|
|
308
|
+
throw error;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|