@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
|
@@ -14,17 +14,23 @@ import { activitySchema } from './protocol/activity.js';
|
|
|
14
14
|
import { imageDataUrlSchema, messageAttachmentSchema } from './protocol/attachments.js';
|
|
15
15
|
import { backgroundTaskSchema, sessionArtifactSchema, sessionPullRequestSchema, sessionScheduledTaskSchema, } from './protocol/background.js';
|
|
16
16
|
import { consentAlwaysEntrySchema, SCREEN_UNAVAILABLE_REASONS, } from './protocol/consent.js';
|
|
17
|
+
import { REFUSE_REASONS, refuseReasonSchema, sessionDialogFieldsShape, } from './protocol/dialog-live.js';
|
|
17
18
|
import { gitCommitSchema, gitFileDetailSchema, gitFileKindsSchema, } from './protocol/git.js';
|
|
18
19
|
import { herdrModeSchema, herdrStatusEventSchema, herdrStatusSchema, } from './protocol/herdr.js';
|
|
19
20
|
import { inboxEventSchemas } from './protocol/inbox.js';
|
|
20
21
|
import { effortLevelSchema, modelIdSchema } from './protocol/model.js';
|
|
21
22
|
import { notesEventSchema } from './protocol/notes.js';
|
|
23
|
+
import { contextLimitStateSchema, sessionUsageSchema, } from './protocol/context.js';
|
|
22
24
|
import { folderAccessEventSchema } from './protocol/folders.js';
|
|
25
|
+
import { sessionCoordinationSchema } from './protocol/coordination.js';
|
|
23
26
|
export * from './protocol/activity.js';
|
|
24
27
|
export * from './protocol/attachments.js';
|
|
25
28
|
export * from './protocol/background.js';
|
|
26
29
|
export * from './protocol/commands.js';
|
|
27
30
|
export * from './protocol/consent.js';
|
|
31
|
+
export * from './protocol/context.js';
|
|
32
|
+
export * from './protocol/coordination.js';
|
|
33
|
+
export * from './protocol/dialog-live.js';
|
|
28
34
|
export * from './protocol/dictation.js';
|
|
29
35
|
export * from './protocol/diff.js';
|
|
30
36
|
export * from './protocol/directories.js';
|
|
@@ -35,6 +41,7 @@ export * from './protocol/herdr.js';
|
|
|
35
41
|
export * from './protocol/inbox.js';
|
|
36
42
|
export * from './protocol/model.js';
|
|
37
43
|
export * from './protocol/notes.js';
|
|
44
|
+
export * from './protocol/presence.js';
|
|
38
45
|
export * from './protocol/resume.js';
|
|
39
46
|
export * from './protocol/terminal.js';
|
|
40
47
|
/**
|
|
@@ -55,74 +62,9 @@ export * from './protocol/terminal.js';
|
|
|
55
62
|
* jako „Nie potwierdzono. [Ponów]" i zapraszała do wysłania jej drugi raz.
|
|
56
63
|
*/
|
|
57
64
|
export const PROTOCOL_VERSION = 3;
|
|
58
|
-
export const contextLimitStateSchema = z.discriminatedUnion('kind', [
|
|
59
|
-
z.object({ kind: z.literal('unknown'), tokens: z.number(), atLeast: z.number().optional() }),
|
|
60
|
-
z.object({
|
|
61
|
-
kind: z.literal('known'),
|
|
62
|
-
tokens: z.number(),
|
|
63
|
-
limit: z.number(),
|
|
64
|
-
source: z.enum(['compact-boundary', 'model', 'statusline']),
|
|
65
|
-
}),
|
|
66
|
-
]);
|
|
67
|
-
/**
|
|
68
|
-
* Okna kontekstu, które znamy na pewno — dla aliasów z flag Raroga (`fable`, `opus[1m]`, …) oraz
|
|
69
|
-
* dla pełnych identyfikatorów Fable ROZWIĄZANYCH z jsonl (follower potwierdza nimi limit sesji).
|
|
70
|
-
* `opus[1m]` = 1M (`contextWindow: 1000000` in `--output-format json`).
|
|
71
|
-
* The bare alias `opus` = 1M (Claude Code 2.1.280): `claude --model opus` resolves to
|
|
72
|
-
* `claude-opus-5-5` with `contextWindow: 1000000`, and `opus[1m]` to `claude-opus-5-5[1m]` with the
|
|
73
|
-
* SAME window — Opus 5.5 has 1M without a variant, like Fable 5.1. The full id `claude-opus-5-5`
|
|
74
|
-
* is in the table because a session on the account's default model (`opus`, no flag) gets its
|
|
75
|
-
* window only from jsonl and without this entry would stay `unknown`.
|
|
76
|
-
*
|
|
77
|
-
* The model list carries only the `fable` alias, yet the full Fable ids stay in this table on
|
|
78
|
-
* purpose: Rarog also reads sessions started outside it, and transcripts with these ids exist.
|
|
79
|
-
* Dropping an entry would not revoke the model — it would take the known window from those
|
|
80
|
-
* sessions and drop the context bar to `unknown`.
|
|
81
|
-
*
|
|
82
|
-
* Fable = 1M, measured on THIS account: the account has the `claude-fable-5[1m]` variant,
|
|
83
|
-
* transcripts carry window sums up to 885 852, manual compactions at `preTokens` 744 448,
|
|
84
|
-
* and herdr shows 14% exactly when the window sum is 148 704 (148 704 / 1M). A 200 000 limit
|
|
85
|
-
* would understate the window fivefold and raise the colour alarm at a third of the session.
|
|
86
|
-
*
|
|
87
|
-
* Sesja bez flagi `--model` na innym modelu niż fable startuje jako `unknown`: aliasy flag
|
|
88
|
-
* (`fable`/`sonnet`/`opus`/`haiku`) nigdy nie są identyfikatorem z jsonl, a wariantu `[1m]`
|
|
89
|
-
* modeli spoza rodziny Fable jsonl nie odróżnia. Alias `fable` = 1M, bo obie znane wersje
|
|
90
|
-
* (5 z pomiaru, 5.1 z dokumentacji) mają to samo okno.
|
|
91
|
-
*
|
|
92
|
-
* Fable 5.1 = 1M z dokumentacji API: 1M to dla `claude-fable-5-1` maksimum
|
|
93
|
-
* I domyślne okno zarazem, więc wariantu `[1m]` ten model nie ma i czysty identyfikator
|
|
94
|
-
* nie zaniża limitu tak, jak robił to `claude-fable-5` bez nawiasu.
|
|
95
|
-
*/
|
|
96
|
-
export const KNOWN_CONTEXT_LIMITS = {
|
|
97
|
-
fable: 1_000_000, 'opus[1m]': 1_000_000, opus: 1_000_000, sonnet: 200_000, haiku: 200_000,
|
|
98
|
-
'claude-fable-5': 1_000_000, 'claude-fable-5-1': 1_000_000, 'claude-opus-5-5': 1_000_000,
|
|
99
|
-
};
|
|
100
65
|
// ---------------------------------------------------------------------------
|
|
101
66
|
// Sesje herdr — jedyne źródło sesji
|
|
102
67
|
// ---------------------------------------------------------------------------
|
|
103
|
-
/**
|
|
104
|
-
* Dialogi spoza jsonl, które Rarog ROZUMIE na tyle, żeby wystawić przyciski.
|
|
105
|
-
*
|
|
106
|
-
* Lista jest ZAMKNIĘTA i jest odbiciem `KNOWN_DIALOGS` z `server/src/herdr/screen.ts` — nie
|
|
107
|
-
* rośnie „przy okazji". Dialog bez odpowiednika w jsonl to dokładnie ta sytuacja, w której
|
|
108
|
-
* Rarog nie wie, co zatwierdza (zgoda MCP, wyjście z trybu plan), więc wszystko spoza tej
|
|
109
|
-
* listy zostaje przy wycinku ekranu i „Odrzuć dialog" — bez przycisku zatwierdzania.
|
|
110
|
-
*/
|
|
111
|
-
export const KNOWN_DIALOG_IDS = ['trust', 'model'];
|
|
112
|
-
export const knownDialogIdSchema = z.enum(KNOWN_DIALOG_IDS);
|
|
113
|
-
/**
|
|
114
|
-
* Klasa dialogu, który rejestr sesji Claude Code zgłasza jako stojący.
|
|
115
|
-
*
|
|
116
|
-
* Serwer czyta ją z pola `waitingFor` pliku `~/.claude/sessions/<pid>.json` i tłumaczy dosłowne
|
|
117
|
-
* nazwy CLI (`permission prompt`, `input needed`, `sandbox request`…) na te krótkie, własne nazwy
|
|
118
|
-
* Raroga (`server/src/cli-version.ts`) — klient nazw CLI nie zna. `other` = dialog jest, tylko nie
|
|
119
|
-
* wiadomo jaki. Lista stoi w protokole, bo czytają ją obie strony: serwer (czytnik, driver,
|
|
120
|
-
* dziennik odmów) i klient (`SessionSummary.cliDialog`).
|
|
121
|
-
*/
|
|
122
|
-
export const CLI_DIALOG_CLASSES = [
|
|
123
|
-
'permission', 'input', 'sandbox', 'worker', 'dialog', 'goal', 'other',
|
|
124
|
-
];
|
|
125
|
-
export const cliDialogClassSchema = z.enum(CLI_DIALOG_CLASSES);
|
|
126
68
|
/**
|
|
127
69
|
* Twardy limit tekstu wysyłanego do PANELU herdr (`agent.prompt`).
|
|
128
70
|
*
|
|
@@ -151,10 +93,6 @@ export const MAX_HERDR_PROMPT_BYTES = 512 * 1024;
|
|
|
151
93
|
* Historia po restarcie serwera zwykle i tak nie dobija do sufitu — tnie ją `HISTORY_MAX_BYTES`.
|
|
152
94
|
*/
|
|
153
95
|
export const MAX_TRANSCRIPT_MESSAGES = 500;
|
|
154
|
-
const _contextLimitSchemaMatchesType = true;
|
|
155
|
-
const _contextLimitTypeMatchesSchema = true;
|
|
156
|
-
void _contextLimitSchemaMatchesType;
|
|
157
|
-
void _contextLimitTypeMatchesSchema;
|
|
158
96
|
/**
|
|
159
97
|
* Kanał zgód (warstwa 1): karta, na którą odpowiada się podpisanym plikiem dla śpiącego hooka
|
|
160
98
|
* `PermissionRequest`, a nie klawiszem do panelu. Dziś jedyna wartość; brak pola = karta ekranowa.
|
|
@@ -201,34 +139,6 @@ export const EXIT_PLAN_MODE_TOOL = 'ExitPlanMode';
|
|
|
201
139
|
* (`shortenPaths`) — a wtedy z linii zostaje sam prefiks `/Users/…`, czyli nic.
|
|
202
140
|
*/
|
|
203
141
|
export const WAITING_TEXT_MAX = 120;
|
|
204
|
-
/**
|
|
205
|
-
* Powody, dla których decyzja z telefonu NIE wyszła do panelu — ZAMKNIĘTA lista.
|
|
206
|
-
*
|
|
207
|
-
* Jedna unia obsługuje trzy rzeczy naraz i to jest cały powód, dla którego mieszka
|
|
208
|
-
* w protokole, a nie po stronie serwera: kontrakt drivera (`DecisionOutcome`), dziennik
|
|
209
|
-
* audytu (`method: "refuse"` — wpisy mają się SUMOWAĆ, `summarizeRefusals` serwera)
|
|
210
|
-
* i ciało odpowiedzi 422 czytane przez klienta. Dwie równoległe listy rozjechałyby się przy
|
|
211
|
-
* pierwszym nowym powodzie, a wtedy licznik odmów przestałby odpowiadać na pytanie
|
|
212
|
-
* „czy ścieżka cyfrowa realnie zawodzi".
|
|
213
|
-
*
|
|
214
|
-
* Powody dzielą się na trzy grupy i tylko dwie ostatnie wracają kodem 422:
|
|
215
|
-
* - **ocena karty** (`mismatch`, `unreadable`, `no-jsonl`) — Rarog nie umiał złożyć karty
|
|
216
|
-
* z przyciskami; nikt jeszcze o nic nie prosił, więc nie ma żądania, na które odpowiedzieć;
|
|
217
|
-
* - **decyzja** (`multi-select` … `send-failed`) — człowiek tapnął, a klawisz nie wyszedł;
|
|
218
|
-
* - **blokada** (`in-flight`) — powstaje w MANAGERZE, nie w driverze: decyzja o tej karcie
|
|
219
|
-
* właśnie leci z drugiego urządzenia. Do dziennika audytu nie trafia nigdy (`auditRefusal`
|
|
220
|
-
* woła wyłącznie driver), więc obietnicy „wpisy się SUMUJĄ" nie narusza.
|
|
221
|
-
*
|
|
222
|
-
* Lista stoi PRZED sekcją schematów, bo `sessionSummarySchema.herdrDialogReason` jej używa,
|
|
223
|
-
* a `z.enum` czyta stałą w chwili budowy schematu.
|
|
224
|
-
*/
|
|
225
|
-
export const REFUSE_REASONS = [
|
|
226
|
-
'mismatch', 'unreadable', 'no-jsonl', 'multi-select', 'no-digit', 'terminal-only',
|
|
227
|
-
'screen-changed', 'stale-card', 'form-submit', 'send-failed', 'in-flight',
|
|
228
|
-
/** Dialog ZGODY CLI (np. „Teach auto mode…") stoi w panelu, choć herdr widzi `idle`. */
|
|
229
|
-
'consent-dialog',
|
|
230
|
-
];
|
|
231
|
-
export const refuseReasonSchema = z.enum(REFUSE_REASONS);
|
|
232
142
|
// ---------------------------------------------------------------------------
|
|
233
143
|
// Schematy zod — bloki domenowe
|
|
234
144
|
// ---------------------------------------------------------------------------
|
|
@@ -237,10 +147,6 @@ export const sessionStateSchema = z.enum([
|
|
|
237
147
|
'limit-reached', 'error', 'interrupted', 'done', 'resumable',
|
|
238
148
|
]);
|
|
239
149
|
export const riskSchema = z.enum(['normal', 'red']);
|
|
240
|
-
export const sessionUsageSchema = z.object({
|
|
241
|
-
contextTokens: z.number(),
|
|
242
|
-
contextLimit: z.number(),
|
|
243
|
-
});
|
|
244
150
|
/*
|
|
245
151
|
* Stands BEFORE `sessionSummarySchema`, which uses it: a module `const` does not hoist like a function, so the
|
|
246
152
|
* reverse order is a TDZ error at module load.
|
|
@@ -321,17 +227,15 @@ export const sessionSummarySchema = z.object({
|
|
|
321
227
|
seen: z.boolean().optional(),
|
|
322
228
|
markedUnseen: z.literal(true).optional(),
|
|
323
229
|
seenBy: z.literal('voice-agent').optional(),
|
|
230
|
+
ownerTurn: z.literal(true).optional(),
|
|
324
231
|
stale: z.boolean().optional(),
|
|
325
232
|
herdrMode: herdrModeSchema.optional(),
|
|
326
|
-
|
|
327
|
-
herdrDialogReason: refuseReasonSchema.optional(),
|
|
328
|
-
herdrDialogScreen: z.string().optional(),
|
|
329
|
-
cliDialog: cliDialogClassSchema.optional(),
|
|
233
|
+
...sessionDialogFieldsShape,
|
|
330
234
|
outOfScope: z.boolean().optional(),
|
|
331
235
|
// Oba pola ADDYTYWNE i opcjonalne — brak `engine` znaczy „Claude", brak `termId`
|
|
332
236
|
// znaczy „nie ma dokąd wejść". `z.object` odcina nieznane klucze, więc bez tych dwóch linii
|
|
333
237
|
// serwer mógłby je wysyłać, a klient parsujący tym schematem i tak by ich nie zobaczył.
|
|
334
|
-
engine: z.
|
|
238
|
+
engine: z.enum(['codex', 'agy']).optional(),
|
|
335
239
|
termId: z.string().optional(),
|
|
336
240
|
activity: activitySchema.optional(),
|
|
337
241
|
backgroundTasks: z.array(backgroundTaskSchema).optional(),
|
|
@@ -343,6 +247,8 @@ export const sessionSummarySchema = z.object({
|
|
|
343
247
|
waitingFor: waitingForSchema.optional(),
|
|
344
248
|
cliUpdate: cliUpdateSchema.optional(),
|
|
345
249
|
promptBlocked: sessionPromptBlockedSchema.optional(),
|
|
250
|
+
projectRoot: z.string().min(1).optional(),
|
|
251
|
+
coordination: sessionCoordinationSchema.optional(),
|
|
346
252
|
});
|
|
347
253
|
/** Blok `tool-call` bez reguły `truncation` — baza dla `blockSchema` i widoku tolerancyjnego dekodera. */
|
|
348
254
|
export const toolCallBlockObjectSchema = z.object({
|
|
@@ -655,6 +561,8 @@ export const createSessionBodySchema = z.object({
|
|
|
655
561
|
fork: z.boolean().optional(),
|
|
656
562
|
ultracode: z.literal(true, { error: 'ultracode w ciele startu tylko jako true; brak pola = bez flagi.' })
|
|
657
563
|
.optional(),
|
|
564
|
+
/** The project's coordinator (`docs/coordinator.md`): `true` or no field, like `ultracode`. */
|
|
565
|
+
coordinator: z.literal(true).optional(),
|
|
658
566
|
}).refine((body) => body.fork !== true || body.resumeFrom !== undefined, {
|
|
659
567
|
message: 'Rozwidlenie wymaga podania sesji do wznowienia (`resumeFrom`).',
|
|
660
568
|
}).refine((body) => body.ultracode !== true || body.effort === undefined || body.effort === 'xhigh', {
|
|
@@ -791,46 +699,6 @@ export const clientLogBodySchema = z.object({
|
|
|
791
699
|
msg: z.string(),
|
|
792
700
|
})),
|
|
793
701
|
});
|
|
794
|
-
/**
|
|
795
|
-
* Beacon obecności (`POST /api/presence`) — jedyny kanał, którym klient mówi serwerowi
|
|
796
|
-
* „patrzę" albo „już nie patrzę".
|
|
797
|
-
*
|
|
798
|
-
* Istnieje, bo obecności NIE DA SIĘ wywnioskować z otwartego strumienia SSE: iOS usypia apkę
|
|
799
|
-
* w tle, a gniazdo potrafi jeszcze chwilę wisieć. Serwer widziałby wtedy „klient jest" przy
|
|
800
|
-
* zgaszonym ekranie i wysyłał powiadomienia dokładnie wtedy, gdy nie miał prawa — czyli
|
|
801
|
-
* powtórzyłby błąd hooków, tylko z innego powodu.
|
|
802
|
-
*
|
|
803
|
-
* Klient odpowiada na heartbeat SSE, DOPÓKI jest widoczny, i zgłasza zmianę od razu przy
|
|
804
|
-
* `visibilitychange`. Koszt: jedno małe żądanie na 25 s przy otwartej apce, ZERO w tle.
|
|
805
|
-
*/
|
|
806
|
-
/**
|
|
807
|
-
* Po tylu ms bez potwierdzenia serwer przestaje uważać klienta za obecnego.
|
|
808
|
-
*
|
|
809
|
-
* Stała mieszka w protokole, bo jest KONTRAKTEM między dwiema stronami, a nie szczegółem
|
|
810
|
-
* którejś z nich: serwer po niej wygasza obecność, a klient musi odświeżać się wyraźnie
|
|
811
|
-
* CZĘŚCIEJ — jedno zgubione żądanie na kiepskim LTE nie ma prawa zamienić patrzącego
|
|
812
|
-
* człowieka w nieobecnego i wypchnąć powiadomienia, którego nikt nie chciał.
|
|
813
|
-
*
|
|
814
|
-
* 40 s covers two presence beacons of the native app (every 20 s), so one lost request is tolerated.
|
|
815
|
-
*/
|
|
816
|
-
export const PRESENCE_TTL_MS = 40_000;
|
|
817
|
-
export const presenceBodySchema = z.object({
|
|
818
|
-
/**
|
|
819
|
-
* Identyfikator KARTY, nie użytkownika — losowany przy starcie skryptu i żyjący tyle, co
|
|
820
|
-
* dokument. Serwer używa go wyłącznie do odróżnienia dwóch urządzeń (telefon i iPad mogą
|
|
821
|
-
* patrzeć naraz) i nie wiąże go z niczym trwałym.
|
|
822
|
-
*/
|
|
823
|
-
clientId: z.string().min(1).max(64),
|
|
824
|
-
/** `document.visibilityState !== 'hidden'`. */
|
|
825
|
-
visible: z.boolean(),
|
|
826
|
-
/**
|
|
827
|
-
* Sesja, której TRANSKRYPT jest otwarty. Brak = lista, ustawienia, terminal.
|
|
828
|
-
*
|
|
829
|
-
* Osobna informacja od `visible` i o czym innym: `visible` gasi push (patrzysz w Raroga
|
|
830
|
-
* gdziekolwiek), a to pole gasi sygnał o sesji, na którą i tak patrzysz.
|
|
831
|
-
*/
|
|
832
|
-
sessionId: z.string().min(1).max(128).optional(),
|
|
833
|
-
});
|
|
834
702
|
/**
|
|
835
703
|
* Etykieta urządzenia w rejestracji APNs (`apnsRegisterBodySchema` w `rest.ts`) — wejście
|
|
836
704
|
* z telefonu; serwer i tak ją sanityzuje przed zapisem (`sanitizeLabel` w `apns-devices.ts`).
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
import { z } from 'zod';
|
|
21
21
|
import { IROH_ENDPOINT_ID_RE, PAIRING_CODE_RE, irohRelayUrl } from './pairing-link.js';
|
|
22
22
|
import { sentenceRefSchema } from './sentences/index.js';
|
|
23
|
-
import { FILE_ENTRY_KINDS, FILE_TOO_LARGE_ERROR, MAX_ANSWER_TEXT_CHARS, MAX_FILES_PER_MESSAGE, MAX_IMAGES_PER_MESSAGE, MAX_MESSAGE_TEXT_CHARS, PUSH_LABEL_MAX_CHARS, TERM_ID_RE, fileAttachmentSchema, imageDataUrlSchema, inboxHeadSchemaOf, knownDialogIdSchema, refuseReasonSchema, sessionStateSchema, sessionSummarySchema, termListResponseSchema, transcriptMessageSchema, waitingForSchema, } from './protocol.js';
|
|
23
|
+
import { FILE_ENTRY_KINDS, FILE_TOO_LARGE_ERROR, MAX_ANSWER_TEXT_CHARS, MAX_FILES_PER_MESSAGE, MAX_IMAGES_PER_MESSAGE, MAX_MESSAGE_TEXT_CHARS, PUSH_LABEL_MAX_CHARS, TERM_ID_RE, diffFileListSchema, fileAttachmentSchema, gitCommitSchema, imageDataUrlSchema, inboxHeadSchemaOf, knownDialogIdSchema, refuseReasonSchema, sessionStateSchema, sessionSummarySchema, termListResponseSchema, transcriptMessageSchema, waitingForSchema, } from './protocol.js';
|
|
24
24
|
/*
|
|
25
25
|
* REST terminala dla apki natywnej: schematy istnieją w `protocol.ts`, tu tylko re-eksport — jedno miejsce
|
|
26
26
|
* kontraktu REST dla klienta w innym języku, zero kopii.
|
|
@@ -808,6 +808,21 @@ export const COMPANION_SPEECH_THROTTLED_ERROR = 'companion-speech-throttled';
|
|
|
808
808
|
/** 502: Soniox did not give a key (5xx, timeout, no connection, a reply without a key). */
|
|
809
809
|
export const COMPANION_SPEECH_UPSTREAM_ERROR = 'companion-speech-upstream';
|
|
810
810
|
// ---------------------------------------------------------------------------
|
|
811
|
+
// Branch diff of a coordinator's thread (`docs/coordinator.md`, "Protocol contract")
|
|
812
|
+
// ---------------------------------------------------------------------------
|
|
813
|
+
/**
|
|
814
|
+
* 200 of `GET /api/sessions/:id/branch-diff/files`: what the thread's branch changes, in the shape of `diff/files`,
|
|
815
|
+
* compared from its merge base with `base.branch` (the branch of the project's main checkout, chosen by the server);
|
|
816
|
+
* `commits` are the branch commits past that base, newest first, and `head` the full SHA of the branch head the list
|
|
817
|
+
* shows. The patch of one file comes from `GET /api/sessions/:id/branch-diff/file?path=…` as a `DiffFilePatch`, and
|
|
818
|
+
* both routes refuse with the error codes of the session diff routes.
|
|
819
|
+
*/
|
|
820
|
+
export const branchDiffFileListSchema = diffFileListSchema.extend({
|
|
821
|
+
commits: z.array(gitCommitSchema),
|
|
822
|
+
base: z.object({ branch: z.string().min(1) }),
|
|
823
|
+
head: z.string().regex(/^[0-9a-f]{40}$/u),
|
|
824
|
+
});
|
|
825
|
+
// ---------------------------------------------------------------------------
|
|
811
826
|
// Inbox: the cards with their text (`docs/implementation-spec.md`, "Inbox")
|
|
812
827
|
// ---------------------------------------------------------------------------
|
|
813
828
|
/**
|
|
@@ -88,6 +88,16 @@ export const DIALOGS_SENTENCES = {
|
|
|
88
88
|
'dialogs.stale-decision': {
|
|
89
89
|
en: "⚠ The answer didn't go through: the dialog in the terminal changed in the meantime. Tap again on the new card. Rarog sent no key.",
|
|
90
90
|
},
|
|
91
|
+
'dialogs.start-dialog.imports': {
|
|
92
|
+
en: 'Claude Code asks in the terminal whether to allow external imports in the instruction files of this project. ' +
|
|
93
|
+
'Answer it in the terminal: Claude Code keeps the answer for this project for good. Rarog sends no key to it.',
|
|
94
|
+
},
|
|
95
|
+
'dialogs.start-dialog.refused': {
|
|
96
|
+
en: '⚠ A Claude Code start dialog stands in the terminal. Rarog sent no key and no text. Answer it in the terminal.',
|
|
97
|
+
},
|
|
98
|
+
'dialogs.start-dialog.unknown': {
|
|
99
|
+
en: "Claude Code stands on a start dialog Rarog doesn't know. Answer it in the terminal; Rarog sends no key to it.",
|
|
100
|
+
},
|
|
91
101
|
'dialogs.submit-abort.not-a-form': { en: 'the screen no longer shows a question form' },
|
|
92
102
|
'dialogs.submit-abort.notes-editing': {
|
|
93
103
|
en: 'the form is in note-editing mode (the digit may have been typed as text; check the field)',
|
|
@@ -12,6 +12,13 @@ export const PUSH_SENTENCES = {
|
|
|
12
12
|
'push.body.fallback.limit': { en: 'Open to see when to try again.' },
|
|
13
13
|
'push.body.fallback.permission': { en: 'Open to decide.' },
|
|
14
14
|
'push.body.fallback.question': { en: 'The agent asked a question. Answer in Rarog.' },
|
|
15
|
+
'push.body.fallback.stalled': { en: 'A subagent is waiting on its own command.' },
|
|
16
|
+
'push.body.fallback.ready-to-merge': { en: 'Checks passed. Open to merge.' },
|
|
17
|
+
'push.detail.merge-ready': {
|
|
18
|
+
en: { one: '{commits} commit, checks passed', other: '{commits} commits, checks passed' },
|
|
19
|
+
args: ['commits:plural'],
|
|
20
|
+
},
|
|
21
|
+
'push.detail.stalled': { en: 'Subagent "{agent}" is waiting on its own command.', args: ['agent:text'] },
|
|
15
22
|
'push.body.label': { en: '{label}', args: ['label:text'] },
|
|
16
23
|
'push.paired-body.mac': {
|
|
17
24
|
en: "{label}. If this wasn't you, revoke it on the Mac: rarog devices",
|
|
@@ -30,6 +37,8 @@ export const PUSH_SENTENCES = {
|
|
|
30
37
|
'push.title.limit': { en: '✋ Plan limit · {project}', args: ['project:text'] },
|
|
31
38
|
'push.title.permission': { en: '⏳ Waiting for permission · {project}', args: ['project:text'] },
|
|
32
39
|
'push.title.question': { en: '❓ Question · {project}', args: ['project:text'] },
|
|
40
|
+
'push.title.ready-to-merge': { en: '🔀 Ready to merge · {project}', args: ['project:text'] },
|
|
41
|
+
'push.title.stalled': { en: '⏰ Waiting over 1 h · {project}', args: ['project:text'] },
|
|
33
42
|
'push.version-title': { en: '🔄 Version changed' },
|
|
34
43
|
'push.version-body.claude-code': { en: 'Claude Code {from} → {to}', args: ['from:text', 'to:text'] },
|
|
35
44
|
'push.version-body.herdr': { en: 'herdr {from} → {to}', args: ['from:text', 'to:text'] },
|
|
@@ -18,6 +18,12 @@ export const REST_SENTENCES = {
|
|
|
18
18
|
'rest.bad-origin': { en: 'Request from a disallowed origin.' },
|
|
19
19
|
'rest.body-contract': { en: "The request body doesn't match the expected format." },
|
|
20
20
|
'rest.body-unreadable': { en: "Couldn't read the request." },
|
|
21
|
+
'rest.branch-diff-no-base': {
|
|
22
|
+
en: "The project's main folder isn't on a branch, or this branch has no commit in common with it.",
|
|
23
|
+
},
|
|
24
|
+
'rest.branch-diff-no-project': {
|
|
25
|
+
en: "This session isn't in a worktree of a project, so it has no branch changes.",
|
|
26
|
+
},
|
|
21
27
|
'rest.client-log-failed': { en: "Couldn't save the log." },
|
|
22
28
|
'rest.companion-busy': { en: 'The voice agent is already checking this session. Try again in a moment.' },
|
|
23
29
|
'rest.companion-claude-only': {
|
|
@@ -97,6 +103,9 @@ export const REST_SENTENCES = {
|
|
|
97
103
|
en: 'This file has {size} MB. The server sends files up to {limit} MB (RAROG_FILES_MAX_MB).',
|
|
98
104
|
args: ['size:int', 'limit:int'],
|
|
99
105
|
},
|
|
106
|
+
'rest.files-agy': {
|
|
107
|
+
en: "Rarog only observes the Antigravity CLI pane, so it doesn't show the files in its directory.",
|
|
108
|
+
},
|
|
100
109
|
'rest.files-codex': { en: "Rarog only observes the Codex pane, so it doesn't show the files in its directory." },
|
|
101
110
|
'rest.files-no-pane': { en: "This session has no herdr pane, so Rarog doesn't show the files in its directory." },
|
|
102
111
|
'rest.files-not-found': { en: "That file or directory isn't there, or Rarog doesn't show it." },
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export const RESTART_SENTENCES = {
|
|
2
|
+
'restart.agy': { en: "Restart the Antigravity CLI pane in herdr. Rarog shows its state but doesn't manage it." },
|
|
2
3
|
'restart.background-task-running': { en: 'A background task is running. A restart would interrupt it.' },
|
|
3
4
|
'restart.busy': { en: 'The session is working or waiting for a decision. You can restart it once it stops.' },
|
|
4
5
|
'restart.codex': { en: "Restart the Codex pane in herdr. Rarog shows its state but doesn't manage it." },
|
|
@@ -20,6 +20,12 @@ export const SESSION_SENTENCES = {
|
|
|
20
20
|
en: { one: 'The answer is too long. Keep it within {max} character.', other: 'The answer is too long. Keep it within {max} characters.' },
|
|
21
21
|
args: ['max:plural'],
|
|
22
22
|
},
|
|
23
|
+
'session.agy-close': {
|
|
24
|
+
en: "Close the Antigravity CLI pane in herdr. Rarog shows its state but doesn't manage it.",
|
|
25
|
+
},
|
|
26
|
+
'session.agy-git': {
|
|
27
|
+
en: 'Rarog only observes the Antigravity CLI pane. Manage git in this project from the terminal or from herdr.',
|
|
28
|
+
},
|
|
23
29
|
'session.bypass-outside-yolo-roots': {
|
|
24
30
|
en: 'bypassPermissions mode is allowed only in directories under RAROG_YOLO_ROOTS.',
|
|
25
31
|
},
|
|
@@ -39,6 +45,24 @@ export const SESSION_SENTENCES = {
|
|
|
39
45
|
'session.conversation-changed': {
|
|
40
46
|
en: 'The session moved to another conversation after the voice agent read it. Nothing was sent.',
|
|
41
47
|
},
|
|
48
|
+
// Refusals of a Launch with the coordinator switch and of a coordinator resume (`sessions/coordinator-start.ts`).
|
|
49
|
+
'session.coordinator-live': {
|
|
50
|
+
en: 'This project already has a coordinator. Switch to it, or close it before starting a new one.',
|
|
51
|
+
},
|
|
52
|
+
'session.coordinator-starting': {
|
|
53
|
+
en: 'A coordinator of this project is starting. Wait until it is ready, then try again.',
|
|
54
|
+
},
|
|
55
|
+
'session.coordinator-not-project': {
|
|
56
|
+
en: "A coordinator starts in the top folder of a project's main git checkout, and {cwd} isn't one.",
|
|
57
|
+
args: ['cwd:text'],
|
|
58
|
+
},
|
|
59
|
+
'session.coordinator-plugin-missing': {
|
|
60
|
+
en: "Rarog couldn't prepare the coordinator plugin ({reason}), so no coordinator started. The server log has the details.",
|
|
61
|
+
args: ['reason:text'],
|
|
62
|
+
},
|
|
63
|
+
'session.coordinator-plugin-path': {
|
|
64
|
+
en: "The coordinator plugin's folder in the server's data directory has a space or a shell character in its path, so Claude Code can't load it. No coordinator started.",
|
|
65
|
+
},
|
|
42
66
|
'session.cwd-denied': { en: "The directory {cwd} isn't allowed. {reason}", args: ['cwd:text', 'reason:code'] },
|
|
43
67
|
'session.cwd-denied.outside-roots': {
|
|
44
68
|
en: "The directory {cwd} isn't allowed. This directory is outside the allowed projects ({roots}).",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rarog/server",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2-beta.2",
|
|
4
4
|
"description": "Rarog is a free, open-source (MIT) iPhone and iPad app, plus a server on your Mac or Linux machine, that shows the Claude Code sessions running in Herdr TUI and lets you drive them.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude-code",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@number0/iroh": "1.2.0",
|
|
37
|
-
"@rarog/shared": "1.1.
|
|
37
|
+
"@rarog/shared": "1.1.2-beta.2",
|
|
38
38
|
"qrcode": "1.5.4",
|
|
39
39
|
"ws": "8.21.3",
|
|
40
40
|
"zod": "4.4.3"
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Entry point of the coordinator plugin. Claude Code 2.1.332 puts this bin/ directory on the Bash tool's PATH while
|
|
3
|
+
# the plugin is loaded (claude --plugin-dir), so a conversation resumed without the plugin has no rarog-coordinator.
|
|
4
|
+
# Every action that changes git, herdr or thread files goes through lib/coordinator.mjs.
|
|
5
|
+
set -euo pipefail
|
|
6
|
+
here="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
|
|
7
|
+
exec node "${here}/../lib/coordinator.mjs" "$@"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"hooks": {
|
|
3
|
+
"PreToolUse": [
|
|
4
|
+
{
|
|
5
|
+
"matcher": "SendMessage",
|
|
6
|
+
"hooks": [
|
|
7
|
+
{
|
|
8
|
+
"type": "command",
|
|
9
|
+
"command": "node",
|
|
10
|
+
"args": ["${CLAUDE_PLUGIN_ROOT}/hooks/recipient.mjs"],
|
|
11
|
+
"timeout": 30,
|
|
12
|
+
"onFailure": "block"
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// PreToolUse hook on SendMessage of the coordinator plugin. A message goes through only when the sender is the
|
|
2
|
+
// coordinator (the conversation in the marker .rarog/coordinator.md, in the process whose socket the marker names)
|
|
3
|
+
// and the recipient is an open thread of this project: a thread file without `merged` whose Claude Code process
|
|
4
|
+
// runs.
|
|
5
|
+
// Accepted forms of `to`: "[A] <name>" and "uds:<socket dir>/<pid>.sock", the socket of the thread's process in the
|
|
6
|
+
// sender's own socket directory. "[A] <name> [ref]" is refused: the ref names a process, not a thread, and may
|
|
7
|
+
// belong to a session of another project; with two sessions of one name the coordinator uses the uds: address from
|
|
8
|
+
// `rarog-coordinator status`. Everything else, and every error, is a deny. An exception that escapes exits non-zero,
|
|
9
|
+
// and hooks.json sets onFailure "block", so a crash or a timeout blocks the call as well.
|
|
10
|
+
import fs from 'node:fs';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import {
|
|
13
|
+
THREAD_PREFIX, projectPaths, pathProblem, readThreads, readMarker, processTable, sessionPids, commandHasSession,
|
|
14
|
+
socketAddress, socketDir,
|
|
15
|
+
} from '../lib/threads.mjs';
|
|
16
|
+
|
|
17
|
+
const isObject = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
18
|
+
|
|
19
|
+
/** Returns null to let the call through, or the reason of the deny. */
|
|
20
|
+
function verdict(input) {
|
|
21
|
+
if (!isObject(input)) return 'the hook input is not a JSON object';
|
|
22
|
+
if (input.tool_name !== 'SendMessage') return `the hook input is for ${JSON.stringify(input.tool_name)}, not SendMessage`;
|
|
23
|
+
if (!isObject(input.tool_input)) return 'the hook input has no tool_input';
|
|
24
|
+
const to = input.tool_input.to;
|
|
25
|
+
if (typeof to !== 'string' || !to.trim()) return 'the message has no recipient';
|
|
26
|
+
const cwd = input.cwd;
|
|
27
|
+
if (typeof cwd !== 'string' || !path.isAbsolute(cwd)) return 'the hook input has no absolute cwd';
|
|
28
|
+
const sender = process.env.CLAUDE_CODE_MESSAGING_SOCKET ?? '';
|
|
29
|
+
if (!path.isAbsolute(sender)) return 'CLAUDE_CODE_MESSAGING_SOCKET is missing in the hook environment';
|
|
30
|
+
let paths;
|
|
31
|
+
try {
|
|
32
|
+
paths = projectPaths(cwd);
|
|
33
|
+
} catch {
|
|
34
|
+
return `${cwd} is not inside a git repository with a main checkout`;
|
|
35
|
+
}
|
|
36
|
+
if (!fs.existsSync(paths.data)) return `there is no coordinator in this project (${paths.data} is missing)`;
|
|
37
|
+
const problem = pathProblem(paths.main, paths.threads);
|
|
38
|
+
if (problem) return `the coordinator directory is unsafe: ${problem}`;
|
|
39
|
+
const marker = readMarker(paths.data);
|
|
40
|
+
if (!marker) return 'there is no coordinator yet; the owner types /rarog:coordinator first';
|
|
41
|
+
if (marker.error) return `the coordinator marker is damaged (${marker.error})`;
|
|
42
|
+
if (marker.marker.conversation !== input.session_id) {
|
|
43
|
+
return 'this conversation is not the coordinator (a copy); it does not message threads';
|
|
44
|
+
}
|
|
45
|
+
if (marker.marker.socket !== sender) {
|
|
46
|
+
return `not the coordinator process: the marker names the socket ${marker.marker.socket}, this process has ${sender}; `
|
|
47
|
+
+ 'after a resume run `rarog-coordinator claim` (it records this process), then send again';
|
|
48
|
+
}
|
|
49
|
+
const { threads, errors } = readThreads(paths.threads, paths.main);
|
|
50
|
+
if (errors.length) return `damaged thread files: ${errors.join('; ')}`;
|
|
51
|
+
const procs = processTable();
|
|
52
|
+
const open = threads.filter((t) => !t.merged).map((t) => ({ t, pids: sessionPids(procs, t.session) }));
|
|
53
|
+
if (to.startsWith('uds:')) {
|
|
54
|
+
const socket = to.slice('uds:'.length);
|
|
55
|
+
const match = /^(\d+)\.sock$/.exec(path.basename(socket));
|
|
56
|
+
let isSocket = false;
|
|
57
|
+
try {
|
|
58
|
+
isSocket = fs.lstatSync(socket).isSocket();
|
|
59
|
+
} catch {
|
|
60
|
+
// no such file
|
|
61
|
+
}
|
|
62
|
+
const exact = match && socket === path.join(socketDir(), match[0]);
|
|
63
|
+
const proc = match ? procs.find((p) => p.pid === Number(match[1])) : null;
|
|
64
|
+
if (exact && isSocket && proc && open.some(({ t }) => commandHasSession(proc.command, t.session))) return null;
|
|
65
|
+
} else if (/^\[A\] .+ \[[0-9a-f]{4,16}\]$/.test(to)) {
|
|
66
|
+
return `"${to}": the form "[A] <name> [ref]" is not accepted, because the ref may name a session of another `
|
|
67
|
+
+ 'project; write "[A] <name>", or, when two sessions share the name, the thread\'s uds: address from '
|
|
68
|
+
+ '`rarog-coordinator status`';
|
|
69
|
+
} else {
|
|
70
|
+
const named = /^\[A\] (.+)$/.exec(to);
|
|
71
|
+
if (named && open.some(({ t, pids }) => t.name === named[1] && pids.length)) return null;
|
|
72
|
+
}
|
|
73
|
+
const reachable = open.filter(({ pids }) => pids.length).map(({ t, pids }) => {
|
|
74
|
+
const address = socketAddress(pids[0]);
|
|
75
|
+
return `"${THREAD_PREFIX}${t.name}"${address ? ` (${address})` : ''}`;
|
|
76
|
+
});
|
|
77
|
+
return `"${to}" is not an open thread of ${paths.main} with a running session; `
|
|
78
|
+
+ `open threads: ${reachable.join(', ') || 'none'}`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
let reason;
|
|
82
|
+
try {
|
|
83
|
+
reason = verdict(JSON.parse(fs.readFileSync(0, 'utf8')));
|
|
84
|
+
} catch (error) {
|
|
85
|
+
reason = `the recipient check failed (${error.message})`;
|
|
86
|
+
}
|
|
87
|
+
if (reason) {
|
|
88
|
+
process.stdout.write(`${JSON.stringify({
|
|
89
|
+
hookSpecificOutput: {
|
|
90
|
+
hookEventName: 'PreToolUse',
|
|
91
|
+
permissionDecision: 'deny',
|
|
92
|
+
permissionDecisionReason: `rarog coordinator: ${reason}`,
|
|
93
|
+
},
|
|
94
|
+
})}\n`);
|
|
95
|
+
}
|