@bridgebrew/sessions 0.0.34 → 0.0.38

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.
@@ -25,9 +25,11 @@ import {
25
25
  afterLive,
26
26
  afterStored,
27
27
  ago,
28
+ dropUnsaved,
28
29
  listChanges,
29
30
  notesOf,
30
31
  reset,
32
+ shownWorktree,
31
33
  useLeftDecisions,
32
34
  useItemTitles,
33
35
  useListing,
@@ -37,6 +39,7 @@ import {
37
39
  import { back, inbox, lineage } from '../listing.ts';
38
40
  import type { Lineage } from './children.tsx';
39
41
  import { answerBody, type Answer } from '../answers.ts';
42
+ import { DetailsPanel, detailsItem, detailsOf, type GitRowsProps } from './details.tsx';
40
43
 
41
44
  /** Settled rows shown before "Show more". */
42
45
  const SETTLED_SHOWN = 10;
@@ -61,11 +64,16 @@ export function MobileSessions({
61
64
  readOnly,
62
65
  setActions,
63
66
  setChrome,
67
+ renderFactorySlot,
64
68
  }: {
65
69
  ctx: Context;
66
70
  node: string;
67
71
  item: string | undefined;
68
72
  readOnly: boolean;
73
+ /** The renderer's factory slots: the `git` plugin's `git.session-details`, the details' git rows. */
74
+ renderFactorySlot?:
75
+ | ((name: string, props: GitRowsProps, options?: { fallback?: React.ReactNode }) => React.ReactNode)
76
+ | undefined;
69
77
  /** The phone shell: `{ bar: false }` hides its bottom bar while the new-session prompt shows over the list. */
70
78
  setChrome?: ((chrome: { bar?: boolean }) => void) | undefined;
71
79
  /** The phone shell's buttons; absent from an older shell. */
@@ -94,7 +102,20 @@ export function MobileSessions({
94
102
  </EmptyState>
95
103
  </section>
96
104
  );
97
- const shown = item ? listing.sessions.find((each) => each.id === item) : undefined;
105
+ // Its Details (plugins#239): an item of its own, pushed from the session's screen, Back closes it.
106
+ const { session: id, details } = item ? detailsOf(item) : { session: undefined, details: false };
107
+ const shown = id ? listing.sessions.find((each) => each.id === id) : undefined;
108
+ if (item && details)
109
+ return (
110
+ <MobileDetails
111
+ ctx={ctx}
112
+ node={node}
113
+ item={item}
114
+ session={shown}
115
+ readOnly={readOnly}
116
+ renderFactorySlot={renderFactorySlot}
117
+ />
118
+ );
98
119
  return item ? (
99
120
  <MobileSession
100
121
  key={item}
@@ -104,6 +125,7 @@ export function MobileSessions({
104
125
  session={shown}
105
126
  listing={listing}
106
127
  readOnly={readOnly}
128
+ setActions={setActions}
107
129
  />
108
130
  ) : (
109
131
  <MobileList
@@ -344,6 +366,65 @@ function NewSession({
344
366
  );
345
367
  }
346
368
 
369
+ /** A session's Details on a phone: the desktop's details panel, alone, titled by its session. */
370
+ function MobileDetails({
371
+ ctx,
372
+ node,
373
+ item,
374
+ session,
375
+ readOnly,
376
+ renderFactorySlot,
377
+ }: {
378
+ ctx: Context;
379
+ node: string;
380
+ item: string;
381
+ session: Session | undefined;
382
+ readOnly: boolean;
383
+ renderFactorySlot?: React.ComponentProps<typeof MobileSessions>['renderFactorySlot'];
384
+ }) {
385
+ const { workspace } = ctx;
386
+ const { store, known } = useListing(ctx, node);
387
+ React.useEffect(() => {
388
+ try {
389
+ ctx.screen.title?.(item, 'Details', session?.title);
390
+ } catch {
391
+ // An older shell: the header names it as it is.
392
+ }
393
+ }, [item, session?.title]);
394
+ const post = (path: string, body: object) =>
395
+ workspace
396
+ .fetch(`/${workspace.slug}/api/sessions/sessions${path}`, {
397
+ method: 'POST',
398
+ headers: { 'content-type': 'application/json', 'x-bridge-node': node },
399
+ body: JSON.stringify(body),
400
+ })
401
+ .then(readJson);
402
+ const load = () => void store?.load().catch(() => {});
403
+ return (
404
+ <section aria-label="Screen" className={cn('flex min-h-0 flex-1 flex-col', reset)}>
405
+ {session ? (
406
+ <div className="min-h-0 flex-1 overflow-y-auto bg-background">
407
+ <DetailsPanel
408
+ session={session}
409
+ slug={shownWorktree(workspace) ?? workspace.slug}
410
+ known={known}
411
+ post={post}
412
+ onChanged={load}
413
+ readOnly={readOnly}
414
+ actPullRequest={(action) =>
415
+ void post(`/pull-request/${action}`, { id: session.id }).then(load, () => {})
416
+ }
417
+ // Its git rows: the `git` plugin's, through its factory (no `sessions.details` here, a child of the screen).
418
+ gitRows={(props) => renderFactorySlot?.('git.session-details', props, { fallback: null }) ?? null}
419
+ />
420
+ </div>
421
+ ) : (
422
+ <EmptyState className="text-sm text-secondary">This session is gone.</EmptyState>
423
+ )}
424
+ </section>
425
+ );
426
+ }
427
+
347
428
  /** The prompt's frame: above the home bar (the prompt's `mobile` variant does the rest). */
348
429
  const promptBox = 'shrink-0 px-2 pb-[max(env(safe-area-inset-bottom),0.5rem)]';
349
430
 
@@ -354,6 +435,7 @@ function MobileSession({
354
435
  session,
355
436
  listing,
356
437
  readOnly,
438
+ setActions,
357
439
  }: {
358
440
  ctx: Context;
359
441
  node: string;
@@ -361,7 +443,24 @@ function MobileSession({
361
443
  session: Session | undefined;
362
444
  listing: Listing;
363
445
  readOnly: boolean;
446
+ setActions?:
447
+ | ((
448
+ actions: readonly { id: string; label: string; icon: string; onSelect: () => void }[],
449
+ ) => void)
450
+ | undefined;
364
451
  }) {
452
+ // Its Details, in the shell's capsule: the details panel, pushed (Back comes back here).
453
+ React.useEffect(() => {
454
+ setActions?.([
455
+ {
456
+ id: 'details',
457
+ label: 'Details',
458
+ icon: 'panel-right',
459
+ onSelect: () => ctx.screen.open(detailsItem(id)),
460
+ },
461
+ ]);
462
+ return () => setActions?.([]);
463
+ }, [setActions, id]);
365
464
  const { workspace } = ctx;
366
465
  const { store } = useListing(ctx, node);
367
466
  const api = `/${workspace.slug}/api/sessions/sessions`;
@@ -433,23 +532,26 @@ function MobileSession({
433
532
  React.useEffect(() => store?.watch(id), [store, id]);
434
533
  React.useEffect(visit, [id]);
435
534
 
436
- // One subscription, resumed after the last `seq` held, 1 s later and doubling to 30 s after an error.
535
+ // One subscription, resumed after the last `seq` the log holds (`saved`), 1 s later and doubling to 30 s after an
536
+ // error.
437
537
  React.useEffect(() => {
438
538
  let last = 0;
539
+ /** The newest `seq` the log holds: kept across a reconnect (`dropUnsaved`). */
540
+ let saved = 0;
439
541
  let stop: (() => void) | undefined;
440
542
  let retry: ReturnType<typeof setTimeout> | undefined;
441
543
  let delay = 1000;
442
544
  let closed = false;
443
545
  /** A snapshot came already: the next one is a reconnect's. */
444
546
  let resumed = false;
445
- const resulted = new Set<string>();
547
+ const resulted = new Map<string, number>();
446
548
  const add = (lines: Stored[]) => {
447
549
  const fresh = lines.filter((line) => line.seq > last);
448
550
  if (!fresh.length) return;
449
551
  last = fresh.at(-1)!.seq;
450
552
  for (const line of fresh) {
451
553
  if (line.type === 'turn/start') resulted.clear();
452
- if (line.type === 'tool/result' && line.id) resulted.add(line.id);
554
+ if (line.type === 'tool/result' && line.id) resulted.set(line.id, line.seq);
453
555
  }
454
556
  if (fresh.some((line) => listChanges.has(line.type))) void load();
455
557
  setEvents((was) => [...was, ...fresh]);
@@ -457,6 +559,7 @@ function MobileSession({
457
559
  const subscribe = () => {
458
560
  let isSynced = false;
459
561
  let retried = false;
562
+ let fresh = true;
460
563
  const again = () => {
461
564
  stop?.();
462
565
  setSynced(false);
@@ -465,18 +568,24 @@ function MobileSession({
465
568
  retry = setTimeout(subscribe, delay);
466
569
  delay = Math.min(delay * 2, 30_000);
467
570
  };
468
- stop = workspace.stream(`${api}/watch?id=${encodeURIComponent(id)}&after=${last}`, {
571
+ stop = workspace.stream(`${api}/watch?id=${encodeURIComponent(id)}&after=${saved}`, {
469
572
  persistent: false,
470
573
  onLost: again,
471
574
  onEnd: again,
472
575
  onItem: (value) => {
473
576
  const data = value as
474
- | { type: 'snapshot'; events: Stored[]; live: Live | null }
577
+ | { type: 'snapshot'; events: Stored[]; live: Live | null; saved?: number }
475
578
  | { type: 'stored'; event: Stored }
579
+ | { type: 'saved'; seq: number }
476
580
  | { type: 'live'; event: LiveEvent }
477
581
  | { type: string };
478
- if (data.type === 'snapshot') {
479
- const snap = data as { events: Stored[]; live: Live | null };
582
+ if (fresh) {
583
+ fresh = false;
584
+ last = dropUnsaved(last, saved, resulted, setEvents);
585
+ }
586
+ if (data.type === 'saved') saved = Math.max(saved, (data as { seq: number }).seq);
587
+ else if (data.type === 'snapshot') {
588
+ const snap = data as { events: Stored[]; live: Live | null; saved?: number };
480
589
  isSynced = true;
481
590
  delay = 1000;
482
591
  setSynced(true);
@@ -484,6 +593,7 @@ function MobileSession({
484
593
  if (resumed) void load();
485
594
  resumed = true;
486
595
  add(snap.events);
596
+ saved = Math.max(saved, snap.saved ?? last);
487
597
  setLive(snap.live);
488
598
  } else if (data.type === 'stored') {
489
599
  const { event } = data as { event: Stored };
@@ -55,7 +55,8 @@ export function PullRequestPill({
55
55
  act,
56
56
  }: {
57
57
  pullRequest: SessionPullRequest;
58
- act: (action: 'watch' | 'unwatch' | 'unlink') => void;
58
+ /** Its actions; none (read-only): the link alone. */
59
+ act?: ((action: 'watch' | 'unwatch' | 'unlink') => void) | undefined;
59
60
  }) {
60
61
  const look = LOOK[pr.state ?? 'open'];
61
62
  const mark = markOf(pr);
@@ -93,7 +94,7 @@ export function PullRequestPill({
93
94
  <Icon name="external-link" />
94
95
  Open on GitHub
95
96
  </DropdownMenuItem>
96
- {pr.watching ? (
97
+ {!act ? null : pr.watching ? (
97
98
  <DropdownMenuItem onClick={() => act('unwatch')}>
98
99
  <Icon name="eye-off" />
99
100
  Stop watching
@@ -106,10 +107,12 @@ export function PullRequestPill({
106
107
  </DropdownMenuItem>
107
108
  )
108
109
  )}
109
- <DropdownMenuItem onClick={() => act('unlink')}>
110
- <Icon name="unlink" />
111
- Unlink
112
- </DropdownMenuItem>
110
+ {act && (
111
+ <DropdownMenuItem onClick={() => act('unlink')}>
112
+ <Icon name="unlink" />
113
+ Unlink
114
+ </DropdownMenuItem>
115
+ )}
113
116
  </DropdownMenuContent>
114
117
  </DropdownMenu>
115
118
  );
@@ -54,15 +54,18 @@ const soonestOf = (tasks: ScheduledTaskView[]): ScheduledTaskView | undefined =>
54
54
  return soonest;
55
55
  };
56
56
 
57
- /** The tasks of one session, in its header: a badge saying when the next one runs, and its menu. */
57
+ /** The tasks of one session, in its details panel: a badge saying when the next one runs, and its menu. */
58
58
  export function SessionScheduled({
59
59
  ctx,
60
60
  node,
61
61
  session,
62
+ wrap = (menu) => menu,
62
63
  }: {
63
64
  ctx: Context;
64
65
  node: string;
65
66
  session: SessionLite;
67
+ /** Where its badge goes (a row of the details panel); nothing drawn while the session has no task. */
68
+ wrap?: (menu: React.ReactNode) => React.ReactNode;
66
69
  }) {
67
70
  const { workspace } = ctx;
68
71
  const { toast } = useToast();
@@ -164,7 +167,7 @@ export function SessionScheduled({
164
167
  const soonest = soonestOf(tasks);
165
168
  const words = soonest?.nextRunAt ? snoozeWakeLabel(soonest.nextRunAt) : 'Not planned';
166
169
 
167
- return (
170
+ return wrap(
168
171
  <DropdownMenu>
169
172
  <DropdownMenuTrigger
170
173
  render={
@@ -198,6 +201,6 @@ export function SessionScheduled({
198
201
  </DropdownMenuSub>
199
202
  ))}
200
203
  </DropdownMenuContent>
201
- </DropdownMenu>
204
+ </DropdownMenu>,
202
205
  );
203
206
  }
@@ -57,8 +57,8 @@ export function SubagentView({
57
57
  load: () => Promise<Stored[]>;
58
58
  folder?: string | undefined;
59
59
  workspace: string;
60
- /** The page's button showing or hiding the sessions list. */
61
- listToggle: React.ReactNode;
60
+ /** The page's button showing or hiding the sessions list, when the window's bar cannot hold it (an older shell). */
61
+ listToggle?: React.ReactNode;
62
62
  /** Stops it through its harness; absent when its harness cannot. */
63
63
  onStop?: (() => void) | undefined;
64
64
  }) {
package/contract.ts CHANGED
@@ -256,7 +256,13 @@ export type WatchMessage =
256
256
  events: Line[];
257
257
  live: (Live & Record<string, unknown>) | null;
258
258
  more?: boolean;
259
+ /** `@bridgebrew/sessions`' extension (not Bridge's copy): every line up to this `seq` is in the log. A `stored`
260
+ * line past it may be lost by a restart, whose next lines may take its number: a page reconnects `after=<saved>`
261
+ * and drops the lines past it then. A reader without it behaves as before. */
262
+ saved?: number;
259
263
  }
264
+ /** `@bridgebrew/sessions`' extension (not Bridge's copy): the lines up to `seq` landed in the log. */
265
+ | { type: 'saved'; seq: number }
260
266
  /** Point reads `text` (`{ type: 'text', text }`, appended to the live text) and `decision` (`{ type: 'decision', id, …
261
267
  * }`, a decision asked); a stored `decision/answered` (`id`) or `turn/end` closes it. */
262
268
  | { type: 'live'; event: { type: string } & Record<string, unknown> }
package/delegations.ts CHANGED
@@ -174,8 +174,9 @@ export interface QueuedQuestion {
174
174
  decision: string;
175
175
  text: string;
176
176
  }
177
- /** A queued message, as `server.ts` keeps it; a result's has `delegations`, a child's question `questions`. */
178
- interface QueueItem {
177
+ /** A queued message, as `server.ts` keeps it; a result's has `delegations`, a child's question `questions`. A type, not
178
+ * an interface: it fits the record's loose queue item (a field another `sessions` plugin wrote kept). */
179
+ type QueueItem = {
179
180
  id: string;
180
181
  text: string;
181
182
  at: string;
@@ -183,7 +184,7 @@ interface QueueItem {
183
184
  delegations?: string[] | undefined;
184
185
  questions?: QueuedQuestion[] | undefined;
185
186
  sender?: string | undefined;
186
- }
187
+ };
187
188
  /** A decision as the harness asks it: a question as its driver says (`kind`), else when it has `questions` or none of
188
189
  * its options allows or denies (`isQuestion`). */
189
190
  export interface Decision {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bridgebrew/sessions",
3
- "version": "0.0.34",
3
+ "version": "0.0.38",
4
4
  "license": "MIT",
5
5
  "description": "Conversations with agents, in the workspace or in a project, through the Profile.",
6
6
  "keywords": [
@@ -27,9 +27,42 @@
27
27
  "implements": [
28
28
  "sessions"
29
29
  ],
30
- "requires": {
31
- "storage": {},
32
- "harness": {}
30
+ "contracts": {
31
+ "provides": {
32
+ "sessions": {
33
+ "version": "1.1",
34
+ "slots": [
35
+ "tab",
36
+ "details"
37
+ ],
38
+ "routes": [
39
+ "/sessions"
40
+ ],
41
+ "screens": [
42
+ "sessions"
43
+ ]
44
+ }
45
+ },
46
+ "uses": {
47
+ "storage": {
48
+ "version": "1.0"
49
+ },
50
+ "harness": {
51
+ "version": "1.0"
52
+ },
53
+ "project": {
54
+ "version": "1.0",
55
+ "optional": true
56
+ },
57
+ "scheduler": {
58
+ "version": "1.0",
59
+ "optional": true
60
+ },
61
+ "github": {
62
+ "version": "1.0",
63
+ "optional": true
64
+ }
65
+ }
33
66
  },
34
67
  "dataVersions": {
35
68
  "sessions": 1,
@@ -336,7 +369,7 @@
336
369
  }
337
370
  },
338
371
  "session_changes": {
339
- "description": "Read what a session of this workspace changed in its git repository and has not committed yet: its files (pending: still uncommitted), its commits, the uncommitted diff of its files, and the other sessions whose uncommitted changes share files with it (shared). Use it before editing a file another session is changing, to keep its work.",
372
+ "description": "Read what a session of this workspace changed in its git repository and has not committed yet: its files (pending: still uncommitted), its commits, the uncommitted diff of its files (past 50 files, each file's line counts and no diff: byFile), and the other sessions whose uncommitted changes share files with it (shared). With path, only that file's diff. Use it before editing a file another session is changing, to keep its work.",
340
373
  "method": "POST",
341
374
  "path": "/sessions/changes",
342
375
  "input": {
@@ -345,6 +378,10 @@
345
378
  "id": {
346
379
  "type": "string",
347
380
  "description": "The session's id (list_sessions)."
381
+ },
382
+ "path": {
383
+ "type": "string",
384
+ "description": "One of its files (as listed in files): answers that file's diff only."
348
385
  }
349
386
  },
350
387
  "required": [
@@ -1015,7 +1052,7 @@
1015
1052
  "typecheck": "bridge plugin check ."
1016
1053
  },
1017
1054
  "dependencies": {
1018
- "@bridgebrew/session-ui": "0.0.1",
1055
+ "@bridgebrew/session-ui": "0.0.2",
1019
1056
  "@openuidev/lang-core": "1.0.1",
1020
1057
  "react-markdown": "10.1.0",
1021
1058
  "remark-gfm": "4.0.1",
@@ -1028,6 +1065,6 @@
1028
1065
  },
1029
1066
  "releaseStage": "dev",
1030
1067
  "engines": {
1031
- "bridge": ">=0.0.1-nightly.20261119.2"
1068
+ "bridge": ">=0.0.1-nightly.20261120.1"
1032
1069
  }
1033
1070
  }