@rarog/server 1.1.1 → 1.1.2-beta.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/node_modules/@rarog/shared/package.json +1 -1
- package/node_modules/@rarog/shared/src/decode.js +46 -1
- package/node_modules/@rarog/shared/src/notify-copy.js +2 -0
- package/node_modules/@rarog/shared/src/protocol/background.js +7 -0
- package/node_modules/@rarog/shared/src/protocol/context.js +57 -0
- package/node_modules/@rarog/shared/src/protocol/coordination.js +42 -0
- package/node_modules/@rarog/shared/src/protocol/dialog-live.js +117 -0
- package/node_modules/@rarog/shared/src/protocol/files.js +1 -1
- package/node_modules/@rarog/shared/src/protocol/inbox.js +6 -0
- package/node_modules/@rarog/shared/src/protocol/presence.js +47 -0
- package/node_modules/@rarog/shared/src/protocol.js +14 -146
- package/node_modules/@rarog/shared/src/rest.js +16 -1
- package/node_modules/@rarog/shared/src/sentences/dialogs.js +10 -0
- package/node_modules/@rarog/shared/src/sentences/push.js +9 -0
- package/node_modules/@rarog/shared/src/sentences/rest.js +9 -0
- package/node_modules/@rarog/shared/src/sentences/restart.js +1 -0
- package/node_modules/@rarog/shared/src/sentences/session.js +24 -0
- package/package.json +2 -2
- package/plugin/rarog/.claude-plugin/plugin.json +4 -0
- package/plugin/rarog/bin/rarog-coordinator +7 -0
- package/plugin/rarog/hooks/hooks.json +18 -0
- package/plugin/rarog/hooks/recipient.mjs +95 -0
- package/plugin/rarog/lib/coordinator.mjs +1340 -0
- package/plugin/rarog/lib/threads.mjs +350 -0
- package/plugin/rarog/skills/coordinator/SKILL.md +111 -0
- package/plugin/rarog/skills/coordinator/check-and-merge.md +46 -0
- package/plugin/rarog/skills/coordinator/close-thread.md +15 -0
- package/plugin/rarog/skills/coordinator/role.md +61 -0
- package/plugin/rarog/skills/coordinator/send-back.md +39 -0
- package/plugin/rarog/skills/coordinator/start-thread.md +43 -0
- package/server/src/bootstrap/coordination.js +49 -0
- package/server/src/bootstrap/coordinator-start.js +27 -0
- package/server/src/bootstrap/inbox.js +4 -0
- package/server/src/bootstrap/pr-status.js +15 -7
- package/server/src/bootstrap/push.js +59 -5
- package/server/src/cli/doctor-pr-status.js +10 -6
- package/server/src/companion/catalog.js +1 -1
- package/server/src/companion/index.js +2 -4
- package/server/src/config/flags.js +4 -0
- package/server/src/config-env.js +15 -0
- package/server/src/config.js +17 -3
- package/server/src/coordination/merge-events.js +86 -0
- package/server/src/coordination/merge-prompt.js +244 -0
- package/server/src/coordination/registry.js +289 -0
- package/server/src/coordination/state.js +94 -0
- package/server/src/coordination/summary.js +422 -0
- package/server/src/coordination/thread-file.js +245 -0
- package/server/src/coordination/thread-git.js +110 -0
- package/server/src/coordination/watch.js +237 -0
- package/server/src/demo/content/coordinator.js +89 -0
- package/server/src/demo/content/en.js +57 -1
- package/server/src/demo/content/pl.js +57 -1
- package/server/src/demo/control.js +4 -2
- package/server/src/demo/inbox.js +12 -0
- package/server/src/demo/mock-herdr.js +5 -4
- package/server/src/demo/review-routes.js +2 -2
- package/server/src/demo/scenarios.js +31 -17
- package/server/src/demo/seeds.js +82 -40
- package/server/src/drivers/herdr/live-dialog.js +412 -0
- package/server/src/drivers/herdr/live-step.js +261 -0
- package/server/src/drivers/herdr/pause-gate.js +60 -0
- package/server/src/drivers/herdr/pull-request-poll.js +5 -5
- package/server/src/drivers/herdr/queue-take-back.js +4 -0
- package/server/src/drivers/herdr/returned-prompt.js +4 -1
- package/server/src/drivers/herdr/screen-fallback.js +50 -0
- package/server/src/drivers/herdr/start-dialog-gate.js +136 -0
- package/server/src/drivers/herdr-driver.js +159 -77
- package/server/src/files/refusals.js +9 -2
- package/server/src/files/session-gate.js +5 -4
- package/server/src/git-branch-diff.js +194 -0
- package/server/src/herdr/argv.js +34 -3
- package/server/src/herdr/audit.js +32 -1
- package/server/src/herdr/background/cli-shapes.js +35 -15
- package/server/src/herdr/background/index.js +7 -7
- package/server/src/herdr/background/merge.js +17 -5
- package/server/src/herdr/background/notification.js +0 -4
- package/server/src/herdr/background/pull-request-files.js +53 -161
- package/server/src/herdr/background/pull-requests.js +54 -632
- package/server/src/herdr/background/queued-prompt.js +46 -0
- package/server/src/herdr/background/work.js +96 -0
- package/server/src/herdr/client.js +22 -46
- package/server/src/herdr/commands/catalog.js +11 -7
- package/server/src/herdr/commands/discover.js +33 -1
- package/server/src/herdr/commands/index.js +3 -2
- package/server/src/herdr/dialogs/copy.js +7 -0
- package/server/src/herdr/dialogs/index.js +13 -1
- package/server/src/herdr/dialogs/layer1/hook-list/hook-list.js +4 -56
- package/server/src/herdr/dialogs/live/model.js +220 -0
- package/server/src/herdr/dialogs/live/policy.js +108 -0
- package/server/src/herdr/dialogs/live/view.js +261 -0
- package/server/src/herdr/dialogs/screen/form.js +6 -4
- package/server/src/herdr/dialogs/screen/option-run.js +25 -3
- package/server/src/herdr/dialogs/screen/parse.js +3 -3
- package/server/src/herdr/dialogs/screen/signatures.js +78 -0
- package/server/src/herdr/dialogs/screen/start-dialog.js +72 -0
- package/server/src/herdr/dialogs/screen/trust-arrow.js +46 -9
- package/server/src/herdr/engines.js +96 -0
- package/server/src/herdr/history-steps.js +9 -4
- package/server/src/herdr/identity.js +20 -5
- package/server/src/herdr/jsonl-follow.js +26 -3
- package/server/src/herdr/label-code.js +104 -0
- package/server/src/herdr/label-migration.js +142 -0
- package/server/src/herdr/launcher.js +30 -5
- package/server/src/herdr/plugin-copy.js +281 -0
- package/server/src/herdr/provenance.js +80 -40
- package/server/src/herdr/session-index.js +19 -0
- package/server/src/herdr/start-dialog-wait.js +96 -0
- package/server/src/herdr/supervisor.js +49 -23
- package/server/src/herdr/types.js +1 -0
- package/server/src/herdr/workspace-resolver.js +5 -4
- package/server/src/inbox/card.js +31 -8
- package/server/src/inbox/heads.js +1 -0
- package/server/src/inbox/inbox.js +21 -4
- package/server/src/inbox/removals.js +10 -1
- package/server/src/index.js +45 -8
- package/server/src/notify/apns-payload.js +5 -3
- package/server/src/notify/content.js +64 -0
- package/server/src/notify/index.js +11 -3
- package/server/src/notify/live-activity-state.js +19 -6
- package/server/src/notify/live-activity.js +5 -2
- package/server/src/notify/policy.js +53 -13
- package/server/src/notify/ready-to-merge.js +148 -0
- package/server/src/notify/stalled-wait.js +213 -0
- package/server/src/pr-status/facts.js +87 -0
- package/server/src/pr-status/gh.js +76 -9
- package/server/src/pr-status/index.js +1 -10
- package/server/src/pr-status/source.js +20 -6
- package/server/src/pr-status/tracker.js +32 -9
- package/server/src/project-root.js +233 -0
- package/server/src/routes/sessions.js +68 -2
- package/server/src/sessions/branch-diff.js +57 -0
- package/server/src/sessions/cli-registry.js +17 -3
- package/server/src/sessions/companion-scope.js +2 -1
- package/server/src/sessions/consent-cards.js +49 -2
- package/server/src/sessions/conversation-lists.js +11 -2
- package/server/src/sessions/coordinator-start.js +172 -0
- package/server/src/sessions/demo-modules.js +1 -0
- package/server/src/sessions/demo-seeds.js +100 -0
- package/server/src/sessions/driver-events.js +68 -14
- package/server/src/sessions/herdr-lifecycle.js +11 -4
- package/server/src/sessions/interrupt-windows.js +28 -4
- package/server/src/sessions/launch-gate.js +36 -11
- package/server/src/sessions/live-dialog.js +69 -0
- package/server/src/sessions/manager.js +138 -287
- package/server/src/sessions/owner-turn.js +36 -0
- package/server/src/sessions/pr-status-link.js +64 -16
- package/server/src/sessions/seen-marks.js +31 -12
- package/server/src/sessions/session-dialog.js +82 -0
- package/server/src/sessions/session-git.js +1 -0
- package/server/src/sessions/session-scope.js +6 -5
- package/server/src/sessions/session-take-back.js +5 -0
- package/server/src/sessions/session.js +82 -10
- package/server/src/sessions/state-machine.js +13 -0
- package/server/src/sessions/state-sentences.js +87 -30
- package/server/src/sessions/test-session.js +50 -0
- package/server/src/sessions/waiting-line.js +49 -0
- package/server/src/term/herdr-backend.js +15 -12
- package/server/src/term/lifecycle.js +4 -6
- package/server/src/transcript-import.js +20 -2
- package/server/src/version.js +4 -0
- /package/server/src/{companion/asks-owner.js → asks-owner.js} +0 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Esc gate of the "Session paused" dialog (`docs/dialogs.md`, "CLI dialogs answered in the terminal"): the pause trace
|
|
3
|
+
* that every dialog screen read leaves in the blocked state, and the fresh read right before an Esc that refuses
|
|
4
|
+
* the key on a pause. It only judges; the driver facade sends or refuses the key. It does not import the facade.
|
|
5
|
+
*/
|
|
6
|
+
import { SESSION_PAUSED_DIALOG, parseOptions, sessionPausedDialog } from '../../herdr/dialogs/index.js';
|
|
7
|
+
export class PauseGate {
|
|
8
|
+
/**
|
|
9
|
+
* Numer blokady, w której ostatni odczyt ekranu pokazał pauzę „Session paused” (`pauseBlocksEscape`);
|
|
10
|
+
* `null` = żaden. Przeżywa odmowę Esc, zgaszoną kartę i odczyt bez dialogu (przemalowanie); zdejmuje go
|
|
11
|
+
* dopiero odczyt z INNYM czytelnym dialogiem, a koniec blokady albo nowa blokada go unieważniają.
|
|
12
|
+
*/
|
|
13
|
+
#pauseSeq = null;
|
|
14
|
+
#port;
|
|
15
|
+
constructor(port) {
|
|
16
|
+
this.#port = port;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Czy `escape` trafiłby w pauzę „Session paused"?
|
|
20
|
+
*
|
|
21
|
+
* Esc zmierzono tylko na pauzie wywołanej atrapą API (CLI 2.1.322), bo prawdziwej pauzy nie wolno wywołać celowo
|
|
22
|
+
* (to mechanizm bezpieczeństwa modelu), a pauza nie ma stopki, która by go nazywała. Dlatego „Odrzuć" i przerwanie
|
|
23
|
+
* nie wysyłają na nią klawisza.
|
|
24
|
+
*
|
|
25
|
+
* Ekran czytamy ŚWIEŻO, tuż przed klawiszem (`readFresh` — ten sam ekran trafia do zrzutu odmowy),
|
|
26
|
+
* przy każdej blokadzie (`blockedNow`): karta i ostatni odczyt nie dowodzą, że pauzy nie ma — dialog
|
|
27
|
+
* potrafi się podmienić w miejscu, zanim ocena przeczyta ekran. Bez blokady
|
|
28
|
+
* i bez podejrzenia Esc idzie jak dotąd, bez odczytu (przerwanie zwykłej tury). Podejrzenie pauzy to karta
|
|
29
|
+
* pauzy albo ślad pauzy z odczytu w tej blokadzie (`#pauseSeq`, przeżywa odmowę i zgaszoną kartę).
|
|
30
|
+
* Odmowa, gdy:
|
|
31
|
+
* - pauza stoi na świeżym ekranie (`sessionPausedDialog` — każdy wariant, także spoza listy);
|
|
32
|
+
* - przy podejrzeniu: odczyt się nie udał albo ekran nie pokazuje żadnego dialogu (przemalowanie) —
|
|
33
|
+
* nie wiadomo, czy pauza zeszła.
|
|
34
|
+
* Inny czytelny dialog = pauza zeszła (ślad gaśnie w `notePause`), Esc idzie jak dotąd.
|
|
35
|
+
*
|
|
36
|
+
* @returns `blocks` = odmowa; `text` = świeży ekran tej bramki (`null` bez odczytu albo po nieudanym), z którego
|
|
37
|
+
* „Odrzuć” po klawiszu poznaje zamknięty dialog (driver, `#clearHookAfterDecision`)
|
|
38
|
+
*/
|
|
39
|
+
async pauseBlocksEscape() {
|
|
40
|
+
const suspected = this.#port.activeTerminalDialog() === SESSION_PAUSED_DIALOG
|
|
41
|
+
|| (this.#pauseSeq === this.#port.blockedSeq() && this.#port.blockedNow());
|
|
42
|
+
if (!suspected && !this.#port.blockedNow())
|
|
43
|
+
return { blocks: false, text: null };
|
|
44
|
+
const text = await this.#port.readFresh();
|
|
45
|
+
if (text === null)
|
|
46
|
+
return { blocks: suspected, text: null };
|
|
47
|
+
const fresh = parseOptions(text);
|
|
48
|
+
return { blocks: fresh === null ? suspected : sessionPausedDialog(fresh), text };
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Ślad pauzy z KAŻDEGO odczytu ekranu dialogu (`#pauseSeq`): pauza zapisuje numer blokady, inny czytelny
|
|
52
|
+
* dialog go zdejmuje, ekran bez dialogu (przemalowanie, odczyt w pół klatki) zostawia go bez zmian.
|
|
53
|
+
*/
|
|
54
|
+
notePause(text) {
|
|
55
|
+
const dialog = parseOptions(text);
|
|
56
|
+
if (dialog === null)
|
|
57
|
+
return;
|
|
58
|
+
this.#pauseSeq = sessionPausedDialog(dialog) ? this.#port.blockedSeq() : null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { PULL_REQUESTS_BACKLOG_MS,
|
|
1
|
+
import { PULL_REQUESTS_BACKLOG_MS, pullRequestLinksSignature } from '../../herdr/background/index.js';
|
|
2
2
|
export function createPullRequestPollState(prReader, prPollMs) {
|
|
3
|
-
return { prReader, prPollMs, prTimer: null, prReading: false, prAgain: false, prSent:
|
|
3
|
+
return { prReader, prPollMs, prTimer: null, prReading: false, prAgain: false, prSent: pullRequestLinksSignature({ linked: [], windowStart: null }) };
|
|
4
4
|
}
|
|
5
5
|
/**
|
|
6
6
|
* Zamawia odczyt plików rozmowy pod kątem PR-ów za `delayMs`. Sygnały, które przyjdą, zanim zegar
|
|
@@ -21,7 +21,7 @@ export function schedulePullRequests(state, deps, delayMs = state.prPollMs) {
|
|
|
21
21
|
}, delayMs);
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
24
|
+
* One PR read and the payout of the links when they differ from the ones sent (the set or the window). Zaległość odczytu
|
|
25
25
|
* (budżet bajtów) zamawia następny po krótkiej przerwie, bez czekania na sygnał.
|
|
26
26
|
*/
|
|
27
27
|
export async function readPullRequests(state, deps) {
|
|
@@ -41,10 +41,10 @@ export async function readPullRequests(state, deps) {
|
|
|
41
41
|
if (read === null)
|
|
42
42
|
return;
|
|
43
43
|
backlog = read.backlog;
|
|
44
|
-
const signature =
|
|
44
|
+
const signature = pullRequestLinksSignature(read.links);
|
|
45
45
|
if (signature !== state.prSent) {
|
|
46
46
|
state.prSent = signature;
|
|
47
|
-
deps.emit(read.
|
|
47
|
+
deps.emit(read.links);
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
finally {
|
|
@@ -85,6 +85,10 @@ export class QueueTakeBack {
|
|
|
85
85
|
return this.#refuse('pane');
|
|
86
86
|
if (this.#field.holdsField())
|
|
87
87
|
return this.#refuse('busy');
|
|
88
|
+
if (await this.#port.startDialogStands())
|
|
89
|
+
return this.#refuse('dialog');
|
|
90
|
+
if (this.#port.disposed())
|
|
91
|
+
return this.#refuse('pane');
|
|
88
92
|
// The last Enter from Rarog's queue first: a hook may still hand its text back to the field.
|
|
89
93
|
while (this.#queue.submitUnsettled()) {
|
|
90
94
|
await this.#sleep(this.#pollMs);
|
|
@@ -49,12 +49,15 @@ export class ReturnedPrompt {
|
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
51
|
* Human prompts of the conversation file, in file order: the newest one is the turn's prompt. A harness notice, a
|
|
52
|
-
* command output and an entry with an image are no prompt the field could show as text
|
|
52
|
+
* command output and an entry with an image are no prompt the field could show as text, and a message from another
|
|
53
|
+
* session was typed into no field.
|
|
53
54
|
*/
|
|
54
55
|
noteFile(entries) {
|
|
55
56
|
for (const entry of entries) {
|
|
56
57
|
if (entry.role !== 'user' || entry.notice !== undefined || entry.commandOutput !== undefined)
|
|
57
58
|
continue;
|
|
59
|
+
if (entry.peer === true)
|
|
60
|
+
continue;
|
|
58
61
|
const texts = entry.blocks.map((block) => (block.type === 'text' && !('ref' in block.text) ? block.text.text : null));
|
|
59
62
|
if (texts.length > 0 && texts.every((text) => text !== null))
|
|
60
63
|
this.#note(texts.join('\n'));
|
|
@@ -106,6 +106,36 @@ export class ScreenFallback {
|
|
|
106
106
|
return refuse('judgement');
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* The consent channel facts of the live dialog card (`herdr/dialogs/live/policy.ts`): the live mode, the judgement of
|
|
111
|
+
* the standing no-hook episode, the hook trace and the hook requests now, the hook process and a foreign hook from the
|
|
112
|
+
* judgement, the restart grace. `toolUse`: the transcript entry of the dialog on screen is known. `episode: false`:
|
|
113
|
+
* the standing episode came with a card of another dialog than the one on screen, so the facts are those without an
|
|
114
|
+
* episode. A fact that cannot be read is a doubt (`null`, or the value that refuses Enter); never throws.
|
|
115
|
+
*/
|
|
116
|
+
liveFacts(toolUse, episode) {
|
|
117
|
+
const sources = this.#deps.consentNoHook;
|
|
118
|
+
let mode = null;
|
|
119
|
+
try {
|
|
120
|
+
mode = consentModeNow(this.#deps);
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
mode = null;
|
|
124
|
+
}
|
|
125
|
+
let standing = null;
|
|
126
|
+
try {
|
|
127
|
+
standing = episode ? this.#port.standing() : null;
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
standing = null;
|
|
131
|
+
}
|
|
132
|
+
const judgement = standing?.judgement ?? null;
|
|
133
|
+
return {
|
|
134
|
+
mode, judged: judgement !== null, trace: standing === null ? null : this.#trace(sources, standing),
|
|
135
|
+
hookWaits: this.#hookWaits(), hookRunning: judgement?.hookRunning ?? null,
|
|
136
|
+
foreignHook: judgement?.foreignHook ?? null, restarting: this.#restarting(sources), toolUse,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
109
139
|
/**
|
|
110
140
|
* The guard that takes the button of a marked card under the live mode and class, the ones the card gate read when
|
|
111
141
|
* it refused the digit; `mode` when the rule cannot be asked.
|
|
@@ -136,6 +166,26 @@ export class ScreenFallback {
|
|
|
136
166
|
// The late hook then goes the desk fallback way.
|
|
137
167
|
}
|
|
138
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Enter of the live dialog card (`live-step.ts`) is about to go to the dialog of a permission card's call in channel
|
|
171
|
+
* mode `main` or `all`: the consent cycle notes it like a digit ({@link keyNoted}), with the call input and the start
|
|
172
|
+
* of the standing no-hook episode, so that a hook of this dialog whose request comes after the note goes back to the
|
|
173
|
+
* terminal. Without an episode or outside those modes nothing is noted. Synchronous, right before the key.
|
|
174
|
+
*/
|
|
175
|
+
liveKeyNoted(toolName, input) {
|
|
176
|
+
try {
|
|
177
|
+
const mode = consentModeNow(this.#deps);
|
|
178
|
+
const standing = this.#port.standing();
|
|
179
|
+
if ((mode !== 'main' && mode !== 'all') || standing === null)
|
|
180
|
+
return;
|
|
181
|
+
this.#deps.consentNoHook?.screenKey?.(standing.sessionId, {
|
|
182
|
+
toolName, inputSha256: canonicalSha256(input), at: this.#deps.now(), since: standing.t0,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
// The late hook then goes the desk fallback way.
|
|
187
|
+
}
|
|
188
|
+
}
|
|
139
189
|
/** The digit went out: the `screen fallback key` line. */
|
|
140
190
|
keySent(verdict) {
|
|
141
191
|
this.#log(screenFallbackKeyLine(verdict.line));
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { START_DIALOG_IMPORTS_MESSAGE, START_DIALOG_UNKNOWN_MESSAGE, resolveOptions, startDialogOf, } from '../../herdr/dialogs/index.js';
|
|
2
|
+
import { stripTerminalControl } from '../../herdr/dialogs/screen/text.js';
|
|
3
|
+
import { composerRegionState } from './commands.js';
|
|
4
|
+
/**
|
|
5
|
+
* Another dialog Rarog reads: a known dialog (also the trust dialog without digits) or a form of a question or
|
|
6
|
+
* a consent. A bare list of digits is not one: an unknown start dialog may number its options too.
|
|
7
|
+
*/
|
|
8
|
+
function readableDialog(text) {
|
|
9
|
+
const resolved = resolveOptions(text, null);
|
|
10
|
+
return resolved.status === 'no-jsonl' && (resolved.knownDialog !== null || resolved.questionForm !== null);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* One screen of a pane in its start phase. Gone takes positive proof: the prompt field, or another dialog Rarog
|
|
14
|
+
* reads. The external imports dialog stands on its signature; any other screen without the prompt field stands only
|
|
15
|
+
* when the launcher found an unknown start dialog, because the bypass mode warning looks the same and herdr reports
|
|
16
|
+
* it `blocked` itself. A blank screen proves nothing.
|
|
17
|
+
*/
|
|
18
|
+
export function readStartDialog(text, phase) {
|
|
19
|
+
if (composerRegionState(text) !== 'unknown')
|
|
20
|
+
return 'gone';
|
|
21
|
+
const dialog = startDialogOf(text);
|
|
22
|
+
if (dialog === null)
|
|
23
|
+
return 'unclear';
|
|
24
|
+
if (dialog.id === 'external-imports')
|
|
25
|
+
return dialog;
|
|
26
|
+
if (readableDialog(text))
|
|
27
|
+
return 'gone';
|
|
28
|
+
return phase.startDialog !== null && phase.startDialog.id === null ? dialog : 'unclear';
|
|
29
|
+
}
|
|
30
|
+
export class StartDialogGate {
|
|
31
|
+
#port;
|
|
32
|
+
/** The start dialog the last screen proving anything (or the launcher) showed; a failed or blank read keeps it. */
|
|
33
|
+
#standing = null;
|
|
34
|
+
/** The launcher's dialog is in the memory already: it counts once, so a screen proving it gone ends it for good. */
|
|
35
|
+
#launcherTaken = false;
|
|
36
|
+
/** The dialog whose sentence the transcript has (`id`, or the title of an unknown one). */
|
|
37
|
+
#announced = null;
|
|
38
|
+
constructor(port) {
|
|
39
|
+
this.#port = port;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* One successful screen read of the pane (every dialog read of the driver goes here).
|
|
43
|
+
*
|
|
44
|
+
* @returns `true` when a start dialog stands that the last screen proving anything did not show: a new dialog
|
|
45
|
+
*/
|
|
46
|
+
note(text) {
|
|
47
|
+
const phase = this.#phase();
|
|
48
|
+
const read = phase === null ? 'gone' : readStartDialog(text, phase);
|
|
49
|
+
if (read === 'unclear')
|
|
50
|
+
return false;
|
|
51
|
+
const before = this.#standing;
|
|
52
|
+
this.#standing = read === 'gone' ? null : read;
|
|
53
|
+
return this.#standing !== null && (before === null || identityOf(before) !== identityOf(this.#standing));
|
|
54
|
+
}
|
|
55
|
+
/** Whether the pane is in its start phase, so a start dialog may stand; no read. */
|
|
56
|
+
inPhase() {
|
|
57
|
+
return this.#port.startPhase() !== null;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Whether the remembered dialog refuses a key or text now, without a read: for a send that must reach the client
|
|
61
|
+
* with no `await` after its own checks. The callers that decide on a key read fresh ({@link refuses}) first.
|
|
62
|
+
*/
|
|
63
|
+
holds() {
|
|
64
|
+
return this.#phase() !== null && this.#standing !== null;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Whether a key or text to the pane is refused: judged on `fresh` (a screen the caller has just read) or on a read
|
|
68
|
+
* made here, and on the remembered dialog when the read fails or proves nothing. Outside the start phase it reads
|
|
69
|
+
* nothing and refuses nothing.
|
|
70
|
+
*/
|
|
71
|
+
async refuses(fresh = null) {
|
|
72
|
+
if (this.#phase() === null) {
|
|
73
|
+
this.#standing = null;
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
const text = fresh ?? await this.#port.readScreen();
|
|
77
|
+
if (text !== null)
|
|
78
|
+
this.note(text);
|
|
79
|
+
return this.#standing !== null;
|
|
80
|
+
}
|
|
81
|
+
/** The start dialog remembered now, without a read; `null` outside the start phase or when none stands. */
|
|
82
|
+
standing() {
|
|
83
|
+
return this.#phase() === null ? null : this.#standing;
|
|
84
|
+
}
|
|
85
|
+
/** A card was shown: the sentence of the start dialog under it, once per dialog. */
|
|
86
|
+
cardShown() {
|
|
87
|
+
const dialog = this.#phase() === null ? null : this.#standing;
|
|
88
|
+
if (dialog === null)
|
|
89
|
+
return;
|
|
90
|
+
const identity = identityOf(dialog);
|
|
91
|
+
if (this.#announced === identity)
|
|
92
|
+
return;
|
|
93
|
+
this.#announced = identity;
|
|
94
|
+
this.#port.system(dialog.id === 'external-imports' ? START_DIALOG_IMPORTS_MESSAGE : START_DIALOG_UNKNOWN_MESSAGE);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The start phase now. The dialog the launcher found on its own read goes into the memory the first time it is
|
|
98
|
+
* known, as proof that it stands: before any read of the driver, and through failed or blank reads, the gate
|
|
99
|
+
* refuses until a screen proves it gone.
|
|
100
|
+
*/
|
|
101
|
+
#phase() {
|
|
102
|
+
const phase = this.#port.startPhase();
|
|
103
|
+
if (phase !== null && phase.startDialog !== null && !this.#launcherTaken) {
|
|
104
|
+
this.#launcherTaken = true;
|
|
105
|
+
this.#standing = phase.startDialog;
|
|
106
|
+
}
|
|
107
|
+
return phase;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The herdr client of the driver and its modules, with every successful `visible` + `ansi` read (the prompt field
|
|
112
|
+
* reads before a key or text) noted as its plain text, like a `detection` read: a field read that already shows a start
|
|
113
|
+
* dialog moves the gate's memory before the next client call. Other members pass through, read on the client at call
|
|
114
|
+
* time.
|
|
115
|
+
*/
|
|
116
|
+
export function clientNotingScreens(client, note) {
|
|
117
|
+
return new Proxy(client, {
|
|
118
|
+
get(target, prop) {
|
|
119
|
+
const value = Reflect.get(target, prop, target);
|
|
120
|
+
if (typeof value !== 'function')
|
|
121
|
+
return value;
|
|
122
|
+
if (prop !== 'readScreen')
|
|
123
|
+
return value.bind(target);
|
|
124
|
+
return async (...args) => {
|
|
125
|
+
const screen = await target.readScreen(...args);
|
|
126
|
+
if (args[1] === 'visible' && args[2] === 'ansi')
|
|
127
|
+
note(stripTerminalControl(screen.text));
|
|
128
|
+
return screen;
|
|
129
|
+
};
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/** One start dialog: its `id`, or the title of an unknown one. */
|
|
134
|
+
function identityOf(dialog) {
|
|
135
|
+
return dialog.id ?? `unknown\n${dialog.title ?? ''}`;
|
|
136
|
+
}
|