@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.
Files changed (161) hide show
  1. package/node_modules/@rarog/shared/package.json +1 -1
  2. package/node_modules/@rarog/shared/src/decode.js +46 -1
  3. package/node_modules/@rarog/shared/src/notify-copy.js +2 -0
  4. package/node_modules/@rarog/shared/src/protocol/background.js +7 -0
  5. package/node_modules/@rarog/shared/src/protocol/context.js +57 -0
  6. package/node_modules/@rarog/shared/src/protocol/coordination.js +42 -0
  7. package/node_modules/@rarog/shared/src/protocol/dialog-live.js +117 -0
  8. package/node_modules/@rarog/shared/src/protocol/files.js +1 -1
  9. package/node_modules/@rarog/shared/src/protocol/inbox.js +6 -0
  10. package/node_modules/@rarog/shared/src/protocol/presence.js +47 -0
  11. package/node_modules/@rarog/shared/src/protocol.js +14 -146
  12. package/node_modules/@rarog/shared/src/rest.js +16 -1
  13. package/node_modules/@rarog/shared/src/sentences/dialogs.js +10 -0
  14. package/node_modules/@rarog/shared/src/sentences/push.js +9 -0
  15. package/node_modules/@rarog/shared/src/sentences/rest.js +9 -0
  16. package/node_modules/@rarog/shared/src/sentences/restart.js +1 -0
  17. package/node_modules/@rarog/shared/src/sentences/session.js +24 -0
  18. package/package.json +2 -2
  19. package/plugin/rarog/.claude-plugin/plugin.json +4 -0
  20. package/plugin/rarog/bin/rarog-coordinator +7 -0
  21. package/plugin/rarog/hooks/hooks.json +18 -0
  22. package/plugin/rarog/hooks/recipient.mjs +95 -0
  23. package/plugin/rarog/lib/coordinator.mjs +1340 -0
  24. package/plugin/rarog/lib/threads.mjs +350 -0
  25. package/plugin/rarog/skills/coordinator/SKILL.md +111 -0
  26. package/plugin/rarog/skills/coordinator/check-and-merge.md +46 -0
  27. package/plugin/rarog/skills/coordinator/close-thread.md +15 -0
  28. package/plugin/rarog/skills/coordinator/role.md +61 -0
  29. package/plugin/rarog/skills/coordinator/send-back.md +39 -0
  30. package/plugin/rarog/skills/coordinator/start-thread.md +43 -0
  31. package/server/src/bootstrap/coordination.js +49 -0
  32. package/server/src/bootstrap/coordinator-start.js +27 -0
  33. package/server/src/bootstrap/inbox.js +4 -0
  34. package/server/src/bootstrap/pr-status.js +15 -7
  35. package/server/src/bootstrap/push.js +59 -5
  36. package/server/src/cli/doctor-pr-status.js +10 -6
  37. package/server/src/companion/catalog.js +1 -1
  38. package/server/src/companion/index.js +2 -4
  39. package/server/src/config/flags.js +4 -0
  40. package/server/src/config-env.js +15 -0
  41. package/server/src/config.js +17 -3
  42. package/server/src/coordination/merge-events.js +86 -0
  43. package/server/src/coordination/merge-prompt.js +244 -0
  44. package/server/src/coordination/registry.js +289 -0
  45. package/server/src/coordination/state.js +94 -0
  46. package/server/src/coordination/summary.js +422 -0
  47. package/server/src/coordination/thread-file.js +245 -0
  48. package/server/src/coordination/thread-git.js +110 -0
  49. package/server/src/coordination/watch.js +237 -0
  50. package/server/src/demo/content/coordinator.js +89 -0
  51. package/server/src/demo/content/en.js +57 -1
  52. package/server/src/demo/content/pl.js +57 -1
  53. package/server/src/demo/control.js +4 -2
  54. package/server/src/demo/inbox.js +12 -0
  55. package/server/src/demo/mock-herdr.js +5 -4
  56. package/server/src/demo/review-routes.js +2 -2
  57. package/server/src/demo/scenarios.js +31 -17
  58. package/server/src/demo/seeds.js +82 -40
  59. package/server/src/drivers/herdr/live-dialog.js +412 -0
  60. package/server/src/drivers/herdr/live-step.js +261 -0
  61. package/server/src/drivers/herdr/pause-gate.js +60 -0
  62. package/server/src/drivers/herdr/pull-request-poll.js +5 -5
  63. package/server/src/drivers/herdr/queue-take-back.js +4 -0
  64. package/server/src/drivers/herdr/returned-prompt.js +4 -1
  65. package/server/src/drivers/herdr/screen-fallback.js +50 -0
  66. package/server/src/drivers/herdr/start-dialog-gate.js +136 -0
  67. package/server/src/drivers/herdr-driver.js +159 -77
  68. package/server/src/files/refusals.js +9 -2
  69. package/server/src/files/session-gate.js +5 -4
  70. package/server/src/git-branch-diff.js +194 -0
  71. package/server/src/herdr/argv.js +34 -3
  72. package/server/src/herdr/audit.js +32 -1
  73. package/server/src/herdr/background/cli-shapes.js +35 -15
  74. package/server/src/herdr/background/index.js +7 -7
  75. package/server/src/herdr/background/merge.js +17 -5
  76. package/server/src/herdr/background/notification.js +0 -4
  77. package/server/src/herdr/background/pull-request-files.js +53 -161
  78. package/server/src/herdr/background/pull-requests.js +54 -632
  79. package/server/src/herdr/background/queued-prompt.js +46 -0
  80. package/server/src/herdr/background/work.js +96 -0
  81. package/server/src/herdr/client.js +22 -46
  82. package/server/src/herdr/commands/catalog.js +11 -7
  83. package/server/src/herdr/commands/discover.js +33 -1
  84. package/server/src/herdr/commands/index.js +3 -2
  85. package/server/src/herdr/dialogs/copy.js +7 -0
  86. package/server/src/herdr/dialogs/index.js +13 -1
  87. package/server/src/herdr/dialogs/layer1/hook-list/hook-list.js +4 -56
  88. package/server/src/herdr/dialogs/live/model.js +220 -0
  89. package/server/src/herdr/dialogs/live/policy.js +108 -0
  90. package/server/src/herdr/dialogs/live/view.js +261 -0
  91. package/server/src/herdr/dialogs/screen/form.js +6 -4
  92. package/server/src/herdr/dialogs/screen/option-run.js +25 -3
  93. package/server/src/herdr/dialogs/screen/parse.js +3 -3
  94. package/server/src/herdr/dialogs/screen/signatures.js +78 -0
  95. package/server/src/herdr/dialogs/screen/start-dialog.js +72 -0
  96. package/server/src/herdr/dialogs/screen/trust-arrow.js +46 -9
  97. package/server/src/herdr/engines.js +96 -0
  98. package/server/src/herdr/history-steps.js +9 -4
  99. package/server/src/herdr/identity.js +20 -5
  100. package/server/src/herdr/jsonl-follow.js +26 -3
  101. package/server/src/herdr/label-code.js +104 -0
  102. package/server/src/herdr/label-migration.js +142 -0
  103. package/server/src/herdr/launcher.js +30 -5
  104. package/server/src/herdr/plugin-copy.js +281 -0
  105. package/server/src/herdr/provenance.js +80 -40
  106. package/server/src/herdr/session-index.js +19 -0
  107. package/server/src/herdr/start-dialog-wait.js +96 -0
  108. package/server/src/herdr/supervisor.js +49 -23
  109. package/server/src/herdr/types.js +1 -0
  110. package/server/src/herdr/workspace-resolver.js +5 -4
  111. package/server/src/inbox/card.js +31 -8
  112. package/server/src/inbox/heads.js +1 -0
  113. package/server/src/inbox/inbox.js +21 -4
  114. package/server/src/inbox/removals.js +10 -1
  115. package/server/src/index.js +45 -8
  116. package/server/src/notify/apns-payload.js +5 -3
  117. package/server/src/notify/content.js +64 -0
  118. package/server/src/notify/index.js +11 -3
  119. package/server/src/notify/live-activity-state.js +19 -6
  120. package/server/src/notify/live-activity.js +5 -2
  121. package/server/src/notify/policy.js +53 -13
  122. package/server/src/notify/ready-to-merge.js +148 -0
  123. package/server/src/notify/stalled-wait.js +213 -0
  124. package/server/src/pr-status/facts.js +87 -0
  125. package/server/src/pr-status/gh.js +76 -9
  126. package/server/src/pr-status/index.js +1 -10
  127. package/server/src/pr-status/source.js +20 -6
  128. package/server/src/pr-status/tracker.js +32 -9
  129. package/server/src/project-root.js +233 -0
  130. package/server/src/routes/sessions.js +68 -2
  131. package/server/src/sessions/branch-diff.js +57 -0
  132. package/server/src/sessions/cli-registry.js +17 -3
  133. package/server/src/sessions/companion-scope.js +2 -1
  134. package/server/src/sessions/consent-cards.js +49 -2
  135. package/server/src/sessions/conversation-lists.js +11 -2
  136. package/server/src/sessions/coordinator-start.js +172 -0
  137. package/server/src/sessions/demo-modules.js +1 -0
  138. package/server/src/sessions/demo-seeds.js +100 -0
  139. package/server/src/sessions/driver-events.js +68 -14
  140. package/server/src/sessions/herdr-lifecycle.js +11 -4
  141. package/server/src/sessions/interrupt-windows.js +28 -4
  142. package/server/src/sessions/launch-gate.js +36 -11
  143. package/server/src/sessions/live-dialog.js +69 -0
  144. package/server/src/sessions/manager.js +138 -287
  145. package/server/src/sessions/owner-turn.js +36 -0
  146. package/server/src/sessions/pr-status-link.js +64 -16
  147. package/server/src/sessions/seen-marks.js +31 -12
  148. package/server/src/sessions/session-dialog.js +82 -0
  149. package/server/src/sessions/session-git.js +1 -0
  150. package/server/src/sessions/session-scope.js +6 -5
  151. package/server/src/sessions/session-take-back.js +5 -0
  152. package/server/src/sessions/session.js +82 -10
  153. package/server/src/sessions/state-machine.js +13 -0
  154. package/server/src/sessions/state-sentences.js +87 -30
  155. package/server/src/sessions/test-session.js +50 -0
  156. package/server/src/sessions/waiting-line.js +49 -0
  157. package/server/src/term/herdr-backend.js +15 -12
  158. package/server/src/term/lifecycle.js +4 -6
  159. package/server/src/transcript-import.js +20 -2
  160. package/server/src/version.js +4 -0
  161. /package/server/src/{companion/asks-owner.js → asks-owner.js} +0 -0
@@ -23,6 +23,10 @@
23
23
  * w regule dla wpisu `user`: wśród 112 zmierzonych promptów człowieka nie miał go żaden, a każda
24
24
  * z 40 wiadomości od subagentów go niesie. Kierunek awarii jest ten sam co przed tym modułem (wiadomości nie
25
25
  * widać), nigdy odwrotny (cudzy tekst jako wypowiedź użytkownika).
26
+ *
27
+ * The module also recognizes a message from another Claude session ({@link crossSessionPrompt}), on this carrier and
28
+ * on the meta `user` entry. It is a separate function with its own condition, so the human prompt rule above stays
29
+ * as it is; the parser shows such a message only when its caller asks for it.
26
30
  */
27
31
  import { CLI_SHAPES } from './cli-shapes.js';
28
32
  const CARRIERS = CLI_SHAPES.notificationCarriers.literals;
@@ -50,3 +54,45 @@ export function queuedHumanPrompt(value) {
50
54
  const at = entry['timestamp'];
51
55
  return { prompt: attachment[CARRIERS.queuedText], at: typeof at === 'string' ? at : '' };
52
56
  }
57
+ const PEER = CLI_SHAPES.crossSessionPeer.literals;
58
+ /**
59
+ * Whether an entry of the MAIN file is a message another Claude session sent with `SendMessage`; `null` = no.
60
+ *
61
+ * Both carriers count, so an idle receiver and a turn that absorbed the message give the same text: the meta `user`
62
+ * entry (idle) and the queue attachment in prompt mode (mid-turn). The origin must be exactly `peer` with a socket
63
+ * address in `from` and a non-empty `body`; a subagent's message (`from` = agent id), a delivery or idle notice
64
+ * (no `peer` origin) and an unmeasured origin stay out. Whether such a message is shown at all is the caller's call:
65
+ * the text is model-written, not typed by the user.
66
+ */
67
+ export function crossSessionPrompt(value) {
68
+ const entry = asRecord(value);
69
+ if (entry === null || entry['isSidechain'] === true)
70
+ return null;
71
+ let origin;
72
+ if (entry['type'] === 'user') {
73
+ if (entry['isMeta'] !== true)
74
+ return null;
75
+ origin = asRecord(entry[QUEUED.origin]);
76
+ }
77
+ else if (entry['type'] === CARRIERS.attachmentType) {
78
+ const attachment = asRecord(entry[CARRIERS.attachmentField]);
79
+ if (attachment === null || attachment['type'] !== CARRIERS.queuedCommand)
80
+ return null;
81
+ if (attachment[QUEUED.mode] !== QUEUED.prompt)
82
+ return null;
83
+ origin = asRecord(attachment[QUEUED.origin]);
84
+ }
85
+ else {
86
+ return null;
87
+ }
88
+ if (origin === null || origin[QUEUED.kind] !== PEER.peer)
89
+ return null;
90
+ const from = origin[PEER.from];
91
+ const body = origin[PEER.body];
92
+ if (typeof from !== 'string' || !from.startsWith(PEER.socket))
93
+ return null;
94
+ if (typeof body !== 'string' || body.trim() === '')
95
+ return null;
96
+ const at = entry['timestamp'];
97
+ return { body, at: typeof at === 'string' ? at : '' };
98
+ }
@@ -1,3 +1,7 @@
1
+ /** From this age of a wait on an own command (`waitingSince` to now) the stage is `long`. */
2
+ export const WAIT_LONG_MS = 30 * 60_000;
3
+ /** From this age of a wait on an own command the stage is `stuck`. */
4
+ export const WAIT_STUCK_MS = 60 * 60_000;
1
5
  /**
2
6
  * Subagent w POSTOJU: rodzaj `agent` z polem `waitingSince`. Skończył turę i czeka na własne
3
7
  * zadanie w tle — nie pracuje i nie skończył.
@@ -49,6 +53,84 @@ export function tasksHoldingDonePush(tasks) {
49
53
  export function waitingOnOwnCommand(tasks) {
50
54
  return (tasks ?? []).some((task) => waitingAgent(task) && (task.ownTasks?.length ?? 0) > 0);
51
55
  }
56
+ /**
57
+ * One task: a subagent in standby ({@link waitingAgent}) with a known open own command (`ownTasks` not empty), the
58
+ * same condition as {@link waitingOnOwnCommand} for a single task.
59
+ */
60
+ function waitsOnOwnCommand(task) {
61
+ return waitingAgent(task) && (task.ownTasks?.length ?? 0) > 0;
62
+ }
63
+ /**
64
+ * The wait stage of one task (`BackgroundTask.ownCommandWait`) at `nowMs`, or `undefined` when the task does not wait
65
+ * on a known own command ({@link waitsOnOwnCommand}).
66
+ *
67
+ * The age runs from `waitingSince`, not from the start of the command or the agent: a command meant to run long (a dev
68
+ * server started before the standby) must not count, and a new standby starts a new wait. This is the only rule that
69
+ * reads the clock; `merge.ts` calls it on every emission, so the list goes out again on the first tick past a
70
+ * threshold. An unreadable `waitingSince` or a clock behind it gives `short`: no proof of a long wait.
71
+ */
72
+ export function ownCommandWaitOf(task, nowMs) {
73
+ if (!waitsOnOwnCommand(task))
74
+ return undefined;
75
+ const age = nowMs - Date.parse(task.waitingSince ?? '');
76
+ if (age >= WAIT_STUCK_MS)
77
+ return 'stuck';
78
+ if (age >= WAIT_LONG_MS)
79
+ return 'long';
80
+ return 'short';
81
+ }
82
+ /**
83
+ * Opaque key of one wait: the agent and the start of its standby. Present only on a task that carries
84
+ * `ownCommandWait`, so it names the same wait across emissions while the stage grows, and a wake followed by a new
85
+ * standby gives a new key. Callers compare keys and never read the two fields themselves.
86
+ */
87
+ export function waitKey(task) {
88
+ if (task.ownCommandWait === undefined || !waitingAgent(task))
89
+ return undefined;
90
+ return JSON.stringify([task.id, task.waitingSince]);
91
+ }
92
+ /** A session that ended (`done`) or waits for a resume: an agent still on its list is a phantom for the rules. */
93
+ function phantomState(state) {
94
+ return state === 'done' || state === 'resumable';
95
+ }
96
+ /**
97
+ * Live Activity counter "waiting": a session after a turn (`waiting-input`) whose list has a wait at `stuck`. Such a
98
+ * session counts as waiting, not as finished or working, and is not the tap target (`aggregateState` in
99
+ * `notify/live-activity-state.ts`). Other states keep their own counter: a decision already waits, a turn works, and
100
+ * `done` or `resumable` has a phantom agent. The stage is read from the field only (`ownCommandWaitOf` set it).
101
+ */
102
+ export function stuckWait(state, tasks) {
103
+ return state === 'waiting-input' && (tasks ?? []).some((task) => task.ownCommandWait === 'stuck');
104
+ }
105
+ /**
106
+ * The edge of the stalled wait alarm between two lists of one session: a wait whose key was below `stuck` on `before`
107
+ * and is `stuck` on `after`. `short` → `stuck` is an edge (a sleeping Mac can skip `long`); a key absent from
108
+ * `before`, or without a stage there (first list after a Rarog restart or a driver swap, an agent before its file was
109
+ * read), is not, so a restart never repeats the alarm. Any session state gives the edge except a phantom one (`done`,
110
+ * `resumable`), which also has nothing at `stuck`; its waits keep their keys in `waitKeys`.
111
+ */
112
+ export function stuckWaits(state, before, after) {
113
+ const below = new Set((before ?? []).flatMap((task) => {
114
+ const key = waitKey(task);
115
+ return key !== undefined && task.ownCommandWait !== 'stuck' ? [key] : [];
116
+ }));
117
+ const waitKeys = [];
118
+ const stuckKeys = [];
119
+ const newly = [];
120
+ for (const task of after ?? []) {
121
+ const key = waitKey(task);
122
+ if (key === undefined)
123
+ continue;
124
+ waitKeys.push(key);
125
+ if (task.ownCommandWait !== 'stuck' || phantomState(state))
126
+ continue;
127
+ stuckKeys.push(key);
128
+ if (below.has(key)) {
129
+ newly.push({ key, agentId: task.id, ...(task.description === undefined ? {} : { description: task.description }) });
130
+ }
131
+ }
132
+ return { newly, stuckKeys, waitKeys };
133
+ }
52
134
  /**
53
135
  * Zaległe „gotowe": czy lista je WSTRZYMUJE — coś pracuje ({@link tasksHoldingDonePush}) albo
54
136
  * subagent w postoju czeka na własną komendę ({@link waitingOnOwnCommand}).
@@ -62,6 +144,18 @@ export function waitingOnOwnCommand(tasks) {
62
144
  export function holdsOwedDone(tasks) {
63
145
  return tasksHoldingDonePush(tasks) > 0 || waitingOnOwnCommand(tasks);
64
146
  }
147
+ /**
148
+ * Subagents that woke between two lists of a session: in standby ({@link waitingAgent}) on the list `before`, on the
149
+ * list `after` under the same id without `waitingSince` (the wake overlay of `merge.ts`). A subagent works in the
150
+ * main pane, so herdr reports that pane as working although the main agent got no input; the manager counts these
151
+ * wakes into the turn tally, and a turn with no input but a wake has no result (`noResultTurn` in
152
+ * `notify/policy.ts`). Not a wake: an agent new on the list, one that came back from dormancy (it was off the list),
153
+ * and one that woke and stood again between two lists (a new `waitingSince`).
154
+ */
155
+ export function agentsWoken(before, after) {
156
+ const waiting = new Set((before ?? []).filter(waitingAgent).map((task) => task.id));
157
+ return (after ?? []).filter((task) => task.kind === 'agent' && !waitingAgent(task) && waiting.has(task.id)).length;
158
+ }
65
159
  /**
66
160
  * Restart sesji na nowym Claude Code: czy lista go blokuje.
67
161
  *
@@ -111,6 +205,8 @@ function openWorkflow(task) {
111
205
  * Kafel Live Activity, licznik „pracuje": na liście jest zadanie, które jeszcze mieli
112
206
  * ({@link liveTask}). Sesja po turze, której wszystkie zadania to czekający subagenci, do
113
207
  * „pracuje" się nie liczy; z nieodebranym wynikiem liczy się do „skończyły".
208
+ * Exception: a session after a turn with a wait at `stuck` ({@link stuckWait}) counts as waiting, neither as working
209
+ * nor as finished.
114
210
  */
115
211
  export function hasBackgroundWork(tasks) {
116
212
  return (tasks ?? []).some(liveTask);
@@ -3,23 +3,27 @@
3
3
  * herdr → klasy błędów Raroga.
4
4
  *
5
5
  * Tu mieszka też TWARDY FILTR WEJŚCIOWY integracji: `agent === 'claude'` (a przy
6
- * `RAROG_CODEX_STATUS` także `agent === 'codex'`), `agent_session.kind === 'id'`
7
- * i `value` pasujące do `ENGINE_SESSION_ID_PATTERN`. Filtr musi być w tym miejscu, bo tylko tu
6
+ * `RAROG_CODEX_STATUS` także `agent === 'codex'`, a przy `RAROG_AGY_STATUS` `agent === 'agy'`; rodzaje zna
7
+ * `engineOfAgent` z `engines.ts`),
8
+ * `agent_session.kind === 'id'` i `value` pasujące do `ENGINE_SESSION_ID_PATTERN`. Filtr musi być
9
+ * w tym miejscu, bo tylko tu
8
10
  * widać jeszcze surowe pola `agent`/`kind` — kontrakt `HerdrAgentInfo` ich nie niesie.
9
11
  * Cokolwiek innego (inny agent, `kind: 'path'`, panel bez `cwd`) NIE ISTNIEJE dla Raroga:
10
12
  * nie ma pliku transkryptu, nie ma sprawdzalnego zakresu, nie ma czego pokazać.
13
+ * A state-only engine is the exception to the session rule: without a session ID it enters with
14
+ * `agentSessionId: ''`.
11
15
  *
12
16
  * Nieznane pola odpowiedzi IGNORUJEMY (`z.looseObject`, nie `z.strictObject`): herdr wydaje
13
17
  * minor co 2–3 tygodnie i dokłada pola addytywnie, a Rarog nie ma prawa paść od nowego pola.
14
18
  */
15
19
  import { z } from 'zod';
16
- import { basename } from 'node:path';
17
20
  import { TERM_ID_RE } from '@rarog/shared';
18
21
  import { foreign, say } from '@rarog/shared/sentences';
19
22
  import { HERDR_PROMPT_WAIT_MS, HERDR_START_REQUEST_TIMEOUT_MS, HERDR_START_WAIT_MS, termPaneTokenOf, } from '../config.js';
20
23
  import { ENGINE_SESSION_ID_PATTERN } from '../transcript-import.js';
21
24
  import { assertAllowedKeys } from './dialogs/send/keys.js';
22
25
  import { RAROG_AGENT_NAME_RE } from './provenance.js';
26
+ import { engineOfAgent, isStateOnlyEngine, normalizeEngineTitle } from './engines.js';
23
27
  import { FORM_SUBMIT_KEY, assertFormSubmitKeys } from './dialogs/send/form-submit.js';
24
28
  import { MODE_CYCLE_KEY, assertModeCycleKeys } from './mode-cycle.js';
25
29
  import { assertDialogKey } from './dialogs/send/key-row.js';
@@ -257,31 +261,6 @@ const startAgentResultSchema = z.looseObject({
257
261
  function toStatus(raw) {
258
262
  return KNOWN_STATUSES.has(raw) ? raw : 'unknown';
259
263
  }
260
- /** Klatka spinnera Codexa: znak brajlowski (U+2800–U+28FF) z odstępem za nim. */
261
- const CODEX_SPINNER_RE = /^[⠀-⣿]+\s*/u;
262
- /**
263
- * Tytuł Codexa → tytuł dla karty. JEDNO miejsce, w którym znika spinner i katalog.
264
- *
265
- * Zmierzone na żywym herdr 0.9.0: `terminal_title_stripped` Codexa ma kształt
266
- * `<pierwszy prompt> | <katalog>`, w trakcie pracy z wiodącą klatką spinnera braille (`⠴ …`),
267
- * a przed pierwszym promptem jest SAMĄ nazwą katalogu.
268
- *
269
- * Normalizacja musi być tutaj, a nie w warstwie widoku, z dwóch powodów: nadzorca porównuje
270
- * tytuły między migawkami, więc kolejne klatki spinnera zgłaszałyby `titleChanged` kilka razy
271
- * na sekundę, a manager ma dostać w zdarzeniu tekst, który da się pokazać bez dalszej obróbki.
272
- * Sufiks katalogu zdejmujemy, bo nazwę projektu wiersz w kliencie i tak bierze z `cwd` — zostawiony
273
- * dublowałby ją w każdym wierszu.
274
- */
275
- export function normalizeCodexTitle(raw, cwd) {
276
- const dir = basename(cwd);
277
- let title = raw.replace(CODEX_SPINNER_RE, '').trim();
278
- if (dir !== '' && title.endsWith(` | ${dir}`)) {
279
- title = title.slice(0, title.length - dir.length - 3).trim();
280
- }
281
- // Tytuł równy samej nazwie katalogu = panel PRZED pierwszym promptem. Pusty string znaczy
282
- // „nie ma tytułu", a manager zamienia go na nazwę katalogu tą samą regułą co dla Claude.
283
- return title === dir ? '' : title;
284
- }
285
264
  /**
286
265
  * Surowy wpis herdr → `HerdrAgentInfo`, albo `null`, gdy agent nie jest dla Raroga.
287
266
  *
@@ -293,22 +272,18 @@ export function normalizeAgentInfo(raw, opts = {}) {
293
272
  if (!parsed.success)
294
273
  return null;
295
274
  const info = parsed.data;
296
- /*
297
- * Bramka silnika. `codex` wchodzi WYŁĄCZNIE przy jawnej fladze; każdy inny agent
298
- * (`future-agent`, `aider`, …) odpada tak jak dotąd — Rarog nie zna ani jego stopki, ani
299
- * jego pliku treści, więc wiersz w sidebarze byłby obietnicą bez pokrycia.
300
- */
301
- const engine = info.agent === 'claude' ? 'claude'
302
- : (info.agent === 'codex' && opts.codexStatus === true ? 'codex' : null);
275
+ // Engine gate: the registry admits `claude` and, behind its flag, each state-only engine.
276
+ const engine = engineOfAgent(info.agent, {
277
+ codexStatus: opts.codexStatus === true, agyStatus: opts.agyStatus === true,
278
+ });
303
279
  if (engine === null)
304
280
  return null;
305
281
  const session = info.agent_session;
306
- if (session === null || session === undefined)
307
- return null;
308
- if (session.kind !== 'id')
309
- return null;
310
- const value = session.value;
311
- if (typeof value !== 'string' || !ENGINE_SESSION_ID_PATTERN.test(value))
282
+ const value = session?.kind === 'id' && typeof session.value === 'string'
283
+ && ENGINE_SESSION_ID_PATTERN.test(session.value) ? session.value : '';
284
+ // Claude needs its session (the transcript file). A state-only engine enters without one, as `''`: herdr 0.9.5
285
+ // reports no `agent_session` for Codex CLI 0.171.0, and the session only addresses the seen mark.
286
+ if (value === '' && !isStateOnlyEngine(engine))
312
287
  return null;
313
288
  const cwd = info.cwd;
314
289
  if (typeof cwd !== 'string' || cwd === '')
@@ -345,9 +320,10 @@ export function normalizeAgentInfo(raw, opts = {}) {
345
320
  // założonych ręcznie w terminalu — czyli do całej dotychczasowej wartości Raroga.
346
321
  // Wpis Codexa jest tu WYJĄTKIEM i to jego jedyne miejsce: nic do niego nie wysyłamy,
347
322
  // a odpowiedź herdr tego pola dla Codexa w ogóle nie niesie (zmierzone).
348
- interactiveReady: engine === 'codex' ? false : (info.interactive_ready ?? true),
349
- title: engine === 'codex'
350
- ? normalizeCodexTitle(info.terminal_title_stripped ?? '', cwd)
323
+ // An agy record does carry `interactive_ready: true`; a state-only entry still takes no sending.
324
+ interactiveReady: isStateOnlyEngine(engine) ? false : (info.interactive_ready ?? true),
325
+ title: isStateOnlyEngine(engine)
326
+ ? normalizeEngineTitle(engine, info.terminal_title_stripped ?? '', cwd)
351
327
  : (info.terminal_title_stripped ?? ''),
352
328
  stateChangeSeq: info.state_change_seq ?? 0,
353
329
  };
@@ -545,7 +521,7 @@ async function readPaneHistory(call, paneId, lines) {
545
521
  /**
546
522
  * Typowana fasada nad transportem.
547
523
  *
548
- * `opts` niesie dziś jedną rzecz — flagę `RAROG_CODEX_STATUS`. Jest polem FASADY,
524
+ * `opts` niesie flagi silników samego stanu (`RAROG_CODEX_STATUS`, `RAROG_AGY_STATUS`). Są polem FASADY,
549
525
  * a nie argumentem każdego wywołania, bo obie drogi wpisu (`agent.list` przy resyncu
550
526
  * i `agent.get` przy pushu) muszą filtrować IDENTYCZNIE: jedna bramka, jedno źródło prawdy.
551
527
  */
@@ -573,7 +549,7 @@ export function createHerdrClient(requester, opts = {}) {
573
549
  const info = parsed.success ? normalizeAgentInfo(parsed.data.agent, opts) : null;
574
550
  if (info === null) {
575
551
  // Panel istnieje, ale nie jest już agentem obsługiwanym przez Raroga (Claude, a przy
576
- // `RAROG_CODEX_STATUS` także Codex) z sesją po id — dla Raroga to dokładnie to samo,
552
+ // fladze silnika także Codex albo agy) — dla Raroga to dokładnie to samo,
577
553
  // co zniknięcie panelu.
578
554
  throw new HerdrGoneError(say('herdr.agent-gone', { key: paneId }));
579
555
  }
@@ -1,5 +1,6 @@
1
1
  /**
2
- * Katalog komend sesji — JEDNA migawka tego, co Rarog przepuszcza z telefonu, per `(cwd, wersja CLI)`.
2
+ * Katalog komend sesji — JEDNA migawka tego, co Rarog przepuszcza z telefonu, per `(cwd, wersja CLI)` and the
3
+ * session's plugin directories (`--plugin-dir` of a coordinator).
3
4
  *
4
5
  * Migawka = wpisy `allowed` rejestru wbudowanych (`registry.ts`, zmierzone per wersja CLI) ∪ wbudowane
5
6
  * skille `allowed` ∪ skille i komendy z dysku w opisanym podzbiorze (`discover.ts`). Ta sama migawka idzie
@@ -141,14 +142,15 @@ export function createCommandCatalogs(opts) {
141
142
  opts.log?.(line);
142
143
  };
143
144
  return {
144
- get(cwd, cliVersion) {
145
+ get(cwd, cliVersion, pluginDirs = []) {
145
146
  if (cliVersion !== COMMANDS_CLI) {
146
147
  logOnce(`command catalog: CLI ${cliVersion ?? 'of unknown version'} not measured — built-in set `
147
148
  + `from the ${COMMANDS_CLI} measurement`);
148
149
  }
149
- // Jedna wersja zmierzona = jeden zestaw wbudowanych, więc klucz pamięci to sam katalog.
150
+ // Jedna wersja zmierzona = jeden zestaw wbudowanych, więc klucz pamięci to katalog i pluginy sesji.
151
+ const key = pluginDirs.length === 0 ? cwd : JSON.stringify([cwd, ...pluginDirs]);
150
152
  const at = now();
151
- const entry = cache.get(cwd);
153
+ const entry = cache.get(key);
152
154
  if (entry !== undefined) {
153
155
  if (at - entry.checkedAt < checkMs)
154
156
  return entry.catalog;
@@ -158,21 +160,23 @@ export function createCommandCatalogs(opts) {
158
160
  }
159
161
  let discovered;
160
162
  try {
161
- discovered = discover({ home: opts.home, cwd, roots: opts.roots, reserved });
163
+ discovered = discover({
164
+ home: opts.home, cwd, roots: opts.roots, reserved, ...(pluginDirs.length === 0 ? {} : { pluginDirs }),
165
+ });
162
166
  }
163
167
  catch (error) {
164
168
  // Skan nie rzuca z założenia; gdyby jednak — wysyłka nie dostaje 500, tylko allow-listę z samego
165
169
  // rejestru (skille z dysku dostają odmowę), a następne pytanie skanuje od nowa.
166
170
  logOnce(`command catalog: disk scan for ${cwd} failed (${error instanceof Error ? error.name : 'error'}) `
167
171
  + '— snapshot from the registry alone');
168
- cache.delete(cwd);
172
+ cache.delete(key);
169
173
  return registryCatalog();
170
174
  }
171
175
  for (const note of discovered.notes)
172
176
  logOnce(note);
173
177
  const fresh = buildCatalog(cwd, discovered);
174
178
  const catalog = entry !== undefined && entry.catalog.revision === fresh.revision ? entry.catalog : fresh;
175
- cache.set(cwd, { catalog, stamps: discovered.stamps, checkedAt: at, scannedAt: at });
179
+ cache.set(key, { catalog, stamps: discovered.stamps, checkedAt: at, scannedAt: at });
176
180
  return catalog;
177
181
  },
178
182
  };
@@ -18,7 +18,9 @@
18
18
  * korzeniowi repo `cwd`, włączone wg `enabledPlugins` (`settings.local.json` > `settings.json`
19
19
  * projektu > `~/.claude/settings.json`; brak wpisu → `defaultEnabled` manifestu, domyślnie `true`),
20
20
  * wyłącznie z domyślnych katalogów `skills/<katalog>/SKILL.md` i `commands/<plik>.md`; komenda
21
- * `/<plugin>:<name|katalog>` albo `/<plugin>:<plik>`.
21
+ * `/<plugin>:<name|katalog>` albo `/<plugin>:<plik>`;
22
+ * - plugin directories of the session (`pluginDirs`, `--plugin-dir` of a coordinator): the same default directories
23
+ * and names, the plugin name from the manifest, without an install entry or `enabledPlugins`.
22
24
  *
23
25
  * Filtry: `user-invocable: false` i `skillOverrides[nazwa] === "off"` (tego drugiego pluginy nie mają)
24
26
  * chowają skill; nazwa spoza kształtu nazw Raroga (`isCommandName`) i nazwa komendy wbudowanej też (przy tej drugiej
@@ -499,6 +501,34 @@ function scanPlugin(scan, pluginsDir, settings, key, entry) {
499
501
  scan.skipped.push({ plugin: key, reason: 'name' });
500
502
  return;
501
503
  }
504
+ scanPluginCommands(scan, installPath, plugin);
505
+ }
506
+ /**
507
+ * Plugin directories the session loads with `--plugin-dir` (the coordinator's plugin copy): no install entry and no
508
+ * `enabledPlugins`, the plugin name only from its manifest (the directory of a copy is named after a version), and the
509
+ * same default directories and name rules as an installed plugin. A manifest without a valid name, or with its own
510
+ * command or skill paths, skips the directory.
511
+ */
512
+ function scanSessionPlugins(scan, dirs) {
513
+ const layout = DISK_LAYOUT.plugins;
514
+ const keys = DISK_LAYOUT.manifestKeys;
515
+ for (const dir of dirs) {
516
+ const manifest = scan.json(join(dir, layout.manifestDir, layout.manifest)) ?? {};
517
+ if (keys.commands in manifest || keys.skills in manifest) {
518
+ scan.skipped.push({ plugin: dir, reason: 'manifest-paths' });
519
+ scan.note(`command catalog: plugin ${dir} has its own command or skill paths in the manifest — skipping`);
520
+ continue;
521
+ }
522
+ const plugin = manifest[keys.name];
523
+ if (typeof plugin !== 'string' || !isCommandSegment(plugin)) {
524
+ scan.skipped.push({ plugin: dir, reason: 'name' });
525
+ continue;
526
+ }
527
+ scanPluginCommands(scan, dir, plugin);
528
+ }
529
+ }
530
+ /** Skills `skills/<dir>/SKILL.md` and commands `commands/<file>.md` of one plugin, named `<plugin>:<…>`. */
531
+ function scanPluginCommands(scan, installPath, plugin) {
502
532
  const skillsDir = join(installPath, DISK_LAYOUT.skillsDir);
503
533
  for (const dir of scan.entries(skillsDir, 'dir')) {
504
534
  if (!isCommandSegment(dir))
@@ -604,6 +634,8 @@ export function discoverCommands(opts) {
604
634
  scanCommandFiles(scan, join(projectDir, DISK_LAYOUT.commandsDir), 'project-command', settings);
605
635
  }
606
636
  scanSynced(scan, opts.home);
637
+ // The session's own plugin first: on a name it shares with an installed plugin, its description goes to the list.
638
+ scanSessionPlugins(scan, opts.pluginDirs ?? []);
607
639
  scanPlugins(scan, opts.home, settings, repoRoot ?? resolve(opts.cwd));
608
640
  const { commands, hidden } = resolveNames(scan, opts.reserved);
609
641
  return {
@@ -16,8 +16,9 @@
16
16
  * (`createSendThrottle`).
17
17
  * - `shape.ts` — reguła rozpoznania komendy w tekście (`classifySlashText`) i kształt Raroga dla
18
18
  * nazwy komendy, jedna definicja dla strażnika managera i drivera.
19
- * - `catalog.ts` — migawka katalogu sesji per `(cwd, wersja CLI)` z `revision` (`createCommandCatalogs`,
20
- * `registryCatalog`) i lista dla apki z migawki (`commandListOf`, `GET /api/sessions/:id/commands`).
19
+ * - `catalog.ts` — migawka katalogu sesji per `(cwd, wersja CLI)` and `--plugin-dir` z `revision`
20
+ * (`createCommandCatalogs`, `registryCatalog`) i lista dla apki z migawki (`commandListOf`,
21
+ * `GET /api/sessions/:id/commands`).
21
22
  * - `discover.ts` — skille i komendy z dysku w wąskim, jawnym podzbiorze źródeł CLI.
22
23
  * - `transcript.ts` — wpis komendy w pliku rozmowy → wiadomość transkryptu (notka `system` komendy lokalnej
23
24
  * i jej wyniku, wiadomość `user` komendy typu prompt), bezstanowo; tu też rozpoznanie promptu
@@ -24,6 +24,13 @@ export const TERMINAL_DIALOG_MESSAGE = say('dialogs.terminal-dialog');
24
24
  * celowo, żeby go zmierzyć (mechanizm bezpieczeństwa modelu) — driver go więc nie wysyła.
25
25
  */
26
26
  export const PAUSE_ESCAPE_MESSAGE = say('dialogs.pause-escape');
27
+ /**
28
+ * A Claude Code start dialog herdr reads as ready: the card's sentence for the external imports dialog (the answer is
29
+ * kept for the project for good) and for an unknown one, and the refusal of a key or text sent to either.
30
+ */
31
+ export const START_DIALOG_IMPORTS_MESSAGE = say('dialogs.start-dialog.imports');
32
+ export const START_DIALOG_UNKNOWN_MESSAGE = say('dialogs.start-dialog.unknown');
33
+ export const START_DIALOG_REFUSED_MESSAGE = say('dialogs.start-dialog.refused');
27
34
  /** Odpowiedź z nieświeżej karty: dialog na ekranie jest już inny niż ten, w który tapnięto. */
28
35
  export const STALE_DECISION_MESSAGE = say('dialogs.stale-decision');
29
36
  /**
@@ -138,6 +138,8 @@
138
138
  * - `screen/confirm.ts` — potwierdzenie ustawień CLI rozpoznane po kształcie (`confirmFrom`).
139
139
  * - `screen/resolve.ts` — cross-check ekranu z jsonl i hookiem (`resolveOptions`).
140
140
  * - `screen/trust-arrow.ts` — dialog zaufania bez cyfr: pełny render, folder, `❯`, odcisk bloku.
141
+ * - `screen/start-dialog.ts` — start dialog herdr reads as ready: no prompt field, and the external imports dialog
142
+ * recognised from its option pair and key footer (`startDialogOf`).
141
143
  * - `screen/mode-footer.ts` — tryb uprawnień ze stopki ekranu (nie dialog: nadzorca, `mode-cycle.ts`).
142
144
  * - `screen/operation.ts` — operacja dialogu zgody (ramka komendy).
143
145
  * - `screen/edit-frame.ts` — dowód wywołania `Edit` i `Write`: ścieżka z nagłówka i diff albo treść z ramki.
@@ -165,6 +167,15 @@
165
167
  * the audit (`episodeVerdictOf`, `LAYER2_EPISODE_VERDICTS`).
166
168
  * - `layer2/verdict.ts` — layer 2 rule (`layer2Verdict`): buttons with whole literal labels from the block's raw
167
169
  * rows, or the reason for none (pure function; the server calls it through `layer2Gate`).
170
+ * - `live/view.ts` — the live dialog card, screen half (`liveRegion`): the dialog region of a raw screen from
171
+ * the top rule to the last footer line, its options, the cursor, the cut and scroll marks,
172
+ * the text under the presentation ceiling and the fingerprint.
173
+ * - `live/policy.ts` — the Enter rule of the live card (`liveEnterWhy`, the closed list `LIVE_ENTER_WHYS`) and
174
+ * the keys the server takes (`liveKeys`); Esc is always among them.
175
+ * - `live/model.ts` — the live card of a screen (`liveDialogView`): the label under the cursor, its lasting
176
+ * effect, the whole option set of a dialog without a key footer, and the wire field
177
+ * `herdrDialogLive` (`liveDialogWire`). Pure functions; `drivers/herdr/live-dialog.ts`
178
+ * calls them.
168
179
  *
169
180
  * ── Jak importować
170
181
  *
@@ -178,7 +189,7 @@
178
189
  * też transkryptu ani modułów drivera herdr (`drivers/herdr/`), a tryb cienia (`shadow/`) nie zna warstwy 1
179
190
  * (strażnik: `server/test/layer1-granica.test.ts`).
180
191
  */
181
- export { FORM_SUBMIT_GONE_MESSAGE, MULTI_SELECT_MESSAGE, NOTE_NOT_ALLOWED_MESSAGE, NOTE_NO_CHANNEL_MESSAGE, NOTE_WRITE_FAILED_MESSAGE, NO_ANSWER_ON_SCREEN_MESSAGE, NO_DIGIT_MESSAGE, PAUSE_ESCAPE_MESSAGE, SCREEN_CHANGED_MESSAGE, STALE_DECISION_MESSAGE, TERMINAL_DIALOG_MESSAGE, TERMINAL_ONLY_MESSAGE, formSubmitAbortMessage, hookAnswerPartialMessage, noteNotDeliveredMessage, } from './copy.js';
192
+ export { FORM_SUBMIT_GONE_MESSAGE, MULTI_SELECT_MESSAGE, NOTE_NOT_ALLOWED_MESSAGE, NOTE_NO_CHANNEL_MESSAGE, NOTE_WRITE_FAILED_MESSAGE, NO_ANSWER_ON_SCREEN_MESSAGE, NO_DIGIT_MESSAGE, PAUSE_ESCAPE_MESSAGE, SCREEN_CHANGED_MESSAGE, STALE_DECISION_MESSAGE, START_DIALOG_IMPORTS_MESSAGE, START_DIALOG_REFUSED_MESSAGE, START_DIALOG_UNKNOWN_MESSAGE, TERMINAL_DIALOG_MESSAGE, TERMINAL_ONLY_MESSAGE, formSubmitAbortMessage, hookAnswerPartialMessage, noteNotDeliveredMessage, } from './copy.js';
182
193
  export { ANSWERED_HOOK_SHIELD_MS, CLI_HOLD_MISSES, CLI_WAITING_PROBES, DECIDED_SHIELD_MS, FORM_FALLBACK_MISSES, FORM_FALLBACK_RETRY_DELAYS_MS, FORM_SUBMIT_CONFIRM_DELAY_MS, HOOK_ANSWER_POLL_MS, HOOK_ANSWER_WAIT_MS, SCREEN_ANSWER_REARM_DELAYS_MS, SHADOW_DEADLINE_MS, } from './timing.js';
183
194
  export { askFormOnScreen, cliDialogOnScreen } from './presence.js';
184
195
  export { DIALOG_ROUTES, DIALOG_ROUTE_REASONS, routeAllowsDigit, routeDialog, routeHookOf, routeScreenOf, } from './router.js';
@@ -202,6 +213,7 @@ export { dialogThreadOnScreen, parseOptions, subagentDialogOnScreen } from './sc
202
213
  export { blockVisible } from './screen/block-visible.js';
203
214
  export { SANDBOX_NETWORK_TOOL } from './screen/kinds.js';
204
215
  export { matchKnownDialog } from './screen/known.js';
216
+ export { startDialogOf } from './screen/start-dialog.js';
205
217
  export { sameDialogIdentity } from './screen/identity.js';
206
218
  export { SESSION_PAUSED_DIALOG, sessionPausedDialog } from './policy/pause.js';
207
219
  export { TERMINAL_DIALOG_IDS } from './policy/terminal.js';
@@ -84,6 +84,7 @@ import { DISK_LAYOUT } from '../../../commands/registry.js';
84
84
  import { parseElapsed } from '../../shadow/liveness.js';
85
85
  import { HOOK_PERMISSION_EVENT } from '../../../hook-commands.js';
86
86
  import { DIRECT_DISK } from '../../../../folder-gate/disk.js';
87
+ import { mainCheckoutOf, upwards } from '../../../../project-root.js';
87
88
  /** Zapas na rozdzielczość `etime` (pełne sekundy) i czas samego `ps`. */
88
89
  export const HOOK_LIST_START_SLACK_MS = 2_000;
89
90
  /** Rejestr CLI pisze `startedAt` 1–7 s po starcie procesu (`cli-version.ts`); zapas do 10 s. */
@@ -184,9 +185,6 @@ const MARKETPLACE_SOURCES = {
184
185
  directory: 'directory',
185
186
  file: 'file',
186
187
  };
187
- /** Linked worktree gita: plik `.git` z jedną linią `gitdir: <katalog>`, a w tym katalogu `commondir`. */
188
- const GIT_FILE_PREFIX = 'gitdir: ';
189
- const GIT_COMMONDIR = 'commondir';
190
188
  class HookListNoProof extends Error {
191
189
  }
192
190
  /**
@@ -532,18 +530,6 @@ class Reader {
532
530
  }
533
531
  }
534
532
  }
535
- /** Katalog i wszystkie wyżej, od niego do korzenia. */
536
- function upwards(dir) {
537
- const out = [];
538
- let current = path.resolve(dir);
539
- for (;;) {
540
- out.push(current);
541
- const parent = path.dirname(current);
542
- if (parent === current)
543
- return out;
544
- current = parent;
545
- }
546
- }
547
533
  /** The negative verdict of a read that threw. */
548
534
  function verdictOf(err) {
549
535
  if (err instanceof HookListNoProof)
@@ -681,7 +667,9 @@ async function readLayers(input, io, current) {
681
667
  const localDirs = new Set();
682
668
  for (const cwd of cwds) {
683
669
  const main = await mainCheckoutOf(reader, cwd);
684
- for (const root of main === null ? [cwd] : [cwd, main]) {
670
+ if (!main.ok)
671
+ throw new HookListNoProof(`worktree:${main.dotGit}`);
672
+ for (const root of main.root === null ? [cwd] : [cwd, main.root]) {
685
673
  projectDirs.add(path.resolve(root));
686
674
  for (const dir of upwards(root))
687
675
  localDirs.add(dir);
@@ -786,46 +774,6 @@ async function syncedTrees(io, reader, root) {
786
774
  }
787
775
  }
788
776
  }
789
- /**
790
- * Główny checkout dla `cwd` w linked worktree gita albo `null` (opis modułu; dokumentacja Claude Code: settings,
791
- * „Where Claude Code keeps the local file in a git repository”; worktrees, „What worktrees share with the main
792
- * checkout”). Najbliższy `.git` od `cwd` w górę: katalog = zwykły checkout (`null`); plik = jedna linia
793
- * `gitdir: <katalog>` (ścieżka bezwzględna albo względna wobec katalogu pliku), a w tym katalogu `commondir` ze
794
- * wspólnym katalogiem repozytorium; bez `commondir` to nie worktree (submoduł, `--separate-git-dir`), korzeniem jest
795
- * katalog z plikiem `.git`. Wspólny katalog musi się nazywać `.git`, główny checkout to katalog nad nim; repozytorium
796
- * bare, `gitdir` bez katalogu i każdy inny układ = brak dowodu. Odczyt bez uruchamiania `git`; pliki `.git` i
797
- * `commondir` przechodzą przez sprawdzenie startu, katalogi gita nie (zmieniają się przy każdej operacji gita),
798
- * dowiązania tak.
799
- */
800
- async function mainCheckoutOf(reader, cwd) {
801
- for (const dir of upwards(cwd)) {
802
- const dotGit = path.join(dir, DISK_LAYOUT.gitDir);
803
- const found = await reader.linked(dotGit);
804
- if (found.info === null)
805
- continue;
806
- if (found.info.kind === 'dir')
807
- return null;
808
- const lines = (await reader.text(dotGit) ?? '').split('\n').filter((line) => line.trim() !== '');
809
- const line = lines.length === 1 ? lines[0] ?? '' : '';
810
- const target = line.startsWith(GIT_FILE_PREFIX) ? line.slice(GIT_FILE_PREFIX.length).trim() : '';
811
- if (target === '')
812
- throw new HookListNoProof(`worktree:${dotGit}`);
813
- const gitDir = await reader.linked(path.isAbsolute(target) ? target : `${path.dirname(found.real)}/${target}`);
814
- if (gitDir.info?.kind !== 'dir')
815
- throw new HookListNoProof(`worktree:${dotGit}`);
816
- const common = (await reader.text(path.join(gitDir.real, GIT_COMMONDIR)))?.trim();
817
- if (common === undefined)
818
- return null;
819
- if (common === '' || common.includes('\n'))
820
- throw new HookListNoProof(`worktree:${dotGit}`);
821
- const commonDir = await reader.linked(path.isAbsolute(common) ? common : `${gitDir.real}/${common}`);
822
- if (commonDir.info?.kind !== 'dir' || path.basename(commonDir.real) !== DISK_LAYOUT.gitDir) {
823
- throw new HookListNoProof(`worktree:${dotGit}`);
824
- }
825
- return path.dirname(commonDir.real);
826
- }
827
- return null;
828
- }
829
777
  /** Ścieżka względna bez wyjścia w górę (`..`), bez ukośnika wstecznego. */
830
778
  const relativeInside = (rel) => !path.isAbsolute(rel) && !rel.includes('\\') && rel.split('/').every((part) => part !== '..');
831
779
  /**