@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
package/server/src/index.js
CHANGED
|
@@ -17,7 +17,7 @@ import { createAdminHandler, publicUrlOf, redact, startAdminSocket } from './aut
|
|
|
17
17
|
import { clearReviewClientLogs } from './client-log.js';
|
|
18
18
|
import { assembleCompanion } from './companion/index.js';
|
|
19
19
|
import { ConfigError, HERDR_HISTORY_BYTES, assertLoopbackHost, loadConfig } from './config.js';
|
|
20
|
-
import { DIALOG_LAYER2_ENV } from './config-env.js';
|
|
20
|
+
import { DIALOG_LAYER2_ENV, DIALOG_LIVE_ENV } from './config-env.js';
|
|
21
21
|
import { skippedOriginLine } from './config/listen.js';
|
|
22
22
|
import { irohAdminStatus } from './iroh/listener.js';
|
|
23
23
|
import { gitReadEnv, probeGitSandboxAtStart } from './git-status.js';
|
|
@@ -33,10 +33,12 @@ import { healthProbes } from './bootstrap/health.js';
|
|
|
33
33
|
import { prepareHookFiles } from './bootstrap/hook-files.js';
|
|
34
34
|
import { loadDemoHerdr } from './bootstrap/herdr.js';
|
|
35
35
|
import { buildRouter, configureHttpServer } from './bootstrap/http.js';
|
|
36
|
+
import { coordinationFollower, createCoordination, wireCoordination } from './bootstrap/coordination.js';
|
|
37
|
+
import { createCoordinatorStart, openCoordinators, pluginFact } from './bootstrap/coordinator-start.js';
|
|
36
38
|
import { assembleInbox } from './bootstrap/inbox.js';
|
|
37
39
|
import { startServerIroh } from './bootstrap/iroh.js';
|
|
38
40
|
import { loadSdk, managerConfig } from './bootstrap/manager.js';
|
|
39
|
-
import { createPush } from './bootstrap/push.js';
|
|
41
|
+
import { createPush, wireReadyToMerge } from './bootstrap/push.js';
|
|
40
42
|
import { createPrStatus } from './bootstrap/pr-status.js';
|
|
41
43
|
import { createSseHub } from './bootstrap/sse.js';
|
|
42
44
|
import { loadTerm } from './bootstrap/term.js';
|
|
@@ -111,7 +113,7 @@ async function readTranscriptTail(file) {
|
|
|
111
113
|
* modułu, wyjątek przy budowie nadzorcy, nieosiągalne gniazdo — wszystko kończy się tak samo,
|
|
112
114
|
* czyli logiem, pustą listą i BANEREM w kliencie. Nigdy 500 i nigdy nieudany start.
|
|
113
115
|
*/
|
|
114
|
-
async function loadHerdr(config, log, shadow, demoContent, consentMode, consentLink, cliVersionReader, versionWatch, consentProofGate, aliveSessions) {
|
|
116
|
+
async function loadHerdr(config, log, shadow, demoContent, consentMode, consentLink, cliVersionReader, versionWatch, consentProofGate, aliveSessions, follow) {
|
|
115
117
|
// `main()` ładuje zestaw treści tylko w demo, więc to jest gałąź demo.
|
|
116
118
|
if (demoContent !== null)
|
|
117
119
|
return loadDemoHerdr(log, demoContent);
|
|
@@ -201,6 +203,8 @@ async function loadHerdr(config, log, shadow, demoContent, consentMode, consentL
|
|
|
201
203
|
launchEnabled: config.herdrLaunch,
|
|
202
204
|
// Bez tej flagi filtr wejściowy odrzuca panele Codexa.
|
|
203
205
|
codexStatusEnabled: config.codexStatusEnabled,
|
|
206
|
+
// Without this flag the input filter drops agy panes.
|
|
207
|
+
agyStatusEnabled: config.agyStatusEnabled,
|
|
204
208
|
// `0` = etykiety tabów zostają z zakładania, bez synchronizacji z kartą i bez migracji.
|
|
205
209
|
tabLabels: config.herdrTabLabels,
|
|
206
210
|
maxPanes: config.maxPanes,
|
|
@@ -329,8 +333,12 @@ async function loadHerdr(config, log, shadow, demoContent, consentMode, consentL
|
|
|
329
333
|
readAgentFiles: config.agentFiles,
|
|
330
334
|
// `RAROG_PROMPT_BLOCK=0` = follower pomija wpis promptu zablokowanego przez hook (`docs/dialogs.md`).
|
|
331
335
|
promptBlock: config.promptBlock,
|
|
336
|
+
// The transcript follower that asks the coordination overlay about bubbles of other sessions.
|
|
337
|
+
...(follow === undefined ? {} : { follow }),
|
|
332
338
|
// `RAROG_DIALOG_LAYER2`: flaga czytana raz przy starcie, do decyzji dociera tym polem (`docs/dialogs.md`).
|
|
333
339
|
dialogLayer2: config.dialogLayer2,
|
|
340
|
+
// `RAROG_DIALOG_LIVE`: read once at start, the driver's live dialog card level (`docs/dialogs.md`).
|
|
341
|
+
dialogLive: config.dialogLive,
|
|
334
342
|
}),
|
|
335
343
|
});
|
|
336
344
|
// Restored messages of a pane that does not attach after the first resync (and a grace) are not sent.
|
|
@@ -363,7 +371,7 @@ async function loadHerdr(config, log, shadow, demoContent, consentMode, consentL
|
|
|
363
371
|
void supervisor.hidden.rememberAlias(engineSessionId, sessionId);
|
|
364
372
|
},
|
|
365
373
|
assertSendable: herdr.assertSendable,
|
|
366
|
-
commandCatalog: (cwd, cliVersion) => commandCatalogs.get(cwd, cliVersion),
|
|
374
|
+
commandCatalog: (cwd, cliVersion, pluginDirs) => commandCatalogs.get(cwd, cliVersion, pluginDirs),
|
|
367
375
|
/*
|
|
368
376
|
* Walidacja `resumeFrom` po TREŚCI transkryptu (`docs/security-model.md`, „`resumeFrom` is validated…”), nie po samym regeksie uuida.
|
|
369
377
|
*
|
|
@@ -528,7 +536,15 @@ async function main() {
|
|
|
528
536
|
});
|
|
529
537
|
// The supervisor's agent set signal for `alive.json`; the writer joins it below (`bootstrap/alive-sessions.ts`).
|
|
530
538
|
const aliveSessions = createAliveSessionsSignal();
|
|
531
|
-
|
|
539
|
+
// Coordinators and their threads in the summaries (`bootstrap/coordination.ts`); `null` in the demo. Before the
|
|
540
|
+
// supervisor, because the transcript follower of every pane asks it. One registry for the overlay and the starts
|
|
541
|
+
// (`bootstrap/coordinator-start.ts`); the plugin fact reads the manager, created below.
|
|
542
|
+
const coordinators = openCoordinators(config, (line) => { log.info(line); });
|
|
543
|
+
const coordination = createCoordination(config, {
|
|
544
|
+
log: (line) => { log.info(line); },
|
|
545
|
+
options: { pluginOf: pluginFact(() => managerRef), ...(coordinators === null ? {} : { registry: coordinators }) },
|
|
546
|
+
});
|
|
547
|
+
const herdr = await loadHerdr(config, log, shadowChannel, demoContent, consentMode, consentLink, cliVersionReader, versionWatch, consentProofGate, aliveSessions, coordination === null ? undefined : coordinationFollower(coordination));
|
|
532
548
|
if (config.demo) {
|
|
533
549
|
log.info('herdr: demo mode, a supervisor mock instead of the socket (zero panes, zero processes)');
|
|
534
550
|
}
|
|
@@ -564,6 +580,8 @@ async function main() {
|
|
|
564
580
|
log.info(`shadow: hook consent channel ${config.consentChannel}`);
|
|
565
581
|
if (!config.demo)
|
|
566
582
|
log.info(`dialogs: layer 2 ${DIALOG_LAYER2_ENV}=${config.dialogLayer2 ? '1' : '0'}`);
|
|
583
|
+
if (!config.demo)
|
|
584
|
+
log.info(`dialogs: live card ${DIALOG_LIVE_ENV}=${String(config.dialogLive)}`);
|
|
567
585
|
/*
|
|
568
586
|
* Manager powstaje niżej, a cykl woła go od pierwszej karty (`onCard`), także w `recover` przed managerem: wtedy
|
|
569
587
|
* referencja jest pusta i karta trafia do urządzeń przez snapshot sesji. Rejestracja przed managerem nie szturcha
|
|
@@ -610,8 +628,20 @@ async function main() {
|
|
|
610
628
|
...(consentCycle === null ? {} : { consentForgotten: consentForgottenPort(consentCycle, log) }),
|
|
611
629
|
...(prStatus === null ? {} : { prStatus: prStatus.port }),
|
|
612
630
|
...(stalledWait === undefined ? {} : { stalledWait }),
|
|
631
|
+
...(coordination === null ? {} : { coordination }),
|
|
632
|
+
...(coordination === null || coordinators === null ? {} : {
|
|
633
|
+
coordinatorStart: createCoordinatorStart(config, {
|
|
634
|
+
registry: coordinators, coordination, log: (line) => { log.info(line); },
|
|
635
|
+
}),
|
|
636
|
+
}),
|
|
613
637
|
});
|
|
614
638
|
managerRef = manager;
|
|
639
|
+
// Roles and merge states follow the session events; the ready-to-merge push follows the thread summaries.
|
|
640
|
+
if (coordination !== null)
|
|
641
|
+
wireCoordination(coordination, manager);
|
|
642
|
+
if (coordination !== null && push.readyToMerge !== undefined) {
|
|
643
|
+
wireReadyToMerge(push.readyToMerge, manager, (id) => coordination.checkedOf(id));
|
|
644
|
+
}
|
|
615
645
|
/*
|
|
616
646
|
* Live Activity słucha strumienia GLOBALNEGO — tego samego, z którego lista klienta zna stan
|
|
617
647
|
* każdej sesji. Każdy event to tylko „przelicz" (składane w 250 ms); czy coś wyjdzie do APNs,
|
|
@@ -628,6 +658,7 @@ async function main() {
|
|
|
628
658
|
*/
|
|
629
659
|
const inboxParts = await assembleInbox({
|
|
630
660
|
config, manager, ready: manager.ready, log: (line) => { log.info(line); },
|
|
661
|
+
...(coordination === null ? {} : { checkedOf: (id) => coordination.checkedOf(id) }),
|
|
631
662
|
});
|
|
632
663
|
const inbox = inboxParts?.inbox ?? null;
|
|
633
664
|
// Nadzorca podpięty, seedy demo założone — dopiero wtedy wpuszczamy ruch HTTP.
|
|
@@ -777,6 +808,7 @@ async function main() {
|
|
|
777
808
|
demoControl?.dispose();
|
|
778
809
|
hub.closeAll();
|
|
779
810
|
prStatus?.tracker.close();
|
|
811
|
+
coordination?.close();
|
|
780
812
|
// `server.close()` NIE dotyka gniazd po upgrade — bez tego proces wisiałby na żywym
|
|
781
813
|
// WebSockecie terminala. Powłoki w panelach herdr zostają: giną wyłącznie kontrolery.
|
|
782
814
|
term?.dispose();
|
|
@@ -19,6 +19,7 @@ import { createHash } from 'node:crypto';
|
|
|
19
19
|
import { NOTIFY_KIND_TITLE } from '@rarog/shared/notify-copy';
|
|
20
20
|
import { isForeignText, isServerSentence, say } from '@rarog/shared/sentences';
|
|
21
21
|
import { serverSystem } from '../version.js';
|
|
22
|
+
import { READY_TO_MERGE_CLASS } from './policy.js';
|
|
22
23
|
/** Ile znaków treści mieści się na banerze, zanim iOS i tak ją utnie w środku słowa. */
|
|
23
24
|
export const MESSAGE_MAX_CHARS = 120;
|
|
24
25
|
/**
|
|
@@ -39,6 +40,7 @@ const FALLBACK_BODY = {
|
|
|
39
40
|
error: 'push.body.fallback.error',
|
|
40
41
|
limit: 'push.body.fallback.limit',
|
|
41
42
|
stalled: 'push.body.fallback.stalled',
|
|
43
|
+
'ready-to-merge': 'push.body.fallback.ready-to-merge',
|
|
42
44
|
};
|
|
43
45
|
/**
|
|
44
46
|
* Jak długo APNs trzyma wiadomość dla telefonu, który akurat jest poza siecią (`apns-expiration`
|
|
@@ -240,6 +242,31 @@ export function buildStalledContent(input) {
|
|
|
240
242
|
...(input.badge === undefined ? {} : { badge: input.badge }),
|
|
241
243
|
};
|
|
242
244
|
}
|
|
245
|
+
/**
|
|
246
|
+
* Push `ready-to-merge`: a coordinator's thread passed its checks and waits for the owner's Merge. The title has the
|
|
247
|
+
* project (`push.title.ready-to-merge`); the body is `push.body.detail-and-label` with the commit count
|
|
248
|
+
* (`push.detail.merge-ready`, singular or plural) as the detail and the thread name as the label. Urgent and
|
|
249
|
+
* short-lived like a decision banner (`READY_TO_MERGE_CLASS`). The collapse key is the session topic ({@link topicFor}), so
|
|
250
|
+
* the banner takes the place of an older banner of the same thread, and a later banner of the thread takes its place.
|
|
251
|
+
*/
|
|
252
|
+
export function buildReadyToMergeContent(input) {
|
|
253
|
+
const label = oneLine(input.name);
|
|
254
|
+
const detail = say('push.detail.merge-ready', { commits: input.commits }).text;
|
|
255
|
+
const body = label === ''
|
|
256
|
+
? sentence(say(FALLBACK_BODY['ready-to-merge']))
|
|
257
|
+
: fitBody((d) => say('push.body.detail-and-label', { detail: d, label }), detail);
|
|
258
|
+
return {
|
|
259
|
+
kind: 'ready-to-merge',
|
|
260
|
+
sessionId: input.sessionId,
|
|
261
|
+
...(input.termId === undefined ? {} : { termId: input.termId }),
|
|
262
|
+
...titleFields(sentence(say(NOTIFY_KIND_TITLE['ready-to-merge'], { project: input.project }))),
|
|
263
|
+
...bodyFields(body),
|
|
264
|
+
topic: topicFor(input.sessionId),
|
|
265
|
+
urgency: URGENCY[READY_TO_MERGE_CLASS],
|
|
266
|
+
ttl: TTL_SECONDS[READY_TO_MERGE_CLASS],
|
|
267
|
+
...(input.badge === undefined ? {} : { badge: input.badge }),
|
|
268
|
+
};
|
|
269
|
+
}
|
|
243
270
|
/**
|
|
244
271
|
* Push PRÓBNY po włączeniu powiadomień: tap otwiera listę sesji. Krótki TTL — próba, która
|
|
245
272
|
* dojdzie po godzinie, niczego już nie potwierdza. Bez plakietki: nie wiemy tu, ile sesji czeka.
|
|
@@ -48,6 +48,10 @@ function sendLogLine(kind, project, report) {
|
|
|
48
48
|
* standby alone keep a fixed wording, because people and documents read them.
|
|
49
49
|
*/
|
|
50
50
|
function noResultCause(turn) {
|
|
51
|
+
// No input at all: a subagent woken from standby worked in the pane.
|
|
52
|
+
if (turn.standbyNotices === 0 && turn.artifactWatch === 0 && turn.compactions === 0) {
|
|
53
|
+
return { turn: 'turn after subagent work alone', owed: 'with subagent work alone' };
|
|
54
|
+
}
|
|
51
55
|
// A context compaction, alone or joined with the other causes of the turn.
|
|
52
56
|
if (turn.compactions > 0) {
|
|
53
57
|
const cause = [
|
|
@@ -200,9 +204,9 @@ export class Notifier {
|
|
|
200
204
|
else if (kind === 'done' && input.backgroundTasks === 0 && input.turnInput !== undefined
|
|
201
205
|
&& noResultTurn(input.turnInput)) {
|
|
202
206
|
// A reason visible neither in the session state nor in the task list: the turn was triggered
|
|
203
|
-
// by a CLI report alone, after which nothing finished.
|
|
204
|
-
// silence keeps its usual reason and no line. An owed "done"
|
|
205
|
-
// own command gets its own wording in the log.
|
|
207
|
+
// by a CLI report alone (or by a woken subagent's work alone), after which nothing finished.
|
|
208
|
+
// With background work running the silence keeps its usual reason and no line. An owed "done"
|
|
209
|
+
// waiting for a subagent with its own command gets its own wording in the log.
|
|
206
210
|
const held = this.#owed.has(input.sessionId) && input.waitingOnOwnCommand === true
|
|
207
211
|
? ', owed waits: the subagent waits for its own command' : '';
|
|
208
212
|
this.#log?.(`${PUSH_QUIET_LOG} ${input.project} (done, ${noResultCause(input.turnInput).turn}${held})`);
|
|
@@ -122,16 +122,25 @@ function workflowOf({ session, task, run }) {
|
|
|
122
122
|
states: counts.map(stateOf),
|
|
123
123
|
};
|
|
124
124
|
}
|
|
125
|
+
/** The merge state of a coordinator's thread (`coordination.merge`); absent for any other session. */
|
|
126
|
+
function threadMerge(session) {
|
|
127
|
+
return session.coordination?.role === 'thread' ? session.coordination.merge?.state : undefined;
|
|
128
|
+
}
|
|
125
129
|
/** Lista sesji → stan treści aktywności (kolejność kluczy = kolejność w kontrakcie). */
|
|
126
130
|
export function aggregateState(sessions, nowMs, extras = {}) {
|
|
127
131
|
const nowSec = Math.floor(nowMs / 1000);
|
|
128
132
|
const waiting = sessions.filter((s) => WAITING.includes(s.state));
|
|
129
133
|
const working = sessions.filter((s) => WORKING.includes(s.state));
|
|
134
|
+
// A thread with a merge state counts by it alone, once: `ready` waits for the owner's Merge, `merging` is the
|
|
135
|
+
// coordinator's work, `merged` counts nowhere. The tap target and the tile lifetime stay with the session state.
|
|
136
|
+
const ready = sessions.filter((s) => threadMerge(s) === 'ready').length;
|
|
137
|
+
const merging = sessions.filter((s) => threadMerge(s) === 'merging').length;
|
|
138
|
+
const plain = sessions.filter((s) => threadMerge(s) === undefined);
|
|
130
139
|
// A session after a turn whose subagent is stuck on its own command waits for the owner: it counts once, as waiting.
|
|
131
|
-
const stuck =
|
|
132
|
-
const background =
|
|
140
|
+
const stuck = plain.filter((s) => stuckWait(s.state, s.backgroundTasks));
|
|
141
|
+
const background = plain.filter((s) => QUIET.includes(s.state) && !stuck.includes(s)
|
|
133
142
|
&& hasBackgroundWork(s.backgroundTasks));
|
|
134
|
-
const finished =
|
|
143
|
+
const finished = plain.filter((s) => s.state === 'waiting-input' && s.seen !== true && !stuck.includes(s) && !hasBackgroundWork(s.backgroundTasks)).length;
|
|
135
144
|
// Wiodąca bez zmian: sesja „w tle" nie jest celem tapnięcia — jej tura już się skończyła. The same holds for a
|
|
136
145
|
// stuck session, so it is not a lead candidate.
|
|
137
146
|
const lead = longest(waiting) ?? longest(working);
|
|
@@ -141,8 +150,8 @@ export function aggregateState(sessions, nowMs, extras = {}) {
|
|
|
141
150
|
const limits = extras.limits !== undefined && Object.keys(extras.limits).length > 0 ? extras.limits : undefined;
|
|
142
151
|
const mac = extras.mac !== undefined && Object.keys(extras.mac).length > 0 ? extras.mac : undefined;
|
|
143
152
|
return {
|
|
144
|
-
waiting:
|
|
145
|
-
working:
|
|
153
|
+
waiting: plain.filter((s) => WAITING.includes(s.state)).length + stuck.length + ready,
|
|
154
|
+
working: plain.filter((s) => WORKING.includes(s.state)).length + background.length + merging,
|
|
146
155
|
finished,
|
|
147
156
|
...(lead === undefined ? {} : { top: topOf(lead) }),
|
|
148
157
|
...(workflows.length === 0 ? {} : { workflows }),
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
export function kindOf(event) {
|
|
3
3
|
switch (event.type) {
|
|
4
4
|
case 'permission-requested': return 'permission';
|
|
5
|
+
case 'subagent-consent-pending': return 'permission';
|
|
5
6
|
case 'question-requested': return 'question';
|
|
6
7
|
case 'agent-blocked': return 'blocked';
|
|
7
8
|
case 'result': return event.subtype === 'success' ? 'done' : 'error';
|
|
@@ -13,8 +14,8 @@ export function kindOf(event) {
|
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
16
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
17
|
+
* A turn WITHOUT A RESULT: a CLI report alone triggered it, or no input at all while a woken subagent worked, and
|
|
18
|
+
* nothing ended. Four kinds, one rule for silence, the owed result and the check before send.
|
|
18
19
|
*
|
|
19
20
|
* - **Subagent standby**: a subagent stops because it waits on its own command. The CLI reports this to the
|
|
20
21
|
* main agent with a `user`-role entry; the main agent writes a sentence ("still waiting") and ends the turn.
|
|
@@ -29,17 +30,25 @@ export function kindOf(event) {
|
|
|
29
30
|
* expires; the pane works for under a minute and writes no reply (measured on CLI 2.1.325). Same condition as
|
|
30
31
|
* the artifact notification: no tool call.
|
|
31
32
|
*
|
|
33
|
+
* - **Subagent work alone**: no input at all, but a subagent woke from standby in the window
|
|
34
|
+
* ({@link TurnInput.subagentWakes}). Its own background command ended, the CLI woke it, and herdr reports the
|
|
35
|
+
* main pane as working while it works; the main agent answers nothing. Its standby notice usually comes a second
|
|
36
|
+
* after the turn end, so it counts towards the next turn (observed on CLI 2.1.332). Accepted risk: a human
|
|
37
|
+
* prompt whose entry reaches the manager only after the turn end, in a window with such a wake, is silenced too.
|
|
38
|
+
*
|
|
32
39
|
* Wspólne: żadnej innej wiadomości `user` od poprzedniego końca tury. Cokolwiek innego — prompt
|
|
33
|
-
* człowieka, notka o końcu komendy, raport subagenta — znaczy, że jest co odebrać.
|
|
34
|
-
*
|
|
35
|
-
*
|
|
40
|
+
* człowieka, notka o końcu komendy, raport subagenta — znaczy, że jest co odebrać. A turn without any `user`
|
|
41
|
+
* message and without a subagent wake has a cause Rarog does not know and gives the ordinary "done", and so does
|
|
42
|
+
* an incomplete tally (`undefined`): no certainty means the ordinary "done".
|
|
36
43
|
*/
|
|
37
44
|
export function noResultTurn(turn) {
|
|
38
45
|
if (turn === undefined || turn.other > 0)
|
|
39
46
|
return false;
|
|
40
47
|
if (turn.artifactWatch > 0 || turn.compactions > 0)
|
|
41
48
|
return turn.toolCalls === 0;
|
|
42
|
-
|
|
49
|
+
if (turn.standbyNotices > 0)
|
|
50
|
+
return true;
|
|
51
|
+
return (turn.subagentWakes ?? 0) > 0;
|
|
43
52
|
}
|
|
44
53
|
/**
|
|
45
54
|
* Czy to zdarzenie jest końcem ZWYKŁEJ tury, czyli zostawia wynik do odebrania (zaległe
|
|
@@ -56,9 +65,9 @@ export function noResultTurn(turn) {
|
|
|
56
65
|
* - uzbrojone „gotowe" gaśnie przy sprawdzeniu, bo subagent ruszył ({@link doneStaysOwed}),
|
|
57
66
|
* a jego następny postój daje już tylko turę po samym postoju.
|
|
58
67
|
*
|
|
59
|
-
* Końcem zwykłej tury NIE jest: tura bez wyniku ({@link noResultTurn}: po samym postoju
|
|
60
|
-
* samym meldunku o artefakcie bez narzędzi), pierwsze `idle` karty
|
|
61
|
-
* ani start sesji ({@link ClassifyInput.afterStart}) — w obu ostatnich żadna tura się nie skończyła.
|
|
68
|
+
* Końcem zwykłej tury NIE jest: tura bez wyniku ({@link noResultTurn}: po samym postoju, po
|
|
69
|
+
* samym meldunku o artefakcie bez narzędzi, after subagent work alone), pierwsze `idle` karty
|
|
70
|
+
* odtworzonej po restarcie herdr ani start sesji ({@link ClassifyInput.afterStart}) — w obu ostatnich żadna tura się nie skończyła.
|
|
62
71
|
* Nor is the end of a turn of a test session ({@link ClassifyInput.testSession}): nobody owes the owner its result.
|
|
63
72
|
*/
|
|
64
73
|
export function leavesResult(input) {
|
|
@@ -86,6 +95,9 @@ export function classify(input) {
|
|
|
86
95
|
case 'permission-requested':
|
|
87
96
|
case 'question-requested':
|
|
88
97
|
case 'agent-blocked':
|
|
98
|
+
// A subagent's card brings `waiting-permission` back. A banner already sent in the same unbroken stay is not sent
|
|
99
|
+
// again (the notifier's sent memory), and one armed by the card's first view and disarmed by a turn end is re-armed.
|
|
100
|
+
case 'subagent-consent-pending':
|
|
89
101
|
return 'blocking';
|
|
90
102
|
// Tura padła. `error_max_turns` jest tu razem z `error` świadomie: nikt nie czeka na
|
|
91
103
|
// odpowiedź, ale sesja stanęła i nie ruszy, dopóki jej nie wznowisz.
|
|
@@ -145,8 +157,8 @@ export function classify(input) {
|
|
|
145
157
|
* tło tylko czeka, dostaje „gotowe" jak sesja bez tła.
|
|
146
158
|
*
|
|
147
159
|
* Drugi warunek: tura nie może być turą bez wyniku ({@link noResultTurn}: sam meldunek o postoju
|
|
148
|
-
* subagenta
|
|
149
|
-
* klasy: dialog i błąd w takiej turze stoją na człowieku jak każde inne. Wyjątek: „gotowe" zaległe
|
|
160
|
+
* subagenta, sam meldunek o artefakcie, po którym agent nie użył narzędzia, or a woken subagent's work
|
|
161
|
+
* alone). Dotyczy tylko tej klasy: dialog i błąd w takiej turze stoją na człowieku jak każde inne. Wyjątek: „gotowe" zaległe
|
|
150
162
|
* po wcześniejszej zwykłej turze (`doneOwed`, {@link leavesResult}) wychodzi także po turze bez
|
|
151
163
|
* wyniku.
|
|
152
164
|
*
|
|
@@ -273,3 +285,29 @@ function stillHolds(input) {
|
|
|
273
285
|
&& !(input.owedRelease === true && input.waitingOnOwnCommand === true);
|
|
274
286
|
}
|
|
275
287
|
}
|
|
288
|
+
/**
|
|
289
|
+
* Which commit is due a `ready-to-merge` push: the `checked` commit of a thread in `ready` that is not the commit
|
|
290
|
+
* already `announced` (pushed, or seen ready by the owner in Rarog). One push per checked commit: the summary
|
|
291
|
+
* refreshes a ready thread many times, and a Merge that ends without a merge brings `ready` back on the same commit,
|
|
292
|
+
* which the owner has just seen. `merging`, `merged` and a thread sent back are due nothing.
|
|
293
|
+
*/
|
|
294
|
+
export function readyToMergeDue(facts, announced) {
|
|
295
|
+
if (facts.state !== 'ready' || facts.checked === undefined)
|
|
296
|
+
return undefined;
|
|
297
|
+
return facts.checked === announced ? undefined : facts.checked;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Verdict on a `ready-to-merge` push after its window ({@link FIRST_CHECK_MS} of {@link READY_TO_MERGE_CLASS}):
|
|
301
|
+
* send only while the thread still stands `ready` on the `armed` commit and nobody looks at Rarog (`presentNow`) or at
|
|
302
|
+
* this thread (`seen`). Like {@link decide}, presence cancels rather than postpones.
|
|
303
|
+
*/
|
|
304
|
+
export function decideReadyToMerge(input) {
|
|
305
|
+
if (input.seen || input.presentNow)
|
|
306
|
+
return 'drop';
|
|
307
|
+
return input.now.state === 'ready' && input.now.checked === input.armed ? 'send' : 'drop';
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* The class a `ready-to-merge` push is handled as: the thread stands on the owner's Merge, as a dialog stands on a
|
|
311
|
+
* decision, so it waits the short window and goes out urgent with a short life (`content.ts`).
|
|
312
|
+
*/
|
|
313
|
+
export const READY_TO_MERGE_CLASS = 'blocking';
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ready-to-merge push: one `ready-to-merge` push per checked commit of a coordinator's thread that stays `ready`
|
|
3
|
+
* through a short window while nobody looks at Rarog. The caller hands in the thread's facts on every summary change
|
|
4
|
+
* ({@link readyToMergeFactsOf}); which commit is due and the verdict after the window are pure rules in `policy.ts`.
|
|
5
|
+
* It sends straight through the APNs sink, next to the banner scheduler (`notify/index.ts`) and never through it,
|
|
6
|
+
* because a thread turning ready is no state transition of its session. It never reads thread files or git; memory
|
|
7
|
+
* lives in the process. No retry after a failed send. Never throws.
|
|
8
|
+
*/
|
|
9
|
+
import { basename } from 'node:path';
|
|
10
|
+
import { buildReadyToMergeContent } from './content.js';
|
|
11
|
+
import { PUSH_QUIET_LOG } from './index.js';
|
|
12
|
+
import { FIRST_CHECK_MS, READY_TO_MERGE_CLASS, decideReadyToMerge, readyToMergeDue } from './policy.js';
|
|
13
|
+
/** The window between a thread turning ready and the check before the send: the window of its class. */
|
|
14
|
+
export const READY_TO_MERGE_CHECK_MS = FIRST_CHECK_MS[READY_TO_MERGE_CLASS];
|
|
15
|
+
/**
|
|
16
|
+
* The thread's facts from its summary, or `undefined` for a coordinator and an ordinary session. The project is the
|
|
17
|
+
* directory name of the main checkout (`projectRoot`), because a thread's own working directory is its worktree;
|
|
18
|
+
* without `projectRoot` the session title.
|
|
19
|
+
*/
|
|
20
|
+
export function readyToMergeFactsOf(summary, checked) {
|
|
21
|
+
const role = summary.coordination;
|
|
22
|
+
if (role?.role !== 'thread')
|
|
23
|
+
return undefined;
|
|
24
|
+
const root = summary.projectRoot === undefined ? '' : basename(summary.projectRoot);
|
|
25
|
+
return {
|
|
26
|
+
sessionId: summary.id,
|
|
27
|
+
project: root === '' ? summary.title : root,
|
|
28
|
+
name: role.name,
|
|
29
|
+
...(summary.termId === undefined ? {} : { termId: summary.termId }),
|
|
30
|
+
...(role.merge === undefined ? {} : { merge: { state: role.merge.state, commits: role.merge.commits } }),
|
|
31
|
+
...(checked === undefined ? {} : { checked }),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const defaultScheduler = {
|
|
35
|
+
setTimeout: (fn, ms) => setTimeout(fn, ms).unref(),
|
|
36
|
+
clearTimeout: (handle) => { clearTimeout(handle); },
|
|
37
|
+
};
|
|
38
|
+
const mergeFacts = (facts) => ({
|
|
39
|
+
...(facts.merge === undefined ? {} : { state: facts.merge.state }),
|
|
40
|
+
...(facts.checked === undefined ? {} : { checked: facts.checked }),
|
|
41
|
+
});
|
|
42
|
+
const OUTCOME_LABEL = {
|
|
43
|
+
delivered: 'SENT',
|
|
44
|
+
failed: 'FAILED',
|
|
45
|
+
'no-receiver': 'NO RECEIVER',
|
|
46
|
+
};
|
|
47
|
+
export function createReadyToMergeAlert(options) {
|
|
48
|
+
const scheduler = options.scheduler ?? defaultScheduler;
|
|
49
|
+
const threads = new Map();
|
|
50
|
+
let closed = false;
|
|
51
|
+
const quiet = (facts, why) => {
|
|
52
|
+
options.log(`${PUSH_QUIET_LOG} ${facts.project} (ready-to-merge, ${why})`);
|
|
53
|
+
};
|
|
54
|
+
const disarm = (entry) => {
|
|
55
|
+
if (entry.timer !== undefined)
|
|
56
|
+
scheduler.clearTimeout(entry.timer);
|
|
57
|
+
entry.timer = undefined;
|
|
58
|
+
entry.pending = undefined;
|
|
59
|
+
};
|
|
60
|
+
const check = async (sessionId, armed) => {
|
|
61
|
+
const entry = threads.get(sessionId);
|
|
62
|
+
if (closed || entry === undefined)
|
|
63
|
+
return;
|
|
64
|
+
entry.timer = undefined;
|
|
65
|
+
entry.pending = undefined;
|
|
66
|
+
const { facts } = entry;
|
|
67
|
+
const verdict = decideReadyToMerge({
|
|
68
|
+
armed,
|
|
69
|
+
now: mergeFacts(facts),
|
|
70
|
+
presentNow: options.presence.active(),
|
|
71
|
+
seen: options.presence.watching(sessionId),
|
|
72
|
+
});
|
|
73
|
+
if (verdict === 'drop') {
|
|
74
|
+
const ready = facts.merge?.state === 'ready' && facts.checked === armed;
|
|
75
|
+
// Seen while ready: the commit is announced. Left ready in the window: a later ready on it is still due.
|
|
76
|
+
if (ready)
|
|
77
|
+
entry.announced = armed;
|
|
78
|
+
quiet(facts, ready ? 'you are watching Rarog' : 'no longer ready on the checked commit');
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
entry.announced = armed;
|
|
82
|
+
const badge = options.badge?.();
|
|
83
|
+
const content = buildReadyToMergeContent({
|
|
84
|
+
project: facts.project, name: facts.name, commits: facts.merge?.commits ?? 0, sessionId,
|
|
85
|
+
...(facts.termId === undefined ? {} : { termId: facts.termId }),
|
|
86
|
+
...(badge === undefined ? {} : { badge }),
|
|
87
|
+
});
|
|
88
|
+
let outcome;
|
|
89
|
+
try {
|
|
90
|
+
outcome = await options.send(content);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
outcome = 'failed';
|
|
94
|
+
}
|
|
95
|
+
options.log(`push: ready-to-merge for ${facts.project} — APNs: ${OUTCOME_LABEL[outcome]}`);
|
|
96
|
+
};
|
|
97
|
+
const update = (facts) => {
|
|
98
|
+
const known = threads.get(facts.sessionId);
|
|
99
|
+
const due = readyToMergeDue(mergeFacts(facts), known?.announced);
|
|
100
|
+
if (known !== undefined)
|
|
101
|
+
known.facts = facts;
|
|
102
|
+
// A refresh while the window runs for this commit does not restart it.
|
|
103
|
+
if (due === undefined || due === known?.pending)
|
|
104
|
+
return;
|
|
105
|
+
const entry = known ?? { facts, announced: undefined, pending: undefined, timer: undefined };
|
|
106
|
+
threads.set(facts.sessionId, entry);
|
|
107
|
+
// A newer checked commit supersedes a pending push about an older one.
|
|
108
|
+
disarm(entry);
|
|
109
|
+
if (options.presence.active()) {
|
|
110
|
+
entry.announced = due;
|
|
111
|
+
quiet(facts, 'you are watching Rarog');
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
entry.pending = due;
|
|
115
|
+
options.log(`push: armed ready-to-merge for ${facts.project} (check in ${String(READY_TO_MERGE_CHECK_MS / 1000)} s)`);
|
|
116
|
+
entry.timer = scheduler.setTimeout(() => {
|
|
117
|
+
check(facts.sessionId, due).catch((err) => {
|
|
118
|
+
options.log(`push: ready-to-merge — internal error ${err.message}`);
|
|
119
|
+
});
|
|
120
|
+
}, READY_TO_MERGE_CHECK_MS);
|
|
121
|
+
};
|
|
122
|
+
return {
|
|
123
|
+
update(facts) {
|
|
124
|
+
if (closed)
|
|
125
|
+
return;
|
|
126
|
+
try {
|
|
127
|
+
update(facts);
|
|
128
|
+
}
|
|
129
|
+
catch (err) {
|
|
130
|
+
options.log(`push: ready-to-merge — internal error ${err.message}`);
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
forget(sessionId) {
|
|
134
|
+
const entry = threads.get(sessionId);
|
|
135
|
+
if (entry === undefined)
|
|
136
|
+
return;
|
|
137
|
+
disarm(entry);
|
|
138
|
+
threads.delete(sessionId);
|
|
139
|
+
},
|
|
140
|
+
close() {
|
|
141
|
+
closed = true;
|
|
142
|
+
for (const entry of threads.values())
|
|
143
|
+
disarm(entry);
|
|
144
|
+
threads.clear();
|
|
145
|
+
return Promise.resolve();
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
}
|