@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
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The `gh`
|
|
3
|
-
*
|
|
2
|
+
* The `gh` source: one batched GraphQL query for up to {@link PR_BATCH_MAX} PRs, run with the user's `gh` login for
|
|
3
|
+
* `github.com`. Every read asks the same fields: state, draft mark, title, creation time and author of each PR, and
|
|
4
|
+
* the login of the account (`viewer`). The only place in the server that starts `gh` (guard:
|
|
5
|
+
* `server/test/pr-status-granice.test.ts`).
|
|
4
6
|
*
|
|
5
7
|
* - program: the first executable `gh` in the closed directory list {@link GH_DIRECTORIES}, looked up once, on the
|
|
6
8
|
* first read; `execFile` without a shell;
|
|
@@ -16,6 +18,7 @@ import { execFile } from 'node:child_process';
|
|
|
16
18
|
import { accessSync, constants, statSync } from 'node:fs';
|
|
17
19
|
import { isAbsolute, join } from 'node:path';
|
|
18
20
|
import { PR_STATUS_ENV_PASSTHROUGH } from '../config-env.js';
|
|
21
|
+
import { clipUnits, stripControlChars } from '../text.js';
|
|
19
22
|
/**
|
|
20
23
|
* Where `gh` is looked for, in this order; `~/` is the server's `HOME`. A closed list of absolute paths, no `PATH`
|
|
21
24
|
* search: the server's `PATH` is minimal, and Homebrew on an Intel Mac, linuxbrew and `~/.local/bin` are not on it.
|
|
@@ -35,6 +38,10 @@ export const GH_TIMEOUT_MS = 20_000;
|
|
|
35
38
|
export const GH_OUTPUT_CAP_BYTES = 1024 * 1024;
|
|
36
39
|
/** PRs per call (aliases in one query). */
|
|
37
40
|
export const PR_BATCH_MAX = 50;
|
|
41
|
+
/** Longest title kept, in UTF-16 code units: the limit of `SessionPullRequest.title`. */
|
|
42
|
+
export const PR_TITLE_MAX = 120;
|
|
43
|
+
/** Fields asked of every PR. */
|
|
44
|
+
const PR_FIELDS = 'state isDraft title createdAt author{login}';
|
|
38
45
|
/** `gh` exit code for "authentication required". */
|
|
39
46
|
const NOT_LOGGED_IN_EXIT = 4;
|
|
40
47
|
/** GitHub's wording of the primary and the secondary rate limit. */
|
|
@@ -91,12 +98,12 @@ export function buildQueryBody(prs) {
|
|
|
91
98
|
const variables = {};
|
|
92
99
|
prs.forEach((pr, i) => {
|
|
93
100
|
declarations.push(`$o${i}:String!,$r${i}:String!,$n${i}:Int!`);
|
|
94
|
-
fields.push(`p${i}:repository(owner:$o${i},name:$r${i}){pullRequest(number:$n${i}){
|
|
101
|
+
fields.push(`p${i}:repository(owner:$o${i},name:$r${i}){pullRequest(number:$n${i}){${PR_FIELDS}}}`);
|
|
95
102
|
variables[`o${i}`] = pr.owner;
|
|
96
103
|
variables[`r${i}`] = pr.repo;
|
|
97
104
|
variables[`n${i}`] = pr.number;
|
|
98
105
|
});
|
|
99
|
-
const query = `query(${declarations.join(',')}){${fields.join(' ')} rateLimit{remaining resetAt}}`;
|
|
106
|
+
const query = `query(${declarations.join(',')}){${fields.join(' ')} viewer{login} rateLimit{remaining resetAt}}`;
|
|
100
107
|
return JSON.stringify({ query, variables });
|
|
101
108
|
}
|
|
102
109
|
function record(value) {
|
|
@@ -135,7 +142,56 @@ function epochOf(value) {
|
|
|
135
142
|
const ms = Date.parse(value);
|
|
136
143
|
return Number.isFinite(ms) ? ms : null;
|
|
137
144
|
}
|
|
138
|
-
/**
|
|
145
|
+
/**
|
|
146
|
+
* A title from GitHub as the list may show it: control characters out, trimmed, at most {@link PR_TITLE_MAX} UTF-16
|
|
147
|
+
* code units. Empty after that, or not a string: no title.
|
|
148
|
+
*/
|
|
149
|
+
export function prTitle(value) {
|
|
150
|
+
if (typeof value !== 'string')
|
|
151
|
+
return undefined;
|
|
152
|
+
const title = clipUnits(stripControlChars(value).trim(), PR_TITLE_MAX);
|
|
153
|
+
return title === '' ? undefined : title;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* What `errors[]` says about each alias (the first element of the error path). Only `NOT_FOUND` at the repository
|
|
157
|
+
* (`[pN]`) or at the PR (`[pN, "pullRequest"]`) means the PR is missing; any other error on the alias path, also next
|
|
158
|
+
* to a not-found one, is an error.
|
|
159
|
+
*/
|
|
160
|
+
function aliasVerdicts(answer) {
|
|
161
|
+
const verdicts = new Map();
|
|
162
|
+
const errors = answer?.['errors'];
|
|
163
|
+
if (!Array.isArray(errors))
|
|
164
|
+
return verdicts;
|
|
165
|
+
for (const item of errors) {
|
|
166
|
+
const error = record(item);
|
|
167
|
+
const path = error?.['path'];
|
|
168
|
+
if (!Array.isArray(path) || typeof path[0] !== 'string')
|
|
169
|
+
continue;
|
|
170
|
+
const alias = path[0];
|
|
171
|
+
const notFound = error?.['type'] === 'NOT_FOUND'
|
|
172
|
+
&& (path.length === 1 || (path.length === 2 && path[1] === 'pullRequest'));
|
|
173
|
+
if (!notFound)
|
|
174
|
+
verdicts.set(alias, 'error');
|
|
175
|
+
else if (verdicts.get(alias) !== 'error')
|
|
176
|
+
verdicts.set(alias, 'missing');
|
|
177
|
+
}
|
|
178
|
+
return verdicts;
|
|
179
|
+
}
|
|
180
|
+
/** Author and creation time of one `pullRequest` object; a verdict from `errors[]` wins over the object. */
|
|
181
|
+
function factsOf(pullRequest, verdict) {
|
|
182
|
+
if (verdict !== undefined)
|
|
183
|
+
return { kind: verdict };
|
|
184
|
+
const author = record(pullRequest?.['author'])?.['login'];
|
|
185
|
+
const createdAtMs = epochOf(pullRequest?.['createdAt']);
|
|
186
|
+
if (typeof author !== 'string' || author === '' || createdAtMs === null)
|
|
187
|
+
return { kind: 'error' };
|
|
188
|
+
return { kind: 'found', author, createdAtMs };
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Answers for `prs` from one run. Reads stdout whatever the exit code; stdout without a `data` object fails the call.
|
|
192
|
+
* The state reads only the PR object, whatever `errors[]` or the facts say; an answer without `viewer.login` makes
|
|
193
|
+
* the facts of every PR an error.
|
|
194
|
+
*/
|
|
139
195
|
export function readGhOutput(run, prs) {
|
|
140
196
|
if (run.failure === 'timeout')
|
|
141
197
|
return { ok: false, failure: 'timeout' };
|
|
@@ -151,14 +207,25 @@ export function readGhOutput(run, prs) {
|
|
|
151
207
|
}
|
|
152
208
|
return { ok: false, failure: run.code === NOT_LOGGED_IN_EXIT ? 'not-logged-in' : 'error' };
|
|
153
209
|
}
|
|
210
|
+
const login = record(data['viewer'])?.['login'];
|
|
211
|
+
const viewer = typeof login === 'string' && login !== '' ? login : null;
|
|
212
|
+
const verdicts = aliasVerdicts(answer);
|
|
154
213
|
const states = new Map();
|
|
214
|
+
const titles = new Map();
|
|
215
|
+
const facts = new Map();
|
|
155
216
|
prs.forEach((pr, i) => {
|
|
156
|
-
|
|
217
|
+
const pullRequest = record(record(data[`p${i}`])?.['pullRequest']);
|
|
218
|
+
states.set(pr.url, stateOf(pullRequest));
|
|
219
|
+
const title = prTitle(pullRequest?.['title']);
|
|
220
|
+
if (title !== undefined)
|
|
221
|
+
titles.set(pr.url, title);
|
|
222
|
+
facts.set(pr.url, viewer === null ? { kind: 'error' } : factsOf(pullRequest, verdicts.get(`p${i}`)));
|
|
157
223
|
});
|
|
158
224
|
const limit = record(data['rateLimit']);
|
|
225
|
+
const result = { ok: true, states, titles, facts, viewer };
|
|
159
226
|
if (limit?.['remaining'] === 0)
|
|
160
|
-
return {
|
|
161
|
-
return
|
|
227
|
+
return { ...result, limitReached: { resetAt: epochOf(limit['resetAt']) } };
|
|
228
|
+
return result;
|
|
162
229
|
}
|
|
163
230
|
/** One `gh` run; resolves, never rejects. */
|
|
164
231
|
export function runGh(bin, opts) {
|
|
@@ -211,7 +278,7 @@ export function createGhSource(opts) {
|
|
|
211
278
|
try {
|
|
212
279
|
const batch = prs.slice(0, PR_BATCH_MAX);
|
|
213
280
|
if (batch.length === 0)
|
|
214
|
-
return { ok: true, states: new Map() };
|
|
281
|
+
return { ok: true, states: new Map(), titles: new Map(), facts: new Map(), viewer: null };
|
|
215
282
|
if (bin === undefined) {
|
|
216
283
|
bin = findGh({ home, ...(opts.directories === undefined ? {} : { directories: opts.directories }) });
|
|
217
284
|
}
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
* PR status (`SessionPullRequest.state`): the state of the PRs that sessions created, read from GitHub with the
|
|
3
|
-
* user's `gh` login while a client is connected. The entry of the directory; callers import only from here.
|
|
4
|
-
*
|
|
5
|
-
* - `source.ts`: PR reference from an address, the read result, the state source contract, the fixed-map source;
|
|
6
|
-
* - `gh.ts`: the `gh` source (program lookup, closed environment, batched query on stdin, output reader) and the
|
|
7
|
-
* login check of `rarog doctor`;
|
|
8
|
-
* - `tracker.ts`: the URL → state map, the rhythm, pauses after failures and the change callback.
|
|
9
|
-
*/
|
|
10
|
-
export { GH_ARGV, GH_AUTH_ARGV, GH_AUTH_TIMEOUT_MS, GH_DIRECTORIES, GH_HOST, GH_OUTPUT_CAP_BYTES, GH_TIMEOUT_MS, PR_BATCH_MAX, PR_STATUS_ENV_PASSTHROUGH, buildQueryBody, checkGhAuth, createGhSource, findGh, ghCandidates, ghEnv, readGhOutput, } from './gh.js';
|
|
1
|
+
export { GH_ARGV, GH_AUTH_ARGV, GH_AUTH_TIMEOUT_MS, GH_DIRECTORIES, GH_HOST, GH_OUTPUT_CAP_BYTES, GH_TIMEOUT_MS, PR_BATCH_MAX, PR_STATUS_ENV_PASSTHROUGH, PR_TITLE_MAX, buildQueryBody, checkGhAuth, createGhSource, findGh, ghCandidates, ghEnv, prTitle, readGhOutput, } from './gh.js';
|
|
11
2
|
export { createFixedPrStateSource, parsePrUrl } from './source.js';
|
|
12
3
|
export { FAILURE_PAUSE_MS, NEW_URL_DELAY_MS, OPEN_REFRESH_MS, RATE_LIMIT_PAUSE_MAX_MS, UNKNOWN_REFRESH_MS, createPrStatusTracker, } from './tracker.js';
|
|
@@ -11,12 +11,26 @@ export function parsePrUrl(url) {
|
|
|
11
11
|
const [, owner = '', repo = '', number = ''] = match;
|
|
12
12
|
return { url, owner, repo, number: Number(number) };
|
|
13
13
|
}
|
|
14
|
-
/** A source that answers from a fixed map and never starts a process. URLs outside the map
|
|
15
|
-
export function createFixedPrStateSource(
|
|
14
|
+
/** A source that answers from a fixed map and never starts a process. URLs outside the map are `missing`. */
|
|
15
|
+
export function createFixedPrStateSource(github) {
|
|
16
16
|
return {
|
|
17
|
-
read: (prs) =>
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
read: (prs) => {
|
|
18
|
+
const states = new Map();
|
|
19
|
+
const titles = new Map();
|
|
20
|
+
const facts = new Map();
|
|
21
|
+
for (const { url } of prs) {
|
|
22
|
+
const pr = github.prs.get(url);
|
|
23
|
+
states.set(url, pr?.state ?? null);
|
|
24
|
+
if (pr?.title !== undefined)
|
|
25
|
+
titles.set(url, pr.title);
|
|
26
|
+
if (pr === undefined)
|
|
27
|
+
facts.set(url, { kind: 'missing' });
|
|
28
|
+
else if (github.viewer === null)
|
|
29
|
+
facts.set(url, { kind: 'error' });
|
|
30
|
+
else
|
|
31
|
+
facts.set(url, { kind: 'found', author: pr.author, createdAtMs: pr.createdAtMs });
|
|
32
|
+
}
|
|
33
|
+
return Promise.resolve({ ok: true, states, titles, facts, viewer: github.viewer });
|
|
34
|
+
},
|
|
21
35
|
};
|
|
22
36
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createPrFactsQueue } from './facts.js';
|
|
1
2
|
import { PR_BATCH_MAX } from './gh.js';
|
|
2
3
|
import { parsePrUrl } from './source.js';
|
|
3
4
|
export const NEW_URL_DELAY_MS = 5_000;
|
|
@@ -23,6 +24,7 @@ export function createPrStatusTracker(opts) {
|
|
|
23
24
|
const newUrlDelayMs = Math.max(0, opts.newUrlDelayMs ?? NEW_URL_DELAY_MS);
|
|
24
25
|
const entries = new Map();
|
|
25
26
|
const sessions = new Map();
|
|
27
|
+
const facts = createPrFactsQueue();
|
|
26
28
|
let connected = false;
|
|
27
29
|
let disabled = false;
|
|
28
30
|
let closed = false;
|
|
@@ -47,7 +49,7 @@ export function createPrStatusTracker(opts) {
|
|
|
47
49
|
clearTimer();
|
|
48
50
|
if (closed || disabled || !connected || reading !== null)
|
|
49
51
|
return;
|
|
50
|
-
let next =
|
|
52
|
+
let next = facts.nextDueAt();
|
|
51
53
|
for (const entry of entries.values())
|
|
52
54
|
if (entry.dueAt < next)
|
|
53
55
|
next = entry.dueAt;
|
|
@@ -59,7 +61,8 @@ export function createPrStatusTracker(opts) {
|
|
|
59
61
|
const pause = (ms) => {
|
|
60
62
|
pausedUntil = scheduler.now() + ms;
|
|
61
63
|
};
|
|
62
|
-
|
|
64
|
+
/** One read's answer: `batch` are the state entries asked, `verified` the facts-only URLs asked with them. */
|
|
65
|
+
const apply = (batch, verified, result) => {
|
|
63
66
|
if (!result.ok) {
|
|
64
67
|
if (result.failure === 'missing-gh') {
|
|
65
68
|
disabled = true;
|
|
@@ -70,7 +73,7 @@ export function createPrStatusTracker(opts) {
|
|
|
70
73
|
? rateLimitPause(result.resetAt)
|
|
71
74
|
: FAILURE_PAUSE_MS;
|
|
72
75
|
pause(ms);
|
|
73
|
-
const count = plural(batch.length);
|
|
76
|
+
const count = plural(batch.length + verified.length);
|
|
74
77
|
safeLog(`pr-status: gh call failed (${result.failure}) for ${count}, paused for ${minutes(ms)} min`);
|
|
75
78
|
return;
|
|
76
79
|
}
|
|
@@ -88,15 +91,19 @@ export function createPrStatusTracker(opts) {
|
|
|
88
91
|
else
|
|
89
92
|
entry.dueAt = now + (state === undefined ? UNKNOWN_REFRESH_MS : OPEN_REFRESH_MS);
|
|
90
93
|
}
|
|
94
|
+
const asked = [...batch.map((entry) => entry.ref.url), ...verified.map((ref) => ref.url)];
|
|
95
|
+
const learned = facts.apply(asked, result, now + UNKNOWN_REFRESH_MS);
|
|
96
|
+
for (const url of learned.urls)
|
|
97
|
+
changed.add(url);
|
|
91
98
|
if (result.limitReached !== undefined) {
|
|
92
99
|
const ms = rateLimitPause(result.limitReached.resetAt);
|
|
93
100
|
pause(ms);
|
|
94
101
|
safeLog(`pr-status: GitHub rate limit reached, paused for ${minutes(ms)} min`);
|
|
95
102
|
}
|
|
96
|
-
if (changed.size === 0)
|
|
103
|
+
if (changed.size === 0 && !learned.viewerChanged)
|
|
97
104
|
return;
|
|
98
105
|
try {
|
|
99
|
-
opts.onChange(changed);
|
|
106
|
+
opts.onChange({ urls: changed, viewerChanged: learned.viewerChanged });
|
|
100
107
|
}
|
|
101
108
|
catch {
|
|
102
109
|
// The caller's failure must not stop the rhythm.
|
|
@@ -121,7 +128,8 @@ export function createPrStatusTracker(opts) {
|
|
|
121
128
|
.filter((entry) => entry.dueAt <= now)
|
|
122
129
|
.sort((a, b) => a.dueAt - b.dueAt)
|
|
123
130
|
.slice(0, PR_BATCH_MAX);
|
|
124
|
-
|
|
131
|
+
const verified = facts.due(now, PR_BATCH_MAX - batch.length, new Set(batch.map((entry) => entry.ref.url)));
|
|
132
|
+
if (batch.length === 0 && verified.length === 0) {
|
|
125
133
|
schedule();
|
|
126
134
|
return;
|
|
127
135
|
}
|
|
@@ -129,7 +137,7 @@ export function createPrStatusTracker(opts) {
|
|
|
129
137
|
reading = controller;
|
|
130
138
|
let read;
|
|
131
139
|
try {
|
|
132
|
-
read = opts.source.read(batch.map((entry) => entry.ref), controller.signal);
|
|
140
|
+
read = opts.source.read([...batch.map((entry) => entry.ref), ...verified], controller.signal);
|
|
133
141
|
}
|
|
134
142
|
catch {
|
|
135
143
|
read = Promise.resolve({ ok: false, failure: 'error' });
|
|
@@ -139,7 +147,7 @@ export function createPrStatusTracker(opts) {
|
|
|
139
147
|
.then((result) => {
|
|
140
148
|
reading = null;
|
|
141
149
|
if (!closed)
|
|
142
|
-
apply(batch, result);
|
|
150
|
+
apply(batch, verified, result);
|
|
143
151
|
})
|
|
144
152
|
.catch(() => {
|
|
145
153
|
reading = null;
|
|
@@ -169,6 +177,8 @@ export function createPrStatusTracker(opts) {
|
|
|
169
177
|
};
|
|
170
178
|
return {
|
|
171
179
|
stateOf: (url) => entries.get(url)?.state,
|
|
180
|
+
factsOf: (url) => facts.factsOf(url),
|
|
181
|
+
viewerLogin: () => facts.viewerLogin(),
|
|
172
182
|
setSessionUrls: (sessionId, urls) => {
|
|
173
183
|
if (closed)
|
|
174
184
|
return;
|
|
@@ -180,10 +190,23 @@ export function createPrStatusTracker(opts) {
|
|
|
180
190
|
// Keeps the previous list; nothing to undo.
|
|
181
191
|
}
|
|
182
192
|
},
|
|
193
|
+
setSessionLinks: (sessionId, urls) => {
|
|
194
|
+
if (closed)
|
|
195
|
+
return;
|
|
196
|
+
try {
|
|
197
|
+
facts.setSessionLinks(sessionId, urls, scheduler.now() + newUrlDelayMs);
|
|
198
|
+
schedule();
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
// Keeps the previous linked set; nothing to undo.
|
|
202
|
+
}
|
|
203
|
+
},
|
|
183
204
|
dropSession: (sessionId) => {
|
|
184
205
|
if (closed)
|
|
185
206
|
return;
|
|
186
|
-
|
|
207
|
+
const listed = sessions.delete(sessionId);
|
|
208
|
+
const linked = facts.dropSession(sessionId);
|
|
209
|
+
if (listed || linked)
|
|
187
210
|
sync();
|
|
188
211
|
},
|
|
189
212
|
setClientConnected: (value) => {
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The main checkout of a directory inside a linked git worktree, read from the `.git` file and `commondir` without
|
|
3
|
+
* running `git`. Reads go through a port that resolves links and reads text, so the caller decides what a read may
|
|
4
|
+
* see and when a changed file stops the read. A layout the function cannot read unambiguously comes back as "no
|
|
5
|
+
* proof" with the `.git` path; the caller turns it into its own refusal.
|
|
6
|
+
*
|
|
7
|
+
* `ProjectRoots` is that read for session summaries: on the work-area disk port, only for a main checkout inside the
|
|
8
|
+
* work area, with conclusive answers remembered per directory until the session's git watcher reports a change. It
|
|
9
|
+
* never runs `git` and never writes.
|
|
10
|
+
*/
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import { areaDiskOf, inExcludedOnDisk, inWorkAreaOnDisk } from './config/work-area.js';
|
|
13
|
+
import { DIRECT_DISK } from './folder-gate/disk.js';
|
|
14
|
+
import { DISK_LAYOUT } from './herdr/commands/registry.js';
|
|
15
|
+
/** Linked worktree gita: plik `.git` z jedną linią `gitdir: <katalog>`, a w tym katalogu `commondir`. */
|
|
16
|
+
const GIT_FILE_PREFIX = 'gitdir: ';
|
|
17
|
+
const GIT_COMMONDIR = 'commondir';
|
|
18
|
+
/** Katalog i wszystkie wyżej, od niego do korzenia. */
|
|
19
|
+
export function upwards(dir) {
|
|
20
|
+
const out = [];
|
|
21
|
+
let current = path.resolve(dir);
|
|
22
|
+
for (;;) {
|
|
23
|
+
out.push(current);
|
|
24
|
+
const parent = path.dirname(current);
|
|
25
|
+
if (parent === current)
|
|
26
|
+
return out;
|
|
27
|
+
current = parent;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Główny checkout dla `cwd` w linked worktree gita albo `null` (opis modułu; dokumentacja Claude Code: settings,
|
|
32
|
+
* „Where Claude Code keeps the local file in a git repository”; worktrees, „What worktrees share with the main
|
|
33
|
+
* checkout”). Najbliższy `.git` od `cwd` w górę: katalog = zwykły checkout (`null`); plik = jedna linia
|
|
34
|
+
* `gitdir: <katalog>` (ścieżka bezwzględna albo względna wobec katalogu pliku), a w tym katalogu `commondir` ze
|
|
35
|
+
* wspólnym katalogiem repozytorium; bez `commondir` to nie worktree (submoduł, `--separate-git-dir`), korzeniem jest
|
|
36
|
+
* katalog z plikiem `.git`. Wspólny katalog musi się nazywać `.git`, główny checkout to katalog nad nim; repozytorium
|
|
37
|
+
* bare, `gitdir` bez katalogu i każdy inny układ = brak dowodu. Odczyt bez uruchamiania `git`; pliki `.git` i
|
|
38
|
+
* `commondir` przechodzą przez sprawdzenie startu, katalogi gita nie (zmieniają się przy każdej operacji gita),
|
|
39
|
+
* dowiązania tak.
|
|
40
|
+
*/
|
|
41
|
+
export async function mainCheckoutOf(reader, cwd) {
|
|
42
|
+
for (const dir of upwards(cwd)) {
|
|
43
|
+
const dotGit = path.join(dir, DISK_LAYOUT.gitDir);
|
|
44
|
+
const found = await reader.linked(dotGit);
|
|
45
|
+
if (found.info === null)
|
|
46
|
+
continue;
|
|
47
|
+
if (found.info.kind === 'dir')
|
|
48
|
+
return { ok: true, root: null };
|
|
49
|
+
const lines = (await reader.text(dotGit) ?? '').split('\n').filter((line) => line.trim() !== '');
|
|
50
|
+
const line = lines.length === 1 ? lines[0] ?? '' : '';
|
|
51
|
+
const target = line.startsWith(GIT_FILE_PREFIX) ? line.slice(GIT_FILE_PREFIX.length).trim() : '';
|
|
52
|
+
if (target === '')
|
|
53
|
+
return { ok: false, dotGit };
|
|
54
|
+
const gitDir = await reader.linked(path.isAbsolute(target) ? target : `${path.dirname(found.real)}/${target}`);
|
|
55
|
+
if (gitDir.info?.kind !== 'dir')
|
|
56
|
+
return { ok: false, dotGit };
|
|
57
|
+
const common = (await reader.text(path.join(gitDir.real, GIT_COMMONDIR)))?.trim();
|
|
58
|
+
if (common === undefined)
|
|
59
|
+
return { ok: true, root: null };
|
|
60
|
+
if (common === '' || common.includes('\n'))
|
|
61
|
+
return { ok: false, dotGit };
|
|
62
|
+
const commonDir = await reader.linked(path.isAbsolute(common) ? common : `${gitDir.real}/${common}`);
|
|
63
|
+
if (commonDir.info?.kind !== 'dir' || path.basename(commonDir.real) !== DISK_LAYOUT.gitDir) {
|
|
64
|
+
return { ok: false, dotGit };
|
|
65
|
+
}
|
|
66
|
+
return { ok: true, root: path.dirname(commonDir.real) };
|
|
67
|
+
}
|
|
68
|
+
return { ok: true, root: null };
|
|
69
|
+
}
|
|
70
|
+
/** Ceiling of a `.git` file and of `commondir`: one path, not kilobytes. A longer file is not a git pointer. */
|
|
71
|
+
const POINTER_MAX_BYTES = 4 * 1024;
|
|
72
|
+
/** Codes of a lookup that finds nothing under the path. */
|
|
73
|
+
const NOTHING_UNDER_PATH = new Set(['ENOENT', 'ENOTDIR']);
|
|
74
|
+
const nothingUnder = (error) => NOTHING_UNDER_PATH.has(error.code ?? '');
|
|
75
|
+
/**
|
|
76
|
+
* The read port of {@link mainCheckoutOf} on a work-area disk. A symlink in the last segment of a pointer path
|
|
77
|
+
* (`.git`, the `gitdir` target, the shared directory) stops the read, because such a link could put a session under
|
|
78
|
+
* any repository's main checkout; links earlier on the path resolve. Pointer files are read only as regular files
|
|
79
|
+
* within {@link POINTER_MAX_BYTES} and never through a link, so a FIFO under the name cannot hold the read.
|
|
80
|
+
*/
|
|
81
|
+
function checkoutReaderOf(disk) {
|
|
82
|
+
return {
|
|
83
|
+
async linked(file) {
|
|
84
|
+
let entry;
|
|
85
|
+
try {
|
|
86
|
+
entry = await disk.call('lstat', { path: file });
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
if (nothingUnder(error))
|
|
90
|
+
return { real: file, info: null };
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
if (entry.isSymbolicLink())
|
|
94
|
+
throw new Error(`a symlink stands at ${file}`);
|
|
95
|
+
const kind = entry.isDirectory() ? 'dir' : entry.isFile() ? 'file' : 'other';
|
|
96
|
+
return { real: await disk.call('realpath', { path: file }), info: { kind } };
|
|
97
|
+
},
|
|
98
|
+
async text(file) {
|
|
99
|
+
let head;
|
|
100
|
+
try {
|
|
101
|
+
head = await disk.call('readHead', { path: file, maxBytes: POINTER_MAX_BYTES, followSymlink: false });
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
if (nothingUnder(error))
|
|
105
|
+
return null;
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
if (head === null || head.truncated)
|
|
109
|
+
throw new Error(`not a git pointer file: ${file}`);
|
|
110
|
+
return head.bytes.toString('utf8');
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
const REFUSED = { kind: 'refused' };
|
|
115
|
+
/**
|
|
116
|
+
* The main checkout a session in `cwd` belongs to, for its summary (`projectRoot`); `undefined` for a directory that
|
|
117
|
+
* is a main checkout itself, lies in no repository, in a submodule, or belongs to a main checkout outside the work
|
|
118
|
+
* area, where actions of the project's group would reach a directory the server does not serve.
|
|
119
|
+
*
|
|
120
|
+
* Reads go through the work-area disk port, so a guarded folder that is closed refuses them without a macOS consent
|
|
121
|
+
* window; a directory in an excluded or closed folder is refused before any read. A conclusive answer (a main
|
|
122
|
+
* checkout, or none) is remembered by the real path of the directory, so other spellings of it share the answer. A
|
|
123
|
+
* git watcher event ({@link forget}) reads again at once and serves the old answer until the new one settles, so
|
|
124
|
+
* the session does not leave its group between the two. A refusal or a failed read is not remembered: the next
|
|
125
|
+
* summary reads again, which is how a folder that opens later gives the field.
|
|
126
|
+
*/
|
|
127
|
+
export class ProjectRoots {
|
|
128
|
+
#roots;
|
|
129
|
+
#home;
|
|
130
|
+
#disk;
|
|
131
|
+
#changed;
|
|
132
|
+
#known = new Map();
|
|
133
|
+
#pending = new Map();
|
|
134
|
+
#reads = 0;
|
|
135
|
+
constructor(config) {
|
|
136
|
+
this.#roots = config.roots;
|
|
137
|
+
this.#home = config.home;
|
|
138
|
+
this.#disk = config.disk ?? DIRECT_DISK;
|
|
139
|
+
this.#changed = config.changed;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* The answer for a summary, without waiting: the remembered main checkout of `cwd`, or `undefined`. A directory
|
|
143
|
+
* without a fresh answer starts a read unless one runs; when it settles with another answer, `changed` gets `cwd`.
|
|
144
|
+
*/
|
|
145
|
+
peek(cwd) {
|
|
146
|
+
const key = this.#keyOf(cwd);
|
|
147
|
+
const known = this.#known.get(key);
|
|
148
|
+
if (known === undefined || known.stale)
|
|
149
|
+
void this.#start(cwd, key, false);
|
|
150
|
+
return known?.root ?? undefined;
|
|
151
|
+
}
|
|
152
|
+
/** The main checkout of `cwd` now: the remembered fresh answer, else the read in flight or a new one. */
|
|
153
|
+
read(cwd) {
|
|
154
|
+
const key = this.#keyOf(cwd);
|
|
155
|
+
const known = this.#known.get(key);
|
|
156
|
+
if (known !== undefined && !known.stale)
|
|
157
|
+
return Promise.resolve(known.root ?? undefined);
|
|
158
|
+
return this.#start(cwd, key, false);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* The git watcher saw a change in the repositories of these session directories: each one with an answer or a read
|
|
162
|
+
* in flight reads again now; a read already in flight may have missed the change, so its answer is dropped.
|
|
163
|
+
*/
|
|
164
|
+
forget(cwds) {
|
|
165
|
+
for (const cwd of cwds) {
|
|
166
|
+
const key = this.#keyOf(cwd);
|
|
167
|
+
const known = this.#known.get(key);
|
|
168
|
+
if (known === undefined && !this.#pending.has(key))
|
|
169
|
+
continue;
|
|
170
|
+
if (known !== undefined)
|
|
171
|
+
known.stale = true;
|
|
172
|
+
void this.#start(cwd, key, true);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/** The real path of `cwd` (metadata only, never waits for a consent window); as written when it does not resolve. */
|
|
176
|
+
#keyOf(cwd) {
|
|
177
|
+
try {
|
|
178
|
+
return this.#disk.sync('realpath', { path: cwd });
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
return path.resolve(cwd);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/** Joins the read in flight for `key`, or starts one; `restart` starts a new one that takes over its askers. */
|
|
185
|
+
#start(cwd, key, restart) {
|
|
186
|
+
const running = this.#pending.get(key);
|
|
187
|
+
if (running !== undefined && !restart) {
|
|
188
|
+
running.askers.add(cwd);
|
|
189
|
+
return running.answer;
|
|
190
|
+
}
|
|
191
|
+
this.#reads += 1;
|
|
192
|
+
const id = this.#reads;
|
|
193
|
+
const askers = new Set(running?.askers ?? []).add(cwd);
|
|
194
|
+
const answer = this.#lookUp(cwd).then((verdict) => this.#settle(key, id, verdict));
|
|
195
|
+
this.#pending.set(key, { id, askers, answer });
|
|
196
|
+
return answer;
|
|
197
|
+
}
|
|
198
|
+
/** Remembers a conclusive answer, drops a refused one, and tells the askers when the served answer changed. */
|
|
199
|
+
#settle(key, id, verdict) {
|
|
200
|
+
const found = verdict.kind === 'root' ? verdict.root : null;
|
|
201
|
+
const pending = this.#pending.get(key);
|
|
202
|
+
if (pending?.id !== id)
|
|
203
|
+
return found ?? undefined;
|
|
204
|
+
this.#pending.delete(key);
|
|
205
|
+
const served = this.#known.get(key)?.root ?? null;
|
|
206
|
+
if (verdict.kind === 'root')
|
|
207
|
+
this.#known.set(key, { root: verdict.root, stale: false });
|
|
208
|
+
else
|
|
209
|
+
this.#known.delete(key);
|
|
210
|
+
if (found !== served)
|
|
211
|
+
for (const cwd of pending.askers)
|
|
212
|
+
this.#changed(cwd);
|
|
213
|
+
return found ?? undefined;
|
|
214
|
+
}
|
|
215
|
+
async #lookUp(cwd) {
|
|
216
|
+
try {
|
|
217
|
+
if (!path.isAbsolute(cwd))
|
|
218
|
+
return REFUSED;
|
|
219
|
+
const area = areaDiskOf(this.#disk);
|
|
220
|
+
if (inExcludedOnDisk(cwd, this.#roots, this.#home, area))
|
|
221
|
+
return REFUSED;
|
|
222
|
+
const main = await mainCheckoutOf(checkoutReaderOf(this.#disk), cwd);
|
|
223
|
+
if (!main.ok)
|
|
224
|
+
return REFUSED;
|
|
225
|
+
if (main.root === null)
|
|
226
|
+
return { kind: 'root', root: null };
|
|
227
|
+
return inWorkAreaOnDisk(main.root, this.#roots, this.#home, area) ? { kind: 'root', root: main.root } : REFUSED;
|
|
228
|
+
}
|
|
229
|
+
catch {
|
|
230
|
+
return REFUSED;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MAX_FILES_PER_MESSAGE, MAX_IMAGES_PER_MESSAGE, MAX_MESSAGE_BODY_BYTES, checkMessageImageLimits, closeBodySchema, createSessionBodySchema, permissionDecisionBodySchema, sessionModeBodySchema, sessionModelBodySchema, } from '@rarog/shared';
|
|
1
|
+
import { MAX_FILES_PER_MESSAGE, MAX_IMAGES_PER_MESSAGE, MAX_MESSAGE_BODY_BYTES, checkMessageImageLimits, closeBodySchema, createSessionBodySchema, dialogKeyBodySchema, permissionDecisionBodySchema, sessionModeBodySchema, sessionModelBodySchema, } from '@rarog/shared';
|
|
2
2
|
import { COMPANION_BUSY_ERROR, COMPANION_CLI_ERROR, COMPANION_DISABLED_ERROR, COMPANION_LIMIT_ERROR, COMPANION_SESSIONS_DISABLED_ERROR, COMPANION_TIMEOUT_ERROR, companionTurnsCountSchema, answersBodySchema, companionAskBodySchema, messageBodySchema, queueTakeBackBodySchema, restartBodySchema, seenBodySchema, } from '@rarog/shared/rest';
|
|
3
3
|
import { say } from '@rarog/shared/sentences';
|
|
4
4
|
import { redact } from '../auth/index.js';
|
|
@@ -6,9 +6,11 @@ import { sendDownload } from '../files/send-file.js';
|
|
|
6
6
|
import { conversationToken } from '../companion/conversation.js';
|
|
7
7
|
import { readSettledTurns } from '../companion/turns-settle.js';
|
|
8
8
|
import { clientLabel, diffErrorStatus, managerErrorStatus, methodNotAllowed, parseBody, readJsonBody, readValidatedBody, recheckDevice, sendError, sendFailure, sendJson, } from '../router.js';
|
|
9
|
+
import { branchDiffFile, branchDiffFiles } from '../sessions/branch-diff.js';
|
|
9
10
|
import { parseLastEventId } from '../sse.js';
|
|
10
11
|
import { decodeSegment } from './context.js';
|
|
11
12
|
import { checkCwd } from './projects.js';
|
|
13
|
+
import { isStateOnlyEngine } from '../herdr/engines.js';
|
|
12
14
|
/**
|
|
13
15
|
* Sprawdza model podany przez klienta wobec allow-listy serwera.
|
|
14
16
|
*
|
|
@@ -113,6 +115,29 @@ const sendDecision = (res, result) => {
|
|
|
113
115
|
}
|
|
114
116
|
sendError(res, 410, 'gone', say('rest.decision-expired'));
|
|
115
117
|
};
|
|
118
|
+
/**
|
|
119
|
+
* The outcome of a live card key as the answer of `POST /api/sessions/:id/dialog-key`: 200 `{live}` (the key went),
|
|
120
|
+
* 409 (no live card), 410 `stale-card` (another or a used occurrence), 422 with the refusal body of a decision (no key
|
|
121
|
+
* went, or `send-failed`: the key may have reached the pane and never goes again), 503 (the write channel is closed).
|
|
122
|
+
*/
|
|
123
|
+
const sendDialogKey = (res, outcome) => {
|
|
124
|
+
switch (outcome.kind) {
|
|
125
|
+
case 'sent':
|
|
126
|
+
sendJson(res, 200, { live: outcome.live });
|
|
127
|
+
return;
|
|
128
|
+
case 'not-shown':
|
|
129
|
+
sendError(res, 409, 'no-live-card', say('dialogs.refuse.stale-card'));
|
|
130
|
+
return;
|
|
131
|
+
case 'stale':
|
|
132
|
+
sendError(res, 410, 'stale-card', say('dialogs.refuse.stale-card'));
|
|
133
|
+
return;
|
|
134
|
+
case 'refused':
|
|
135
|
+
sendError(res, 422, 'refused', say(`dialogs.refuse.${outcome.reason}`), { reason: outcome.reason });
|
|
136
|
+
return;
|
|
137
|
+
case 'send-off':
|
|
138
|
+
sendError(res, 503, 'herdr-send-off', say('session.herdr-read-only'));
|
|
139
|
+
}
|
|
140
|
+
};
|
|
116
141
|
/**
|
|
117
142
|
* Uruchamia akcję managera i mapuje wyjątki na 404/409/500.
|
|
118
143
|
*
|
|
@@ -243,6 +268,34 @@ export async function routeSessions(ctx, req, res, rq) {
|
|
|
243
268
|
sendJson(res, 200, answer);
|
|
244
269
|
return true;
|
|
245
270
|
}
|
|
271
|
+
/*
|
|
272
|
+
* The branch diff of a coordinator's thread (`sessions/branch-diff.ts`): `GET …/branch-diff/files` (files and
|
|
273
|
+
* commits of the branch past its base) and `GET …/branch-diff/file?path=…` (one file's patch), refusing with the
|
|
274
|
+
* codes of the routes above; a session that is no thread of a project gets 400 `bad-request` with a sentence.
|
|
275
|
+
*/
|
|
276
|
+
if (action === 'branch-diff' && segments.length === 5 && (segments[4] === 'files' || segments[4] === 'file')) {
|
|
277
|
+
if (method !== 'GET')
|
|
278
|
+
return methodNotAllowed(res, 'GET');
|
|
279
|
+
const port = manager.branchDiffPort();
|
|
280
|
+
let answer;
|
|
281
|
+
try {
|
|
282
|
+
answer = segments[4] === 'files'
|
|
283
|
+
? await branchDiffFiles(sessionId, port)
|
|
284
|
+
: await branchDiffFile(sessionId, url.searchParams.get('path') ?? '', port);
|
|
285
|
+
}
|
|
286
|
+
catch (err) {
|
|
287
|
+
const status = diffErrorStatus(err);
|
|
288
|
+
if (status === 500)
|
|
289
|
+
log.error(`manager action failed: ${redact(err, secrets)}`);
|
|
290
|
+
if (!res.headersSent)
|
|
291
|
+
sendFailure(res, status, err, 'diff');
|
|
292
|
+
return true;
|
|
293
|
+
}
|
|
294
|
+
if (!recheckDevice(req, res, 'while reading the branch diff of'))
|
|
295
|
+
return true;
|
|
296
|
+
sendJson(res, 200, answer);
|
|
297
|
+
return true;
|
|
298
|
+
}
|
|
246
299
|
/*
|
|
247
300
|
* GET /api/sessions/:id/files?dir=<rel> → one directory of the session (`files/session-files.ts`): the gate of the
|
|
248
301
|
* file routes, the listing, git's `ignored` labels. With `RAROG_FILES=0` the route does not exist: 404 as an
|
|
@@ -447,7 +500,7 @@ export async function routeSessions(ctx, req, res, rq) {
|
|
|
447
500
|
const session = manager.get(sessionId);
|
|
448
501
|
// Sesja poza zasięgiem i wpis Codexa nie oddają niczego z katalogu panelu: to ta
|
|
449
502
|
// sama granica co transkrypt i diff, a czytnik nie jest o nic pytany.
|
|
450
|
-
const closed = session === undefined || session.outOfScope === true || session.engine
|
|
503
|
+
const closed = session === undefined || session.outOfScope === true || isStateOnlyEngine(session.engine);
|
|
451
504
|
const image = closed || deps.readUpload === undefined
|
|
452
505
|
? null
|
|
453
506
|
: await deps.readUpload(session.cwd, decodeSegment(segments[4] ?? ''));
|
|
@@ -783,6 +836,19 @@ export async function routeSessions(ctx, req, res, rq) {
|
|
|
783
836
|
}
|
|
784
837
|
return true;
|
|
785
838
|
}
|
|
839
|
+
/*
|
|
840
|
+
* POST /api/sessions/:id/dialog-key {id, rev, key}: one key of the live dialog card (`docs/dialogs.md`, "Live
|
|
841
|
+
* dialog card"). The manager answers 404, 409 during a restart and 400 outside the work area with its sentence;
|
|
842
|
+
* the outcome of the key maps in `sendDialogKey`. No retry on the server's side: a key goes at most once.
|
|
843
|
+
*/
|
|
844
|
+
if (action === 'dialog-key' && segments.length === 4) {
|
|
845
|
+
const body = await readValidatedBody(req, res, config, dialogKeyBodySchema);
|
|
846
|
+
if (body === null)
|
|
847
|
+
return true;
|
|
848
|
+
return runManagerAction(res, log, secrets, async () => {
|
|
849
|
+
sendDialogKey(res, await manager.dialogKey(sessionId, body));
|
|
850
|
+
}, 'message');
|
|
851
|
+
}
|
|
786
852
|
if (action === 'permissions' && segments.length === 5) {
|
|
787
853
|
const permId = decodeSegment(segments[4] ?? '');
|
|
788
854
|
const body = await readValidatedBody(req, res, config, permissionDecisionBodySchema);
|