shellpuppet 0.2.0 → 0.3.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.
- package/README.md +83 -18
- package/dist/agents/agy/index.d.ts +2 -0
- package/dist/agents/agy/index.js +11 -0
- package/dist/agents/agy/index.js.map +1 -0
- package/dist/agents/agy/nudge.d.ts +2 -0
- package/dist/agents/agy/nudge.js +29 -0
- package/dist/agents/agy/nudge.js.map +1 -0
- package/dist/agents/agy/reading.d.ts +2 -0
- package/dist/agents/agy/reading.js +28 -0
- package/dist/agents/agy/reading.js.map +1 -0
- package/dist/agents/barNudge.d.ts +9 -0
- package/dist/agents/barNudge.js +21 -0
- package/dist/agents/barNudge.js.map +1 -0
- package/dist/agents/claude/index.d.ts +2 -0
- package/dist/agents/claude/index.js +31 -0
- package/dist/agents/claude/index.js.map +1 -0
- package/dist/agents/claude/nudge.d.ts +2 -0
- package/dist/agents/claude/nudge.js +38 -0
- package/dist/agents/claude/nudge.js.map +1 -0
- package/dist/agents/claude/prompts.d.ts +9 -0
- package/dist/agents/claude/prompts.js +16 -0
- package/dist/agents/claude/prompts.js.map +1 -0
- package/dist/agents/claude/reading.d.ts +2 -0
- package/dist/agents/claude/reading.js +25 -0
- package/dist/agents/claude/reading.js.map +1 -0
- package/dist/agents/codex/index.d.ts +2 -0
- package/dist/agents/codex/index.js +28 -0
- package/dist/agents/codex/index.js.map +1 -0
- package/dist/agents/codex/nudge.d.ts +2 -0
- package/dist/agents/codex/nudge.js +35 -0
- package/dist/agents/codex/nudge.js.map +1 -0
- package/dist/agents/codex/prompts.d.ts +9 -0
- package/dist/agents/codex/prompts.js +14 -0
- package/dist/agents/codex/prompts.js.map +1 -0
- package/dist/agents/codex/reading.d.ts +2 -0
- package/dist/agents/codex/reading.js +22 -0
- package/dist/agents/codex/reading.js.map +1 -0
- package/dist/agents/generic/index.d.ts +3 -0
- package/dist/agents/generic/index.js +9 -0
- package/dist/agents/generic/index.js.map +1 -0
- package/dist/agents/generic/prompts.d.ts +2 -0
- package/dist/agents/generic/prompts.js +10 -0
- package/dist/agents/generic/prompts.js.map +1 -0
- package/dist/agents/grok/actionBox.d.ts +13 -0
- package/dist/agents/grok/actionBox.js +127 -0
- package/dist/agents/grok/actionBox.js.map +1 -0
- package/dist/agents/grok/index.d.ts +2 -0
- package/dist/agents/grok/index.js +20 -0
- package/dist/agents/grok/index.js.map +1 -0
- package/dist/agents/grok/nudge.d.ts +2 -0
- package/dist/agents/grok/nudge.js +76 -0
- package/dist/agents/grok/nudge.js.map +1 -0
- package/dist/agents/grok/prompts.d.ts +4 -0
- package/dist/agents/grok/prompts.js +89 -0
- package/dist/agents/grok/prompts.js.map +1 -0
- package/dist/agents/grok/reading.d.ts +2 -0
- package/dist/agents/grok/reading.js +49 -0
- package/dist/agents/grok/reading.js.map +1 -0
- package/dist/agents/grok/readingRules.d.ts +2 -0
- package/dist/agents/grok/readingRules.js +44 -0
- package/dist/agents/grok/readingRules.js.map +1 -0
- package/dist/agents/index.d.ts +28 -0
- package/dist/agents/index.js +46 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/input.d.ts +2 -0
- package/dist/agents/input.js +9 -0
- package/dist/agents/input.js.map +1 -0
- package/dist/agents/mimo/index.d.ts +2 -0
- package/dist/agents/mimo/index.js +13 -0
- package/dist/agents/mimo/index.js.map +1 -0
- package/dist/agents/mimo/nudge.d.ts +3 -0
- package/dist/agents/mimo/nudge.js +59 -0
- package/dist/agents/mimo/nudge.js.map +1 -0
- package/dist/agents/mimo/prompts.d.ts +2 -0
- package/dist/agents/mimo/prompts.js +40 -0
- package/dist/agents/mimo/prompts.js.map +1 -0
- package/dist/agents/mimo/reading.d.ts +2 -0
- package/dist/agents/mimo/reading.js +31 -0
- package/dist/agents/mimo/reading.js.map +1 -0
- package/dist/agents/mimo/readingRules.d.ts +2 -0
- package/dist/agents/mimo/readingRules.js +79 -0
- package/dist/agents/mimo/readingRules.js.map +1 -0
- package/dist/agents/mimo/stalls.d.ts +2 -0
- package/dist/agents/mimo/stalls.js +81 -0
- package/dist/agents/mimo/stalls.js.map +1 -0
- package/dist/agents/muse/index.d.ts +2 -0
- package/dist/agents/muse/index.js +20 -0
- package/dist/agents/muse/index.js.map +1 -0
- package/dist/agents/muse/input.d.ts +3 -0
- package/dist/agents/muse/input.js +7 -0
- package/dist/agents/muse/input.js.map +1 -0
- package/dist/agents/muse/nudge.d.ts +2 -0
- package/dist/agents/muse/nudge.js +33 -0
- package/dist/agents/muse/nudge.js.map +1 -0
- package/dist/agents/muse/prompts.d.ts +14 -0
- package/dist/agents/muse/prompts.js +132 -0
- package/dist/agents/muse/prompts.js.map +1 -0
- package/dist/agents/muse/reading.d.ts +2 -0
- package/dist/agents/muse/reading.js +33 -0
- package/dist/agents/muse/reading.js.map +1 -0
- package/dist/agents/muse/readingRules.d.ts +2 -0
- package/dist/agents/muse/readingRules.js +49 -0
- package/dist/agents/muse/readingRules.js.map +1 -0
- package/dist/agents/nudgeReading.d.ts +74 -0
- package/dist/agents/nudgeReading.js +262 -0
- package/dist/agents/nudgeReading.js.map +1 -0
- package/dist/agents/opencode/index.d.ts +2 -0
- package/dist/agents/opencode/index.js +21 -0
- package/dist/agents/opencode/index.js.map +1 -0
- package/dist/agents/opencode/nudge.d.ts +6 -0
- package/dist/agents/opencode/nudge.js +187 -0
- package/dist/agents/opencode/nudge.js.map +1 -0
- package/dist/agents/opencode/prompts.d.ts +6 -0
- package/dist/agents/opencode/prompts.js +198 -0
- package/dist/agents/opencode/prompts.js.map +1 -0
- package/dist/agents/opencode/reading.d.ts +2 -0
- package/dist/agents/opencode/reading.js +29 -0
- package/dist/agents/opencode/reading.js.map +1 -0
- package/dist/agents/opencode/stalls.d.ts +3 -0
- package/dist/agents/opencode/stalls.js +14 -0
- package/dist/agents/opencode/stalls.js.map +1 -0
- package/dist/agents/qoder/index.d.ts +2 -0
- package/dist/agents/qoder/index.js +12 -0
- package/dist/agents/qoder/index.js.map +1 -0
- package/dist/agents/qoder/nudge.d.ts +2 -0
- package/dist/agents/qoder/nudge.js +16 -0
- package/dist/agents/qoder/nudge.js.map +1 -0
- package/dist/agents/qoder/prompts.d.ts +2 -0
- package/dist/agents/qoder/prompts.js +6 -0
- package/dist/agents/qoder/prompts.js.map +1 -0
- package/dist/agents/qoder/reading.d.ts +2 -0
- package/dist/agents/qoder/reading.js +41 -0
- package/dist/agents/qoder/reading.js.map +1 -0
- package/dist/agents/types.d.ts +187 -0
- package/dist/agents/types.js +2 -0
- package/dist/agents/types.js.map +1 -0
- package/dist/cli/index.js +255 -33
- package/dist/cli/index.js.map +1 -1
- package/dist/client/http.d.ts +17 -3
- package/dist/client/http.js +232 -35
- package/dist/client/http.js.map +1 -1
- package/dist/core/dialogs.d.ts +2 -4
- package/dist/core/dialogs.js +6 -12
- package/dist/core/dialogs.js.map +1 -1
- package/dist/core/mailbox.d.ts +222 -0
- package/dist/core/mailbox.js +545 -0
- package/dist/core/mailbox.js.map +1 -0
- package/dist/core/manager.d.ts +3 -0
- package/dist/core/manager.js +37 -2
- package/dist/core/manager.js.map +1 -1
- package/dist/core/messageText.d.ts +2 -0
- package/dist/core/messageText.js +6 -0
- package/dist/core/messageText.js.map +1 -0
- package/dist/core/nudge.d.ts +37 -0
- package/dist/core/nudge.js +57 -0
- package/dist/core/nudge.js.map +1 -0
- package/dist/core/promptDetector.d.ts +14 -12
- package/dist/core/promptDetector.js +113 -363
- package/dist/core/promptDetector.js.map +1 -1
- package/dist/core/promptText.d.ts +1 -0
- package/dist/core/promptText.js +4 -0
- package/dist/core/promptText.js.map +1 -0
- package/dist/core/readiness.d.ts +14 -0
- package/dist/core/readiness.js +95 -0
- package/dist/core/readiness.js.map +1 -0
- package/dist/core/reasoning.d.ts +68 -7
- package/dist/core/reasoning.js +572 -325
- package/dist/core/reasoning.js.map +1 -1
- package/dist/core/renderer.d.ts +63 -3
- package/dist/core/renderer.js +368 -42
- package/dist/core/renderer.js.map +1 -1
- package/dist/core/selection.d.ts +1 -1
- package/dist/core/selection.js +3 -3
- package/dist/core/selection.js.map +1 -1
- package/dist/core/session.d.ts +166 -14
- package/dist/core/session.js +1000 -86
- package/dist/core/session.js.map +1 -1
- package/dist/core/types.d.ts +60 -4
- package/dist/core/types.js +41 -0
- package/dist/core/types.js.map +1 -1
- package/dist/core/waiter.d.ts +9 -2
- package/dist/core/waiter.js +35 -10
- package/dist/core/waiter.js.map +1 -1
- package/dist/daemon/audit.d.ts +1 -1
- package/dist/daemon/audit.js +2 -1
- package/dist/daemon/audit.js.map +1 -1
- package/dist/daemon/config.d.ts +42 -0
- package/dist/daemon/config.js +159 -4
- package/dist/daemon/config.js.map +1 -1
- package/dist/daemon/folderPicker.js +21 -2
- package/dist/daemon/folderPicker.js.map +1 -1
- package/dist/daemon/homeOwner.d.ts +15 -0
- package/dist/daemon/homeOwner.js +106 -0
- package/dist/daemon/homeOwner.js.map +1 -0
- package/dist/daemon/index.js +10 -6
- package/dist/daemon/index.js.map +1 -1
- package/dist/daemon/launchProfiles.d.ts +5 -0
- package/dist/daemon/launchProfiles.js +42 -40
- package/dist/daemon/launchProfiles.js.map +1 -1
- package/dist/daemon/liveness.d.ts +1 -1
- package/dist/daemon/liveness.js +2 -2
- package/dist/daemon/liveness.js.map +1 -1
- package/dist/daemon/nudgeScheduler.d.ts +21 -0
- package/dist/daemon/nudgeScheduler.js +61 -0
- package/dist/daemon/nudgeScheduler.js.map +1 -0
- package/dist/daemon/paths.d.ts +22 -16
- package/dist/daemon/paths.js +137 -49
- package/dist/daemon/paths.js.map +1 -1
- package/dist/daemon/restartHold.d.ts +16 -0
- package/dist/daemon/restartHold.js +126 -0
- package/dist/daemon/restartHold.js.map +1 -0
- package/dist/daemon/restartSource.d.ts +7 -0
- package/dist/daemon/restartSource.js +89 -0
- package/dist/daemon/restartSource.js.map +1 -0
- package/dist/daemon/screenshot.d.ts +4 -1
- package/dist/daemon/screenshot.js +45 -7
- package/dist/daemon/screenshot.js.map +1 -1
- package/dist/daemon/server.d.ts +71 -13
- package/dist/daemon/server.js +1601 -296
- package/dist/daemon/server.js.map +1 -1
- package/dist/daemon/sessionFeed.js +4 -1
- package/dist/daemon/sessionFeed.js.map +1 -1
- package/dist/mcp/config.js +2 -1
- package/dist/mcp/config.js.map +1 -1
- package/dist/mcp/index.js +12 -2
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/tools.d.ts +21 -1
- package/dist/mcp/tools.js +213 -28
- package/dist/mcp/tools.js.map +1 -1
- package/dist/viewer/dashboard-folders.js +7 -1
- package/dist/viewer/dashboard-layout.js +6 -52
- package/dist/viewer/dashboard.css +20 -4
- package/dist/viewer/dashboard.html +12 -3
- package/dist/viewer/dashboard.js +550 -378
- package/dist/viewer/pane.js +744 -136
- package/dist/viewer/viewer.css +1 -1
- package/dist/viewer/viewer.js +3 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -11,25 +11,39 @@
|
|
|
11
11
|
* match, or find found nothing.
|
|
12
12
|
*/
|
|
13
13
|
import { writeFile } from 'node:fs/promises';
|
|
14
|
+
import { readFileSync } from 'node:fs';
|
|
14
15
|
import { resolve } from 'node:path';
|
|
15
16
|
import process from 'node:process';
|
|
16
|
-
import { DaemonGoneError, discoverDaemon, ensureDaemon, request, waitForPendingDaemon } from '../client/http.js';
|
|
17
|
+
import { DaemonGoneError, daemonStartMode, discoverDaemon, ensureDaemon, request, waitForPendingDaemon, withDaemonStartLock } from '../client/http.js';
|
|
17
18
|
import { assertNodeVersion, packageVersion } from '../daemon/meta.js';
|
|
18
19
|
import { NO_MATCHES } from '../core/find.js';
|
|
20
|
+
import { visibleMessageText } from '../core/messageText.js';
|
|
19
21
|
import { resultRefusal } from '../core/reasoning.js';
|
|
20
|
-
import { readDaemonState, shellpuppetHome } from '../daemon/paths.js';
|
|
22
|
+
import { inspectDaemonState, readDaemonState, shellpuppetHome } from '../daemon/paths.js';
|
|
23
|
+
import { clearRestartHold, readRestartHold, writeRestartHold } from '../daemon/restartHold.js';
|
|
21
24
|
import { planPassedEnv } from '../mcp/config.js';
|
|
22
25
|
import { isEnvNamesProblem, readDaemonConfig } from '../daemon/config.js';
|
|
23
26
|
import { agentNameFor } from '../core/reasoning.js';
|
|
24
27
|
import { knownKeys } from '../core/keys.js';
|
|
25
|
-
import { listedState } from '../core/types.js';
|
|
28
|
+
import { listedState, stallLine, startReadyLine, SESSION_IDENTITY_ENV_NAMES, SESSION_IDENTITY_ENV_RULE } from '../core/types.js';
|
|
26
29
|
import { installDesktopShortcut, uninstallDesktopShortcut, userShortcutOptions } from './desktopShortcut.js';
|
|
27
30
|
const USAGE = `ShellPuppet: drive a real terminal session; humans watch and type via the viewer.
|
|
28
31
|
|
|
29
32
|
Usage:
|
|
33
|
+
shellpuppet previous [--json] Read sessions saved before a daemon restart
|
|
34
|
+
shellpuppet launch <profile> [--name NAME] [--folder NAME] [--root-index N] [--folder-path PATH] [--resume-id ID]
|
|
30
35
|
shellpuppet start [options] <command> [args...] Launch a program in a new session
|
|
31
36
|
--label <s> --purpose <s> --cols <n> --rows <n> --cwd <dir>
|
|
32
37
|
--ready-text <s> --ready-quiet <ms> --no-shell --hold --agent <name>
|
|
38
|
+
--wait-ready --ready-timeout <ms>
|
|
39
|
+
Pass --wait-ready when starting an agent CLI to delegate work to. It uses
|
|
40
|
+
its known ready signals, or your --ready-text/--ready-quiet override.
|
|
41
|
+
Returns for readiness, a question needing an answer, exit or timeout.
|
|
42
|
+
--ready-timeout defaults to 30000 ms, capped at 300000. A longer wait
|
|
43
|
+
needs a longer caller budget, including startup overhead. If the caller
|
|
44
|
+
gives up, it may lose the answer; the session still exists in list.
|
|
45
|
+
Readiness is tracked for up to five minutes from start. Unknown programs
|
|
46
|
+
need an explicit condition. Without --wait-ready, start returns without waiting.
|
|
33
47
|
--env-name <NAME> (repeatable) --no-viewer
|
|
34
48
|
--no-viewer opens no dashboard or viewer window, for a short scripted session nobody
|
|
35
49
|
needs to watch; viewer-url still gives a link to it.
|
|
@@ -60,8 +74,11 @@ Usage:
|
|
|
60
74
|
Options go BEFORE the command; everything after the command is passed
|
|
61
75
|
to the daemon unchanged (so its own --flags survive).
|
|
62
76
|
shellpuppet list [--waiting] [--hide-reasoning] List sessions, or only waiting prompts
|
|
63
|
-
shellpuppet snap <id> [--last <n>] [--hide-reasoning]
|
|
77
|
+
shellpuppet snap <id> [--last <n>] [--hide-reasoning] [--wider COLSxROWS] [--wider-timeout <ms>]
|
|
64
78
|
Print the rendered screen
|
|
79
|
+
--wider temporarily enlarges the grid, waits 250 ms of quiet (at most
|
|
80
|
+
1500 ms by default), reads, then restores its size and controller.
|
|
81
|
+
--wider-timeout sets the redraw cap from 250 to 30000 ms.
|
|
65
82
|
--hide-reasoning leaves out an agent CLI's reasoning, each block as one
|
|
66
83
|
"[reasoning hidden: N lines]" line; a session whose agent has no
|
|
67
84
|
signature is refused (exit 2), never printed unfiltered.
|
|
@@ -70,24 +87,29 @@ Usage:
|
|
|
70
87
|
reasoning. --hide-reasoning is accepted but changes nothing: result
|
|
71
88
|
always leaves reasoning out. Exits 3, with the reason on stderr, while
|
|
72
89
|
the agent is still working or when no answer is recognised.
|
|
73
|
-
shellpuppet type <id> <text> [--enter] [--verify] Type text
|
|
74
|
-
for
|
|
90
|
+
shellpuppet type <id> <text> [--enter] [--verify] Type text; --enter sends the text,
|
|
91
|
+
waits for its painted draft and a quiet
|
|
92
|
+
screen, then checks again before Enter.
|
|
93
|
+
If the draft is absent, Enter is not sent.
|
|
94
|
+
--verify re-reads the screen.
|
|
75
95
|
shellpuppet key <id> <name> Press a key (enter, escape, ctrl+c, f1…)
|
|
76
|
-
shellpuppet wait <id> [--text <s>|--regex <r>|--quiet <ms>|--prompt]
|
|
96
|
+
shellpuppet wait <id> [--text <s>|--regex <r>|--quiet <ms>|--prompt|--stalled]
|
|
77
97
|
[--timeout <ms>] [--debounce <ms>] [--match-after-input true|false]
|
|
78
98
|
[--hide-reasoning]
|
|
79
99
|
Wait for a condition, print the screen
|
|
80
100
|
--prompt waits until the session asks a permission question
|
|
81
101
|
(the one you just answered does not count until it has been
|
|
82
102
|
seen to go; --match-after-input false accepts any prompt)
|
|
103
|
+
--stalled waits for a supported idle provider error, with
|
|
104
|
+
fixed reason and since metadata; combine with --prompt
|
|
83
105
|
--match-after-input true ignores text/regex matches at or
|
|
84
106
|
before the echo of what you last typed
|
|
85
107
|
--debounce waits for the condition to hold on every poll
|
|
86
108
|
for this many ms; a missed poll restarts it, while other
|
|
87
109
|
output such as a ticking timer does not; a match on the
|
|
88
110
|
final screen settles at once if the program exits
|
|
89
|
-
shellpuppet wait --prompt [id ...] [--now] [--timeout <ms>] [--hide-reasoning]
|
|
90
|
-
Wait for any listed session's prompt,
|
|
111
|
+
shellpuppet wait [--prompt] [--stalled] [id ...] [--now] [--timeout <ms>] [--hide-reasoning]
|
|
112
|
+
Wait for any listed session's prompt or stall,
|
|
91
113
|
or every live session if no ids are given;
|
|
92
114
|
--now polls once without waiting
|
|
93
115
|
shellpuppet find <id> <pattern> [--hide-reasoning]
|
|
@@ -120,7 +142,12 @@ Usage:
|
|
|
120
142
|
start/restart: --direct starts without daemon.startWith.
|
|
121
143
|
stop/restart: --force to kill live sessions. status and stop never
|
|
122
144
|
start a daemon: one that has gone is reported as not running.
|
|
145
|
+
stop: --hold [seconds] prevents auto-start for 120 s by default (1 to 600).
|
|
123
146
|
shellpuppet mcp Run the MCP stdio server (long-running)
|
|
147
|
+
shellpuppet msg send <to> <text|-> Send a message; - reads standard input
|
|
148
|
+
shellpuppet msg inbox|outbox|directory|wait Read messages and live names
|
|
149
|
+
shellpuppet msg claim <name>|release|log Manage an outside claim or inspect the log
|
|
150
|
+
shellpuppet inbox Alias for msg inbox
|
|
124
151
|
shellpuppet --version | --help
|
|
125
152
|
|
|
126
153
|
Any verb accepts --json for the raw API response.
|
|
@@ -148,7 +175,10 @@ const VALUE_FLAGS = new Set([
|
|
|
148
175
|
'cwd',
|
|
149
176
|
'ready-text',
|
|
150
177
|
'ready-quiet',
|
|
178
|
+
'ready-timeout',
|
|
151
179
|
'last',
|
|
180
|
+
'wider',
|
|
181
|
+
'wider-timeout',
|
|
152
182
|
'text',
|
|
153
183
|
'regex',
|
|
154
184
|
'quiet',
|
|
@@ -158,6 +188,11 @@ const VALUE_FLAGS = new Set([
|
|
|
158
188
|
'out',
|
|
159
189
|
'width',
|
|
160
190
|
'height',
|
|
191
|
+
'from',
|
|
192
|
+
'limit',
|
|
193
|
+
'participant',
|
|
194
|
+
'folder', 'folder-path', 'root-index', 'resume-id', 'name',
|
|
195
|
+
'mark-read',
|
|
161
196
|
]);
|
|
162
197
|
/**
|
|
163
198
|
* `stopAtFirstPositional` is how `start` avoids eating the target command's
|
|
@@ -183,6 +218,9 @@ function parseArgs(argv, stopAtFirstPositional = false) {
|
|
|
183
218
|
fail(2, `--${name} needs a value.`);
|
|
184
219
|
lists.set(name, [...(lists.get(name) ?? []), value]);
|
|
185
220
|
}
|
|
221
|
+
else if (name === 'hold' && argv[0] === 'stop' && argv[i + 1] !== undefined && !argv[i + 1]?.startsWith('--')) {
|
|
222
|
+
flags.set(name, argv[++i] ?? '');
|
|
223
|
+
}
|
|
186
224
|
else if (VALUE_FLAGS.has(name)) {
|
|
187
225
|
const value = argv[++i];
|
|
188
226
|
if (value === undefined)
|
|
@@ -241,6 +279,21 @@ async function call(connection, method, path, body, options = {}) {
|
|
|
241
279
|
function printJson(value) {
|
|
242
280
|
console.log(JSON.stringify(value, null, 2));
|
|
243
281
|
}
|
|
282
|
+
function printableMessages(payload) {
|
|
283
|
+
const sanitise = (entry) => {
|
|
284
|
+
if (typeof entry !== 'object' || entry === null)
|
|
285
|
+
return entry;
|
|
286
|
+
const message = entry;
|
|
287
|
+
return typeof message['text'] === 'string'
|
|
288
|
+
? { ...message, text: visibleMessageText(message['text']) } : entry;
|
|
289
|
+
};
|
|
290
|
+
return {
|
|
291
|
+
...payload,
|
|
292
|
+
...(Array.isArray(payload['messages'])
|
|
293
|
+
? { messages: payload['messages'].map(sanitise) } : {}),
|
|
294
|
+
...(Object.hasOwn(payload, 'message') ? { message: sanitise(payload['message']) } : {}),
|
|
295
|
+
};
|
|
296
|
+
}
|
|
244
297
|
async function main() {
|
|
245
298
|
assertNodeVersion();
|
|
246
299
|
const argv = process.argv.slice(2);
|
|
@@ -284,7 +337,68 @@ async function main() {
|
|
|
284
337
|
}
|
|
285
338
|
const connection = await ensureDaemon({ logger: stderrLogger });
|
|
286
339
|
surfaceWarnings(connection);
|
|
340
|
+
if (verb === 'msg' || verb === 'inbox') {
|
|
341
|
+
const sub = verb === 'inbox' ? 'inbox' : parsed.positionals[0];
|
|
342
|
+
const params = new URLSearchParams();
|
|
343
|
+
if (parsed.flags.has('limit'))
|
|
344
|
+
params.set('limit', String(parsed.flags.get('limit')));
|
|
345
|
+
if (parsed.flags.has('from'))
|
|
346
|
+
params.set('from', String(parsed.flags.get('from')));
|
|
347
|
+
if (parsed.flags.has('timeout'))
|
|
348
|
+
params.set('timeoutMs', String(parsed.flags.get('timeout')));
|
|
349
|
+
if (parsed.flags.has('mark-read'))
|
|
350
|
+
params.set('markRead', String(parsed.flags.get('mark-read')));
|
|
351
|
+
if (parsed.flags.has('participant'))
|
|
352
|
+
params.set('participant', String(parsed.flags.get('participant')));
|
|
353
|
+
let payload;
|
|
354
|
+
if (sub === 'send') {
|
|
355
|
+
const to = parsed.positionals[1] ?? fail(2, 'msg send needs a recipient.');
|
|
356
|
+
const input = parsed.positionals[2] ?? fail(2, 'msg send needs text or -.');
|
|
357
|
+
payload = await call(connection, 'POST', '/messages', { to, text: input === '-' ? readFileSync(0, 'utf8') : input });
|
|
358
|
+
}
|
|
359
|
+
else if (sub === 'claim') {
|
|
360
|
+
const name = parsed.positionals[1] ?? fail(2, 'msg claim needs a name.');
|
|
361
|
+
payload = await call(connection, 'POST', '/messages/claims', { name });
|
|
362
|
+
if (!wantJson) {
|
|
363
|
+
const claim = `${String(payload['claimId'])}:${String(payload['secret'])}`;
|
|
364
|
+
console.log(`SHELLPUPPET_CLAIM=${claim}`);
|
|
365
|
+
console.log(`PowerShell: $env:SHELLPUPPET_CLAIM='${claim}'`);
|
|
366
|
+
console.log(`POSIX shell: export SHELLPUPPET_CLAIM='${claim}'`);
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
else if (sub === 'release') {
|
|
371
|
+
const match = process.env['SHELLPUPPET_CLAIM']?.match(/^(claim_[a-f0-9]{32}):.+$/);
|
|
372
|
+
if (match === undefined || match === null)
|
|
373
|
+
fail(2, 'Set SHELLPUPPET_CLAIM before release.');
|
|
374
|
+
payload = await call(connection, 'DELETE', `/messages/claims/${match[1]}`);
|
|
375
|
+
}
|
|
376
|
+
else if (['inbox', 'outbox', 'directory', 'wait', 'log'].includes(sub ?? '')) {
|
|
377
|
+
payload = await call(connection, 'GET', `/messages/${sub}?${params.toString()}`);
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
380
|
+
fail(2, 'msg needs send, inbox, outbox, directory, wait, claim, release or log.');
|
|
381
|
+
}
|
|
382
|
+
printJson(['inbox', 'outbox', 'wait', 'log'].includes(sub ?? '') ? printableMessages(payload) : payload);
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
287
385
|
switch (verb) {
|
|
386
|
+
case 'previous':
|
|
387
|
+
printJson(await call(connection, 'GET', '/launcher/previous'));
|
|
388
|
+
return;
|
|
389
|
+
case 'launch': {
|
|
390
|
+
if (parsed.positionals.length !== 1 || parsed.lists.size || [...parsed.flags.keys()].some(key => !['json', 'name', 'folder', 'folder-path', 'root-index', 'resume-id'].includes(key))) {
|
|
391
|
+
fail(2, 'launch requires one profile and accepts only profile launch options.');
|
|
392
|
+
}
|
|
393
|
+
const payload = await call(connection, 'POST', '/launcher/launch', { profile: parsed.positionals[0],
|
|
394
|
+
name: parsed.flags.get('name'), folder: parsed.flags.get('folder'), folderPath: parsed.flags.get('folder-path'),
|
|
395
|
+
rootIndex: intFlag(parsed, 'root-index'), resumeId: parsed.flags.get('resume-id') });
|
|
396
|
+
if (wantJson)
|
|
397
|
+
printJson(payload);
|
|
398
|
+
else
|
|
399
|
+
console.log(`Started session ${String(payload['id'])} from profile ${String(payload['profile'])}.`);
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
288
402
|
case 'start': {
|
|
289
403
|
const command = parsed.positionals[0];
|
|
290
404
|
if (command === undefined)
|
|
@@ -303,6 +417,8 @@ async function main() {
|
|
|
303
417
|
...(parsed.flags.has('ready-text')
|
|
304
418
|
? { readyText: String(parsed.flags.get('ready-text')) }
|
|
305
419
|
: {}),
|
|
420
|
+
...(parsed.flags.get('wait-ready') === true ? { waitReady: true } : {}),
|
|
421
|
+
...(intFlag(parsed, 'ready-timeout') !== undefined ? { readyTimeout: intFlag(parsed, 'ready-timeout') } : {}),
|
|
306
422
|
...(intFlag(parsed, 'ready-quiet') !== undefined
|
|
307
423
|
? { readyQuiet: intFlag(parsed, 'ready-quiet') }
|
|
308
424
|
: {}),
|
|
@@ -315,6 +431,9 @@ async function main() {
|
|
|
315
431
|
const daemonConfig = readDaemonConfig(shellpuppetHome());
|
|
316
432
|
const agent = agentNameFor(parsed.flags.has('agent') ? String(parsed.flags.get('agent')) : undefined, command, daemonConfig.config.agentSignatures ?? []);
|
|
317
433
|
const envNames = parsed.lists.get('env-name') ?? [];
|
|
434
|
+
const reserved = envNames.filter((name) => SESSION_IDENTITY_ENV_NAMES.has(name.toUpperCase()));
|
|
435
|
+
if (reserved.length > 0)
|
|
436
|
+
fail(2, `Not started: ${SESSION_IDENTITY_ENV_RULE} ${reserved.join(', ')}.`);
|
|
318
437
|
if (envNames.length > 0) {
|
|
319
438
|
for (const problem of daemonConfig.problems.filter(isEnvNamesProblem))
|
|
320
439
|
console.error(`warning: ${problem}`);
|
|
@@ -376,7 +495,13 @@ async function main() {
|
|
|
376
495
|
else {
|
|
377
496
|
console.log(`viewer: no window opened (--no-viewer); viewer-url ${String(result['id'])} mints a link`);
|
|
378
497
|
}
|
|
379
|
-
|
|
498
|
+
const readyWait = result['readyWait'];
|
|
499
|
+
if (readyWait !== undefined) {
|
|
500
|
+
console.log(startReadyLine(readyWait, result['exitCode'], result['readyReason']));
|
|
501
|
+
if (readyWait.prompt !== undefined)
|
|
502
|
+
console.log(JSON.stringify(readyWait.prompt, null, 2));
|
|
503
|
+
}
|
|
504
|
+
else if (result['ready'] !== true) {
|
|
380
505
|
console.log('ready: false. First paint is not readiness; wait before typing.');
|
|
381
506
|
}
|
|
382
507
|
}
|
|
@@ -408,8 +533,9 @@ async function main() {
|
|
|
408
533
|
}
|
|
409
534
|
console.log(`${s.id} ${listedState(s)} ` +
|
|
410
535
|
`${String(s.cols)}x${String(s.rows)} watchers:${String(s.watchers)} ` +
|
|
411
|
-
`${s.ready ? 'ready' : 'NOT-READY'} ${s.label}` +
|
|
412
|
-
(s.agent !== null && s.agent !== undefined ? ` agent:${s.agent}` : '')
|
|
536
|
+
`${s.stalled !== undefined ? stallLine(s.stalled) : s.ready ? 'ready' : 'NOT-READY'} ${s.label}` +
|
|
537
|
+
(s.agent !== null && s.agent !== undefined ? ` agent:${s.agent}` : '') +
|
|
538
|
+
(s.parent !== undefined ? ` parent:${s.parent}` : ''));
|
|
413
539
|
const waiting = s.waitingOnPrompt;
|
|
414
540
|
if (waiting !== undefined) {
|
|
415
541
|
console.log(` WAITING ${String(Math.round(waiting.waitingMs / 1000))}s on a prompt` +
|
|
@@ -423,12 +549,19 @@ async function main() {
|
|
|
423
549
|
case 'snap': {
|
|
424
550
|
const id = parsed.positionals[0] ?? fail(2, 'snap needs a session id.');
|
|
425
551
|
const last = intFlag(parsed, 'last');
|
|
552
|
+
const wider = parsed.flags.get('wider');
|
|
553
|
+
if (wider !== undefined && (typeof wider !== 'string' || !/^\d+x\d+$/.test(wider)))
|
|
554
|
+
fail(2, '--wider must be COLSxROWS.');
|
|
426
555
|
const query = [
|
|
427
556
|
...(last !== undefined ? [`lastLines=${String(last)}`] : []),
|
|
428
557
|
...(parsed.flags.get('hide-reasoning') === true ? ['hideReasoning=1'] : []),
|
|
558
|
+
...(wider !== undefined ? [`wider=${String(wider)}`] : []),
|
|
559
|
+
...(intFlag(parsed, 'wider-timeout') !== undefined ? [`widerTimeout=${String(intFlag(parsed, 'wider-timeout'))}`] : []),
|
|
429
560
|
];
|
|
430
561
|
const path = `/sessions/${id}/snapshot${query.length > 0 ? `?${query.join('&')}` : ''}`;
|
|
431
562
|
const result = await call(connection, 'GET', path);
|
|
563
|
+
if (result['restored'] === false)
|
|
564
|
+
console.error('Grid changed during the wider read; the original grid was not restored.');
|
|
432
565
|
if (wantJson)
|
|
433
566
|
printJson(result);
|
|
434
567
|
else if (last !== undefined)
|
|
@@ -469,6 +602,13 @@ async function main() {
|
|
|
469
602
|
});
|
|
470
603
|
if (wantJson)
|
|
471
604
|
printJson(result);
|
|
605
|
+
else if (result['submitted'] === false) {
|
|
606
|
+
console.log(String(result['message']));
|
|
607
|
+
process.exit(1);
|
|
608
|
+
}
|
|
609
|
+
else if (result['submitRetried'] === true) {
|
|
610
|
+
console.log(`typed ${String(result['bytes'])} bytes. ${String(result['message'])}`);
|
|
611
|
+
}
|
|
472
612
|
else if (result['verified'] === false) {
|
|
473
613
|
console.log('typed, but the text did NOT appear on screen. The app may still be ' +
|
|
474
614
|
'loading, a panel may have focus or, commonly with --enter, the app ' +
|
|
@@ -482,7 +622,8 @@ async function main() {
|
|
|
482
622
|
// knowing the keystrokes landed, so say so rather than printing the
|
|
483
623
|
// same line as an unverified type.
|
|
484
624
|
console.log(`typed ${String(result['bytes'])} bytes` +
|
|
485
|
-
(result['verified'] === true ? ' (verified on screen).' : '.')
|
|
625
|
+
(result['verified'] === true ? ' (verified on screen).' : '.') +
|
|
626
|
+
(typeof result['message'] === 'string' ? ` ${result['message']}` : ''));
|
|
486
627
|
}
|
|
487
628
|
break;
|
|
488
629
|
}
|
|
@@ -497,9 +638,17 @@ async function main() {
|
|
|
497
638
|
break;
|
|
498
639
|
}
|
|
499
640
|
case 'wait': {
|
|
500
|
-
const multi = parsed.flags.get('prompt') === true && (parsed.positionals.length !== 1 || parsed.flags.get('now') === true);
|
|
641
|
+
const multi = (parsed.flags.get('prompt') === true || parsed.flags.get('stalled') === true) && (parsed.positionals.length !== 1 || parsed.flags.get('now') === true);
|
|
501
642
|
if (multi) {
|
|
502
|
-
const
|
|
643
|
+
for (const name of ['text', 'regex', 'quiet', 'debounce', 'match-after-input']) {
|
|
644
|
+
if (parsed.flags.has(name))
|
|
645
|
+
fail(2, 'A multi-session wait accepts --prompt and/or --stalled, --timeout, --now and --hide-reasoning only.');
|
|
646
|
+
}
|
|
647
|
+
const params = new URLSearchParams();
|
|
648
|
+
if (parsed.flags.get('prompt') === true)
|
|
649
|
+
params.set('prompt', 'true');
|
|
650
|
+
if (parsed.flags.get('stalled') === true)
|
|
651
|
+
params.set('stalled', 'true');
|
|
503
652
|
for (const id of parsed.positionals)
|
|
504
653
|
params.append('session', id);
|
|
505
654
|
if (parsed.flags.get('now') === true)
|
|
@@ -513,6 +662,10 @@ async function main() {
|
|
|
513
662
|
printJson(result);
|
|
514
663
|
else {
|
|
515
664
|
for (const waiting of result['sessions']) {
|
|
665
|
+
if (waiting.stalled !== undefined) {
|
|
666
|
+
console.log(`${waiting.id} ${waiting.label} ${stallLine(waiting.stalled)}`);
|
|
667
|
+
continue;
|
|
668
|
+
}
|
|
516
669
|
console.log(`${waiting.id} ${waiting.label} WAITING ${String(Math.round(waiting.waitingMs / 1000))}s` + (waiting.question === undefined ? '' : `: ${waiting.question}`));
|
|
517
670
|
for (const [index, option] of (waiting.options ?? []).entries())
|
|
518
671
|
console.log(` ${index === waiting.selectedOption ? '* ' : ' '}${option}`);
|
|
@@ -525,7 +678,7 @@ async function main() {
|
|
|
525
678
|
}
|
|
526
679
|
const id = parsed.positionals[0] ?? fail(2, 'wait needs a session id.');
|
|
527
680
|
const params = new URLSearchParams();
|
|
528
|
-
for (const name of ['text', 'regex', 'quiet', 'timeout', 'debounce', 'prompt']) {
|
|
681
|
+
for (const name of ['text', 'regex', 'quiet', 'timeout', 'debounce', 'prompt', 'stalled']) {
|
|
529
682
|
const value = parsed.flags.get(name);
|
|
530
683
|
if (value !== undefined)
|
|
531
684
|
params.set(name, String(value));
|
|
@@ -546,6 +699,8 @@ async function main() {
|
|
|
546
699
|
// line.
|
|
547
700
|
if (typeof result['detail'] === 'string')
|
|
548
701
|
console.error(result['detail']);
|
|
702
|
+
if (result['stalled'] !== undefined)
|
|
703
|
+
console.error(stallLine(result['stalled']));
|
|
549
704
|
const detected = result['prompt'];
|
|
550
705
|
if (detected !== undefined) {
|
|
551
706
|
// stderr, like the outcome line: stdout stays the screen alone, so
|
|
@@ -688,15 +843,24 @@ async function daemonVerb(parsed, wantJson) {
|
|
|
688
843
|
const direct = parsed.flags.get('direct') === true;
|
|
689
844
|
if (direct && sub !== 'start' && sub !== 'restart')
|
|
690
845
|
fail(2, '--direct applies only to daemon start or restart.');
|
|
846
|
+
const holdFlag = parsed.flags.get('hold');
|
|
847
|
+
if (holdFlag !== undefined && sub !== 'stop')
|
|
848
|
+
fail(2, '--hold applies only to daemon stop.');
|
|
849
|
+
const holdSeconds = holdFlag === undefined ? undefined : holdFlag === true ? 120 : Number(holdFlag);
|
|
850
|
+
if (holdSeconds !== undefined && (!Number.isInteger(holdSeconds) || holdSeconds < 1 || holdSeconds > 600)) {
|
|
851
|
+
fail(2, '--hold needs a whole number of seconds from 1 to 600.');
|
|
852
|
+
}
|
|
691
853
|
// Every request here passes `autoStart: false`: asking about or stopping a
|
|
692
854
|
// daemon must never start one, so a daemon that goes between being found
|
|
693
855
|
// and being asked is reported as not running.
|
|
694
856
|
const daemonOnly = { autoStart: false };
|
|
857
|
+
const shutdownWarnings = [];
|
|
858
|
+
const warningFields = () => shutdownWarnings.length ? { warnings: shutdownWarnings } : {};
|
|
695
859
|
/** Stop the daemon, or say false when it had already gone. */
|
|
696
860
|
const stopRunning = async (connection) => {
|
|
697
861
|
let response;
|
|
698
862
|
try {
|
|
699
|
-
response = await request(connection, 'POST', '/daemon/shutdown', { force }, {
|
|
863
|
+
response = await request(connection, 'POST', '/daemon/shutdown', { force, ...(sub === 'restart' || holdSeconds !== undefined ? { restart: true } : {}) }, {
|
|
700
864
|
logger: stderrLogger,
|
|
701
865
|
actor: 'cli',
|
|
702
866
|
...daemonOnly,
|
|
@@ -710,6 +874,20 @@ async function daemonVerb(parsed, wantJson) {
|
|
|
710
874
|
if (response.status === 409) {
|
|
711
875
|
fail(1, `${String(response.body['error'])} (use --force)`);
|
|
712
876
|
}
|
|
877
|
+
if (response.status >= 400) {
|
|
878
|
+
const message = response.body['error'];
|
|
879
|
+
throw new Error(typeof message === 'string' ? message : 'Daemon shutdown failed.');
|
|
880
|
+
}
|
|
881
|
+
const warnings = response.body['warnings'];
|
|
882
|
+
if (Array.isArray(warnings)) {
|
|
883
|
+
for (const warning of warnings) {
|
|
884
|
+
if (typeof warning !== 'string')
|
|
885
|
+
continue;
|
|
886
|
+
shutdownWarnings.push(warning);
|
|
887
|
+
if (!wantJson)
|
|
888
|
+
console.error(warning);
|
|
889
|
+
}
|
|
890
|
+
}
|
|
713
891
|
// Wait for the port to actually go quiet so restart cannot race it.
|
|
714
892
|
const deadline = Date.now() + 10_000;
|
|
715
893
|
while (Date.now() < deadline) {
|
|
@@ -727,8 +905,11 @@ async function daemonVerb(parsed, wantJson) {
|
|
|
727
905
|
};
|
|
728
906
|
switch (sub) {
|
|
729
907
|
case 'status': {
|
|
908
|
+
const hold = readRestartHold(shellpuppetHome(), stderrLogger);
|
|
909
|
+
const holdRemainingSeconds = hold === null ? undefined : Math.max(1, Math.ceil((hold.expiresAt - Date.now()) / 1000));
|
|
730
910
|
const notRunning = () => {
|
|
731
|
-
console.log(wantJson ? JSON.stringify({ running: false }
|
|
911
|
+
console.log(wantJson ? JSON.stringify({ running: false, ...(holdRemainingSeconds !== undefined ? { holdRemainingSeconds } : {}) }) :
|
|
912
|
+
`not running${holdRemainingSeconds === undefined ? '' : `; restart hold ends in ${String(holdRemainingSeconds)} s`}`);
|
|
732
913
|
};
|
|
733
914
|
const connection = await discoverDaemon({ logger: stderrLogger });
|
|
734
915
|
if (connection === null) {
|
|
@@ -765,12 +946,14 @@ async function daemonVerb(parsed, wantJson) {
|
|
|
765
946
|
version: connection.version,
|
|
766
947
|
sessions: list,
|
|
767
948
|
startedWrapped,
|
|
949
|
+
...(holdRemainingSeconds !== undefined ? { holdRemainingSeconds } : {}),
|
|
768
950
|
...(environment !== undefined ? { sessionEnv: environment } : {}),
|
|
769
951
|
});
|
|
770
952
|
}
|
|
771
953
|
else {
|
|
772
954
|
console.log(`running on port ${String(connection.port)}, version ${connection.version}, ` +
|
|
773
955
|
`${String(list.length)} session(s), started wrapped: ${String(startedWrapped)}` +
|
|
956
|
+
(holdRemainingSeconds !== undefined ? `, restart hold ends in ${String(holdRemainingSeconds)} s` : '') +
|
|
774
957
|
(environment !== undefined ? `, session environment ${environment.mode}` : ''));
|
|
775
958
|
if (environment !== undefined && environment.exposed.length > 0) {
|
|
776
959
|
console.error(`warning: sessionEnv "passthrough" hands every session the daemon's whole ` +
|
|
@@ -783,17 +966,21 @@ async function daemonVerb(parsed, wantJson) {
|
|
|
783
966
|
// `--help` says every verb accepts --json, so these three answer in JSON
|
|
784
967
|
// when asked, and a script driving the daemon need not parse English.
|
|
785
968
|
case 'start': {
|
|
786
|
-
const
|
|
787
|
-
|
|
788
|
-
|
|
969
|
+
const { connection, alreadyRunning } = await withDaemonStartLock({ logger: stderrLogger }, async (lock) => {
|
|
970
|
+
clearRestartHold(shellpuppetHome());
|
|
971
|
+
const existing = await discoverDaemon({ logger: stderrLogger });
|
|
972
|
+
return existing !== null ? { connection: existing, alreadyRunning: true } :
|
|
973
|
+
{ connection: await ensureDaemon({ logger: stderrLogger, direct }, lock), alreadyRunning: false };
|
|
974
|
+
});
|
|
975
|
+
if (alreadyRunning) {
|
|
976
|
+
surfaceWarnings(connection);
|
|
789
977
|
if (wantJson) {
|
|
790
|
-
printJson({ running: true, port:
|
|
978
|
+
printJson({ running: true, port: connection.port, version: connection.version, startedWrapped: readDaemonState(shellpuppetHome())?.startedWrapped === true });
|
|
791
979
|
}
|
|
792
980
|
else
|
|
793
|
-
console.log(`already running on port ${String(
|
|
981
|
+
console.log(`already running on port ${String(connection.port)}`);
|
|
794
982
|
return;
|
|
795
983
|
}
|
|
796
|
-
const connection = await ensureDaemon({ logger: stderrLogger, direct });
|
|
797
984
|
surfaceWarnings(connection);
|
|
798
985
|
if (wantJson) {
|
|
799
986
|
printJson({ running: true, port: connection.port, version: connection.version, startedWrapped: readDaemonState(shellpuppetHome())?.startedWrapped === true });
|
|
@@ -804,32 +991,67 @@ async function daemonVerb(parsed, wantJson) {
|
|
|
804
991
|
return;
|
|
805
992
|
}
|
|
806
993
|
case 'stop': {
|
|
994
|
+
if (holdSeconds !== undefined) {
|
|
995
|
+
const stopped = await withDaemonStartLock({ logger: stderrLogger }, async () => {
|
|
996
|
+
const existing = await discoverDaemon({ logger: stderrLogger });
|
|
997
|
+
const didStop = existing !== null && await stopRunning(existing);
|
|
998
|
+
writeRestartHold(shellpuppetHome(), holdSeconds);
|
|
999
|
+
return didStop;
|
|
1000
|
+
});
|
|
1001
|
+
if (wantJson)
|
|
1002
|
+
printJson({ running: false, stopped: true, ...warningFields(), holdRemainingSeconds: holdSeconds });
|
|
1003
|
+
else
|
|
1004
|
+
console.log(stopped ? `stopped; restart hold ends in ${String(holdSeconds)} s` :
|
|
1005
|
+
`not running; restart hold ends in ${String(holdSeconds)} s`);
|
|
1006
|
+
return;
|
|
1007
|
+
}
|
|
807
1008
|
const connection = await waitForPendingDaemon({ logger: stderrLogger });
|
|
808
1009
|
// A daemon that went before it could be told to stop was not running.
|
|
809
1010
|
if (connection === null || !(await stopRunning(connection))) {
|
|
810
1011
|
// Nothing to stop IS the outcome asked for, so it reads the same to a
|
|
811
1012
|
// script as a daemon that was stopped.
|
|
812
1013
|
if (wantJson)
|
|
813
|
-
printJson({ running: false, stopped: true });
|
|
1014
|
+
printJson({ running: false, stopped: true, ...warningFields() });
|
|
814
1015
|
else
|
|
815
1016
|
console.log('not running');
|
|
816
1017
|
return;
|
|
817
1018
|
}
|
|
818
1019
|
if (wantJson)
|
|
819
|
-
printJson({ running: false, stopped: true });
|
|
1020
|
+
printJson({ running: false, stopped: true, ...warningFields() });
|
|
820
1021
|
else
|
|
821
1022
|
console.log('stopped');
|
|
822
1023
|
return;
|
|
823
1024
|
}
|
|
824
1025
|
case 'restart': {
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
1026
|
+
const connection = await withDaemonStartLock({ logger: stderrLogger }, async (lock) => {
|
|
1027
|
+
const home = shellpuppetHome();
|
|
1028
|
+
clearRestartHold(home);
|
|
1029
|
+
const record = inspectDaemonState(home);
|
|
1030
|
+
if (record.kind !== 'record') {
|
|
1031
|
+
throw new Error('Cannot restart without a readable daemon record. Wait about 15 seconds and run `shellpuppet daemon restart` again. If the record is still missing, the daemon is usually stopped; check that no ShellPuppet daemon process is running before `shellpuppet daemon start`.');
|
|
1032
|
+
}
|
|
1033
|
+
const existing = await discoverDaemon({ logger: stderrLogger });
|
|
1034
|
+
if (existing === null)
|
|
1035
|
+
return ensureDaemon({ logger: stderrLogger, direct }, lock);
|
|
1036
|
+
const state = readDaemonState(home);
|
|
1037
|
+
if (state === null || state.pid !== existing.pid || state.instanceId !== existing.instanceId) {
|
|
1038
|
+
throw new Error('The daemon changed while preparing its restart. Try again.');
|
|
1039
|
+
}
|
|
1040
|
+
// Publish the daemon being replaced before the shutdown request. Peers
|
|
1041
|
+
// can still see its healthy port until the stop completes.
|
|
1042
|
+
writeRestartHold(home, 140, { ...(existing.instanceId === undefined ? {} : { instanceId: existing.instanceId }),
|
|
1043
|
+
pid: existing.pid, port: existing.port, startMode: daemonStartMode(home, direct) });
|
|
1044
|
+
try {
|
|
1045
|
+
await stopRunning(existing);
|
|
1046
|
+
return await ensureDaemon({ logger: stderrLogger, direct }, lock);
|
|
1047
|
+
}
|
|
1048
|
+
finally {
|
|
1049
|
+
clearRestartHold(home);
|
|
1050
|
+
}
|
|
1051
|
+
});
|
|
830
1052
|
surfaceWarnings(connection);
|
|
831
1053
|
if (wantJson) {
|
|
832
|
-
printJson({ running: true, port: connection.port, version: connection.version, startedWrapped: readDaemonState(shellpuppetHome())?.startedWrapped === true });
|
|
1054
|
+
printJson({ running: true, ...warningFields(), port: connection.port, version: connection.version, startedWrapped: readDaemonState(shellpuppetHome())?.startedWrapped === true });
|
|
833
1055
|
}
|
|
834
1056
|
else {
|
|
835
1057
|
console.log(`restarted on port ${String(connection.port)}, version ${connection.version}`);
|
|
@@ -837,7 +1059,7 @@ async function daemonVerb(parsed, wantJson) {
|
|
|
837
1059
|
return;
|
|
838
1060
|
}
|
|
839
1061
|
default:
|
|
840
|
-
fail(2, 'daemon needs one of: status, start, stop [--force], restart [--force]');
|
|
1062
|
+
fail(2, 'daemon needs one of: status, start, stop [--force] [--hold [seconds]], restart [--force]');
|
|
841
1063
|
}
|
|
842
1064
|
}
|
|
843
1065
|
main().catch((error) => {
|