@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
@@ -7,16 +7,15 @@ import { join } from "path";
7
7
  import { loadDetachedMaintenanceContext } from "../agent/maintenance-context.js";
8
8
  import { createRunner } from "../agent/runner-factory.js";
9
9
  import { scanConversationsForInterruptedTurns } from "../agent/turn/turn-recovery.js";
10
- import { BootstrapExitError, bootstrapAppHome, DEFAULT_BOOTSTRAP_PATHS, parseArgs, printBootstrapSummary, printFirstRunGuide, readCliVersion, } from "../app/home.js";
10
+ import { ensureModelOnboarding } from "../app/auth-command.js";
11
+ import { BootstrapExitError, bootstrapAppHome, DEFAULT_BOOTSTRAP_PATHS, parseArgs, printBootstrapSummary, printStartupReadySummary, readCliVersion, } from "../app/home.js";
11
12
  import { prepareAppServices } from "../app/services.js";
12
13
  import { CHANNELS_INDEX_FILENAME, createChannelIndex } from "../channel/channel-index.js";
13
14
  import { ChannelStore } from "../channel/store.js";
14
15
  import { PipiclawSettingsManager } from "../config/settings.js";
15
16
  import { getToolsConfigPath, loadToolsConfig } from "../config/tools.js";
16
- import { buildDeskList } from "../desk/commands.js";
17
17
  import { initializeDefaultDesk } from "../desk/default.js";
18
18
  import { getDeskDir } from "../desk/paths.js";
19
- import { listDesks } from "../desk/registry.js";
20
19
  import { StartupRefusal } from "../desk/startup-error.js";
21
20
  import { createEventsWatcher } from "../events/watcher.js";
22
21
  import { createExecutor } from "../executor.js";
@@ -24,6 +23,7 @@ import { createFileStore } from "../file-store.js";
24
23
  import { createJobRuntime } from "../jobs/runtime.js";
25
24
  import * as log from "../log.js";
26
25
  import { MemoryMaintenanceScheduler } from "../memory/scheduler.js";
26
+ import { flushModelCredentials } from "../models/credential-work.js";
27
27
  import { defaultModel } from "../models/runtime.js";
28
28
  import { loadSecurityConfigWithDiagnostics } from "../security/config.js";
29
29
  import { logSecurityEvent } from "../security/logger.js";
@@ -31,6 +31,7 @@ import { fileStamp } from "../shared/format.js";
31
31
  import { errorMessage } from "../shared/text-utils.js";
32
32
  import { renderRunNotice } from "../subagents/commands.js";
33
33
  import { createSubAgentRuntime } from "../subagents/run-registry.js";
34
+ import { findConflictingWorkspaceLease } from "../subagents/workspace-lease.js";
34
35
  import { taskSessionPath } from "../tasks/session-path.js";
35
36
  import { getUsageLedger } from "../usage/ledger.js";
36
37
  import { acquireDaemonLock, tryAcquireDaemonLock } from "./daemon-lock.js";
@@ -116,7 +117,7 @@ async function buildRuntimeContext(options, daemonLock) {
116
117
  const sessionResetChains = new Map();
117
118
  const activeTasks = new Set();
118
119
  /** Channels with a `/stop` watchdog in flight, so a burst of `/stop` starts only one. */
119
- const stopWatchdogs = new Set();
120
+ const stopWatchdogs = new Map();
120
121
  let durableDispatch;
121
122
  let shuttingDown = false;
122
123
  const executor = options.executor ?? createExecutor();
@@ -162,15 +163,17 @@ async function buildRuntimeContext(options, daemonLock) {
162
163
  });
163
164
  }
164
165
  },
165
- createWatcher: (target) => options.createEventsWatcher
166
- ? options.createEventsWatcher(target)
167
- : createEventsWatcher({
166
+ createWatcher: (target) => {
167
+ if (options.createEventsWatcher)
168
+ return options.createEventsWatcher(target);
169
+ const security = loadSecurityConfigWithDiagnostics(appHomeDir).config;
170
+ return createEventsWatcher({
168
171
  ...target,
169
172
  isBound: (channelId) => deskRuntime.isBoundTo(channelId, target.desk),
170
173
  isReachable: (channelId) => transports.isReachable(channelId),
171
174
  sink: ingress,
172
175
  executor,
173
- commandGuardConfig: loadSecurityConfigWithDiagnostics(appHomeDir).config.commandGuard,
176
+ commandGuardConfig: security.enabled ? security.commandGuard : undefined,
174
177
  historyPath: options.paths.eventHistoryPath,
175
178
  dispatch,
176
179
  spawnTask: createTaskSpawner({
@@ -178,11 +181,26 @@ async function buildRuntimeContext(options, daemonLock) {
178
181
  wake: () => taskLane.notify(),
179
182
  notify: (desk, channelId, text) => deskRuntime.sendFromDesk(desk, channelId, text),
180
183
  }),
181
- }),
184
+ });
185
+ },
182
186
  send: (channelId, text) => pushTo(channelId, { text }),
183
187
  isChannelBusy: (channelId) => channelRunners.get(channelId)?.isBusy() ?? false,
188
+ isDeskBusy: (desk, currentCwd) => {
189
+ const runningTask = taskLane?.runningTaskInDesk(desk);
190
+ if (runningTask)
191
+ return `后台任务 \`${runningTask}\` 正在执行当前步骤`;
192
+ const lease = findConflictingWorkspaceLease(currentCwd, {
193
+ mode: "write",
194
+ deskDir: getDeskDir(workspaceDir, desk),
195
+ });
196
+ if (lease)
197
+ return `委派 \`${lease.runId}\` 正在占用当前工作目录`;
198
+ return undefined;
199
+ },
200
+ describeChannel: (channelId) => labelOf(channelId),
184
201
  releaseRunner: (channelId) => releaseCachedRunner(channelRunners, channelId),
185
202
  onBindingChanged: () => channelIndex.noteBindingChanged(),
203
+ onActivated: () => taskLane?.notify(),
186
204
  });
187
205
  await deskRuntime.load();
188
206
  const isBoundTo = (channelId, desk) => deskRuntime.isBoundTo(channelId, desk);
@@ -204,6 +222,7 @@ async function buildRuntimeContext(options, daemonLock) {
204
222
  const describeChannel = (desk, channelId) => ({
205
223
  label: labelOf(channelId),
206
224
  boundHere: deskRuntime.isBoundTo(channelId, desk),
225
+ reachable: transports.isReachable(channelId),
207
226
  });
208
227
  const archiveIncomingMessage = async (channelId, message, contextLabel) => {
209
228
  try {
@@ -220,6 +239,7 @@ async function buildRuntimeContext(options, daemonLock) {
220
239
  /** What every runner of a channel shares: the desk's managers, settings and how the channel is named and answered. */
221
240
  const runnerPaths = (conversation, channelId) => ({
222
241
  fileStore,
242
+ executor,
223
243
  jobManager: jobs.get(conversation.desk),
224
244
  runManager: runs.get(conversation.desk),
225
245
  appHomeDir,
@@ -253,13 +273,21 @@ async function buildRuntimeContext(options, daemonLock) {
253
273
  return undefined;
254
274
  const { conversation } = resolution;
255
275
  const existing = channelRunners.get(channelId);
256
- if (existing && existing.conversation.desk === conversation.desk) {
257
- // Re-insert to move this channel to the end (most-recently-used) of the Map's
258
- // iteration order, which evictIdleRunnersOverCap relies on.
259
- channelRunners.delete(channelId);
260
- channelRunners.set(channelId, existing);
261
- return existing;
276
+ if (existing) {
277
+ if (existing.conversation.desk === conversation.desk && existing.conversation.cwd === conversation.cwd) {
278
+ // Re-insert to move this channel to the end (most-recently-used) of the Map's
279
+ // iteration order, which evictIdleRunnersOverCap relies on.
280
+ channelRunners.delete(channelId);
281
+ channelRunners.set(channelId, existing);
282
+ return existing;
283
+ }
284
+ // Keep the in-flight runner reachable for `/stop` and steer until its turn settles; the
285
+ // next call after it finishes replaces it with one built for the updated desk/cwd.
286
+ if (existing.isBusy())
287
+ return existing;
288
+ void releaseCachedRunner(channelRunners, channelId);
262
289
  }
290
+ runtimeSettingsManager.reload();
263
291
  const runner = createRunner(conversation, { ...runnerPaths(conversation, channelId), getTaskControl });
264
292
  channelRunners.set(channelId, runner);
265
293
  void evictIdleRunnersOverCap(channelRunners);
@@ -281,6 +309,7 @@ async function buildRuntimeContext(options, daemonLock) {
281
309
  isShuttingDown,
282
310
  createRunner: (conversation) => createRunner(conversation, {
283
311
  profile: { kind: "request" },
312
+ executor,
284
313
  jobManager: jobs.get(conversation.desk),
285
314
  runManager: runs.get(conversation.desk),
286
315
  appHomeDir,
@@ -305,10 +334,13 @@ async function buildRuntimeContext(options, daemonLock) {
305
334
  ensureBinding: (channelId, desk) => deskRuntime.ensureDefaultBinding(channelId, desk),
306
335
  unbind: (channelId) => deskRuntime.unbind(channelId),
307
336
  deskPort: (channelId) => ({
308
- list: async () => buildDeskList(await listDesks(workspaceDir), deskRuntime.bindingTable(), deskRuntime.boundDesk(channelId), labelOf),
337
+ list: () => deskRuntime.listDeskItems(channelId, labelOf),
309
338
  channelIndexPath: join(workspaceDir, CHANNELS_INDEX_FILENAME),
310
- create: (name) => deskRuntime.create(name),
339
+ create: (name, cwd) => deskRuntime.create(name, cwd),
311
340
  bind: (name) => deskRuntime.bind(channelId, name),
341
+ cwd: (input) => deskRuntime.cwd(channelId, input),
342
+ archive: (name) => deskRuntime.archive(channelId, name),
343
+ unarchive: (name) => deskRuntime.unarchive(name),
312
344
  }),
313
345
  describeChannel,
314
346
  cliVersion,
@@ -388,16 +420,19 @@ async function buildRuntimeContext(options, daemonLock) {
388
420
  const taskLane = new TaskLane({
389
421
  getActiveDesks: () => deskRuntime.activeDesks(),
390
422
  getDeskDir: (desk) => getDeskDir(workspaceDir, desk),
423
+ getDeskCwd: (desk) => deskRuntime.deskCwd(desk),
391
424
  isBoundTo,
425
+ onDeskIdle: (desk) => void deskRuntime.reconcileActivity(desk),
392
426
  isReachable: (channelId) => transports.isReachable(channelId),
393
- // One runner per executing task, built from the task's own report channel (spec 064, D13).
427
+ // One runner per executing task, built from its desk's conversation record even when the
428
+ // report channel is currently bound to another desk (Direction 1.2).
394
429
  createTaskRunner: (target) => {
395
- const resolution = deskRuntime.resolve(target.channelId);
396
- if (resolution.kind !== "bound" || resolution.conversation.desk !== target.desk) {
397
- throw new Error(`Task ${target.taskId}: report channel ${target.channelId} is not bound to desk ${target.desk}`);
430
+ const conversation = deskRuntime.taskConversation(target.desk, target.channelId);
431
+ if (!conversation) {
432
+ throw new Error(`Task ${target.taskId}: desk ${target.desk} is unavailable for channel ${target.channelId}`);
398
433
  }
399
- return createRunner(resolution.conversation, {
400
- ...runnerPaths(resolution.conversation, target.channelId),
434
+ return createRunner(conversation, {
435
+ ...runnerPaths(conversation, target.channelId),
401
436
  profile: {
402
437
  kind: "task",
403
438
  sessionPath: taskSessionPath(target.deskDir, target.taskId),
@@ -434,7 +469,9 @@ async function buildRuntimeContext(options, daemonLock) {
434
469
  // gets a lightweight disk-backed context instead of resurrecting a full runner.
435
470
  getRuntimeContext: async (conversation) => {
436
471
  const runner = channelRunners.get(conversation.channelId);
437
- if (runner && runner.conversation.desk === conversation.desk) {
472
+ if (runner &&
473
+ runner.conversation.desk === conversation.desk &&
474
+ runner.conversation.cwd === conversation.cwd) {
438
475
  return runner.getMemoryMaintenanceContext();
439
476
  }
440
477
  return loadDetachedMaintenanceContext({
@@ -465,6 +502,7 @@ async function buildRuntimeContext(options, daemonLock) {
465
502
  channelIndex,
466
503
  channelRunners,
467
504
  activeTasks,
505
+ flushCredentials: () => flushModelCredentials(options.paths.authConfigPath),
468
506
  markShuttingDown: () => {
469
507
  shuttingDown = true;
470
508
  },
@@ -509,11 +547,33 @@ export async function bootstrap(argv, options = {}) {
509
547
  parseArgs(argv, paths, io);
510
548
  const bootstrapResult = bootstrapAppHome(paths);
511
549
  printBootstrapSummary(bootstrapResult, io, paths);
512
- // A freshly written template is the expected first-run outcome, not a failure: guide and exit 0.
513
- // A template that exists but is still unfilled is caught by the transport loader (`loadTransports`) and exits 1.
514
- if (bootstrapResult.channelTemplateCreated) {
515
- printFirstRunGuide(io, paths);
516
- throw new BootstrapExitError(0);
550
+ let daemonLock;
551
+ try {
552
+ daemonLock = await acquireDaemonLock(paths.appHomeDir);
553
+ }
554
+ catch (error) {
555
+ if (!(error instanceof StartupRefusal))
556
+ throw error;
557
+ io.error(error.message);
558
+ throw new BootstrapExitError(1);
559
+ }
560
+ let readiness;
561
+ if (startServices || options.interactive !== undefined) {
562
+ const interactive = options.interactive ??
563
+ (startServices && options.io === undefined && process.stdin.isTTY === true && process.stderr.isTTY === true);
564
+ try {
565
+ readiness = await ensureModelOnboarding({
566
+ paths,
567
+ io,
568
+ interactive,
569
+ confirmLogin: options.confirmModelLogin,
570
+ performLogin: options.performModelLogin,
571
+ });
572
+ }
573
+ catch (error) {
574
+ await daemonLock.release();
575
+ throw error;
576
+ }
517
577
  }
518
578
  const { settingsManager } = prepareAppServices(paths);
519
579
  log.logStartup(paths.workspaceDir);
@@ -521,6 +581,7 @@ export async function bootstrap(argv, options = {}) {
521
581
  try {
522
582
  runtime = await createRuntimeContext({
523
583
  paths,
584
+ daemonLock,
524
585
  ...(options.transports ? { transports: options.transports } : {}),
525
586
  registerSignalHandlers,
526
587
  startServices,
@@ -533,6 +594,9 @@ export async function bootstrap(argv, options = {}) {
533
594
  io.error(error.message);
534
595
  throw new BootstrapExitError(1);
535
596
  }
597
+ if (startServices) {
598
+ printStartupReadySummary(io, paths, runtime.transports.all().map((transport) => transport.name), readiness);
599
+ }
536
600
  return {
537
601
  store: runtime.store,
538
602
  shutdown: async () => {
@@ -15,8 +15,8 @@ export async function tryAcquireDaemonLock(appHomeDir) {
15
15
  return {
16
16
  kind: "held",
17
17
  holder: result.heldBy
18
- ? `pid ${result.heldBy.pid} on ${result.heldBy.hostname} since ${result.heldBy.acquiredAt}`
19
- : "another process",
18
+ ? `pid ${result.heldBy.pid}(主机 ${result.heldBy.hostname},启动于 ${result.heldBy.acquiredAt})`
19
+ : "另一个进程",
20
20
  };
21
21
  }
22
22
  /** Take the lock, or refuse to start and say who holds it. */
@@ -24,5 +24,5 @@ export async function acquireDaemonLock(appHomeDir) {
24
24
  const result = await tryAcquireDaemonLock(appHomeDir);
25
25
  if (result.kind === "acquired")
26
26
  return result.handle;
27
- throw new StartupRefusal(`Another Pipiclaw runtime is already using ${appHomeDir} (${result.holder}). Stop it first; if no Pipiclaw process is running, delete ${lockPath(appHomeDir)}.`);
27
+ throw new StartupRefusal(`目录 ${appHomeDir} 已被另一个 Pipiclaw 进程占用(${result.holder})。\n如需与正在运行的服务对话,请直接执行 \`pipiclaw tui\`;如需重启服务,请先停止原进程(若确认无进程运行,可删除锁文件 ${lockPath(appHomeDir)})。`);
28
28
  }
@@ -1,5 +1,5 @@
1
- import type { BindOutcome } from "../desk/commands.js";
2
- import type { BindingsFile, ConversationKind, CreateDeskOutcome, DeskConversation } from "../desk/types.js";
1
+ import { type BindOutcome, type DeskListItem } from "../desk/commands.js";
2
+ import type { ArchiveDeskOutcome, BindingsFile, ConversationKind, CreateDeskOutcome, DeskConversation, DeskCwdOutcome, UnarchiveDeskOutcome } from "../desk/types.js";
3
3
  export type ChannelResolution = {
4
4
  kind: "bound";
5
5
  conversation: DeskConversation;
@@ -41,11 +41,19 @@ export interface DeskRuntimeOptions {
41
41
  createWatcher: (target: {
42
42
  desk: string;
43
43
  deskDir: string;
44
+ cwd: string;
44
45
  }) => DeskWatcher;
45
46
  /** The transport's plain send, for background notices that pass the binding guard. */
46
47
  send: (channelId: string, text: string) => Promise<boolean>;
47
48
  /** Whether the channel has a turn in flight; `/desk bind` refuses then (D5 step 1). */
48
49
  isChannelBusy: (channelId: string) => boolean;
50
+ /**
51
+ * Optional check for active execution in `desk` (e.g. a running task step or checkout lease on
52
+ * `currentCwd`); returns a short Chinese reason to refuse mutating `cwd` or archiving mid-flight.
53
+ */
54
+ isDeskBusy?: (desk: string, currentCwd: string) => string | undefined;
55
+ /** Human-readable channel label for `/desk` messages. */
56
+ describeChannel?: (channelId: string) => string;
49
57
  /**
50
58
  * Drop the channel's cached runner and dispose it — its final reflect lands in the desk it was
51
59
  * bound to (D5 step 5). Called only after the new binding is on disk.
@@ -53,12 +61,15 @@ export interface DeskRuntimeOptions {
53
61
  releaseRunner: (channelId: string) => Promise<void>;
54
62
  /** A binding changed (the channel index rewrites its desk column). */
55
63
  onBindingChanged?: (channelId: string) => void;
64
+ /** A desk was activated or gained a bound channel (wakes the task lane to drain held deliveries). */
65
+ onActivated?: (desk: string) => void;
56
66
  }
57
67
  export declare class DeskRuntime {
58
68
  private readonly options;
59
69
  private bindings;
60
- /** Every desk a binding points at, as last read from disk. */
70
+ /** Every desk a binding or scan has touched, kept fresh when `desk.json`'s stamp changes. */
61
71
  private readonly records;
72
+ private readonly recordStamps;
62
73
  private readonly active;
63
74
  private readonly watchers;
64
75
  /** Activation and dormancy of one desk run in order, so interleaved calls settle on the last one. */
@@ -74,7 +85,16 @@ export declare class DeskRuntime {
74
85
  */
75
86
  load(): Promise<void>;
76
87
  private refreshRecord;
88
+ private syncRecordIfChanged;
77
89
  resolve(channelId: string): ChannelResolution;
90
+ /** Effective working directory of `desk`, independent of whether any channel is currently bound to it. */
91
+ deskCwd(desk: string): string | undefined;
92
+ /**
93
+ * Build the `DeskConversation` a task runner in `desk` needs for `channelId`, even after
94
+ * `channelId` has rebound to another desk (Direction 1.2: background task execution is decoupled
95
+ * from current chat binding; `desk.json` retains the registered conversation record).
96
+ */
97
+ taskConversation(desk: string, channelId: string): DeskConversation | undefined;
78
98
  /** The producer- and admission-side check of INV-5: is this channel bound to this (available) desk? */
79
99
  isBoundTo(channelId: string, desk: string): boolean;
80
100
  /** The whole binding table, for `/desk list`. A copy: callers cannot change bindings through it. */
@@ -90,7 +110,7 @@ export declare class DeskRuntime {
90
110
  /** The channel a conversation directory of this desk belongs to (for `session_search` labels). */
91
111
  channelOfConversation(desk: string, conversation: string): string | undefined;
92
112
  private boundChannelsOf;
93
- /** Startup: activate every desk that has at least one binding. */
113
+ /** Startup: activate every non-archived desk that has a binding or retained background work. */
94
114
  activateBound(): Promise<void>;
95
115
  /**
96
116
  * D6 activation: repair the desk's bound conversations, then mark it active (the task driver and
@@ -99,10 +119,23 @@ export declare class DeskRuntime {
99
119
  activate(desk: string): Promise<void>;
100
120
  /** D6 dormancy: stop the watcher and leave the background scans. Running runs and jobs are untouched. */
101
121
  deactivate(desk: string): Promise<void>;
122
+ /** Put an unbound desk to sleep once its last runnable task and task-spawning event are gone. */
123
+ reconcileActivity(desk: string): Promise<void>;
102
124
  private startWatcher;
103
125
  private stopWatcher;
104
126
  /** `/desk new`: an empty desk, bound to nothing and therefore dormant (D5). */
105
- create(name: string): Promise<CreateDeskOutcome>;
127
+ create(name: string, cwd?: string): Promise<CreateDeskOutcome>;
128
+ /** `/desk list` rows enriched with live background task and pending-delivery counts. */
129
+ listDeskItems(askingChannelId: string, labelOf: (channelId: string) => string): Promise<DeskListItem[]>;
130
+ /** `/desk cwd`: view or update the working directory of `channelId`'s bound desk. */
131
+ cwd(channelId: string, input: {
132
+ cwd?: string;
133
+ reset?: boolean;
134
+ }): Promise<DeskCwdOutcome>;
135
+ /** `/desk archive <name>`: retire an idle desk, unbinding stale terminal sessions and stopping events. */
136
+ archive(askingChannelId: string | undefined, name: string): Promise<ArchiveDeskOutcome>;
137
+ /** `/desk unarchive <name>`: clear `archivedAt` and re-activate if work is waiting. */
138
+ unarchive(name: string): Promise<UnarchiveDeskOutcome>;
106
139
  /** `/desk bind` from `channelId`, in D5's order. Throws only when the bindings write itself fails. */
107
140
  bind(channelId: string, name: string): Promise<BindOutcome>;
108
141
  /**
@@ -113,8 +146,8 @@ export declare class DeskRuntime {
113
146
  private bindNow;
114
147
  /**
115
148
  * The channel is gone for good (a Web API conversation was deleted): drop its binding, its
116
- * runner, and — when it was the desk's last channel — the desk's activity. Its conversation
117
- * directory stays in the desk as history. Whether there was a binding to drop.
149
+ * runner, and — when it was the desk's last channel and no background work remains — the desk's
150
+ * activity. Its conversation directory stays in the desk as history. Whether there was a binding to drop.
118
151
  */
119
152
  unbind(channelId: string): Promise<boolean>;
120
153
  /** Start the event watchers of every active desk; later activations start theirs directly. */