@oyasmi/pipiclaw 0.8.8 → 0.8.9-beta.2

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.
Files changed (110) hide show
  1. package/README.md +8 -3
  2. package/dist/agent/channel-runner.d.ts +1 -0
  3. package/dist/agent/channel-runner.js +3 -2
  4. package/dist/agent/effect-ledger.d.ts +11 -0
  5. package/dist/agent/effect-ledger.js +42 -0
  6. package/dist/agent/job-manager.d.ts +90 -13
  7. package/dist/agent/job-manager.js +235 -20
  8. package/dist/agent/prompt/sections.js +11 -2
  9. package/dist/agent/prompt/types.d.ts +7 -1
  10. package/dist/agent/runner-factory.d.ts +7 -0
  11. package/dist/agent/session-events.js +20 -1
  12. package/dist/index.d.ts +1 -1
  13. package/dist/log.d.ts +6 -0
  14. package/dist/log.js +12 -0
  15. package/dist/memory/consolidation.d.ts +5 -0
  16. package/dist/memory/consolidation.js +35 -147
  17. package/dist/memory/extraction.d.ts +45 -0
  18. package/dist/memory/extraction.js +227 -0
  19. package/dist/memory/lifecycle.js +5 -0
  20. package/dist/memory/maintenance-jobs.js +7 -0
  21. package/dist/memory/post-turn-review.d.ts +3 -1
  22. package/dist/memory/post-turn-review.js +20 -189
  23. package/dist/memory/recall.d.ts +0 -1
  24. package/dist/memory/recall.js +135 -77
  25. package/dist/memory/sidecar-worker.d.ts +7 -0
  26. package/dist/memory/sidecar-worker.js +23 -5
  27. package/dist/memory/task-digest.js +1 -1
  28. package/dist/paths.d.ts +1 -0
  29. package/dist/paths.js +11 -0
  30. package/dist/playbooks/background-jobs.md +40 -0
  31. package/dist/playbooks/catalog.d.ts +1 -7
  32. package/dist/playbooks/catalog.js +4 -14
  33. package/dist/playbooks/event-scheduling.md +8 -4
  34. package/dist/playbooks/memory-and-learning.md +1 -1
  35. package/dist/playbooks/outbound-media.md +45 -0
  36. package/dist/playbooks/runtime-orientation.md +1 -1
  37. package/dist/playbooks/task-closeout.md +12 -11
  38. package/dist/playbooks/task-delegation.md +11 -5
  39. package/dist/playbooks/task-driving.md +54 -21
  40. package/dist/playbooks/task-planning.md +46 -19
  41. package/dist/runtime/bootstrap.js +29 -4
  42. package/dist/runtime/channel-context.d.ts +33 -0
  43. package/dist/runtime/dingtalk.d.ts +22 -2
  44. package/dist/runtime/dingtalk.js +141 -0
  45. package/dist/runtime/durable-dispatch.d.ts +10 -0
  46. package/dist/runtime/durable-dispatch.js +42 -1
  47. package/dist/runtime/event-validation.d.ts +48 -0
  48. package/dist/runtime/event-validation.js +81 -0
  49. package/dist/runtime/events.d.ts +17 -8
  50. package/dist/runtime/events.js +96 -22
  51. package/dist/runtime/store.d.ts +1 -1
  52. package/dist/runtime/task-commands.js +29 -51
  53. package/dist/runtime/task-driver.d.ts +5 -8
  54. package/dist/runtime/task-driver.js +120 -93
  55. package/dist/runtime/task-migration.d.ts +11 -0
  56. package/dist/runtime/task-migration.js +70 -0
  57. package/dist/settings.d.ts +11 -0
  58. package/dist/settings.js +12 -0
  59. package/dist/shared/recoverable-error.d.ts +26 -0
  60. package/dist/shared/recoverable-error.js +29 -0
  61. package/dist/shared/task-events.d.ts +0 -26
  62. package/dist/shared/task-events.js +0 -15
  63. package/dist/shared/task-ledger.d.ts +32 -8
  64. package/dist/shared/task-ledger.js +66 -17
  65. package/dist/subagents/builtin/explorer.md +16 -0
  66. package/dist/subagents/builtin/researcher.md +17 -0
  67. package/dist/subagents/builtin/verifier.md +17 -0
  68. package/dist/subagents/discovery.d.ts +17 -3
  69. package/dist/subagents/discovery.js +88 -15
  70. package/dist/subagents/tool.d.ts +21 -1
  71. package/dist/subagents/tool.js +140 -12
  72. package/dist/tasks/control.d.ts +4 -0
  73. package/dist/tasks/control.js +3 -0
  74. package/dist/tasks/store.d.ts +28 -1
  75. package/dist/tasks/store.js +63 -6
  76. package/dist/tasks/transitions.d.ts +40 -0
  77. package/dist/tasks/transitions.js +82 -0
  78. package/dist/tools/bash.d.ts +2 -0
  79. package/dist/tools/bash.js +18 -5
  80. package/dist/tools/event-manage.js +28 -77
  81. package/dist/tools/index.d.ts +4 -0
  82. package/dist/tools/index.js +7 -2
  83. package/dist/tools/job.js +2 -2
  84. package/dist/tools/memory-manage.js +0 -1
  85. package/dist/tools/registry.d.ts +29 -8
  86. package/dist/tools/registry.js +39 -22
  87. package/dist/tools/send-media.d.ts +28 -0
  88. package/dist/tools/send-media.js +88 -0
  89. package/dist/tools/task-manage/create.d.ts +2 -0
  90. package/dist/tools/task-manage/create.js +35 -0
  91. package/dist/tools/task-manage/lifecycle.d.ts +6 -0
  92. package/dist/tools/task-manage/lifecycle.js +197 -0
  93. package/dist/tools/task-manage/schema.d.ts +43 -0
  94. package/dist/tools/task-manage/schema.js +90 -0
  95. package/dist/tools/task-manage/shared.d.ts +36 -0
  96. package/dist/tools/task-manage/shared.js +247 -0
  97. package/dist/tools/task-manage/types.d.ts +53 -0
  98. package/dist/tools/task-manage/types.js +1 -0
  99. package/dist/tools/task-manage/verification.d.ts +16 -0
  100. package/dist/tools/task-manage/verification.js +112 -0
  101. package/dist/tools/task-manage.d.ts +9 -89
  102. package/dist/tools/task-manage.js +8 -696
  103. package/dist/tools/tool-details.d.ts +44 -0
  104. package/dist/tools/tool-details.js +62 -0
  105. package/dist/tui/app.js +2 -0
  106. package/dist/tui/terminal-media-sender.d.ts +9 -0
  107. package/dist/tui/terminal-media-sender.js +15 -0
  108. package/package.json +2 -2
  109. package/dist/playbooks/task-recurring.md +0 -41
  110. package/dist/playbooks/task-repair.md +0 -45
@@ -0,0 +1,44 @@
1
+ import type { AgentTool } from "@earendil-works/pi-agent-core";
2
+ /**
3
+ * The `details` contract for tool results, and the recoverable-rejection mechanism
4
+ * built on it.
5
+ *
6
+ * `details` is the structured, non-model-facing channel of a tool result: the model reads
7
+ * `content`, the runtime reads `details`. Before this contract existed each tool invented its
8
+ * own shape, several emitted no `kind` at all (bash did on the async path but not the sync
9
+ * one), and nothing bound emitters to consumers — so the discriminator drifted freely.
10
+ *
11
+ * The discriminator is therefore no longer written by hand. `withToolDetails` stamps it from
12
+ * the registry's tool name at the point the tool set is built, which makes every result
13
+ * conform by construction: a tool cannot forget it, and it cannot disagree with the name the
14
+ * tool is registered under.
15
+ */
16
+ export { RecoverableToolError } from "../shared/recoverable-error.js";
17
+ /**
18
+ * Every tool that can appear in a tool set. Equal to the registry's tool names plus
19
+ * `subagent`, which is registered separately (see the note on TOOL_REGISTRY).
20
+ */
21
+ export type ToolDetailsKind = "read" | "bash" | "edit" | "grep" | "write" | "web_search" | "web_fetch" | "send_media" | "session_search" | "memory_manage" | "skill_manage" | "event_manage" | "task_manage" | "job" | "subagent";
22
+ /** The fields every tool result's `details` carries. Tool-specific fields extend this. */
23
+ export interface ToolDetails {
24
+ /** Which tool produced this result. Stamped by `withToolDetails`; never written by hand. */
25
+ kind: ToolDetailsKind;
26
+ /**
27
+ * Set when the call was rejected for a reason the model can resolve on its own (see
28
+ * `RecoverableToolError`). Transports use it to keep the retry out of the user's face.
29
+ */
30
+ recoverable?: true;
31
+ }
32
+ /** Read the `details` off a tool result, if it carries a conforming one. */
33
+ export declare function toolResultDetails(result: unknown): ToolDetails | null;
34
+ /** True when the result is a rejection the model can resolve on its own. */
35
+ export declare function isRecoverableRejection(result: unknown): boolean;
36
+ /**
37
+ * Bind a tool to the contract: stamp `kind` on every result it returns, and convert a
38
+ * `RecoverableToolError` into a normal result the model can read and act on.
39
+ *
40
+ * Applied once in `buildToolSet`, so every registered tool is covered without each one
41
+ * having to remember. `kind` is stamped last and unconditionally: the name a tool is
42
+ * registered under is the authoritative discriminator.
43
+ */
44
+ export declare function withToolDetails(tool: AgentTool<any>, kind: ToolDetailsKind): AgentTool<any>;
@@ -0,0 +1,62 @@
1
+ import { RecoverableToolError } from "../shared/recoverable-error.js";
2
+ import { isRecord } from "../shared/type-guards.js";
3
+ /**
4
+ * The `details` contract for tool results, and the recoverable-rejection mechanism
5
+ * built on it.
6
+ *
7
+ * `details` is the structured, non-model-facing channel of a tool result: the model reads
8
+ * `content`, the runtime reads `details`. Before this contract existed each tool invented its
9
+ * own shape, several emitted no `kind` at all (bash did on the async path but not the sync
10
+ * one), and nothing bound emitters to consumers — so the discriminator drifted freely.
11
+ *
12
+ * The discriminator is therefore no longer written by hand. `withToolDetails` stamps it from
13
+ * the registry's tool name at the point the tool set is built, which makes every result
14
+ * conform by construction: a tool cannot forget it, and it cannot disagree with the name the
15
+ * tool is registered under.
16
+ */
17
+ export { RecoverableToolError } from "../shared/recoverable-error.js";
18
+ /** Read the `details` off a tool result, if it carries a conforming one. */
19
+ export function toolResultDetails(result) {
20
+ if (!isRecord(result) || !("details" in result)) {
21
+ return null;
22
+ }
23
+ const details = result.details;
24
+ return isRecord(details) && typeof details.kind === "string" ? details : null;
25
+ }
26
+ /** True when the result is a rejection the model can resolve on its own. */
27
+ export function isRecoverableRejection(result) {
28
+ return toolResultDetails(result)?.recoverable === true;
29
+ }
30
+ /**
31
+ * Bind a tool to the contract: stamp `kind` on every result it returns, and convert a
32
+ * `RecoverableToolError` into a normal result the model can read and act on.
33
+ *
34
+ * Applied once in `buildToolSet`, so every registered tool is covered without each one
35
+ * having to remember. `kind` is stamped last and unconditionally: the name a tool is
36
+ * registered under is the authoritative discriminator.
37
+ */
38
+ export function withToolDetails(tool, kind) {
39
+ return {
40
+ ...tool,
41
+ execute: async (toolCallId, params, signal, onUpdate) => {
42
+ try {
43
+ const result = (await tool.execute(toolCallId, params, signal, onUpdate));
44
+ return {
45
+ ...result,
46
+ details: { ...(isRecord(result.details) ? result.details : {}), kind },
47
+ };
48
+ }
49
+ catch (error) {
50
+ if (error instanceof RecoverableToolError) {
51
+ // Returned, not rethrown: a rejection is an outcome, not a fault. The `Rejected:`
52
+ // prefix keeps the model from reading a non-error result as success.
53
+ return {
54
+ content: [{ type: "text", text: `Rejected: ${error.message}` }],
55
+ details: { kind, recoverable: true },
56
+ };
57
+ }
58
+ throw error;
59
+ }
60
+ },
61
+ };
62
+ }
package/dist/tui/app.js CHANGED
@@ -23,6 +23,7 @@ import { getUsageLedger } from "../usage/ledger.js";
23
23
  import { parseUsageMode, renderUsageReport } from "../usage/render.js";
24
24
  import { TUI_SLASH_COMMANDS } from "./commands.js";
25
25
  import { createFrontend } from "./renderer.js";
26
+ import { createTerminalMediaSender } from "./terminal-media-sender.js";
26
27
  import { TurnController } from "./turn-controller.js";
27
28
  const DEFAULT_CHANNEL_ID = "tui_local";
28
29
  const CHANNEL_ID_PATTERN = /^[A-Za-z0-9._-]+$/;
@@ -79,6 +80,7 @@ export async function runTuiApp(options) {
79
80
  appHomeDir: paths.appHomeDir,
80
81
  authConfigPath: paths.authConfigPath,
81
82
  modelsConfigPath: paths.modelsConfigPath,
83
+ mediaSender: createTerminalMediaSender(io),
82
84
  });
83
85
  const tuiSettings = settingsManager.getTuiSettings();
84
86
  const traits = {
@@ -0,0 +1,9 @@
1
+ import type { BootstrapIO } from "../runtime/bootstrap.js";
2
+ import type { MediaSender } from "../runtime/channel-context.js";
3
+ /**
4
+ * Terminal implementation of the `MediaSender` port. There is no chat surface to
5
+ * push a file to, and the bytes already came from a local file, so "sending" here
6
+ * just surfaces a notice — keeping the `send_media` tool available and behaving
7
+ * symmetrically across transports rather than being silently absent in the TUI.
8
+ */
9
+ export declare function createTerminalMediaSender(io: BootstrapIO): MediaSender;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Terminal implementation of the `MediaSender` port. There is no chat surface to
3
+ * push a file to, and the bytes already came from a local file, so "sending" here
4
+ * just surfaces a notice — keeping the `send_media` tool available and behaving
5
+ * symmetrically across transports rather than being silently absent in the TUI.
6
+ */
7
+ export function createTerminalMediaSender(io) {
8
+ return {
9
+ async sendMedia(_channelId, media) {
10
+ const sizeKb = (media.data.length / 1024).toFixed(1);
11
+ io.log(`📎 [send_media] ${media.kind}: ${media.fileName} (${sizeKb}KB)`);
12
+ return { ok: true };
13
+ },
14
+ };
15
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oyasmi/pipiclaw",
3
- "version": "0.8.8",
3
+ "version": "0.8.9-beta.2",
4
4
  "description": "An AI assistant runtime for coding and team workflows, with DingTalk AI Cards, sub-agents, memory, and scheduled events.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -22,7 +22,7 @@
22
22
  ],
23
23
  "scripts": {
24
24
  "clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true }); require('node:fs').rmSync('coverage', { recursive: true, force: true });\"",
25
- "build": "tsc -p tsconfig.build.json && node -e \"const fs = require('node:fs'); const src = 'src/playbooks', dst = 'dist/playbooks'; fs.mkdirSync(dst, { recursive: true }); for (const f of fs.readdirSync(src)) if (f.endsWith('.md')) fs.copyFileSync(src + '/' + f, dst + '/' + f); fs.chmodSync('dist/main.js', 0o755)\"",
25
+ "build": "tsc -p tsconfig.build.json && node scripts/copy-md-assets.mjs && node -e \"require('node:fs').chmodSync('dist/main.js', 0o755)\"",
26
26
  "dev": "tsc -p tsconfig.build.json --watch --preserveWatchOutput",
27
27
  "lint": "biome check .",
28
28
  "typecheck": "tsc --noEmit -p tsconfig.json",
@@ -1,41 +0,0 @@
1
- ---
2
- name: task-recurring
3
- description: Before creating, rescheduling, pausing, or retiring a recurring task.
4
- requires-tools: task_manage
5
- priority: 43
6
- ---
7
-
8
- # 周期性任务
9
-
10
- 一个周期任务就是**一个文件**:`tasks/<id>.md`。节奏在 frontmatter 的 `schedule`(五段 cron,按主机时区解释),做法与跨周期经验在正文。没有配套事件,也没有 `.schedule` 命名约定。
11
-
12
- `recurrence` 只是给人看的可选标注(如 `每周一`),没有机器语义。周期性 = `schedule` 是否存在。
13
-
14
- ## 创建
15
-
16
- 按 `task-planning.md` 创建 task,并给 `schedule`:
17
-
18
- ```
19
- task_manage create id=weekly-report title=... goal=... dod=... schedule="30 9 * * 1"
20
- ```
21
-
22
- cron 最密每 30 分钟一次,落盘前校验。纯提醒(无产出、无验收)不建 task,用普通 periodic event。
23
-
24
- ## 周期运行
25
-
26
- done 的周期任务留在原地睡眠:`task_manage done` 会用 croner 算出下一次 occurrence 写入 `wake`,状态是 `done` + 未来的 `wake`。到点时 driver 自动派发一条 cycle-start 唤醒。
27
-
28
- - 收到 cycle-start:调用 `task_manage start-cycle`,给稳定 cycleId。它原子折叠上一周期日志、清空本周期用量/验收/授权/worktree 元数据并置 in-progress。
29
- - 上周期未完成:不要覆盖或虚勾 DoD。先完成、如实缩小本轮范围并验收,或与用户确认后 cancel 整项任务。
30
-
31
- 周期内继续、等待和恢复只用 task `wake`。
32
-
33
- ## 复盘、调整和退役
34
-
35
- 每轮闭环前把返工原因、预检步骤和格式偏好写回 Manual;跨任务才沉淀 workspace skill。
36
-
37
- - 改节奏:`task_manage set schedule="<新 cron>"`;若任务当前 done,同一次写入会重算 `wake`。一处真相。
38
- - 暂停:`/tasks pause <id>`;`/tasks resume` 恢复。
39
- - 退役:`task_manage cancel`,归档任务并清理全部 task-owned events。
40
-
41
- 不要手工改 status 开周期。
@@ -1,45 +0,0 @@
1
- ---
2
- name: task-repair
3
- description: When a task is escalated, stalled, not waking, or has broken control metadata.
4
- requires-tools: task_manage
5
- priority: 44
6
- ---
7
-
8
- # 任务诊断与修复
9
-
10
- 先用 `task_manage list` 看结构化状态;让用户用 `/tasks doctor` 看带 Next step 的一致性检查,用 `/tasks stats <id>` 看 attempts/token/cost/wall time、最近结果和 verifier 状态。
11
-
12
- ## escalated
13
-
14
- driver 在 deadline、累计预算耗尽或 terminal dependency 时停止任务。先读 Current Cycle 和 stats,判断空转、范围错误、预算过小还是依赖终止。
15
-
16
- - 方向错:修 Manual/nextAction、重新拆解或 cancel。
17
- - 预算确实不足:向用户说明后用 `task_manage set` 调整 budget/deadline,并把 status 设回 in-progress。
18
- - 依赖终止:恢复/重建依赖,或 set 更新 dependsOn。
19
-
20
- escalated 不能 progress/candidate;set 是审查原因后的修复入口,不要反射性加预算。
21
-
22
- ## 不唤醒或频繁唤醒
23
-
24
- 可推进 = 非 done/cancelled/escalated/paused,且 wake 缺失、无效或已到期。
25
-
26
- - paused:用户 `/tasks resume <id>`。
27
- - wake 太远:纠正 wake;急催用 `/tasks run <id>`。
28
- - TUI 已关闭:没有 daemon,不能自动唤醒。
29
- - 反复空转:查最新 note/nextAction,修 Manual;不要伪造 progress 换短 cooldown。
30
-
31
- ## 坏 frontmatter/control
32
-
33
- frontmatter 只认开头 `---` 块中的 status/wake/recurrence/control;control 必须是单行 JSON。driver 对不可读 frontmatter fail-open 以便唤醒修复,task_manage 对坏 control fail-closed 防止覆盖。
34
-
35
- 先 read,只有此场景才用 edit 修合法 frontmatter;随后用 task_manage set 让后续更新回到工具轨道。control 不确定时删除坏行,再用 set 重建默认结构。
36
-
37
- ## stale gate
38
-
39
- PASS 和 external approval 都绑定 task body;PASS 还可能绑定 Git artifact subject。progress、正文编辑或产物变化后 done 会拒绝:重跑 verifier或请用户重新 approve,不绕过。组合流程见 `task-closeout.md`。
40
-
41
- ## 事件与重启
42
-
43
- done/cancel 会清理 `task.<channelId>.<id>.*`;孤儿事件用 event_manage 删除。周期任务的节奏在 frontmatter 的 `schedule`;旧 `.checkin` / `.schedule` 是 legacy,把 cron 折进 frontmatter 后删除事件,以 wake 为单一恢复条件(`/tasks doctor` 会给出迁移提示)。
44
-
45
- task 文件是恢复真相。daemon 重启会清空内存 cooldown,可推进任务可能很快重放;durable dispatch 租约也提供至少一次派发。每次先核对已完成产物,避免重复外部动作。