@aliou/pi-processes 0.9.4 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/CONTRIBUTING.md +40 -42
  2. package/README.md +54 -84
  3. package/extensions/process-tabs.ts +26 -0
  4. package/extensions/processes/client.ts +194 -0
  5. package/extensions/processes/commands/clear.ts +29 -0
  6. package/extensions/processes/commands/kill.ts +152 -0
  7. package/extensions/processes/commands/overview.ts +102 -0
  8. package/extensions/processes/components/overview-component.ts +729 -0
  9. package/extensions/processes/components/overview-panel.ts +177 -0
  10. package/extensions/processes/config/defaults.ts +28 -0
  11. package/extensions/processes/config/index.ts +13 -0
  12. package/extensions/processes/config/loader.ts +62 -0
  13. package/extensions/processes/config/migrations/000-import-legacy-process-config.ts +113 -0
  14. package/extensions/processes/config/migrations/001-v0-9-4-to-v0-10-0-config.ts +184 -0
  15. package/extensions/processes/config/migrations/002-stamp-v0-10-0-config-version.ts +21 -0
  16. package/extensions/processes/config/migrations/index.ts +25 -0
  17. package/extensions/processes/config/schema.ts +9 -0
  18. package/extensions/processes/config/types.ts +72 -0
  19. package/extensions/processes/constants.ts +1 -0
  20. package/extensions/processes/handlers/commands.ts +113 -0
  21. package/extensions/processes/handlers/kill-process.ts +31 -0
  22. package/extensions/processes/handlers/notifications.ts +147 -0
  23. package/extensions/processes/handlers/requests.ts +114 -0
  24. package/extensions/processes/handlers/subscriptions.ts +144 -0
  25. package/extensions/processes/hooks/background-blocker.ts +201 -0
  26. package/extensions/processes/hooks/cleanup.ts +43 -0
  27. package/extensions/processes/hooks/event-bridge.ts +32 -0
  28. package/extensions/processes/i18n/index.ts +3 -0
  29. package/extensions/processes/i18n/messages.ts +27 -0
  30. package/extensions/processes/i18n/translator.ts +49 -0
  31. package/extensions/processes/index.ts +109 -0
  32. package/extensions/processes/message-renderer.ts +117 -0
  33. package/extensions/processes/notification-sender.ts +43 -0
  34. package/extensions/processes/notifications/classify.ts +27 -0
  35. package/extensions/processes/notifications/log-matchers.ts +146 -0
  36. package/extensions/processes/notifications/registry.ts +225 -0
  37. package/extensions/processes/notifications/render-content.ts +122 -0
  38. package/extensions/processes/notifications/service.ts +336 -0
  39. package/extensions/processes/notifications/types.ts +11 -0
  40. package/extensions/processes/settings/apply-setting-change.ts +30 -0
  41. package/extensions/processes/settings/build-sections.ts +420 -0
  42. package/extensions/processes/settings/index.ts +42 -0
  43. package/extensions/processes/tools/clear/index.ts +21 -0
  44. package/extensions/processes/tools/clear/render.ts +40 -0
  45. package/extensions/processes/tools/components/index.ts +4 -0
  46. package/extensions/processes/tools/components/process-action-header.ts +31 -0
  47. package/extensions/processes/tools/components/process-action-title.ts +17 -0
  48. package/extensions/processes/tools/components/tool-layout.ts +70 -0
  49. package/extensions/processes/tools/components/watch.ts +53 -0
  50. package/extensions/processes/tools/index.ts +265 -0
  51. package/extensions/processes/tools/list/index.ts +157 -0
  52. package/extensions/processes/tools/list/render.ts +211 -0
  53. package/extensions/processes/tools/notify.ts +191 -0
  54. package/extensions/processes/tools/output/index.ts +307 -0
  55. package/extensions/processes/tools/output/render.ts +229 -0
  56. package/extensions/processes/tools/schema.ts +263 -0
  57. package/extensions/processes/tools/start/index.ts +64 -0
  58. package/extensions/processes/tools/start/render.ts +67 -0
  59. package/extensions/processes/tools/stop/index.ts +35 -0
  60. package/extensions/processes/tools/stop/render.ts +43 -0
  61. package/extensions/processes/tools/update/index.ts +320 -0
  62. package/extensions/processes/tools/update/render.ts +251 -0
  63. package/extensions/processes/tools/utils.ts +112 -0
  64. package/extensions/processes/tools/watch-format.ts +14 -0
  65. package/extensions/processes/tools/write/index.ts +75 -0
  66. package/extensions/processes/tools/write/render.ts +68 -0
  67. package/extensions/processes/utils/truncate.ts +285 -0
  68. package/extensions/processes-dock/client.ts +60 -0
  69. package/extensions/processes-dock/commands/dock.ts +70 -0
  70. package/extensions/processes-dock/commands/pin.ts +166 -0
  71. package/extensions/processes-dock/components/log-dock-component.ts +375 -0
  72. package/extensions/processes-dock/dock-state.ts +33 -0
  73. package/extensions/processes-dock/index.ts +28 -0
  74. package/extensions/processes-dock/logs-client.ts +5 -0
  75. package/extensions/processes-dock/widget/setup.ts +520 -0
  76. package/extensions/processes-dock/widget/status.ts +149 -0
  77. package/extensions/processes-dock/widget/types.ts +16 -0
  78. package/extensions/processes-logs/client.ts +51 -0
  79. package/extensions/processes-logs/commands/logs.ts +108 -0
  80. package/extensions/processes-logs/completions.ts +31 -0
  81. package/extensions/processes-logs/components/log-file-viewer.ts +274 -0
  82. package/extensions/processes-logs/components/log-overlay-component.ts +685 -0
  83. package/extensions/processes-logs/index.ts +27 -0
  84. package/extensions/processes-logs/logs-client.ts +101 -0
  85. package/extensions/shared/line-buffer.ts +35 -0
  86. package/extensions/shared/output-payload.ts +28 -0
  87. package/extensions/shared/ui.ts +146 -0
  88. package/package.json +47 -20
  89. package/schema.json +134 -0
  90. package/skills/pi-processes/SKILL.md +496 -25
  91. package/src/get-manager.ts +15 -0
  92. package/src/manager/index.ts +182 -0
  93. package/src/manager/internal-types.ts +130 -0
  94. package/src/manager/limits.ts +15 -0
  95. package/src/manager/process-log-store.ts +422 -0
  96. package/src/manager/process-output.ts +345 -0
  97. package/src/manager/process-registry.ts +78 -0
  98. package/src/manager/process-runtime-controller.ts +499 -0
  99. package/src/protocol/broadcasts.ts +14 -0
  100. package/src/protocol/channels.ts +30 -0
  101. package/src/protocol/commands.ts +24 -0
  102. package/src/protocol/index.ts +34 -0
  103. package/src/protocol/logs.ts +23 -0
  104. package/src/protocol/notifications.ts +48 -0
  105. package/src/protocol/requests.ts +76 -0
  106. package/src/types.ts +66 -0
  107. package/src/utils/ansi.ts +2 -4
  108. package/src/utils/format.ts +24 -32
  109. package/src/utils/index.ts +5 -1
  110. package/src/utils/is-record.ts +3 -0
  111. package/src/utils/match-line.ts +32 -0
  112. package/src/utils/platform.ts +13 -0
  113. package/src/utils/shorten-path.ts +11 -0
  114. package/src/utils/signals.ts +22 -0
  115. package/src/commands/clear/command.ts +0 -14
  116. package/src/commands/clear/index.ts +0 -1
  117. package/src/commands/completions.ts +0 -38
  118. package/src/commands/dock/command.ts +0 -29
  119. package/src/commands/dock/index.ts +0 -1
  120. package/src/commands/index.ts +0 -33
  121. package/src/commands/kill/command.ts +0 -69
  122. package/src/commands/kill/index.ts +0 -1
  123. package/src/commands/logs/command.ts +0 -47
  124. package/src/commands/logs/index.ts +0 -1
  125. package/src/commands/pick-process.ts +0 -34
  126. package/src/commands/pin/command.ts +0 -34
  127. package/src/commands/pin/index.ts +0 -1
  128. package/src/commands/processes/command.ts +0 -39
  129. package/src/commands/processes/index.ts +0 -1
  130. package/src/commands/settings/apply-setting-change.ts +0 -72
  131. package/src/commands/settings/build-sections.ts +0 -160
  132. package/src/commands/settings/command.ts +0 -20
  133. package/src/commands/settings/index.ts +0 -1
  134. package/src/components/log-dock-component.test.ts +0 -29
  135. package/src/components/log-dock-component.ts +0 -236
  136. package/src/components/log-file-viewer.ts +0 -317
  137. package/src/components/log-overlay-component.ts +0 -546
  138. package/src/components/panel-helpers.ts +0 -37
  139. package/src/components/process-picker-component.ts +0 -166
  140. package/src/components/processes-component.ts +0 -485
  141. package/src/components/status-format.ts +0 -38
  142. package/src/config.ts +0 -107
  143. package/src/constants/index.ts +0 -16
  144. package/src/constants/types.ts +0 -106
  145. package/src/hooks/background-blocker.ts +0 -66
  146. package/src/hooks/cleanup.ts +0 -10
  147. package/src/hooks/index.ts +0 -32
  148. package/src/hooks/message-renderer.ts +0 -115
  149. package/src/hooks/process-end.ts +0 -69
  150. package/src/hooks/process-watch.ts +0 -85
  151. package/src/hooks/utils.ts +0 -23
  152. package/src/hooks/widget/index.ts +0 -2
  153. package/src/hooks/widget/setup.ts +0 -167
  154. package/src/hooks/widget/status-widget.ts +0 -105
  155. package/src/hooks/widget/types.ts +0 -20
  156. package/src/index.ts +0 -35
  157. package/src/manager.test.ts +0 -331
  158. package/src/manager.ts +0 -758
  159. package/src/tools/actions/clear.ts +0 -20
  160. package/src/tools/actions/debug.ts +0 -148
  161. package/src/tools/actions/index.ts +0 -171
  162. package/src/tools/actions/kill.ts +0 -89
  163. package/src/tools/actions/list.ts +0 -188
  164. package/src/tools/actions/logs.ts +0 -117
  165. package/src/tools/actions/output.ts +0 -269
  166. package/src/tools/actions/start.ts +0 -245
  167. package/src/tools/actions/write.ts +0 -113
  168. package/src/tools/index.ts +0 -207
  169. package/src/utils/ansi.test.ts +0 -22
  170. package/src/utils/command-executor.test.ts +0 -48
  171. package/src/utils/keybindings.ts +0 -71
@@ -1,39 +1,510 @@
1
1
  ---
2
2
  name: pi-processes
3
- description: Manage long-running commands in the background with the process tool. Use when a task needs a dev server, test watcher, build watcher, local API, or log tail to keep running while the conversation continues.
3
+ description: Manage long-running commands with the process tool. Use when a task needs a dev server, watcher, build, test watcher, local API, log tail, or other command to keep running while the conversation continues.
4
4
  ---
5
5
 
6
6
  # pi-processes
7
7
 
8
- Use this skill when work needs a long-running command to stay alive while Pi continues with other steps.
8
+ Use the `process` tool for commands that should keep running while the agent continues working. Do not use shell background patterns such as `&`, `nohup`, `disown`, or `setsid` when `process` fits.
9
9
 
10
- ## Prefer this workflow
10
+ ## The core loop: start, do not wait, get notified
11
11
 
12
- - Use the `process` tool for long-running commands.
13
- - Avoid shell background patterns when the process tool fits.
14
- - Give processes stable, clear names.
15
- - Continue the task after starting a process instead of waiting on it.
16
- - Inspect output or log files only when needed.
17
- - Kill and clear processes when they are no longer useful.
12
+ A started process runs in the background and the manager brings you back when something happens. You do not need to sleep, poll, or hold your turn for a process to finish.
18
13
 
19
- ## Good fits
14
+ 1. `process start` a long-running command, with `notify.logMatches` for the signals you care about.
15
+ 2. End your turn or move on to other work. Do not call `process output` in a loop waiting for "ready".
16
+ 3. The process notifies you when:
17
+ - a `logMatches` pattern hits (readiness, error, progress),
18
+ - the process exits successfully (`onSuccess`, default `context`),
19
+ - the process fails or crashes (`onFailure`, default `turn`),
20
+ - the process is killed, by you or externally (`onKilled`, default `context`).
21
+ 4. When a watch is too noisy or wrong, fix it with `process update` — do not restart the process just to change watches.
22
+ 5. `process stop` obsolete live processes and `process clear` finished entries when they are no longer useful.
20
23
 
21
- - `pnpm dev`
22
- - `npm run server`
23
- - `pnpm test --watch`
24
- - `tail -f <logfile>`
25
- - local preview or build watchers
24
+ The only reason to wait after `process start` is when the next step literally cannot proceed until the process is ready, and even then prefer a `logMatches` watch over polling.
26
25
 
27
- ## Typical flow
26
+ ## Actions
28
27
 
29
- 1. Start the long-running command with a clear name.
30
- 2. Continue the main task.
31
- 3. Inspect `output` or `logs` if something needs attention.
32
- 4. Use alert flags when success or failure should trigger a follow-up turn.
33
- 5. Kill and clear the process when done.
28
+ ### `process start`
34
29
 
35
- ## Notes
30
+ Starts a managed process.
36
31
 
37
- - Users can inspect and manage running processes from `/ps`.
38
- - Use `write` when a process expects stdin input.
39
- - Use `output` for a quick tail and `logs` when the full log files are more useful.
32
+ Use it for dev servers, test watchers, build watchers, long-running log tails, local APIs, and other commands that should continue while the conversation moves on.
33
+
34
+ Good:
35
+
36
+ ```json
37
+ {
38
+ "action": "start",
39
+ "name": "web-dev",
40
+ "command": "pnpm dev",
41
+ "cwd": "/path/to/project",
42
+ "notify": {
43
+ "onSuccess": "context",
44
+ "onFailure": "turn",
45
+ "logMatches": [
46
+ { "pattern": "ready", "mode": "literal", "stream": "both" },
47
+ { "pattern": "EADDRINUSE", "mode": "literal", "stream": "stderr", "on": "turn" }
48
+ ]
49
+ }
50
+ }
51
+ ```
52
+
53
+ Optional `cwd` sets the working directory for the spawned command. Omit it to inherit the agent's current working directory.
54
+
55
+ Empty `logMatches` patterns (literal or regex) are rejected at start and update time. Use `mode: "regex"` only when literal matching is not enough, scope by `stream` to cut noise, and use `repeat: true` when a matcher should fire more than once.
56
+
57
+ Bad:
58
+
59
+ ```bash
60
+ pnpm dev &
61
+ nohup pnpm dev >/tmp/dev.log 2>&1 &
62
+ ```
63
+
64
+ ### `process list`
65
+
66
+ Shows managed processes and log file paths.
67
+
68
+ Use it before `process start` when a duplicate process would be harmful or noisy. Do not repeat the visible process table back to the user unless you need to explain a decision.
69
+
70
+ Optional filters:
71
+
72
+ - `statuses`: `all`, `running`, `finished`, `failed`, `terminating`, `terminate_timeout`, `killed`
73
+ - `sortBy`: `startTime_desc`, `startTime_asc`, `name_asc`, `name_desc`, `status_asc`
74
+ - `limit`: maximum number of processes to return
75
+
76
+ Good:
77
+
78
+ ```json
79
+ { "action": "list", "statuses": ["running"] }
80
+ ```
81
+
82
+ ```json
83
+ { "action": "list", "statuses": ["failed", "killed"], "sortBy": "startTime_desc", "limit": 10 }
84
+ ```
85
+
86
+ Bad:
87
+
88
+ ```text
89
+ Starting another dev server without checking whether one is already running.
90
+ ```
91
+
92
+ ### `process output`
93
+
94
+ Reads recent stdout/stderr from one process.
95
+
96
+ Use it for targeted checks, especially with `pattern` and `mode`. Do not use it as a polling loop. Do not use it for deep log inspection; use `read` on the stdout/stderr file paths instead.
97
+
98
+ Good:
99
+
100
+ ```json
101
+ {
102
+ "action": "output",
103
+ "id": "proc_1",
104
+ "stream": "stderr",
105
+ "pattern": "EADDRINUSE",
106
+ "mode": "literal"
107
+ }
108
+ ```
109
+
110
+ Bad:
111
+
112
+ ```text
113
+ Calling process output every few seconds waiting for "ready".
114
+ ```
115
+
116
+ Use watches instead:
117
+
118
+ ```json
119
+ {
120
+ "action": "update",
121
+ "id": "proc_1",
122
+ "watches": {
123
+ "mode": "append",
124
+ "items": [{ "pattern": "ready", "mode": "literal" }]
125
+ }
126
+ }
127
+ ```
128
+
129
+ ### `process update`
130
+
131
+ Renames a running process or changes its watches. Update only works while the process is running.
132
+
133
+ Use it instead of restarting a process just to add, remove, or replace watch patterns. You can change `name` and `watches` in the same call.
134
+
135
+ `watches.mode` controls how the `items` are applied:
136
+
137
+ - `append` — add the items to the existing watches.
138
+ - `replace` — replace all watches with the items.
139
+ - `remove` — remove specific watches. Identify each by `index`, or by `pattern` (index takes precedence when both are given).
140
+ - `clear` — remove all watches. `items` is ignored.
141
+
142
+ Good:
143
+
144
+ ```json
145
+ {
146
+ "action": "update",
147
+ "id": "proc_1",
148
+ "name": "api-dev",
149
+ "watches": {
150
+ "mode": "append",
151
+ "items": [
152
+ { "pattern": "Server listening", "mode": "literal" },
153
+ { "pattern": "EADDRINUSE", "mode": "literal", "stream": "stderr" }
154
+ ]
155
+ }
156
+ }
157
+ ```
158
+
159
+ Bad:
160
+
161
+ ```text
162
+ Stopping and restarting a server only to add a readiness matcher.
163
+ ```
164
+
165
+ ### `process write`
166
+
167
+ Sends bytes to a running process's stdin.
168
+
169
+ Use it to drive interactive servers, REPLs, and CLIs that expect input after they start. Pass `input` for the bytes to write, and set `end: true` to close stdin (for example to signal EOF to a waiting process).
170
+
171
+ Good:
172
+
173
+ ```json
174
+ { "action": "write", "id": "proc_1", "input": "quit\n" }
175
+ ```
176
+
177
+ ```json
178
+ { "action": "write", "id": "proc_1", "end": true }
179
+ ```
180
+
181
+ Bad:
182
+
183
+ ```text
184
+ Writing with no `input` and no `end` (a no-op). The tool rejects it.
185
+ ```
186
+
187
+ ### `process stop`
188
+
189
+ Stops a managed process.
190
+
191
+ Use it when a process is obsolete, blocking a port, or no longer needed. Intentional stops suppress normal failure noise.
192
+
193
+ Good:
194
+
195
+ ```json
196
+ { "action": "stop", "id": "proc_1" }
197
+ ```
198
+
199
+ ### `process clear`
200
+
201
+ Clears finished processes and their log storage.
202
+
203
+ Use it after stopped, failed, or completed processes are no longer useful. It never clears live processes.
204
+
205
+ Good:
206
+
207
+ ```json
208
+ { "action": "clear" }
209
+ ```
210
+
211
+ ## Notification reference
212
+
213
+ `notify` on `process start` (and watches on `process update`) control how the manager brings you back.
214
+
215
+ Exit attention:
216
+
217
+ - `notify.onSuccess` — when the process exits successfully. Defaults to `context`.
218
+ - `notify.onFailure` — when the process fails or crashes. Defaults to `turn`.
219
+ - `notify.onKilled` — when the process is killed, by you or externally. Defaults to `context`.
220
+
221
+ Log match watches (`notify.logMatches`, up to 20, each pattern up to 500 chars):
222
+
223
+ - `pattern` — required. Literal by default; regex when `mode: "regex"`. Empty patterns are rejected.
224
+ - `mode` — `literal` (default) or `regex`.
225
+ - `stream` — `stdout`, `stderr`, or `both` (default). Scope to cut noise.
226
+ - `repeat` — `false` (default) fires once; `true` fires on every match.
227
+ - `on` — `turn`, `context`, or `ignore`. Overrides the default attention for that watch. Defaults to `turn`.
228
+
229
+ `turn` interrupts with an agent message. `context` adds the notice as context without interrupting. `ignore` records the match silently.
230
+
231
+ ## Use cases
232
+
233
+ ### Dev server readiness
234
+
235
+ Start a server, get brought back when it prints its ready marker, then keep working.
236
+
237
+ ```json
238
+ {
239
+ "action": "start",
240
+ "name": "web-dev",
241
+ "command": "pnpm dev",
242
+ "notify": {
243
+ "logMatches": [{ "pattern": "ready", "stream": "stdout" }]
244
+ }
245
+ }
246
+ ```
247
+
248
+ You do not wait. End your turn; the watch fires and the manager brings you back.
249
+
250
+ ### Test watcher failures
251
+
252
+ Keep a watcher running and react only when a test fails.
253
+
254
+ ```json
255
+ {
256
+ "action": "start",
257
+ "name": "vitest-watch",
258
+ "command": "pnpm test --watch",
259
+ "notify": {
260
+ "logMatches": [
261
+ { "pattern": "FAIL", "stream": "stdout", "repeat": true, "on": "turn" },
262
+ { "pattern": "Error:", "stream": "stderr", "repeat": true, "on": "turn" }
263
+ ]
264
+ }
265
+ }
266
+ ```
267
+
268
+ ### Build errors from stderr
269
+
270
+ Watch a build watcher and surface type or compile errors as they happen.
271
+
272
+ ```json
273
+ {
274
+ "action": "start",
275
+ "name": "builder",
276
+ "command": "pnpm build --watch",
277
+ "notify": {
278
+ "logMatches": [
279
+ { "pattern": "TypeError|ReferenceError", "mode": "regex", "stream": "stderr", "repeat": true }
280
+ ]
281
+ }
282
+ }
283
+ ```
284
+
285
+ ### Repeatable progress markers
286
+
287
+ Fire on every job completion, not just the first.
288
+
289
+ ```json
290
+ {
291
+ "action": "start",
292
+ "name": "worker",
293
+ "command": "pnpm worker",
294
+ "notify": {
295
+ "logMatches": [{ "pattern": "job completed", "stream": "stdout", "repeat": true }]
296
+ }
297
+ }
298
+ ```
299
+
300
+ ### Interactive process that needs stdin
301
+
302
+ Start a process that waits for input, drive it, then close stdin.
303
+
304
+ ```json
305
+ { "action": "start", "name": "customer-import", "command": "npm run import:customer" }
306
+ ```
307
+
308
+ ```json
309
+ { "action": "write", "id": "proc_1", "input": "ALFKI\n", "end": true }
310
+ ```
311
+
312
+ The process prints its result and exits; `onFailure`/`onSuccess` brings you back.
313
+
314
+ ## When a log watch is too noisy
315
+
316
+ A watch that fires too often wastes turns. Fix it with `process update` — never restart the process just to change watches.
317
+
318
+ First, diagnose: is the pattern too broad, on the wrong stream, or repeating when it should fire once?
319
+
320
+ Then pick a `watches.mode`:
321
+
322
+ - **Tighten the pattern or scope the stream** — `replace` all watches with corrected ones.
323
+
324
+ ```json
325
+ {
326
+ "action": "update",
327
+ "id": "proc_1",
328
+ "watches": {
329
+ "mode": "replace",
330
+ "items": [{ "pattern": "EADDRINUSE", "stream": "stderr" }]
331
+ }
332
+ }
333
+ ```
334
+
335
+ - **Drop `repeat`** — if a `repeat: true` watch fires on every line, replace it with the same pattern and `repeat` omitted (defaults to `false`).
336
+
337
+ - **Remove one watch** — `remove` by `index` or `pattern`.
338
+
339
+ ```json
340
+ {
341
+ "action": "update",
342
+ "id": "proc_1",
343
+ "watches": {
344
+ "mode": "remove",
345
+ "items": [{ "pattern": "ready" }]
346
+ }
347
+ }
348
+ ```
349
+
350
+ ```json
351
+ {
352
+ "action": "update",
353
+ "id": "proc_1",
354
+ "watches": {
355
+ "mode": "remove",
356
+ "items": [{ "index": 0 }]
357
+ }
358
+ }
359
+ ```
360
+
361
+ - **Silence without removing** — set the watch's `on` to `ignore` so matches are recorded but do not interrupt.
362
+
363
+ ```json
364
+ {
365
+ "action": "update",
366
+ "id": "proc_1",
367
+ "watches": {
368
+ "mode": "replace",
369
+ "items": [{ "pattern": "job completed", "stream": "stdout", "repeat": true, "on": "ignore" }]
370
+ }
371
+ }
372
+ ```
373
+
374
+ - **Remove all watches** — `clear`.
375
+
376
+ ```json
377
+ {
378
+ "action": "update", "id": "proc_1", "watches": { "mode": "clear" } }
379
+ ```
380
+
381
+ ## Common mistakes
382
+
383
+ ### Polling output instead of setting watches
384
+
385
+ Bad:
386
+
387
+ ```text
388
+ Call process output repeatedly until the server is ready.
389
+ ```
390
+
391
+ Good:
392
+
393
+ ```json
394
+ {
395
+ "action": "start",
396
+ "name": "web-dev",
397
+ "command": "pnpm dev",
398
+ "notify": { "logMatches": [{ "pattern": "ready", "mode": "literal" }] }
399
+ }
400
+ ```
401
+
402
+ ### Waiting or sleeping after start
403
+
404
+ Bad:
405
+
406
+ ```text
407
+ Start a dev server, then sleep or hold the turn until it is ready.
408
+ ```
409
+
410
+ Good:
411
+
412
+ ```text
413
+ Start the server with a "ready" watch and end the turn. The watch brings you back.
414
+ ```
415
+
416
+ ### Restarting instead of updating watches
417
+
418
+ Bad:
419
+
420
+ ```text
421
+ Stop and restart a process because you forgot to watch for EADDRINUSE, or because a watch is too noisy.
422
+ ```
423
+
424
+ Good:
425
+
426
+ ```json
427
+ {
428
+ "action": "update",
429
+ "id": "proc_1",
430
+ "watches": {
431
+ "mode": "append",
432
+ "items": [{ "pattern": "EADDRINUSE", "stream": "stderr" }]
433
+ }
434
+ }
435
+ ```
436
+
437
+ ### Starting duplicates
438
+
439
+ Bad:
440
+
441
+ ```text
442
+ Start `pnpm dev` without checking existing process state.
443
+ ```
444
+
445
+ Good:
446
+
447
+ ```json
448
+ { "action": "list", "statuses": ["running"] }
449
+ ```
450
+
451
+ Then start only if needed.
452
+
453
+ ### Missing common failure watches
454
+
455
+ When starting servers, consider watches for readiness and common failure signals:
456
+
457
+ - `ready`
458
+ - `listening`
459
+ - `compiled`
460
+ - `EADDRINUSE`
461
+ - `Error:`
462
+ - `UnhandledPromiseRejection`
463
+
464
+ Keep watch patterns specific enough to avoid noisy false positives.
465
+
466
+ ### Re-summarizing visible tool output
467
+
468
+ Bad:
469
+
470
+ ```text
471
+ The process list shows proc_1 is running, proc_2 exited, and proc_3 failed...
472
+ ```
473
+
474
+ Good:
475
+
476
+ ```text
477
+ I'll reuse the existing `web-dev` process.
478
+ ```
479
+
480
+ ### Using vague names
481
+
482
+ Bad names:
483
+
484
+ - `server`
485
+ - `test`
486
+ - `watch`
487
+
488
+ Good names:
489
+
490
+ - `web-dev`
491
+ - `api-dev`
492
+ - `vitest-watch`
493
+ - `tail-app-logs`
494
+
495
+ ### Leaving obsolete processes running
496
+
497
+ Stop live processes that are no longer useful, especially duplicate dev servers or commands occupying ports. Clear finished entries when they are no longer needed for debugging.
498
+
499
+ ## UI commands
500
+
501
+ Users can inspect and control processes with:
502
+
503
+ - `/ps` for overview and control.
504
+ - `/ps:logs` for focused logs.
505
+ - `/ps:dock` and `/ps:pin` when the dock extension is loaded.
506
+ - `/ps:kill` to stop a running process.
507
+ - `/ps:clear` to remove finished entries.
508
+ - `/ps:settings` for package settings.
509
+
510
+ Do not ask the user to start long-running commands manually. If a process needs to run, use the `process` tool.
@@ -0,0 +1,15 @@
1
+ import { ProcessManager } from "./manager";
2
+
3
+ export interface ManagerOptions {
4
+ getConfiguredShellPath?: () => string | undefined;
5
+ }
6
+
7
+ /**
8
+ * Create a ProcessManager for the current extension instance.
9
+ * The extension owns shutdown and must call manager.killAll()/cleanup().
10
+ */
11
+ export function getManager(opts?: ManagerOptions): ProcessManager {
12
+ return new ProcessManager({
13
+ getConfiguredShellPath: opts?.getConfiguredShellPath,
14
+ });
15
+ }