@celljs/ta-cron 4.13.0 → 4.14.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/README.en.md CHANGED
@@ -33,7 +33,7 @@ Times are local to the machine of the Ta service. A command may end with `--name
33
33
  ## How it runs
34
34
 
35
35
  - Three parts, none of which changes Ta's core:
36
- - **Server side** (`pi.host`, `web-src/host.ts`): the scheduler. It runs in the Ta service with one timer, asleep until the next task is due (it looks again within a minute at the latest, to follow a changed clock or a machine that slept). Tasks and runs are kept in the data of the package (`extension-data/@celljs/ta-cron.json` of the agent directory), the last 20 runs of each task.
36
+ - **Server side** (`pi.host`, `web-src/host.ts`): the scheduler. It runs in the Ta service with one timer, asleep until the next task is due (it looks again within a minute at the latest, to follow a changed clock or a machine that slept). Tasks and runs are kept in the data of the package (`extension-data/@celljs/ta-cron.json` of the agent directory), the last 20 runs of each task. Other packages read the tasks and runs with `callPackageHost('@celljs/ta-cron', …)`: `list()`, `runs(id, limit?)` (newest first), not by the data of this package (the brief of ta-recall does so).
37
37
  - **pi extension** (`pi.extensions`, `web-src/extension.ts`): `/loop`, `/remind`, `/schedule` and the tool `schedule_task`. A command answers with a card in the conversation, which the model does not read.
38
38
  - **Web extension** (`pi.web`, `web-src/index.tsx`): the Scheduled page, the cards of the commands, a notice when a run ends, and the Next up card of the board (a swipe to the right over the first tab of a phone, a button of the rail elsewhere): the three tasks running or due first.
39
39
  - **One run, one conversation**: each run opens a new session (in the `ta-cron` group) in the task's directory (by default that of the conversation that made it; an `ssh://` directory works too), with the task's model and thinking level if it has them. The system prompt it adds tells Ta that nobody watches, not to ask anything, and to end with a summary; the last answer is the summary of the run. Once the run ends its session closes (after whoever is looking at it leaves), and its file stays.
package/README.md CHANGED
@@ -33,7 +33,7 @@ Ta 自带的 pi 包(默认开启,可在 Web 客户端的 设置 → 扩展
33
33
  ## 怎么运行
34
34
 
35
35
  - 由三部分组成,都不改 Ta 的核心:
36
- - **服务端**(`pi.host`,`web-src/host.ts`):调度器。Ta 服务启动时运行,只有一个计时器,睡到最近一个任务的时间(最长一分钟后再看一次,以便跟上系统时间的变化和休眠)。任务和运行记录存在包数据里(agent 目录的 `extension-data/@celljs/ta-cron.json`),每个任务保留最近 20 次运行。
36
+ - **服务端**(`pi.host`,`web-src/host.ts`):调度器。Ta 服务启动时运行,只有一个计时器,睡到最近一个任务的时间(最长一分钟后再看一次,以便跟上系统时间的变化和休眠)。任务和运行记录存在包数据里(agent 目录的 `extension-data/@celljs/ta-cron.json`),每个任务保留最近 20 次运行。别的包经 `callPackageHost('@celljs/ta-cron', …)` 读任务和运行:`list()`、`runs(id, limit?)`(新的在前),不读本包的数据(ta-recall 的简报就这样读)。
37
37
  - **pi 扩展**(`pi.extensions`,`web-src/extension.ts`):`/loop`、`/remind`、`/schedule` 和工具 `schedule_task`。命令的回答是对话里的一张卡片,不进入模型的上下文。
38
38
  - **Web 扩展**(`pi.web`,`web-src/index.tsx`):"定时任务"页、命令回答的卡片、运行结束时的通知,以及小组件面板(首页往右划,电脑上是导轨的按钮)里的"接下来"卡片:正在运行和最近要运行的三个任务。
39
39
  - **一次运行,一个对话**:每次运行打开一个新会话(归在 `ta-cron` 分组下),工作目录是任务的目录(默认是创建它的对话的目录,可以是 `ssh://` 远程目录),可单独指定模型和思考级别。追加的系统提示告诉 Ta 没人在看、不要提问、最后写一段总结;最后一条回答就是这次运行的总结。运行结束后会话关闭(有人正在看时等看完再关),对话文件保留。
@@ -27,6 +27,27 @@ var TaHostUtil;
27
27
  });
28
28
  }
29
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;
30
51
  })(TaHostUtil || (TaHostUtil = {}));
31
52
  var TA_KEEP_MARK = "[ta:keep]";
32
53
  var TA_ASK_ENTRY = "ta-ask";
@@ -929,7 +950,7 @@ function activate(pi) {
929
950
  host: answer?.host,
930
951
  scheduler: answer?.service
931
952
  }));
932
- const isRun = (ctx) => ctx.getSystemPrompt().includes(RUN_MARK);
953
+ const isRun = (ctx) => TaHostUtil.marked(ctx.getSystemPrompt(), RUN_MARK);
933
954
  const scheduler = async (ctx) => {
934
955
  if (isRun(ctx)) {
935
956
  throw new Error(NOT_IN_RUN);
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@celljs/ta-cron",
3
- "version": "4.13.0",
3
+ "version": "4.14.0",
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"
7
7
  ],
8
- "homepage": "https://github.com/cellbang/cell",
8
+ "homepage": "https://github.com/cellbang/ta",
9
9
  "bugs": {
10
- "url": "https://github.com/cellbang/cell/issues"
10
+ "url": "https://github.com/cellbang/ta/issues"
11
11
  },
12
12
  "repository": {
13
13
  "type": "git",
@@ -27,8 +27,8 @@
27
27
  "watch": "tsc -b -w --preserveWatchOutput"
28
28
  },
29
29
  "devDependencies": {
30
- "@celljs/ta-protocol": "4.13.0",
31
- "@celljs/ta-web": "4.13.0",
30
+ "@celljs/ta-protocol": "4.14.0",
31
+ "@celljs/ta-web": "4.14.0",
32
32
  "@types/react": "^19.3.0"
33
33
  },
34
34
  "publishConfig": {
package/web/index.js CHANGED
@@ -711,16 +711,21 @@ class CronClient {
711
711
  start() {
712
712
  this.stop = this.api.storage.onChange((keys) => {
713
713
  if (keys.includes(Keys.TASKS)) {
714
- this.load();
714
+ this.quietly(this.load());
715
715
  }
716
716
  for (const key of keys) {
717
717
  const id = key.startsWith("runs/") ? key.slice(5) : undefined;
718
718
  if (id && this.state.runs[id]) {
719
- this.loadRuns(id);
719
+ this.quietly(this.loadRuns(id));
720
720
  }
721
721
  }
722
722
  });
723
- this.load();
723
+ this.quietly(this.load());
724
+ }
725
+ quietly(reading) {
726
+ reading.catch(() => {
727
+ return;
728
+ });
724
729
  }
725
730
  dispose() {
726
731
  this.stop?.();
@@ -754,7 +759,7 @@ class CronClient {
754
759
  this.reading = undefined;
755
760
  if (this.again) {
756
761
  this.again = false;
757
- this.load();
762
+ this.quietly(this.load());
758
763
  }
759
764
  }
760
765
  }