pacework 1.7.15 → 1.7.16
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/bin/pacework-runner-ctl.mjs +22 -1319
- package/lib/home.mjs +19 -3
- package/lib/shell-commands.mjs +6 -1
- package/lib/shell-handlers.mjs +1413 -0
- package/package.json +1 -1
package/lib/home.mjs
CHANGED
|
@@ -81,6 +81,15 @@ function runCtlInteractive(ctlScript, args) {
|
|
|
81
81
|
})
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
/** Command output without the blank lines the shell puts around it. */
|
|
85
|
+
export function trimBlankEdges(lines) {
|
|
86
|
+
const start = lines.findIndex((line) => line.trim())
|
|
87
|
+
if (start < 0) return []
|
|
88
|
+
let end = lines.length
|
|
89
|
+
while (!lines[end - 1].trim()) end -= 1
|
|
90
|
+
return lines.slice(start, end)
|
|
91
|
+
}
|
|
92
|
+
|
|
84
93
|
function lastLine(text) {
|
|
85
94
|
return String(text ?? "").split("\n").map((line) => line.trim()).filter(Boolean).pop() ?? ""
|
|
86
95
|
}
|
|
@@ -102,7 +111,12 @@ function jobLine(job, width) {
|
|
|
102
111
|
return ` ${mark} ${id} ${title} ${style.gray(tail)}`
|
|
103
112
|
}
|
|
104
113
|
|
|
105
|
-
|
|
114
|
+
/**
|
|
115
|
+
* runCommand(input) runs a prompt command in this process with the shell's own
|
|
116
|
+
* handlers and resolves to `{ ok, lines }`. Without it (older callers), the
|
|
117
|
+
* command runs as `pacework shell --command` in a child process.
|
|
118
|
+
*/
|
|
119
|
+
export async function runHome({ ctlScript, version, runCommand }) {
|
|
106
120
|
const stdin = process.stdin
|
|
107
121
|
const stdout = process.stdout
|
|
108
122
|
let mode = "home"
|
|
@@ -300,8 +314,10 @@ export async function runHome({ ctlScript, version }) {
|
|
|
300
314
|
const invocation = ["shell", "--command", input]
|
|
301
315
|
if (commandTakesTerminal(command, args)) return suspend(() => runCtlInteractive(ctlScript, invocation))
|
|
302
316
|
return withBusy(`Running /${command}`, async () => {
|
|
303
|
-
const result =
|
|
304
|
-
|
|
317
|
+
const result = runCommand
|
|
318
|
+
? await runCommand(input)
|
|
319
|
+
: await runCtl(ctlScript, invocation).then(({ ok, output }) => ({ ok, lines: output.split("\n") }))
|
|
320
|
+
const output = trimBlankEdges(result.lines)
|
|
305
321
|
if (output.length > 3) {
|
|
306
322
|
resultView = { command: `/${command}`, lines: output, offset: 0 }
|
|
307
323
|
mode = "result"
|
package/lib/shell-commands.mjs
CHANGED
|
@@ -70,8 +70,13 @@ export function closestShellCommand(input) {
|
|
|
70
70
|
return distance <= 2 ? best : null
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Commands the main screen hands the terminal to: they stream, ask questions
|
|
75
|
+
* on stdin (the agent picker of /run, the login prompt), or start a process
|
|
76
|
+
* that prints straight to the terminal (start, restart).
|
|
77
|
+
*/
|
|
73
78
|
export function commandTakesTerminal(command, args) {
|
|
74
|
-
return ["login", "connect", "tail", "watch", "logtail", "update"].includes(command)
|
|
79
|
+
return ["login", "connect", "tail", "watch", "logtail", "update", "run", "start", "restart"].includes(command)
|
|
75
80
|
|| (command === "mcp" && args[0] === "install")
|
|
76
81
|
}
|
|
77
82
|
|