pi-background 0.2.0 → 0.2.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.
- package/extensions/background.ts +14 -2
- package/package.json +1 -1
package/extensions/background.ts
CHANGED
|
@@ -45,6 +45,14 @@ function summary(job: Job): string {
|
|
|
45
45
|
return `${job.id} [${state}, ${elapsed(job)}] ${job.command}\n log: ${job.log}`;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
/** The part of a command worth showing: its first line, without a leading cd and with a script path shortened to its name. */
|
|
49
|
+
function shownCommand(command: string): string {
|
|
50
|
+
return command
|
|
51
|
+
.split("\n")[0]
|
|
52
|
+
.replace(/^\s*(cd\s+("[^"]*"|'[^']*'|\S+)\s*(&&|;)\s*)+/, "")
|
|
53
|
+
.replace(/^\S*\/(?=[^\s/]+(\s|$))/, "");
|
|
54
|
+
}
|
|
55
|
+
|
|
48
56
|
/** True when a command starts a job with a bare & (not &&, 2>&1, &> or |&). */
|
|
49
57
|
function startsBackgroundJob(command: string): boolean {
|
|
50
58
|
return /&/.test(command.replace(/&&|[0-9]*>&[0-9-]*|&>>?|\|&/g, ""));
|
|
@@ -120,10 +128,10 @@ export default function (pi: ExtensionAPI) {
|
|
|
120
128
|
render(width: number) {
|
|
121
129
|
const live = running();
|
|
122
130
|
const lines = live.slice(0, MAX_SHOWN_JOBS).map((job) => {
|
|
123
|
-
const command = job.command
|
|
131
|
+
const command = shownCommand(job.command);
|
|
124
132
|
const text =
|
|
125
133
|
theme.fg("accent", " ⏵ ") +
|
|
126
|
-
theme.fg("toolTitle", `${job.id} ${command.length >
|
|
134
|
+
theme.fg("toolTitle", `${job.id} ${command.length > 50 ? `${command.slice(0, 49)}…` : command}`) +
|
|
127
135
|
theme.fg("dim", ` · ${elapsed(job)}${jobsLine() === "full" && job.lastLine ? ` · ${job.lastLine}` : ""}`);
|
|
128
136
|
return truncateToWidth(text, width);
|
|
129
137
|
});
|
|
@@ -173,11 +181,15 @@ export default function (pi: ExtensionAPI) {
|
|
|
173
181
|
"After bg_run, continue with independent work or end your turn; a message with the exit code and log tail arrives automatically when the job exits, so never sleep, poll or tail the log to wait for it.",
|
|
174
182
|
"Keep using bash for quick commands whose output you need right away, such as git, ls, cat, grep, find, file inspection and short checks.",
|
|
175
183
|
"To react when a bg_run job prints something specific while it keeps running (a server is ready, an epoch finished, an error appeared), pass wake_on with a regex instead of polling.",
|
|
184
|
+
"Don't redirect a bg_run command's output to a file (> file, 2>&1, nohup): bg_run already saves all of it to the job's log, and redirecting hides the job's progress from the user and from wake_on. If the output should be kept, tell the user where the job's log is.",
|
|
185
|
+
"bg_run starts only after the other tool calls in the same reply have finished, so editing a file and starting a job that uses it in one reply is safe.",
|
|
176
186
|
"Use bg_status to check progress of a bg_run job and bg_kill to stop one.",
|
|
177
187
|
`bash commands time out after ${BASH_DEFAULT_TIMEOUT / 60} minutes unless you pass timeout (at most ${BASH_MAX_TIMEOUT / 60} minutes); run anything that may take longer with bg_run instead.`,
|
|
178
188
|
"Unless the user explicitly asks for that bash command, never wait, poll or sleep in bash (while/until loops with sleep, watch, repeated status checks), not even as part of a larger command; start the wait with bg_run and pass wake_on to be woken when the awaited output appears.",
|
|
179
189
|
"Unless the user explicitly asks otherwise, start long-running processes (training or evaluation runs, servers, watchers) with bg_run, not with & or nohup in bash followed by sleep; pass wake_on matching the lines you want to see, such as results or Traceback.",
|
|
180
190
|
],
|
|
191
|
+
// Runs after the edits in the same reply, so the job starts from the code pi just wrote
|
|
192
|
+
executionMode: "sequential",
|
|
181
193
|
renderShell: "self",
|
|
182
194
|
renderCall: (args: any, theme, context) => row(theme, `Background $ ${String(args?.command ?? "").split("\n")[0]}`, context),
|
|
183
195
|
renderResult: (result, { expanded }, theme) => note(theme, result, expanded),
|