@oyasmi/pipiclaw 0.9.5 → 0.9.6-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 (345) hide show
  1. package/README.en.md +300 -142
  2. package/README.md +295 -140
  3. package/dist/agent/builtin-commands.d.ts +1 -1
  4. package/dist/agent/builtin-commands.js +1 -1
  5. package/dist/agent/channel-runner.d.ts +4 -3
  6. package/dist/agent/channel-runner.js +17 -28
  7. package/dist/agent/maintenance-context.js +2 -2
  8. package/dist/agent/prompt/builder.d.ts +1 -1
  9. package/dist/agent/prompt/builder.js +1 -1
  10. package/dist/agent/prompt/extension.d.ts +1 -1
  11. package/dist/agent/prompt/extension.js +1 -1
  12. package/dist/agent/prompt/manifest.d.ts +6 -1
  13. package/dist/agent/prompt/manifest.js +12 -5
  14. package/dist/agent/prompt/resources.d.ts +0 -3
  15. package/dist/agent/prompt/resources.js +0 -6
  16. package/dist/agent/prompt/sections.d.ts +2 -2
  17. package/dist/agent/prompt/sections.js +36 -26
  18. package/dist/agent/prompt/types.d.ts +3 -2
  19. package/dist/agent/runner-factory.js +1 -1
  20. package/dist/agent/session/command-extension.js +3 -1
  21. package/dist/agent/session/compaction-summary.js +3 -6
  22. package/dist/agent/session/compaction.d.ts +2 -0
  23. package/dist/agent/session/compaction.js +22 -14
  24. package/dist/agent/session/event-guards.d.ts +2 -1
  25. package/dist/agent/session/event-guards.js +6 -0
  26. package/dist/agent/session/model-selection.d.ts +2 -1
  27. package/dist/agent/session/model-selection.js +5 -5
  28. package/dist/agent/session/session-events.js +31 -4
  29. package/dist/agent/session/session-host.d.ts +5 -3
  30. package/dist/agent/session/session-host.js +20 -16
  31. package/dist/agent/status-render.js +3 -0
  32. package/dist/agent/stop-watchdog.js +5 -1
  33. package/dist/agent/turn/task-digest.d.ts +2 -5
  34. package/dist/agent/turn/task-digest.js +25 -45
  35. package/dist/agent/turn/turn-context.js +4 -6
  36. package/dist/agent/turn/turn-error.d.ts +1 -1
  37. package/dist/agent/turn/turn-error.js +9 -0
  38. package/dist/agent/turn/turn-pipeline.d.ts +10 -5
  39. package/dist/agent/turn/turn-pipeline.js +36 -7
  40. package/dist/agent/turn/turn-prompt.d.ts +2 -0
  41. package/dist/agent/turn/turn-prompt.js +2 -1
  42. package/dist/agent/turn/turn-recovery.js +4 -1
  43. package/dist/agent/turn/turn-state.d.ts +2 -0
  44. package/dist/agent/turn/turn-state.js +2 -1
  45. package/dist/agent/types.d.ts +23 -3
  46. package/dist/agent/types.js +2 -0
  47. package/dist/app/auth-command.d.ts +25 -0
  48. package/dist/app/auth-command.js +200 -67
  49. package/dist/app/home.d.ts +7 -8
  50. package/dist/app/home.js +143 -56
  51. package/dist/channel/attachments.d.ts +4 -0
  52. package/dist/channel/attachments.js +4 -0
  53. package/dist/channel/channel-context.d.ts +6 -0
  54. package/dist/channel/config.d.ts +3 -0
  55. package/dist/channel/config.js +11 -5
  56. package/dist/channel/store.d.ts +1 -1
  57. package/dist/commands/catalog.js +42 -10
  58. package/dist/commands/router.js +5 -1
  59. package/dist/desk/commands.d.ts +44 -5
  60. package/dist/desk/commands.js +162 -28
  61. package/dist/desk/paths.d.ts +6 -0
  62. package/dist/desk/paths.js +21 -1
  63. package/dist/desk/registry.d.ts +17 -2
  64. package/dist/desk/registry.js +122 -12
  65. package/dist/desk/types.d.ts +83 -1
  66. package/dist/dingtalk/bot.d.ts +1 -1
  67. package/dist/dingtalk/bot.js +4 -3
  68. package/dist/dingtalk/config.js +10 -10
  69. package/dist/dingtalk/delivery.js +15 -8
  70. package/dist/dingtalk/inbound-media.d.ts +36 -14
  71. package/dist/dingtalk/inbound-media.js +71 -12
  72. package/dist/dingtalk/inbound.d.ts +9 -2
  73. package/dist/dingtalk/inbound.js +17 -2
  74. package/dist/dingtalk/media.d.ts +4 -10
  75. package/dist/dingtalk/media.js +58 -32
  76. package/dist/events/commands.d.ts +2 -0
  77. package/dist/events/commands.js +13 -8
  78. package/dist/events/history.d.ts +9 -0
  79. package/dist/events/history.js +66 -0
  80. package/dist/events/parse.js +7 -3
  81. package/dist/events/types.d.ts +3 -0
  82. package/dist/events/watcher.d.ts +4 -8
  83. package/dist/events/watcher.js +53 -58
  84. package/dist/jobs/kill.d.ts +23 -0
  85. package/dist/jobs/kill.js +65 -0
  86. package/dist/jobs/manager.d.ts +19 -18
  87. package/dist/jobs/manager.js +36 -103
  88. package/dist/main.js +15 -3
  89. package/dist/memory/boundary-work.d.ts +2 -1
  90. package/dist/memory/boundary-work.js +1 -1
  91. package/dist/memory/lifecycle.d.ts +2 -1
  92. package/dist/memory/lifecycle.js +2 -2
  93. package/dist/memory/reflect-job.d.ts +2 -1
  94. package/dist/memory/reflect-job.js +1 -1
  95. package/dist/memory/reflect.d.ts +2 -1
  96. package/dist/memory/reflect.js +25 -4
  97. package/dist/memory/scheduler.d.ts +2 -1
  98. package/dist/memory/scheduler.js +1 -1
  99. package/dist/memory/session-corpus.d.ts +1 -1
  100. package/dist/memory/session-corpus.js +76 -1
  101. package/dist/memory/session-search.d.ts +2 -1
  102. package/dist/memory/session-search.js +14 -12
  103. package/dist/memory/sidecar-worker.d.ts +2 -1
  104. package/dist/memory/sidecar-worker.js +2 -4
  105. package/dist/memory/store.d.ts +2 -0
  106. package/dist/memory/store.js +19 -9
  107. package/dist/models/credential-work.d.ts +7 -0
  108. package/dist/models/credential-work.js +36 -0
  109. package/dist/models/login-ui.js +4 -4
  110. package/dist/models/provider-login.js +7 -6
  111. package/dist/models/requests.d.ts +8 -0
  112. package/dist/models/requests.js +69 -0
  113. package/dist/models/runtime.d.ts +3 -1
  114. package/dist/models/runtime.js +9 -2
  115. package/dist/playbooks/agent-delegation.md +20 -45
  116. package/dist/playbooks/background-jobs.md +1 -1
  117. package/dist/playbooks/catalog.js +1 -1
  118. package/dist/playbooks/delegation-inline.md +25 -0
  119. package/dist/playbooks/delegation-recovery.md +28 -0
  120. package/dist/playbooks/event-scheduling.md +18 -37
  121. package/dist/playbooks/event-sensors.md +26 -0
  122. package/dist/playbooks/event-task-template.md +22 -0
  123. package/dist/playbooks/learning-and-skills.md +26 -0
  124. package/dist/playbooks/memory-operations.md +36 -0
  125. package/dist/playbooks/outbound-media.md +2 -2
  126. package/dist/playbooks/runtime-files.md +29 -0
  127. package/dist/playbooks/runtime-operations.md +25 -0
  128. package/dist/playbooks/runtime-orientation.md +18 -53
  129. package/dist/playbooks/task-lead.md +22 -68
  130. package/dist/playbooks/task-manage.md +38 -0
  131. package/dist/playbooks/task-recovery.md +24 -0
  132. package/dist/playbooks/task-verify.md +22 -0
  133. package/dist/runtime/bootstrap.d.ts +10 -0
  134. package/dist/runtime/bootstrap.js +93 -29
  135. package/dist/runtime/daemon-lock.js +3 -3
  136. package/dist/runtime/desk-runtime.d.ts +40 -7
  137. package/dist/runtime/desk-runtime.js +330 -44
  138. package/dist/runtime/durable-dispatch.d.ts +14 -2
  139. package/dist/runtime/durable-dispatch.js +207 -65
  140. package/dist/runtime/ingress-busy.js +17 -8
  141. package/dist/runtime/ingress-commands.js +24 -4
  142. package/dist/runtime/ingress-deps.d.ts +4 -1
  143. package/dist/runtime/ingress.js +6 -1
  144. package/dist/runtime/request-execution.js +7 -6
  145. package/dist/runtime/shutdown.d.ts +4 -1
  146. package/dist/runtime/shutdown.js +88 -35
  147. package/dist/runtime/task-close.d.ts +1 -1
  148. package/dist/runtime/task-close.js +6 -3
  149. package/dist/runtime/task-control.d.ts +2 -3
  150. package/dist/runtime/task-control.js +38 -11
  151. package/dist/runtime/task-input.js +1 -1
  152. package/dist/runtime/task-lane-types.d.ts +12 -2
  153. package/dist/runtime/task-lane-types.js +9 -0
  154. package/dist/runtime/task-lane.d.ts +2 -0
  155. package/dist/runtime/task-lane.js +38 -20
  156. package/dist/runtime/task-step.d.ts +3 -3
  157. package/dist/runtime/task-step.js +34 -16
  158. package/dist/runtime/transports.js +6 -5
  159. package/dist/runtime/turn-run.js +103 -66
  160. package/dist/security/command-guard.d.ts +1 -1
  161. package/dist/security/command-guard.js +259 -314
  162. package/dist/security/path-guard.js +48 -7
  163. package/dist/security/shell-parse.d.ts +10 -0
  164. package/dist/security/shell-parse.js +224 -0
  165. package/dist/security/types.d.ts +2 -0
  166. package/dist/subagents/commands.d.ts +1 -1
  167. package/dist/subagents/commands.js +14 -5
  168. package/dist/subagents/completion-wake.js +6 -0
  169. package/dist/subagents/detached-discovery.d.ts +1 -1
  170. package/dist/subagents/discovery.d.ts +18 -199
  171. package/dist/subagents/discovery.js +35 -289
  172. package/dist/subagents/dispatch.d.ts +1 -2
  173. package/dist/subagents/dispatch.js +50 -29
  174. package/dist/subagents/external/antigravity-cli.d.ts +2 -0
  175. package/dist/subagents/external/antigravity-cli.js +517 -0
  176. package/dist/subagents/external/claude-code.js +8 -17
  177. package/dist/subagents/external/codex-cli.js +8 -18
  178. package/dist/subagents/external/cursor-cli.js +34 -31
  179. package/dist/subagents/external/dispatch.d.ts +21 -7
  180. package/dist/subagents/external/dispatch.js +146 -12
  181. package/dist/subagents/external/exec.js +3 -0
  182. package/dist/subagents/external/harness.d.ts +57 -33
  183. package/dist/subagents/external/harness.js +69 -40
  184. package/dist/subagents/external/reconciliation.js +1 -0
  185. package/dist/subagents/external/registry.js +4 -1
  186. package/dist/subagents/external/role-warnings.d.ts +4 -13
  187. package/dist/subagents/external/role-warnings.js +4 -28
  188. package/dist/subagents/external/run.d.ts +1 -2
  189. package/dist/subagents/external/run.js +16 -26
  190. package/dist/subagents/external/settlement.d.ts +2 -0
  191. package/dist/subagents/external/settlement.js +13 -3
  192. package/dist/subagents/format.d.ts +1 -1
  193. package/dist/subagents/format.js +1 -1
  194. package/dist/subagents/internal/outcome.d.ts +1 -2
  195. package/dist/subagents/internal/outcome.js +19 -12
  196. package/dist/subagents/internal/provider-retry.d.ts +1 -2
  197. package/dist/subagents/internal/provider-retry.js +2 -4
  198. package/dist/subagents/internal/run.d.ts +2 -3
  199. package/dist/subagents/internal/run.js +27 -4
  200. package/dist/subagents/internal/state.d.ts +2 -5
  201. package/dist/subagents/internal/state.js +1 -2
  202. package/dist/subagents/internal/worker.d.ts +1 -2
  203. package/dist/subagents/internal/worker.js +20 -10
  204. package/dist/subagents/resolve.d.ts +56 -0
  205. package/dist/subagents/resolve.js +202 -0
  206. package/dist/subagents/result.d.ts +6 -4
  207. package/dist/subagents/result.js +39 -6
  208. package/dist/subagents/run-record.d.ts +54 -2
  209. package/dist/subagents/run-record.js +7 -0
  210. package/dist/subagents/runs.d.ts +6 -31
  211. package/dist/subagents/runs.js +26 -31
  212. package/dist/subagents/task-envelope.d.ts +1 -2
  213. package/dist/subagents/task-envelope.js +13 -4
  214. package/dist/subagents/task-settlement.js +1 -0
  215. package/dist/subagents/types.d.ts +105 -6
  216. package/dist/subagents/types.js +16 -1
  217. package/dist/subagents/workspace-lease.d.ts +41 -24
  218. package/dist/subagents/workspace-lease.js +159 -24
  219. package/dist/subagents/worktree.d.ts +52 -0
  220. package/dist/subagents/worktree.js +363 -0
  221. package/dist/tasks/archive.js +4 -0
  222. package/dist/tasks/brief.d.ts +5 -1
  223. package/dist/tasks/brief.js +19 -5
  224. package/dist/tasks/commands.d.ts +6 -1
  225. package/dist/tasks/commands.js +32 -7
  226. package/dist/tasks/control.d.ts +11 -0
  227. package/dist/tasks/delivery.d.ts +2 -0
  228. package/dist/tasks/delivery.js +141 -21
  229. package/dist/tasks/loop-log.d.ts +12 -0
  230. package/dist/tasks/loop-log.js +10 -1
  231. package/dist/tasks/receipts.d.ts +7 -3
  232. package/dist/tasks/receipts.js +34 -5
  233. package/dist/tools/bash.d.ts +3 -0
  234. package/dist/tools/bash.js +29 -15
  235. package/dist/tools/contract/presentation.js +7 -5
  236. package/dist/tools/edit-diff.d.ts +11 -0
  237. package/dist/tools/edit-diff.js +148 -0
  238. package/dist/tools/edit-match.d.ts +18 -0
  239. package/dist/tools/edit-match.js +242 -0
  240. package/dist/tools/edit.d.ts +10 -2
  241. package/dist/tools/edit.js +91 -361
  242. package/dist/tools/event-manage.d.ts +2 -1
  243. package/dist/tools/event-manage.js +46 -39
  244. package/dist/tools/file-observations.d.ts +9 -0
  245. package/dist/tools/file-observations.js +50 -0
  246. package/dist/tools/glob-match.d.ts +3 -1
  247. package/dist/tools/glob-match.js +40 -17
  248. package/dist/tools/glob.d.ts +1 -0
  249. package/dist/tools/glob.js +39 -19
  250. package/dist/tools/grep-command.d.ts +13 -0
  251. package/dist/tools/grep-command.js +77 -0
  252. package/dist/tools/grep.js +96 -201
  253. package/dist/tools/index.d.ts +6 -2
  254. package/dist/tools/index.js +9 -4
  255. package/dist/tools/job.js +12 -11
  256. package/dist/tools/read.d.ts +2 -0
  257. package/dist/tools/read.js +10 -2
  258. package/dist/tools/registry.d.ts +16 -11
  259. package/dist/tools/registry.js +32 -12
  260. package/dist/tools/send-media.js +9 -5
  261. package/dist/tools/session-search.d.ts +2 -1
  262. package/dist/tools/session-search.js +15 -5
  263. package/dist/tools/skill.js +13 -12
  264. package/dist/tools/subagent-manage.d.ts +1 -1
  265. package/dist/tools/subagent-manage.js +25 -152
  266. package/dist/tools/subagent.d.ts +24 -2
  267. package/dist/tools/subagent.js +24 -18
  268. package/dist/tools/task-manage/control-tools.js +1 -1
  269. package/dist/tools/task-manage/factory.d.ts +2 -2
  270. package/dist/tools/task-manage/factory.js +40 -4
  271. package/dist/tools/task-manage/lifecycle.d.ts +3 -3
  272. package/dist/tools/task-manage/lifecycle.js +56 -13
  273. package/dist/tools/task-manage/schema.d.ts +4 -1
  274. package/dist/tools/task-manage/schema.js +4 -1
  275. package/dist/tools/task-manage/shared.d.ts +1 -1
  276. package/dist/tools/task-manage/types.d.ts +5 -1
  277. package/dist/tools/write-content.d.ts +7 -1
  278. package/dist/tools/write-content.js +18 -6
  279. package/dist/tools/write.d.ts +3 -0
  280. package/dist/tools/write.js +6 -2
  281. package/dist/tui/cli.d.ts +6 -6
  282. package/dist/tui/cli.js +120 -28
  283. package/dist/tui/client.d.ts +7 -0
  284. package/dist/tui/client.js +67 -16
  285. package/dist/tui/frontend.d.ts +2 -0
  286. package/dist/tui/pitui-frontend.d.ts +4 -0
  287. package/dist/tui/pitui-frontend.js +27 -0
  288. package/dist/tui/render.d.ts +1 -0
  289. package/dist/tui/render.js +5 -0
  290. package/dist/tui/session.js +6 -0
  291. package/dist/usage/ledger.d.ts +1 -1
  292. package/dist/usage/render.js +1 -1
  293. package/dist/web/client.d.ts +1 -0
  294. package/dist/web/client.js +11 -0
  295. package/dist/web/fetch.js +6 -3
  296. package/dist/webapi/auth.d.ts +0 -3
  297. package/dist/webapi/auth.js +3 -7
  298. package/dist/webapi/config.js +17 -14
  299. package/dist/webapi/key-command.js +41 -41
  300. package/dist/webapi/response-state.d.ts +7 -1
  301. package/dist/webapi/response-state.js +166 -3
  302. package/dist/webapi/routes/websocket.js +24 -1
  303. package/dist/webapi/server.d.ts +3 -1
  304. package/dist/webapi/server.js +32 -1
  305. package/dist/webapi/service.js +8 -0
  306. package/dist/webapi/transport.d.ts +2 -0
  307. package/dist/webapi/transport.js +11 -1
  308. package/examples/sub-agents/README.md +43 -75
  309. package/examples/sub-agents/agy-main.md +21 -0
  310. package/examples/sub-agents/claude-high.md +21 -0
  311. package/examples/sub-agents/claude-main.md +21 -0
  312. package/examples/sub-agents/codex-flash.md +21 -0
  313. package/examples/sub-agents/codex-high.md +21 -0
  314. package/examples/sub-agents/codex-main.md +21 -0
  315. package/examples/sub-agents/codex-review.md +20 -0
  316. package/examples/sub-agents/cursor-high.md +20 -0
  317. package/examples/sub-agents/cursor-main.md +20 -0
  318. package/examples/sub-agents/glm-flash.md +21 -0
  319. package/examples/sub-agents/glm-high.md +21 -0
  320. package/examples/sub-agents/pi-scout.md +20 -0
  321. package/package.json +11 -12
  322. package/dist/agent/session/request-tools.d.ts +0 -3
  323. package/dist/agent/session/request-tools.js +0 -20
  324. package/dist/models/api-keys.d.ts +0 -11
  325. package/dist/models/api-keys.js +0 -22
  326. package/dist/playbooks/memory-and-learning.md +0 -55
  327. package/examples/sub-agents/agents/claude-high.md +0 -23
  328. package/examples/sub-agents/agents/claude-main.md +0 -23
  329. package/examples/sub-agents/agents/codex-flash.md +0 -23
  330. package/examples/sub-agents/agents/codex-high.md +0 -23
  331. package/examples/sub-agents/agents/codex-main.md +0 -23
  332. package/examples/sub-agents/agents/codex-review.md +0 -23
  333. package/examples/sub-agents/agents/cursor-high.md +0 -22
  334. package/examples/sub-agents/agents/cursor-main.md +0 -22
  335. package/examples/sub-agents/agents/glm-flash.md +0 -23
  336. package/examples/sub-agents/agents/glm-high.md +0 -23
  337. package/examples/sub-agents/agents/scout.md +0 -30
  338. package/examples/sub-agents/roles/builder-hard.md +0 -34
  339. package/examples/sub-agents/roles/builder.md +0 -34
  340. package/examples/sub-agents/roles/explorer.md +0 -39
  341. package/examples/sub-agents/roles/git-committer.md +0 -43
  342. package/examples/sub-agents/roles/planner.md +0 -33
  343. package/examples/sub-agents/roles/reviewer.md +0 -33
  344. package/examples/sub-agents/roles/verifier.md +0 -35
  345. package/examples/sub-agents/roles/worker.md +0 -34
@@ -1,254 +1,47 @@
1
- import * as Diff from "diff";
2
1
  import { Type } from "typebox";
3
2
  import { fingerprintOf, fingerprintsEqual } from "../file-store.js";
4
3
  import { DEFAULT_SECURITY_CONFIG } from "../security/config.js";
5
4
  import { checkPathGuard } from "../security/path-guard-check.js";
6
5
  import { RecoverableToolError } from "../shared/recoverable-error.js";
6
+ import { assertPathWritableUnderLease } from "../subagents/workspace-lease.js";
7
7
  import { withTaskFileMutation } from "../tasks/file-mutation.js";
8
- /**
9
- * Generate a unified diff string with line numbers and context. `startLineOld`/`startLineNew` let
10
- * a caller render a *window* of a larger file (spec 044, D2.3) while still printing the file's real
11
- * absolute line numbers instead of restarting at 1.
12
- */
13
- function generateDiffString(oldContent, newContent, contextLines = 4, startLineOld = 1, startLineNew = 1) {
14
- const parts = Diff.diffLines(oldContent, newContent);
15
- const output = [];
16
- const oldLines = oldContent.split("\n");
17
- const newLines = newContent.split("\n");
18
- const maxLineNum = Math.max(startLineOld + oldLines.length, startLineNew + newLines.length);
19
- const lineNumWidth = String(maxLineNum).length;
20
- let oldLineNum = startLineOld;
21
- let newLineNum = startLineNew;
22
- let lastWasChange = false;
23
- for (let i = 0; i < parts.length; i++) {
24
- const part = parts[i];
25
- const raw = part.value.split("\n");
26
- if (raw[raw.length - 1] === "") {
27
- raw.pop();
28
- }
29
- if (part.added || part.removed) {
30
- for (const line of raw) {
31
- if (part.added) {
32
- const lineNum = String(newLineNum).padStart(lineNumWidth, " ");
33
- output.push(`+${lineNum} ${line}`);
34
- newLineNum++;
35
- }
36
- else {
37
- const lineNum = String(oldLineNum).padStart(lineNumWidth, " ");
38
- output.push(`-${lineNum} ${line}`);
39
- oldLineNum++;
40
- }
41
- }
42
- lastWasChange = true;
43
- }
44
- else {
45
- const nextPartIsChange = i < parts.length - 1 && (parts[i + 1].added || parts[i + 1].removed);
46
- if (lastWasChange || nextPartIsChange) {
47
- let linesToShow = raw;
48
- let skipStart = 0;
49
- let skipEnd = 0;
50
- if (!lastWasChange) {
51
- skipStart = Math.max(0, raw.length - contextLines);
52
- linesToShow = raw.slice(skipStart);
53
- }
54
- if (!nextPartIsChange && linesToShow.length > contextLines) {
55
- skipEnd = linesToShow.length - contextLines;
56
- linesToShow = linesToShow.slice(0, contextLines);
57
- }
58
- if (skipStart > 0) {
59
- output.push(` ${"".padStart(lineNumWidth, " ")} ...`);
60
- }
61
- for (const line of linesToShow) {
62
- const lineNum = String(oldLineNum).padStart(lineNumWidth, " ");
63
- output.push(` ${lineNum} ${line}`);
64
- oldLineNum++;
65
- newLineNum++;
66
- }
67
- if (skipEnd > 0) {
68
- output.push(` ${"".padStart(lineNumWidth, " ")} ...`);
69
- }
70
- oldLineNum += skipStart + skipEnd;
71
- newLineNum += skipStart + skipEnd;
72
- }
73
- else {
74
- oldLineNum += raw.length;
75
- newLineNum += raw.length;
76
- }
77
- lastWasChange = false;
78
- }
79
- }
80
- return output.join("\n");
81
- }
8
+ import { clampDiffForEcho, renderEditDiff, renderStreamingEditDiff } from "./edit-diff.js";
9
+ import { planInlineEdit, planStreamingEdit } from "./edit-match.js";
10
+ import { observeCurrentFile } from "./file-observations.js";
82
11
  const editSchema = Type.Object({
83
- path: Type.String({ description: "Path to the file to edit (relative or absolute)" }),
84
- oldText: Type.String({ description: "Exact text to find and replace (must match exactly)" }),
85
- newText: Type.String({ description: "New text to replace the old text with" }),
86
- replaceAll: Type.Optional(Type.Boolean({
87
- description: "Replace every occurrence instead of requiring a unique match. Defaults to false (the match must be unique).",
12
+ path: Type.String({ description: "File path." }),
13
+ oldText: Type.Optional(Type.String({ description: "Exact anchor for a single edit." })),
14
+ newText: Type.Optional(Type.String({ description: "Replacement for a single edit." })),
15
+ replaceAll: Type.Optional(Type.Boolean({ description: "Replace all matches; default false." })),
16
+ edits: Type.Optional(Type.Array(Type.Object({
17
+ oldText: Type.String(),
18
+ newText: Type.String(),
19
+ replaceAll: Type.Optional(Type.Boolean()),
20
+ }), {
21
+ minItems: 1,
22
+ maxItems: 50,
23
+ description: "Atomic edits against the original file. Use instead of top-level oldText/newText/replaceAll.",
88
24
  })),
89
25
  });
90
- /** Max diff lines echoed back to the model in the success result before eliding the rest. */
91
- const DIFF_ECHO_MAX_LINES = 40;
92
- /** Byte ceiling on the echoed diff — 40 lines of a minified single-line file can be hundreds of KB. */
93
- const DIFF_ECHO_MAX_BYTES = 8 * 1024;
94
- /** Consecutive byte-identical no-ops of the same payload before the soft error escalates to a hard stop. */
95
26
  const NOOP_HARD_LIMIT = 3;
96
- /** Above this, `edit` switches from "read whole file into memory" to the streaming two-pass path (D2.2). */
97
27
  const EDIT_INLINE_MAX_BYTES = 8 * 1024 * 1024;
98
- /** Bytes scanned from the head of the file for the binary guard (D2.5). */
99
- const BINARY_SNIFF_BYTES = 8 * 1024;
100
- /**
101
- * Hard cap on how many `replaceAll` match offsets the streaming path records in memory (D2.2). A
102
- * file with more occurrences than this is almost certainly the wrong target for a text edit (e.g.
103
- * a needle that matches on every line of a huge generated file); failing loudly with a narrowing
104
- * suggestion is one of the sanctioned "bounded" outcomes (spec 044, design principle P2), not a
105
- * silent truncation.
106
- */
107
- const MAX_REPLACE_ALL_OFFSETS = 200_000;
108
- /** Bytes of file context shown around each match in the streaming path's local diff (D2.3). */
109
- const DIFF_WINDOW_BYTES = 2000;
110
- /** How many of a `replaceAll` match's diffs get rendered on the streaming path. */
111
- const MAX_DIFF_WINDOWS = 5;
112
- function clampDiffForEcho(diff) {
113
- const lines = diff.split("\n");
114
- if (lines.length <= DIFF_ECHO_MAX_LINES && Buffer.byteLength(diff, "utf-8") <= DIFF_ECHO_MAX_BYTES) {
115
- return diff;
28
+ function normalizeEdits({ edits, oldText, newText, replaceAll }) {
29
+ if (edits !== undefined && (oldText !== undefined || newText !== undefined || replaceAll !== undefined)) {
30
+ throw new RecoverableToolError("Use either edits or top-level oldText/newText/replaceAll.");
116
31
  }
117
- let kept = lines.slice(0, DIFF_ECHO_MAX_LINES);
118
- while (kept.length > 1 && Buffer.byteLength(kept.join("\n"), "utf-8") > DIFF_ECHO_MAX_BYTES) {
119
- kept = kept.slice(0, -1);
32
+ if (edits === undefined && (typeof oldText !== "string" || typeof newText !== "string")) {
33
+ throw new RecoverableToolError("Provide both oldText and newText, or use edits.");
120
34
  }
121
- let shown = kept.join("\n");
122
- if (Buffer.byteLength(shown, "utf-8") > DIFF_ECHO_MAX_BYTES) {
123
- // A single line still over budget: hard-cut on a UTF-8 boundary.
124
- shown = Buffer.from(shown, "utf-8").subarray(0, DIFF_ECHO_MAX_BYTES).toString("utf-8");
35
+ const hunks = edits ?? [{ oldText: oldText, newText: newText, replaceAll }];
36
+ if (hunks.length === 0 || hunks.length > 50) {
37
+ throw new RecoverableToolError("Provide 1 to 50 edits; split larger requests across calls.");
125
38
  }
126
- const omitted = lines.length - kept.length;
127
- return `${shown}\n[diff truncated${omitted > 0 ? `, ${omitted} more line(s)` : ""}; the full diff is in the tool result details]`;
128
- }
129
- /** All non-overlapping byte offsets of `needle` in `haystack`, left to right (mirrors `String.split`). */
130
- function findAllOffsets(haystack, needle) {
131
- const offsets = [];
132
- let from = 0;
133
- while (true) {
134
- const idx = haystack.indexOf(needle, from);
135
- if (idx === -1)
136
- break;
137
- offsets.push(idx);
138
- from = idx + needle.length;
139
- }
140
- return offsets;
141
- }
142
- /** Byte-level splice: replace `needle` at every offset in `offsets` (ascending) with `replacement`. */
143
- function spliceBuffer(source, needle, replacement, offsets) {
144
- const parts = [];
145
- let cursor = 0;
146
- for (const offset of offsets) {
147
- parts.push(source.subarray(cursor, offset));
148
- parts.push(replacement);
149
- cursor = offset + needle.length;
150
- }
151
- parts.push(source.subarray(cursor));
152
- return Buffer.concat(parts);
153
- }
154
- /**
155
- * A streaming scan for every non-overlapping occurrence of `needle`, safe against a match that
156
- * straddles a chunk boundary (D2.2). Carries the last `needle.length - 1` bytes of each window into
157
- * the next iteration so a split match is still found, without ever holding more than one window in
158
- * memory. Also tracks the 1-indexed line number of each match (from a running newline count) and
159
- * sniffs the first `BINARY_SNIFF_BYTES` for a NUL byte (D2.5).
160
- */
161
- async function scanOccurrences(stream, needle, maxOffsets) {
162
- const overlapLen = needle.length - 1;
163
- let carry = Buffer.alloc(0);
164
- let windowBaseOffset = 0;
165
- let newlinesBeforeWindow = 0;
166
- let count = 0;
167
- // Absolute byte position just past the last accepted match. A window carries the last
168
- // `overlapLen` bytes of its predecessor, so without this guard a match that ended inside the
169
- // carry region would be re-found (from a fresh `from = 0`) and reported as a second, overlapping
170
- // offset -- which `spliceBuffer` then turns into a corrupt file. Verified against a non-overlapping
171
- // `Buffer.indexOf` reference over 165 boundary combinations.
172
- let nextAllowed = 0;
173
- let offsets = [];
174
- const lineNumbers = new Map();
175
- let looksBinary = false;
176
- let sniffed = 0;
177
- let totalBytes = 0;
178
- for await (const chunk of stream) {
179
- totalBytes += chunk.length;
180
- if (sniffed < BINARY_SNIFF_BYTES) {
181
- const take = chunk.subarray(0, BINARY_SNIFF_BYTES - sniffed);
182
- if (take.includes(0))
183
- looksBinary = true;
184
- sniffed += take.length;
39
+ for (const [index, hunk] of hunks.entries()) {
40
+ if (hunk.oldText.length === 0) {
41
+ throw new RecoverableToolError(`oldText must not be empty (edit #${index + 1}). Read the target and supply an exact anchor.`);
185
42
  }
186
- const window = carry.length > 0 ? Buffer.concat([carry, chunk]) : chunk;
187
- let from = Math.max(0, nextAllowed - windowBaseOffset);
188
- while (true) {
189
- const idx = window.indexOf(needle, from);
190
- if (idx === -1)
191
- break;
192
- const absoluteOffset = windowBaseOffset + idx;
193
- count++;
194
- nextAllowed = absoluteOffset + needle.length;
195
- if (offsets && offsets.length < maxOffsets) {
196
- offsets.push(absoluteOffset);
197
- const lineNumber = newlinesBeforeWindow + countNewlines(window, 0, idx) + 1;
198
- lineNumbers.set(absoluteOffset, lineNumber);
199
- }
200
- else if (offsets) {
201
- offsets = undefined; // Overflowed: stop tracking, caller must fail closed if it needed them.
202
- }
203
- from = idx + needle.length;
204
- }
205
- const retiredLen = Math.max(0, window.length - overlapLen);
206
- newlinesBeforeWindow += countNewlines(window, 0, retiredLen);
207
- windowBaseOffset += retiredLen;
208
- carry = window.subarray(retiredLen);
209
- }
210
- return { count, offsets, lineNumbers, looksBinary, totalBytes };
211
- }
212
- function countNewlines(buf, start, end) {
213
- let n = 0;
214
- for (let i = start; i < end; i++) {
215
- if (buf[i] === 0x0a)
216
- n++;
217
43
  }
218
- return n;
219
- }
220
- async function* readStreamChunks(store, path, signal) {
221
- for await (const chunk of store.openRead(path)) {
222
- if (signal?.aborted)
223
- throw new Error("Aborted");
224
- yield chunk;
225
- }
226
- }
227
- /** Copy `[start, end)` of `path` onto `out`, with simple backpressure handling. */
228
- function copyRange(store, path, start, end, out) {
229
- if (end <= start)
230
- return Promise.resolve();
231
- return new Promise((resolveCopy, reject) => {
232
- const src = store.openRead(path, { start, end: end - 1 });
233
- src.on("data", (chunk) => {
234
- if (!out.write(chunk)) {
235
- src.pause();
236
- out.once("drain", () => src.resume());
237
- }
238
- });
239
- src.on("end", () => resolveCopy());
240
- src.on("error", reject);
241
- });
242
- }
243
- /** Expand a byte window to the nearest line boundaries so the rendered diff never starts/ends mid-line. */
244
- function expandToLineBoundaries(bytes, start, end, fileSize) {
245
- let s = start;
246
- while (s > 0 && bytes[s - 1] !== undefined && bytes[s - 1] !== 0x0a)
247
- s--;
248
- let e = end;
249
- while (e < fileSize && bytes[e] !== undefined && bytes[e] !== 0x0a)
250
- e++;
251
- return { start: s, end: e };
44
+ return hunks;
252
45
  }
253
46
  async function checkFingerprintUnchanged(fileStore, target, path, before) {
254
47
  const after = await fileStore.stat(target);
@@ -263,24 +56,17 @@ export function createEditTool(fileStore, options = {}) {
263
56
  agentWorkspaceDir: process.cwd(),
264
57
  cwd: process.cwd(),
265
58
  };
266
- // Per-tool-instance counter of consecutive byte-identical no-op edits, keyed by the exact
267
- // (path, oldText, newText) payload. A model stuck re-issuing the same no-op edit is chasing a
268
- // bug that lives elsewhere; after NOOP_HARD_LIMIT we escalate from a soft steer to a hard stop
269
- // so the loop can't burn turns. Any successful edit clears the streak (see below).
270
59
  const noopCounts = new Map();
271
60
  return {
272
61
  name: "edit",
273
62
  label: "edit",
274
- // Serialize with other mutating tools in the same batch. `checkFingerprintUnchanged` runs
275
- // before the write, so two concurrent edits can both pass it and then overwrite each other's
276
- // result; running the batch one tool at a time closes that window (spec: batch 1.3).
63
+ // Serialize with other mutating tools in the same SDK batch.
277
64
  executionMode: "sequential",
278
- description: "Edit a file by replacing exact text. The oldText must match exactly (including whitespace). Use this for precise, surgical edits.",
65
+ description: "Replace exact text, including whitespace. Matches must be unique unless replaceAll is true.",
279
66
  parameters: editSchema,
280
- execute: async (_toolCallId, { path, oldText, newText, replaceAll, }, signal) => {
281
- if (oldText.length === 0) {
282
- throw new RecoverableToolError("oldText must not be empty.");
283
- }
67
+ execute: async (_toolCallId, args, signal) => {
68
+ const { path } = args;
69
+ const hunks = normalizeEdits(args);
284
70
  const target = await checkPathGuard(path, "read", securityConfig, securityContext, {
285
71
  tool: "edit",
286
72
  channelId: options.channelId,
@@ -290,142 +76,69 @@ export function createEditTool(fileStore, options = {}) {
290
76
  // symlink-write check lstats the pre-symlink-resolution path, and handing it a resolved
291
77
  // value would blind it to "the path itself is a symlink". Both calls return the same
292
78
  // `resolvedPath` for read and write, so `target` stays the one value we open.
293
- await checkPathGuard(path, "write", securityConfig, securityContext, {
79
+ const writableTarget = await checkPathGuard(path, "write", securityConfig, securityContext, {
294
80
  tool: "edit",
295
81
  channelId: options.channelId,
296
82
  });
83
+ if (writableTarget !== target) {
84
+ throw new RecoverableToolError(`${path} resolved to different targets during this edit. Re-read it and retry.`);
85
+ }
86
+ assertPathWritableUnderLease(target, {
87
+ deskDir: options.deskDir,
88
+ excludeRunId: options.leaseOwnerRunId,
89
+ });
297
90
  return withTaskFileMutation(options.deskDir, target, async () => {
298
91
  const before = await fileStore.stat(target);
299
- if (!before || !before.isFile) {
300
- throw new RecoverableToolError(`File not found: ${path}`);
92
+ if (!before?.isFile) {
93
+ throw new RecoverableToolError(`File not found: ${path}. Read the parent directory to check the path.`);
301
94
  }
302
- const needle = Buffer.from(oldText, "utf-8");
303
- const replacement = Buffer.from(newText, "utf-8");
304
- const isNoopPayload = needle.equals(replacement);
305
- const applyNoop = () => {
306
- const noopKey = `${path}\x00${oldText}\x00${newText}`;
95
+ const note = options.observations?.describeEditNote(target, path, before);
96
+ const result = before.size <= EDIT_INLINE_MAX_BYTES
97
+ ? await editInline(fileStore, target, path, before, hunks, signal)
98
+ : await editStreaming(fileStore, target, path, before, hunks, signal);
99
+ if (!result) {
100
+ const noopKey = JSON.stringify([target, hunks]);
307
101
  const streak = (noopCounts.get(noopKey) ?? 0) + 1;
308
102
  noopCounts.set(noopKey, streak);
309
103
  if (streak >= NOOP_HARD_LIMIT) {
310
- throw new Error(`STOP. This exact edit to ${path} has been a no-op ${streak} times in a row. ` +
311
- `The bug is somewhere else — re-read the file to verify the anchor text before editing again. ` +
312
- `Do NOT widen oldText or add lines to force a match.`);
104
+ throw new Error(`STOP. This exact edit to ${path} has been a no-op ${streak} times in a row. Re-read the file to verify what still needs changing.`);
313
105
  }
314
- throw new RecoverableToolError(`No changes made to ${path}: oldText and newText are byte-identical at the match, so the replacement produced no change. ` +
315
- `Re-read the file to confirm what actually needs changing before editing again.`);
316
- };
317
- let result;
318
- if (before.size <= EDIT_INLINE_MAX_BYTES) {
319
- result = await editInline(fileStore, target, path, before, needle, replacement, replaceAll === true, signal);
320
- }
321
- else {
322
- result = await editStreaming(fileStore, target, path, before, needle, replacement, replaceAll === true, isNoopPayload, signal);
106
+ throw new RecoverableToolError(`No changes made to ${path}: the replacements produced byte-identical content. Re-read the file to verify what still needs changing.`);
323
107
  }
324
- if (isNoopPayload) {
325
- applyNoop();
326
- }
327
- // A real edit breaks any no-op streak.
328
108
  noopCounts.clear();
329
- const replacementSummary = replaceAll
330
- ? `Replaced ${result.occurrences} occurrence${result.occurrences === 1 ? "" : "s"} in ${path}.`
331
- : `Successfully replaced text in ${path}. Changed ${oldText.length} characters to ${newText.length} characters.`;
109
+ await observeCurrentFile(options.observations, fileStore, target);
110
+ const { oldText, newText, replaceAll } = hunks[0];
111
+ const replacementSummary = hunks.length > 1
112
+ ? `Applied ${hunks.length} edits to ${path} (${result.occurrences} replacements).`
113
+ : replaceAll
114
+ ? `Replaced ${result.occurrences} occurrence${result.occurrences === 1 ? "" : "s"} in ${path}.`
115
+ : `Successfully replaced text in ${path}. Changed ${oldText.length} characters to ${newText.length} characters.`;
332
116
  const echoedDiff = result.diff.trim() ? `\n\n${clampDiffForEcho(result.diff)}` : "";
333
117
  return {
334
- content: [{ type: "text", text: `${replacementSummary}${echoedDiff}` }],
335
- details: {
336
- path: target,
337
- diff: result.diff,
338
- patch: result.patch,
339
- },
118
+ content: [{ type: "text", text: `${replacementSummary}${echoedDiff}${note ? `\n${note}` : ""}` }],
119
+ details: { path: target, diff: result.diff, patch: result.patch },
340
120
  };
341
121
  });
342
122
  },
343
123
  };
344
124
  }
345
- /** D2.1: small file path -- read whole, splice in memory, write atomically. */
346
- async function editInline(fileStore, target, path, before, needle, replacement, replaceAll, signal) {
125
+ async function editInline(fileStore, target, path, before, hunks, signal) {
347
126
  const { data } = await fileStore.readBytes(target, { signal });
348
- if (data.subarray(0, BINARY_SNIFF_BYTES).includes(0)) {
349
- throw new RecoverableToolError(`${path} looks like a binary file (a NUL byte appears in the first ${BINARY_SNIFF_BYTES} bytes). ` +
350
- "Use bash for binary edits — edit is for text.");
351
- }
352
- const offsets = findAllOffsets(data, needle);
353
- if (offsets.length === 0) {
354
- throw new RecoverableToolError(`Could not find the exact text in ${path}. The old text must match exactly including all whitespace and newlines.`);
355
- }
356
- if (offsets.length > 1 && !replaceAll) {
357
- throw new RecoverableToolError(`Found ${offsets.length} occurrences of the text in ${path}. The text must be unique, or pass replaceAll: true to replace all of them. Please provide more context to make it unique.`);
358
- }
359
- const useOffsets = replaceAll ? offsets : [offsets[0]];
360
- const newData = spliceBuffer(data, needle, replacement, useOffsets);
361
- if (newData.equals(data)) {
362
- // Byte-identical payload -- caller (createEditTool) turns this into the no-op error/hard-stop.
363
- return { text: "", diff: "", patch: "", occurrences: useOffsets.length };
364
- }
127
+ const { newData, occurrences } = planInlineEdit(data, path, hunks);
128
+ if (newData.equals(data))
129
+ return undefined;
365
130
  await checkFingerprintUnchanged(fileStore, target, path, before);
366
131
  await fileStore.writeAtomic(target, newData, { preserveMode: true, signal });
367
- const oldText = data.toString("utf-8");
368
- const newText = newData.toString("utf-8");
369
- const diff = generateDiffString(oldText, newText);
370
- const patch = Diff.createPatch(path, oldText, newText);
371
- return { text: "", diff, patch, occurrences: useOffsets.length };
132
+ return { ...renderEditDiff(path, data, newData), occurrences };
372
133
  }
373
- /** D2.2: streaming two-pass path for files over EDIT_INLINE_MAX_BYTES. */
374
- async function editStreaming(fileStore, target, path, before, needle, replacement, replaceAll, isNoopPayload, signal) {
375
- // Pass 1: scan for occurrences, line numbers, and a binary sniff -- no writes yet, so the
376
- // uniqueness/existence judgment is made before anything touches disk.
377
- const scan = await scanOccurrences(readStreamChunks(fileStore, target, signal), needle, MAX_REPLACE_ALL_OFFSETS);
378
- if (scan.looksBinary) {
379
- throw new RecoverableToolError(`${path} looks like a binary file (a NUL byte appears in the first ${BINARY_SNIFF_BYTES} bytes). ` +
380
- "Use bash for binary edits — edit is for text.");
381
- }
382
- if (scan.count === 0) {
383
- throw new RecoverableToolError(`Could not find the exact text in ${path}. The old text must match exactly including all whitespace and newlines.`);
384
- }
385
- if (scan.count > 1 && !replaceAll) {
386
- throw new RecoverableToolError(`Found ${scan.count} occurrences of the text in ${path}. The text must be unique, or pass replaceAll: true to replace all of them. Please provide more context to make it unique.`);
387
- }
388
- if (!scan.offsets) {
389
- throw new RecoverableToolError(`${path} has more than ${MAX_REPLACE_ALL_OFFSETS} occurrences of the text -- too many to replace in one call on a file this large. ` +
390
- "Narrow the pattern (add more context) so it matches far fewer places.");
391
- }
392
- const matchOffsets = replaceAll ? scan.offsets : [scan.offsets[0]];
393
- const occurrences = matchOffsets.length;
394
- if (isNoopPayload) {
395
- // The caller turns this into the no-op error/hard-stop; no point writing an identical file.
396
- return { text: "", diff: "", patch: "", occurrences };
397
- }
398
- // Local diff windows, read from the *original* file before pass 2 rewrites it.
399
- const diffParts = [];
400
- const patchParts = [];
401
- const shown = Math.min(matchOffsets.length, MAX_DIFF_WINDOWS);
402
- for (let i = 0; i < shown; i++) {
403
- const offset = matchOffsets[i];
404
- const rawStart = Math.max(0, offset - DIFF_WINDOW_BYTES);
405
- const rawEnd = Math.min(before.size, offset + needle.length + DIFF_WINDOW_BYTES);
406
- const { data: windowBytes } = await fileStore.readBytes(target, {
407
- start: rawStart,
408
- maxBytes: rawEnd - rawStart,
409
- signal,
410
- });
411
- const { start, end } = expandToLineBoundaries(windowBytes, offset - rawStart, offset - rawStart + needle.length, windowBytes.length);
412
- const oldWindow = windowBytes.subarray(start, end).toString("utf-8");
413
- const newWindow = windowBytes.subarray(start, offset - rawStart).toString("utf-8") +
414
- replacement.toString("utf-8") +
415
- windowBytes.subarray(offset - rawStart + needle.length, end).toString("utf-8");
416
- const startLine = scan.lineNumbers.get(offset) ?? 1;
417
- // The window itself may start mid-file above `offset`'s line, so back up the printed line
418
- // number by however many newlines are in the window before the expanded start.
419
- const linesBeforeWindowStart = countNewlines(windowBytes, 0, start);
420
- const linesBeforeMatch = countNewlines(windowBytes, 0, offset - rawStart);
421
- const windowStartLine = startLine - (linesBeforeMatch - linesBeforeWindowStart);
422
- diffParts.push(generateDiffString(oldWindow, newWindow, 4, windowStartLine, windowStartLine));
423
- patchParts.push(Diff.createPatch(path, oldWindow, newWindow));
424
- }
425
- if (matchOffsets.length > shown) {
426
- diffParts.push(`[+${matchOffsets.length - shown} more occurrence(s) replaced, diff not shown]`);
427
- }
428
- // Pass 2: apply. Stream-copy the file, splicing in `replacement` at each recorded offset.
134
+ async function editStreaming(fileStore, target, path, before, hunks, signal) {
135
+ if (hunks.length > 1) {
136
+ throw new RecoverableToolError(`${path} exceeds 8 MiB. Split the edits into separate single-edit calls.`);
137
+ }
138
+ const { needle, replacement, matchOffsets, lineNumbers } = await planStreamingEdit(fileStore, target, path, hunks[0], signal);
139
+ if (needle.equals(replacement))
140
+ return undefined;
141
+ const diff = await renderStreamingEditDiff(fileStore, target, path, before.size, needle, replacement, matchOffsets, lineNumbers, signal);
429
142
  await checkFingerprintUnchanged(fileStore, target, path, before);
430
143
  await fileStore.replaceViaTemp(target, async (out) => {
431
144
  let cursor = 0;
@@ -435,6 +148,23 @@ async function editStreaming(fileStore, target, path, before, needle, replacemen
435
148
  cursor = offset + needle.length;
436
149
  }
437
150
  await copyRange(fileStore, target, cursor, before.size, out);
151
+ await checkFingerprintUnchanged(fileStore, target, path, before);
438
152
  }, { preserveMode: true, signal });
439
- return { text: "", diff: diffParts.join("\n\n"), patch: patchParts.join("\n"), occurrences };
153
+ return { ...diff, occurrences: matchOffsets.length };
154
+ }
155
+ /** Copy `[start, end)` of `path` onto `out`, with simple backpressure handling. */
156
+ function copyRange(store, path, start, end, out) {
157
+ if (end <= start)
158
+ return Promise.resolve();
159
+ return new Promise((resolveCopy, reject) => {
160
+ const src = store.openRead(path, { start, end: end - 1 });
161
+ src.on("data", (chunk) => {
162
+ if (!out.write(chunk)) {
163
+ src.pause();
164
+ out.once("drain", () => src.resume());
165
+ }
166
+ });
167
+ src.on("end", () => resolveCopy());
168
+ src.on("error", reject);
169
+ });
440
170
  }
@@ -7,7 +7,7 @@ declare const eventManageSchema: Type.TObject<{
7
7
  action: Type.TUnion<[Type.TLiteral<"list">, Type.TLiteral<"show">, Type.TLiteral<"create">, Type.TLiteral<"update">, Type.TLiteral<"delete">]>;
8
8
  name: Type.TOptional<Type.TString>;
9
9
  definition: Type.TOptional<Type.TObject<{
10
- type: Type.TUnion<[Type.TLiteral<"one-shot">, Type.TLiteral<"periodic">, Type.TLiteral<"immediate">]>;
10
+ type: Type.TUnion<[Type.TLiteral<"one-shot">, Type.TLiteral<"periodic">]>;
11
11
  text: Type.TOptional<Type.TString>;
12
12
  task: Type.TOptional<Type.TObject<{
13
13
  title: Type.TString;
@@ -41,6 +41,7 @@ export type EventDefinitionInput = {
41
41
  type: "bash";
42
42
  command: string;
43
43
  timeoutMs?: number;
44
+ timeout?: number;
44
45
  };
45
46
  };
46
47
  export interface EventManageListEntry {