@celljs/ta-initiative 0.0.0-stage → 4.13.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.
package/web/index.js ADDED
@@ -0,0 +1,1226 @@
1
+ // web-src/i18n.ts
2
+ var en = {
3
+ settingsTitle: "Initiative",
4
+ modeLabel: "How much Ta does on its own",
5
+ modeHint: "Where each kind of thing starts, whether Ta may come to do it on its own as you accept it, and how often a day it may tell you at once: Quiet once, Balanced 3 times, Active no limit.",
6
+ quietLabel: "Quiet hours",
7
+ quietHint: "Ta tells you of nothing at once in these hours: it waits in Suggestions and the brief.",
8
+ quietFrom: "From",
9
+ quietTo: "to",
10
+ modeQuiet: "Quiet",
11
+ modeBalanced: "Balanced",
12
+ modeActive: "Active",
13
+ kindsLabel: "What Ta may do",
14
+ kindsHint: "Each goes up a level as you accept it and down as you decline or undo it; pick a level to keep it there.",
15
+ levelAuto: "Auto · {level}",
16
+ levelAutoPlain: "Auto",
17
+ levelOff: "Never",
18
+ levelDigest: "In the brief",
19
+ levelAsk: "Ask me",
20
+ levelAct: "Do it, tell me",
21
+ reasonStart: "Where it starts",
22
+ reasonUp: "Up on {date}: you accepted it 3 times in a row",
23
+ reasonDown: "Down on {date}: declined or undone",
24
+ reasonLocked: "You chose it",
25
+ inboxTitle: "Suggestions",
26
+ inboxWaiting: "Waiting for you",
27
+ inboxDone: "Done on its own",
28
+ inboxEmpty: "Nothing waits. When Ta finds work you ask for again and again, it suggests it here.",
29
+ accept: "OK",
30
+ decline: "No",
31
+ always: "Always do it",
32
+ neverAgain: "Never suggest this",
33
+ undo: "Undo",
34
+ undoneState: "Undone",
35
+ failedState: "Failed: {error}",
36
+ inBrief: "From the brief",
37
+ evidence: "From {count} conversations",
38
+ homeDetail: "{waiting} waiting · {done} done on its own",
39
+ homeWaiting: "{waiting} waiting for you",
40
+ homeDone: "{done} done on its own",
41
+ toolPropose: "Propose",
42
+ acceptedLine: "Accepted",
43
+ declinedLine: "Declined",
44
+ expiredLine: "No longer waits",
45
+ enabledLabel: "Review the scheduled tasks",
46
+ enabledHint: "Ta looks back at what you asked since the last review: work you asked for again and again becomes a scheduled task, tasks that keep failing or no longer matter are turned off. Each change goes as far as you let its kind (above): done, or asked in Suggestions. It reports in the conversation Evolve, where you can answer; it remembers what you said.",
47
+ everyLabel: "How often",
48
+ everyDays: "Every {days} days",
49
+ every1: "Every day",
50
+ every7: "Every week",
51
+ every14: "Every two weeks",
52
+ every30: "Every month",
53
+ timeLabel: "At",
54
+ autoLabel: "Let Ta choose how often",
55
+ autoHint: "After each review Ta sets the next: sooner while your work changes, later while nothing does.",
56
+ autoNote: "Ta: {note}",
57
+ nowLabel: "Review now",
58
+ nowButton: "Review",
59
+ lastNext: "Last {last} · next {next}",
60
+ nextOnly: "First review {next}",
61
+ never: "never",
62
+ conversation: "Evolve",
63
+ failed: "Could not do it: {message}",
64
+ toolPace: "Set review pace",
65
+ toolProfile: "Update what Ta knows of you",
66
+ learnLabel: "Learn about me",
67
+ learnHint: "At each review Ta writes down how you work and what you usually want next; every conversation reads it, so Ta needs telling less and does more on its own.",
68
+ profileLabel: "What Ta knows of you",
69
+ profileHint: "Edit it freely: Ta keeps your changes and builds on them.",
70
+ profileEmpty: "Nothing yet: Ta writes it at the next review.",
71
+ profileSave: "Save",
72
+ profileSaved: "Saved"
73
+ };
74
+ var zh = {
75
+ settingsTitle: "主动",
76
+ modeLabel: "主动程度",
77
+ modeHint: "决定每类事从哪一档开始、你接受得多了 Ta 能不能自己直接做,以及一天最多即时提醒几次:安静 1 次、适中 3 次、积极不限。",
78
+ quietLabel: "安静时段",
79
+ quietHint: "这段时间里 Ta 不即时提醒你,建议都留在“Ta 的建议”和简报里。",
80
+ quietFrom: "从",
81
+ quietTo: "到",
82
+ modeQuiet: "安静",
83
+ modeBalanced: "适中",
84
+ modeActive: "积极",
85
+ kindsLabel: "Ta 可以做的事",
86
+ kindsHint: "每类事你接受得多就升一档,拒绝或撤销就降一档;手动选了档位就不再自动变。",
87
+ levelAuto: "自动 · {level}",
88
+ levelAutoPlain: "自动",
89
+ levelOff: "不提",
90
+ levelDigest: "只进简报",
91
+ levelAsk: "先问我",
92
+ levelAct: "先做后报",
93
+ reasonStart: "初始档位",
94
+ reasonUp: "{date} 升档:连续接受 3 次",
95
+ reasonDown: "{date} 降档:被拒绝或撤销",
96
+ reasonLocked: "你选定的",
97
+ inboxTitle: "Ta 的建议",
98
+ inboxWaiting: "等你决定",
99
+ inboxDone: "已替你做",
100
+ inboxEmpty: "暂时没有建议。Ta 发现你反复交代的事,会在这里提出。",
101
+ accept: "好",
102
+ decline: "不用",
103
+ always: "以后直接做",
104
+ neverAgain: "别再提这类",
105
+ undo: "撤销",
106
+ undoneState: "已撤销",
107
+ failedState: "失败:{error}",
108
+ inBrief: "来自简报",
109
+ evidence: "依据 {count} 个对话",
110
+ homeDetail: "等你决定 {waiting} · 已替你做 {done}",
111
+ homeWaiting: "等你决定 {waiting}",
112
+ homeDone: "已替你做 {done}",
113
+ toolPropose: "提议",
114
+ acceptedLine: "已同意",
115
+ declinedLine: "已拒绝",
116
+ expiredLine: "已失效",
117
+ enabledLabel: "定期整理定时任务",
118
+ enabledHint: "Ta 回顾上次以来你交代过的事:反复做的工作建成定时任务,总是失败或已经过时的任务停用;每项改动按上面的档位直接做,或放进“Ta 的建议”等你点头。结果写进“自我进化”对话,你可以在里面回复,Ta 会记住你的意见。",
119
+ everyLabel: "多久一次",
120
+ everyDays: "每 {days} 天",
121
+ every1: "每天",
122
+ every7: "每周",
123
+ every14: "每两周",
124
+ every30: "每月",
125
+ timeLabel: "时间",
126
+ autoLabel: "让 Ta 决定节奏",
127
+ autoHint: "每次整理后由 Ta 定下一次:工作变化多就勤一点,没什么变化就久一点。",
128
+ autoNote: "Ta:{note}",
129
+ nowLabel: "现在整理一次",
130
+ nowButton: "整理",
131
+ lastNext: "上次 {last} · 下次 {next}",
132
+ nextOnly: "首次 {next}",
133
+ never: "无",
134
+ conversation: "自我进化",
135
+ failed: "没有成功:{message}",
136
+ toolPace: "调整整理节奏",
137
+ toolProfile: "更新对你的了解",
138
+ learnLabel: "了解我",
139
+ learnHint: "每次整理时,Ta 记下你的做事方式和你通常接下来想做什么;所有对话都会参考,你要交代的越来越少,Ta 主动做的越来越多。",
140
+ profileLabel: "Ta 对你的了解",
141
+ profileHint: "可以直接修改,Ta 会保留你的改动并在此基础上补充。",
142
+ profileEmpty: "还没有内容,下次整理时 Ta 会写。",
143
+ profileSave: "保存",
144
+ profileSaved: "已保存"
145
+ };
146
+ var InitiativeWords;
147
+ ((InitiativeWords) => {
148
+ function of(language) {
149
+ return /^zh/i.test(language) ? zh : en;
150
+ }
151
+ InitiativeWords.of = of;
152
+ function format(text, values) {
153
+ return text.replace(/\{(\w+)\}/g, (match, key) => values[key] ?? match);
154
+ }
155
+ InitiativeWords.format = format;
156
+ })(InitiativeWords ||= {});
157
+
158
+ // web-src/conversation.ts
159
+ async function openConversation(pi, file) {
160
+ const opened = await pi.openChat?.(file);
161
+ if (opened !== undefined) {
162
+ return opened;
163
+ }
164
+ const open = (await pi.server.listSessions()).find((session) => session.sessionFile === file);
165
+ if (open) {
166
+ await pi.switchSession(open.sessionId);
167
+ pi.ui.showView("");
168
+ return true;
169
+ }
170
+ const saved = (await pi.server.listSavedSessions()).find((session) => session.sessionFile === file);
171
+ if (!saved) {
172
+ return false;
173
+ }
174
+ const sessionId = pi.server.openSession({ cwd: saved.cwd, sessionFile: file }).then((session) => session.sessionId);
175
+ await pi.switchSession(sessionId, { title: saved.sessionName || saved.firstMessage, cwd: saved.cwd, sessionFile: file });
176
+ pi.ui.showView("");
177
+ return true;
178
+ }
179
+
180
+ // web-src/initiative-protocol.ts
181
+ var NAME = "@celljs/ta-initiative";
182
+ var PACE_TOOL = "evolve_pace";
183
+ var PROFILE_TOOL = "evolve_profile";
184
+ var PROPOSE_TOOL = "propose";
185
+ var CARD_TYPE = "ta-initiative";
186
+ var BLOCK = "ta-propose";
187
+ var LEVELS = ["off", "digest", "ask", "act"];
188
+ var MODES = ["quiet", "balanced", "active"];
189
+ var Keys;
190
+ ((Keys) => {
191
+ Keys.SETTINGS = "settings";
192
+ Keys.FILE = "file";
193
+ Keys.LAST = "last";
194
+ Keys.NOTE = "note";
195
+ Keys.PROFILE = "profile";
196
+ Keys.MODE = "mode";
197
+ Keys.LOCKS = "locks";
198
+ Keys.PROPOSALS = "proposals";
199
+ Keys.SEEN = "seen";
200
+ Keys.QUIET = "quiet";
201
+ Keys.MIGRATED = "migrated";
202
+ })(Keys ||= {});
203
+ var Limits;
204
+ ((Limits) => {
205
+ Limits.MIN_DAYS = 1;
206
+ Limits.MAX_DAYS = 30;
207
+ Limits.LOOK_BACK_DAYS = 7;
208
+ Limits.MATERIAL_CHARS = 48000;
209
+ Limits.RUNS = 5;
210
+ Limits.PROMPT_CHARS = 400;
211
+ Limits.SUMMARY_CHARS = 240;
212
+ Limits.NEW_TASKS = 3;
213
+ Limits.PROFILE_CHARS = 3000;
214
+ Limits.PROPOSALS_KEPT = 200;
215
+ Limits.OUTCOMES = 20;
216
+ Limits.UP_AFTER = 3;
217
+ Limits.DOWN_AFTER = 2;
218
+ Limits.EXPIRE_DAYS = 14;
219
+ Limits.UNDO_DAYS = 7;
220
+ Limits.BUDGET = { quiet: 1, balanced: 3, active: Number.POSITIVE_INFINITY };
221
+ Limits.NOTICE_MS = 2 * 60000;
222
+ })(Limits ||= {});
223
+
224
+ // web-src/inbox-util.ts
225
+ var DAY_MS = 24 * 60 * 60000;
226
+ function waits(proposal) {
227
+ return proposal.state === "pending" || proposal.state === "digest";
228
+ }
229
+ var InboxUtil;
230
+ ((InboxUtil) => {
231
+ function waiting(proposals) {
232
+ return proposals.filter(waits).sort((a, b) => a.state === b.state ? b.at - a.at : a.state === "pending" ? -1 : 1);
233
+ }
234
+ InboxUtil.waiting = waiting;
235
+ function done(proposals, now) {
236
+ return proposals.filter((proposal) => proposal.auto && ["done", "undone", "failed"].includes(proposal.state) && now - (proposal.decidedAt ?? proposal.at) <= Limits.UNDO_DAYS * DAY_MS).sort((a, b) => (b.decidedAt ?? b.at) - (a.decidedAt ?? a.at));
237
+ }
238
+ InboxUtil.done = done;
239
+ function canUndo(proposal, now) {
240
+ return proposal.state === "done" && !!proposal.undo && now - (proposal.decidedAt ?? proposal.at) <= Limits.UNDO_DAYS * DAY_MS;
241
+ }
242
+ InboxUtil.canUndo = canUndo;
243
+ function home(proposals, seen, now) {
244
+ const open = waiting(proposals);
245
+ const did = done(proposals, now).filter((proposal) => proposal.state === "done");
246
+ if (open.length === 0 && did.length === 0) {
247
+ return;
248
+ }
249
+ const at = Math.max(...[...open, ...did].map((proposal) => Math.max(proposal.at, proposal.decidedAt ?? 0)));
250
+ return { waiting: open.length, done: did.length, at, unseen: at > seen };
251
+ }
252
+ InboxUtil.home = home;
253
+ })(InboxUtil ||= {});
254
+
255
+ // web-src/notify-util.ts
256
+ var NotifyUtil;
257
+ ((NotifyUtil) => {
258
+ NotifyUtil.QUIET = { enabled: true, start: "22:00", end: "08:00" };
259
+ function quiet(value) {
260
+ const stored = value && typeof value === "object" ? value : {};
261
+ return {
262
+ enabled: typeof stored.enabled === "boolean" ? stored.enabled : NotifyUtil.QUIET.enabled,
263
+ start: typeof stored.start === "string" && minutes(stored.start) !== undefined ? stored.start : NotifyUtil.QUIET.start,
264
+ end: typeof stored.end === "string" && minutes(stored.end) !== undefined ? stored.end : NotifyUtil.QUIET.end
265
+ };
266
+ }
267
+ NotifyUtil.quiet = quiet;
268
+ function minutes(text) {
269
+ const match = /^(\d{1,2}):(\d{2})$/.exec(text.trim());
270
+ const hours = Number(match?.[1]);
271
+ const mins = Number(match?.[2]);
272
+ return match && hours < 24 && mins < 60 ? hours * 60 + mins : undefined;
273
+ }
274
+ NotifyUtil.minutes = minutes;
275
+ function isQuiet(hours, now) {
276
+ const start = minutes(hours.start);
277
+ const end = minutes(hours.end);
278
+ if (!hours.enabled || start === undefined || end === undefined || start === end) {
279
+ return false;
280
+ }
281
+ const date = new Date(now);
282
+ const at = date.getHours() * 60 + date.getMinutes();
283
+ return start < end ? at >= start && at < end : at >= start || at < end;
284
+ }
285
+ NotifyUtil.isQuiet = isQuiet;
286
+ function toldToday(proposals, now) {
287
+ const day = new Date(now).toDateString();
288
+ return proposals.filter((proposal) => proposal.notifiedAt && new Date(proposal.notifiedAt).toDateString() === day).length;
289
+ }
290
+ NotifyUtil.toldToday = toldToday;
291
+ function tell(input) {
292
+ const { proposal } = input;
293
+ return proposal.state === "pending" && proposal.level === "ask" && proposal.urgency === "now" && proposal.source !== "turn" && input.pages > 0 && !isQuiet(input.quiet, input.now) && input.told < Limits.BUDGET[input.mode];
294
+ }
295
+ NotifyUtil.tell = tell;
296
+ })(NotifyUtil ||= {});
297
+
298
+ // web-src/pace-util.ts
299
+ var DAY_MS2 = 24 * 60 * 60000;
300
+ var PaceUtil;
301
+ ((PaceUtil) => {
302
+ PaceUtil.DEFAULT = { enabled: true, every: 7, time: "20:00", auto: false, learn: true };
303
+ PaceUtil.CHOICES = [1, 7, 14, 30];
304
+ function settings(value) {
305
+ const stored = value && typeof value === "object" ? value : {};
306
+ return {
307
+ enabled: typeof stored.enabled === "boolean" ? stored.enabled : PaceUtil.DEFAULT.enabled,
308
+ every: typeof stored.every === "number" && Number.isFinite(stored.every) ? days(stored.every) : PaceUtil.DEFAULT.every,
309
+ time: typeof stored.time === "string" && parseTime(stored.time) ? stored.time : PaceUtil.DEFAULT.time,
310
+ auto: typeof stored.auto === "boolean" ? stored.auto : PaceUtil.DEFAULT.auto,
311
+ learn: typeof stored.learn === "boolean" ? stored.learn : PaceUtil.DEFAULT.learn
312
+ };
313
+ }
314
+ PaceUtil.settings = settings;
315
+ function days(value) {
316
+ return Math.min(Limits.MAX_DAYS, Math.max(Limits.MIN_DAYS, Math.round(value)));
317
+ }
318
+ PaceUtil.days = days;
319
+ function parseTime(text) {
320
+ const match = /^(\d{1,2}):(\d{2})$/.exec(text.trim());
321
+ if (!match) {
322
+ return;
323
+ }
324
+ const hours = Number(match[1]);
325
+ const minutes = Number(match[2]);
326
+ return hours < 24 && minutes < 60 ? { hours, minutes } : undefined;
327
+ }
328
+ PaceUtil.parseTime = parseTime;
329
+ function next(settings2, last) {
330
+ const { hours, minutes } = parseTime(settings2.time) ?? { hours: 20, minutes: 0 };
331
+ const day = new Date(last + settings2.every * DAY_MS2);
332
+ day.setHours(hours, minutes, 0, 0);
333
+ return day.getTime();
334
+ }
335
+ PaceUtil.next = next;
336
+ function due(settings2, last, now) {
337
+ return settings2.enabled && last !== undefined && now >= next(settings2, last);
338
+ }
339
+ PaceUtil.due = due;
340
+ function since(last, now) {
341
+ const earliest = now - Limits.MAX_DAYS * DAY_MS2;
342
+ const latest = now - Limits.LOOK_BACK_DAYS * DAY_MS2;
343
+ return Math.max(earliest, Math.min(latest, last ?? latest));
344
+ }
345
+ PaceUtil.since = since;
346
+ })(PaceUtil ||= {});
347
+
348
+ // web-src/initiative-store.ts
349
+ var KEYS = [Keys.SETTINGS, Keys.LAST, Keys.FILE, Keys.NOTE, Keys.PROFILE, Keys.MODE, Keys.LOCKS, Keys.PROPOSALS, Keys.SEEN, Keys.QUIET];
350
+
351
+ class InitiativeStore {
352
+ pi;
353
+ current = {
354
+ review: { settings: PaceUtil.DEFAULT },
355
+ kinds: [],
356
+ proposals: [],
357
+ mode: "balanced",
358
+ seen: 0,
359
+ quiet: NotifyUtil.QUIET,
360
+ loaded: false
361
+ };
362
+ listeners = new Set;
363
+ constructor(pi) {
364
+ this.pi = pi;
365
+ this.read();
366
+ pi.storage.onChange((keys) => keys.some((key) => KEYS.includes(key)) && this.read());
367
+ }
368
+ get state() {
369
+ return this.current;
370
+ }
371
+ get status() {
372
+ return this.current.review;
373
+ }
374
+ subscribe(listener) {
375
+ this.listeners.add(listener);
376
+ return () => this.listeners.delete(listener);
377
+ }
378
+ async change(patch) {
379
+ const settings = PaceUtil.settings({ ...this.current.review.settings, ...patch });
380
+ this.set({ ...this.current, review: { ...this.current.review, settings } });
381
+ await this.pi.storage.set(Keys.SETTINGS, settings);
382
+ }
383
+ async saveProfile(profile) {
384
+ const kept = await this.pi.callHost("setProfile", profile);
385
+ this.set({ ...this.current, review: { ...this.current.review, profile: kept || undefined } });
386
+ }
387
+ async decide(id, decision) {
388
+ await this.pi.callHost("decide", id, decision);
389
+ this.read();
390
+ }
391
+ async undo(id) {
392
+ await this.pi.callHost("undo", id);
393
+ this.read();
394
+ }
395
+ async setLevel(kind, level) {
396
+ await this.pi.callHost("setLevel", kind, level);
397
+ this.read();
398
+ }
399
+ async setMode(mode) {
400
+ this.set({ ...this.current, mode });
401
+ await this.pi.callHost("setMode", mode);
402
+ this.read();
403
+ }
404
+ async setQuiet(patch) {
405
+ const quiet = NotifyUtil.quiet({ ...this.current.quiet, ...patch });
406
+ this.set({ ...this.current, quiet });
407
+ await this.pi.storage.set(Keys.QUIET, quiet);
408
+ }
409
+ see() {
410
+ const newest = this.current.proposals.reduce((at, proposal) => Math.max(at, proposal.at, proposal.decidedAt ?? 0), 0);
411
+ if (newest > this.current.seen) {
412
+ this.set({ ...this.current, seen: newest });
413
+ this.pi.storage.set(Keys.SEEN, newest).catch(() => {
414
+ return;
415
+ });
416
+ }
417
+ }
418
+ read() {
419
+ Promise.all([
420
+ this.pi.callHost("reviewStatus").catch(() => {
421
+ return;
422
+ }),
423
+ this.pi.callHost("kinds").catch(() => {
424
+ return;
425
+ }),
426
+ this.pi.storage.get(Keys.PROPOSALS).catch(() => {
427
+ return;
428
+ }),
429
+ this.pi.storage.get(Keys.MODE).catch(() => {
430
+ return;
431
+ }),
432
+ this.pi.storage.get(Keys.SEEN).catch(() => {
433
+ return;
434
+ }),
435
+ this.pi.storage.get(Keys.QUIET).catch(() => {
436
+ return;
437
+ })
438
+ ]).then(([review, kinds, proposals, mode, seen, quiet]) => this.set({
439
+ review: review ? { ...review, settings: PaceUtil.settings(review.settings) } : this.current.review,
440
+ kinds: Array.isArray(kinds) ? kinds : this.current.kinds,
441
+ proposals: Array.isArray(proposals) ? proposals : [],
442
+ mode: MODES.includes(mode) ? mode : "balanced",
443
+ seen: typeof seen === "number" ? seen : 0,
444
+ quiet: NotifyUtil.quiet(quiet),
445
+ loaded: true
446
+ }));
447
+ }
448
+ set(state) {
449
+ this.current = state;
450
+ for (const listener of this.listeners) {
451
+ listener();
452
+ }
453
+ }
454
+ }
455
+ function useInitiative(react, store) {
456
+ return react.useSyncExternalStore((listener) => store.subscribe(listener), () => store.state);
457
+ }
458
+
459
+ // web-src/notices.ts
460
+ function proposalFile(proposal) {
461
+ return proposal.action?.type === "session" ? proposal.action.sessionFile : proposal.evidence?.[0];
462
+ }
463
+ function watchNotices(pi, store) {
464
+ const told = new Set;
465
+ const look = () => {
466
+ const words = InitiativeWords.of(pi.ui.language);
467
+ const now = Date.now();
468
+ for (const proposal of store.state.proposals) {
469
+ if (!proposal.notifiedAt || proposal.state !== "pending" || now - proposal.notifiedAt > Limits.NOTICE_MS || told.has(proposal.id)) {
470
+ continue;
471
+ }
472
+ told.add(proposal.id);
473
+ const file = proposalFile(proposal);
474
+ const action = proposal.action;
475
+ pi.ui.notifySession?.({
476
+ key: `ta-initiative:${proposal.id}`,
477
+ title: words.inboxTitle,
478
+ ...file ? {} : { view: `${NAME}/inbox` },
479
+ ...file ? { sessionFile: file } : {},
480
+ ...proposal.cwd ? { cwd: proposal.cwd } : {},
481
+ level: "ask",
482
+ text: proposal.why ? `${proposal.title}
483
+ ${proposal.why}` : proposal.title,
484
+ actions: [
485
+ {
486
+ label: words.accept,
487
+ run: () => void store.decide(proposal.id, "accept").then(() => action?.type === "session" ? openConversation(pi, action.sessionFile) : undefined).catch(() => {
488
+ return;
489
+ })
490
+ },
491
+ { label: words.decline, run: () => void store.decide(proposal.id, "decline").catch(() => {
492
+ return;
493
+ }) }
494
+ ]
495
+ });
496
+ }
497
+ };
498
+ look();
499
+ return store.subscribe(look);
500
+ }
501
+ function conversationProposals(proposals, sessionFile) {
502
+ return sessionFile ? proposals.filter((proposal) => proposal.state === "pending" && proposal.source === "host" && proposal.action?.type === "session" && proposal.action.sessionFile === sessionFile) : [];
503
+ }
504
+
505
+ // web-src/react.ts
506
+ var React;
507
+ function bind(react) {
508
+ React = react;
509
+ }
510
+ var idle = () => [false, async (action) => await action()];
511
+ function useBusy(ui) {
512
+ return (ui.useBusy ?? idle)();
513
+ }
514
+
515
+ // web-src/inbox.tsx
516
+ function message(error) {
517
+ return error instanceof Error ? error.message : String(error);
518
+ }
519
+ function clock(at) {
520
+ const date = new Date(at);
521
+ const pad = (value) => String(value).padStart(2, "0");
522
+ return `${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`;
523
+ }
524
+ function kindTitle(kinds, id, language) {
525
+ const kind = kinds.find((one) => one.kind.id === id)?.kind;
526
+ return kind ? /^zh/i.test(language) ? kind.title.zh : kind.title.en : id;
527
+ }
528
+ function Act({ pi, label, primary, onClick }) {
529
+ const [busy, run] = useBusy(pi.ui);
530
+ const words = InitiativeWords.of(pi.ui.language);
531
+ const act = async () => {
532
+ try {
533
+ await onClick();
534
+ } catch (error) {
535
+ pi.ui.notify(InitiativeWords.format(words.failed, { message: message(error) }), "error");
536
+ }
537
+ };
538
+ return /* @__PURE__ */ React.createElement("button", {
539
+ type: "button",
540
+ className: `ta-button${primary ? " ta-primary" : ""}${busy ? " ta-busy" : ""}`,
541
+ disabled: busy,
542
+ onClick: () => void run(act)
543
+ }, busy && /* @__PURE__ */ React.createElement("span", {
544
+ className: "ta-spinner ta-busy-mark"
545
+ }), /* @__PURE__ */ React.createElement("span", null, label));
546
+ }
547
+ function Evidence({ pi, proposal, words }) {
548
+ const files = proposal.evidence ?? [];
549
+ if (files.length === 0) {
550
+ return null;
551
+ }
552
+ return /* @__PURE__ */ React.createElement("button", {
553
+ type: "button",
554
+ className: "tin-link",
555
+ onClick: () => void openConversation(pi, files[0])
556
+ }, InitiativeWords.format(words.evidence, { count: String(files.length) }));
557
+ }
558
+ function Waiting({
559
+ pi,
560
+ store,
561
+ proposal,
562
+ kinds,
563
+ away
564
+ }) {
565
+ const words = InitiativeWords.of(pi.ui.language);
566
+ const decide = (decision) => async () => {
567
+ await store.decide(proposal.id, decision);
568
+ const action = proposal.action;
569
+ if (away && action?.type === "session" && (decision === "accept" || decision === "always")) {
570
+ await openConversation(pi, action.sessionFile);
571
+ }
572
+ };
573
+ const reversible = kinds.find((one) => one.kind.id === proposal.kind)?.kind.reversible ?? false;
574
+ return /* @__PURE__ */ React.createElement("li", {
575
+ className: "tin-card"
576
+ }, /* @__PURE__ */ React.createElement("div", {
577
+ className: "tin-kind"
578
+ }, /* @__PURE__ */ React.createElement("span", null, kindTitle(kinds, proposal.kind, pi.ui.language)), proposal.state === "digest" && /* @__PURE__ */ React.createElement("span", {
579
+ className: "tin-tag"
580
+ }, words.inBrief), /* @__PURE__ */ React.createElement("span", {
581
+ className: "tin-time"
582
+ }, clock(proposal.at))), /* @__PURE__ */ React.createElement("div", {
583
+ className: "tin-title"
584
+ }, proposal.title), proposal.why && /* @__PURE__ */ React.createElement("div", {
585
+ className: "tin-why"
586
+ }, proposal.why), /* @__PURE__ */ React.createElement(Evidence, {
587
+ pi,
588
+ proposal,
589
+ words
590
+ }), /* @__PURE__ */ React.createElement("div", {
591
+ className: "tin-actions"
592
+ }, /* @__PURE__ */ React.createElement(Act, {
593
+ pi,
594
+ label: words.accept,
595
+ primary: true,
596
+ onClick: decide("accept")
597
+ }), /* @__PURE__ */ React.createElement(Act, {
598
+ pi,
599
+ label: words.decline,
600
+ onClick: decide("decline")
601
+ })), /* @__PURE__ */ React.createElement("div", {
602
+ className: "tin-more"
603
+ }, reversible && /* @__PURE__ */ React.createElement("button", {
604
+ type: "button",
605
+ className: "tin-link",
606
+ onClick: () => void decide("always")().catch(() => {
607
+ return;
608
+ })
609
+ }, words.always), /* @__PURE__ */ React.createElement("button", {
610
+ type: "button",
611
+ className: "tin-link",
612
+ onClick: () => void decide("never")().catch(() => {
613
+ return;
614
+ })
615
+ }, words.neverAgain)));
616
+ }
617
+ function Done({
618
+ pi,
619
+ store,
620
+ proposal,
621
+ kinds,
622
+ now
623
+ }) {
624
+ const words = InitiativeWords.of(pi.ui.language);
625
+ const state = proposal.state === "undone" ? words.undoneState : proposal.state === "failed" ? InitiativeWords.format(words.failedState, { error: proposal.error ?? "" }) : "";
626
+ return /* @__PURE__ */ React.createElement("li", {
627
+ className: "tin-card tin-done",
628
+ "data-state": proposal.state
629
+ }, /* @__PURE__ */ React.createElement("div", {
630
+ className: "tin-kind"
631
+ }, /* @__PURE__ */ React.createElement("span", null, kindTitle(kinds, proposal.kind, pi.ui.language)), /* @__PURE__ */ React.createElement("span", {
632
+ className: "tin-time"
633
+ }, clock(proposal.decidedAt ?? proposal.at))), /* @__PURE__ */ React.createElement("div", {
634
+ className: "tin-title"
635
+ }, proposal.title), proposal.why && /* @__PURE__ */ React.createElement("div", {
636
+ className: "tin-why"
637
+ }, proposal.why), state && /* @__PURE__ */ React.createElement("div", {
638
+ className: "tin-state"
639
+ }, state), InboxUtil.canUndo(proposal, now) && /* @__PURE__ */ React.createElement("div", {
640
+ className: "tin-actions"
641
+ }, /* @__PURE__ */ React.createElement(Act, {
642
+ pi,
643
+ label: words.undo,
644
+ onClick: () => store.undo(proposal.id)
645
+ })));
646
+ }
647
+ function Inbox({ pi, store }) {
648
+ const state = useInitiative(React, store);
649
+ const words = InitiativeWords.of(pi.ui.language);
650
+ const now = Date.now();
651
+ const waiting = InboxUtil.waiting(state.proposals);
652
+ const done = InboxUtil.done(state.proposals, now);
653
+ React.useEffect(() => {
654
+ if (state.loaded) {
655
+ store.see();
656
+ }
657
+ }, [store, state.loaded, state.proposals]);
658
+ return /* @__PURE__ */ React.createElement("div", {
659
+ className: "tin-inbox"
660
+ }, waiting.length === 0 && done.length === 0 && state.loaded && /* @__PURE__ */ React.createElement("div", {
661
+ className: "tin-empty"
662
+ }, words.inboxEmpty), waiting.length > 0 && /* @__PURE__ */ React.createElement("section", null, /* @__PURE__ */ React.createElement("h3", {
663
+ className: "tin-head"
664
+ }, words.inboxWaiting), /* @__PURE__ */ React.createElement("ul", {
665
+ className: "tin-list"
666
+ }, waiting.map((proposal) => /* @__PURE__ */ React.createElement(Waiting, {
667
+ key: proposal.id,
668
+ pi,
669
+ store,
670
+ proposal,
671
+ kinds: state.kinds,
672
+ away: true
673
+ })))), done.length > 0 && /* @__PURE__ */ React.createElement("section", null, /* @__PURE__ */ React.createElement("h3", {
674
+ className: "tin-head"
675
+ }, words.inboxDone), /* @__PURE__ */ React.createElement("ul", {
676
+ className: "tin-list"
677
+ }, done.map((proposal) => /* @__PURE__ */ React.createElement(Done, {
678
+ key: proposal.id,
679
+ pi,
680
+ store,
681
+ proposal,
682
+ kinds: state.kinds,
683
+ now
684
+ })))));
685
+ }
686
+ function AboveComposer({ pi, store, sessionFile }) {
687
+ const state = useInitiative(React, store);
688
+ const proposals = conversationProposals(state.proposals, sessionFile);
689
+ if (proposals.length === 0) {
690
+ return null;
691
+ }
692
+ return /* @__PURE__ */ React.createElement("ul", {
693
+ className: "tin-list tin-above"
694
+ }, proposals.map((proposal) => /* @__PURE__ */ React.createElement(Waiting, {
695
+ key: proposal.id,
696
+ pi,
697
+ store,
698
+ proposal,
699
+ kinds: state.kinds
700
+ })));
701
+ }
702
+ function ProposalCards({ pi, store, ids }) {
703
+ const state = useInitiative(React, store);
704
+ const now = Date.now();
705
+ const words = InitiativeWords.of(pi.ui.language);
706
+ const proposals = ids.flatMap((id) => state.proposals.filter((proposal) => proposal.id === id));
707
+ if (proposals.length === 0) {
708
+ return null;
709
+ }
710
+ return /* @__PURE__ */ React.createElement("ul", {
711
+ className: "tin-list tin-in-chat"
712
+ }, proposals.map((proposal) => waits(proposal) ? /* @__PURE__ */ React.createElement(Waiting, {
713
+ key: proposal.id,
714
+ pi,
715
+ store,
716
+ proposal,
717
+ kinds: state.kinds
718
+ }) : proposal.auto ? /* @__PURE__ */ React.createElement(Done, {
719
+ key: proposal.id,
720
+ pi,
721
+ store,
722
+ proposal,
723
+ kinds: state.kinds,
724
+ now
725
+ }) : /* @__PURE__ */ React.createElement("li", {
726
+ key: proposal.id,
727
+ className: "tin-decided"
728
+ }, proposal.state === "done" ? words.acceptedLine : proposal.state === "declined" ? words.declinedLine : words.expiredLine, " · ", proposal.title)));
729
+ }
730
+
731
+ // web-src/page-initiative.ts
732
+ var PAGE = "@celljs/ta-web";
733
+ function pageInitiative(pi, store) {
734
+ const define = (kind) => pi.callHost("defineKind", { ...kind, owner: PAGE });
735
+ const levels = () => JSON.stringify(store.state.kinds.map((status) => [status.kind.id, status.level, status.locked ?? ""]));
736
+ return {
737
+ level: async (kind) => {
738
+ await define(kind);
739
+ return pi.callHost("level", kind.id);
740
+ },
741
+ setLevel: async (kind, level) => {
742
+ await define(kind);
743
+ await store.setLevel(kind.id, level);
744
+ },
745
+ record: async (kind, outcome, title) => {
746
+ await define(kind);
747
+ await pi.callHost("record", { kind: kind.id, title, why: "", outcome });
748
+ },
749
+ subscribe: (listener) => {
750
+ let last = levels();
751
+ return store.subscribe(() => {
752
+ const now = levels();
753
+ if (now !== last) {
754
+ last = now;
755
+ listener();
756
+ }
757
+ });
758
+ }
759
+ };
760
+ }
761
+
762
+ // web-src/settings.tsx
763
+ function message2(error) {
764
+ return error instanceof Error ? error.message : String(error);
765
+ }
766
+ function notifyFailure(pi, error) {
767
+ pi.ui.notify(InitiativeWords.format(InitiativeWords.of(pi.ui.language).failed, { message: message2(error) }), "error");
768
+ }
769
+ function useStatus(store) {
770
+ const [status, setStatus] = React.useState(store.status);
771
+ React.useEffect(() => {
772
+ setStatus(store.status);
773
+ return store.subscribe(() => setStatus(store.status));
774
+ }, [store]);
775
+ return status;
776
+ }
777
+ function Toggle({ pi, checked, label, onChange }) {
778
+ const Switch = pi.ui.Switch;
779
+ if (Switch) {
780
+ return /* @__PURE__ */ React.createElement(Switch, {
781
+ checked,
782
+ label,
783
+ onChange: (on) => onChange(on).catch((error) => notifyFailure(pi, error))
784
+ });
785
+ }
786
+ return /* @__PURE__ */ React.createElement("input", {
787
+ type: "checkbox",
788
+ role: "switch",
789
+ className: "ta-switch",
790
+ checked,
791
+ "aria-checked": checked,
792
+ "aria-label": label,
793
+ onChange: (event) => void onChange(event.target.checked).catch((error) => notifyFailure(pi, error))
794
+ });
795
+ }
796
+ function SettingSwitch({ pi, store, field, label }) {
797
+ const { settings } = useStatus(store);
798
+ return /* @__PURE__ */ React.createElement(Toggle, {
799
+ pi,
800
+ checked: settings[field],
801
+ label,
802
+ onChange: (on) => store.change({ [field]: on })
803
+ });
804
+ }
805
+ function everyLabel(words, days) {
806
+ const named = { 1: words.every1, 7: words.every7, 14: words.every14, 30: words.every30 };
807
+ return named[days] ?? InitiativeWords.format(words.everyDays, { days: String(days) });
808
+ }
809
+ function Every({ pi, store }) {
810
+ const words = InitiativeWords.of(pi.ui.language);
811
+ const { settings } = useStatus(store);
812
+ const choices = PaceUtil.CHOICES.includes(settings.every) ? PaceUtil.CHOICES : [...PaceUtil.CHOICES, settings.every].sort((a, b) => a - b);
813
+ return /* @__PURE__ */ React.createElement("select", {
814
+ className: "tev-field",
815
+ "aria-label": words.everyLabel,
816
+ value: settings.every,
817
+ disabled: !settings.enabled,
818
+ onChange: (event) => void store.change({ every: Number(event.target.value) }).catch((error) => notifyFailure(pi, error))
819
+ }, choices.map((days) => /* @__PURE__ */ React.createElement("option", {
820
+ key: days,
821
+ value: days
822
+ }, everyLabel(words, days))));
823
+ }
824
+ function Time({ pi, store }) {
825
+ const words = InitiativeWords.of(pi.ui.language);
826
+ const { settings } = useStatus(store);
827
+ return /* @__PURE__ */ React.createElement("input", {
828
+ type: "time",
829
+ className: "tev-field",
830
+ "aria-label": words.timeLabel,
831
+ value: settings.time,
832
+ disabled: !settings.enabled,
833
+ onChange: (event) => PaceUtil.parseTime(event.target.value) && void store.change({ time: event.target.value }).catch((error) => notifyFailure(pi, error))
834
+ });
835
+ }
836
+ function when(at, words) {
837
+ if (at === undefined) {
838
+ return words.never;
839
+ }
840
+ const date = new Date(at);
841
+ const pad = (value) => String(value).padStart(2, "0");
842
+ return `${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`;
843
+ }
844
+ function Now({ pi, store }) {
845
+ const words = InitiativeWords.of(pi.ui.language);
846
+ const status = useStatus(store);
847
+ const [busy, run] = useBusy(pi.ui);
848
+ const review = async () => {
849
+ try {
850
+ const file = await pi.callHost("reviewNow");
851
+ if (file) {
852
+ await openConversation(pi, file);
853
+ }
854
+ } catch (error) {
855
+ notifyFailure(pi, error);
856
+ }
857
+ };
858
+ const line = status.file ? InitiativeWords.format(words.lastNext, { last: when(status.last, words), next: when(status.next, words) }) : status.next !== undefined ? InitiativeWords.format(words.nextOnly, { next: when(status.next, words) }) : "";
859
+ return /* @__PURE__ */ React.createElement("div", {
860
+ className: "tev-now"
861
+ }, line && /* @__PURE__ */ React.createElement("span", {
862
+ className: "tev-when"
863
+ }, line), /* @__PURE__ */ React.createElement("button", {
864
+ type: "button",
865
+ className: `ta-button${busy ? " ta-busy" : ""}`,
866
+ disabled: busy,
867
+ onClick: () => void run(review)
868
+ }, busy && /* @__PURE__ */ React.createElement("span", {
869
+ className: "ta-spinner ta-busy-mark"
870
+ }), /* @__PURE__ */ React.createElement("span", null, words.nowButton)));
871
+ }
872
+ function Profile({ pi, store }) {
873
+ const words = InitiativeWords.of(pi.ui.language);
874
+ const status = useStatus(store);
875
+ const stored = status.profile ?? "";
876
+ const [text, setText] = React.useState(stored);
877
+ const [edited, setEdited] = React.useState(false);
878
+ const [busy, run] = useBusy(pi.ui);
879
+ React.useEffect(() => {
880
+ if (!edited) {
881
+ setText(stored);
882
+ }
883
+ }, [stored, edited]);
884
+ const save = async () => {
885
+ try {
886
+ await store.saveProfile(text);
887
+ setEdited(false);
888
+ pi.ui.notify(words.profileSaved, "info");
889
+ } catch (error) {
890
+ notifyFailure(pi, error);
891
+ }
892
+ };
893
+ return /* @__PURE__ */ React.createElement("div", {
894
+ className: "tev-profile"
895
+ }, /* @__PURE__ */ React.createElement("textarea", {
896
+ className: "tev-field tev-profile-text",
897
+ "aria-label": words.profileLabel,
898
+ placeholder: words.profileEmpty,
899
+ value: text,
900
+ disabled: !status.settings.learn,
901
+ onChange: (event) => {
902
+ setText(event.target.value);
903
+ setEdited(true);
904
+ }
905
+ }), edited && /* @__PURE__ */ React.createElement("button", {
906
+ type: "button",
907
+ className: `ta-button${busy ? " ta-busy" : ""}`,
908
+ disabled: busy,
909
+ onClick: () => void run(save)
910
+ }, busy && /* @__PURE__ */ React.createElement("span", {
911
+ className: "ta-spinner ta-busy-mark"
912
+ }), /* @__PURE__ */ React.createElement("span", null, words.profileSave)));
913
+ }
914
+ function levelLabel(words, level) {
915
+ return { off: words.levelOff, digest: words.levelDigest, ask: words.levelAsk, act: words.levelAct }[level];
916
+ }
917
+ var MODE_WORDS = { quiet: "modeQuiet", balanced: "modeBalanced", active: "modeActive" };
918
+ function ModeSelect({ pi, store }) {
919
+ const words = InitiativeWords.of(pi.ui.language);
920
+ const { mode } = useInitiative(React, store);
921
+ return /* @__PURE__ */ React.createElement("select", {
922
+ className: "tev-field",
923
+ "aria-label": words.modeLabel,
924
+ value: mode,
925
+ onChange: (event) => void store.setMode(event.target.value).catch((error) => notifyFailure(pi, error))
926
+ }, MODES.map((one) => /* @__PURE__ */ React.createElement("option", {
927
+ key: one,
928
+ value: one
929
+ }, words[MODE_WORDS[one]])));
930
+ }
931
+ function reasonText(words, status) {
932
+ const date = status.reason.at ? new Date(status.reason.at).toLocaleDateString() : "";
933
+ switch (status.reason.cause) {
934
+ case "up":
935
+ return InitiativeWords.format(words.reasonUp, { date });
936
+ case "down":
937
+ return InitiativeWords.format(words.reasonDown, { date });
938
+ case "locked":
939
+ return words.reasonLocked;
940
+ default:
941
+ return words.reasonStart;
942
+ }
943
+ }
944
+ function Quiet({ pi, store }) {
945
+ const words = InitiativeWords.of(pi.ui.language);
946
+ const { quiet } = useInitiative(React, store);
947
+ const time = (field, label) => /* @__PURE__ */ React.createElement("input", {
948
+ type: "time",
949
+ className: "tev-field",
950
+ "aria-label": label,
951
+ value: quiet[field],
952
+ disabled: !quiet.enabled,
953
+ onChange: (event) => void store.setQuiet({ [field]: event.target.value }).catch((error) => notifyFailure(pi, error))
954
+ });
955
+ return /* @__PURE__ */ React.createElement("div", {
956
+ className: "tin-quiet"
957
+ }, time("start", words.quietFrom), /* @__PURE__ */ React.createElement("span", {
958
+ className: "tev-when"
959
+ }, words.quietTo), time("end", words.quietTo), /* @__PURE__ */ React.createElement(Toggle, {
960
+ pi,
961
+ checked: quiet.enabled,
962
+ label: words.quietLabel,
963
+ onChange: (enabled) => store.setQuiet({ enabled })
964
+ }));
965
+ }
966
+ function Kinds({ pi, store }) {
967
+ const words = InitiativeWords.of(pi.ui.language);
968
+ const { kinds } = useInitiative(React, store);
969
+ const zh2 = /^zh/i.test(pi.ui.language);
970
+ return /* @__PURE__ */ React.createElement("ul", {
971
+ className: "tin-kinds"
972
+ }, kinds.map((status) => /* @__PURE__ */ React.createElement("li", {
973
+ key: status.kind.id,
974
+ className: "tin-kind-row"
975
+ }, /* @__PURE__ */ React.createElement("div", {
976
+ className: "tin-kind-text"
977
+ }, /* @__PURE__ */ React.createElement("div", {
978
+ className: "tin-kind-name"
979
+ }, zh2 ? status.kind.title.zh : status.kind.title.en), /* @__PURE__ */ React.createElement("div", {
980
+ className: "tin-kind-reason"
981
+ }, reasonText(words, status))), /* @__PURE__ */ React.createElement("select", {
982
+ className: "tev-field",
983
+ "aria-label": zh2 ? status.kind.title.zh : status.kind.title.en,
984
+ value: status.locked ?? "auto",
985
+ onChange: (event) => {
986
+ const value = event.target.value;
987
+ store.setLevel(status.kind.id, value === "auto" ? null : value).catch((error) => notifyFailure(pi, error));
988
+ }
989
+ }, /* @__PURE__ */ React.createElement("option", {
990
+ value: "auto"
991
+ }, status.locked ? words.levelAutoPlain : InitiativeWords.format(words.levelAuto, { level: levelLabel(words, status.level) })), LEVELS.filter((level) => level !== "act" || status.kind.reversible).map((level) => /* @__PURE__ */ React.createElement("option", {
992
+ key: level,
993
+ value: level
994
+ }, levelLabel(words, level)))))));
995
+ }
996
+ function initiativeSettings(pi, store) {
997
+ const words = () => InitiativeWords.of(pi.ui.language);
998
+ const autoHint = () => {
999
+ const { note, settings } = store.status;
1000
+ return settings.auto && note ? `${words().autoHint} ${InitiativeWords.format(words().autoNote, { note })}` : words().autoHint;
1001
+ };
1002
+ return {
1003
+ title: () => words().settingsTitle,
1004
+ icon: pi.ui.icons.Sparkles,
1005
+ rows: [
1006
+ { key: "mode", label: () => words().modeLabel, description: () => words().modeHint, render: () => /* @__PURE__ */ React.createElement(ModeSelect, {
1007
+ pi,
1008
+ store
1009
+ }) },
1010
+ { key: "quiet", label: () => words().quietLabel, description: () => words().quietHint, render: () => /* @__PURE__ */ React.createElement(Quiet, {
1011
+ pi,
1012
+ store
1013
+ }) },
1014
+ {
1015
+ key: "kinds",
1016
+ label: () => words().kindsLabel,
1017
+ description: () => words().kindsHint,
1018
+ render: () => /* @__PURE__ */ React.createElement(Kinds, {
1019
+ pi,
1020
+ store
1021
+ }),
1022
+ stacked: true
1023
+ },
1024
+ {
1025
+ key: "enabled",
1026
+ label: () => words().enabledLabel,
1027
+ description: () => words().enabledHint,
1028
+ render: () => /* @__PURE__ */ React.createElement(SettingSwitch, {
1029
+ pi,
1030
+ store,
1031
+ field: "enabled",
1032
+ label: words().enabledLabel
1033
+ })
1034
+ },
1035
+ { key: "every", label: () => words().everyLabel, render: () => /* @__PURE__ */ React.createElement(Every, {
1036
+ pi,
1037
+ store
1038
+ }) },
1039
+ { key: "time", label: () => words().timeLabel, render: () => /* @__PURE__ */ React.createElement(Time, {
1040
+ pi,
1041
+ store
1042
+ }) },
1043
+ {
1044
+ key: "auto",
1045
+ label: () => words().autoLabel,
1046
+ description: autoHint,
1047
+ render: () => /* @__PURE__ */ React.createElement(SettingSwitch, {
1048
+ pi,
1049
+ store,
1050
+ field: "auto",
1051
+ label: words().autoLabel
1052
+ })
1053
+ },
1054
+ {
1055
+ key: "learn",
1056
+ label: () => words().learnLabel,
1057
+ description: () => words().learnHint,
1058
+ render: () => /* @__PURE__ */ React.createElement(SettingSwitch, {
1059
+ pi,
1060
+ store,
1061
+ field: "learn",
1062
+ label: words().learnLabel
1063
+ })
1064
+ },
1065
+ {
1066
+ key: "profile",
1067
+ label: () => words().profileLabel,
1068
+ description: () => words().profileHint,
1069
+ render: () => /* @__PURE__ */ React.createElement(Profile, {
1070
+ pi,
1071
+ store
1072
+ }),
1073
+ stacked: true
1074
+ },
1075
+ { key: "now", label: () => words().nowLabel, render: () => /* @__PURE__ */ React.createElement(Now, {
1076
+ pi,
1077
+ store
1078
+ }), stacked: true }
1079
+ ]
1080
+ };
1081
+ }
1082
+
1083
+ // web-src/style.ts
1084
+ var STYLE = `
1085
+ .tev-field { height: 32px; padding: 0 8px; border: 1px solid var(--ta-border-field); border-radius: 8px; background: transparent; color: var(--ta-text); font: inherit; font-size: calc(13px * var(--ta-font-scale)); }
1086
+ .tev-field:disabled { opacity: 0.5; }
1087
+ .tev-now { flex: 1; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: space-between; }
1088
+ .tev-profile { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; width: 100%; }
1089
+ .tev-profile-text { width: 100%; height: auto; min-height: 160px; padding: 8px; box-sizing: border-box; line-height: 1.55; resize: vertical; font-size: calc(13px * var(--ta-font-scale)); }
1090
+ [data-touch] .tev-profile-text { font-size: 16px; }
1091
+ /* The suggestions: a card each, its kind, what and why, the answers */
1092
+ .tin-inbox { max-width: 680px; margin: 0 auto; padding: 12px 16px 32px; }
1093
+ .tin-head { margin: 16px 2px 8px; color: var(--ta-muted); font-size: calc(12.5px * var(--ta-font-scale)); font-weight: 500; }
1094
+ .tin-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 10px; }
1095
+ .tin-card { padding: 12px 14px; border: 1px solid var(--ta-border-muted); border-radius: 12px; background: var(--ta-card); }
1096
+ .tin-kind { display: flex; align-items: center; gap: 8px; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
1097
+ .tin-kind > span:first-child { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1098
+ .tin-tag { flex: none; padding: 0 6px; border-radius: 6px; background: var(--ta-hover); }
1099
+ .tin-time { flex: none; font-variant-numeric: tabular-nums; }
1100
+ .tin-title { margin-top: 6px; color: var(--ta-text); font-size: calc(15px * var(--ta-font-scale)); font-weight: 600; line-height: 1.45; overflow-wrap: anywhere; }
1101
+ .tin-why { margin-top: 4px; color: var(--ta-text); font-size: calc(13.5px * var(--ta-font-scale)); line-height: 1.55; opacity: 0.85; overflow-wrap: anywhere; }
1102
+ .tin-state { margin-top: 6px; color: var(--ta-muted); font-size: calc(12.5px * var(--ta-font-scale)); }
1103
+ .tin-card[data-state='failed'] .tin-state { color: var(--ta-red, #d33); }
1104
+ .tin-done .tin-title { font-weight: 500; }
1105
+ .tin-actions { display: flex; gap: 8px; margin-top: 10px; }
1106
+ .tin-actions .ta-button { min-width: 64px; justify-content: center; }
1107
+ [data-touch] .tin-actions .ta-button { min-height: 38px; flex: 1; }
1108
+ .tin-more { display: flex; gap: 14px; margin-top: 8px; }
1109
+ .tin-link { padding: 0; border: 0; background: none; color: var(--ta-muted); font: inherit; font-size: calc(12.5px * var(--ta-font-scale)); cursor: pointer; text-align: left; }
1110
+ .tin-link:hover { color: var(--ta-text); }
1111
+ .tin-card > .tin-link { margin-top: 6px; display: block; }
1112
+ .tin-above { margin: 0 0 8px; }
1113
+ .tin-above .tin-card { padding: 10px 12px; }
1114
+ .tin-in-chat { margin: 4px 0; max-width: 620px; }
1115
+ .tin-decided { color: var(--ta-muted); font-size: calc(12.5px * var(--ta-font-scale)); overflow-wrap: anywhere; }
1116
+ .tin-empty { padding: 48px 12px; color: var(--ta-muted); text-align: center; font-size: calc(13.5px * var(--ta-font-scale)); line-height: 1.6; }
1117
+ .tin-quiet { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
1118
+ /* The kinds, in the settings */
1119
+ .tin-kinds { margin: 0; padding: 0; list-style: none; width: 100%; }
1120
+ .tin-kind-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-top: 1px solid var(--ta-border-muted); }
1121
+ .tin-kind-row:first-child { border-top: 0; }
1122
+ .tin-kind-text { flex: 1; min-width: 0; }
1123
+ .tin-kind-name { color: var(--ta-text); font-size: calc(13.5px * var(--ta-font-scale)); }
1124
+ .tin-kind-reason { margin-top: 2px; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
1125
+ .tev-when { color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); font-variant-numeric: tabular-nums; }
1126
+ `;
1127
+ function injectStyle() {
1128
+ const element = document.createElement("style");
1129
+ element.dataset.taPackage = "ta-initiative";
1130
+ element.textContent = STYLE;
1131
+ document.head.appendChild(element);
1132
+ return () => element.remove();
1133
+ }
1134
+
1135
+ // web-src/index.tsx
1136
+ var INBOX_VIEW = `${NAME}/inbox`;
1137
+ function chatIcons(pi, store) {
1138
+ return {
1139
+ icon: (chat) => chat.sessionFile && chat.sessionFile === store.status.file && pi.ui.icons.Sparkles ? { icon: pi.ui.icons.Sparkles, tint: "evolve" } : undefined,
1140
+ subscribe: (listener) => store.subscribe(listener)
1141
+ };
1142
+ }
1143
+ function inboxHome(pi, store) {
1144
+ let built;
1145
+ let items = [];
1146
+ return {
1147
+ items: () => {
1148
+ if (store.state !== built) {
1149
+ built = store.state;
1150
+ const words = InitiativeWords.of(pi.ui.language);
1151
+ const home = InboxUtil.home(built.proposals, built.seen, Date.now());
1152
+ const icon = pi.ui.icons.ListChecks ?? pi.ui.icons.Sparkles;
1153
+ const detail = home ? home.waiting && home.done ? InitiativeWords.format(words.homeDetail, { waiting: String(home.waiting), done: String(home.done) }) : home.waiting ? InitiativeWords.format(words.homeWaiting, { waiting: String(home.waiting) }) : InitiativeWords.format(words.homeDone, { done: String(home.done) }) : "";
1154
+ items = home && icon ? [
1155
+ {
1156
+ id: "inbox",
1157
+ title: words.inboxTitle,
1158
+ detail,
1159
+ icon,
1160
+ tint: "initiative",
1161
+ at: home.at,
1162
+ unseen: home.unseen,
1163
+ open: () => pi.ui.showView(INBOX_VIEW)
1164
+ }
1165
+ ] : [];
1166
+ }
1167
+ return items;
1168
+ },
1169
+ subscribe: (listener) => store.subscribe(listener)
1170
+ };
1171
+ }
1172
+ function activate(pi) {
1173
+ bind(pi.React);
1174
+ const removeStyle = injectStyle();
1175
+ const store = new InitiativeStore(pi);
1176
+ pi.registerSettings(initiativeSettings(pi, store));
1177
+ pi.registerView("inbox", {
1178
+ title: () => InitiativeWords.of(pi.ui.language).inboxTitle,
1179
+ icon: pi.ui.icons.ListChecks ?? pi.ui.icons.Sparkles,
1180
+ render: () => /* @__PURE__ */ React.createElement(Inbox, {
1181
+ pi,
1182
+ store
1183
+ }),
1184
+ order: 75,
1185
+ discover: true
1186
+ });
1187
+ pi.registerMessageRenderer(CARD_TYPE, ({ message: message3 }) => {
1188
+ const ids = message3.details?.ids;
1189
+ return Array.isArray(ids) ? /* @__PURE__ */ React.createElement(ProposalCards, {
1190
+ pi,
1191
+ store,
1192
+ ids: ids.filter((id) => typeof id === "string")
1193
+ }) : null;
1194
+ });
1195
+ pi.registerCodeRenderer?.(BLOCK, () => null);
1196
+ pi.registerComposerAddon({ above: ({ conversation }) => /* @__PURE__ */ React.createElement(AboveComposer, {
1197
+ pi,
1198
+ store,
1199
+ sessionFile: conversation.sessionFile
1200
+ }) });
1201
+ pi.registerInitiative?.(pageInitiative(pi, store));
1202
+ const stopNotices = watchNotices(pi, store);
1203
+ pi.registerHomeItems?.(inboxHome(pi, store));
1204
+ pi.registerChatIcon?.(chatIcons(pi, store));
1205
+ pi.registerToolRenderer?.((name, next) => {
1206
+ const words = InitiativeWords.of(pi.ui.language);
1207
+ switch (name) {
1208
+ case PACE_TOOL:
1209
+ return { renderCall: (args) => ({ verb: words.toolPace, target: typeof args.days === "number" ? String(args.days) : "" }) };
1210
+ case PROFILE_TOOL:
1211
+ return { renderCall: () => ({ verb: words.toolProfile, target: "" }) };
1212
+ case PROPOSE_TOOL:
1213
+ return { renderCall: (args) => ({ verb: words.toolPropose, target: typeof args.title === "string" ? args.title : "" }) };
1214
+ default:
1215
+ return next();
1216
+ }
1217
+ });
1218
+ return () => {
1219
+ stopNotices();
1220
+ removeStyle();
1221
+ };
1222
+ }
1223
+ export {
1224
+ activate as default,
1225
+ INBOX_VIEW
1226
+ };