@zhushanwen/pi-scheduler 0.10.2 → 0.10.4

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.md CHANGED
@@ -28,6 +28,16 @@ npm install @zhushanwen/pi-scheduler
28
28
 
29
29
  安装后扩展在 pi 会话启动时自动装配(见下节),无需额外配置。
30
30
 
31
+ ## 工具激活(deferred)
32
+
33
+ `schedule` / `schedule_control` 工具注册为 `exposure: "deferred"`——不占常驻工具声明,由 pi 内置 `tool_search` 工具检索命中后按需激活。taiji 宿主内开箱即用(宿主启动时已激活 `tool_search`);独立 pi 使用需在 `<agentDir>/settings.json`(默认 `~/.pi/agent/settings.json`)开启:
34
+
35
+ ```json
36
+ { "defaultTools": ["+tool_search"] }
37
+ ```
38
+
39
+ `+` 前缀是增量修饰(保留 read/bash/edit/write 默认集)。未开启 `tool_search` 时这两个工具对模型不可见。
40
+
31
41
  ## 激活方式
32
42
 
33
43
  扩展 factory(`src/index.ts`)监听 pi 的 session 生命周期事件,在 `session_start` 时装配完整调用链:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhushanwen/pi-scheduler",
3
- "version": "0.10.2",
3
+ "version": "0.10.4",
4
4
  "type": "module",
5
5
  "main": "index.ts",
6
6
  "taiji": {
@@ -51,10 +51,10 @@
51
51
  },
52
52
  "dependencies": {
53
53
  "croner": "^9.0.0",
54
- "@zhushanwen/extension-protocol": "0.20.0",
54
+ "@zhushanwen/extension-protocol": "0.21.0",
55
+ "@zhushanwen/pi-ext-guards": "0.5.0",
55
56
  "@zhushanwen/pi-extension-logger": "0.6.2",
56
- "@zhushanwen/pi-ext-guards": "0.4.4",
57
- "@zhushanwen/pi-llm-shared": "0.11.2",
57
+ "@zhushanwen/pi-llm-shared": "0.11.3",
58
58
  "@zhushanwen/pi-session-path": "0.1.0"
59
59
  },
60
60
  "scripts": {
package/src/index.ts CHANGED
@@ -256,13 +256,14 @@ export default function schedulerExtension(pi: ExtensionAPI): void {
256
256
  pi.registerTool({
257
257
  name: 'schedule',
258
258
  label: 'Schedule',
259
+ // deferred(tool-declaration-slimming D4):不常驻声明,tool_search 命中即激活;
260
+ // 迁移写入的 +tool_search 条目(runtime pi-codemode-settings)承载检索入口
261
+ exposure: 'deferred',
259
262
  description:
260
263
  'Create a scheduled task that fires a message at intervals or cron schedule. ' +
261
- 'The task is created immediately (no confirmation form). Call it only when the user ' +
262
- 'has already expressed the timing; if the timing or the reminder content is missing ' +
263
- 'or ambiguous, clarify with the user first — never guess a schedule. The task only ' +
264
- 'fires while this session stays open. The response includes the task id and next run ' +
265
- 'time(s); repeat them back to the user so the task is easy to verify or undo.',
264
+ 'The task is created immediately (no confirmation form). It is a session-scoped reminder, ' +
265
+ 'not a system cron job — it only fires while this session stays open. ' +
266
+ 'The response includes the task id and next run time(s).',
266
267
  parameters: ScheduleParams,
267
268
  promptGuidelines: scheduleGuidelines,
268
269
  async execute(
@@ -284,6 +285,8 @@ export default function schedulerExtension(pi: ExtensionAPI): void {
284
285
  pi.registerTool({
285
286
  name: 'schedule_control',
286
287
  label: 'Schedule Control',
288
+ // deferred(tool-declaration-slimming D4):同 schedule
289
+ exposure: 'deferred',
287
290
  description: 'Manage scheduled tasks: list, toggle, delete, or run immediately.',
288
291
  parameters: ScheduleControlParams,
289
292
  promptGuidelines: controlGuidelines,
package/src/tool.ts CHANGED
@@ -16,16 +16,12 @@ export const ScheduleParams = Type.Object({
16
16
 
17
17
  export type ScheduleParamsT = Static<typeof ScheduleParams>
18
18
 
19
+ // D1 单源化:guidelines 只承载使用纪律(何时调用 / 结果复述 / 撤销方式);
20
+ // 参数格式与默认值(duration/cron、kind、expires、model 语义)单源在 ScheduleParams
21
+ // 字段说明,此处不再复述;「会话内存活」等行为边界在工具 description。
19
22
  export const scheduleGuidelines = [
20
- 'This tool creates the scheduled task immediately. It does NOT open a confirmation form and does NOT ask the user to confirm in chat — the created task is active as soon as the call returns.',
21
- 'Only call this tool when the user asks to create a scheduled task AND the timing is already expressed (a duration like 5m/2h/1d, an explicit wall-clock time, or a cron expression).',
22
- 'If the timing or the reminder content is missing or ambiguous, first clarify it with the user (the ask-user tool or a question in chat) — never guess a schedule and never create the task silently.',
23
- 'The task only fires while this session stays open (it is a session-scoped reminder, not a system cron job); mention that when it matters.',
24
- 'Schedule accepts duration (5m, 2h, 1d) for interval-based or cron expression for time-based.',
25
- 'Default kind is recurring. Set kind="once" for one-time reminders.',
26
- 'model accepts a scoped model id (provider/model) the task runs with; omit it to follow the session\'s current model.',
27
- 'After creation, the response includes the task id and next run time(s). Repeat the schedule, the next run time, and the task id back to the user so they can verify or undo it.',
28
- 'Default expiry is 7 days. Use expires="never" for long-term tasks.',
23
+ 'Only call this tool when the user asks to create a scheduled task AND the timing is already expressed (a duration, an explicit wall-clock time, or a cron expression); if the timing or the reminder content is missing or ambiguous, clarify with the user first (ask-user tool or chat) — never guess a schedule and never create the task silently.',
24
+ 'After creation, repeat the schedule, the next run time(s), and the task id back to the user so they can verify or undo it.',
29
25
  'To undo a task, use schedule_control delete (or toggle it off) — do not create a duplicate instead.',
30
26
  ]
31
27
 
@@ -93,18 +89,21 @@ export async function handleSchedule(
93
89
  // ── schedule_control tool ──
94
90
 
95
91
  export const ScheduleControlParams = Type.Object({
96
- action: Type.Union([Type.Literal('list'), Type.Literal('toggle'), Type.Literal('delete'), Type.Literal('run')], { description: 'Action to perform.' }),
92
+ action: Type.Union([Type.Literal('list'), Type.Literal('toggle'), Type.Literal('delete'), Type.Literal('run')], {
93
+ description:
94
+ 'Action to perform. run dispatches the task now: the message is sent immediately via steer (interrupting the current turn if the agent is busy).',
95
+ }),
97
96
  id: Type.Optional(Type.String({ description: 'Task id. Required for toggle/delete/run.' })),
98
97
  enabled: Type.Optional(Type.Boolean({ description: 'Target enabled state. Required for toggle.' })),
99
98
  })
100
99
 
101
100
  export type ScheduleControlParamsT = Static<typeof ScheduleControlParams>
102
101
 
102
+ // D1 单源化:action 枚举与 run 的派发语义在 ScheduleControlParams.action 字段说明,
103
+ // guidelines 只留操作纪律(先 list 拿 id、暂停优先 toggle)。
103
104
  export const controlGuidelines = [
104
- 'Use action="list" to see all scheduled tasks.',
105
105
  'After listing, use the returned id for toggle/delete/run.',
106
106
  'Prefer toggle(enabled=false) over delete for temporary pauses.',
107
- 'action="run" dispatches the task now: the message is sent immediately via steer (interrupting the current turn if the agent is busy).',
108
107
  ]
109
108
 
110
109
  export async function handleScheduleControl(service: SchedulerService, params: ScheduleControlParamsT) {