@rarog/server 1.1.2-beta.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 +43 -1
- package/node_modules/@rarog/shared/src/notify-copy.js +1 -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/push.js +6 -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/push.js +24 -1
- 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/inbox.js +12 -0
- package/server/src/demo/mock-herdr.js +3 -2
- package/server/src/demo/review-routes.js +2 -2
- package/server/src/demo/seeds.js +20 -2
- 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/returned-prompt.js +4 -1
- package/server/src/drivers/herdr/screen-fallback.js +50 -0
- package/server/src/drivers/herdr/start-dialog-gate.js +4 -0
- package/server/src/drivers/herdr-driver.js +88 -66
- 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 +19 -0
- package/server/src/herdr/background/queued-prompt.js +46 -0
- package/server/src/herdr/background/work.js +12 -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/index.js +9 -0
- 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 +4 -3
- package/server/src/herdr/dialogs/screen/signatures.js +23 -0
- 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 +20 -1
- package/server/src/herdr/plugin-copy.js +281 -0
- package/server/src/herdr/session-index.js +19 -0
- package/server/src/herdr/supervisor.js +16 -13
- package/server/src/herdr/types.js +1 -0
- 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 +37 -5
- package/server/src/notify/content.js +27 -0
- package/server/src/notify/index.js +7 -3
- package/server/src/notify/live-activity-state.js +14 -5
- package/server/src/notify/policy.js +49 -11
- package/server/src/notify/ready-to-merge.js +148 -0
- 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 +4 -1
- 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 +61 -11
- package/server/src/sessions/herdr-lifecycle.js +11 -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 +124 -282
- package/server/src/sessions/owner-turn.js +36 -0
- 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 +72 -7
- package/server/src/sessions/state-machine.js +2 -0
- package/server/src/sessions/state-sentences.js +87 -30
- package/server/src/sessions/waiting-line.js +49 -0
- 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,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The live dialog card, screen half: the dialog region of a raw pane screen (top rule to the last footer line), its
|
|
3
|
+
* options, the cursor, the cut and scroll marks, the capped text and the fingerprint.
|
|
4
|
+
*
|
|
5
|
+
* It decides nothing: which keys the server takes stands in `policy.ts`, the label under the cursor and the card
|
|
6
|
+
* fields in `model.ts`. No I/O; every screen pattern comes from the signature registry.
|
|
7
|
+
*/
|
|
8
|
+
import { createHash } from 'node:crypto';
|
|
9
|
+
import { LAYER2_EXCERPT_MAX_CHARS, LAYER2_EXCERPT_MAX_LINES } from '../layer2/card.js';
|
|
10
|
+
import { withoutAutoDeny } from '../screen/auto-deny.js';
|
|
11
|
+
import { lineBelow } from '../screen/block.js';
|
|
12
|
+
import { headerAboveEdge, operationAbove } from '../screen/operation.js';
|
|
13
|
+
import { HORIZONTAL_RULE_PATTERN, blockTopOf } from '../screen/region.js';
|
|
14
|
+
import { SCREEN_SIGNATURES } from '../screen/signatures.js';
|
|
15
|
+
import { trimmedLines } from '../screen/text.js';
|
|
16
|
+
const KEY_FOOTER = SCREEN_SIGNATURES.dialogKeyFooter.pattern;
|
|
17
|
+
const OPTION_ROW = SCREEN_SIGNATURES.dialogOptionRow.pattern;
|
|
18
|
+
const SESSION_NAME_EDGE = SCREEN_SIGNATURES.sessionNameEdge.pattern;
|
|
19
|
+
const SCROLL_MARK = SCREEN_SIGNATURES.listScrollMarker.pattern;
|
|
20
|
+
const HIDDEN_LINES = SCREEN_SIGNATURES.hiddenLinesMarker.pattern;
|
|
21
|
+
const OPERATION_RULE = SCREEN_SIGNATURES.operationRule.pattern;
|
|
22
|
+
const CHECKBOX = SCREEN_SIGNATURES.optionCheckbox.pattern;
|
|
23
|
+
const SUBMIT_ROW = SCREEN_SIGNATURES.formSubmitRow.pattern;
|
|
24
|
+
const PLAN_TITLE = SCREEN_SIGNATURES.planTitle.pattern;
|
|
25
|
+
/** The cursor glyph of a dialog option. */
|
|
26
|
+
export const LIVE_CURSOR = SCREEN_SIGNATURES.dialogCursorMark.pattern;
|
|
27
|
+
const indent = (line) => line.length - line.trimStart().length;
|
|
28
|
+
/** Lines that are never the content of a dialog: empty lines, horizontal rules, the session name edge. */
|
|
29
|
+
function chrome(line) {
|
|
30
|
+
const trimmed = line.trim();
|
|
31
|
+
return trimmed === '' || HORIZONTAL_RULE_PATTERN.test(trimmed) || SESSION_NAME_EDGE.test(trimmed);
|
|
32
|
+
}
|
|
33
|
+
/** Column of the digit of an option row, from the parts the registry pattern captured. */
|
|
34
|
+
function digitColumn(line, match) {
|
|
35
|
+
return line.length - (match[2] ?? '').length - 2 - (match[1] ?? '').length;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* First line of the key footer under the options, or `-1`. The footer is the highest key footer line in the block of
|
|
39
|
+
* non-empty lines that ends on the last line; an option row, a line with the cursor, a rule or an empty line ends
|
|
40
|
+
* the block.
|
|
41
|
+
*/
|
|
42
|
+
function footerStart(lines, last) {
|
|
43
|
+
let top = last;
|
|
44
|
+
while (top >= 0) {
|
|
45
|
+
const line = lines[top] ?? '';
|
|
46
|
+
const trimmed = line.trim();
|
|
47
|
+
const ends = trimmed === '' || OPTION_ROW.test(line) || line.includes(LIVE_CURSOR)
|
|
48
|
+
|| HORIZONTAL_RULE_PATTERN.test(trimmed);
|
|
49
|
+
if (ends)
|
|
50
|
+
break;
|
|
51
|
+
top -= 1;
|
|
52
|
+
}
|
|
53
|
+
for (let i = top + 1; i <= last; i += 1)
|
|
54
|
+
if (KEY_FOOTER.test((lines[i] ?? '').trim()))
|
|
55
|
+
return i;
|
|
56
|
+
return -1;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Numbered options: the last "1." row above `end` sets the digit column; the options are the rows in that column. A
|
|
60
|
+
* list cut at the top has no "1." row: its lowest option row sets the column and the rows in it from the top of the
|
|
61
|
+
* screen are the options, whose digits then do not run from 1.
|
|
62
|
+
*/
|
|
63
|
+
function numberedOptions(lines, end) {
|
|
64
|
+
let one = -1;
|
|
65
|
+
let first = null;
|
|
66
|
+
let lowest = -1;
|
|
67
|
+
let lowestMatch = null;
|
|
68
|
+
for (let i = end - 1; i >= 0 && one === -1; i -= 1) {
|
|
69
|
+
const match = OPTION_ROW.exec(lines[i] ?? '');
|
|
70
|
+
if (match === null)
|
|
71
|
+
continue;
|
|
72
|
+
if (lowestMatch === null) {
|
|
73
|
+
lowest = i;
|
|
74
|
+
lowestMatch = match;
|
|
75
|
+
}
|
|
76
|
+
if (match[1] === '1') {
|
|
77
|
+
one = i;
|
|
78
|
+
first = match;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const anchor = first ?? lowestMatch;
|
|
82
|
+
if (anchor === null)
|
|
83
|
+
return null;
|
|
84
|
+
const head = lines[first === null ? lowest : one] ?? '';
|
|
85
|
+
const column = digitColumn(head, anchor);
|
|
86
|
+
const options = [];
|
|
87
|
+
for (let i = first === null ? 0 : one; i < end; i += 1) {
|
|
88
|
+
const line = lines[i] ?? '';
|
|
89
|
+
const match = OPTION_ROW.exec(line);
|
|
90
|
+
if (match === null || digitColumn(line, match) !== column)
|
|
91
|
+
continue;
|
|
92
|
+
options.push({ line: i, digit: match[1] ?? '', label: match[2] ?? '' });
|
|
93
|
+
}
|
|
94
|
+
const numbered = options.every((option, k) => option.digit === String(k + 1));
|
|
95
|
+
return { options, column, labelColumn: head.length - (anchor[2] ?? '').length, numbered, digits: true };
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Options without digits ("Teach auto mode", the trust dialog): the rows in the label column of the cursor, contiguous
|
|
99
|
+
* around it (empty lines between them included). A choice needs two of them. A numbered option row is never one of
|
|
100
|
+
* them, so a numbered list cut above its "1." row stays a numbered list, and rows right under a numbered option row
|
|
101
|
+
* (no empty line between) that start at its label column or further right continue that option, so they make no
|
|
102
|
+
* choice.
|
|
103
|
+
*/
|
|
104
|
+
function digitlessOptions(lines, end) {
|
|
105
|
+
const cursor = lines.slice(0, end).findLastIndex((line) => line.trimStart().startsWith(LIVE_CURSOR));
|
|
106
|
+
if (cursor === -1)
|
|
107
|
+
return null;
|
|
108
|
+
const row = lines[cursor] ?? '';
|
|
109
|
+
if (OPTION_ROW.test(row))
|
|
110
|
+
return null;
|
|
111
|
+
const after = row.slice(row.indexOf(LIVE_CURSOR) + LIVE_CURSOR.length);
|
|
112
|
+
const labelColumn = row.length - after.trimStart().length;
|
|
113
|
+
if (after.trim() === '')
|
|
114
|
+
return null;
|
|
115
|
+
const inColumn = (i) => {
|
|
116
|
+
const line = lines[i] ?? '';
|
|
117
|
+
return line.trim() !== '' && indent(line) === labelColumn && !OPTION_ROW.test(line);
|
|
118
|
+
};
|
|
119
|
+
const walk = (from, step) => {
|
|
120
|
+
const found = [];
|
|
121
|
+
for (let i = from; i >= 0 && i < end; i += step) {
|
|
122
|
+
if (inColumn(i))
|
|
123
|
+
found.push(i);
|
|
124
|
+
else if ((lines[i] ?? '').trim() !== '')
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
return found;
|
|
128
|
+
};
|
|
129
|
+
const at = [...walk(cursor - 1, -1).reverse(), cursor, ...walk(cursor + 1, 1)];
|
|
130
|
+
if (at.length < 2)
|
|
131
|
+
return null;
|
|
132
|
+
const above = lines[(at[0] ?? cursor) - 1] ?? '';
|
|
133
|
+
const option = OPTION_ROW.exec(above);
|
|
134
|
+
if (option !== null && above.length - (option[2] ?? '').length <= labelColumn)
|
|
135
|
+
return null;
|
|
136
|
+
const options = at.map((line) => ({
|
|
137
|
+
line, digit: null, label: line === cursor ? after.trim() : (lines[line] ?? '').trim(),
|
|
138
|
+
}));
|
|
139
|
+
return { options, column: labelColumn, labelColumn, numbered: true, digits: false };
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* The top rule of the dialog block above the first option, or `null` when it is off screen. The nearest block rule
|
|
143
|
+
* (the operation frame is passed over) is the top, but the plan dialog draws a second rule of the same width between
|
|
144
|
+
* the plan text and its question: the identical rule right above, with the plan title under it, is the top then. An
|
|
145
|
+
* identical rule with anything else under it stands in the scrollback above the dialog. A rule above an operation
|
|
146
|
+
* frame whose own top is cut off belongs to the frame's content or the scrollback, and a rule under an operation frame
|
|
147
|
+
* with no block rule above that frame is the inner rule of a dialog taller than the pane (`measured/exitplanmode.txt`
|
|
148
|
+
* without its first rows): neither counts.
|
|
149
|
+
*/
|
|
150
|
+
function topRule(lines, firstOption) {
|
|
151
|
+
let top = blockTopOf(lines, firstOption);
|
|
152
|
+
const higher = top === null ? null : blockTopOf(lines, top.line);
|
|
153
|
+
if (top !== null && higher !== null && lines[higher.line] === lines[top.line]) {
|
|
154
|
+
const title = lineBelow(lines, higher.line, top.line);
|
|
155
|
+
if (PLAN_TITLE.test((lines[title] ?? '').trim()))
|
|
156
|
+
top = higher;
|
|
157
|
+
}
|
|
158
|
+
if (top !== null) {
|
|
159
|
+
const above = blockTopOf(lines, top.line)?.line ?? -1;
|
|
160
|
+
if (lines.slice(above + 1, top.line).some((line) => OPERATION_RULE.test(line.trim())))
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
const from = top?.line ?? -1;
|
|
164
|
+
for (let frame = firstOption - 1; frame > from; frame -= 1) {
|
|
165
|
+
if (!OPERATION_RULE.test((lines[frame] ?? '').trim()))
|
|
166
|
+
continue;
|
|
167
|
+
return headerAboveEdge(lines, frame + 1, operationAbove(lines, frame + 1)) ? null : top;
|
|
168
|
+
}
|
|
169
|
+
return top;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Whether the cursor row is the Submit or Next row of a multi-select form: the word alone in the label column, with
|
|
173
|
+
* options whose labels start with a checkbox. An option description stands further right or left of that column.
|
|
174
|
+
*/
|
|
175
|
+
function submitRow(row, found) {
|
|
176
|
+
const after = row.slice(row.indexOf(LIVE_CURSOR) + LIVE_CURSOR.length);
|
|
177
|
+
return SUBMIT_ROW.test(after.trim()) && row.length - after.trimStart().length === found.labelColumn
|
|
178
|
+
&& found.options.some((option) => CHECKBOX.test(option.label));
|
|
179
|
+
}
|
|
180
|
+
/** Rows under the presentation ceiling (60 lines, 4000 characters), cut at the top, and how many were cut. */
|
|
181
|
+
function capped(rows) {
|
|
182
|
+
let cut = Math.max(0, rows.length - LAYER2_EXCERPT_MAX_LINES);
|
|
183
|
+
let text = rows.slice(cut).join('\n');
|
|
184
|
+
while (text.length > LAYER2_EXCERPT_MAX_CHARS && cut < rows.length - 1) {
|
|
185
|
+
cut += 1;
|
|
186
|
+
text = rows.slice(cut).join('\n');
|
|
187
|
+
}
|
|
188
|
+
return { text, cut };
|
|
189
|
+
}
|
|
190
|
+
/** The dialog region of a raw pane screen; `null` = no dialog with options on it. */
|
|
191
|
+
export function liveRegion(screen) {
|
|
192
|
+
const lines = trimmedLines(screen);
|
|
193
|
+
const last = lines.findLastIndex((line) => !chrome(line));
|
|
194
|
+
if (last === -1)
|
|
195
|
+
return null;
|
|
196
|
+
let footer = footerStart(lines, last);
|
|
197
|
+
const numbered = numberedOptions(lines, footer === -1 ? last + 1 : footer);
|
|
198
|
+
const digitless = footer === -1 ? null : digitlessOptions(lines, footer);
|
|
199
|
+
// A choice without digits below the last numbered row: the numbered rows above it are content or scrollback.
|
|
200
|
+
const below = digitless !== null
|
|
201
|
+
&& (digitless.options[0]?.line ?? -1) > (numbered?.options.at(-1)?.line ?? -1);
|
|
202
|
+
const found = below ? digitless : numbered;
|
|
203
|
+
if (found === null)
|
|
204
|
+
return null;
|
|
205
|
+
// A key line indented past the options is a hint under an option (the plan's "shift+tab to approve…"), no footer.
|
|
206
|
+
if (footer !== -1 && indent(lines[footer] ?? '') > found.column)
|
|
207
|
+
footer = -1;
|
|
208
|
+
if (footer === -1) {
|
|
209
|
+
if (!found.digits)
|
|
210
|
+
return null;
|
|
211
|
+
const end = lines[last] ?? '';
|
|
212
|
+
const onOption = found.options.some((option) => option.line === last);
|
|
213
|
+
if (!onOption && (indent(end) < found.labelColumn || HORIZONTAL_RULE_PATTERN.test(end.trim())))
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
const firstOption = found.options[0]?.line ?? last;
|
|
217
|
+
const top = topRule(lines, firstOption);
|
|
218
|
+
const start = top === null ? 0 : top.line + 1;
|
|
219
|
+
const rows = lines.slice(start, last + 1);
|
|
220
|
+
const zoneEnd = (footer === -1 ? last + 1 : footer) - start;
|
|
221
|
+
const first = firstOption - start;
|
|
222
|
+
let marker = null;
|
|
223
|
+
let scrolled = false;
|
|
224
|
+
for (let i = Math.max(0, first - 1); i < zoneEnd; i += 1) {
|
|
225
|
+
const trimmed = (rows[i] ?? '').trim();
|
|
226
|
+
const count = HIDDEN_LINES.exec(trimmed);
|
|
227
|
+
if (count !== null)
|
|
228
|
+
marker ??= Number(count[1]);
|
|
229
|
+
else if (SCROLL_MARK.test(trimmed))
|
|
230
|
+
scrolled = true;
|
|
231
|
+
}
|
|
232
|
+
const cursors = rows.reduce((sum, row) => sum + row.split(LIVE_CURSOR).length - 1, 0);
|
|
233
|
+
const cursorAt = rows.findIndex((row) => row.trimStart().startsWith(LIVE_CURSOR));
|
|
234
|
+
const placed = found.options.some((option) => option.line - start === cursorAt)
|
|
235
|
+
|| (cursorAt >= first && cursorAt < zoneEnd && submitRow(rows[cursorAt] ?? '', found));
|
|
236
|
+
const cursorRow = cursors === 1 && placed ? cursorAt : -1;
|
|
237
|
+
const ruleAbove = rows.slice(0, first).findLastIndex((row) => HORIZONTAL_RULE_PATTERN.test(row.trim()));
|
|
238
|
+
const { text, cut } = capped(rows);
|
|
239
|
+
let hidden;
|
|
240
|
+
if (marker !== null)
|
|
241
|
+
hidden = marker + cut;
|
|
242
|
+
else if (top === null)
|
|
243
|
+
hidden = null;
|
|
244
|
+
else
|
|
245
|
+
hidden = cut > 0 ? cut : undefined;
|
|
246
|
+
return {
|
|
247
|
+
rows,
|
|
248
|
+
options: found.options.map((option) => ({ row: option.line - start, digit: option.digit, label: option.label })),
|
|
249
|
+
labelColumn: found.labelColumn,
|
|
250
|
+
footer: footer === -1 ? null : footer - start,
|
|
251
|
+
zoneEnd,
|
|
252
|
+
numbered: found.numbered,
|
|
253
|
+
scrolled,
|
|
254
|
+
cursors,
|
|
255
|
+
cursorRow,
|
|
256
|
+
bodyStart: ruleAbove + 1,
|
|
257
|
+
...(hidden === undefined ? {} : { hiddenAbove: hidden }),
|
|
258
|
+
text,
|
|
259
|
+
print: createHash('sha256').update(withoutAutoDeny(rows).join('\n')).digest('hex'),
|
|
260
|
+
};
|
|
261
|
+
}
|
|
@@ -25,9 +25,10 @@ export function formFooter(region) {
|
|
|
25
25
|
return region.slice(Math.max(0, region.length - FORM_FOOTER_LINES)).join('\n').toLowerCase();
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
28
|
+
* Signature of notes editing: in the preview variant the footer shows `ctrl+g to edit in Nvim` after `n` enters the
|
|
29
|
+
* notes field. The marker is short on purpose: a narrow pane wraps the footer mid-phrase (measured: "ctrl+g to\nedit in
|
|
30
|
+
* Nvim"). A form without a preview shows the same phrase with the cursor on the free-text row or on Submit (Claude Code
|
|
31
|
+
* 2.1.332), so the marker alone does not prove notes editing there.
|
|
31
32
|
*/
|
|
32
33
|
export const NOTES_EDITING_MARKER = SCREEN_SIGNATURES.notesEditing.pattern;
|
|
33
34
|
/**
|
|
@@ -921,6 +921,29 @@ export const SCREEN_SIGNATURES = {
|
|
|
921
921
|
pattern: /(?:^|\s)[↑↓]$|^[↑↓]\s/u,
|
|
922
922
|
cli: '2.1.312',
|
|
923
923
|
},
|
|
924
|
+
hiddenLinesMarker: {
|
|
925
|
+
what: 'line-count marker under the options of a tall dialog ("↑ 54 more lines"): the dialog is cut at the top by '
|
|
926
|
+
+ 'that many lines; it also matches the list scroll marker, so the live card reads it first',
|
|
927
|
+
// `measured/zgoda-bash-wysoka-2.1.328.txt` (Bash consent with a 90-line command in a 52-row pane)
|
|
928
|
+
pattern: /^ *↑ (\d+) more lines$/u,
|
|
929
|
+
cli: '2.1.328',
|
|
930
|
+
},
|
|
931
|
+
dialogCursorMark: {
|
|
932
|
+
what: 'cursor glyph of a dialog option (`❯ 1. Yes`, `❯ No, exit`): the live card counts it in the whole dialog '
|
|
933
|
+
+ 'region and reads the option under it',
|
|
934
|
+
// `measured/multiselect-2.1.328.txt`, `kontrolny/zaufanie-2.1.319.txt`
|
|
935
|
+
pattern: '❯',
|
|
936
|
+
cli: '2.1.328',
|
|
937
|
+
},
|
|
938
|
+
negativeOption: {
|
|
939
|
+
what: 'option label that declines ("No", "No, exit", "No, disable external imports"): choosing it saves nothing, '
|
|
940
|
+
+ 'so escalation markers in the dialog content do not make it lasting; numbered options that end on it at the '
|
|
941
|
+
+ 'bottom of the screen count as the whole set of a dialog without a key footer',
|
|
942
|
+
// `kontrolny/tryb-bypass-2.1.319.txt`, `kontrolny/importy-zewnetrzne-2.1.332.txt`, without a key footer:
|
|
943
|
+
// `measured/zgoda-webfetch-2.1.322.txt`, `measured/exitplanmode-bez-planu-2.1.328.txt`, `dialog-model-switch.txt`
|
|
944
|
+
pattern: /^no\b/iu,
|
|
945
|
+
cli: '2.1.332',
|
|
946
|
+
},
|
|
924
947
|
optionLabelCut: {
|
|
925
948
|
what: 'wielokropek na końcu etykiety opcji albo jej linii: etykieta ucięta na szerokości kolumny',
|
|
926
949
|
// `measured/picker-model-2.1.312-26kol.txt` („Defau…”: kolumna etykiety ucięta wielokropkiem)
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Engine registry of herdr agents: the only place that knows the agent kinds herdr reports (`agent` of an
|
|
3
|
+
* `agent.list` record), which of them Rarog admits, which are state-only and how their pane title becomes a card
|
|
4
|
+
* title, and which sentence refuses each action on a state-only card. It does not read the socket and keeps no state;
|
|
5
|
+
* the input filter in `client.ts` and every gate on an entry, card or session ask it instead of comparing kind
|
|
6
|
+
* literals themselves.
|
|
7
|
+
*/
|
|
8
|
+
import { basename } from 'node:path';
|
|
9
|
+
import { say } from '@rarog/shared/sentences';
|
|
10
|
+
/**
|
|
11
|
+
* Whether an engine is state-only. The rule is "not Claude", so a new engine gets the state-only gates without
|
|
12
|
+
* touching them. `undefined` is Claude: a session or summary without an `engine` field.
|
|
13
|
+
*/
|
|
14
|
+
export function isStateOnlyEngine(engine) {
|
|
15
|
+
return engine !== undefined && engine !== 'claude';
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Refusal sentences per state-only engine: the one place that picks a sentence by engine. The gates that throw them
|
|
19
|
+
* are the server's boundary, not the client's copy: an old client or `curl` may still ask for these actions, and a
|
|
20
|
+
* state-only entry must give state alone.
|
|
21
|
+
*/
|
|
22
|
+
export const STATE_ONLY_REFUSALS = {
|
|
23
|
+
codex: {
|
|
24
|
+
close: say('session.codex-close'), git: say('session.codex-git'), restart: say('restart.codex'),
|
|
25
|
+
files: say('rest.files-codex'),
|
|
26
|
+
},
|
|
27
|
+
agy: {
|
|
28
|
+
close: say('session.agy-close'), git: say('session.agy-git'), restart: say('restart.agy'),
|
|
29
|
+
files: say('rest.files-agy'),
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* The engine of a raw herdr agent kind, or `null` when the pane does not exist for Rarog.
|
|
34
|
+
*
|
|
35
|
+
* Bramka silnika. `codex` i `agy` wchodzą WYŁĄCZNIE przy jawnej fladze, każdy przy swojej; każdy inny agent
|
|
36
|
+
* (`future-agent`, `aider`, …) odpada tak jak dotąd — Rarog nie zna ani jego stopki, ani
|
|
37
|
+
* jego pliku treści, więc wiersz w sidebarze byłby obietnicą bez pokrycia.
|
|
38
|
+
*/
|
|
39
|
+
export function engineOfAgent(agent, flags) {
|
|
40
|
+
if (agent === 'claude')
|
|
41
|
+
return 'claude';
|
|
42
|
+
if (agent === 'codex' && flags.codexStatus)
|
|
43
|
+
return 'codex';
|
|
44
|
+
if (agent === 'agy' && flags.agyStatus)
|
|
45
|
+
return 'agy';
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
/** Klatka spinnera Codexa: znak brajlowski (U+2800–U+28FF) z odstępem za nim. */
|
|
49
|
+
const CODEX_SPINNER_RE = /^[⠀-⣿]+\s*/u;
|
|
50
|
+
/**
|
|
51
|
+
* Prefix of a Codex title while an approval waits. Codex CLI 0.171.0 alternates the mark between `!` and `.` about
|
|
52
|
+
* once a second at the same state number, so a kept prefix would change the card title every second.
|
|
53
|
+
*/
|
|
54
|
+
const CODEX_ACTION_REQUIRED_RE = /^\[ [!.] \] Action Required \| /u;
|
|
55
|
+
/**
|
|
56
|
+
* Tytuł Codexa → tytuł dla karty. JEDNO miejsce, w którym znika spinner i katalog.
|
|
57
|
+
*
|
|
58
|
+
* Zmierzone na żywym herdr 0.9.0: `terminal_title_stripped` Codexa ma kształt
|
|
59
|
+
* `<pierwszy prompt> | <katalog>`, w trakcie pracy z wiodącą klatką spinnera braille (`⠴ …`),
|
|
60
|
+
* a przed pierwszym promptem jest SAMĄ nazwą katalogu.
|
|
61
|
+
*
|
|
62
|
+
* Normalizacja musi być tutaj, a nie w warstwie widoku, z dwóch powodów: nadzorca porównuje
|
|
63
|
+
* tytuły między migawkami, więc kolejne klatki spinnera zgłaszałyby `titleChanged` kilka razy
|
|
64
|
+
* na sekundę, a manager ma dostać w zdarzeniu tekst, który da się pokazać bez dalszej obróbki.
|
|
65
|
+
* Sufiks katalogu zdejmujemy, bo nazwę projektu wiersz w kliencie i tak bierze z `cwd` — zostawiony
|
|
66
|
+
* dublowałby ją w każdym wierszu.
|
|
67
|
+
*/
|
|
68
|
+
export function normalizeCodexTitle(raw, cwd) {
|
|
69
|
+
const dir = basename(cwd);
|
|
70
|
+
let title = raw.replace(CODEX_SPINNER_RE, '').replace(CODEX_ACTION_REQUIRED_RE, '').trim();
|
|
71
|
+
if (dir !== '' && title.endsWith(` | ${dir}`)) {
|
|
72
|
+
title = title.slice(0, title.length - dir.length - 3).trim();
|
|
73
|
+
}
|
|
74
|
+
// Tytuł równy samej nazwie katalogu = panel PRZED pierwszym promptem. Pusty string znaczy
|
|
75
|
+
// „nie ma tytułu", a manager zamienia go na nazwę katalogu tą samą regułą co dla Claude.
|
|
76
|
+
return title === dir ? '' : title;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The `agy` command line as a pane title: `agy` alone or followed by its arguments. herdr 0.9.5 reports the command
|
|
80
|
+
* line as the title of an Antigravity CLI 1.5.18 pane for the whole life of the agent, also after a prompt.
|
|
81
|
+
*/
|
|
82
|
+
const AGY_COMMAND_LINE_RE = /^agy(?:\s|$)/u;
|
|
83
|
+
/** agy title → card title: the command line is no title (the card is named after its directory), any other passes. */
|
|
84
|
+
function normalizeAgyTitle(raw) {
|
|
85
|
+
return AGY_COMMAND_LINE_RE.test(raw.trim()) ? '' : raw;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Pane title of a state-only engine → card title. An empty string means "no title": the manager then names the
|
|
89
|
+
* card after its directory, as for Claude.
|
|
90
|
+
*/
|
|
91
|
+
export function normalizeEngineTitle(engine, title, cwd) {
|
|
92
|
+
switch (engine) {
|
|
93
|
+
case 'codex': return normalizeCodexTitle(title, cwd);
|
|
94
|
+
case 'agy': return normalizeAgyTitle(title);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -84,6 +84,7 @@ export async function readHistoryTail(read, path, size, opts) {
|
|
|
84
84
|
const parsed = parseTranscriptTail(complete, {
|
|
85
85
|
dropFirstLine: false, limit: opts.limit, ...(opts.promptBlock ? {} : { promptBlock: false }),
|
|
86
86
|
...(opts.turnMarks === true ? { turnMarks: true } : {}),
|
|
87
|
+
...(opts.crossSessionPrompts === true ? { crossSessionPrompts: true } : {}),
|
|
87
88
|
});
|
|
88
89
|
tail = {
|
|
89
90
|
complete,
|
|
@@ -142,7 +143,9 @@ export function historyMessages(entries, port) {
|
|
|
142
143
|
}
|
|
143
144
|
const follow = port.follow(m);
|
|
144
145
|
const command = m.command !== undefined;
|
|
145
|
-
|
|
146
|
+
// A message from another session is no echo of a send from Rarog, even with the same text.
|
|
147
|
+
const echoable = m.notice === undefined && m.peer !== true
|
|
148
|
+
&& (command ? m.command?.part === 'invocation' : m.role === 'user');
|
|
146
149
|
const echo = echoable ? port.takeEcho(m, command) : null;
|
|
147
150
|
if (echo === null)
|
|
148
151
|
messages.push(follow);
|
|
@@ -152,16 +155,18 @@ export function historyMessages(entries, port) {
|
|
|
152
155
|
return messages;
|
|
153
156
|
}
|
|
154
157
|
/**
|
|
155
|
-
* Znacznik wyniku komendy jest dla drivera: manager dostaje wiadomości bez niego.
|
|
158
|
+
* Znacznik wyniku komendy jest dla drivera: manager dostaje wiadomości bez niego. The mark of a message from another
|
|
159
|
+
* session serves the driver (`ReturnedPrompt.noteHistory`) and reaches the manager as `notFromOwner`, server-only
|
|
160
|
+
* knowledge for the owner's turn.
|
|
156
161
|
*
|
|
157
162
|
* @returns the messages for the manager and the name of the last command output in the batch, if any.
|
|
158
163
|
*/
|
|
159
164
|
export function withoutCommandOutput(messages) {
|
|
160
165
|
let output;
|
|
161
|
-
const stripped = messages.map(({ commandOutput, ...message }) => {
|
|
166
|
+
const stripped = messages.map(({ commandOutput, peer, ...message }) => {
|
|
162
167
|
if (commandOutput !== undefined)
|
|
163
168
|
output = commandOutput;
|
|
164
|
-
return message;
|
|
169
|
+
return peer === true ? { ...message, notFromOwner: true } : message;
|
|
165
170
|
});
|
|
166
171
|
return { messages: stripped, output };
|
|
167
172
|
}
|
|
@@ -132,7 +132,8 @@ function loadState(file) {
|
|
|
132
132
|
const entry = raw;
|
|
133
133
|
if (typeof entry.key !== 'string' || entry.key === '')
|
|
134
134
|
continue;
|
|
135
|
-
|
|
135
|
+
// `''` is the address of a state-only card without a session ID: the pane alone (`key`).
|
|
136
|
+
if (typeof entry.agentSessionId !== 'string')
|
|
136
137
|
continue;
|
|
137
138
|
// Numer stanu MUSI być skończoną liczbą: `NaN` w porównaniu jest zawsze fałszem, więc
|
|
138
139
|
// wpis-śmieć znaczyłby „widziane" albo „niewidziane" zależnie od strony nierówności.
|
|
@@ -151,6 +152,15 @@ function loadState(file) {
|
|
|
151
152
|
}
|
|
152
153
|
return { aliases, seen };
|
|
153
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Whether an entry's engine session answers a read at this session. `''` addresses a state-only card without a
|
|
157
|
+
* session ID by its pane and matches either way: a session ID that herdr starts or stops reporting for the same pane
|
|
158
|
+
* keeps the mark, while two different session IDs never match. The callers compare the state number for equality,
|
|
159
|
+
* and only a state-only card writes or reads `''`.
|
|
160
|
+
*/
|
|
161
|
+
function sameSession(stored, asked) {
|
|
162
|
+
return stored === asked || stored === '' || asked === '';
|
|
163
|
+
}
|
|
154
164
|
/**
|
|
155
165
|
* Aliasy sesji i znaczniki `seen`, trzymane w RAM i utrwalane ATOMOWO (tmp + rename).
|
|
156
166
|
*
|
|
@@ -212,7 +222,7 @@ export function createHiddenStore(opts) {
|
|
|
212
222
|
return {
|
|
213
223
|
seenSeq(key, agentSessionId) {
|
|
214
224
|
const entry = seen.get(key);
|
|
215
|
-
if (entry === undefined || entry.agentSessionId
|
|
225
|
+
if (entry === undefined || !sameSession(entry.agentSessionId, agentSessionId))
|
|
216
226
|
return undefined;
|
|
217
227
|
return entry.unseen === true ? undefined : entry.stateChangeSeq;
|
|
218
228
|
},
|
|
@@ -220,7 +230,11 @@ export function createHiddenStore(opts) {
|
|
|
220
230
|
const current = seen.get(key);
|
|
221
231
|
if (current?.agentSessionId === agentSessionId
|
|
222
232
|
&& current.unseen !== true
|
|
223
|
-
|
|
233
|
+
// A pane address (`''`) gets its key back after a herdr server restart with the state number counted from
|
|
234
|
+
// zero, so a receipt at a lower number there is a new one and replaces the entry.
|
|
235
|
+
&& (agentSessionId === ''
|
|
236
|
+
? current.stateChangeSeq === stateChangeSeq
|
|
237
|
+
: current.stateChangeSeq >= stateChangeSeq)) {
|
|
224
238
|
// Znacznik już obejmuje ten stan — zapis niczego by nie zmienił, a przy 17 panelach
|
|
225
239
|
// odświeżanych co 30 s byłby stałym ruchem na dysku.
|
|
226
240
|
if (current.by === by)
|
|
@@ -236,13 +250,14 @@ export function createHiddenStore(opts) {
|
|
|
236
250
|
},
|
|
237
251
|
seenBy(key, agentSessionId) {
|
|
238
252
|
const entry = seen.get(key);
|
|
239
|
-
if (entry === undefined || entry.agentSessionId
|
|
253
|
+
if (entry === undefined || !sameSession(entry.agentSessionId, agentSessionId) || entry.unseen === true) {
|
|
240
254
|
return undefined;
|
|
255
|
+
}
|
|
241
256
|
return entry.by;
|
|
242
257
|
},
|
|
243
258
|
unseenSeq(key, agentSessionId) {
|
|
244
259
|
const entry = seen.get(key);
|
|
245
|
-
if (entry === undefined || entry.agentSessionId
|
|
260
|
+
if (entry === undefined || !sameSession(entry.agentSessionId, agentSessionId))
|
|
246
261
|
return undefined;
|
|
247
262
|
return entry.unseen === true ? entry.stateChangeSeq : undefined;
|
|
248
263
|
},
|
|
@@ -367,6 +367,8 @@ class Follower {
|
|
|
367
367
|
#tasksScan;
|
|
368
368
|
/** Rozpoznanie promptu zablokowanego przez hook (`JsonlFollowOptions.promptBlock`). */
|
|
369
369
|
#promptBlock;
|
|
370
|
+
#crossSessionPromptsOf;
|
|
371
|
+
#onEntry;
|
|
370
372
|
/** Identyfikator sesji silnika; `null` = nie przeszedł wzorca, transkryptu nie będzie. */
|
|
371
373
|
#agentSessionId = null;
|
|
372
374
|
/** Rośnie przy każdym otwarciu sesji silnika; unieważnia odczyty w locie (patrz `#openSession`). */
|
|
@@ -580,6 +582,8 @@ class Follower {
|
|
|
580
582
|
this.#tasksScan = { ...opts.tasksScan, logBytes: opts.tasksScan?.logBytes ?? TASKS_SCAN_LOG_BYTES };
|
|
581
583
|
this.#usage = createUsageTracker(this.#knownContextLimit);
|
|
582
584
|
this.#promptBlock = opts.promptBlock !== false;
|
|
585
|
+
this.#crossSessionPromptsOf = opts.crossSessionPrompts ?? (() => false);
|
|
586
|
+
this.#onEntry = opts.onEntry;
|
|
583
587
|
// Unknown until a history read replaces the tracker; a read that fails before that must not answer "empty".
|
|
584
588
|
this.#cliQueue.lose();
|
|
585
589
|
this.#openSession(opts.agentSessionId);
|
|
@@ -1077,6 +1081,7 @@ class Follower {
|
|
|
1077
1081
|
return readHistoryTail((p, start, length) => this.#io.readRange(p, start, length), path, size, {
|
|
1078
1082
|
firstWindow: this.#historyBytes, maxBytes: this.#historyMaxBytes, limit: this.#historyMessages,
|
|
1079
1083
|
promptBlock: this.#promptBlock, stale: () => this.#stale(gen),
|
|
1084
|
+
...(this.#crossSessionPrompts() ? { crossSessionPrompts: true } : {}),
|
|
1080
1085
|
});
|
|
1081
1086
|
}
|
|
1082
1087
|
/**
|
|
@@ -1676,17 +1681,25 @@ class Follower {
|
|
|
1676
1681
|
for (const line of combined.slice(0, cut).split('\n'))
|
|
1677
1682
|
this.#handleLine(line);
|
|
1678
1683
|
}
|
|
1684
|
+
#crossSessionPrompts() {
|
|
1685
|
+
return this.#agentSessionId !== null && this.#crossSessionPromptsOf(this.#agentSessionId);
|
|
1686
|
+
}
|
|
1679
1687
|
#handleLine(line) {
|
|
1680
1688
|
// Dwa niezależne przebiegi po tej samej linii: `#noteRaw` bierze to, czego parser treści
|
|
1681
1689
|
// nie zwraca (surowy `input`, `id`, `usage`, tryb), a `parseImportLine` — treść.
|
|
1682
1690
|
const raw = parseJsonlEntry(line);
|
|
1691
|
+
if (raw !== null && this.#agentSessionId !== null)
|
|
1692
|
+
this.#onEntry?.(this.#agentSessionId, raw);
|
|
1683
1693
|
const openBefore = this.#pending.open;
|
|
1684
1694
|
this.#noteRaw(raw);
|
|
1685
1695
|
// The end of the call on the row (live tail only): the row moves to a call still open, or to `thinking`.
|
|
1686
1696
|
const ended = toolEndActivity(raw, openBefore, this.#pending.open);
|
|
1687
1697
|
if (ended !== null)
|
|
1688
1698
|
this.#push({ type: 'activity', ...ended });
|
|
1689
|
-
const entry = parseImportLine(line,
|
|
1699
|
+
const entry = parseImportLine(line, {
|
|
1700
|
+
...(this.#promptBlock ? {} : { promptBlock: false }),
|
|
1701
|
+
...(this.#crossSessionPrompts() ? { crossSessionPrompts: true } : {}),
|
|
1702
|
+
});
|
|
1690
1703
|
// The call entry that repeats the plain "/compact" entry before it gives nothing, as in the history.
|
|
1691
1704
|
if (entry !== null && this.#fileEcho.repeats(entry.fileEcho, entry.message !== null))
|
|
1692
1705
|
return;
|
|
@@ -1724,6 +1737,11 @@ class Follower {
|
|
|
1724
1737
|
this.#push({ type: 'message', role: 'user', blocks: message.blocks, notice: message.notice });
|
|
1725
1738
|
return;
|
|
1726
1739
|
}
|
|
1740
|
+
// A message from another session is not a send from Rarog either, even with the same text.
|
|
1741
|
+
if (message.peer === true) {
|
|
1742
|
+
this.#push({ type: 'message', role: 'user', blocks: message.blocks, peer: true });
|
|
1743
|
+
return;
|
|
1744
|
+
}
|
|
1727
1745
|
// Echo własnego promptu gasimy TU, a nie w managerze (patrz nagłówek pliku). Wiadomości
|
|
1728
1746
|
// z niego nie ma, ale fakt zostaje: CLI właśnie wzięło ten prompt do tury (kolejka zmierzona
|
|
1729
1747
|
// na 2.1.299). Manager liczy go też przy wysyłce, tyle że prompt wysłany w trakcie tury trafia tu
|
|
@@ -1772,6 +1790,7 @@ class Follower {
|
|
|
1772
1790
|
* Wywołanie komendy zapamiętuje swoją nazwę, a wynik dostaje `commandOutput` z nazwą z wpisu albo
|
|
1773
1791
|
* z ostatniego wywołania — driver kończy po nim komendę lokalną wysłaną z Raroga. Wołane dla
|
|
1774
1792
|
* KAŻDEJ wiadomości w kolejności pliku (historia i tail), także dla wywołania zgaszonego echem.
|
|
1793
|
+
* The mark of a message from another session goes on to the driver (`FollowMessage.peer`).
|
|
1775
1794
|
*/
|
|
1776
1795
|
#followMessage(message) {
|
|
1777
1796
|
const { command, ...rest } = message;
|