shellpuppet 0.2.1 → 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 +63 -16
- 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 +185 -19
- package/dist/cli/index.js.map +1 -1
- package/dist/client/http.d.ts +5 -1
- package/dist/client/http.js +39 -9
- 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 +165 -13
- package/dist/core/session.js +998 -84
- 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/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 +20 -16
- package/dist/daemon/paths.js +137 -49
- package/dist/daemon/paths.js.map +1 -1
- 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 +70 -13
- package/dist/daemon/server.js +1596 -294
- 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 +549 -382
- 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
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import type { AgentSignature, CompiledSignature, LineTest } from '../core/reasoning.js';
|
|
2
|
+
import type { DialogSignature } from '../core/dialogs.js';
|
|
3
|
+
import type { DetectedPrompt } from '../core/promptDetector.js';
|
|
4
|
+
import type { CursorPosition } from '../core/types.js';
|
|
5
|
+
import type { CellStyle, StyledLine } from '../core/renderer.js';
|
|
6
|
+
export type ProgramMatch = string;
|
|
7
|
+
export type AgentSource = 'explicit' | 'program' | 'fallback';
|
|
8
|
+
export interface VerifyTiming {
|
|
9
|
+
baseMs: number;
|
|
10
|
+
perCharacterMs: number;
|
|
11
|
+
maxMs: number;
|
|
12
|
+
}
|
|
13
|
+
/** Reserved for a later, explicitly configured safety adapter. */
|
|
14
|
+
export interface SafetyAdapter {
|
|
15
|
+
readonly kind: string;
|
|
16
|
+
}
|
|
17
|
+
export interface PromptLine {
|
|
18
|
+
text: string;
|
|
19
|
+
index: number;
|
|
20
|
+
}
|
|
21
|
+
export interface PromptRows {
|
|
22
|
+
kind: 'rows';
|
|
23
|
+
styledHeading?: RegExp;
|
|
24
|
+
numbered?: RegExp;
|
|
25
|
+
pointer?: RegExp;
|
|
26
|
+
/** A module's input row, which must not seed a pointer chooser. */
|
|
27
|
+
composer?: RegExp;
|
|
28
|
+
footer?: RegExp;
|
|
29
|
+
marker?: RegExp;
|
|
30
|
+
busy?: RegExp;
|
|
31
|
+
keyHint?: RegExp;
|
|
32
|
+
questionPrefix?: RegExp;
|
|
33
|
+
commandStart?: (raw: string[], firstOption: number) => number;
|
|
34
|
+
clackMessage?: (raw: string[], index: number) => string[];
|
|
35
|
+
}
|
|
36
|
+
export type PromptShape = {
|
|
37
|
+
kind: 'dialog';
|
|
38
|
+
signature: DialogSignature;
|
|
39
|
+
} | {
|
|
40
|
+
kind: 'menu';
|
|
41
|
+
order: number;
|
|
42
|
+
detect: (raw: string[], lines: PromptLine[], tail: PromptLine[], busy: (text: string) => boolean, viewportRows?: number, styled?: readonly StyledLine[]) => DetectedPrompt | null;
|
|
43
|
+
} | PromptRows;
|
|
44
|
+
export interface PromptSettler {
|
|
45
|
+
settle(prompt: DetectedPrompt | null, screen: string, now: number, styled?: readonly StyledLine[]): DetectedPrompt | null;
|
|
46
|
+
}
|
|
47
|
+
export interface ReadingContext {
|
|
48
|
+
matches: (line: StyledLine, test: CompiledSignature['composer']) => boolean;
|
|
49
|
+
ink: (line: StyledLine) => CellStyle[];
|
|
50
|
+
ranges: (lines: readonly StyledLine[], signature: CompiledSignature, limit: number) => [number, number][];
|
|
51
|
+
}
|
|
52
|
+
export interface ReadingRules {
|
|
53
|
+
/** Crop only independently framed adjacent UI, before any reading walk. */
|
|
54
|
+
contentRegion?: (lines: readonly StyledLine[]) => readonly StyledLine[];
|
|
55
|
+
/** Rows owned by a live frame, even if its controls were painted on physical wraps. */
|
|
56
|
+
claimPromptRows?: (lines: readonly StyledLine[], prompt: DetectedPrompt | null) => readonly [number, number] | null;
|
|
57
|
+
composer?: (lines: readonly StyledLine[], index: number, signature: CompiledSignature, context: ReadingContext) => boolean;
|
|
58
|
+
busyWithoutComposer?: boolean;
|
|
59
|
+
busy?: (lines: readonly StyledLine[], turnStart: number, chrome: number, signature: CompiledSignature, context: ReadingContext) => boolean;
|
|
60
|
+
pendingComposer?: boolean;
|
|
61
|
+
/** Live answer content, outside tools and quotations; missing turn context is inconclusive. */
|
|
62
|
+
liveContent?: (lines: readonly StyledLine[], turnStart: number, candidate: number, context: ReadingContext) => boolean | 'inconclusive';
|
|
63
|
+
/** Remove a side panel only when the surrounding frame establishes its columns. */
|
|
64
|
+
inputRegion?: (lines: readonly StyledLine[], composer: number) => readonly StyledLine[];
|
|
65
|
+
}
|
|
66
|
+
/** An evidenced error at the end of an idle turn, never a phrase search. */
|
|
67
|
+
export interface StallSignature {
|
|
68
|
+
reason: string;
|
|
69
|
+
/** Fixed product wording. Never supplied by the terminal. */
|
|
70
|
+
description: string;
|
|
71
|
+
/** Complete visible marker row, excluding trailing space, before styled reads. */
|
|
72
|
+
marker: {
|
|
73
|
+
text: string | RegExp;
|
|
74
|
+
fg: string[];
|
|
75
|
+
};
|
|
76
|
+
/** Controls on the completed footer only; group 1 retains its semantic prefix. */
|
|
77
|
+
cosmetic?: RegExp;
|
|
78
|
+
/** Framing shared with the module's answer reader, independent of body text. */
|
|
79
|
+
contentRegion?: ReadingRules['contentRegion'];
|
|
80
|
+
chrome: LineTest[];
|
|
81
|
+
/** Columns whose ink establishes row ownership for cheap invalidation. */
|
|
82
|
+
frameColumns: number[];
|
|
83
|
+
before: LineTest;
|
|
84
|
+
/** Some versions omit the neutral introduction above the coloured error. */
|
|
85
|
+
beforeOptional?: boolean;
|
|
86
|
+
rows: LineTest[];
|
|
87
|
+
/** The general error message may occupy several red-gutter rows. */
|
|
88
|
+
flexibleMessage?: boolean;
|
|
89
|
+
/** A long error can leave only its coloured body visible above the footer. */
|
|
90
|
+
clippedBody?: boolean;
|
|
91
|
+
footer: LineTest;
|
|
92
|
+
composer: LineTest;
|
|
93
|
+
/** Mode row immediately before the closing edge, for partial redraw ownership. */
|
|
94
|
+
composerStatus?: LineTest;
|
|
95
|
+
/** Allowed non-blank rows of the idle composer, including placeholders. */
|
|
96
|
+
idle: LineTest[];
|
|
97
|
+
/** A styled suggestion with the shortcut's opening parenthesis at the inset right edge. */
|
|
98
|
+
idleClipped?: {
|
|
99
|
+
row: LineTest;
|
|
100
|
+
rightInset: number;
|
|
101
|
+
};
|
|
102
|
+
/** Positional rows immediately below the closing edge; later rows are output. */
|
|
103
|
+
bottom: LineTest[];
|
|
104
|
+
/** A live modal banner may interrupt a busy turn without an idle footer. */
|
|
105
|
+
overlay?: {
|
|
106
|
+
message: LineTest;
|
|
107
|
+
background: string;
|
|
108
|
+
centreOffset: number;
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* What a module can tell about typing into the composer it already describes.
|
|
113
|
+
* `queue` is a running turn whose composer is visible and empty, for a program
|
|
114
|
+
* that takes a submitted line while it works (queued or handed to the turn).
|
|
115
|
+
*/
|
|
116
|
+
export type NudgeReadiness = 'ready' | 'busy' | 'queue' | 'draft' | 'unknown';
|
|
117
|
+
/**
|
|
118
|
+
* One visible viewport. Plain rows are enough for a recorded transcript.
|
|
119
|
+
* When styled rows are set, their text is that same viewport: the ink tells
|
|
120
|
+
* the recorded placeholder from a draft. A difference is not judged.
|
|
121
|
+
*/
|
|
122
|
+
export interface NudgeView {
|
|
123
|
+
/** Cursor and optional physical cells from the same viewport as the text. */
|
|
124
|
+
cursor?: CursorPosition;
|
|
125
|
+
untrimmedRow?: (y: number) => StyledLine | undefined;
|
|
126
|
+
rows: readonly string[];
|
|
127
|
+
styled?: readonly StyledLine[];
|
|
128
|
+
/** Exact daemon line allowed in the composer during a delayed submission. */
|
|
129
|
+
expectedDraft?: string;
|
|
130
|
+
/** Require a blank composer or the module's exact known placeholder. */
|
|
131
|
+
exactEmpty?: boolean;
|
|
132
|
+
}
|
|
133
|
+
/** Internal harness data and the few detector walks not yet expressed as data. */
|
|
134
|
+
export interface AgentModule {
|
|
135
|
+
name: string;
|
|
136
|
+
programs: ProgramMatch[];
|
|
137
|
+
reading: AgentSignature;
|
|
138
|
+
prompts: PromptShape[];
|
|
139
|
+
input?: {
|
|
140
|
+
submit?: {
|
|
141
|
+
key: string;
|
|
142
|
+
delayMs?: number;
|
|
143
|
+
matches?: (data: string) => boolean;
|
|
144
|
+
/** Minimum pause for a pasted line, scaled by its length where measured. */
|
|
145
|
+
perCharacterMs?: number;
|
|
146
|
+
/** Quiet time after the draft is visible, before Enter. */
|
|
147
|
+
quietMs?: number;
|
|
148
|
+
/** Time for the composer to settle after Enter. */
|
|
149
|
+
settleMs?: number;
|
|
150
|
+
/** Extra time after the minimum pause to wait for a painted, quiet draft. */
|
|
151
|
+
maxWaitMs?: number;
|
|
152
|
+
/** A composer replacement: group 1 is the placeholder; named group chars is its length, if shown. */
|
|
153
|
+
pastePlaceholder?: RegExp;
|
|
154
|
+
};
|
|
155
|
+
resizeBehindSubmit?: boolean;
|
|
156
|
+
verifyMs?: VerifyTiming;
|
|
157
|
+
};
|
|
158
|
+
readiness?: {
|
|
159
|
+
/** Alternative literal ready signals recorded in agent-profiles.md. */
|
|
160
|
+
readyText?: string[];
|
|
161
|
+
/** A composer whose position matters as well as its text. */
|
|
162
|
+
readyScreen?: (screen: string) => boolean;
|
|
163
|
+
readyQuietMs?: number;
|
|
164
|
+
settleMs?: number;
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Whether this program's screen is idle with an empty composer.
|
|
168
|
+
* Absent means the module cannot tell, and the session is never judged ready.
|
|
169
|
+
*/
|
|
170
|
+
nudge?: {
|
|
171
|
+
readiness(view: NudgeView): NudgeReadiness;
|
|
172
|
+
/** The composer and footer text to compare across paints while a turn runs. */
|
|
173
|
+
composerBlock?: (rows: readonly string[], cursor?: CursorPosition) => string;
|
|
174
|
+
/** A separately framed idle pane whose neighbours can repaint without holding up input. */
|
|
175
|
+
idlePane?: (view: NudgeView) => string | undefined;
|
|
176
|
+
};
|
|
177
|
+
/** Conversation id exported to a child tool by this agent, when available. */
|
|
178
|
+
resumeIdMarkers?: readonly string[];
|
|
179
|
+
env?: {
|
|
180
|
+
sessionMarkers: string[];
|
|
181
|
+
};
|
|
182
|
+
safety?: SafetyAdapter;
|
|
183
|
+
stalls?: StallSignature[];
|
|
184
|
+
matchesProgram?: (pattern: ProgramMatch, program: string) => boolean;
|
|
185
|
+
createPromptSettler?: () => PromptSettler;
|
|
186
|
+
readingRules?: ReadingRules;
|
|
187
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/agents/types.ts"],"names":[],"mappings":""}
|
package/dist/cli/index.js
CHANGED
|
@@ -11,11 +11,13 @@
|
|
|
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
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
22
|
import { inspectDaemonState, readDaemonState, shellpuppetHome } from '../daemon/paths.js';
|
|
21
23
|
import { clearRestartHold, readRestartHold, writeRestartHold } from '../daemon/restartHold.js';
|
|
@@ -23,14 +25,25 @@ import { planPassedEnv } from '../mcp/config.js';
|
|
|
23
25
|
import { isEnvNamesProblem, readDaemonConfig } from '../daemon/config.js';
|
|
24
26
|
import { agentNameFor } from '../core/reasoning.js';
|
|
25
27
|
import { knownKeys } from '../core/keys.js';
|
|
26
|
-
import { listedState } from '../core/types.js';
|
|
28
|
+
import { listedState, stallLine, startReadyLine, SESSION_IDENTITY_ENV_NAMES, SESSION_IDENTITY_ENV_RULE } from '../core/types.js';
|
|
27
29
|
import { installDesktopShortcut, uninstallDesktopShortcut, userShortcutOptions } from './desktopShortcut.js';
|
|
28
30
|
const USAGE = `ShellPuppet: drive a real terminal session; humans watch and type via the viewer.
|
|
29
31
|
|
|
30
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]
|
|
31
35
|
shellpuppet start [options] <command> [args...] Launch a program in a new session
|
|
32
36
|
--label <s> --purpose <s> --cols <n> --rows <n> --cwd <dir>
|
|
33
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.
|
|
34
47
|
--env-name <NAME> (repeatable) --no-viewer
|
|
35
48
|
--no-viewer opens no dashboard or viewer window, for a short scripted session nobody
|
|
36
49
|
needs to watch; viewer-url still gives a link to it.
|
|
@@ -61,8 +74,11 @@ Usage:
|
|
|
61
74
|
Options go BEFORE the command; everything after the command is passed
|
|
62
75
|
to the daemon unchanged (so its own --flags survive).
|
|
63
76
|
shellpuppet list [--waiting] [--hide-reasoning] List sessions, or only waiting prompts
|
|
64
|
-
shellpuppet snap <id> [--last <n>] [--hide-reasoning]
|
|
77
|
+
shellpuppet snap <id> [--last <n>] [--hide-reasoning] [--wider COLSxROWS] [--wider-timeout <ms>]
|
|
65
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.
|
|
66
82
|
--hide-reasoning leaves out an agent CLI's reasoning, each block as one
|
|
67
83
|
"[reasoning hidden: N lines]" line; a session whose agent has no
|
|
68
84
|
signature is refused (exit 2), never printed unfiltered.
|
|
@@ -71,24 +87,29 @@ Usage:
|
|
|
71
87
|
reasoning. --hide-reasoning is accepted but changes nothing: result
|
|
72
88
|
always leaves reasoning out. Exits 3, with the reason on stderr, while
|
|
73
89
|
the agent is still working or when no answer is recognised.
|
|
74
|
-
shellpuppet type <id> <text> [--enter] [--verify] Type text
|
|
75
|
-
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.
|
|
76
95
|
shellpuppet key <id> <name> Press a key (enter, escape, ctrl+c, f1…)
|
|
77
|
-
shellpuppet wait <id> [--text <s>|--regex <r>|--quiet <ms>|--prompt]
|
|
96
|
+
shellpuppet wait <id> [--text <s>|--regex <r>|--quiet <ms>|--prompt|--stalled]
|
|
78
97
|
[--timeout <ms>] [--debounce <ms>] [--match-after-input true|false]
|
|
79
98
|
[--hide-reasoning]
|
|
80
99
|
Wait for a condition, print the screen
|
|
81
100
|
--prompt waits until the session asks a permission question
|
|
82
101
|
(the one you just answered does not count until it has been
|
|
83
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
|
|
84
105
|
--match-after-input true ignores text/regex matches at or
|
|
85
106
|
before the echo of what you last typed
|
|
86
107
|
--debounce waits for the condition to hold on every poll
|
|
87
108
|
for this many ms; a missed poll restarts it, while other
|
|
88
109
|
output such as a ticking timer does not; a match on the
|
|
89
110
|
final screen settles at once if the program exits
|
|
90
|
-
shellpuppet wait --prompt [id ...] [--now] [--timeout <ms>] [--hide-reasoning]
|
|
91
|
-
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,
|
|
92
113
|
or every live session if no ids are given;
|
|
93
114
|
--now polls once without waiting
|
|
94
115
|
shellpuppet find <id> <pattern> [--hide-reasoning]
|
|
@@ -123,6 +144,10 @@ Usage:
|
|
|
123
144
|
start a daemon: one that has gone is reported as not running.
|
|
124
145
|
stop: --hold [seconds] prevents auto-start for 120 s by default (1 to 600).
|
|
125
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
|
|
126
151
|
shellpuppet --version | --help
|
|
127
152
|
|
|
128
153
|
Any verb accepts --json for the raw API response.
|
|
@@ -150,7 +175,10 @@ const VALUE_FLAGS = new Set([
|
|
|
150
175
|
'cwd',
|
|
151
176
|
'ready-text',
|
|
152
177
|
'ready-quiet',
|
|
178
|
+
'ready-timeout',
|
|
153
179
|
'last',
|
|
180
|
+
'wider',
|
|
181
|
+
'wider-timeout',
|
|
154
182
|
'text',
|
|
155
183
|
'regex',
|
|
156
184
|
'quiet',
|
|
@@ -160,6 +188,11 @@ const VALUE_FLAGS = new Set([
|
|
|
160
188
|
'out',
|
|
161
189
|
'width',
|
|
162
190
|
'height',
|
|
191
|
+
'from',
|
|
192
|
+
'limit',
|
|
193
|
+
'participant',
|
|
194
|
+
'folder', 'folder-path', 'root-index', 'resume-id', 'name',
|
|
195
|
+
'mark-read',
|
|
163
196
|
]);
|
|
164
197
|
/**
|
|
165
198
|
* `stopAtFirstPositional` is how `start` avoids eating the target command's
|
|
@@ -246,6 +279,21 @@ async function call(connection, method, path, body, options = {}) {
|
|
|
246
279
|
function printJson(value) {
|
|
247
280
|
console.log(JSON.stringify(value, null, 2));
|
|
248
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
|
+
}
|
|
249
297
|
async function main() {
|
|
250
298
|
assertNodeVersion();
|
|
251
299
|
const argv = process.argv.slice(2);
|
|
@@ -289,7 +337,68 @@ async function main() {
|
|
|
289
337
|
}
|
|
290
338
|
const connection = await ensureDaemon({ logger: stderrLogger });
|
|
291
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
|
+
}
|
|
292
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
|
+
}
|
|
293
402
|
case 'start': {
|
|
294
403
|
const command = parsed.positionals[0];
|
|
295
404
|
if (command === undefined)
|
|
@@ -308,6 +417,8 @@ async function main() {
|
|
|
308
417
|
...(parsed.flags.has('ready-text')
|
|
309
418
|
? { readyText: String(parsed.flags.get('ready-text')) }
|
|
310
419
|
: {}),
|
|
420
|
+
...(parsed.flags.get('wait-ready') === true ? { waitReady: true } : {}),
|
|
421
|
+
...(intFlag(parsed, 'ready-timeout') !== undefined ? { readyTimeout: intFlag(parsed, 'ready-timeout') } : {}),
|
|
311
422
|
...(intFlag(parsed, 'ready-quiet') !== undefined
|
|
312
423
|
? { readyQuiet: intFlag(parsed, 'ready-quiet') }
|
|
313
424
|
: {}),
|
|
@@ -320,6 +431,9 @@ async function main() {
|
|
|
320
431
|
const daemonConfig = readDaemonConfig(shellpuppetHome());
|
|
321
432
|
const agent = agentNameFor(parsed.flags.has('agent') ? String(parsed.flags.get('agent')) : undefined, command, daemonConfig.config.agentSignatures ?? []);
|
|
322
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(', ')}.`);
|
|
323
437
|
if (envNames.length > 0) {
|
|
324
438
|
for (const problem of daemonConfig.problems.filter(isEnvNamesProblem))
|
|
325
439
|
console.error(`warning: ${problem}`);
|
|
@@ -381,7 +495,13 @@ async function main() {
|
|
|
381
495
|
else {
|
|
382
496
|
console.log(`viewer: no window opened (--no-viewer); viewer-url ${String(result['id'])} mints a link`);
|
|
383
497
|
}
|
|
384
|
-
|
|
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) {
|
|
385
505
|
console.log('ready: false. First paint is not readiness; wait before typing.');
|
|
386
506
|
}
|
|
387
507
|
}
|
|
@@ -413,8 +533,9 @@ async function main() {
|
|
|
413
533
|
}
|
|
414
534
|
console.log(`${s.id} ${listedState(s)} ` +
|
|
415
535
|
`${String(s.cols)}x${String(s.rows)} watchers:${String(s.watchers)} ` +
|
|
416
|
-
`${s.ready ? 'ready' : 'NOT-READY'} ${s.label}` +
|
|
417
|
-
(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}` : ''));
|
|
418
539
|
const waiting = s.waitingOnPrompt;
|
|
419
540
|
if (waiting !== undefined) {
|
|
420
541
|
console.log(` WAITING ${String(Math.round(waiting.waitingMs / 1000))}s on a prompt` +
|
|
@@ -428,12 +549,19 @@ async function main() {
|
|
|
428
549
|
case 'snap': {
|
|
429
550
|
const id = parsed.positionals[0] ?? fail(2, 'snap needs a session id.');
|
|
430
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.');
|
|
431
555
|
const query = [
|
|
432
556
|
...(last !== undefined ? [`lastLines=${String(last)}`] : []),
|
|
433
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'))}`] : []),
|
|
434
560
|
];
|
|
435
561
|
const path = `/sessions/${id}/snapshot${query.length > 0 ? `?${query.join('&')}` : ''}`;
|
|
436
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.');
|
|
437
565
|
if (wantJson)
|
|
438
566
|
printJson(result);
|
|
439
567
|
else if (last !== undefined)
|
|
@@ -474,6 +602,13 @@ async function main() {
|
|
|
474
602
|
});
|
|
475
603
|
if (wantJson)
|
|
476
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
|
+
}
|
|
477
612
|
else if (result['verified'] === false) {
|
|
478
613
|
console.log('typed, but the text did NOT appear on screen. The app may still be ' +
|
|
479
614
|
'loading, a panel may have focus or, commonly with --enter, the app ' +
|
|
@@ -487,7 +622,8 @@ async function main() {
|
|
|
487
622
|
// knowing the keystrokes landed, so say so rather than printing the
|
|
488
623
|
// same line as an unverified type.
|
|
489
624
|
console.log(`typed ${String(result['bytes'])} bytes` +
|
|
490
|
-
(result['verified'] === true ? ' (verified on screen).' : '.')
|
|
625
|
+
(result['verified'] === true ? ' (verified on screen).' : '.') +
|
|
626
|
+
(typeof result['message'] === 'string' ? ` ${result['message']}` : ''));
|
|
491
627
|
}
|
|
492
628
|
break;
|
|
493
629
|
}
|
|
@@ -502,9 +638,17 @@ async function main() {
|
|
|
502
638
|
break;
|
|
503
639
|
}
|
|
504
640
|
case 'wait': {
|
|
505
|
-
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);
|
|
506
642
|
if (multi) {
|
|
507
|
-
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');
|
|
508
652
|
for (const id of parsed.positionals)
|
|
509
653
|
params.append('session', id);
|
|
510
654
|
if (parsed.flags.get('now') === true)
|
|
@@ -518,6 +662,10 @@ async function main() {
|
|
|
518
662
|
printJson(result);
|
|
519
663
|
else {
|
|
520
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
|
+
}
|
|
521
669
|
console.log(`${waiting.id} ${waiting.label} WAITING ${String(Math.round(waiting.waitingMs / 1000))}s` + (waiting.question === undefined ? '' : `: ${waiting.question}`));
|
|
522
670
|
for (const [index, option] of (waiting.options ?? []).entries())
|
|
523
671
|
console.log(` ${index === waiting.selectedOption ? '* ' : ' '}${option}`);
|
|
@@ -530,7 +678,7 @@ async function main() {
|
|
|
530
678
|
}
|
|
531
679
|
const id = parsed.positionals[0] ?? fail(2, 'wait needs a session id.');
|
|
532
680
|
const params = new URLSearchParams();
|
|
533
|
-
for (const name of ['text', 'regex', 'quiet', 'timeout', 'debounce', 'prompt']) {
|
|
681
|
+
for (const name of ['text', 'regex', 'quiet', 'timeout', 'debounce', 'prompt', 'stalled']) {
|
|
534
682
|
const value = parsed.flags.get(name);
|
|
535
683
|
if (value !== undefined)
|
|
536
684
|
params.set(name, String(value));
|
|
@@ -551,6 +699,8 @@ async function main() {
|
|
|
551
699
|
// line.
|
|
552
700
|
if (typeof result['detail'] === 'string')
|
|
553
701
|
console.error(result['detail']);
|
|
702
|
+
if (result['stalled'] !== undefined)
|
|
703
|
+
console.error(stallLine(result['stalled']));
|
|
554
704
|
const detected = result['prompt'];
|
|
555
705
|
if (detected !== undefined) {
|
|
556
706
|
// stderr, like the outcome line: stdout stays the screen alone, so
|
|
@@ -704,11 +854,13 @@ async function daemonVerb(parsed, wantJson) {
|
|
|
704
854
|
// daemon must never start one, so a daemon that goes between being found
|
|
705
855
|
// and being asked is reported as not running.
|
|
706
856
|
const daemonOnly = { autoStart: false };
|
|
857
|
+
const shutdownWarnings = [];
|
|
858
|
+
const warningFields = () => shutdownWarnings.length ? { warnings: shutdownWarnings } : {};
|
|
707
859
|
/** Stop the daemon, or say false when it had already gone. */
|
|
708
860
|
const stopRunning = async (connection) => {
|
|
709
861
|
let response;
|
|
710
862
|
try {
|
|
711
|
-
response = await request(connection, 'POST', '/daemon/shutdown', { force }, {
|
|
863
|
+
response = await request(connection, 'POST', '/daemon/shutdown', { force, ...(sub === 'restart' || holdSeconds !== undefined ? { restart: true } : {}) }, {
|
|
712
864
|
logger: stderrLogger,
|
|
713
865
|
actor: 'cli',
|
|
714
866
|
...daemonOnly,
|
|
@@ -722,6 +874,20 @@ async function daemonVerb(parsed, wantJson) {
|
|
|
722
874
|
if (response.status === 409) {
|
|
723
875
|
fail(1, `${String(response.body['error'])} (use --force)`);
|
|
724
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
|
+
}
|
|
725
891
|
// Wait for the port to actually go quiet so restart cannot race it.
|
|
726
892
|
const deadline = Date.now() + 10_000;
|
|
727
893
|
while (Date.now() < deadline) {
|
|
@@ -833,7 +999,7 @@ async function daemonVerb(parsed, wantJson) {
|
|
|
833
999
|
return didStop;
|
|
834
1000
|
});
|
|
835
1001
|
if (wantJson)
|
|
836
|
-
printJson({ running: false, stopped: true, holdRemainingSeconds: holdSeconds });
|
|
1002
|
+
printJson({ running: false, stopped: true, ...warningFields(), holdRemainingSeconds: holdSeconds });
|
|
837
1003
|
else
|
|
838
1004
|
console.log(stopped ? `stopped; restart hold ends in ${String(holdSeconds)} s` :
|
|
839
1005
|
`not running; restart hold ends in ${String(holdSeconds)} s`);
|
|
@@ -845,13 +1011,13 @@ async function daemonVerb(parsed, wantJson) {
|
|
|
845
1011
|
// Nothing to stop IS the outcome asked for, so it reads the same to a
|
|
846
1012
|
// script as a daemon that was stopped.
|
|
847
1013
|
if (wantJson)
|
|
848
|
-
printJson({ running: false, stopped: true });
|
|
1014
|
+
printJson({ running: false, stopped: true, ...warningFields() });
|
|
849
1015
|
else
|
|
850
1016
|
console.log('not running');
|
|
851
1017
|
return;
|
|
852
1018
|
}
|
|
853
1019
|
if (wantJson)
|
|
854
|
-
printJson({ running: false, stopped: true });
|
|
1020
|
+
printJson({ running: false, stopped: true, ...warningFields() });
|
|
855
1021
|
else
|
|
856
1022
|
console.log('stopped');
|
|
857
1023
|
return;
|
|
@@ -885,7 +1051,7 @@ async function daemonVerb(parsed, wantJson) {
|
|
|
885
1051
|
});
|
|
886
1052
|
surfaceWarnings(connection);
|
|
887
1053
|
if (wantJson) {
|
|
888
|
-
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 });
|
|
889
1055
|
}
|
|
890
1056
|
else {
|
|
891
1057
|
console.log(`restarted on port ${String(connection.port)}, version ${connection.version}`);
|