@celljs/ta-cron 4.12.0 → 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/README.en.md +2 -2
- package/README.md +2 -2
- package/extension/index.mjs +113 -258
- package/host/index.mjs +9 -0
- package/package.json +12 -4
- package/web/index.js +607 -784
package/README.en.md
CHANGED
|
@@ -18,9 +18,9 @@ A pi package that comes with Ta (on by default; turn it off in Settings → Exte
|
|
|
18
18
|
/schedule help
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
Or just say "sum up yesterday's commits every day at 9": Ta makes the task with the tool `schedule_task`. The Scheduled page of the web client (under Discover by default; pin it there or under Settings > Navigation) lists every task with its rule, its next run and a switch, two lines a task on a phone; the switch moves as it is tapped, before the service answers. Opened, its prompt and the summary of each run, and "Open conversation" goes to the conversation of that run. The … of a task opens its menu (a right click or a hold does too): run it now, edit it, delete it. Tasks are made, edited, run and deleted there too; the dialog picks a task's model from a list with a search box (type part of its name, id or provider; arrows and Enter pick; the models with credentials in the settings of its directory, pi packages' such as other agents included) and its thinking level, or leaves the defaults of the settings. An opened task starts with Run now, Edit and Make an extension, its prompt shows four lines until "Show all", and the page scrolls in its own box, however long the summary of a run that is open. Make an extension opens a new conversation that asks Ta, with the ta-package skill, for an extension of the task: a page of its own that shows its results in a form that suits them (and a card of the board when that helps), where the user goes through past runs, runs it now and turns it on or off. The task keeps running here; the extension reads and drives it with `pi.packages.callPackageHost('@celljs/ta-cron', …)` (`list`, `get`, `runs`, `run`, `setEnabled`, `update`). The conversation shows one line; the task, its prompt and its last result are in a `<context>` block for the model (`web-src/task-extension.ts`), so that another coding agent without the tool `schedule_task` can make it too. The conversation is on the model of Settings → Making extensions (`makeModel` in the data of `@celljs/ta-extensions`), else the default.
|
|
21
|
+
Or just say "sum up yesterday's commits every day at 9": Ta makes the task with the tool `schedule_task`. The Scheduled page of the web client (under Discover by default; pin it there or under Settings > Navigation) lists every task with its rule, its next run and a switch, two lines a task on a phone; the switch moves as it is tapped, before the service answers. Opened, its prompt and the summary of each run, and "Open conversation" goes to the conversation of that run. The … of a task opens its menu (a right click or a hold does too): run it now, edit it, ask Ta to change it, delete it. Tasks are made, edited, run and deleted there too; the dialog picks a task's model from a list with a search box (type part of its name, id or provider; arrows and Enter pick; the models with credentials in the settings of its directory, pi packages' such as other agents included) and its thinking level, or leaves the defaults of the settings. An opened task starts with Run now, Edit, Ask Ta to change and Make an extension. Ask Ta to change asks what should change (say, "only on weekdays at 9") and opens a new conversation in the task's directory, where Ta changes only what was said with `schedule_task` (action `update`) and says in a line what changed; the conversation shows the user's words, and the task as it is, its prompt and how its last run ended are in a `<context>` block for the model (`web-src/task-change.ts`). its prompt shows four lines until "Show all", and the page scrolls in its own box, however long the summary of a run that is open. Make an extension opens a new conversation that asks Ta, with the ta-package skill, for an extension of the task: a page of its own that shows its results in a form that suits them (and a card of the board when that helps), where the user goes through past runs, runs it now and turns it on or off. The task keeps running here; the extension reads and drives it with `pi.packages.callPackageHost('@celljs/ta-cron', …)` (`list`, `get`, `runs`, `run`, `setEnabled`, `update`). The conversation shows one line; the task, its prompt and its last result are in a `<context>` block for the model (`web-src/task-extension.ts`), so that another coding agent without the tool `schedule_task` can make it too. The conversation is on the model of Settings → Making extensions (`makeModel` in the data of `@celljs/ta-extensions`), else the default.
|
|
22
22
|
|
|
23
|
-
A conversation can be made a task too: in the + on the left of the message box
|
|
23
|
+
A conversation can be made a task too: Keep in the + on the left of the message box ([@celljs/ta-recall](../ta-recall/README.en.md)) has Ta pick how to keep it, the `<context>` of its message starting with `[ta:keep]`; on that message and the three replies of the user after it, the pi extension adds a section `<ta-cron-keep>` to the system prompt: what suits a scheduled task, and to ask how often first, with two or three choices, unless it was said. When Ta picks a task, it writes what the conversation did as a prompt complete in itself (a run does not see the conversation) and ends its answer with it in a `ta-cron-task` block; the pi extension reads the block, creates the task in the directory of the conversation and answers with a "Scheduled" card (`web-src/chat-task.ts`). It needs no tool `schedule_task`, so the conversations of other coding agents have it too; the conversations of runs do not.
|
|
24
24
|
|
|
25
25
|
## Time rules
|
|
26
26
|
|
package/README.md
CHANGED
|
@@ -18,9 +18,9 @@ Ta 自带的 pi 包(默认开启,可在 Web 客户端的 设置 → 扩展
|
|
|
18
18
|
/schedule help
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
也可以直接说"每天 9 点帮我汇总昨天的提交":Ta 用工具 `schedule_task` 建任务。Web 客户端的"定时任务"页(默认收在"发现"里,可以在那里或 设置 → 导航 固定到导航栏)列出所有任务:时间规则、下次运行、开关(手机上每个任务两行),开关一点就动,不用等服务回答;展开看提示词和每次运行的总结,点"打开对话"进入那次运行的对话,任务右边的 …
|
|
21
|
+
也可以直接说"每天 9 点帮我汇总昨天的提交":Ta 用工具 `schedule_task` 建任务。Web 客户端的"定时任务"页(默认收在"发现"里,可以在那里或 设置 → 导航 固定到导航栏)列出所有任务:时间规则、下次运行、开关(手机上每个任务两行),开关一点就动,不用等服务回答;展开看提示词和每次运行的总结,点"打开对话"进入那次运行的对话,任务右边的 … 是它的菜单(右键或长按也一样):立即运行、编辑、让 Ta 改、删除;也能在这里新建、编辑、立即运行和删除;新建和编辑时从可搜索的列表里选这个任务用的模型(输入名字、模型 id 或提供方即可筛选,方向键和回车选择;任务所在目录的设置里有凭据的模型,包括 pi 包提供的,如外部 Agent)和思考级别,不选就用设置里的默认值。展开的任务顶部是"立即运行""编辑""让 Ta 改"和"做成扩展","让 Ta 改"先问一句想怎么改(比如"只在工作日早上 9 点运行"),再在任务所在目录开一个新对话,Ta 用 `schedule_task` 的 update 只改说到的地方,改完说一句改了什么;对话里只显示这句话,任务当前的设置、提示词和最近一次运行结果放在给模型的 `<context>` 块里(`web-src/task-change.ts`)。提示词先显示四行,"展开全文"看全部;页面在自己的区域里滚动,展开再长的运行总结也能滚到底。"做成扩展"开一个新对话,请 Ta 用 ta-package 技能为这个任务做一个扩展:按结果的特点做专属页面(需要时加一张小组件卡片),在里面看历史运行、立即运行、开关任务。任务仍由这里按时运行,扩展经 `pi.packages.callPackageHost('@celljs/ta-cron', …)` 读写它(`list`、`get`、`runs`、`run`、`setEnabled`、`update`);对话里只显示一句话,任务、提示词和最近一次结果放在给模型的 `<context>` 块里(`web-src/task-extension.ts`),没有 `schedule_task` 工具的外部 Agent 也能做。这个对话用 设置 → 做扩展 选的模型(`@celljs/ta-extensions` 的包数据 `makeModel`),不选就跟随默认模型。
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
也可以把一段对话直接做成任务:输入框左侧 + 里的"存下来"([@celljs/ta-recall](../ta-recall/README.md))让 Ta 判断这段对话该怎么存,消息的 `<context>` 以 `[ta:keep]` 开头;这条消息和之后用户的三条回复里,pi 扩展在系统提示加一段 `<ta-cron-keep>`,说明什么样的事适合做成定时任务、没说多久运行一次就先给两三个选项问用户。Ta 选了定时任务时,在这段对话里把做过的事写成一份独立的提示词(每次运行看不到这段对话),用一个 `ta-cron-task` 代码块收尾;pi 扩展读到它就在这段对话的目录里建好任务,并在对话里回一张"已创建定时任务"卡片(`web-src/chat-task.ts`)。这一步不靠 `schedule_task` 工具,所以外部 Agent 的对话里也能用;任务运行的对话里没有这一项。
|
|
24
24
|
|
|
25
25
|
## 时间规则
|
|
26
26
|
|
package/extension/index.mjs
CHANGED
|
@@ -5,19 +5,92 @@ var TaHostUtil;
|
|
|
5
5
|
TaHostUtil2.WAIT_MS = 1000;
|
|
6
6
|
function reach(events, name, waitMs = TaHostUtil2.WAIT_MS) {
|
|
7
7
|
return new Promise((resolve) => {
|
|
8
|
+
let heard = false;
|
|
9
|
+
let answered = false;
|
|
8
10
|
const timer = setTimeout(() => resolve(undefined), waitMs);
|
|
9
11
|
const request = {
|
|
10
12
|
name,
|
|
13
|
+
heard: () => {
|
|
14
|
+
heard = true;
|
|
15
|
+
},
|
|
11
16
|
resolve: (answer) => {
|
|
17
|
+
answered = true;
|
|
12
18
|
clearTimeout(timer);
|
|
13
19
|
resolve(answer);
|
|
14
20
|
}
|
|
15
21
|
};
|
|
16
22
|
events.emit(TA_HOST_EVENT, request);
|
|
23
|
+
if (!heard && !answered) {
|
|
24
|
+
clearTimeout(timer);
|
|
25
|
+
resolve(undefined);
|
|
26
|
+
}
|
|
17
27
|
});
|
|
18
28
|
}
|
|
19
29
|
TaHostUtil2.reach = reach;
|
|
30
|
+
function marked(systemPrompt, mark) {
|
|
31
|
+
return role(systemPrompt).includes(mark);
|
|
32
|
+
}
|
|
33
|
+
TaHostUtil2.marked = marked;
|
|
34
|
+
function role(systemPrompt) {
|
|
35
|
+
if (!systemPrompt) {
|
|
36
|
+
return "";
|
|
37
|
+
}
|
|
38
|
+
const open = `<addendum>
|
|
39
|
+
`;
|
|
40
|
+
const start = systemPrompt.indexOf(open);
|
|
41
|
+
const context = systemPrompt.indexOf(`<project_context>
|
|
42
|
+
`);
|
|
43
|
+
if (start < 0 || context >= 0 && context < start) {
|
|
44
|
+
return "";
|
|
45
|
+
}
|
|
46
|
+
const end = systemPrompt.indexOf(`
|
|
47
|
+
</addendum>`, start);
|
|
48
|
+
return systemPrompt.slice(start + open.length, end < 0 ? undefined : end);
|
|
49
|
+
}
|
|
50
|
+
TaHostUtil2.role = role;
|
|
20
51
|
})(TaHostUtil || (TaHostUtil = {}));
|
|
52
|
+
var TA_KEEP_MARK = "[ta:keep]";
|
|
53
|
+
var TA_ASK_ENTRY = "ta-ask";
|
|
54
|
+
var TaAskUtil;
|
|
55
|
+
(function(TaAskUtil2) {
|
|
56
|
+
const LENGTH = 120;
|
|
57
|
+
function entry(question) {
|
|
58
|
+
const line = question.replace(/\s+/g, " ").trim();
|
|
59
|
+
return { question: line.length > LENGTH ? `${line.slice(0, LENGTH - 1)}…` : line };
|
|
60
|
+
}
|
|
61
|
+
TaAskUtil2.entry = entry;
|
|
62
|
+
function asking(entries) {
|
|
63
|
+
var _a;
|
|
64
|
+
for (let i = entries.length - 1;i >= 0; i--) {
|
|
65
|
+
const entry2 = entries[i];
|
|
66
|
+
if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY) {
|
|
70
|
+
return read(entry2);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
TaAskUtil2.asking = asking;
|
|
76
|
+
function next(asked, entry2) {
|
|
77
|
+
var _a;
|
|
78
|
+
if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
return entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY ? read(entry2) : asked;
|
|
82
|
+
}
|
|
83
|
+
TaAskUtil2.next = next;
|
|
84
|
+
function read(found) {
|
|
85
|
+
var _a;
|
|
86
|
+
const question = (_a = found.data) === null || _a === undefined ? undefined : _a.question;
|
|
87
|
+
if (typeof question !== "string" || !question.trim()) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const at = found.timestamp ? Date.parse(found.timestamp) : Number.NaN;
|
|
91
|
+
return { question: entry(question).question, at: Number.isNaN(at) ? 0 : at };
|
|
92
|
+
}
|
|
93
|
+
})(TaAskUtil || (TaAskUtil = {}));
|
|
21
94
|
|
|
22
95
|
// web-src/cron-protocol.ts
|
|
23
96
|
var NAME = "@celljs/ta-cron";
|
|
@@ -45,235 +118,6 @@ var Limits;
|
|
|
45
118
|
Limits.PARALLEL_RUNS = 3;
|
|
46
119
|
})(Limits ||= {});
|
|
47
120
|
|
|
48
|
-
// web-src/i18n.ts
|
|
49
|
-
var EN = {
|
|
50
|
-
title: "Scheduled",
|
|
51
|
-
cardTitle: "Next up",
|
|
52
|
-
cardEmpty: "Nothing scheduled",
|
|
53
|
-
newTask: "New task",
|
|
54
|
-
editTask: "Edit task",
|
|
55
|
-
count: "{count} tasks",
|
|
56
|
-
runningCount: "{count} running",
|
|
57
|
-
emptyTitle: "Let Ta work on a schedule",
|
|
58
|
-
emptyHint: "Each run is a new conversation; you get the summary.",
|
|
59
|
-
example1: "Sum up yesterday’s commits",
|
|
60
|
-
example2: "Check that CI passes",
|
|
61
|
-
example3: "Write the daily report",
|
|
62
|
-
next: "in {time}",
|
|
63
|
-
nextAt: "Next {time}",
|
|
64
|
-
running: "Running…",
|
|
65
|
-
paused: "Paused",
|
|
66
|
-
done: "Done",
|
|
67
|
-
runNow: "Run now",
|
|
68
|
-
edit: "Edit",
|
|
69
|
-
delete: "Delete",
|
|
70
|
-
confirmDelete: "Delete {name}?",
|
|
71
|
-
confirmDeleteMessage: "Its runs go too; their conversations stay.",
|
|
72
|
-
enable: "On",
|
|
73
|
-
prompt: "What should Ta do?",
|
|
74
|
-
promptPlaceholder: "For example: check whether CI on main passes; if not, find out why",
|
|
75
|
-
name: "Name",
|
|
76
|
-
namePlaceholder: "Optional",
|
|
77
|
-
when: "When",
|
|
78
|
-
once: "Once",
|
|
79
|
-
every: "Every",
|
|
80
|
-
daily: "Daily",
|
|
81
|
-
weekdays: "Weekdays",
|
|
82
|
-
weekly: "Weekly",
|
|
83
|
-
custom: "Cron",
|
|
84
|
-
minutes: "minutes",
|
|
85
|
-
hours: "hours",
|
|
86
|
-
days: "days",
|
|
87
|
-
directory: "Directory",
|
|
88
|
-
notify: "Tell me",
|
|
89
|
-
notifyDefault: "Default",
|
|
90
|
-
notifyAlways: "Every run",
|
|
91
|
-
notifyError: "When it fails",
|
|
92
|
-
notifyNever: "Never",
|
|
93
|
-
model: "Model",
|
|
94
|
-
thinking: "Thinking",
|
|
95
|
-
more: "More",
|
|
96
|
-
cancel: "Cancel",
|
|
97
|
-
save: "Save",
|
|
98
|
-
create: "Create",
|
|
99
|
-
preview: "Next run {time}",
|
|
100
|
-
noNext: "No next run",
|
|
101
|
-
runs: "Runs",
|
|
102
|
-
noRuns: "No runs yet",
|
|
103
|
-
byHand: "by hand",
|
|
104
|
-
openChat: "Open conversation",
|
|
105
|
-
noChat: "This run has no conversation.",
|
|
106
|
-
success: "Done",
|
|
107
|
-
error: "Failed",
|
|
108
|
-
missed: "Missed",
|
|
109
|
-
interrupted: "The Ta service stopped during the run.",
|
|
110
|
-
timeout: "The run took too long and was stopped.",
|
|
111
|
-
missedText: "The Ta service was not running at its time.",
|
|
112
|
-
started: "Started {name}",
|
|
113
|
-
finished: "{name} is done",
|
|
114
|
-
failed: "{name} failed",
|
|
115
|
-
created: "Scheduled",
|
|
116
|
-
updated: "Updated",
|
|
117
|
-
enabled: "Turned on",
|
|
118
|
-
disabled: "Turned off",
|
|
119
|
-
removed: "Removed {names}",
|
|
120
|
-
removedNone: "Nothing removed",
|
|
121
|
-
noTasks: "No scheduled tasks yet. Try /loop 30m <prompt>.",
|
|
122
|
-
show: "Show",
|
|
123
|
-
failedAction: "Could not do it: {message}",
|
|
124
|
-
help: "Scheduled tasks",
|
|
125
|
-
serviceNeeded: "Scheduled tasks run in the Ta service.",
|
|
126
|
-
makeExtension: "Make an extension",
|
|
127
|
-
makeExtensionHint: "Ta makes a page of its own for what this task finds",
|
|
128
|
-
extensionAsk: 'Make the scheduled task "{name}" an extension that shows its results',
|
|
129
|
-
promptLabel: "What Ta does",
|
|
130
|
-
showAll: "Show all",
|
|
131
|
-
showLess: "Show less",
|
|
132
|
-
stats: "Ran {runs} times",
|
|
133
|
-
statsFailed: "Ran {runs} times · {fails} failed",
|
|
134
|
-
lastRun: "Last {time}",
|
|
135
|
-
moreOptions: "More options",
|
|
136
|
-
shortcut: "{key} + Enter to {action}",
|
|
137
|
-
modelFailed: "The model for making extensions ({model}) cannot be used, so the default one is: {message}",
|
|
138
|
-
fromChat: "Make a scheduled task",
|
|
139
|
-
fromChatDetail: "Do this again on a schedule",
|
|
140
|
-
fromChatWhen: "How often",
|
|
141
|
-
fromChatOther: "Another time",
|
|
142
|
-
fromChatOtherDetail: "Ta asks you",
|
|
143
|
-
fromChatAsk: "Make what this conversation did a scheduled task: {when}",
|
|
144
|
-
fromChatAskWhen: "Make what this conversation did a scheduled task; ask me how often first",
|
|
145
|
-
toolAdd: "Schedule",
|
|
146
|
-
toolUpdate: "Change scheduled task",
|
|
147
|
-
toolList: "List scheduled tasks",
|
|
148
|
-
toolShow: "Look at scheduled task",
|
|
149
|
-
toolEnable: "Turn on scheduled task",
|
|
150
|
-
toolDisable: "Pause scheduled task",
|
|
151
|
-
toolDelete: "Delete scheduled task",
|
|
152
|
-
toolRun: "Run scheduled task",
|
|
153
|
-
toolRuns: "Look at the runs of",
|
|
154
|
-
toolClear: "Clear scheduled tasks",
|
|
155
|
-
toolOther: "Scheduled tasks"
|
|
156
|
-
};
|
|
157
|
-
var ZH = {
|
|
158
|
-
title: "定时任务",
|
|
159
|
-
cardTitle: "接下来",
|
|
160
|
-
cardEmpty: "没有排着的任务",
|
|
161
|
-
newTask: "新建任务",
|
|
162
|
-
editTask: "编辑任务",
|
|
163
|
-
count: "{count} 个任务",
|
|
164
|
-
runningCount: "{count} 个运行中",
|
|
165
|
-
emptyTitle: "让 Ta 按时干活",
|
|
166
|
-
emptyHint: "每次运行都是一个新对话,结束后给你看总结。",
|
|
167
|
-
example1: "汇总昨天的提交",
|
|
168
|
-
example2: "检查 CI 是否通过",
|
|
169
|
-
example3: "写今天的日报",
|
|
170
|
-
next: "{time}后",
|
|
171
|
-
nextAt: "下次 {time}",
|
|
172
|
-
running: "运行中…",
|
|
173
|
-
paused: "已暂停",
|
|
174
|
-
done: "已完成",
|
|
175
|
-
runNow: "立即运行",
|
|
176
|
-
edit: "编辑",
|
|
177
|
-
delete: "删除",
|
|
178
|
-
confirmDelete: "删除“{name}”?",
|
|
179
|
-
confirmDeleteMessage: "它的运行记录一起删除;对话保留。",
|
|
180
|
-
enable: "启用",
|
|
181
|
-
prompt: "要 Ta 做什么?",
|
|
182
|
-
promptPlaceholder: "例如:检查 main 分支的 CI 是否通过,没通过就查明原因",
|
|
183
|
-
name: "名字",
|
|
184
|
-
namePlaceholder: "可不填",
|
|
185
|
-
when: "时间",
|
|
186
|
-
once: "一次",
|
|
187
|
-
every: "每隔",
|
|
188
|
-
daily: "每天",
|
|
189
|
-
weekdays: "工作日",
|
|
190
|
-
weekly: "每周",
|
|
191
|
-
custom: "Cron",
|
|
192
|
-
minutes: "分钟",
|
|
193
|
-
hours: "小时",
|
|
194
|
-
days: "天",
|
|
195
|
-
directory: "目录",
|
|
196
|
-
notify: "通知我",
|
|
197
|
-
notifyDefault: "默认",
|
|
198
|
-
notifyAlways: "每次运行",
|
|
199
|
-
notifyError: "失败时",
|
|
200
|
-
notifyNever: "不通知",
|
|
201
|
-
model: "模型",
|
|
202
|
-
thinking: "思考级别",
|
|
203
|
-
more: "更多",
|
|
204
|
-
cancel: "取消",
|
|
205
|
-
save: "保存",
|
|
206
|
-
create: "创建",
|
|
207
|
-
preview: "下次运行 {time}",
|
|
208
|
-
noNext: "没有下次运行",
|
|
209
|
-
runs: "运行记录",
|
|
210
|
-
noRuns: "还没有运行过",
|
|
211
|
-
byHand: "手动",
|
|
212
|
-
openChat: "打开对话",
|
|
213
|
-
noChat: "这次运行没有对话。",
|
|
214
|
-
success: "完成",
|
|
215
|
-
error: "失败",
|
|
216
|
-
missed: "错过",
|
|
217
|
-
interrupted: "Ta 服务在运行中途停止了。",
|
|
218
|
-
timeout: "运行时间太长,已停止。",
|
|
219
|
-
missedText: "到点时 Ta 服务没有运行。",
|
|
220
|
-
started: "已开始运行“{name}”",
|
|
221
|
-
finished: "“{name}”已完成",
|
|
222
|
-
failed: "“{name}”运行失败",
|
|
223
|
-
created: "已创建定时任务",
|
|
224
|
-
updated: "已更新",
|
|
225
|
-
enabled: "已启用",
|
|
226
|
-
disabled: "已暂停",
|
|
227
|
-
removed: "已删除 {names}",
|
|
228
|
-
removedNone: "没有删除任何任务",
|
|
229
|
-
noTasks: "还没有定时任务。试试 /loop 30m <要做的事>。",
|
|
230
|
-
show: "查看",
|
|
231
|
-
failedAction: "操作失败:{message}",
|
|
232
|
-
help: "定时任务",
|
|
233
|
-
serviceNeeded: "定时任务在 Ta 服务里运行。",
|
|
234
|
-
makeExtension: "做成扩展",
|
|
235
|
-
makeExtensionHint: "让 Ta 为这个任务的结果做一个专属页面",
|
|
236
|
-
extensionAsk: "把定时任务“{name}”做成扩展,用专属页面呈现它的运行结果",
|
|
237
|
-
promptLabel: "Ta 要做的事",
|
|
238
|
-
showAll: "展开全文",
|
|
239
|
-
showLess: "收起",
|
|
240
|
-
stats: "已运行 {runs} 次",
|
|
241
|
-
statsFailed: "已运行 {runs} 次 · 失败 {fails} 次",
|
|
242
|
-
lastRun: "上次 {time}",
|
|
243
|
-
moreOptions: "更多选项",
|
|
244
|
-
shortcut: "{key} + 回车{action}",
|
|
245
|
-
modelFailed: "做扩展的模型({model})现在用不了,已改用默认模型:{message}",
|
|
246
|
-
fromChat: "做成定时任务",
|
|
247
|
-
fromChatDetail: "定期再做一遍这次的事",
|
|
248
|
-
fromChatWhen: "多久运行一次",
|
|
249
|
-
fromChatOther: "其他时间",
|
|
250
|
-
fromChatOtherDetail: "让 Ta 问我",
|
|
251
|
-
fromChatAsk: "把这次对话做的事做成定时任务,{when} 运行",
|
|
252
|
-
fromChatAskWhen: "把这次对话做的事做成定时任务,先问我多久运行一次",
|
|
253
|
-
toolAdd: "新建定时任务",
|
|
254
|
-
toolUpdate: "修改定时任务",
|
|
255
|
-
toolList: "查看定时任务",
|
|
256
|
-
toolShow: "查看定时任务",
|
|
257
|
-
toolEnable: "开启定时任务",
|
|
258
|
-
toolDisable: "暂停定时任务",
|
|
259
|
-
toolDelete: "删除定时任务",
|
|
260
|
-
toolRun: "立即运行定时任务",
|
|
261
|
-
toolRuns: "查看运行记录",
|
|
262
|
-
toolClear: "清空定时任务",
|
|
263
|
-
toolOther: "定时任务"
|
|
264
|
-
};
|
|
265
|
-
var CronWords;
|
|
266
|
-
((CronWords) => {
|
|
267
|
-
function of(language) {
|
|
268
|
-
return language === "zh-CN" ? ZH : EN;
|
|
269
|
-
}
|
|
270
|
-
CronWords.of = of;
|
|
271
|
-
function format(text, values) {
|
|
272
|
-
return text.replace(/\{(\w+)\}/g, (whole, key) => (key in values) ? String(values[key]) : whole);
|
|
273
|
-
}
|
|
274
|
-
CronWords.format = format;
|
|
275
|
-
})(CronWords ||= {});
|
|
276
|
-
|
|
277
121
|
// web-src/cron-expression.ts
|
|
278
122
|
var FIELDS = [
|
|
279
123
|
{ name: "minute", min: 0, max: 59 },
|
|
@@ -988,37 +832,41 @@ var CronTool;
|
|
|
988
832
|
|
|
989
833
|
// web-src/chat-task.ts
|
|
990
834
|
var TASK_BLOCK = "ta-cron-task";
|
|
991
|
-
var
|
|
835
|
+
var KEEP_SECTION = "ta-cron-keep";
|
|
836
|
+
var KEEP_TURNS = 3;
|
|
992
837
|
var ChatTask;
|
|
993
838
|
((ChatTask) => {
|
|
994
|
-
function
|
|
995
|
-
const words = CronWords.of(language);
|
|
996
|
-
const ask = schedule2 ? CronWords.format(words.fromChatAsk, { when: ScheduleUtil.describe(schedule2, language) }) : words.fromChatAskWhen;
|
|
997
|
-
return `<context>
|
|
998
|
-
${context(schedule2)}
|
|
999
|
-
</context>
|
|
1000
|
-
${ask}`;
|
|
1001
|
-
}
|
|
1002
|
-
ChatTask.message = message;
|
|
1003
|
-
function context(schedule2) {
|
|
839
|
+
function section() {
|
|
1004
840
|
const fence = "```";
|
|
1005
841
|
return [
|
|
1006
|
-
|
|
1007
|
-
|
|
842
|
+
`The user asked to keep how a conversation got its work done (their message whose context starts with ${TA_KEEP_MARK}). One form it can take is a scheduled task of Ta that does it again and again: when it should be done on a schedule with nobody asking (a check, a report, an upgrade); not what needs the user's eye, a device in their hand or a decision of theirs.`,
|
|
843
|
+
"- Unless the conversation says how often, ask, with two or three choices that suit the work, and write the task once you know.",
|
|
1008
844
|
"- Each run is a new conversation in this directory with nobody watching, and it does not see this one: write a prompt complete in itself, with the goal, the repository, branch, files, commands, links and other specifics found here, the steps that worked, and what its last answer should report (short: what it found, what changed since the run before, what needs the user).",
|
|
1009
845
|
'- Leave out what was only tried and dropped, and what holds only this once: say "since the last run" or "yesterday" rather than a date.',
|
|
1010
846
|
`- Say in a line or two what the task does, then end your answer with it in a fenced block of the language ${TASK_BLOCK}, which Ta reads to create the task: do not create it with ${CronTool.NAME} or a command. A longer fence when the prompt has one of its own:`,
|
|
1011
847
|
`${fence}${TASK_BLOCK}`,
|
|
1012
848
|
"name: <short, for the list>",
|
|
1013
|
-
|
|
849
|
+
"when: <30m, 2h, @daily, or five fields of cron, as 0 9 * * 1-5>",
|
|
1014
850
|
"---",
|
|
1015
851
|
"<the prompt>",
|
|
1016
|
-
fence
|
|
1017
|
-
"- When the conversation holds nothing worth doing again, say so, ask what the task should do, and leave the block out until you know."
|
|
852
|
+
fence
|
|
1018
853
|
].join(`
|
|
1019
854
|
`);
|
|
1020
855
|
}
|
|
1021
|
-
ChatTask.
|
|
856
|
+
ChatTask.section = section;
|
|
857
|
+
function keeping(prompt, entries) {
|
|
858
|
+
if (prompt?.includes(TA_KEEP_MARK)) {
|
|
859
|
+
return true;
|
|
860
|
+
}
|
|
861
|
+
let turns = 0;
|
|
862
|
+
return back(entries, (said) => {
|
|
863
|
+
if (said.includes(TA_KEEP_MARK)) {
|
|
864
|
+
return true;
|
|
865
|
+
}
|
|
866
|
+
return ++turns >= KEEP_TURNS ? false : undefined;
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
ChatTask.keeping = keeping;
|
|
1022
870
|
function find(text2) {
|
|
1023
871
|
const lines = text2.split(/\r?\n/);
|
|
1024
872
|
let found;
|
|
@@ -1057,23 +905,26 @@ ${ask}`;
|
|
|
1057
905
|
}
|
|
1058
906
|
ChatTask.schedule = schedule;
|
|
1059
907
|
function pending(entries) {
|
|
908
|
+
return back(entries, (said) => said.includes(TA_KEEP_MARK) ? true : undefined);
|
|
909
|
+
}
|
|
910
|
+
ChatTask.pending = pending;
|
|
911
|
+
function back(entries, test) {
|
|
1060
912
|
for (let index = entries.length - 1;index >= 0; index--) {
|
|
1061
913
|
const entry = entries[index];
|
|
1062
914
|
const custom = entry.type === "custom_message" ? entry : entry.message?.role === "custom" ? entry.message : undefined;
|
|
1063
915
|
if (custom?.customType === REPLY_TYPE && created(custom.details)) {
|
|
1064
|
-
return;
|
|
916
|
+
return false;
|
|
1065
917
|
}
|
|
1066
918
|
if (entry.type !== "message" || entry.message?.role !== "user") {
|
|
1067
919
|
continue;
|
|
1068
920
|
}
|
|
1069
|
-
const
|
|
1070
|
-
if (
|
|
1071
|
-
return
|
|
921
|
+
const answer = test(text(entry.message.content));
|
|
922
|
+
if (answer !== undefined) {
|
|
923
|
+
return answer;
|
|
1072
924
|
}
|
|
1073
925
|
}
|
|
1074
|
-
return;
|
|
926
|
+
return false;
|
|
1075
927
|
}
|
|
1076
|
-
ChatTask.pending = pending;
|
|
1077
928
|
function text(content) {
|
|
1078
929
|
if (typeof content === "string") {
|
|
1079
930
|
return content;
|
|
@@ -1099,7 +950,7 @@ function activate(pi) {
|
|
|
1099
950
|
host: answer?.host,
|
|
1100
951
|
scheduler: answer?.service
|
|
1101
952
|
}));
|
|
1102
|
-
const isRun = (ctx) => ctx.getSystemPrompt()
|
|
953
|
+
const isRun = (ctx) => TaHostUtil.marked(ctx.getSystemPrompt(), RUN_MARK);
|
|
1103
954
|
const scheduler = async (ctx) => {
|
|
1104
955
|
if (isRun(ctx)) {
|
|
1105
956
|
throw new Error(NOT_IN_RUN);
|
|
@@ -1115,9 +966,13 @@ function activate(pi) {
|
|
|
1115
966
|
pi.on("session_start", () => {
|
|
1116
967
|
reach();
|
|
1117
968
|
});
|
|
1118
|
-
pi.on("before_agent_start", (
|
|
969
|
+
pi.on("before_agent_start", (event, ctx) => {
|
|
1119
970
|
if (isRun(ctx)) {
|
|
1120
971
|
pi.setActiveTools(pi.getActiveTools().filter((name) => name !== CronTool.NAME));
|
|
972
|
+
return;
|
|
973
|
+
}
|
|
974
|
+
if (event.systemPromptOptions && ChatTask.keeping(event.prompt, ctx.sessionManager.getBranch())) {
|
|
975
|
+
event.systemPromptOptions.sections = { ...event.systemPromptOptions.sections, [KEEP_SECTION]: ChatTask.section() };
|
|
1121
976
|
}
|
|
1122
977
|
});
|
|
1123
978
|
pi.on("context", (event) => {
|
|
@@ -1157,12 +1012,12 @@ function activate(pi) {
|
|
|
1157
1012
|
}
|
|
1158
1013
|
try {
|
|
1159
1014
|
const draft = [...event.messages].reverse().filter((message) => message.role === "assistant").map((message) => ChatTask.find(ChatTask.text(message.content))).find((found) => found !== undefined);
|
|
1160
|
-
|
|
1161
|
-
const schedule = draft?.schedule ?? ask?.schedule;
|
|
1162
|
-
if (!draft || !ask || !schedule) {
|
|
1015
|
+
if (!draft?.schedule || !ChatTask.pending(ctx.sessionManager.getBranch())) {
|
|
1163
1016
|
return;
|
|
1164
1017
|
}
|
|
1165
|
-
reply(await create({ name: draft.name || undefined, prompt: draft.prompt, schedule }, await scheduler(ctx)), {
|
|
1018
|
+
reply(await create({ name: draft.name || undefined, prompt: draft.prompt, schedule: draft.schedule }, await scheduler(ctx)), {
|
|
1019
|
+
triggerTurn: false
|
|
1020
|
+
});
|
|
1166
1021
|
} catch (error) {
|
|
1167
1022
|
reply({ kind: "error", message: error instanceof Error ? error.message : String(error) }, { triggerTurn: false });
|
|
1168
1023
|
}
|
package/host/index.mjs
CHANGED
|
@@ -582,6 +582,15 @@ var TaskUtil;
|
|
|
582
582
|
return line.replace(/^\s*(?:#{1,6}\s+|[-*+]\s+|>\s*|\d+[.)]\s+)/, "").replace(/\*\*|__|`/g, "").replace(/\[([^\]]*)\]\([^)]*\)/g, "$1").trim();
|
|
583
583
|
}
|
|
584
584
|
TaskUtil.firstLine = firstLine;
|
|
585
|
+
function split(tasks, stay = new Set) {
|
|
586
|
+
const listed = [];
|
|
587
|
+
const off = [];
|
|
588
|
+
for (const task of tasks) {
|
|
589
|
+
(task.enabled || task.lastStatus === "running" || stay.has(task.id) ? listed : off).push(task);
|
|
590
|
+
}
|
|
591
|
+
return [listed, off];
|
|
592
|
+
}
|
|
593
|
+
TaskUtil.split = split;
|
|
585
594
|
function missed(task, now) {
|
|
586
595
|
return task.schedule.kind === "once" && !!task.nextRunAt && now.getTime() - new Date(task.nextRunAt).getTime() > Limits.GRACE_MS;
|
|
587
596
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/ta-cron",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.13.1",
|
|
4
4
|
"description": "A pi package for Ta: prompts that run on a schedule, once, every so often or by a cron expression, each run in a conversation of its own in the Ta service",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package"
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"watch": "tsc -b -w --preserveWatchOutput"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@celljs/ta-protocol": "4.
|
|
31
|
-
"@celljs/ta-web": "4.
|
|
30
|
+
"@celljs/ta-protocol": "4.13.1",
|
|
31
|
+
"@celljs/ta-web": "4.13.1",
|
|
32
32
|
"@types/react": "^19.3.0"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
|
@@ -61,6 +61,14 @@
|
|
|
61
61
|
"host": "./host/index.mjs",
|
|
62
62
|
"extensions": [
|
|
63
63
|
"./extension/index.mjs"
|
|
64
|
-
]
|
|
64
|
+
],
|
|
65
|
+
"permissions": {
|
|
66
|
+
"host": {
|
|
67
|
+
"list": "cron.view",
|
|
68
|
+
"get": "cron.view",
|
|
69
|
+
"runs": "cron.view",
|
|
70
|
+
"*": "cron.manage"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
65
73
|
}
|
|
66
74
|
}
|