@rarog/server 1.0.1 → 1.1.0
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/README.md +18 -5
- package/node_modules/@rarog/shared/package.json +1 -1
- package/node_modules/@rarog/shared/src/decode.js +64 -3
- package/node_modules/@rarog/shared/src/protocol/files.js +33 -0
- package/node_modules/@rarog/shared/src/protocol/folders.js +27 -0
- package/node_modules/@rarog/shared/src/protocol/herdr.js +23 -0
- package/node_modules/@rarog/shared/src/protocol/inbox.js +38 -0
- package/node_modules/@rarog/shared/src/protocol/notes.js +7 -1
- package/node_modules/@rarog/shared/src/protocol.js +20 -47
- package/node_modules/@rarog/shared/src/rest.js +106 -12
- package/node_modules/@rarog/shared/src/sentences/herdr.js +0 -4
- package/node_modules/@rarog/shared/src/sentences/index.js +7 -1
- package/node_modules/@rarog/shared/src/sentences/rest.js +21 -0
- package/package.json +3 -3
- package/server/src/auth/admin.js +3 -1
- package/server/src/bootstrap/consent.js +99 -2
- package/server/src/bootstrap/folder-gate.js +55 -0
- package/server/src/bootstrap/http.js +3 -2
- package/server/src/bootstrap/inbox.js +29 -4
- package/server/src/bootstrap/sse.js +2 -1
- package/server/src/cli/doctor-no-hook.js +162 -0
- package/server/src/cli/doctor.js +2 -0
- package/server/src/cli/service-log.js +27 -0
- package/server/src/cli/service.js +5 -2
- package/server/src/cli/templates/launchd.plist +1 -1
- package/server/src/cli/templates/rarog.service +1 -1
- package/server/src/cli/update-channel.js +100 -0
- package/server/src/cli/update-provenance.js +37 -19
- package/server/src/cli/update-registry.js +160 -62
- package/server/src/cli/update.js +13 -3
- package/server/src/companion/turns-settle.js +4 -1
- package/server/src/companion/turns.js +36 -5
- package/server/src/config/files.js +32 -0
- package/server/src/config/flags.js +10 -1
- package/server/src/config/protected-dirs.js +2 -0
- package/server/src/config/roots.js +13 -8
- package/server/src/config/work-area.js +36 -12
- package/server/src/config-env.js +33 -0
- package/server/src/config.js +22 -2
- package/server/src/demo/control.js +9 -1
- package/server/src/demo/files.js +49 -0
- package/server/src/demo/inbox.js +73 -0
- package/server/src/demo/review-routes.js +6 -1
- package/server/src/device-effects.js +3 -1
- package/server/src/drivers/herdr/consent-no-hook-io.js +89 -0
- package/server/src/drivers/herdr/consent-no-hook.js +411 -0
- package/server/src/drivers/herdr/refusals.js +226 -0
- package/server/src/drivers/herdr/returned-prompt.js +172 -0
- package/server/src/drivers/herdr/screen-fallback.js +246 -0
- package/server/src/drivers/herdr-driver.js +193 -295
- package/server/src/files/file-index.js +248 -0
- package/server/src/files/ignored.js +119 -0
- package/server/src/files/listing.js +82 -0
- package/server/src/files/path-rule.js +199 -0
- package/server/src/files/refusals.js +50 -0
- package/server/src/files/send-file.js +115 -0
- package/server/src/files/session-download.js +51 -0
- package/server/src/files/session-files.js +38 -0
- package/server/src/files/session-gate.js +53 -0
- package/server/src/folder-gate/client.js +314 -0
- package/server/src/folder-gate/disk.js +455 -0
- package/server/src/folder-gate/folders.js +23 -0
- package/server/src/folder-gate/gate.js +220 -0
- package/server/src/folder-gate/helper.js +118 -0
- package/server/src/folder-gate/install.js +27 -0
- package/server/src/folder-gate/relay-worker.js +147 -0
- package/server/src/folder-gate/types.js +115 -0
- package/server/src/folder-gate/wire.js +170 -0
- package/server/src/fs-browse.js +55 -23
- package/server/src/fs-mkdir.js +3 -1
- package/server/src/git-status.js +16 -7
- package/server/src/git-watch.js +130 -19
- package/server/src/git-work-tree.js +3 -3
- package/server/src/herdr/audit.js +1 -1
- package/server/src/herdr/client.js +2 -2
- package/server/src/herdr/commands/discover.js +21 -9
- package/server/src/herdr/dialogs/consent-gate.js +28 -8
- package/server/src/herdr/dialogs/decide/sources.js +5 -2
- package/server/src/herdr/dialogs/hook/contract.js +16 -9
- package/server/src/herdr/dialogs/index.js +12 -2
- package/server/src/herdr/dialogs/layer1/cycle.js +43 -7
- package/server/src/herdr/dialogs/layer1/hook-list/hook-list.js +166 -86
- package/server/src/herdr/dialogs/layer1/hook-list/session-facts.js +135 -0
- package/server/src/herdr/dialogs/layer1/screen-key.js +52 -0
- package/server/src/herdr/dialogs/layer1/version-gate.js +13 -5
- package/server/src/herdr/dialogs/no-hook.js +63 -0
- package/server/src/herdr/dialogs/router.js +21 -6
- package/server/src/herdr/dialogs/screen/block.js +10 -0
- package/server/src/herdr/dialogs/screen/parse.js +33 -3
- package/server/src/herdr/dialogs/screen/resolve.js +9 -7
- package/server/src/herdr/dialogs/screen-fallback.js +55 -0
- package/server/src/herdr/dialogs/shadow/alive.js +9 -8
- package/server/src/herdr/jsonl-follow.js +55 -14
- package/server/src/herdr/jsonl-pending.js +25 -1
- package/server/src/herdr/provenance.js +3 -3
- package/server/src/herdr/socket.js +25 -28
- package/server/src/herdr/supervisor.js +13 -10
- package/server/src/herdr/transcript-path.js +36 -0
- package/server/src/herdr/trust.js +11 -8
- package/server/src/herdr/uploads-registry.js +3 -2
- package/server/src/herdr/uploads.js +170 -47
- package/server/src/inbox/card.js +18 -9
- package/server/src/inbox/dialogs.js +40 -12
- package/server/src/inbox/heads.js +55 -0
- package/server/src/inbox/inbox.js +24 -2
- package/server/src/inbox/index.js +3 -1
- package/server/src/index.js +44 -21
- package/server/src/install/repair.js +8 -0
- package/server/src/iroh/listener.js +3 -0
- package/server/src/iroh/log-budget.js +1 -0
- package/server/src/iroh/socket.js +2 -1
- package/server/src/log-timestamps.js +9 -4
- package/server/src/notes/store.js +3 -2
- package/server/src/router.js +20 -2
- package/server/src/routes/devices.js +2 -2
- package/server/src/routes/inbox.js +91 -0
- package/server/src/routes/projects.js +5 -1
- package/server/src/routes/sessions.js +145 -18
- package/server/src/routes/system.js +9 -4
- package/server/src/safe-read.js +86 -1
- package/server/src/sessions/companion-scope.js +16 -7
- package/server/src/sessions/demo-modules.js +16 -0
- package/server/src/sessions/diff-measure.js +30 -0
- package/server/src/sessions/done-retention.js +57 -0
- package/server/src/sessions/launch-gate.js +2 -2
- package/server/src/sessions/manager.js +78 -190
- package/server/src/sessions/project-scan.js +9 -3
- package/server/src/sessions/ring-buffer.js +5 -3
- package/server/src/sessions/seen-marks.js +9 -6
- package/server/src/sessions/session-git.js +31 -2
- package/server/src/sessions/session-scope.js +30 -0
- package/server/src/sessions/session.js +19 -0
- package/server/src/sessions/state-sentences.js +1 -1
- package/server/src/sessions/waiting-line.js +72 -0
- package/server/src/sse.js +143 -10
- package/server/src/term/herdr-backend.js +2 -2
- package/server/src/term/index.js +2 -15
- package/server/src/term/registry.js +4 -3
- package/server/src/term/ws.js +9 -1
- package/server/src/version.js +30 -0
package/README.md
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
# Rarog
|
|
2
2
|
|
|
3
|
-
Rarog is
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Rarog is a free, open-source (MIT) iPhone and iPad app, plus a server on your Mac or Linux machine, that shows the
|
|
4
|
+
Claude Code sessions running in Herdr TUI and lets you drive them. Herdr ([herdr.dev](https://herdr.dev)) is
|
|
5
|
+
a terminal multiplexer. From the phone you follow every session, answer its permission prompts and questions, and
|
|
6
|
+
send it prompts, photos and files.
|
|
6
7
|
|
|
7
8
|
## What it is
|
|
8
9
|
|
|
@@ -39,8 +40,9 @@ Threat model, killswitches (flags that switch capabilities off) and how to repor
|
|
|
39
40
|
- npm 11 or newer, or pnpm, for the npm package; pnpm 11.4.0 for a clone (`packageManager` in `package.json`).
|
|
40
41
|
- Claude Code (`claude`), signed in with `/login`. Do not export `CLAUDE_CODE_OAUTH_TOKEN` or Anthropic API keys in
|
|
41
42
|
interactive shells (for example in `~/.zshrc`): a session would use them instead of that login.
|
|
42
|
-
- herdr (`herdr` in `PATH` or `~/.local/bin/herdr`) with API protocol 22 (herdr 0.9.0 to
|
|
43
|
-
protocol Rarog does not work
|
|
43
|
+
- herdr (`herdr` in `PATH` or `~/.local/bin/herdr`) with API protocol 22 or newer (tested on 22, herdr 0.9.0 to
|
|
44
|
+
0.9.5). With an older protocol Rarog does not work. A newer one is untested, and Rarog works on it fully;
|
|
45
|
+
`RAROG_HERDR_SEND=0` keeps Rarog read-only on such a herdr.
|
|
44
46
|
- A way for the app to reach the server: the iroh listener, where the native iroh module installs (Apple silicon,
|
|
45
47
|
Linux x64 and arm64), or an HTTPS address in a private network: Tailscale (`rarog setup` maps it with
|
|
46
48
|
`tailscale serve`) or your own reverse proxy with TLS. An Intel Mac has no iroh module, so it needs the HTTPS
|
|
@@ -130,6 +132,17 @@ checks the installation, and `rarog help` lists every command. Dictation needs `
|
|
|
130
132
|
`~/.config/rarog/secret/private.env` (directory 0700, file 0600). By default the server keeps its state and its log
|
|
131
133
|
`server.log` in `~/.local/share/rarog`.
|
|
132
134
|
|
|
135
|
+
## Updating
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
rarog update # the newest release; rarog update --beta also takes a newer beta
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
`rarog update` installs the newest release from the npm registry with npm, in a terminal, and finishes it: the
|
|
142
|
+
Claude SDK, the service, the hook copy and a restart. A rollback is `npm i -g @rarog/server@<version>`, then
|
|
143
|
+
`rarog update --finish`. An installation made with pnpm updates by other steps; they and the details are in
|
|
144
|
+
[docs/distribution.md](docs/distribution.md), section "Install from the npm registry".
|
|
145
|
+
|
|
133
146
|
## Where next
|
|
134
147
|
|
|
135
148
|
Documentation index: [docs/README.md](docs/README.md). Good starting points:
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* złotych ramek (`shared/test/sse-fixtures.test.ts` sprawdza nim `degrades`, które czyta Swift).
|
|
23
23
|
*/
|
|
24
24
|
import { z } from 'zod';
|
|
25
|
-
import { activityEventSchema, activitySchema, backgroundTaskSchema, blockSchema, contextLimitStateSchema, deltaEventSchema, gitFileDetailSchema, gitStatusEventSchema, helloEventSchema, herdrStatusEventSchema, messageAttachmentSchema, messageEventSchema, notesEventSchema, parseServerEvent, permissionPendingEventSchema, permissionRequestObjectSchema, permissionRequestSchema, permissionResolvedEventSchema, permissionSettledEventSchema, questionOptionSchema, questionPendingEventSchema, questionRequestSchema, questionSchema, questionResolvedEventSchema, sessionChangedEventSchema, sessionPullRequestSchema, sessionsSnapshotEventSchema, sessionSummarySchema, stateEventSchema, transcriptMessageSchema, transcriptNoticeSchema, transcriptSnapshotEventSchema, usageEventSchema, toolCallBlockObjectSchema, waitingForSchema, withDetailTruncation, withDisplayTextTruncation, } from './protocol.js';
|
|
25
|
+
import { activityEventSchema, activitySchema, backgroundTaskSchema, blockSchema, contextLimitStateSchema, deltaEventSchema, folderAccessEventSchema, gitFileDetailSchema, gitStatusEventSchema, helloEventSchema, herdrStatusEventSchema, inboxCardKindSchema, inboxDialogKindSchema, inboxEventSchemas, inboxHeadSchemaOf, macFolderBlockSchema, macFolderStateSchema, messageAttachmentSchema, messageEventSchema, notesEventSchema, parseServerEvent, permissionPendingEventSchema, permissionRequestObjectSchema, permissionRequestSchema, permissionResolvedEventSchema, permissionSettledEventSchema, questionOptionSchema, questionPendingEventSchema, questionRequestSchema, questionSchema, questionResolvedEventSchema, sessionChangedEventSchema, sessionPullRequestSchema, sessionStateSchema, sessionsSnapshotEventSchema, sessionSummarySchema, stateEventSchema, transcriptMessageSchema, transcriptNoticeSchema, transcriptSnapshotEventSchema, usageEventSchema, toolCallBlockObjectSchema, waitingForSchema, withDetailTruncation, withDisplayTextTruncation, } from './protocol.js';
|
|
26
26
|
/**
|
|
27
27
|
* Wartownik „ta wersja klienta tego nie zna". Zarezerwowany w KLIENCIE: serwer go nie nadaje
|
|
28
28
|
* i nie zna (schematy ścisłe), więc w polu stanu nie pomyli się z żadną prawdziwą wartością.
|
|
@@ -111,6 +111,17 @@ export const DEGRADATIONS = {
|
|
|
111
111
|
'pullRequests.state': undefined,
|
|
112
112
|
/** `SessionSummary.seenBy`: an unknown picker drops the field, so the received result reads as a human's. */
|
|
113
113
|
seenBy: undefined,
|
|
114
|
+
/**
|
|
115
|
+
* An `inbox-heads` head with an unknown `kind`, `state` or `dialog`: that head drops out of the list and the other
|
|
116
|
+
* heads stay, so a card kind added later does not empty an older app's Inbox. A single `inbox-head` with such a
|
|
117
|
+
* value is one item with nothing left to show and is ignored whole.
|
|
118
|
+
*/
|
|
119
|
+
'inbox.head': undefined,
|
|
120
|
+
/**
|
|
121
|
+
* A `folder-access` block with an unknown `state`: that folder drops out of the list and the other blocks stay, so a
|
|
122
|
+
* state added later does not hide the folders an older app can name.
|
|
123
|
+
*/
|
|
124
|
+
'folder-access.block': undefined,
|
|
114
125
|
};
|
|
115
126
|
/**
|
|
116
127
|
* Znacznik widoku surowego: ta wartość przeszła GAŁĄŹ ZAPASOWĄ. Zgłaszany zawsze, bez porównania
|
|
@@ -123,6 +134,16 @@ class Unknown {
|
|
|
123
134
|
this.value = value;
|
|
124
135
|
}
|
|
125
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* A list element the client cannot read. The result drops it from its list; the raw view keeps it in place, wrapped,
|
|
139
|
+
* so {@link collect} reports its markers at the input index and pairs the elements after it with the right result.
|
|
140
|
+
*/
|
|
141
|
+
class Dropped {
|
|
142
|
+
value;
|
|
143
|
+
constructor(value) {
|
|
144
|
+
this.value = value;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
126
147
|
/**
|
|
127
148
|
* Schematy tolerancyjne, zbudowane ze ścisłych przez `.extend` pól wyliczeniowych.
|
|
128
149
|
*
|
|
@@ -234,6 +255,29 @@ function buildSchemas(raw) {
|
|
|
234
255
|
channel: lenientOpt(questionRequestSchema.shape.channel, undefined),
|
|
235
256
|
questions: z.array(questionSchema.extend({ options: z.array(option) })),
|
|
236
257
|
});
|
|
258
|
+
/*
|
|
259
|
+
* `inbox-heads`: a head with an unknown string in `kind`, `state` or `dialog` drops out and the rest of the list
|
|
260
|
+
* stays. Any other broken head (`null`, a missing field, an empty `version`) still rejects the frame, also next to
|
|
261
|
+
* an unknown value.
|
|
262
|
+
*/
|
|
263
|
+
const [inboxHeadsEvent, inboxHeadEvent, inboxRemovedEvent] = inboxEventSchemas(sessionStateSchema);
|
|
264
|
+
const inboxHead = inboxHeadSchemaOf(sessionStateSchema);
|
|
265
|
+
const unreadableHead = inboxHead.extend({
|
|
266
|
+
kind: lenient(inboxCardKindSchema, undefined),
|
|
267
|
+
state: lenient(sessionStateSchema, undefined),
|
|
268
|
+
dialog: lenientOpt(inboxDialogKindSchema.optional(), undefined),
|
|
269
|
+
}).transform((head) => new Dropped(head));
|
|
270
|
+
const inboxHeads = z.array(z.union([inboxHead, unreadableHead]))
|
|
271
|
+
.transform((heads) => (raw ? heads : heads.filter((head) => !(head instanceof Dropped))));
|
|
272
|
+
/*
|
|
273
|
+
* `folder-access`: a block with an unknown string in `state` drops out and the rest of the list stays. Any other
|
|
274
|
+
* broken block (`null`, a missing field, an empty `path`) still rejects the frame, also next to an unknown state.
|
|
275
|
+
*/
|
|
276
|
+
const unreadableBlock = macFolderBlockSchema.extend({
|
|
277
|
+
state: lenient(macFolderStateSchema, undefined),
|
|
278
|
+
}).transform((block) => new Dropped(block));
|
|
279
|
+
const folderBlocks = z.array(z.union([macFolderBlockSchema, unreadableBlock]))
|
|
280
|
+
.transform((blocks) => (raw ? blocks : blocks.filter((block) => !(block instanceof Dropped))));
|
|
237
281
|
return z.discriminatedUnion('type', [
|
|
238
282
|
helloEventSchema,
|
|
239
283
|
sessionsSnapshotEventSchema.extend({ sessions: z.array(summary) }),
|
|
@@ -270,6 +314,11 @@ function buildSchemas(raw) {
|
|
|
270
314
|
usageEventSchema,
|
|
271
315
|
herdrStatusEventSchema,
|
|
272
316
|
notesEventSchema,
|
|
317
|
+
folderAccessEventSchema.extend({ blocked: folderBlocks }),
|
|
318
|
+
inboxHeadsEvent.extend({ heads: inboxHeads }),
|
|
319
|
+
// One head is one item: an unknown value ignores the frame, and the next head or `GET /api/inbox` mends it.
|
|
320
|
+
inboxHeadEvent,
|
|
321
|
+
inboxRemovedEvent,
|
|
273
322
|
]);
|
|
274
323
|
}
|
|
275
324
|
/** Budowane przy PIERWSZEJ ramce spoza ścisłego kontraktu — ścieżka szybka ich nie potrzebuje. */
|
|
@@ -287,13 +336,25 @@ function collect(raw, out, path, acc) {
|
|
|
287
336
|
acc.push({ path, value: raw.value });
|
|
288
337
|
return;
|
|
289
338
|
}
|
|
339
|
+
if (raw instanceof Dropped) {
|
|
340
|
+
collect(raw.value, undefined, path, acc);
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
290
343
|
if (typeof raw !== 'object' || raw === null)
|
|
291
344
|
return;
|
|
292
345
|
const target = typeof out === 'object' && out !== null ? out : undefined;
|
|
346
|
+
// A dropped element exists only in the raw view, so every later element sits that many places earlier in `out`.
|
|
347
|
+
let dropped = 0;
|
|
293
348
|
for (const [key, value] of Object.entries(raw)) {
|
|
294
|
-
|
|
349
|
+
if (value instanceof Dropped) {
|
|
350
|
+
dropped += 1;
|
|
351
|
+
collect(value, undefined, `${path}/${key}`, acc);
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
const outKey = dropped === 0 ? key : String(Number(key) - dropped);
|
|
355
|
+
const next = target?.[outKey];
|
|
295
356
|
if (next === undefined)
|
|
296
|
-
delete target?.[
|
|
357
|
+
delete target?.[outKey];
|
|
297
358
|
collect(value, next, `${path}/${key}`, acc);
|
|
298
359
|
}
|
|
299
360
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** Most entries one listing carries; a directory with more comes cut, with `truncated: true`. */
|
|
2
|
+
export const MAX_FILE_ENTRIES = 1000;
|
|
3
|
+
/** Kinds of a listing entry. Symlinks and special files (FIFO, socket, device) are never listed. */
|
|
4
|
+
export const FILE_ENTRY_KINDS = ['dir', 'file'];
|
|
5
|
+
/**
|
|
6
|
+
* Order of a listing: directories before files, then by name without letter case (`toLowerCase`), then by the name
|
|
7
|
+
* itself, both compared by UTF-16 code units (no locale), so every client sorts the same way.
|
|
8
|
+
*/
|
|
9
|
+
export function compareFileEntries(a, b) {
|
|
10
|
+
if (a.kind !== b.kind)
|
|
11
|
+
return a.kind === 'dir' ? -1 : 1;
|
|
12
|
+
return byCodeUnits(a.name.toLowerCase(), b.name.toLowerCase()) || byCodeUnits(a.name, b.name);
|
|
13
|
+
}
|
|
14
|
+
function byCodeUnits(a, b) {
|
|
15
|
+
if (a === b)
|
|
16
|
+
return 0;
|
|
17
|
+
return a < b ? -1 : 1;
|
|
18
|
+
}
|
|
19
|
+
/* Codes of the refusals of both file routes (field `error` of a 4xx body). */
|
|
20
|
+
/** 400: the path failed the shape check (empty segment, `.` or `..`, a leading or trailing `/`, NUL, over 4096 B). */
|
|
21
|
+
export const FILES_BAD_PATH_ERROR = 'bad-path';
|
|
22
|
+
/** 400: the session's directory is outside the work area, or the session has no pane: its files stay on the server. */
|
|
23
|
+
export const FILES_OUT_OF_SCOPE_ERROR = 'out-of-scope';
|
|
24
|
+
/** 400: a Codex entry, which Rarog only observes. */
|
|
25
|
+
export const FILES_CODEX_ERROR = 'codex';
|
|
26
|
+
/**
|
|
27
|
+
* 404: nothing to list or send under this path: it does not exist, or the server never shows it (a segment that
|
|
28
|
+
* starts with a dot, `node_modules`, a symlink, a special file, a file with more than one hard link, a path outside
|
|
29
|
+
* the session directory or the work area). The app reads it as "this directory or file is gone".
|
|
30
|
+
*/
|
|
31
|
+
export const FILES_NOT_FOUND_ERROR = 'not-found';
|
|
32
|
+
/** 413: the file is larger than `maxBytes`; refused before the first byte, the body is {@link FileTooLargeBody}. */
|
|
33
|
+
export const FILE_TOO_LARGE_ERROR = 'file-too-large';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Protocol contract, macOS folders area: the `folder-access` SSE frame (`FolderAccessEvent`), the guarded folders of
|
|
3
|
+
* the home directory the server keeps closed until macOS lets it in.
|
|
4
|
+
*
|
|
5
|
+
* The full list goes in every frame, sorted by `name`. A server with the folder gate on sends it on every global
|
|
6
|
+
* stream right after `sessions-snapshot`, also empty, and again on every change of the list. The frame is fleeting:
|
|
7
|
+
* `seq: null`, outside every ring buffer. A server without the gate never sends it.
|
|
8
|
+
*
|
|
9
|
+
* Re-exported unchanged by `shared/src/protocol.ts`; code imports the names from there.
|
|
10
|
+
*/
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
/**
|
|
13
|
+
* Why a folder is closed: `waiting` (no answer from the disk, macOS probably shows a window on the Mac), `denied`
|
|
14
|
+
* (macOS refused; System Settings decide) or `unchecked` (the server could not tell; details in the server log).
|
|
15
|
+
*/
|
|
16
|
+
export const MAC_FOLDER_STATES = ['waiting', 'denied', 'unchecked'];
|
|
17
|
+
export const macFolderStateSchema = z.enum(MAC_FOLDER_STATES);
|
|
18
|
+
export const macFolderBlockSchema = z.object({
|
|
19
|
+
name: z.string().min(1),
|
|
20
|
+
path: z.string().min(1),
|
|
21
|
+
state: macFolderStateSchema,
|
|
22
|
+
since: z.string(),
|
|
23
|
+
});
|
|
24
|
+
export const folderAccessEventSchema = z.object({
|
|
25
|
+
type: z.literal('folder-access'),
|
|
26
|
+
blocked: z.array(macFolderBlockSchema),
|
|
27
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Protocol contract, herdr area: the pane's permission mode read from the screen and the availability of the herdr
|
|
3
3
|
* integration (`HerdrStatus`, the source of the "herdr unavailable" banner and of the launch permission).
|
|
4
|
+
* The live availability change, the `herdr-status` SSE frame, lives here too (`HerdrStatusEvent`).
|
|
4
5
|
*
|
|
5
6
|
* Re-exported unchanged by `shared/src/protocol.ts`; code imports the names from there.
|
|
6
7
|
*/
|
|
@@ -21,3 +22,25 @@ const _herdrStatusSchemaMatchesType = true;
|
|
|
21
22
|
const _herdrStatusTypeMatchesSchema = true;
|
|
22
23
|
void _herdrStatusSchemaMatchesType;
|
|
23
24
|
void _herdrStatusTypeMatchesSchema;
|
|
25
|
+
/**
|
|
26
|
+
* Świadomie WĘŻSZY niż `herdrStatusSchema`: `version`/`protocol` interesują tylko ramkę
|
|
27
|
+
* startową (baner „protokół nowszy niż testowany"), a nie każdą zmianę dostępności.
|
|
28
|
+
*
|
|
29
|
+
* `canLaunch` is not cosmetic: with the answer to "may I start a session" only in the
|
|
30
|
+
* `sessions-snapshot` frame, the phone would keep the last known value until the next reconnect,
|
|
31
|
+
* so a panel closed by hand at the Mac would free a slot while the app still showed a dimmed "+"
|
|
32
|
+
* and the limit sentence.
|
|
33
|
+
*
|
|
34
|
+
* OPCJONALNE, bo event jest współdzielony ze starszymi wydaniami frontu i backendu: brak pola
|
|
35
|
+
* znaczy „nie wiem", a nie „nie wolno" — klient zostawia wtedy poprzednią wartość zamiast gasić
|
|
36
|
+
* przycisk na podstawie ciszy.
|
|
37
|
+
*/
|
|
38
|
+
export const herdrStatusEventSchema = z.object({
|
|
39
|
+
type: z.literal('herdr-status'),
|
|
40
|
+
available: z.boolean(),
|
|
41
|
+
agentCount: z.number(),
|
|
42
|
+
readOnly: z.boolean(),
|
|
43
|
+
canLaunch: z.boolean().optional(),
|
|
44
|
+
detail: z.string().optional(),
|
|
45
|
+
detailRef: sentenceRefSchema.optional(),
|
|
46
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Protocol contract, Inbox area: the heads of Inbox cards on the global stream, without the card text.
|
|
3
|
+
*
|
|
4
|
+
* A stream gets them only when it asks with `inbox=1` (`GET /api/stream?inbox=1`): `inbox-heads` right after
|
|
5
|
+
* `sessions-snapshot`, then `inbox-head` when a visible card changes and `inbox-removed` when it leaves the visible
|
|
6
|
+
* cards. The text comes from `GET /api/inbox` (`rest.ts`). The head carries the protocol's `SessionState`, which an
|
|
7
|
+
* area file does not import: the types and schemas take it as a parameter, and `protocol.ts` binds it.
|
|
8
|
+
*
|
|
9
|
+
* Re-exported unchanged by `shared/src/protocol.ts`; code imports the names from there.
|
|
10
|
+
*/
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
/** `result`: the turn ended with a result; `decision`: the turn waits for a person; `failed`: the turn stopped. */
|
|
13
|
+
export const INBOX_CARD_KINDS = ['result', 'decision', 'failed'];
|
|
14
|
+
export const inboxCardKindSchema = z.enum(INBOX_CARD_KINDS);
|
|
15
|
+
/** What a `decision` card waits for: a permission card, a question card, or a dialog in the pane without a card. */
|
|
16
|
+
export const INBOX_DIALOG_KINDS = ['permission', 'question', 'panel'];
|
|
17
|
+
export const inboxDialogKindSchema = z.enum(INBOX_DIALOG_KINDS);
|
|
18
|
+
/** The head schema over the protocol's session state schema. */
|
|
19
|
+
export function inboxHeadSchemaOf(state) {
|
|
20
|
+
return z.object({
|
|
21
|
+
sessionId: z.string().min(1),
|
|
22
|
+
turnId: z.string().min(1),
|
|
23
|
+
version: z.string().min(1),
|
|
24
|
+
kind: inboxCardKindSchema,
|
|
25
|
+
state,
|
|
26
|
+
at: z.string(),
|
|
27
|
+
dialog: inboxDialogKindSchema.optional(),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/** The three event schemas, in the order of {@link InboxEventOf}, for the protocol's event union. */
|
|
31
|
+
export function inboxEventSchemas(state) {
|
|
32
|
+
const head = inboxHeadSchemaOf(state);
|
|
33
|
+
return [
|
|
34
|
+
z.object({ type: z.literal('inbox-heads'), heads: z.array(head) }),
|
|
35
|
+
z.object({ type: z.literal('inbox-head'), head }),
|
|
36
|
+
z.object({ type: z.literal('inbox-removed'), sessionId: z.string().min(1), turnId: z.string().min(1) }),
|
|
37
|
+
];
|
|
38
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Protocol contract, project notes area: `/api/notes
|
|
2
|
+
* Protocol contract, project notes area: `/api/notes` and the `notes` SSE frame (`NotesEvent`).
|
|
3
3
|
*
|
|
4
4
|
* Re-exported unchanged by `shared/src/protocol.ts`; code imports the names from there.
|
|
5
5
|
*/
|
|
@@ -89,3 +89,9 @@ export const notesConflictBodySchema = z.object({
|
|
|
89
89
|
messageRef: sentenceRefSchema.optional(),
|
|
90
90
|
current: notesDocSchema,
|
|
91
91
|
});
|
|
92
|
+
/** Project notes changed: the directory and the "empty after the write" bit, no content ({@link NotesEvent}). */
|
|
93
|
+
export const notesEventSchema = z.object({
|
|
94
|
+
type: z.literal('notes'),
|
|
95
|
+
cwd: z.string().min(1),
|
|
96
|
+
empty: z.boolean(),
|
|
97
|
+
});
|
|
@@ -5,9 +5,8 @@
|
|
|
5
5
|
* `null`, a klient loguje i ignoruje zdarzenie. Dzięki temu starszy klient przeżyje nowszy
|
|
6
6
|
* serwer bez wysypywania strumienia SSE.
|
|
7
7
|
*
|
|
8
|
-
* Types and schemas of separate areas live in `./protocol/`, one file per area
|
|
9
|
-
*
|
|
10
|
-
* not import this file.
|
|
8
|
+
* Types and schemas of separate areas live in `./protocol/`, one file per area, re-exported here, so code imports
|
|
9
|
+
* the contract from `protocol.ts` (`@rarog/shared`) only. An area file does not import this file.
|
|
11
10
|
*/
|
|
12
11
|
import { z } from 'zod';
|
|
13
12
|
import { say, sentenceRefSchema } from './sentences/index.js';
|
|
@@ -16,8 +15,11 @@ import { imageDataUrlSchema, messageAttachmentSchema } from './protocol/attachme
|
|
|
16
15
|
import { backgroundTaskSchema, sessionArtifactSchema, sessionPullRequestSchema, sessionScheduledTaskSchema, } from './protocol/background.js';
|
|
17
16
|
import { consentAlwaysEntrySchema, SCREEN_UNAVAILABLE_REASONS, } from './protocol/consent.js';
|
|
18
17
|
import { gitCommitSchema, gitFileDetailSchema, gitFileKindsSchema, } from './protocol/git.js';
|
|
19
|
-
import { herdrModeSchema, herdrStatusSchema } from './protocol/herdr.js';
|
|
18
|
+
import { herdrModeSchema, herdrStatusEventSchema, herdrStatusSchema, } from './protocol/herdr.js';
|
|
19
|
+
import { inboxEventSchemas } from './protocol/inbox.js';
|
|
20
20
|
import { effortLevelSchema, modelIdSchema } from './protocol/model.js';
|
|
21
|
+
import { notesEventSchema } from './protocol/notes.js';
|
|
22
|
+
import { folderAccessEventSchema } from './protocol/folders.js';
|
|
21
23
|
export * from './protocol/activity.js';
|
|
22
24
|
export * from './protocol/attachments.js';
|
|
23
25
|
export * from './protocol/background.js';
|
|
@@ -26,8 +28,11 @@ export * from './protocol/consent.js';
|
|
|
26
28
|
export * from './protocol/dictation.js';
|
|
27
29
|
export * from './protocol/diff.js';
|
|
28
30
|
export * from './protocol/directories.js';
|
|
31
|
+
export * from './protocol/files.js';
|
|
32
|
+
export * from './protocol/folders.js';
|
|
29
33
|
export * from './protocol/git.js';
|
|
30
34
|
export * from './protocol/herdr.js';
|
|
35
|
+
export * from './protocol/inbox.js';
|
|
31
36
|
export * from './protocol/model.js';
|
|
32
37
|
export * from './protocol/notes.js';
|
|
33
38
|
export * from './protocol/resume.js';
|
|
@@ -211,7 +216,7 @@ export const WAITING_TEXT_MAX = 120;
|
|
|
211
216
|
* z przyciskami; nikt jeszcze o nic nie prosił, więc nie ma żądania, na które odpowiedzieć;
|
|
212
217
|
* - **decyzja** (`multi-select` … `send-failed`) — człowiek tapnął, a klawisz nie wyszedł;
|
|
213
218
|
* - **blokada** (`in-flight`) — powstaje w MANAGERZE, nie w driverze: decyzja o tej karcie
|
|
214
|
-
* właśnie leci z drugiego urządzenia. Do dziennika audytu nie trafia nigdy (
|
|
219
|
+
* właśnie leci z drugiego urządzenia. Do dziennika audytu nie trafia nigdy (`auditRefusal`
|
|
215
220
|
* woła wyłącznie driver), więc obietnicy „wpisy się SUMUJĄ" nie narusza.
|
|
216
221
|
*
|
|
217
222
|
* Lista stoi PRZED sekcją schematów, bo `sessionSummarySchema.herdrDialogReason` jej używa,
|
|
@@ -545,37 +550,6 @@ export const usageEventSchema = z.object({
|
|
|
545
550
|
contextTokens: z.number(),
|
|
546
551
|
contextLimit: z.number(),
|
|
547
552
|
});
|
|
548
|
-
/**
|
|
549
|
-
* Świadomie WĘŻSZY niż `herdrStatusSchema`: `version`/`protocol` interesują tylko ramkę
|
|
550
|
-
* startową (baner „protokół nowszy niż testowany"), a nie każdą zmianę dostępności.
|
|
551
|
-
*
|
|
552
|
-
* `canLaunch` is not cosmetic: with the answer to "may I start a session" only in the
|
|
553
|
-
* `sessions-snapshot` frame, the phone would keep the last known value until the next reconnect,
|
|
554
|
-
* so a panel closed by hand at the Mac would free a slot while the app still showed a dimmed "+"
|
|
555
|
-
* and the limit sentence.
|
|
556
|
-
*
|
|
557
|
-
* OPCJONALNE, bo event jest współdzielony ze starszymi wydaniami frontu i backendu: brak pola
|
|
558
|
-
* znaczy „nie wiem", a nie „nie wolno" — klient zostawia wtedy poprzednią wartość zamiast gasić
|
|
559
|
-
* przycisk na podstawie ciszy.
|
|
560
|
-
*/
|
|
561
|
-
export const herdrStatusEventSchema = z.object({
|
|
562
|
-
type: z.literal('herdr-status'),
|
|
563
|
-
available: z.boolean(),
|
|
564
|
-
agentCount: z.number(),
|
|
565
|
-
readOnly: z.boolean(),
|
|
566
|
-
canLaunch: z.boolean().optional(),
|
|
567
|
-
detail: z.string().optional(),
|
|
568
|
-
detailRef: sentenceRefSchema.optional(),
|
|
569
|
-
});
|
|
570
|
-
/**
|
|
571
|
-
* Zmiana notatek projektu. Katalog i bit „pusty po zapisie", zero treści — powód przy
|
|
572
|
-
* wariancie w {@link ServerEvent}.
|
|
573
|
-
*/
|
|
574
|
-
export const notesEventSchema = z.object({
|
|
575
|
-
type: z.literal('notes'),
|
|
576
|
-
cwd: z.string().min(1),
|
|
577
|
-
empty: z.boolean(),
|
|
578
|
-
});
|
|
579
553
|
export const serverEventSchema = z.discriminatedUnion('type', [
|
|
580
554
|
helloEventSchema,
|
|
581
555
|
sessionsSnapshotEventSchema,
|
|
@@ -592,8 +566,8 @@ export const serverEventSchema = z.discriminatedUnion('type', [
|
|
|
592
566
|
stateEventSchema,
|
|
593
567
|
gitStatusEventSchema,
|
|
594
568
|
usageEventSchema,
|
|
595
|
-
herdrStatusEventSchema,
|
|
596
|
-
|
|
569
|
+
herdrStatusEventSchema, notesEventSchema, folderAccessEventSchema,
|
|
570
|
+
...inboxEventSchemas(sessionStateSchema),
|
|
597
571
|
]);
|
|
598
572
|
const _schemaMatchesType = true;
|
|
599
573
|
const _typeMatchesSchema = true;
|
|
@@ -793,21 +767,20 @@ export const decisionRefusedBodySchema = z.object({
|
|
|
793
767
|
export const INTERRUPT_DELIVERY = ['yes', 'no', 'pending'];
|
|
794
768
|
export const interruptDeliverySchema = z.enum(INTERRUPT_DELIVERY);
|
|
795
769
|
/**
|
|
796
|
-
*
|
|
797
|
-
*
|
|
798
|
-
* `session` niesie ŚWIEŻE `SessionSummary`: stan przestawia się
|
|
799
|
-
* synchronicznie, więc odpowiedź na POST-a naprawia widok także wtedy, gdy `EventSource`
|
|
800
|
-
* umarł po cichu i nie zgłosił błędu.
|
|
770
|
+
* Answer of `POST /api/sessions/:id/interrupt`: **202**.
|
|
801
771
|
*
|
|
802
|
-
*
|
|
803
|
-
*
|
|
804
|
-
*
|
|
805
|
-
*
|
|
772
|
+
* `session` carries a FRESH `SessionSummary`: the state changes synchronously, so the answer fixes the view even when
|
|
773
|
+
* `EventSource` died silently. Every field but `ok` is OPTIONAL: `session` is absent from an older server, `delivered`
|
|
774
|
+
* from a route that does not wait for the driver; a client without `delivered` has two branches (success, exception),
|
|
775
|
+
* the only allowed reaction. `returnedPrompt` stands only after a delivered key whose Esc put the interrupted turn's
|
|
776
|
+
* prompt back into Claude Code's prompt field (CLI 2.1.329), proven by the whole field equal to that prompt; it is the
|
|
777
|
+
* prompt as the server sent or read it. Absent: no hand-back was proven.
|
|
806
778
|
*/
|
|
807
779
|
export const interruptResponseSchema = z.object({
|
|
808
780
|
ok: z.literal(true),
|
|
809
781
|
session: sessionSummarySchema.optional(),
|
|
810
782
|
delivered: interruptDeliverySchema.optional(),
|
|
783
|
+
returnedPrompt: z.string().min(1).optional(),
|
|
811
784
|
});
|
|
812
785
|
export const clientLogBodySchema = z.object({
|
|
813
786
|
events: z.array(z.object({
|
|
@@ -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 { 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, sessionSummarySchema, termListResponseSchema, transcriptMessageSchema, } 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, fileAttachmentSchema, 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.
|
|
@@ -76,25 +76,26 @@ export const messageBodySchema = z.object({
|
|
|
76
76
|
});
|
|
77
77
|
/**
|
|
78
78
|
* `POST /api/sessions/:id/seen`. Without fields (`{}`, as the app sends it) a human viewed the result. `by:
|
|
79
|
-
* "voice-agent"` with `
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
* otherwise a 409
|
|
84
|
-
* another value of
|
|
79
|
+
* "voice-agent"` with `conversation` and `readMark` is the voice agent across sessions picking up the result it read:
|
|
80
|
+
* both come from one answer of the turns route (`companionTurnsSchema`). The server accepts it only for a result
|
|
81
|
+
* standing in `waiting-input` with no decision card over it, in the engine conversation the session writes and its
|
|
82
|
+
* pane runs, while the session's memory holds no message newer than the read and its `stateSince` is the one of the
|
|
83
|
+
* read; otherwise a 409
|
|
84
|
+
* (`session.seen-result-changed`) and nothing changes. All three or none: a part is a 400, as is another value of
|
|
85
|
+
* `by`. Other keys are dropped, as in every body schema that is not strict.
|
|
85
86
|
*
|
|
86
87
|
* With `RAROG_COMPANION_SESSIONS` off (or the voice agent off), a body with the three fields is a 503 like the other
|
|
87
88
|
* routes of the mode across sessions (`docs/companion.md`, "Picking up a result").
|
|
88
89
|
*/
|
|
89
90
|
export const seenBodySchema = z.object({
|
|
90
91
|
by: z.literal('voice-agent').optional(),
|
|
91
|
-
stateSince: z.string().min(1).max(64).optional(),
|
|
92
92
|
conversation: z.string().min(1).max(64).optional(),
|
|
93
|
+
readMark: z.string().min(1).max(64).optional(),
|
|
93
94
|
}).refine((body) => {
|
|
94
|
-
const given = [body.by, body.
|
|
95
|
+
const given = [body.by, body.conversation, body.readMark].filter((field) => field !== undefined).length;
|
|
95
96
|
return given === 0 || given === 3;
|
|
96
97
|
}, {
|
|
97
|
-
message: 'by,
|
|
98
|
+
message: 'by, conversation and readMark come all three or none',
|
|
98
99
|
});
|
|
99
100
|
/**
|
|
100
101
|
* Sufit JEDNEJ notatki do odpowiedzi, w jednostkach UTF-16 (`string.length`): sufit Raroga,
|
|
@@ -723,13 +724,17 @@ export const companionTurnsCountSchema = z.string().regex(/^[1-9]$/u).transform(
|
|
|
723
724
|
* messages of this response from 1 and is not the stream's `seq`). A turn starts at a human message that the app
|
|
724
725
|
* shows as a turn. `conversation` is an opaque token of that conversation: the same while the server runs, another
|
|
725
726
|
* for another conversation and after a server restart; it is not the engine's id. `stateSince` is the session's
|
|
726
|
-
* `stateSince` at the read. `
|
|
727
|
-
* and
|
|
727
|
+
* `stateSince` at the read. `readMark` is an opaque name of the newest message the server's memory of the session held
|
|
728
|
+
* and of the session's `stateSince` when the route took the session for this read, before the file was read; the voice
|
|
729
|
+
* agent's pick-up of the result sends it back (`seenBodySchema`). An answer with no messages, or with a message cut
|
|
730
|
+
* to its start by the size limit, carries a mark that names no read, which no pick-up matches. `complete: false` =
|
|
731
|
+
* the read window starts inside the oldest returned turn, so its prompt and its first messages are missing.
|
|
728
732
|
*/
|
|
729
733
|
export const companionTurnsSchema = z.object({
|
|
730
734
|
messages: z.array(transcriptMessageSchema),
|
|
731
735
|
conversation: z.string().min(1),
|
|
732
736
|
stateSince: z.string(),
|
|
737
|
+
readMark: z.string().min(1).max(64),
|
|
733
738
|
complete: z.boolean(),
|
|
734
739
|
});
|
|
735
740
|
/** 503: the voice agent works, but the mode across sessions is off (`RAROG_COMPANION_SESSIONS`). */
|
|
@@ -802,3 +807,92 @@ export const COMPANION_SPEECH_UNCONFIGURED_ERROR = 'companion-speech-unconfigure
|
|
|
802
807
|
export const COMPANION_SPEECH_THROTTLED_ERROR = 'companion-speech-throttled';
|
|
803
808
|
/** 502: Soniox did not give a key (5xx, timeout, no connection, a reply without a key). */
|
|
804
809
|
export const COMPANION_SPEECH_UPSTREAM_ERROR = 'companion-speech-upstream';
|
|
810
|
+
// ---------------------------------------------------------------------------
|
|
811
|
+
// Inbox: the cards with their text (`docs/implementation-spec.md`, "Inbox")
|
|
812
|
+
// ---------------------------------------------------------------------------
|
|
813
|
+
/**
|
|
814
|
+
* The decision a `decision` card waits for, as the session summary carries it: a permission or question card
|
|
815
|
+
* (`waitingFor`, and `requestId`, the `permId` or `qId` of that card in the session stream) or a dialog in the pane
|
|
816
|
+
* without a card (`herdrDialog`, `herdrDialogReason`). The pending card itself comes with the session stream.
|
|
817
|
+
*/
|
|
818
|
+
export const inboxCardDialogSchema = z.discriminatedUnion('kind', [
|
|
819
|
+
z.object({
|
|
820
|
+
kind: z.literal('permission'), waitingFor: waitingForSchema.optional(), requestId: z.string().min(1).optional(),
|
|
821
|
+
}),
|
|
822
|
+
z.object({
|
|
823
|
+
kind: z.literal('question'), waitingFor: waitingForSchema.optional(), requestId: z.string().min(1).optional(),
|
|
824
|
+
}),
|
|
825
|
+
z.object({
|
|
826
|
+
kind: z.literal('panel'), herdrDialog: knownDialogIdSchema.optional(),
|
|
827
|
+
herdrDialogReason: refuseReasonSchema.optional(),
|
|
828
|
+
}),
|
|
829
|
+
]);
|
|
830
|
+
/**
|
|
831
|
+
* One visible Inbox card with its text: the head of `inbox-head` (`protocol/inbox.ts`), whose `dialog` here is the
|
|
832
|
+
* whole {@link inboxCardDialogSchema} instead of its kind, plus `text`, the last message of the agent's turn (at most
|
|
833
|
+
* 12 000 Unicode scalars), and `truncated` when the text lost its start to that ceiling.
|
|
834
|
+
*/
|
|
835
|
+
export const inboxCardSchema = inboxHeadSchemaOf(sessionStateSchema).extend({
|
|
836
|
+
text: z.string(),
|
|
837
|
+
truncated: z.boolean(),
|
|
838
|
+
dialog: inboxCardDialogSchema.optional(),
|
|
839
|
+
});
|
|
840
|
+
/** 200 of `GET /api/inbox`: every visible card, newest first. */
|
|
841
|
+
export const inboxListSchema = z.object({ cards: z.array(inboxCardSchema) });
|
|
842
|
+
/** 200 of `GET /api/inbox/:sessionId`: the session's visible card; no `card` = the session has none now. */
|
|
843
|
+
export const inboxCardResponseSchema = z.object({ card: inboxCardSchema.optional() });
|
|
844
|
+
/**
|
|
845
|
+
* `POST /api/inbox/:sessionId/remove` and `/restore`: the turn and the version of the card the device shows (from its
|
|
846
|
+
* head). Another turn or version is a 409 {@link INBOX_CARD_CHANGED_ERROR} without effect.
|
|
847
|
+
*/
|
|
848
|
+
export const inboxActionBodySchema = z.object({
|
|
849
|
+
turnId: z.string().min(1).max(64),
|
|
850
|
+
version: z.string().min(1).max(64),
|
|
851
|
+
});
|
|
852
|
+
/**
|
|
853
|
+
* 200 of remove and restore. `changed: false` = the card already was removed (restored), nothing happened again.
|
|
854
|
+
* `receipt: "skipped"` = the card is removed (restored), but the receipt of the result it would give (remove) or take
|
|
855
|
+
* back (restore) did not happen, because no read confirmed the card's turn or the session moved meanwhile.
|
|
856
|
+
*/
|
|
857
|
+
export const inboxActionResponseSchema = z.object({
|
|
858
|
+
ok: z.literal(true),
|
|
859
|
+
changed: z.boolean(),
|
|
860
|
+
receipt: z.literal('skipped').optional(),
|
|
861
|
+
});
|
|
862
|
+
/** 409 of remove and restore: the session has no card of that turn and version now; nothing happened. */
|
|
863
|
+
export const INBOX_CARD_CHANGED_ERROR = 'inbox-card-changed';
|
|
864
|
+
/** 503 of every Inbox route: the Inbox is off on the server (`RAROG_INBOX=0`). */
|
|
865
|
+
export const INBOX_DISABLED_ERROR = 'inbox-disabled';
|
|
866
|
+
// ---------------------------------------------------------------------------
|
|
867
|
+
// Session files: the listing of one directory, the index and the refusal of a file over the limit (`protocol/files.ts`)
|
|
868
|
+
// ---------------------------------------------------------------------------
|
|
869
|
+
/** One entry of {@link fileListingSchema}: `size` for files only, `ignored` only as `true`. */
|
|
870
|
+
export const fileEntrySchema = z.object({
|
|
871
|
+
name: z.string().min(1),
|
|
872
|
+
kind: z.enum(FILE_ENTRY_KINDS),
|
|
873
|
+
size: z.number().int().nonnegative().optional(),
|
|
874
|
+
ignored: z.literal(true).optional(),
|
|
875
|
+
});
|
|
876
|
+
/** 200 of `GET /api/sessions/:id/files?dir=<rel>` ({@link FileListing}). */
|
|
877
|
+
export const fileListingSchema = z.object({
|
|
878
|
+
dir: z.string(),
|
|
879
|
+
entries: z.array(fileEntrySchema),
|
|
880
|
+
truncated: z.boolean(),
|
|
881
|
+
maxBytes: z.number().int().positive(),
|
|
882
|
+
});
|
|
883
|
+
/** 200 of `GET /api/sessions/:id/files/index` ({@link FileIndex}). */
|
|
884
|
+
export const fileIndexSchema = z.object({
|
|
885
|
+
paths: z.array(z.string().min(1)),
|
|
886
|
+
truncated: z.boolean(),
|
|
887
|
+
maxBytes: z.number().int().positive(),
|
|
888
|
+
});
|
|
889
|
+
/** 413 `file-too-large` of `GET /api/sessions/:id/files/raw?path=<rel>` ({@link FileTooLargeBody}). */
|
|
890
|
+
export const fileTooLargeBodySchema = z.object({
|
|
891
|
+
error: z.literal(FILE_TOO_LARGE_ERROR),
|
|
892
|
+
message: z.string(),
|
|
893
|
+
messageRef: sentenceRefSchema.optional(),
|
|
894
|
+
size: z.number().int().nonnegative(),
|
|
895
|
+
maxBytes: z.number().int().positive(),
|
|
896
|
+
});
|
|
897
|
+
const _fileContract = [true, true, true, true, true, true, true, true];
|
|
898
|
+
void _fileContract;
|
|
@@ -69,10 +69,6 @@ export const HERDR_SENTENCES = {
|
|
|
69
69
|
en: 'herdr protocol {protocol} is older than the tested {oldest}. Integration is turned off.',
|
|
70
70
|
args: ['protocol:text', 'oldest:text'],
|
|
71
71
|
},
|
|
72
|
-
'herdr.protocol-unknown': {
|
|
73
|
-
en: 'herdr protocol {protocol} is unknown (tested: {tested}), read-only',
|
|
74
|
-
args: ['protocol:text', 'tested:text'],
|
|
75
|
-
},
|
|
76
72
|
'herdr.response-bad-shape': { en: 'The `{method}` response has an unknown shape.', args: ['method:text'] },
|
|
77
73
|
'herdr.response-foreign-id': {
|
|
78
74
|
en: 'A herdr response with an unexpected ID (expected {expected}). Protocol error.',
|
|
@@ -91,7 +91,13 @@ export const SENTENCES = Object.freeze({
|
|
|
91
91
|
/**
|
|
92
92
|
* Kody wycofane. Wpis przenosi się tu z pliku obszaru bez zmiany szablonu i argumentów, z `since`; nie znika nigdy.
|
|
93
93
|
*/
|
|
94
|
-
export const RETIRED = Object.freeze({
|
|
94
|
+
export const RETIRED = Object.freeze({
|
|
95
|
+
'herdr.protocol-unknown': {
|
|
96
|
+
en: 'herdr protocol {protocol} is unknown (tested: {tested}), read-only',
|
|
97
|
+
args: ['protocol:text', 'tested:text'],
|
|
98
|
+
since: '1.1.0',
|
|
99
|
+
},
|
|
100
|
+
});
|
|
95
101
|
/** Kształt `ref` na drucie; uszkodzony `ref` (`null`, pusty kod, ponad 8 argumentów, nie-łańcuch) odrzuca ramkę. */
|
|
96
102
|
export const sentenceRefSchema = z.object({
|
|
97
103
|
code: z.string().min(1),
|