@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
@@ -0,0 +1,194 @@
1
+ /**
2
+ * Branch diff of a coordinator's thread: the files and commits its branch adds past the merge base with the branch of
3
+ * the project's main checkout, and one file's patch, read between two commits pinned once per request (boundary:
4
+ * `docs/security-model.md`, "Git reads"). Collectors only: the session gate, the routes and the log line live
5
+ * elsewhere, and nothing here reads the working tree.
6
+ */
7
+ import { DIFF_BAD_PATH_ERROR, DIFF_FILE_NOT_FOUND_ERROR, DIFF_GIT_FAILED_ERROR } from '@rarog/shared';
8
+ import { DiffError, MAX_DIFF_FILE_PATCH_BYTES, MAX_DIFF_LIST_FILES, parseNameStatusZ, validateDiffPath, } from './git-diff.js';
9
+ import { GIT_LOG_FORMAT, NO_EXT_DIFF, RELATIVE, clampPatch, parseGitLog, parseNumstatZ } from './git-status.js';
10
+ /** Most commits a list carries, the newest ones; the list of files has its own cap (`MAX_DIFF_LIST_FILES`). */
11
+ export const MAX_BRANCH_DIFF_COMMITS = 500;
12
+ const BRANCH_REF = 'refs/heads/';
13
+ const FULL_SHA = /^[0-9a-f]{40}$/u;
14
+ const NO_PROJECT_ROOT = { ok: false, refusal: 'no-project-root' };
15
+ const NO_BASE = { ok: false, refusal: 'no-base' };
16
+ /** Run in the main checkout: the full name of the branch `HEAD` is on, or `HEAD` when it is detached. */
17
+ function baseBranchArgs() {
18
+ return { sub: 'rev-parse', rest: ['--symbolic-full-name', 'HEAD'] };
19
+ }
20
+ /**
21
+ * Run in the session directory: its head, then for `<base>...HEAD` the two tips and every merge base with a leading
22
+ * `^`. No such line means the two share no commit.
23
+ */
24
+ function rangeArgs(baseRef) {
25
+ return { sub: 'rev-parse', rest: ['HEAD^{commit}', `${baseRef}...HEAD`] };
26
+ }
27
+ function nameStatusArgs(range) {
28
+ return { sub: 'diff', rest: [NO_EXT_DIFF, RELATIVE, '--name-status', '-z', range.base, range.head] };
29
+ }
30
+ function numstatArgs(range) {
31
+ return { sub: 'diff', rest: [NO_EXT_DIFF, RELATIVE, '--numstat', '-z', range.base, range.head] };
32
+ }
33
+ function logArgs(range, max) {
34
+ return {
35
+ sub: 'log', rest: [`--format=${GIT_LOG_FORMAT}`, `--max-count=${String(max)}`, `${range.base}..${range.head}`],
36
+ };
37
+ }
38
+ /**
39
+ * One path exactly, in both trees: `:(literal)` makes `docs/*.md` a path, not a pattern, and the excluded `<path>/`
40
+ * keeps out the files under the same name when a file became a directory or a directory a file, which a pathspec
41
+ * matches as well. The magic stands per pathspec, so the command has no global `--literal-pathspecs`, which would
42
+ * turn it off.
43
+ */
44
+ function exactPathspec(path) {
45
+ return [`:(literal)${path}`, `:(exclude,literal)${path}/`];
46
+ }
47
+ /** `origin` is the source of a rename. */
48
+ function patchArgs(range, path, origin) {
49
+ return {
50
+ sub: 'diff',
51
+ rest: [
52
+ NO_EXT_DIFF, RELATIVE, range.base, range.head, '--',
53
+ ...exactPathspec(path), ...(origin === undefined ? [] : exactPathspec(origin)),
54
+ ],
55
+ };
56
+ }
57
+ /** A runner that does not throw: an exception, also a synchronous one, is a process that did not start. */
58
+ async function runGit(run, command, cwd) {
59
+ try {
60
+ return await run(command, cwd);
61
+ }
62
+ catch {
63
+ return { ok: false, stdout: '', spawnFailed: 'UNKNOWN' };
64
+ }
65
+ }
66
+ /**
67
+ * The output of a command that must succeed. Every command here reads commits that exist (the range is pinned), so a
68
+ * refusal is as much a failure as a timeout: an empty list would pass for a branch without changes.
69
+ */
70
+ function answered(result) {
71
+ if (!result.ok)
72
+ throw new DiffError(DIFF_GIT_FAILED_ERROR);
73
+ return result;
74
+ }
75
+ /**
76
+ * The range of this request, or why there is none. The branch comes from the main checkout, the head and the merge base
77
+ * from the session directory. Several merge bases (criss-cross merges): the first one git prints, the one
78
+ * `git diff <a>...<b>` takes.
79
+ */
80
+ async function resolveRange(cwd, projectRoot, run) {
81
+ const ref = answered(await runGit(run, baseBranchArgs(), projectRoot)).stdout.trim();
82
+ const branch = ref.startsWith(BRANCH_REF) ? ref.slice(BRANCH_REF.length) : '';
83
+ if (branch === '' || /\s/u.test(branch))
84
+ return 'no-base';
85
+ const lines = answered(await runGit(run, rangeArgs(ref), cwd)).stdout.split('\n').filter((line) => line !== '');
86
+ const [head, ...rest] = lines;
87
+ const tips = rest.filter((line) => !line.startsWith('^'));
88
+ const bases = rest.filter((line) => line.startsWith('^')).map((line) => line.slice(1));
89
+ // Output of another shape (a SHA-256 repository, an unreadable line) cannot be pinned: no list rather than a guess.
90
+ if (head === undefined || tips.length !== 2 || ![head, ...tips, ...bases].every((sha) => FULL_SHA.test(sha))) {
91
+ throw new DiffError(DIFF_GIT_FAILED_ERROR);
92
+ }
93
+ const base = bases[0];
94
+ return base === undefined ? 'no-base' : { branch, base, head };
95
+ }
96
+ /** Line counts, or none: past their budget or on a failure the list goes without them, as the session list does. */
97
+ async function readCounts(cwd, range, run) {
98
+ if (run === null)
99
+ return new Map();
100
+ const result = await runGit(run, numstatArgs(range), cwd);
101
+ return result.ok ? parseNumstatZ(result.stdout) : new Map();
102
+ }
103
+ /** `git log` lines in `GIT_LOG_FORMAT`, newest first; a line cut by the read cap is dropped. */
104
+ function parseCommits(result) {
105
+ const lines = result.stdout.split('\n');
106
+ if (result.capped === true)
107
+ lines.pop();
108
+ return lines.map((line) => (line === '' ? null : parseGitLog(line))).filter((commit) => commit !== null);
109
+ }
110
+ /**
111
+ * The files and commits of the session's branch past its merge base with the branch of the main checkout, in git's
112
+ * order, with the head they show. Only committed content: work the thread has not committed is in the session diff.
113
+ *
114
+ * @throws DiffError `git-failed` when git did not answer or refused a read.
115
+ */
116
+ export async function collectBranchDiffList(target, opts) {
117
+ const projectRoot = target.projectRoot;
118
+ if (projectRoot === undefined || projectRoot === '')
119
+ return NO_PROJECT_ROOT;
120
+ const range = await resolveRange(target.cwd, projectRoot, opts.run);
121
+ if (range === 'no-base')
122
+ return NO_BASE;
123
+ const [names, counts, log] = await Promise.all([
124
+ runGit(opts.run, nameStatusArgs(range), target.cwd),
125
+ readCounts(target.cwd, range, opts.runNumstat ?? null),
126
+ runGit(opts.run, logArgs(range, opts.maxCommits ?? MAX_BRANCH_DIFF_COMMITS), target.cwd),
127
+ ]);
128
+ const listed = answered(names);
129
+ const commits = parseCommits(answered(log));
130
+ const max = opts.maxFiles ?? MAX_DIFF_LIST_FILES;
131
+ const files = [];
132
+ let truncated = listed.capped === true;
133
+ for (const [path, entry] of parseNameStatusZ(listed.stdout)) {
134
+ if (files.length >= max) {
135
+ truncated = true;
136
+ break;
137
+ }
138
+ files.push({ path, status: entry.status, ...counts.get(path) });
139
+ }
140
+ return { ok: true, value: { files, truncated, commits, base: { branch: range.branch }, head: range.head } };
141
+ }
142
+ /**
143
+ * The source of a rename for the pathspec, or `undefined` when another entry of the list is that path, whose block the
144
+ * patch would then carry, or lies under it, where the name became a directory on the branch. Without the source the
145
+ * file shows as new in full.
146
+ */
147
+ function originToInclude(path, entry, listed, partial) {
148
+ const origin = entry.origin;
149
+ if (origin === undefined || partial)
150
+ return undefined;
151
+ const under = `${origin}/`;
152
+ for (const other of listed.keys()) {
153
+ if (other !== path && (other === origin || other.startsWith(under)))
154
+ return undefined;
155
+ }
156
+ return origin;
157
+ }
158
+ /**
159
+ * The patch of one file of the branch diff.
160
+ *
161
+ * Order: the shape check (`bad-path`), then the range and the list of this request, then the patch between the same two
162
+ * commits.
163
+ *
164
+ * @throws DiffError `bad-path`: the path failed the shape check;
165
+ * `diff-file-not-found`: the path is not on the list of the current range (the branch moved, the file is not
166
+ * changed on the branch, only main or the working tree changed it);
167
+ * `git-failed`: git did not answer or refused, or a list cut by the read cap cannot tell the path is not on it.
168
+ */
169
+ export async function collectBranchDiffFile(target, rawPath, opts) {
170
+ const projectRoot = target.projectRoot;
171
+ if (projectRoot === undefined || projectRoot === '')
172
+ return NO_PROJECT_ROOT;
173
+ const path = validateDiffPath(rawPath);
174
+ if (path === null)
175
+ throw new DiffError(DIFF_BAD_PATH_ERROR);
176
+ const range = await resolveRange(target.cwd, projectRoot, opts.run);
177
+ if (range === 'no-base')
178
+ return NO_BASE;
179
+ const names = answered(await runGit(opts.run, nameStatusArgs(range), target.cwd));
180
+ const partial = names.capped === true;
181
+ const listed = parseNameStatusZ(names.stdout);
182
+ const entry = listed.get(path);
183
+ if (entry === undefined)
184
+ throw new DiffError(partial ? DIFF_GIT_FAILED_ERROR : DIFF_FILE_NOT_FOUND_ERROR);
185
+ const result = answered(await runGit(opts.run, patchArgs(range, path, originToInclude(path, entry, listed, partial)), target.cwd));
186
+ const capped = result.capped === true;
187
+ // A prefix cut by the read cap ends in half a line, which goes, as in `clampPatch`.
188
+ const cut = capped ? result.stdout.lastIndexOf('\n') : -1;
189
+ const patch = cut === -1 ? result.stdout : result.stdout.slice(0, cut + 1);
190
+ if (patch === '' && !capped)
191
+ throw new DiffError(DIFF_FILE_NOT_FOUND_ERROR);
192
+ const clamped = clampPatch(patch, opts.maxPatchBytes ?? MAX_DIFF_FILE_PATCH_BYTES);
193
+ return { ok: true, value: { path, patch: clamped.patch, truncated: clamped.truncated || capped } };
194
+ }
@@ -15,6 +15,7 @@
15
15
  * Allow-lista jest sprawdzana PO ZBUDOWANIU tablicy, a nie tylko przy budowie: budowniczy może
16
16
  * się pomylić, a `agent.start` uruchamia PROCES na Macu użytkownika.
17
17
  */
18
+ import { posix } from 'node:path';
18
19
  import { EFFORT_LEVELS, MODEL_ID_PATTERN, PERMISSION_MODES } from '@rarog/shared';
19
20
  import { say } from '@rarog/shared/sentences';
20
21
  import { ENGINE_SESSION_ID_PATTERN } from '../transcript-import.js';
@@ -34,6 +35,28 @@ export const ALLOWED_CLAUDE_FLAGS = new Set([
34
35
  ]);
35
36
  /** Jedyna flaga bez wartości. */
36
37
  export const VALUELESS_CLAUDE_FLAGS = new Set(['--fork-session']);
38
+ /**
39
+ * The only flag whose value is a path: the coordinator plugin copy. Its value passes {@link isPluginDirValue}, not
40
+ * {@link ARG_VALUE_PATTERN}, which has no `/`. Kept out of {@link ALLOWED_CLAUDE_FLAGS}, so a path never passes as
41
+ * the value of another flag and no other value passes here.
42
+ */
43
+ export const PATH_CLAUDE_FLAGS = new Set(['--plugin-dir']);
44
+ /** Ceiling of a `--plugin-dir` value in characters. */
45
+ export const PLUGIN_DIR_MAX = 512;
46
+ /**
47
+ * Shape of the plugin copy path: absolute, segments of letters, digits, `.`, `_`, `@`, `+` and `-`, ending in
48
+ * `/plugins/coordinator/<version>` (the layout of `plugin-copy.ts`). No space, quote, `$`, backtick, `;`, `|`, `&`,
49
+ * `<`, `>`, `(`, `)`, `\`, `*`, `?`, `[`, `]`, `~`, `#`, `!` or line end: the value is shell text like every other.
50
+ */
51
+ const PLUGIN_DIR_PATTERN = /^(?:\/[A-Za-z0-9._@+-]+)+\/plugins\/coordinator\/[A-Za-z0-9.+-]+$/;
52
+ /**
53
+ * Whether `value` may follow `--plugin-dir`: the shape above, at most {@link PLUGIN_DIR_MAX} characters, and
54
+ * normalized (no `.` or `..` segment, no `//`), so the path names the copy itself and nothing next to it. Decided from
55
+ * the value alone, because the gate after the build ({@link assertAllowedArgs}) sees only the array.
56
+ */
57
+ export function isPluginDirValue(value) {
58
+ return value.length <= PLUGIN_DIR_MAX && PLUGIN_DIR_PATTERN.test(value) && posix.normalize(value) === value;
59
+ }
37
60
  /**
38
61
  * Flagi wymienione w planie jako zablokowane NA STAŁE.
39
62
  *
@@ -119,7 +142,8 @@ export function assertAllowedArgs(args) {
119
142
  i += 1;
120
143
  continue;
121
144
  }
122
- if (!ALLOWED_CLAUDE_FLAGS.has(flag)) {
145
+ const path = PATH_CLAUDE_FLAGS.has(flag);
146
+ if (!path && !ALLOWED_CLAUDE_FLAGS.has(flag)) {
123
147
  throw notAllowed(i, flag);
124
148
  }
125
149
  const value = args[i + 1];
@@ -129,7 +153,7 @@ export function assertAllowedArgs(args) {
129
153
  if (value.startsWith('-')) {
130
154
  throw new HerdrArgvError(say('herdr.argv-value-like-flag.quoted', { flag }));
131
155
  }
132
- if (!ARG_VALUE_PATTERN.test(value)) {
156
+ if (path ? !isPluginDirValue(value) : !ARG_VALUE_PATTERN.test(value)) {
133
157
  throw new HerdrArgvError(say('herdr.argv-value-charset.quoted', { flag }));
134
158
  }
135
159
  i += 2;
@@ -148,7 +172,7 @@ function assertValue(flag, value) {
148
172
  * **ZERO argumentów pozycyjnych** — funkcja nie ma nawet parametru na prompt i mieć go nie
149
173
  * będzie (`docs/security-model.md`, „Starting sessions from the phone: three powers”).
150
174
  * Kolejność flag jest kontraktem: `--session-id`, `--resume` (+ `--fork-session`),
151
- * `--model`, `--effort`, `--permission-mode`.
175
+ * `--model`, `--effort`, `--permission-mode`, `--plugin-dir` (coordinator start and resume only, never a fork).
152
176
  *
153
177
  * Brak `req.model` → BRAK flagi `--model` (model domyślny konta) — to jest ścieżka DOMYŚLNA,
154
178
  * a nie przypadek brzegowy. Tak samo `effort` i `permissionMode`.
@@ -229,6 +253,13 @@ export function buildClaudeArgs(req, sessionId) {
229
253
  }
230
254
  args.push('--permission-mode', assertValue('--permission-mode', req.permissionMode));
231
255
  }
256
+ // A fork of the coordinator is an ordinary session, so it never gets the coordinator plugin.
257
+ if (req.pluginDir !== undefined && !forking) {
258
+ if (!isPluginDirValue(req.pluginDir)) {
259
+ throw new HerdrArgvError(say('herdr.argv-value-charset.quoted', { flag: '--plugin-dir' }));
260
+ }
261
+ args.push('--plugin-dir', req.pluginDir);
262
+ }
232
263
  assertAllowedArgs(args);
233
264
  return args;
234
265
  }
@@ -20,10 +20,12 @@
20
20
  import { appendFile, chmod, mkdir, rename, stat } from 'node:fs/promises';
21
21
  import { createHash } from 'node:crypto';
22
22
  import path from 'node:path';
23
- import { CLI_DIALOG_CLASSES, REFUSE_REASONS } from '@rarog/shared';
23
+ import { CLI_DIALOG_CLASSES, DIALOG_LIVE_KEYS, REFUSE_REASONS } from '@rarog/shared';
24
24
  import { REDACTED, redact } from '../auth/index.js';
25
25
  import { HOOK_BUDGET_SOURCES } from './hook-config.js';
26
26
  import { BLOCK_CARD_VERDICTS, DIALOG_ROUTES, DIALOG_ROUTE_REASONS, LAYER2_EPISODE_VERDICTS, LAYER2_WHYS, SHADOW_RESULTS, TERMINAL_DIALOG_IDS, } from './dialogs/index.js';
27
+ import { LIVE_CARD_SHAPES, LIVE_VERIFY_OUTCOMES } from './dialogs/live/model.js';
28
+ import { LIVE_ENTER_WHYS } from './dialogs/live/policy.js';
27
29
  import { NO_PROOF_REASONS } from './dialogs/shadow/evidence.js';
28
30
  export const HERDR_AUDIT_FILENAME = 'herdr-audit.log';
29
31
  /** Powyżej tego rozmiaru plik jedzie do `.log.1` (jedna generacja wstecz, jak `client.log`). */
@@ -135,6 +137,20 @@ export const AUDIT_MISMATCH_REASONS = [
135
137
  * `jsonl` — wpis transkryptu, `hook` — zrzut hooka, `screen` — sam ekran.
136
138
  */
137
139
  export const AUDIT_CARD_SOURCES = ['jsonl', 'hook', 'screen'];
140
+ /**
141
+ * What came of a key of the live card (`liveResult`): it went (`sent`), the step refused it before any key
142
+ * (`refused`, with `reason`), or the client call failed after it started (`failed`, reason `send-failed`): the key
143
+ * may have reached the pane.
144
+ */
145
+ export const LIVE_KEY_RESULTS = ['sent', 'refused', 'failed'];
146
+ /** The fields of the live card lines, those set: the driver copies them into its entry in one step. */
147
+ export function pickLiveFields(shape) {
148
+ const { liveShape, liveKeys, liveWhy, liveKey, liveRev, liveResult, liveOutcome, engineSessionId } = shape;
149
+ const all = {
150
+ liveShape, liveKeys, liveWhy, liveKey, liveRev, liveResult, liveOutcome, engineSessionId,
151
+ };
152
+ return Object.fromEntries(Object.entries(all).filter(([, value]) => value !== undefined));
153
+ }
138
154
  /** Kind of key a layer 2 card sent (`layer2Key`): a digit, a key of the key row (`send/key-row.ts`) or Esc. */
139
155
  export const LAYER2_KEY_KINDS = ['digit', 'key', 'escape'];
140
156
  /**
@@ -230,6 +246,18 @@ export function auditShapeFields(shape) {
230
246
  ? shape.layer2Key : undefined);
231
247
  put('layer2Outcome', shape.layer2Outcome !== undefined
232
248
  && LAYER2_VERIFY_OUTCOMES.includes(shape.layer2Outcome) ? shape.layer2Outcome : undefined);
249
+ put('liveShape', shape.liveShape !== undefined && LIVE_CARD_SHAPES.includes(shape.liveShape)
250
+ ? shape.liveShape : undefined);
251
+ put('liveWhy', shape.liveWhy !== undefined && LIVE_ENTER_WHYS.includes(shape.liveWhy)
252
+ ? shape.liveWhy : undefined);
253
+ put('liveKey', shape.liveKey !== undefined && DIALOG_LIVE_KEYS.includes(shape.liveKey)
254
+ ? shape.liveKey : undefined);
255
+ put('liveRev', auditCount(shape.liveRev));
256
+ put('liveResult', shape.liveResult !== undefined && LIVE_KEY_RESULTS.includes(shape.liveResult)
257
+ ? shape.liveResult : undefined);
258
+ put('liveOutcome', shape.liveOutcome !== undefined
259
+ && LIVE_VERIFY_OUTCOMES.includes(shape.liveOutcome) ? shape.liveOutcome : undefined);
260
+ put('engineSessionId', auditId(shape.engineSessionId));
233
261
  return out;
234
262
  }
235
263
  /** Ścieżka dziennika dla katalogu danych Raroga. */
@@ -251,6 +279,9 @@ function toLine(event, at, secrets) {
251
279
  entry['sender'] = event.sender;
252
280
  if (event.keys !== undefined)
253
281
  entry['keys'] = [...event.keys];
282
+ if (event.liveKeys !== undefined) {
283
+ entry['liveKeys'] = event.liveKeys.filter((key) => DIALOG_LIVE_KEYS.includes(key));
284
+ }
254
285
  /*
255
286
  * Kontekst decyzji (`docs/security-model.md`, „Starting sessions from the phone: three powers”).
256
287
  * Wpis `keys: ['1']` nie odpowiada na pytanie „co zatwierdzono" —
@@ -42,25 +42,10 @@ export const CLI_SHAPES = {
42
42
  literals: {
43
43
  open: '<task-notification>',
44
44
  taskId: '<task-id>',
45
- // The call that started the task and the file its output goes to (also on CLI 2.1.316, live session file).
46
- toolUseId: '<tool-use-id>',
47
- outputFile: '<output-file>',
48
- /*
49
- * The output file's place: `<tmp>/claude-<uid>/<slug>/<session uuid>/tasks/<task id>.output`. For a `Bash`
50
- * command a regular file with the output and an `[exited with code N]` line; for an agent the CLI puts a
51
- * symlink to the agent's conversation file there. The CLI deletes these files after some days (unmeasured).
52
- * Read only by the pull request reader (`pull-request-files.ts`).
53
- */
54
- outputDir: 'tasks',
55
- outputExtension: '.output',
56
45
  status: '<status>',
57
46
  summary: '<summary>',
58
47
  },
59
48
  cli: '2.1.296',
60
- common: {
61
- outputDir: 'ordinary word: the driver event of the task list has the same name',
62
- outputExtension: 'ordinary word: `.output` stands in code as an object field (`deps.output`)',
63
- },
64
49
  },
65
50
  notificationCarriers: {
66
51
  what: 'wpisy niosące meldunek poza wpisem `user` z gołym napisem: kolejka promptów i załącznik',
@@ -92,6 +77,25 @@ export const CLI_SHAPES = {
92
77
  cli: '2.1.296',
93
78
  common: { prompt: ORDINARY_WORD, origin: ORDINARY_WORD, kind: ORDINARY_WORD, human: ORDINARY_WORD },
94
79
  },
80
+ /**
81
+ * A message another Claude session sent with `SendMessage` lands in the receiving session's main file on the same
82
+ * two carriers as a human prompt: a meta `user` entry when the receiver is idle, a queue attachment in prompt mode
83
+ * when the message is absorbed into a running turn. Both carry the origin kind `peer`, the sender's inbox socket in
84
+ * `from` and the bare message text in `body`. A subagent's message to its parent has the same origin kind and a
85
+ * `body`, but `from` holds the agent id, never a socket address. The sender's process id stands in
86
+ * `verifiedPeerPid` and, as `<pid>.sock`, in the socket's file name. Measured by hand on session files
87
+ * (CLI 2.1.302–2.1.332). Read by `queued-prompt.ts` and `coordination/merge-prompt.ts`.
88
+ */
89
+ crossSessionPeer: {
90
+ what: 'origin of a message from another Claude session: kind, sender socket, sender process and message text',
91
+ literals: { peer: 'peer', from: 'from', body: 'body', socket: 'uds:', verifiedPid: 'verifiedPeerPid' },
92
+ cli: '2.1.331',
93
+ common: {
94
+ peer: 'origin kind shared with subagent messages; modules that tell senders apart may read it too',
95
+ from: ORDINARY_WORD,
96
+ body: ORDINARY_WORD,
97
+ },
98
+ },
95
99
  notificationOrigin: {
96
100
  what: 'wartość `origin.kind` wpisu, którą CLI znakuje notkę o zadaniu w tle (bramka notki)',
97
101
  literals: { kind: 'task-notification' },
@@ -430,6 +434,22 @@ export const CLI_SHAPES = {
430
434
  createdAt: 'ordinary word: device and note stores have a field with this name',
431
435
  },
432
436
  },
437
+ /**
438
+ * The entry that links a pull request to the conversation (`pull-requests.ts`): a top-level entry
439
+ * `{type, sessionId, prNumber, prUrl, prRepository, timestamp}` in the main conversation file, seen on CLI
440
+ * 2.1.296–2.1.3xx and never in a subagent file. No conversation in the Rarog workspace has one, so no measured fixture
441
+ * holds it: the literals stand on the list outside the measurement in `herdr-background-fixtures.test.ts`.
442
+ */
443
+ prLink: {
444
+ what: 'the entry that links a pull request to the conversation: its type, PR URL, number and repository',
445
+ literals: {
446
+ type: 'pr-link',
447
+ url: 'prUrl',
448
+ number: 'prNumber',
449
+ repository: 'prRepository',
450
+ },
451
+ cli: '2.1.296',
452
+ },
433
453
  };
434
454
  /**
435
455
  * Literał jako fragment wyrażenia regularnego — bez znaczenia specjalnego żadnego znaku.
@@ -24,15 +24,15 @@
24
24
  * o usunięciu (notka harnessu, ten sam parser co meldunek zadania) → lista adresów
25
25
  * z tytułem i czasem. Nie zadanie w tle: stoi tu, bo meldunek jedzie tym samym
26
26
  * nośnikiem, a jego słowa trzyma ten sam rejestr. Opis: `docs/artifacts.md`.
27
- * - `pull-requests.ts` — CZYSTE: pull requesty sesji. Wywołanie `Bash` z poleceniem `gh pr create`
28
- * i linia wyniku z adresem PR → lista adresów z repo, numerem, czasem i tytułem. Nie
29
- * zadanie w tle: stoi tu obok artefaktów, bo czyta te same pliki rozmowy i jedzie tą samą
30
- * drogą do apki. Opis: `docs/pull-requests.md`.
27
+ * - `pull-requests.ts` — PURE: pull requests linked to the conversation. The CLI's link entry with a GitHub
28
+ * PR URL → the linked set (URL, repo, number, first entry time), and the window's lower bound.
29
+ * Not a background task: it lives here because the registry holds its CLI words. Which
30
+ * linked PRs a card shows: `sessions/pr-status-link.ts`. Description: `docs/pull-requests.md`.
31
31
  * - `scheduled-tasks.ts` — PURE: the session's scheduled tasks (crons). `CronCreate`, `CronDelete` and `CronList`
32
32
  * results, the run line and the carry attachment → the list of armed tasks; also the prefilter for
33
33
  * raw lines. Not a background task: it lives here because the registry holds its CLI words.
34
- * - `pull-request-files.ts` — czytnik plików rozmowy pod kątem PR-ów: plik główny, pliki
35
- * subagentów i agentów workflow, wszystkie, przyrostowo, z prefiltrem i budżetem bajtów.
34
+ * - `pull-request-files.ts` — the reader of the main conversation file for pull requests: incrementally,
35
+ * with a prefilter and a byte budget; the linked set and the window of one conversation.
36
36
  * - `scheduled-task-file.ts` — the reader of the main conversation file for the scheduled tasks:
37
37
  * incrementally, with the tracker's prefilter, the list rebuilt from zero on truncation.
38
38
  * - `incremental-read.ts` — one incremental read of one conversation file: offset, chunks, byte
@@ -85,7 +85,7 @@ export { createWorkflowRunReader, phaseCounts } from './workflow-run.js';
85
85
  export { createAgentFileReader } from './agent-file.js';
86
86
  export { scanMainFileBefore } from './main-scan.js';
87
87
  export { artifactsSignature, createArtifactsTracker } from './artifacts.js';
88
- export { pullRequestsSignature } from './pull-requests.js';
88
+ export { isPullRequestLinkEntry, pullRequestLinksSignature } from './pull-requests.js';
89
89
  export { createScheduledTasksTracker } from './scheduled-tasks.js';
90
90
  export { PULL_REQUESTS_BACKLOG_MS, PULL_REQUESTS_POLL_MS, createPullRequestFilesReader, } from './pull-request-files.js';
91
91
  export { SCHEDULED_TASKS_BACKLOG_MS, SCHEDULED_TASKS_POLL_MS, createScheduledTaskFileReader, } from './scheduled-task-file.js';
@@ -1,3 +1,4 @@
1
+ import { ownCommandWaitOf } from './work.js';
1
2
  /**
2
3
  * Co ile driver odczytuje pliki obok transkryptu: rozkłady OTWARTYCH przebiegów workflow
3
4
  * i pliki OTWARTYCH subagentów.
@@ -170,8 +171,11 @@ function refreshDormant(state, now, fresh) {
170
171
  * nie ma na liście);
171
172
  * - wynik odczytu, który wrócił po zmianie `waitingSince`, niczego nie psuje: czas wpisu jest
172
173
  * faktem o pliku i zestawia się z BIEŻĄCYM postojem, nie z tym sprzed odczytu.
174
+ *
175
+ * The wait stage (`ownCommandWait`) is set last, on the copy, from the view after the wake and the own commands:
176
+ * `ownCommandWaitOf` in `work.ts` decides, with the clock of this emission (`now`).
173
177
  */
174
- function agentView(state, task) {
178
+ function agentView(state, task, now) {
175
179
  const facts = state.agents.get(task.id);
176
180
  if (facts === undefined)
177
181
  return task;
@@ -187,16 +191,20 @@ function agentView(state, task) {
187
191
  // Własne komendy widać także pod agentem, który pracuje: to dalej jego otwarte zadania.
188
192
  if (own.length > 0)
189
193
  view.ownTasks = own;
194
+ const wait = ownCommandWaitOf(view, now);
195
+ if (wait !== undefined)
196
+ view.ownCommandWait = wait;
190
197
  return view;
191
198
  }
192
199
  /**
193
200
  * Zadania followera z nakładkami tam, gdzie je znamy. Reszta jedzie bez zmian; agent uśpiony
194
201
  * (`state.dormant`) nie jedzie wcale. Funkcja samego stanu: uśpienie liczy `emitChanged`.
202
+ * `now` is the clock of the emission; only the wait stage of an agent reads it.
195
203
  */
196
- export function mergedTasks(state) {
204
+ export function mergedTasks(state, now) {
197
205
  return state.raw.flatMap((task) => {
198
206
  if (task.kind === 'agent')
199
- return state.dormant.has(task.id) ? [] : [agentView(state, task)];
207
+ return state.dormant.has(task.id) ? [] : [agentView(state, task, now)];
200
208
  const run = task.runId === undefined ? undefined : state.runs.get(task.runId)?.run;
201
209
  return [run === undefined ? task : { ...task, run }];
202
210
  });
@@ -208,10 +216,14 @@ export function mergedTasks(state) {
208
216
  * zdarzenie `tasks` z samym `ended`), a odczyt pliku subagenta co tick przynosi nowy czas wpisu,
209
217
  * który zwykle niczego w liście nie zmienia. Manager po każdej liście rozsyła `session-changed`,
210
218
  * więc powtórka tej samej listy byłaby pustą ramką do każdego klienta.
219
+ *
220
+ * The compared list carries the wait stage, so a threshold passed between two ticks changes the JSON and goes out on
221
+ * the first tick after it, with no change in any file.
211
222
  */
212
223
  function emitChanged(state, deps, fresh = NO_FRESH) {
213
- refreshDormant(state, deps.scheduler.now(), fresh);
214
- const merged = mergedTasks(state);
224
+ const now = deps.scheduler.now();
225
+ refreshDormant(state, now, fresh);
226
+ const merged = mergedTasks(state, now);
215
227
  const json = JSON.stringify(merged);
216
228
  if (json === state.sent)
217
229
  return;
@@ -46,8 +46,6 @@ function tagPattern(open) {
46
46
  return new RegExp(`${literalSource(open)}([\\s\\S]*?)${literalSource(closing(open))}`);
47
47
  }
48
48
  const TASK_ID = tagPattern(MARKS.taskId);
49
- const TOOL_USE_ID = tagPattern(MARKS.toolUseId);
50
- const OUTPUT_FILE = tagPattern(MARKS.outputFile);
51
49
  const STATUS = tagPattern(MARKS.status);
52
50
  const SUMMARY = tagPattern(MARKS.summary);
53
51
  /**
@@ -180,8 +178,6 @@ export function parseTaskNotification(text) {
180
178
  const exitCode = exitCodeOf(summary);
181
179
  return {
182
180
  id: tag(text, TASK_ID),
183
- toolUseId: tag(text, TOOL_USE_ID),
184
- outputFile: tag(text, OUTPUT_FILE),
185
181
  status: tag(text, STATUS),
186
182
  summary,
187
183
  name: quotedName(summary),