@rarog/server 1.1.1 → 1.1.2-beta.1
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 +3 -0
- package/node_modules/@rarog/shared/src/notify-copy.js +1 -0
- package/node_modules/@rarog/shared/src/protocol/background.js +7 -0
- package/node_modules/@rarog/shared/src/sentences/dialogs.js +10 -0
- package/node_modules/@rarog/shared/src/sentences/push.js +3 -0
- package/package.json +2 -2
- package/server/src/bootstrap/pr-status.js +15 -7
- package/server/src/bootstrap/push.js +36 -5
- package/server/src/cli/doctor-pr-status.js +10 -6
- package/server/src/demo/control.js +4 -2
- package/server/src/demo/mock-herdr.js +2 -2
- package/server/src/demo/scenarios.js +31 -17
- package/server/src/demo/seeds.js +62 -38
- 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/start-dialog-gate.js +132 -0
- package/server/src/drivers/herdr-driver.js +75 -15
- package/server/src/herdr/background/cli-shapes.js +16 -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/work.js +84 -0
- package/server/src/herdr/dialogs/copy.js +7 -0
- package/server/src/herdr/dialogs/index.js +4 -1
- package/server/src/herdr/dialogs/screen/form.js +2 -1
- 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 +55 -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/jsonl-follow.js +6 -2
- 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/provenance.js +80 -40
- package/server/src/herdr/start-dialog-wait.js +96 -0
- package/server/src/herdr/supervisor.js +33 -10
- package/server/src/herdr/workspace-resolver.js +5 -4
- package/server/src/index.js +8 -3
- package/server/src/notify/apns-payload.js +5 -3
- package/server/src/notify/content.js +37 -0
- package/server/src/notify/index.js +4 -0
- package/server/src/notify/live-activity-state.js +9 -5
- package/server/src/notify/live-activity.js +5 -2
- package/server/src/notify/policy.js +4 -2
- 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/sessions/conversation-lists.js +8 -2
- package/server/src/sessions/driver-events.js +7 -3
- package/server/src/sessions/interrupt-windows.js +28 -4
- package/server/src/sessions/manager.js +14 -5
- package/server/src/sessions/pr-status-link.js +64 -16
- package/server/src/sessions/session.js +10 -3
- package/server/src/sessions/state-machine.js +11 -0
- package/server/src/sessions/test-session.js +50 -0
- package/server/src/term/herdr-backend.js +15 -12
- package/server/src/term/lifecycle.js +4 -6
|
@@ -0,0 +1,132 @@
|
|
|
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
|
+
/** A card was shown: the sentence of the start dialog under it, once per dialog. */
|
|
82
|
+
cardShown() {
|
|
83
|
+
const dialog = this.#phase() === null ? null : this.#standing;
|
|
84
|
+
if (dialog === null)
|
|
85
|
+
return;
|
|
86
|
+
const identity = identityOf(dialog);
|
|
87
|
+
if (this.#announced === identity)
|
|
88
|
+
return;
|
|
89
|
+
this.#announced = identity;
|
|
90
|
+
this.#port.system(dialog.id === 'external-imports' ? START_DIALOG_IMPORTS_MESSAGE : START_DIALOG_UNKNOWN_MESSAGE);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The start phase now. The dialog the launcher found on its own read goes into the memory the first time it is
|
|
94
|
+
* known, as proof that it stands: before any read of the driver, and through failed or blank reads, the gate
|
|
95
|
+
* refuses until a screen proves it gone.
|
|
96
|
+
*/
|
|
97
|
+
#phase() {
|
|
98
|
+
const phase = this.#port.startPhase();
|
|
99
|
+
if (phase !== null && phase.startDialog !== null && !this.#launcherTaken) {
|
|
100
|
+
this.#launcherTaken = true;
|
|
101
|
+
this.#standing = phase.startDialog;
|
|
102
|
+
}
|
|
103
|
+
return phase;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The herdr client of the driver and its modules, with every successful `visible` + `ansi` read (the prompt field
|
|
108
|
+
* reads before a key or text) noted as its plain text, like a `detection` read: a field read that already shows a start
|
|
109
|
+
* dialog moves the gate's memory before the next client call. Other members pass through, read on the client at call
|
|
110
|
+
* time.
|
|
111
|
+
*/
|
|
112
|
+
export function clientNotingScreens(client, note) {
|
|
113
|
+
return new Proxy(client, {
|
|
114
|
+
get(target, prop) {
|
|
115
|
+
const value = Reflect.get(target, prop, target);
|
|
116
|
+
if (typeof value !== 'function')
|
|
117
|
+
return value;
|
|
118
|
+
if (prop !== 'readScreen')
|
|
119
|
+
return value.bind(target);
|
|
120
|
+
return async (...args) => {
|
|
121
|
+
const screen = await target.readScreen(...args);
|
|
122
|
+
if (args[1] === 'visible' && args[2] === 'ansi')
|
|
123
|
+
note(stripTerminalControl(screen.text));
|
|
124
|
+
return screen;
|
|
125
|
+
};
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
/** One start dialog: its `id`, or the title of an unknown one. */
|
|
130
|
+
function identityOf(dialog) {
|
|
131
|
+
return dialog.id ?? `unknown\n${dialog.title ?? ''}`;
|
|
132
|
+
}
|
|
@@ -15,6 +15,7 @@ import { cliWaitsForPermission, noteConsentRegistryRead } from './herdr/consent-
|
|
|
15
15
|
import { PromptQueue, promptEntry } from './herdr/prompt-queue.js';
|
|
16
16
|
import { QueueTakeBack } from './herdr/queue-take-back.js';
|
|
17
17
|
import { ReturnedPrompt } from './herdr/returned-prompt.js';
|
|
18
|
+
import { StartDialogGate, clientNotingScreens } from './herdr/start-dialog-gate.js';
|
|
18
19
|
import { TurnGuard } from './herdr/turn-guard.js';
|
|
19
20
|
import { FormReserve } from './herdr/form-reserve.js';
|
|
20
21
|
import { CliReserve } from './herdr/cli-reserve.js';
|
|
@@ -25,7 +26,7 @@ import { ScreenFallback } from './herdr/screen-fallback.js';
|
|
|
25
26
|
import { Layer2Cards, isLayer2Id, layer2HoldsKeys } from './herdr/layer2-card.js';
|
|
26
27
|
import { Layer2Step } from './herdr/layer2-step.js';
|
|
27
28
|
import { approveContext, auditRefusal, layer2KeyRefusal, refuseDecision, refuseNote, refuseSend, reportStaleDecision, } from './herdr/refusals.js';
|
|
28
|
-
import { ANSWERED_HOOK_SHIELD_MS, CLI_WAITING_PROBES, DECIDED_SHIELD_MS, FORM_SUBMIT_CONFIRM_DELAY_MS, FORM_SUBMIT_GONE_MESSAGE, FORM_SUBMIT_KEY, HOOK_ANSWER_POLL_MS, HOOK_ANSWER_WAIT_MS, HOOK_PERMISSION_REQUEST_EVENT, MULTI_SELECT_MESSAGE, NOTE_NOT_ALLOWED_MESSAGE, NOTE_NO_CHANNEL_MESSAGE, NOTE_WRITE_FAILED_MESSAGE, NO_ANSWER_ON_SCREEN_MESSAGE, NO_DIGIT_MESSAGE, PAUSE_ESCAPE_MESSAGE, SCREEN_ANSWER_REARM_DELAYS_MS, SCREEN_CHANGED_MESSAGE, SCREEN_DIALOG_TOOL, TERMINAL_DIALOG_MESSAGE, TERMINAL_ONLY_MESSAGE, affirmativeOption, alwaysOption, admittedHook, applyMultiSelectOverride, blockCardRecord, confirmFormSubmit, decideCard, dialogShapeOf, measuredConsentHolds, evaluationReqId, fallbackSnippet, formSubmitAbortMessage, hookAnnotations, hookAnswerPartialMessage, besideAtDecision, hookPendingFor, hookPendingFrom, noteNotDeliveredMessage, optionPolicy, otherDialogDump, screenAnswerIndex, screenDialogCard, screenFormReqId, staleDumpProvesOther, } from '../herdr/dialogs/index.js';
|
|
29
|
+
import { ANSWERED_HOOK_SHIELD_MS, CLI_WAITING_PROBES, DECIDED_SHIELD_MS, FORM_SUBMIT_CONFIRM_DELAY_MS, FORM_SUBMIT_GONE_MESSAGE, FORM_SUBMIT_KEY, HOOK_ANSWER_POLL_MS, HOOK_ANSWER_WAIT_MS, HOOK_PERMISSION_REQUEST_EVENT, MULTI_SELECT_MESSAGE, NOTE_NOT_ALLOWED_MESSAGE, NOTE_NO_CHANNEL_MESSAGE, NOTE_WRITE_FAILED_MESSAGE, NO_ANSWER_ON_SCREEN_MESSAGE, NO_DIGIT_MESSAGE, PAUSE_ESCAPE_MESSAGE, SCREEN_ANSWER_REARM_DELAYS_MS, SCREEN_CHANGED_MESSAGE, SCREEN_DIALOG_TOOL, START_DIALOG_REFUSED_MESSAGE, TERMINAL_DIALOG_MESSAGE, TERMINAL_ONLY_MESSAGE, affirmativeOption, alwaysOption, admittedHook, applyMultiSelectOverride, blockCardRecord, confirmFormSubmit, decideCard, dialogShapeOf, measuredConsentHolds, evaluationReqId, fallbackSnippet, formSubmitAbortMessage, hookAnnotations, hookAnswerPartialMessage, besideAtDecision, hookPendingFor, hookPendingFrom, noteNotDeliveredMessage, optionPolicy, otherDialogDump, screenAnswerIndex, screenDialogCard, screenFormReqId, staleDumpProvesOther, } from '../herdr/dialogs/index.js';
|
|
29
30
|
import { shadowAuditFields } from '../herdr/audit.js';
|
|
30
31
|
import { diagnosisFields, originFields } from './herdr/audit-fields.js';
|
|
31
32
|
import { ASK_USER_QUESTION_TOOL, SANDBOX_NETWORK_TOOL, SESSION_PAUSED_DIALOG, canonicalLabel, exitDialogTasks, matchKnownDialog, parseOptions, resolveOptions, sameDialogIdentity, sessionPausedDialog, standingConsentDialog, } from '../herdr/dialogs/index.js';
|
|
@@ -293,6 +294,8 @@ export class HerdrDriver {
|
|
|
293
294
|
#screenFallback;
|
|
294
295
|
/** The port of the refusals and their audit funnel: `drivers/herdr/refusals.ts`. */
|
|
295
296
|
#refusals;
|
|
297
|
+
/** No key or text to a start dialog herdr reads as ready: `drivers/herdr/start-dialog-gate.ts`. */
|
|
298
|
+
#startGate;
|
|
296
299
|
/** The wait behind a command dialog the driver confirmed: `drivers/herdr/command-dialog-settle.ts`. */
|
|
297
300
|
#commandSettle;
|
|
298
301
|
/** The layer 2 card with buttons (`docs/dialog-card.md`): `drivers/herdr/layer2-card.ts`. */
|
|
@@ -330,7 +333,10 @@ export class HerdrDriver {
|
|
|
330
333
|
#pulseEcho = createPulseEcho();
|
|
331
334
|
/** Bieżąca sesja silnika (zmienia ją `/clear`) — potrzebna do `init` z metadanych jsonl. */
|
|
332
335
|
#agentSessionId;
|
|
333
|
-
constructor(handle,
|
|
336
|
+
constructor(handle, driverDeps) {
|
|
337
|
+
// Field reads with attributes feed the start dialog gate too; the other deps are read through from `driverDeps`.
|
|
338
|
+
const deps = Object.create(driverDeps, { client: { enumerable: true, value: clientNotingScreens(driverDeps.client, (text) => { if (!this.#disposed)
|
|
339
|
+
this.#noteStartDialog(text); }) } });
|
|
334
340
|
this.#deps = deps;
|
|
335
341
|
this.#scheduler = deps.scheduler ?? systemScheduler;
|
|
336
342
|
this.#snippet = deps.snippet ?? fallbackSnippet;
|
|
@@ -359,9 +365,17 @@ export class HerdrDriver {
|
|
|
359
365
|
this.#formReserve = new FormReserve({ deps, scheduler: this.#scheduler }, reservePort);
|
|
360
366
|
this.#cliReserve = new CliReserve({ inScope: this.#inScope, form: this.#formReserve }, reservePort);
|
|
361
367
|
this.#refusals = this.#refusalPort();
|
|
368
|
+
this.#startGate = new StartDialogGate({
|
|
369
|
+
startPhase: deps.startPhase ?? (() => null),
|
|
370
|
+
readScreen: () => this.#readDialog(true), system: (text) => { this.#system(text); },
|
|
371
|
+
});
|
|
362
372
|
this.#commandSettle = new CommandDialogSettle({ pollMs: deps.modelConfirmPollMs ?? MODEL_CONFIRM_POLL_MS }, {
|
|
363
373
|
disposed: () => this.#disposed,
|
|
364
|
-
readScreen: () => this.#deps.client.readScreen(this.#paneId, 'detection').then((s) =>
|
|
374
|
+
readScreen: () => this.#deps.client.readScreen(this.#paneId, 'detection').then((s) => {
|
|
375
|
+
if (!this.#disposed)
|
|
376
|
+
this.#noteStartDialog(s.text);
|
|
377
|
+
return s.text;
|
|
378
|
+
}, () => null),
|
|
365
379
|
cliHold: () => this.#cliReserve.cliHold, blockedSeq: () => this.#blockedSeq,
|
|
366
380
|
sleep: (ms) => this.#sleep(ms), now: () => this.#scheduler.now(),
|
|
367
381
|
});
|
|
@@ -430,10 +444,10 @@ export class HerdrDriver {
|
|
|
430
444
|
cwd: this.#cwd, agentSessionId: handle.agent.agentSessionId,
|
|
431
445
|
})
|
|
432
446
|
: null;
|
|
433
|
-
//
|
|
447
|
+
// Session pull requests: the same scope gate, the main file only.
|
|
434
448
|
this.#pullRequests = createPullRequestPollState(this.#inScope
|
|
435
449
|
? (deps.pullRequestFiles ?? createPullRequestFilesReader)({
|
|
436
|
-
cwd: this.#cwd, agentSessionId: handle.agent.agentSessionId,
|
|
450
|
+
cwd: this.#cwd, agentSessionId: handle.agent.agentSessionId,
|
|
437
451
|
// Ten sam plik, który czyta follower: bez drugiego globu po magazynie i z jego relokacją.
|
|
438
452
|
locate: () => this.#follower?.transcriptOffset?.()?.file ?? null,
|
|
439
453
|
})
|
|
@@ -603,6 +617,10 @@ export class HerdrDriver {
|
|
|
603
617
|
const dialogStands = await this.#commandSettle.settle();
|
|
604
618
|
if (this.#disposed)
|
|
605
619
|
return;
|
|
620
|
+
// A start dialog takes no message, not even one parked to its end: a fresh read, not only the memory.
|
|
621
|
+
const startDialog = this.#startGate.inPhase() && await this.#startGate.refuses();
|
|
622
|
+
if (this.#startDialogHeld(echo, startDialog) || this.#disposed)
|
|
623
|
+
return;
|
|
606
624
|
/*
|
|
607
625
|
* Panel Claude w trakcie tury (albo z wiadomością, która już czeka, albo zaraz po Enterze takiej wiadomości,
|
|
608
626
|
* którego skutku driver jeszcze nie zna): wklejenie, sprawdzenie i osobny Enter
|
|
@@ -776,6 +794,7 @@ export class HerdrDriver {
|
|
|
776
794
|
disposed, paneId, agentSessionId, driverHold, consentCardStands, cliWaiting,
|
|
777
795
|
audit: (entry) => { this.#audit(entry); },
|
|
778
796
|
enqueue: (step) => this.#enqueue(step),
|
|
797
|
+
startDialogStands: () => this.#startGate.refuses(),
|
|
779
798
|
};
|
|
780
799
|
}
|
|
781
800
|
/** Port of the turn guard: driver state it reads and steps that stay in the facade. */
|
|
@@ -909,6 +928,18 @@ export class HerdrDriver {
|
|
|
909
928
|
this.#follower?.forgetEcho(echo);
|
|
910
929
|
this.#emit({ type: 'echo-refused', token: echo });
|
|
911
930
|
}
|
|
931
|
+
/** No key or text while a start dialog stands (`start-dialog-gate.ts`): the echo back and the sentence. */
|
|
932
|
+
#startDialogHeld(echo, held = this.#startGate.holds()) {
|
|
933
|
+
if (!held)
|
|
934
|
+
return false;
|
|
935
|
+
this.#refuseEcho(echo);
|
|
936
|
+
this.#system(START_DIALOG_REFUSED_MESSAGE);
|
|
937
|
+
return true;
|
|
938
|
+
}
|
|
939
|
+
/** A decision or an interrupt refused over a start dialog: the sentence, and the card judged again. */
|
|
940
|
+
#startDialogRefused(why) {
|
|
941
|
+
return this.#disposed ? STALE : refuseDecision(this.#refusals, START_DIALOG_REFUSED_MESSAGE, why, 'terminal-only');
|
|
942
|
+
}
|
|
912
943
|
/**
|
|
913
944
|
* Prompt z detekcją zawieszenia.
|
|
914
945
|
*
|
|
@@ -1003,6 +1034,8 @@ export class HerdrDriver {
|
|
|
1003
1034
|
}
|
|
1004
1035
|
/** Jedna próba `prompt` z `wait` + wpis dziennika; błędy inne niż stall lecą do transkryptu. */
|
|
1005
1036
|
async #promptAttempt(text, echo, source) {
|
|
1037
|
+
if (this.#startDialogHeld(echo))
|
|
1038
|
+
return 'failed';
|
|
1006
1039
|
try {
|
|
1007
1040
|
await this.#deps.client.prompt(this.#paneId, text, true);
|
|
1008
1041
|
this.#audit(promptEntry(text, source));
|
|
@@ -1046,6 +1079,7 @@ export class HerdrDriver {
|
|
|
1046
1079
|
}
|
|
1047
1080
|
if (this.#disposed)
|
|
1048
1081
|
return false;
|
|
1082
|
+
this.#noteStartDialog(screen);
|
|
1049
1083
|
return screenHoldsNeedle(screen, text);
|
|
1050
1084
|
}
|
|
1051
1085
|
/**
|
|
@@ -1147,6 +1181,10 @@ export class HerdrDriver {
|
|
|
1147
1181
|
return STALE;
|
|
1148
1182
|
return refuseDecision(this.#refusals, PAUSE_ESCAPE_MESSAGE, 'Esc na pauzie „Session paused”', 'terminal-only');
|
|
1149
1183
|
}
|
|
1184
|
+
if (this.#startGate.inPhase() && await this.#startGate.refuses(pause.text)) {
|
|
1185
|
+
this.#shadowKeySent(shadow, false);
|
|
1186
|
+
return this.#startDialogRefused('start dialog: Esc');
|
|
1187
|
+
}
|
|
1150
1188
|
if (this.#disposed) {
|
|
1151
1189
|
this.#shadowKeySent(shadow, false);
|
|
1152
1190
|
return STALE;
|
|
@@ -1214,6 +1252,8 @@ export class HerdrDriver {
|
|
|
1214
1252
|
// czego odrzucać ani czego zdejmować, więc to jest `stale`, nie odmowa.
|
|
1215
1253
|
return step.then((outcome) => outcome ?? STALE);
|
|
1216
1254
|
}
|
|
1255
|
+
if (this.#startGate.holds())
|
|
1256
|
+
return Promise.resolve(this.#startDialogRefused('start dialog: approve'));
|
|
1217
1257
|
const active = this.#activeReq;
|
|
1218
1258
|
if (active === null)
|
|
1219
1259
|
return Promise.resolve(STALE);
|
|
@@ -1963,6 +2003,8 @@ export class HerdrDriver {
|
|
|
1963
2003
|
let verdict = await read(true);
|
|
1964
2004
|
if (verdict === null)
|
|
1965
2005
|
return STALE;
|
|
2006
|
+
if (this.#startGate.holds())
|
|
2007
|
+
return this.#startDialogRefused('start dialog: trust step');
|
|
1966
2008
|
if (!verdict.ok)
|
|
1967
2009
|
return refuse(verdict.reason);
|
|
1968
2010
|
const audit = {
|
|
@@ -2731,12 +2773,17 @@ export class HerdrDriver {
|
|
|
2731
2773
|
* on the pause stays a refusal (`#pauseBlocksEscape`): before any state change and after the field read above, so
|
|
2732
2774
|
* no read follows the gate before the key. `refuseDecision` restores the card the manager took at the interrupt.
|
|
2733
2775
|
*/
|
|
2734
|
-
|
|
2776
|
+
const pause = await this.#pauseBlocksEscape();
|
|
2777
|
+
if (pause.blocks) {
|
|
2735
2778
|
if (!this.#disposed) {
|
|
2736
2779
|
refuseDecision(this.#refusals, PAUSE_ESCAPE_MESSAGE, 'przerwanie: Esc na pauzie „Session paused”', 'terminal-only');
|
|
2737
2780
|
}
|
|
2738
2781
|
return false;
|
|
2739
2782
|
}
|
|
2783
|
+
if (this.#startGate.inPhase() && await this.#startGate.refuses(pause.text)) {
|
|
2784
|
+
this.#startDialogRefused('interrupt: start dialog');
|
|
2785
|
+
return false;
|
|
2786
|
+
}
|
|
2740
2787
|
/*
|
|
2741
2788
|
* Przerwanie unieważnia watchdog tury: pytanie „wysłane, a panel nie ruszył?" traci
|
|
2742
2789
|
* sens, gdy to człowiek świadomie ubił turę — bez tego watchdog umiał po karencji
|
|
@@ -3257,6 +3304,7 @@ export class HerdrDriver {
|
|
|
3257
3304
|
this.#screenText = screen.text;
|
|
3258
3305
|
this.#screenAt = this.#scheduler.now();
|
|
3259
3306
|
this.#notePause(screen.text);
|
|
3307
|
+
this.#noteStartDialog(screen.text);
|
|
3260
3308
|
return screen.text;
|
|
3261
3309
|
}
|
|
3262
3310
|
catch {
|
|
@@ -3307,6 +3355,15 @@ export class HerdrDriver {
|
|
|
3307
3355
|
return;
|
|
3308
3356
|
this.#pauseSeq = sessionPausedDialog(dialog) ? this.#blockedSeq : null;
|
|
3309
3357
|
}
|
|
3358
|
+
/**
|
|
3359
|
+
* A successful `detection` read for the start dialog gate: every dialog read and every read of a gate before a key
|
|
3360
|
+
* or text, so the gate's last synchronous check before the client call judges the newest screen.
|
|
3361
|
+
*/
|
|
3362
|
+
#noteStartDialog(text) {
|
|
3363
|
+
// A start dialog standing up after an own answer is the next dialog, not the repaint of the answered one.
|
|
3364
|
+
if (this.#startGate.note(text) && this.#answeredSeq === this.#blockedSeq)
|
|
3365
|
+
this.#blockedSeq += 1;
|
|
3366
|
+
}
|
|
3310
3367
|
/** Whether {@link #readDialog} without `force` returns the screen cache instead of reading. */
|
|
3311
3368
|
#screenCached() {
|
|
3312
3369
|
return this.#screenText !== null && this.#scheduler.now() - this.#screenAt < this.#screenCacheMs;
|
|
@@ -3439,12 +3496,7 @@ export class HerdrDriver {
|
|
|
3439
3496
|
scheduler: this.#scheduler,
|
|
3440
3497
|
pollMs: this.#tasksPollMs,
|
|
3441
3498
|
disposed: () => this.#disposed,
|
|
3442
|
-
emit: (tasks) => {
|
|
3443
|
-
this.#emit({ type: 'background-tasks', tasks });
|
|
3444
|
-
// Zmiana listy zadań (start albo koniec agenta, rozkład workflow) bywa jedynym znakiem pracy, gdy plik
|
|
3445
|
-
// główny milczy: agent mógł właśnie utworzyć PR we własnym pliku.
|
|
3446
|
-
this.#schedulePullRequests();
|
|
3447
|
-
},
|
|
3499
|
+
emit: (tasks) => { this.#emit({ type: 'background-tasks', tasks }); },
|
|
3448
3500
|
};
|
|
3449
3501
|
}
|
|
3450
3502
|
/** Contact with `drivers/herdr/pull-request-poll.ts`, built at every call, like `#tasksDeps`. */
|
|
@@ -3452,7 +3504,9 @@ export class HerdrDriver {
|
|
|
3452
3504
|
return {
|
|
3453
3505
|
scheduler: this.#scheduler,
|
|
3454
3506
|
disposed: () => this.#disposed,
|
|
3455
|
-
emit: (
|
|
3507
|
+
emit: ({ linked, windowStart }) => {
|
|
3508
|
+
this.#emit({ type: 'pull-requests', pullRequests: linked, ...(windowStart === null ? {} : { windowStart }) });
|
|
3509
|
+
},
|
|
3456
3510
|
};
|
|
3457
3511
|
}
|
|
3458
3512
|
/** Contact with `drivers/herdr/scheduled-task-poll.ts`, built at every call. */
|
|
@@ -3507,11 +3561,15 @@ export class HerdrDriver {
|
|
|
3507
3561
|
*/
|
|
3508
3562
|
if (event.type === 'tasks') {
|
|
3509
3563
|
noteTasks(this.#tasks, this.#tasksDeps, event);
|
|
3564
|
+
return;
|
|
3565
|
+
}
|
|
3566
|
+
// A pull request link entry: only a read signal. Not a sign of file life (no turn watchdog, no send guard).
|
|
3567
|
+
if (event.type === 'pull-request-entry') {
|
|
3510
3568
|
this.#schedulePullRequests();
|
|
3511
3569
|
return;
|
|
3512
3570
|
}
|
|
3513
3571
|
this.#lastFollowAt = this.#scheduler.now();
|
|
3514
|
-
//
|
|
3572
|
+
// The main file grew: it may hold a PR link entry or the first timed entry (the conversation window).
|
|
3515
3573
|
this.#schedulePullRequests();
|
|
3516
3574
|
crons.scheduleScheduledTasks(this.#crons, this.#cronsDeps);
|
|
3517
3575
|
resetPulseEcho(this.#pulseEcho);
|
|
@@ -3970,6 +4028,7 @@ export class HerdrDriver {
|
|
|
3970
4028
|
: null;
|
|
3971
4029
|
this.#noHook.cardShown(card, event);
|
|
3972
4030
|
this.#emit(event);
|
|
4031
|
+
this.#startGate.cardShown();
|
|
3973
4032
|
this.#auditBlockCard(card.active);
|
|
3974
4033
|
}
|
|
3975
4034
|
/**
|
|
@@ -4050,6 +4109,7 @@ export class HerdrDriver {
|
|
|
4050
4109
|
}
|
|
4051
4110
|
if (this.#disposed)
|
|
4052
4111
|
return false;
|
|
4112
|
+
this.#noteStartDialog(text);
|
|
4053
4113
|
onScreen?.(text);
|
|
4054
4114
|
const dialog = standingConsentDialog(text);
|
|
4055
4115
|
await this.#noteConsentDialog(dialog, text);
|
|
@@ -4141,7 +4201,7 @@ export class HerdrDriver {
|
|
|
4141
4201
|
* @returns `true`, gdy wywołanie się powiodło.
|
|
4142
4202
|
*/
|
|
4143
4203
|
async #send(call, entry, op = 'message', echo) {
|
|
4144
|
-
if (this.#disposed)
|
|
4204
|
+
if (this.#disposed || this.#startDialogHeld(echo))
|
|
4145
4205
|
return false;
|
|
4146
4206
|
try {
|
|
4147
4207
|
await call();
|
|
@@ -42,25 +42,10 @@ export const CLI_SHAPES = {
|
|
|
42
42
|
literals: {
|
|
43
43
|
open: '<task-notification>',
|
|
44
44
|
taskId: '<task-id>',
|
|
45
|
-
// The call that started the task and the file its output goes to (also on CLI 2.1.316, live session file).
|
|
46
|
-
toolUseId: '<tool-use-id>',
|
|
47
|
-
outputFile: '<output-file>',
|
|
48
|
-
/*
|
|
49
|
-
* The output file's place: `<tmp>/claude-<uid>/<slug>/<session uuid>/tasks/<task id>.output`. For a `Bash`
|
|
50
|
-
* command a regular file with the output and an `[exited with code N]` line; for an agent the CLI puts a
|
|
51
|
-
* symlink to the agent's conversation file there. The CLI deletes these files after some days (unmeasured).
|
|
52
|
-
* Read only by the pull request reader (`pull-request-files.ts`).
|
|
53
|
-
*/
|
|
54
|
-
outputDir: 'tasks',
|
|
55
|
-
outputExtension: '.output',
|
|
56
45
|
status: '<status>',
|
|
57
46
|
summary: '<summary>',
|
|
58
47
|
},
|
|
59
48
|
cli: '2.1.296',
|
|
60
|
-
common: {
|
|
61
|
-
outputDir: 'ordinary word: the driver event of the task list has the same name',
|
|
62
|
-
outputExtension: 'ordinary word: `.output` stands in code as an object field (`deps.output`)',
|
|
63
|
-
},
|
|
64
49
|
},
|
|
65
50
|
notificationCarriers: {
|
|
66
51
|
what: 'wpisy niosące meldunek poza wpisem `user` z gołym napisem: kolejka promptów i załącznik',
|
|
@@ -430,6 +415,22 @@ export const CLI_SHAPES = {
|
|
|
430
415
|
createdAt: 'ordinary word: device and note stores have a field with this name',
|
|
431
416
|
},
|
|
432
417
|
},
|
|
418
|
+
/**
|
|
419
|
+
* The entry that links a pull request to the conversation (`pull-requests.ts`): a top-level entry
|
|
420
|
+
* `{type, sessionId, prNumber, prUrl, prRepository, timestamp}` in the main conversation file, seen on CLI
|
|
421
|
+
* 2.1.296–2.1.3xx and never in a subagent file. No conversation in the Rarog workspace has one, so no measured fixture
|
|
422
|
+
* holds it: the literals stand on the list outside the measurement in `herdr-background-fixtures.test.ts`.
|
|
423
|
+
*/
|
|
424
|
+
prLink: {
|
|
425
|
+
what: 'the entry that links a pull request to the conversation: its type, PR URL, number and repository',
|
|
426
|
+
literals: {
|
|
427
|
+
type: 'pr-link',
|
|
428
|
+
url: 'prUrl',
|
|
429
|
+
number: 'prNumber',
|
|
430
|
+
repository: 'prRepository',
|
|
431
|
+
},
|
|
432
|
+
cli: '2.1.296',
|
|
433
|
+
},
|
|
433
434
|
};
|
|
434
435
|
/**
|
|
435
436
|
* Literał jako fragment wyrażenia regularnego — bez znaczenia specjalnego żadnego znaku.
|
|
@@ -24,15 +24,15 @@
|
|
|
24
24
|
* o usunięciu (notka harnessu, ten sam parser co meldunek zadania) → lista adresów
|
|
25
25
|
* z tytułem i czasem. Nie zadanie w tle: stoi tu, bo meldunek jedzie tym samym
|
|
26
26
|
* nośnikiem, a jego słowa trzyma ten sam rejestr. Opis: `docs/artifacts.md`.
|
|
27
|
-
* - `pull-requests.ts` —
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
27
|
+
* - `pull-requests.ts` — PURE: pull requests linked to the conversation. The CLI's link entry with a GitHub
|
|
28
|
+
* PR URL → the linked set (URL, repo, number, first entry time), and the window's lower bound.
|
|
29
|
+
* Not a background task: it lives here because the registry holds its CLI words. Which
|
|
30
|
+
* linked PRs a card shows: `sessions/pr-status-link.ts`. Description: `docs/pull-requests.md`.
|
|
31
31
|
* - `scheduled-tasks.ts` — PURE: the session's scheduled tasks (crons). `CronCreate`, `CronDelete` and `CronList`
|
|
32
32
|
* results, the run line and the carry attachment → the list of armed tasks; also the prefilter for
|
|
33
33
|
* raw lines. Not a background task: it lives here because the registry holds its CLI words.
|
|
34
|
-
* - `pull-request-files.ts` —
|
|
35
|
-
*
|
|
34
|
+
* - `pull-request-files.ts` — the reader of the main conversation file for pull requests: incrementally,
|
|
35
|
+
* with a prefilter and a byte budget; the linked set and the window of one conversation.
|
|
36
36
|
* - `scheduled-task-file.ts` — the reader of the main conversation file for the scheduled tasks:
|
|
37
37
|
* incrementally, with the tracker's prefilter, the list rebuilt from zero on truncation.
|
|
38
38
|
* - `incremental-read.ts` — one incremental read of one conversation file: offset, chunks, byte
|
|
@@ -85,7 +85,7 @@ export { createWorkflowRunReader, phaseCounts } from './workflow-run.js';
|
|
|
85
85
|
export { createAgentFileReader } from './agent-file.js';
|
|
86
86
|
export { scanMainFileBefore } from './main-scan.js';
|
|
87
87
|
export { artifactsSignature, createArtifactsTracker } from './artifacts.js';
|
|
88
|
-
export {
|
|
88
|
+
export { isPullRequestLinkEntry, pullRequestLinksSignature } from './pull-requests.js';
|
|
89
89
|
export { createScheduledTasksTracker } from './scheduled-tasks.js';
|
|
90
90
|
export { PULL_REQUESTS_BACKLOG_MS, PULL_REQUESTS_POLL_MS, createPullRequestFilesReader, } from './pull-request-files.js';
|
|
91
91
|
export { SCHEDULED_TASKS_BACKLOG_MS, SCHEDULED_TASKS_POLL_MS, createScheduledTaskFileReader, } from './scheduled-task-file.js';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ownCommandWaitOf } from './work.js';
|
|
1
2
|
/**
|
|
2
3
|
* Co ile driver odczytuje pliki obok transkryptu: rozkłady OTWARTYCH przebiegów workflow
|
|
3
4
|
* i pliki OTWARTYCH subagentów.
|
|
@@ -170,8 +171,11 @@ function refreshDormant(state, now, fresh) {
|
|
|
170
171
|
* nie ma na liście);
|
|
171
172
|
* - wynik odczytu, który wrócił po zmianie `waitingSince`, niczego nie psuje: czas wpisu jest
|
|
172
173
|
* faktem o pliku i zestawia się z BIEŻĄCYM postojem, nie z tym sprzed odczytu.
|
|
174
|
+
*
|
|
175
|
+
* The wait stage (`ownCommandWait`) is set last, on the copy, from the view after the wake and the own commands:
|
|
176
|
+
* `ownCommandWaitOf` in `work.ts` decides, with the clock of this emission (`now`).
|
|
173
177
|
*/
|
|
174
|
-
function agentView(state, task) {
|
|
178
|
+
function agentView(state, task, now) {
|
|
175
179
|
const facts = state.agents.get(task.id);
|
|
176
180
|
if (facts === undefined)
|
|
177
181
|
return task;
|
|
@@ -187,16 +191,20 @@ function agentView(state, task) {
|
|
|
187
191
|
// Własne komendy widać także pod agentem, który pracuje: to dalej jego otwarte zadania.
|
|
188
192
|
if (own.length > 0)
|
|
189
193
|
view.ownTasks = own;
|
|
194
|
+
const wait = ownCommandWaitOf(view, now);
|
|
195
|
+
if (wait !== undefined)
|
|
196
|
+
view.ownCommandWait = wait;
|
|
190
197
|
return view;
|
|
191
198
|
}
|
|
192
199
|
/**
|
|
193
200
|
* Zadania followera z nakładkami tam, gdzie je znamy. Reszta jedzie bez zmian; agent uśpiony
|
|
194
201
|
* (`state.dormant`) nie jedzie wcale. Funkcja samego stanu: uśpienie liczy `emitChanged`.
|
|
202
|
+
* `now` is the clock of the emission; only the wait stage of an agent reads it.
|
|
195
203
|
*/
|
|
196
|
-
export function mergedTasks(state) {
|
|
204
|
+
export function mergedTasks(state, now) {
|
|
197
205
|
return state.raw.flatMap((task) => {
|
|
198
206
|
if (task.kind === 'agent')
|
|
199
|
-
return state.dormant.has(task.id) ? [] : [agentView(state, task)];
|
|
207
|
+
return state.dormant.has(task.id) ? [] : [agentView(state, task, now)];
|
|
200
208
|
const run = task.runId === undefined ? undefined : state.runs.get(task.runId)?.run;
|
|
201
209
|
return [run === undefined ? task : { ...task, run }];
|
|
202
210
|
});
|
|
@@ -208,10 +216,14 @@ export function mergedTasks(state) {
|
|
|
208
216
|
* zdarzenie `tasks` z samym `ended`), a odczyt pliku subagenta co tick przynosi nowy czas wpisu,
|
|
209
217
|
* który zwykle niczego w liście nie zmienia. Manager po każdej liście rozsyła `session-changed`,
|
|
210
218
|
* więc powtórka tej samej listy byłaby pustą ramką do każdego klienta.
|
|
219
|
+
*
|
|
220
|
+
* The compared list carries the wait stage, so a threshold passed between two ticks changes the JSON and goes out on
|
|
221
|
+
* the first tick after it, with no change in any file.
|
|
211
222
|
*/
|
|
212
223
|
function emitChanged(state, deps, fresh = NO_FRESH) {
|
|
213
|
-
|
|
214
|
-
|
|
224
|
+
const now = deps.scheduler.now();
|
|
225
|
+
refreshDormant(state, now, fresh);
|
|
226
|
+
const merged = mergedTasks(state, now);
|
|
215
227
|
const json = JSON.stringify(merged);
|
|
216
228
|
if (json === state.sent)
|
|
217
229
|
return;
|
|
@@ -46,8 +46,6 @@ function tagPattern(open) {
|
|
|
46
46
|
return new RegExp(`${literalSource(open)}([\\s\\S]*?)${literalSource(closing(open))}`);
|
|
47
47
|
}
|
|
48
48
|
const TASK_ID = tagPattern(MARKS.taskId);
|
|
49
|
-
const TOOL_USE_ID = tagPattern(MARKS.toolUseId);
|
|
50
|
-
const OUTPUT_FILE = tagPattern(MARKS.outputFile);
|
|
51
49
|
const STATUS = tagPattern(MARKS.status);
|
|
52
50
|
const SUMMARY = tagPattern(MARKS.summary);
|
|
53
51
|
/**
|
|
@@ -180,8 +178,6 @@ export function parseTaskNotification(text) {
|
|
|
180
178
|
const exitCode = exitCodeOf(summary);
|
|
181
179
|
return {
|
|
182
180
|
id: tag(text, TASK_ID),
|
|
183
|
-
toolUseId: tag(text, TOOL_USE_ID),
|
|
184
|
-
outputFile: tag(text, OUTPUT_FILE),
|
|
185
181
|
status: tag(text, STATUS),
|
|
186
182
|
summary,
|
|
187
183
|
name: quotedName(summary),
|