@rarog/server 1.1.1 → 1.1.2-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/node_modules/@rarog/shared/package.json +1 -1
- package/node_modules/@rarog/shared/src/decode.js +46 -1
- package/node_modules/@rarog/shared/src/notify-copy.js +2 -0
- package/node_modules/@rarog/shared/src/protocol/background.js +7 -0
- package/node_modules/@rarog/shared/src/protocol/context.js +57 -0
- package/node_modules/@rarog/shared/src/protocol/coordination.js +42 -0
- package/node_modules/@rarog/shared/src/protocol/dialog-live.js +117 -0
- package/node_modules/@rarog/shared/src/protocol/files.js +1 -1
- package/node_modules/@rarog/shared/src/protocol/inbox.js +6 -0
- package/node_modules/@rarog/shared/src/protocol/presence.js +47 -0
- package/node_modules/@rarog/shared/src/protocol.js +14 -146
- package/node_modules/@rarog/shared/src/rest.js +16 -1
- package/node_modules/@rarog/shared/src/sentences/dialogs.js +10 -0
- package/node_modules/@rarog/shared/src/sentences/push.js +9 -0
- package/node_modules/@rarog/shared/src/sentences/rest.js +9 -0
- package/node_modules/@rarog/shared/src/sentences/restart.js +1 -0
- package/node_modules/@rarog/shared/src/sentences/session.js +24 -0
- package/package.json +2 -2
- package/plugin/rarog/.claude-plugin/plugin.json +4 -0
- package/plugin/rarog/bin/rarog-coordinator +7 -0
- package/plugin/rarog/hooks/hooks.json +18 -0
- package/plugin/rarog/hooks/recipient.mjs +95 -0
- package/plugin/rarog/lib/coordinator.mjs +1340 -0
- package/plugin/rarog/lib/threads.mjs +350 -0
- package/plugin/rarog/skills/coordinator/SKILL.md +111 -0
- package/plugin/rarog/skills/coordinator/check-and-merge.md +46 -0
- package/plugin/rarog/skills/coordinator/close-thread.md +15 -0
- package/plugin/rarog/skills/coordinator/role.md +61 -0
- package/plugin/rarog/skills/coordinator/send-back.md +39 -0
- package/plugin/rarog/skills/coordinator/start-thread.md +43 -0
- package/server/src/bootstrap/coordination.js +49 -0
- package/server/src/bootstrap/coordinator-start.js +27 -0
- package/server/src/bootstrap/inbox.js +4 -0
- package/server/src/bootstrap/pr-status.js +15 -7
- package/server/src/bootstrap/push.js +59 -5
- package/server/src/cli/doctor-pr-status.js +10 -6
- package/server/src/companion/catalog.js +1 -1
- package/server/src/companion/index.js +2 -4
- package/server/src/config/flags.js +4 -0
- package/server/src/config-env.js +15 -0
- package/server/src/config.js +17 -3
- package/server/src/coordination/merge-events.js +86 -0
- package/server/src/coordination/merge-prompt.js +244 -0
- package/server/src/coordination/registry.js +289 -0
- package/server/src/coordination/state.js +94 -0
- package/server/src/coordination/summary.js +422 -0
- package/server/src/coordination/thread-file.js +245 -0
- package/server/src/coordination/thread-git.js +110 -0
- package/server/src/coordination/watch.js +237 -0
- package/server/src/demo/content/coordinator.js +89 -0
- package/server/src/demo/content/en.js +57 -1
- package/server/src/demo/content/pl.js +57 -1
- package/server/src/demo/control.js +4 -2
- package/server/src/demo/inbox.js +12 -0
- package/server/src/demo/mock-herdr.js +5 -4
- package/server/src/demo/review-routes.js +2 -2
- package/server/src/demo/scenarios.js +31 -17
- package/server/src/demo/seeds.js +82 -40
- package/server/src/drivers/herdr/live-dialog.js +412 -0
- package/server/src/drivers/herdr/live-step.js +261 -0
- package/server/src/drivers/herdr/pause-gate.js +60 -0
- package/server/src/drivers/herdr/pull-request-poll.js +5 -5
- package/server/src/drivers/herdr/queue-take-back.js +4 -0
- package/server/src/drivers/herdr/returned-prompt.js +4 -1
- package/server/src/drivers/herdr/screen-fallback.js +50 -0
- package/server/src/drivers/herdr/start-dialog-gate.js +136 -0
- package/server/src/drivers/herdr-driver.js +159 -77
- package/server/src/files/refusals.js +9 -2
- package/server/src/files/session-gate.js +5 -4
- package/server/src/git-branch-diff.js +194 -0
- package/server/src/herdr/argv.js +34 -3
- package/server/src/herdr/audit.js +32 -1
- package/server/src/herdr/background/cli-shapes.js +35 -15
- package/server/src/herdr/background/index.js +7 -7
- package/server/src/herdr/background/merge.js +17 -5
- package/server/src/herdr/background/notification.js +0 -4
- package/server/src/herdr/background/pull-request-files.js +53 -161
- package/server/src/herdr/background/pull-requests.js +54 -632
- package/server/src/herdr/background/queued-prompt.js +46 -0
- package/server/src/herdr/background/work.js +96 -0
- package/server/src/herdr/client.js +22 -46
- package/server/src/herdr/commands/catalog.js +11 -7
- package/server/src/herdr/commands/discover.js +33 -1
- package/server/src/herdr/commands/index.js +3 -2
- package/server/src/herdr/dialogs/copy.js +7 -0
- package/server/src/herdr/dialogs/index.js +13 -1
- package/server/src/herdr/dialogs/layer1/hook-list/hook-list.js +4 -56
- package/server/src/herdr/dialogs/live/model.js +220 -0
- package/server/src/herdr/dialogs/live/policy.js +108 -0
- package/server/src/herdr/dialogs/live/view.js +261 -0
- package/server/src/herdr/dialogs/screen/form.js +6 -4
- package/server/src/herdr/dialogs/screen/option-run.js +25 -3
- package/server/src/herdr/dialogs/screen/parse.js +3 -3
- package/server/src/herdr/dialogs/screen/signatures.js +78 -0
- package/server/src/herdr/dialogs/screen/start-dialog.js +72 -0
- package/server/src/herdr/dialogs/screen/trust-arrow.js +46 -9
- package/server/src/herdr/engines.js +96 -0
- package/server/src/herdr/history-steps.js +9 -4
- package/server/src/herdr/identity.js +20 -5
- package/server/src/herdr/jsonl-follow.js +26 -3
- package/server/src/herdr/label-code.js +104 -0
- package/server/src/herdr/label-migration.js +142 -0
- package/server/src/herdr/launcher.js +30 -5
- package/server/src/herdr/plugin-copy.js +281 -0
- package/server/src/herdr/provenance.js +80 -40
- package/server/src/herdr/session-index.js +19 -0
- package/server/src/herdr/start-dialog-wait.js +96 -0
- package/server/src/herdr/supervisor.js +49 -23
- package/server/src/herdr/types.js +1 -0
- package/server/src/herdr/workspace-resolver.js +5 -4
- package/server/src/inbox/card.js +31 -8
- package/server/src/inbox/heads.js +1 -0
- package/server/src/inbox/inbox.js +21 -4
- package/server/src/inbox/removals.js +10 -1
- package/server/src/index.js +45 -8
- package/server/src/notify/apns-payload.js +5 -3
- package/server/src/notify/content.js +64 -0
- package/server/src/notify/index.js +11 -3
- package/server/src/notify/live-activity-state.js +19 -6
- package/server/src/notify/live-activity.js +5 -2
- package/server/src/notify/policy.js +53 -13
- package/server/src/notify/ready-to-merge.js +148 -0
- package/server/src/notify/stalled-wait.js +213 -0
- package/server/src/pr-status/facts.js +87 -0
- package/server/src/pr-status/gh.js +76 -9
- package/server/src/pr-status/index.js +1 -10
- package/server/src/pr-status/source.js +20 -6
- package/server/src/pr-status/tracker.js +32 -9
- package/server/src/project-root.js +233 -0
- package/server/src/routes/sessions.js +68 -2
- package/server/src/sessions/branch-diff.js +57 -0
- package/server/src/sessions/cli-registry.js +17 -3
- package/server/src/sessions/companion-scope.js +2 -1
- package/server/src/sessions/consent-cards.js +49 -2
- package/server/src/sessions/conversation-lists.js +11 -2
- package/server/src/sessions/coordinator-start.js +172 -0
- package/server/src/sessions/demo-modules.js +1 -0
- package/server/src/sessions/demo-seeds.js +100 -0
- package/server/src/sessions/driver-events.js +68 -14
- package/server/src/sessions/herdr-lifecycle.js +11 -4
- package/server/src/sessions/interrupt-windows.js +28 -4
- package/server/src/sessions/launch-gate.js +36 -11
- package/server/src/sessions/live-dialog.js +69 -0
- package/server/src/sessions/manager.js +138 -287
- package/server/src/sessions/owner-turn.js +36 -0
- package/server/src/sessions/pr-status-link.js +64 -16
- package/server/src/sessions/seen-marks.js +31 -12
- package/server/src/sessions/session-dialog.js +82 -0
- package/server/src/sessions/session-git.js +1 -0
- package/server/src/sessions/session-scope.js +6 -5
- package/server/src/sessions/session-take-back.js +5 -0
- package/server/src/sessions/session.js +82 -10
- package/server/src/sessions/state-machine.js +13 -0
- package/server/src/sessions/state-sentences.js +87 -30
- package/server/src/sessions/test-session.js +50 -0
- package/server/src/sessions/waiting-line.js +49 -0
- package/server/src/term/herdr-backend.js +15 -12
- package/server/src/term/lifecycle.js +4 -6
- package/server/src/transcript-import.js +20 -2
- package/server/src/version.js +4 -0
- /package/server/src/{companion/asks-owner.js → asks-owner.js} +0 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { textAsksOwner } from '../asks-owner.js';
|
|
2
|
+
/**
|
|
3
|
+
* Whether a message the session is about to append asks the owner: an agent message with a text block that asks
|
|
4
|
+
* (`asks-owner.ts`). Read before the size cap, because the history merges the agent entries of a long turn into one
|
|
5
|
+
* message whose cut tail would otherwise lose the question.
|
|
6
|
+
*/
|
|
7
|
+
export function blocksAskOwner(role, blocks) {
|
|
8
|
+
return role === 'assistant' && blocks.some((block) => block.type === 'text' && textAsksOwner(block.text.text));
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The owner's message: a prompt (`user` without a harness notice and without the "not from the owner" mark) or the
|
|
12
|
+
* note of a prompt blocked by a hook, which after a restart is all that stands for the blocked prompt.
|
|
13
|
+
*/
|
|
14
|
+
export function isOwnerMessage(message, notFromOwner) {
|
|
15
|
+
if (message.role === 'user')
|
|
16
|
+
return message.notice === undefined && !notFromOwner;
|
|
17
|
+
return message.role === 'system' && message.promptBlocked !== undefined;
|
|
18
|
+
}
|
|
19
|
+
/** Whether the session waits for the owner after a question; a prompt held as a deferred echo has answered it. */
|
|
20
|
+
export function ownerTurn(session) {
|
|
21
|
+
if (session.heldEchoes.length > 0)
|
|
22
|
+
return false;
|
|
23
|
+
for (const message of session.messagesNewestFirst()) {
|
|
24
|
+
if (message.seq <= session.conversationStartSeq)
|
|
25
|
+
return false;
|
|
26
|
+
if (isOwnerMessage(message, session.notFromOwner(message)))
|
|
27
|
+
return false;
|
|
28
|
+
if (session.asksOwner(message))
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
/** The mark for the app's echo of a sent text: a local command (`/rename`, `/model`) is no message of the owner. */
|
|
34
|
+
export function localCommandMark(slash) {
|
|
35
|
+
return slash?.kind === 'local' ? { notFromOwner: true } : {};
|
|
36
|
+
}
|
|
@@ -1,33 +1,72 @@
|
|
|
1
|
-
|
|
1
|
+
import { newestFirst } from '../herdr/background/pull-requests.js';
|
|
2
|
+
/** How many PRs at most stand on the session list; the list rides in every snapshot frame, like artifacts. */
|
|
3
|
+
export const PULL_REQUESTS_MAX = 20;
|
|
4
|
+
/**
|
|
5
|
+
* The PRs a card shows: the linked PRs whose author is `viewer` and that GitHub says were created at or after
|
|
6
|
+
* `windowStart`, with the GitHub title and the link time as `createdAt`, newest first, at most
|
|
7
|
+
* {@link PULL_REQUESTS_MAX} after the filter. No login, no window or no facts = not shown. Pure.
|
|
8
|
+
*/
|
|
9
|
+
export function visiblePullRequests(input) {
|
|
10
|
+
const { linked, windowStart, viewer, factsOf } = input;
|
|
11
|
+
if (viewer === null || windowStart === null || windowStart === undefined)
|
|
12
|
+
return [];
|
|
13
|
+
const from = Date.parse(windowStart);
|
|
14
|
+
if (Number.isNaN(from))
|
|
15
|
+
return [];
|
|
16
|
+
const visible = [];
|
|
17
|
+
for (const { url, repo, number, createdAt } of linked) {
|
|
18
|
+
const facts = factsOf(url);
|
|
19
|
+
if (facts === undefined || facts.author !== viewer || !(facts.createdAtMs >= from))
|
|
20
|
+
continue;
|
|
21
|
+
const { title } = facts;
|
|
22
|
+
visible.push(title === undefined ? { url, repo, number, createdAt } : { url, repo, number, createdAt, title });
|
|
23
|
+
}
|
|
24
|
+
return visible.sort(newestFirst).slice(0, PULL_REQUESTS_MAX);
|
|
25
|
+
}
|
|
26
|
+
const urlsOf = (list) => (list ?? []).map((pr) => pr.url);
|
|
2
27
|
export class SessionPrStatus {
|
|
3
28
|
#port;
|
|
4
29
|
#deps;
|
|
5
30
|
constructor(port, deps) {
|
|
6
31
|
this.#port = port;
|
|
7
32
|
this.#deps = deps;
|
|
8
|
-
port?.listen((
|
|
33
|
+
port?.listen((change) => { this.#changed(change); });
|
|
9
34
|
}
|
|
10
35
|
/**
|
|
11
|
-
* The `pull-requests` driver event: a card's metadata without a state
|
|
12
|
-
*
|
|
13
|
-
* attach).
|
|
36
|
+
* The `pull-requests` driver event: the conversation's linked set and window, a card's metadata without a state
|
|
37
|
+
* transition, `seen` or push. An empty set clears the fields; a card frame goes out only when the shown list
|
|
38
|
+
* changed (the driver pays the set out at every attach).
|
|
14
39
|
*/
|
|
15
|
-
applyList(session,
|
|
16
|
-
const
|
|
17
|
-
if (
|
|
40
|
+
applyList(session, linked, windowStart) {
|
|
41
|
+
const links = linked.length > 0 ? linked : undefined;
|
|
42
|
+
if (links === undefined && session.pullRequestLinks === undefined && session.pullRequests === undefined)
|
|
18
43
|
return;
|
|
19
|
-
session.
|
|
20
|
-
|
|
21
|
-
this
|
|
44
|
+
session.pullRequestLinks = links;
|
|
45
|
+
session.pullRequestWindowStart = links === undefined ? undefined : windowStart;
|
|
46
|
+
if (this.sync(session))
|
|
47
|
+
this.#deps.emitSessionChanged(session);
|
|
22
48
|
}
|
|
23
|
-
/** Drops the list (another conversation or out of scope) and tells the tracker. */
|
|
49
|
+
/** Drops the list and the links (another conversation or out of scope) and tells the tracker. */
|
|
24
50
|
clear(session) {
|
|
25
51
|
session.pullRequests = undefined;
|
|
52
|
+
session.pullRequestLinks = undefined;
|
|
53
|
+
session.pullRequestWindowStart = undefined;
|
|
26
54
|
this.sync(session);
|
|
27
55
|
}
|
|
28
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* The shown list again from the session's links and window, and the tracker told both (the linked set to verify,
|
|
58
|
+
* the shown URLs to keep fresh); call after anything that set the PR fields. `true` = the shown list changed.
|
|
59
|
+
*/
|
|
29
60
|
sync(session) {
|
|
30
|
-
|
|
61
|
+
const before = session.pullRequests;
|
|
62
|
+
const shown = this.#port === undefined ? [] : visiblePullRequests({
|
|
63
|
+
linked: session.pullRequestLinks ?? [], windowStart: session.pullRequestWindowStart,
|
|
64
|
+
viewer: this.#port.viewerLogin(), factsOf: (url) => this.#port?.factsOf(url),
|
|
65
|
+
});
|
|
66
|
+
session.pullRequests = shown.length > 0 ? shown : undefined;
|
|
67
|
+
this.#port?.setSessionLinks(session.id, urlsOf(session.pullRequestLinks));
|
|
68
|
+
this.#port?.setSessionUrls(session.id, urlsOf(session.pullRequests));
|
|
69
|
+
return JSON.stringify(before ?? []) !== JSON.stringify(shown);
|
|
31
70
|
}
|
|
32
71
|
forget(sessionId) {
|
|
33
72
|
this.#port?.dropSession(sessionId);
|
|
@@ -41,9 +80,18 @@ export class SessionPrStatus {
|
|
|
41
80
|
return state === undefined ? pr : { ...pr, state };
|
|
42
81
|
});
|
|
43
82
|
}
|
|
44
|
-
|
|
83
|
+
/**
|
|
84
|
+
* A tracker answer: the sessions that link a changed URL (every session with links when the `gh` login changed)
|
|
85
|
+
* get their list again; a frame goes to those whose shown list changed or that show a URL whose state changed.
|
|
86
|
+
*/
|
|
87
|
+
#changed({ urls, viewerChanged }) {
|
|
45
88
|
for (const session of this.#deps.sessions.values()) {
|
|
46
|
-
|
|
89
|
+
const links = session.pullRequestLinks ?? [];
|
|
90
|
+
if (links.length === 0 || (!viewerChanged && !links.some((pr) => urls.has(pr.url))))
|
|
91
|
+
continue;
|
|
92
|
+
const listChanged = this.sync(session);
|
|
93
|
+
const shownChanged = urlsOf(session.pullRequests).some((url) => urls.has(url));
|
|
94
|
+
if (listChanged || shownChanged)
|
|
47
95
|
this.#deps.emitSessionChanged(session);
|
|
48
96
|
}
|
|
49
97
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { say } from '@rarog/shared/sentences';
|
|
2
|
+
import { isStateOnlyEngine } from '../herdr/engines.js';
|
|
2
3
|
import { noResultTurn } from '../notify/policy.js';
|
|
3
4
|
import { inReadConversation } from './companion-scope.js';
|
|
4
5
|
import { BadStateError } from './errors.js';
|
|
@@ -230,7 +231,8 @@ export function clearReceipt(session) {
|
|
|
230
231
|
/**
|
|
231
232
|
* A turn without a result keeps the received result of the previous turn. Such a turn (`noResultTurn`:
|
|
232
233
|
* started by a subagent standby notice alone, or by an artifact notification or a context compaction alone with no
|
|
233
|
-
* tool call
|
|
234
|
+
* tool call, or a pane working with no input while a subagent woken from standby works in it) leaves nothing new to
|
|
235
|
+
* read, so its end must not light the card as a new result once the previous one
|
|
234
236
|
* was received.
|
|
235
237
|
*
|
|
236
238
|
* `#applyTransition` calls this after the turn start has cleared the seen fields and before it sends the session
|
|
@@ -303,10 +305,11 @@ export function noteHumanReceipt(session) {
|
|
|
303
305
|
* indeksu pisarzy jsonl nie dotyczy. Bez uuidu albo bez numeru stanu znacznik byłby
|
|
304
306
|
* zgadywaniem (po restarcie serwera herdr numery startują od nowa), więc wtedy nie
|
|
305
307
|
* zapisujemy nic: karta i tak schodzi z sekcji uwagi, tyle że tylko w tym procesie.
|
|
308
|
+
* A state-only card without a session ID is the exception: its address is the pane ({@link markSessionOf}).
|
|
306
309
|
*/
|
|
307
310
|
export function rememberSeenMark(session, store) {
|
|
308
311
|
const key = session.herdrKey;
|
|
309
|
-
const engineSessionId = session
|
|
312
|
+
const engineSessionId = markSessionOf(session);
|
|
310
313
|
const seq = session.herdrSeq;
|
|
311
314
|
if (key === undefined || engineSessionId === undefined || seq === undefined)
|
|
312
315
|
return;
|
|
@@ -315,7 +318,7 @@ export function rememberSeenMark(session, store) {
|
|
|
315
318
|
/** Ręczne „nieprzeczytane" pod tym samym adresem i numerem co {@link rememberSeenMark}. */
|
|
316
319
|
export function rememberUnseenMark(session, store) {
|
|
317
320
|
const key = session.herdrKey;
|
|
318
|
-
const engineSessionId = session
|
|
321
|
+
const engineSessionId = markSessionOf(session);
|
|
319
322
|
const seq = session.herdrSeq;
|
|
320
323
|
if (key === undefined || engineSessionId === undefined || seq === undefined)
|
|
321
324
|
return;
|
|
@@ -369,7 +372,7 @@ export function clearHerdrDone(session, key, deps) {
|
|
|
369
372
|
*/
|
|
370
373
|
export function seenSeqWentBack(session, store) {
|
|
371
374
|
const key = session.herdrKey;
|
|
372
|
-
const engineSessionId = session
|
|
375
|
+
const engineSessionId = markSessionOf(session);
|
|
373
376
|
const current = session.herdrSeq;
|
|
374
377
|
if (store === undefined || key === undefined || engineSessionId === undefined)
|
|
375
378
|
return false;
|
|
@@ -391,7 +394,7 @@ export function seenMarkCovers(session, store) {
|
|
|
391
394
|
const key = session.herdrKey;
|
|
392
395
|
// Ta sama para adresów co w `markSeen()` — inaczej znacznik Codexa dałoby się zapisać,
|
|
393
396
|
// ale nigdy odczytać.
|
|
394
|
-
const engineSessionId = session
|
|
397
|
+
const engineSessionId = markSessionOf(session);
|
|
395
398
|
const current = session.herdrSeq;
|
|
396
399
|
if (store === undefined || key === undefined || engineSessionId === undefined)
|
|
397
400
|
return false;
|
|
@@ -404,14 +407,15 @@ export function seenMarkCovers(session, store) {
|
|
|
404
407
|
/**
|
|
405
408
|
* To samo pytanie dla panelu, który dopiero staje się kartą (`appeared`).
|
|
406
409
|
*
|
|
407
|
-
*
|
|
408
|
-
*
|
|
409
|
-
*
|
|
410
|
+
* `agentSessionId` wpisu z herdr niesie uuid TEGO silnika, który w panelu siedzi (dla Codexa — rollout,
|
|
411
|
+
* `''` when herdr reports none), a znacznik jest zapisany dokładnie pod tym adresem ({@link markSessionOfAgent}).
|
|
412
|
+
* Rozejście się pól zaczyna się dopiero w `Session`.
|
|
410
413
|
*/
|
|
411
414
|
export function wasSeen(agent, store) {
|
|
412
415
|
if (store === undefined)
|
|
413
416
|
return false;
|
|
414
|
-
|
|
417
|
+
const address = markSessionOfAgent(agent);
|
|
418
|
+
return address !== undefined && store.seq(agent.key, address) === agent.stateChangeSeq;
|
|
415
419
|
}
|
|
416
420
|
/**
|
|
417
421
|
* Who received the result of a pane that becomes a card, when it was not a human: the `by` of the durable receipt
|
|
@@ -419,15 +423,30 @@ export function wasSeen(agent, store) {
|
|
|
419
423
|
* may be another result, which nobody picked up.
|
|
420
424
|
*/
|
|
421
425
|
export function seenByOf(agent, store) {
|
|
422
|
-
|
|
426
|
+
const address = markSessionOfAgent(agent);
|
|
427
|
+
if (store === undefined || address === undefined || store.seq(agent.key, address) !== agent.stateChangeSeq) {
|
|
423
428
|
return undefined;
|
|
424
|
-
|
|
429
|
+
}
|
|
430
|
+
return store.seenBy(agent.key, address);
|
|
425
431
|
}
|
|
426
432
|
/** Ręczne „nieprzeczytane" przy tym samym numerze stanu — ten sam adres co {@link wasSeen}. */
|
|
427
433
|
export function wasMarkedUnseen(agent, store) {
|
|
428
434
|
if (store === undefined)
|
|
429
435
|
return false;
|
|
430
|
-
|
|
436
|
+
const address = markSessionOfAgent(agent);
|
|
437
|
+
return address !== undefined && store.unseenSeq(agent.key, address) === agent.stateChangeSeq;
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* The engine session part of a durable mark's address; the other part is the card's herdr key. A state-only card
|
|
441
|
+
* without a session ID (herdr reports none for Codex) is addressed by its pane alone, as `''`: its mark still
|
|
442
|
+
* survives a resync and a Rarog restart. Claude without a session has no address, so no mark.
|
|
443
|
+
*/
|
|
444
|
+
function markSessionOf(session) {
|
|
445
|
+
return session.engineSessionId ?? session.observedSessionId ?? (isStateOnlyEngine(session.engine) ? '' : undefined);
|
|
446
|
+
}
|
|
447
|
+
/** The same address for a pane that becomes a card: its entry carries the session ID, `''` when herdr reports none. */
|
|
448
|
+
function markSessionOfAgent(agent) {
|
|
449
|
+
return agent.agentSessionId !== '' || isStateOnlyEngine(agent.engine) ? agent.agentSessionId : undefined;
|
|
431
450
|
}
|
|
432
451
|
function describeError(error) {
|
|
433
452
|
return error instanceof Error ? error.message : String(error);
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { STALE } from '../drivers/types.js';
|
|
2
|
+
import { BadRequestError, BadStateError } from './errors.js';
|
|
3
|
+
import { HERDR_ALLOW_MESSAGE, HERDR_OUT_OF_SCOPE_MESSAGE } from './state-sentences.js';
|
|
4
|
+
/**
|
|
5
|
+
* Dialog, którego Rarog nie zna z jsonl — decyzja adresowana SAMĄ SESJĄ.
|
|
6
|
+
*
|
|
7
|
+
* Taka karta nie ma wpisu w `PendingInteractions` (stan `waiting-permission` bez pending),
|
|
8
|
+
* bo nie ma z czego jej złożyć: `permId` pochodzi z `tool_use.id` w transkrypcie, a tego
|
|
9
|
+
* dialogu w transkrypcie nie ma. Zwykła ścieżka first-wins oddałaby tu `gone`.
|
|
10
|
+
*
|
|
11
|
+
* `deny` (`escape`) wolno ZAWSZE — anuluje, nigdy nie zatwierdza (wyjątki w driverze: pauza „Session
|
|
12
|
+
* paused” i karta warstwy 2 — odmowa `refused` jak każda inna). `allow` wolno WYŁĄCZNIE
|
|
13
|
+
* dla dialogu rozpoznanego z zamkniętej listy sygnatur: dopiero wtedy Rarog
|
|
14
|
+
* wie, co zatwierdza, a cyfrę składa driver z TEKSTU opcji twierdzącej. Dla wszystkiego
|
|
15
|
+
* innego zostaje 409 z radą „zatwierdź w terminalu" — i to jest granica, za którą Rarog
|
|
16
|
+
* przestałby być narzędziem, a stałby się klikaczem w cudze menu.
|
|
17
|
+
*/
|
|
18
|
+
export async function decideHerdrDialog(session, decision, port) {
|
|
19
|
+
/*
|
|
20
|
+
* Dialog z zamkniętej listy sygnatur (trust/model) nie niesie `alwaysLabel`, więc UI nie
|
|
21
|
+
* ma skąd wysłać `allow-always` — a gdyby wysłał (stary bundle, ręczny POST), odmowa jest
|
|
22
|
+
* jedyną uczciwą odpowiedzią: nie ma opcji, którą to zatwierdza.
|
|
23
|
+
*/
|
|
24
|
+
if (decision === 'allow-always')
|
|
25
|
+
throw new BadStateError(HERDR_ALLOW_MESSAGE);
|
|
26
|
+
if (decision === 'allow' && session.herdrDialog === undefined) {
|
|
27
|
+
throw new BadStateError(HERDR_ALLOW_MESSAGE);
|
|
28
|
+
}
|
|
29
|
+
// Panel spoza zasięgu odmawia TUTAJ, a nie dopiero w driverze: `HerdrOutOfScopeError`
|
|
30
|
+
// nie ma odpowiednika w `managerErrorStatus`, więc wracałby do telefonu jako 500
|
|
31
|
+
// („Błąd serwera.") zamiast zdania, które mówi, co się stało.
|
|
32
|
+
if (session.outOfScope === true)
|
|
33
|
+
throw new BadRequestError(HERDR_OUT_OF_SCOPE_MESSAGE);
|
|
34
|
+
port.assertHerdrWritable();
|
|
35
|
+
/*
|
|
36
|
+
* Rozpoznanie gaśnie PRZED wysłaniem cyfry, a nie po przemalowaniu ekranu — i musi zgasnąć
|
|
37
|
+
* przed `await`, bo ta karta nie ma wpisu w `#pending`, więc nie chroni jej blokada
|
|
38
|
+
* równoległych prób stamtąd. Drugie tapnięcie w „Zatwierdź" (dwa urządzenia, powtórzony
|
|
39
|
+
* tap) w oknie, w którym driver czyta ekran, wysłałoby DRUGĄ cyfrę do panelu, który
|
|
40
|
+
* zdążył już ruszyć dalej — czyli w środek następnego dialogu.
|
|
41
|
+
*
|
|
42
|
+
* Po `refused` rozpoznanie wraca WYŁĄCZNIE dla `send-failed` — warunki przy samym
|
|
43
|
+
* przywróceniu niżej.
|
|
44
|
+
*/
|
|
45
|
+
const dialog = session.herdrDialog;
|
|
46
|
+
if (decision === 'allow') {
|
|
47
|
+
session.herdrDialog = undefined;
|
|
48
|
+
port.emitSessionChanged(session);
|
|
49
|
+
}
|
|
50
|
+
// `reqId` jest dla drivera herdr nieznaczący (nie ma prośby o zgodę, jest dialog na
|
|
51
|
+
// ekranie), ale kontrakt `SessionDriver` go wymaga — przekazujemy id sesji. Driver
|
|
52
|
+
// rozpoznaje po tym kartę ekranową i szuka cyfry u siebie, nie po `reqId`.
|
|
53
|
+
const outcome = await (session.driver?.respondPermission(session.id, decision)
|
|
54
|
+
?? Promise.resolve(STALE));
|
|
55
|
+
if (outcome.kind === 'refused') {
|
|
56
|
+
/*
|
|
57
|
+
* Rozpoznanie WRACA tylko po `send-failed`: to jedyna odmowa, przy której z Raroga nie
|
|
58
|
+
* wyszedł ani jeden bajt, driver karty nie wycofał (`refuseSend` świadomie nie woła ani
|
|
59
|
+
* `#clearActive`, ani `#scheduleEvaluate`) i dialog na pewno stoi dalej na ekranie.
|
|
60
|
+
*
|
|
61
|
+
* Pozostałe powody (`screen-changed`, `no-digit`, `multi-select`, `terminal-only`,
|
|
62
|
+
* `form-submit`) idą przez `#clearActive`, czyli przez zdarzenie `permission-cleared`,
|
|
63
|
+
* po którym handler managera zeruje `herdrDialog` — i to zerowanie jest PRAWDĄ NOWSZĄ niż
|
|
64
|
+
* migawka sprzed `await`. Bezwarunkowe przywracanie cofało je i zostawiało „Zatwierdź"
|
|
65
|
+
* dla dialogu, którego driver się przed chwilą wyparł. Odbudowę karty robi
|
|
66
|
+
* `#scheduleEvaluate()` w driverze — jedna ścieżka, nie druga mechanika tutaj;
|
|
67
|
+
* kosztem jest przycisk znikający na jeden debounce oceny.
|
|
68
|
+
*
|
|
69
|
+
* Warunek `herdrDialog === undefined` domyka drugą stronę: gdyby w oknie `await`
|
|
70
|
+
* wszedł ŚWIEŻY `screen-dialog`, migawka sprzed decyzji nadpisałaby nowe rozpoznanie.
|
|
71
|
+
*/
|
|
72
|
+
if (decision === 'allow' && outcome.reason === 'send-failed'
|
|
73
|
+
&& session.herdrDialog === undefined) {
|
|
74
|
+
session.herdrDialog = dialog;
|
|
75
|
+
port.emitSessionChanged(session);
|
|
76
|
+
}
|
|
77
|
+
return { outcome: 'refused', reason: outcome.reason };
|
|
78
|
+
}
|
|
79
|
+
if (outcome.kind === 'stale')
|
|
80
|
+
return { outcome: 'gone' };
|
|
81
|
+
return { outcome: 'ok' };
|
|
82
|
+
}
|
|
@@ -246,6 +246,7 @@ export class SessionGit {
|
|
|
246
246
|
* resztę rodzeństwa. Sesja mogła zniknąć w oknie debounce'u — wtedy nie ma o co pytać.
|
|
247
247
|
*/
|
|
248
248
|
#gitChanged(cwds) {
|
|
249
|
+
this.#port.gitChanged?.(cwds);
|
|
249
250
|
for (const cwd of cwds) {
|
|
250
251
|
for (const session of this.#port.sessions.values()) {
|
|
251
252
|
if (session.cwd !== cwd)
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { sessionCwdInArea } from './companion-scope.js';
|
|
2
2
|
import { BadRequestError } from './errors.js';
|
|
3
|
-
import {
|
|
3
|
+
import { HERDR_OUT_OF_SCOPE_DIFF_MESSAGE } from './state-sentences.js';
|
|
4
|
+
import { STATE_ONLY_REFUSALS, isStateOnlyEngine } from '../herdr/engines.js';
|
|
4
5
|
/**
|
|
5
6
|
* Bramka wspólna WSZYSTKICH tras diffa — starej i obu per plik. Oddaje sesję, z której
|
|
6
7
|
* katalogu wolno czytać, albo `null` w demo: tam diff to stały mock, bez odczytu z dysku.
|
|
7
8
|
*/
|
|
8
9
|
export function diffSession(id, port) {
|
|
9
10
|
const session = port.require(id);
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
if (session.engine
|
|
13
|
-
throw new BadRequestError(
|
|
11
|
+
// Scope gate: the working diff is the CONTENT of the directory, and a state-only entry promises state alone.
|
|
12
|
+
// The client draws no button for it; this is the second line, for an old client and for `curl`.
|
|
13
|
+
if (isStateOnlyEngine(session.engine))
|
|
14
|
+
throw new BadRequestError(STATE_ONLY_REFUSALS[session.engine].git);
|
|
14
15
|
// Panel poza zasięgiem: ta sama granica co transkrypt i wycinek ekranu — treść katalogu zostaje na Macu.
|
|
15
16
|
if (session.outOfScope === true)
|
|
16
17
|
throw new BadRequestError(HERDR_OUT_OF_SCOPE_DIFF_MESSAGE);
|
|
@@ -2,6 +2,7 @@ import { say } from '@rarog/shared/sentences';
|
|
|
2
2
|
import { echoKey } from '../herdr/jsonl-follow.js';
|
|
3
3
|
import { BadRequestError, BadStateError, GoneError } from './errors.js';
|
|
4
4
|
import { pauseHeldFlush, takeHeld } from './held-echo.js';
|
|
5
|
+
import { ownerTurn } from './owner-turn.js';
|
|
5
6
|
import { SEND_REGISTRY_WINDOW_MS } from './send-registry.js';
|
|
6
7
|
import { HERDR_OUT_OF_SCOPE_MESSAGE, RESTART_IN_PROGRESS_MESSAGE } from './state-sentences.js';
|
|
7
8
|
/** How long a result answers a retry: the window of the send registry, so a retry after a long outage still matches. */
|
|
@@ -67,7 +68,11 @@ export class SessionTakeBack {
|
|
|
67
68
|
#answer(session, result, entry, results, timing) {
|
|
68
69
|
if ('refused' in result)
|
|
69
70
|
throw takeBackRefusal(result.refused);
|
|
71
|
+
const turnBefore = ownerTurn(session);
|
|
70
72
|
const items = [...result.cli, ...result.rarog].map((taken) => itemOf(session, taken));
|
|
73
|
+
// A held prompt counted as the owner's answer: without it the question waits again, and the list has to know.
|
|
74
|
+
if (ownerTurn(session) !== turnBefore)
|
|
75
|
+
this.#port.emitSessionChanged(session);
|
|
71
76
|
entry.doneAt = this.#port.now();
|
|
72
77
|
// Take-backs that ran together finish over the cap: the oldest finished results go now, not at the next start.
|
|
73
78
|
this.#trim(results);
|
|
@@ -2,6 +2,7 @@ import { createHash, randomBytes } from 'node:crypto';
|
|
|
2
2
|
import { MAX_TRANSCRIPT_MESSAGES } from '@rarog/shared';
|
|
3
3
|
import { isServerSentence, say } from '@rarog/shared/sentences';
|
|
4
4
|
import { MAX_MESSAGE_BYTES, RING_MAX_BYTES, RingBuffer, jsonBytes } from './ring-buffer.js';
|
|
5
|
+
import { blocksAskOwner, ownerTurn } from './owner-turn.js';
|
|
5
6
|
/**
|
|
6
7
|
* Ile wiadomości trzymamy w RAM na sesję. Stała mieszka w shared (ten sam sufit
|
|
7
8
|
* tnie tablicę `messages` w store klienta); tu zostaje re-eksport dla dotychczasowych importów.
|
|
@@ -236,6 +237,12 @@ export class Session {
|
|
|
236
237
|
* kasowana razem z kartą.
|
|
237
238
|
*/
|
|
238
239
|
cliDialog;
|
|
240
|
+
/**
|
|
241
|
+
* The live dialog card (`docs/dialogs.md`, "Live dialog card"): the dialog region of the pane and the keys the server
|
|
242
|
+
* takes now. The driver owns its lifetime and sends it with the `dialog-live` event (`sessions/live-dialog.ts`); a card
|
|
243
|
+
* swap leaves it, leaving the blocked state clears it.
|
|
244
|
+
*/
|
|
245
|
+
herdrDialogLive;
|
|
239
246
|
/** Panel spoza `RAROG_HERDR_ROOTS`: karta bez transkryptu i bez wysyłki. */
|
|
240
247
|
outOfScope;
|
|
241
248
|
/** Adres panelu w herdr; zmienia się przy `pane move`, więc NIGDY nie jest kluczem. */
|
|
@@ -336,11 +343,18 @@ export class Session {
|
|
|
336
343
|
*/
|
|
337
344
|
artifacts;
|
|
338
345
|
/**
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
*
|
|
346
|
+
* The PRs the card shows (`docs/pull-requests.md`): the owner's PRs among `pullRequestLinks`, recomputed by
|
|
347
|
+
* `pr-status-link.ts` from the links, the window and the facts from GitHub. VOLATILE like `artifacts`. `undefined`
|
|
348
|
+
* = none shown; an empty array is never kept here.
|
|
342
349
|
*/
|
|
343
350
|
pullRequests;
|
|
351
|
+
/**
|
|
352
|
+
* Pull requests linked to the current conversation (the driver's `pull-requests` event, newest first, at most 100)
|
|
353
|
+
* and the time of the conversation's first entry. VOLATILE like `pullRequests` and cleared with it when the
|
|
354
|
+
* conversation changes; `pullRequests` is what the card shows from them. `undefined` = no links or no read.
|
|
355
|
+
*/
|
|
356
|
+
pullRequestLinks;
|
|
357
|
+
pullRequestWindowStart;
|
|
344
358
|
/**
|
|
345
359
|
* Scheduled tasks of the current conversation (`docs/scheduled-tasks.md`), VOLATILE like `pullRequests`: the driver
|
|
346
360
|
* reads them from the conversation file and pays the list out at every attach. `undefined` = none or no read.
|
|
@@ -356,7 +370,7 @@ export class Session {
|
|
|
356
370
|
*/
|
|
357
371
|
observedSessionId;
|
|
358
372
|
/**
|
|
359
|
-
*
|
|
373
|
+
* Engine of a state-only pane (the herdr engine registry) or `undefined` (Claude).
|
|
360
374
|
*
|
|
361
375
|
* Niezmienny przez całe życie karty: zmiana silnika w tym samym panelu to `gone` +
|
|
362
376
|
* `appeared` w nadzorcy, czyli NOWA karta. Gdyby to pole dało się przestawić w miejscu,
|
|
@@ -378,11 +392,20 @@ export class Session {
|
|
|
378
392
|
* bieżącego procesu CLI. `undefined` = nie wiemy (ustawienia Claude Code mogą je włączyć bez wiedzy Raroga).
|
|
379
393
|
*/
|
|
380
394
|
ultracode;
|
|
395
|
+
/** {@link SessionInit.projectRoot} and {@link SessionInit.coordination} of a demo seed. */
|
|
396
|
+
projectRoot;
|
|
397
|
+
coordination;
|
|
381
398
|
/**
|
|
382
399
|
* Wersja CLI zainstalowana w chwili startu panelu przez Raroga: zapas dla bramki wersji, gdy rejestr
|
|
383
400
|
* procesów CLI nie ma jeszcze wpisu świeżego panelu. Pole SERWEROWE: nie ma go w `summary()` ani w rejestrze.
|
|
384
401
|
*/
|
|
385
402
|
cliVersionAtLaunch;
|
|
403
|
+
/**
|
|
404
|
+
* `--plugin-dir` of the session's process: the coordinator plugin copy (`sessions/coordinator-start.ts`), `null` for
|
|
405
|
+
* a process this server started without it, `undefined` for a pane it found (its arguments are not known). A server
|
|
406
|
+
* field: not in `summary()` nor in the registry, so a server restart forgets it.
|
|
407
|
+
*/
|
|
408
|
+
pluginDir;
|
|
386
409
|
/** Żywy driver albo `null` (sesja zamknięta, wznawialna, albo odtworzona z rejestru). */
|
|
387
410
|
driver = null;
|
|
388
411
|
/**
|
|
@@ -390,16 +413,26 @@ export class Session {
|
|
|
390
413
|
* notek o końcu obserwacji artefaktu, ile czegokolwiek innego roli `user` i ile wywołań narzędzi
|
|
391
414
|
* głównego agenta. Pole SERWEROWE, nie ma go w `summary()` ani w rejestrze.
|
|
392
415
|
*
|
|
393
|
-
* `undefined`
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
*
|
|
416
|
+
* `undefined` means an INCOMPLETE tally that nothing may be inferred from: after a driver attaches and after
|
|
417
|
+
* every history portion (the messages of a running turn stand in the history, which is not counted), after a lost
|
|
418
|
+
* continuity of the conversation file (a new conversation in the pane, a truncation, a skipped growth) and after
|
|
419
|
+
* a turn end with an empty tally (that turn's message may not have arrived from the file yet and would count
|
|
420
|
+
* towards the next one), unless a subagent woke from standby in that window (`subagentWakes`): the turn was its
|
|
421
|
+
* work alone, and the tally after it starts from zero. It becomes complete at the next end of a REAL turn the
|
|
422
|
+
* manager sees, or earlier, from zero, when the attach history of a pane just adopted shows it out of a turn
|
|
423
|
+
* ({@link turnTallyAttach}).
|
|
398
424
|
*
|
|
399
425
|
* Liczy manager (`#noteTurnInput`, `#noteToolCalls`), zamyka koniec tury (`#applyTransition`),
|
|
400
426
|
* czyta harmonogram powiadomień: tura bez wyniku (`noResultTurn`) nie daje „gotowe".
|
|
401
427
|
*/
|
|
402
428
|
turnInput = undefined;
|
|
429
|
+
/**
|
|
430
|
+
* The attach of the driver of a pane just adopted, while its history may still start the turn tally from zero
|
|
431
|
+
* (`tallyAfterHistory` in `state-sentences.ts`): the attach time and whether history was read while the card was
|
|
432
|
+
* still standing up. `undefined` once a turn starts or ends, the file continuity is lost, or a zero turn settles.
|
|
433
|
+
* Server field, RAM.
|
|
434
|
+
*/
|
|
435
|
+
turnTallyAttach = undefined;
|
|
403
436
|
/**
|
|
404
437
|
* Koniec tury po samym meldunku o artefakcie, w której manager nie zobaczył wywołania narzędzia:
|
|
405
438
|
* zdarzenie końca, rachunek z tej chwili i czas. Also a turn after a compaction alone.
|
|
@@ -494,6 +527,10 @@ export class Session {
|
|
|
494
527
|
#messages = [];
|
|
495
528
|
/** Suma wag wiadomości w `#messages` — drugi sufit transkryptu (bajty, nie sztuki). */
|
|
496
529
|
#messageBytes = 0;
|
|
530
|
+
/** Ring `seq` of the messages in memory with the "not from the owner" mark ({@link MessageExtra.notFromOwner}). */
|
|
531
|
+
#notFromOwner = new Set();
|
|
532
|
+
/** Ring `seq` of the messages in memory that asked the owner when appended, before the size cap (`owner-turn.ts`). */
|
|
533
|
+
#asksOwner = new Set();
|
|
497
534
|
/**
|
|
498
535
|
* Random name of this memory of the session for {@link readMark}: a card made again under the same id (a pane that
|
|
499
536
|
* resumes the same conversation) numbers its messages from 1 again.
|
|
@@ -540,7 +577,10 @@ export class Session {
|
|
|
540
577
|
this.model = init.model;
|
|
541
578
|
this.effort = init.effort;
|
|
542
579
|
this.ultracode = init.ultracode;
|
|
580
|
+
this.projectRoot = init.projectRoot;
|
|
581
|
+
this.coordination = init.coordination;
|
|
543
582
|
this.cliVersionAtLaunch = init.cliVersionAtLaunch;
|
|
583
|
+
this.pluginDir = init.pluginDir;
|
|
544
584
|
this.seen = init.seen;
|
|
545
585
|
this.stale = undefined;
|
|
546
586
|
this.herdrMode = init.herdrMode;
|
|
@@ -550,6 +590,7 @@ export class Session {
|
|
|
550
590
|
this.herdrDialogReason = undefined;
|
|
551
591
|
this.herdrDialogScreen = undefined;
|
|
552
592
|
this.cliDialog = undefined;
|
|
593
|
+
this.herdrDialogLive = undefined;
|
|
553
594
|
this.outOfScope = init.outOfScope;
|
|
554
595
|
this.paneId = init.paneId;
|
|
555
596
|
this.launchedByRarog = init.launchedByRarog;
|
|
@@ -598,6 +639,8 @@ export class Session {
|
|
|
598
639
|
summary.herdrDialogScreen = this.herdrDialogScreen;
|
|
599
640
|
if (this.cliDialog !== undefined)
|
|
600
641
|
summary.cliDialog = this.cliDialog;
|
|
642
|
+
if (this.herdrDialogLive !== undefined)
|
|
643
|
+
summary.herdrDialogLive = this.herdrDialogLive;
|
|
601
644
|
if (this.outOfScope !== undefined)
|
|
602
645
|
summary.outOfScope = this.outOfScope;
|
|
603
646
|
// `engine` i `termId` jadą na drut, `observedSessionId` NIE — uuid rollouta Codexa
|
|
@@ -644,6 +687,12 @@ export class Session {
|
|
|
644
687
|
summary.effort = this.effort;
|
|
645
688
|
if (this.ultracode !== undefined)
|
|
646
689
|
summary.ultracode = this.ultracode;
|
|
690
|
+
if (this.projectRoot !== undefined)
|
|
691
|
+
summary.projectRoot = this.projectRoot;
|
|
692
|
+
if (this.coordination !== undefined)
|
|
693
|
+
summary.coordination = structuredClone(this.coordination);
|
|
694
|
+
if (ownerTurn(this))
|
|
695
|
+
summary.ownerTurn = true;
|
|
647
696
|
return summary;
|
|
648
697
|
}
|
|
649
698
|
/**
|
|
@@ -669,6 +718,10 @@ export class Session {
|
|
|
669
718
|
const seq = this.ring.push(event);
|
|
670
719
|
message.seq = seq;
|
|
671
720
|
this.#messages.push(message);
|
|
721
|
+
if (extra.notFromOwner === true)
|
|
722
|
+
this.#notFromOwner.add(seq);
|
|
723
|
+
if (blocksAskOwner(role, blocks))
|
|
724
|
+
this.#asksOwner.add(seq);
|
|
672
725
|
this.#messageBytes += jsonBytes(message);
|
|
673
726
|
if (this.#messages.length > MAX_TRANSCRIPT_MESSAGES) {
|
|
674
727
|
this.#dropOldestMessages(this.#messages.length - MAX_TRANSCRIPT_MESSAGES);
|
|
@@ -701,8 +754,11 @@ export class Session {
|
|
|
701
754
|
/** Zdejmuje `count` najstarszych wiadomości razem z ich wagą. */
|
|
702
755
|
#dropOldestMessages(count) {
|
|
703
756
|
const gone = this.#messages.splice(0, count);
|
|
704
|
-
for (const message of gone)
|
|
757
|
+
for (const message of gone) {
|
|
705
758
|
this.#messageBytes -= jsonBytes(message);
|
|
759
|
+
this.#notFromOwner.delete(message.seq);
|
|
760
|
+
this.#asksOwner.delete(message.seq);
|
|
761
|
+
}
|
|
706
762
|
if (this.#messages.length === 0)
|
|
707
763
|
this.#messageBytes = 0;
|
|
708
764
|
}
|
|
@@ -737,6 +793,22 @@ export class Session {
|
|
|
737
793
|
const stamp = createHash('sha256').update(this.stateSince).digest('base64url').slice(0, 11);
|
|
738
794
|
return `${this.#memoryId}.${String(this.#messages.at(-1)?.seq ?? 0)}.${stamp}`;
|
|
739
795
|
}
|
|
796
|
+
/** Messages in memory from the newest back, for a scan that stops early (`owner-turn.ts`). */
|
|
797
|
+
*messagesNewestFirst() {
|
|
798
|
+
for (let at = this.#messages.length - 1; at >= 0; at -= 1) {
|
|
799
|
+
const message = this.#messages[at];
|
|
800
|
+
if (message !== undefined)
|
|
801
|
+
yield message;
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
/** Whether a message in memory carries the server-only "not from the owner" mark. */
|
|
805
|
+
notFromOwner(message) {
|
|
806
|
+
return this.#notFromOwner.has(message.seq);
|
|
807
|
+
}
|
|
808
|
+
/** Whether a message in memory asked the owner when it was appended, read before the size cap. */
|
|
809
|
+
asksOwner(message) {
|
|
810
|
+
return this.#asksOwner.has(message.seq);
|
|
811
|
+
}
|
|
740
812
|
get messageCount() {
|
|
741
813
|
return this.#messages.length;
|
|
742
814
|
}
|
|
@@ -72,6 +72,17 @@ export const MAX_TURNS_DETAIL = say('state.max-turns');
|
|
|
72
72
|
export function isTerminal(state) {
|
|
73
73
|
return state === TERMINAL_STATE;
|
|
74
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* The zero turn of a session started without a prompt: `init` and a successful `result`, so the card waits for the
|
|
77
|
+
* first message. A card that already stands on a decision (a start dialog whose card came before the launch result)
|
|
78
|
+
* keeps it: the synthetic `result` would take it to a sendable `waiting-input` while the dialog stands in the terminal.
|
|
79
|
+
* The pane's `idle` after the answer ends that dialog like any other.
|
|
80
|
+
*/
|
|
81
|
+
export function zeroTurnEvents(state) {
|
|
82
|
+
if (state === 'waiting-permission' || state === 'waiting-question')
|
|
83
|
+
return [];
|
|
84
|
+
return [{ type: 'driver-init' }, { type: 'result', subtype: 'success' }];
|
|
85
|
+
}
|
|
75
86
|
/**
|
|
76
87
|
* Czysta funkcja przejścia.
|
|
77
88
|
*
|
|
@@ -139,6 +150,8 @@ export function transition(state, ev) {
|
|
|
139
150
|
// i „Odrzuć dialog (Esc)" zamiast kart zgody (pusta tablica `pendingPermissions`).
|
|
140
151
|
case 'agent-blocked':
|
|
141
152
|
return AGENT_BLOCKED_FROM.includes(state) ? 'waiting-permission' : state;
|
|
153
|
+
case 'subagent-consent-pending':
|
|
154
|
+
return state === 'running' || state === 'waiting-input' ? 'waiting-permission' : state;
|
|
142
155
|
}
|
|
143
156
|
// Nieznany wariant zdarzenia (np. nowszy serwer w przyszłości) — identyczność, nigdy wyjątek.
|
|
144
157
|
return state;
|