@bridgebrew/sessions 0.0.0-stage → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +43 -2
  3. package/answers.ts +167 -0
  4. package/browser/branch-actions.tsx +166 -0
  5. package/browser/changes.tsx +415 -0
  6. package/browser/children.tsx +650 -0
  7. package/browser/conversation.tsx +2381 -0
  8. package/browser/decision-questions.tsx +191 -0
  9. package/browser/elapsed.tsx +44 -0
  10. package/browser/gallery.tsx +218 -0
  11. package/browser/index.tsx +3434 -0
  12. package/browser/media-origins.tsx +38 -0
  13. package/browser/mobile.tsx +663 -0
  14. package/browser/open-link.tsx +30 -0
  15. package/browser/pull-request.tsx +116 -0
  16. package/browser/questions.tsx +156 -0
  17. package/browser/session-scheduled.tsx +203 -0
  18. package/browser/subagent-view.tsx +136 -0
  19. package/browser/subagents.tsx +339 -0
  20. package/browser/tabs.tsx +228 -0
  21. package/browser/tsconfig.json +15 -0
  22. package/browser/views/view.tsx +1064 -0
  23. package/browser/views.tsx +166 -0
  24. package/contract.ts +287 -0
  25. package/delegations.ts +1975 -0
  26. package/diff.ts +88 -0
  27. package/docs/en/images.mdx +51 -0
  28. package/docs/en/index.mdx +22 -0
  29. package/docs/en/meta.json +4 -0
  30. package/docs/en/organize-sessions.mdx +53 -0
  31. package/docs/en/start-a-session.mdx +63 -0
  32. package/docs/meta.json +4 -0
  33. package/git.ts +223 -0
  34. package/listing.ts +382 -0
  35. package/package.json +1023 -4
  36. package/peers.ts +677 -0
  37. package/pull-request-watch.ts +282 -0
  38. package/pull-requests.ts +606 -0
  39. package/server.ts +5920 -0
  40. package/text.ts +19 -0
  41. package/tsconfig.json +3 -0
  42. package/viewer-activity.ts +57 -0
  43. package/views/examples.ts +153 -0
  44. package/views/library.ts +1116 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 bridgebrew
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,44 @@
1
- # Temporary Holding Version
1
+ # Sessions (`@bridgebrew/sessions`)
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Conversations with AI agents, in the workspace or in a project: start a chat, follow the agent's work, answer its
4
+ questions, and sort finished work aside. It replaces Bridge's built-in Sessions Lite under the same key.
5
+
6
+ ## Install
7
+
8
+ Installed with every new workspace. It needs a storage plugin and at least one harness (an agent driver such as
9
+ `@bridgebrew/harness-claude`, `@bridgebrew/harness-codex` or `@bridgebrew/harness-opencode`). Snooze appears only when
10
+ the workspace has the scheduler plugin.
11
+
12
+ ## Use
13
+
14
+ Open **Sessions**, select **New chat**, choose a Profile and a Model, review **Permissions**, and send. A project
15
+ session works in the project's folder; a workspace session manages the workspace. While a turn runs, a new message
16
+ waits in a queue; **Stop** (or Escape twice) interrupts the turn. After a restart, the agent continues a turn that was
17
+ cut.
18
+
19
+ - **The list**: Pinned, Active, Working, Snoozed and Settled shelves. A row shows a waiting decision, a running turn or
20
+ unread work. Pin, settle, snooze, tag, rename or archive a session from its menu; Undo is offered for 5 seconds.
21
+ - **Keys**: ⌘⇧S settles and ⌘⇧P pins the open session, ⌘⇧[ and ⌘⇧] open the previous and next one, ⌘⇧M opens the model
22
+ picker.
23
+ - **Images**: send up to 8 images with a message; see the images and videos the agent shows; pin the ones to keep in
24
+ the gallery (per session, project or workspace).
25
+ - **Agents' tools**: an agent can list, triage and tag sessions, ask or notify another session, delegate work to a child
26
+ session, show a view in the session, work on its own git branch, and link or watch a pull request.
27
+
28
+ Settings:
29
+
30
+ - **Auto-settle after (days)**: an idle session moves to Settled after this many days; 0 never. Default 3.
31
+ - **Fold working sessions**: sessions whose agent works fold into Working, Active keeps those that need you. Default on.
32
+ - **Snooze choices**: what Snooze offers, soonest first. Default: in 1 hour, in 3 hours,
33
+ today 18:00, tomorrow 9:00, Monday 9:00.
34
+ - **Time to answer a question (minutes)**: how long an agent has to answer another session. Default 10.
35
+ - **Prompt**: the field you write in (Full, Basic, or another installed). Default: the first installed.
36
+ - **New session's branch**: a new session of a git project works on the project's branch (`main`) or on a new branch
37
+ of its own. Default `main`.
38
+ - **Watched pull request: read every (minutes)**: default 2. **Linked pull request: read every (minutes)**: default 10.
39
+ - **Settle on pull request**: when the pull request is merged, merged or closed, or never. Default merged.
40
+ - **Open pull request keeps a session active**: default on.
41
+
42
+ ## Contracts
43
+
44
+ Implements `sessions`. Requires `storage` and `harness`.
package/answers.ts ADDED
@@ -0,0 +1,167 @@
1
+ // The answers to a decision's questions (the harness contract's `questions`, an agent's question tool): what a decision
2
+ // asks, whether an answer fits what it offered (`checkAnswer`, as the driver checks it again), and how an answer reads
3
+ // (`answerSummary`, for the timeline and a cut turn's continuation). Pure: the server, `delegations.ts` and the pages use
4
+ // it.
5
+
6
+ /** One option of a decision: a question's, or a plain decision's (`kind` allow, deny or other). */
7
+ export interface Choice {
8
+ id: string;
9
+ label: string;
10
+ description?: string | undefined;
11
+ kind?: string | undefined;
12
+ }
13
+ /** One question of a decision, as the harness contract's `DecisionQuestion`. */
14
+ export interface Question {
15
+ id: string;
16
+ header?: string | undefined;
17
+ question: string;
18
+ options: Choice[];
19
+ multiSelect?: true | undefined;
20
+ custom?: true | undefined;
21
+ required?: boolean | undefined;
22
+ }
23
+ /** A decision as asked (`decision/asked`, a live one, a cut turn's left open). */
24
+ export interface Asked {
25
+ title?: string | undefined;
26
+ options?: Choice[] | undefined;
27
+ kind?: 'question' | 'approval' | undefined;
28
+ questions?: Question[] | undefined;
29
+ }
30
+ /** Per question (its id), the options chosen and the free text. */
31
+ export interface Answers {
32
+ answers: { question: string; options?: string[]; text?: string }[];
33
+ }
34
+ /** An answer to a decision: an option id, `null` (dismissed), or its questions' answers. */
35
+ export type Answer = string | null | Answers;
36
+
37
+ /** Answers as a route parsed them (an absent field `undefined`), in the contract's shape. */
38
+ export const answersOf = (
39
+ given: { question: string; options?: string[] | undefined; text?: string | undefined }[],
40
+ ): Answers => ({
41
+ answers: given.map(({ question, options, text }) => ({
42
+ question,
43
+ ...(options !== undefined && { options }),
44
+ ...(text !== undefined && { text }),
45
+ })),
46
+ });
47
+
48
+ /** The questions of decision `asked`: its own, else one question made of its title and options (an old driver's). */
49
+ export const questionsOf = (asked: Asked): Question[] =>
50
+ asked.questions?.length
51
+ ? asked.questions
52
+ : [
53
+ {
54
+ id: '',
55
+ question: asked.title ?? '',
56
+ options: (asked.options ?? []).map(({ id, label }) => ({ id, label })),
57
+ },
58
+ ];
59
+
60
+ /** Whether a decision is a question (an agent asking the user) rather than an approval (a permission to allow): as its
61
+ * driver says (`kind`), else a question when it has `questions`, or options none of which allows or denies. */
62
+ export const isQuestion = (asked: Asked) =>
63
+ asked.kind !== undefined
64
+ ? asked.kind === 'question'
65
+ : !!asked.questions?.length ||
66
+ (!!asked.options?.length && asked.options.every((each) => each.kind === 'other'));
67
+
68
+ /** Why `answer` does not fit decision `asked` (a code and a message), else undefined. `null` always fits (dismissed);
69
+ * a plain option id fits a decision with that option (one with `questions` offers it only for a single single-choice
70
+ * question); answers fit a decision with `questions`, each question once, its options among its own, several only
71
+ * with `multiSelect`, a text only with `custom` (without `multiSelect`, in place of an option), and every required
72
+ * question answered. */
73
+ export const checkAnswer = (
74
+ asked: Asked,
75
+ answer: Answer,
76
+ ):
77
+ | { code: 'invalid_option' | 'invalid_answer' | 'custom_answer_unavailable'; message: string }
78
+ | undefined => {
79
+ if (answer === null) return undefined;
80
+ if (typeof answer === 'string')
81
+ return asked.options?.some((each) => each.id === answer)
82
+ ? undefined
83
+ : { code: 'invalid_option', message: `it has no option ${answer}` };
84
+ const questions = asked.questions ?? [];
85
+ if (!questions.length)
86
+ return {
87
+ code: 'invalid_answer',
88
+ message: 'it asks no questions: answer it with one of its options',
89
+ };
90
+ const seen = new Set<string>();
91
+ for (const each of answer.answers) {
92
+ const question = questions.find((one) => one.id === each.question);
93
+ if (!question)
94
+ return {
95
+ code: 'invalid_answer',
96
+ message: `it has no question ${each.question}: its questions are ${questions.map((one) => one.id).join(', ')}`,
97
+ };
98
+ if (seen.has(question.id))
99
+ return { code: 'invalid_answer', message: `question ${question.id} is answered twice` };
100
+ seen.add(question.id);
101
+ const ids = question.options.map((one) => one.id).join(', ');
102
+ const chosen = each.options ?? [];
103
+ const wrong = chosen.find((one) => !question.options.some((option) => option.id === one));
104
+ if (wrong !== undefined)
105
+ return {
106
+ code: 'invalid_option',
107
+ message: `question ${question.id} has no option ${wrong}${ids ? `: choose among ${ids}` : ''}`,
108
+ };
109
+ if (new Set(chosen).size !== chosen.length)
110
+ return { code: 'invalid_answer', message: `question ${question.id} has an option twice` };
111
+ if (chosen.length > 1 && !question.multiSelect)
112
+ return {
113
+ code: 'invalid_answer',
114
+ message: `question ${question.id} takes one option (multiSelect false)`,
115
+ };
116
+ if (each.text !== undefined && !question.custom)
117
+ return {
118
+ code: 'custom_answer_unavailable',
119
+ message: `question ${question.id} takes no free text (allowCustomAnswer false)${ids ? `: choose among ${ids}` : ''}`,
120
+ };
121
+ // A single choice is one value: an option, or the text in its stead (OpenCode's form takes one string).
122
+ if (!question.multiSelect && chosen.length && each.text?.trim())
123
+ return {
124
+ code: 'invalid_answer',
125
+ message: `question ${question.id} takes one answer (multiSelect false): an option or a text, not both`,
126
+ };
127
+ }
128
+ const unanswered = questions.find((question) => {
129
+ if (question.required === false) return false;
130
+ const given = answer.answers.find((each) => each.question === question.id);
131
+ return !given?.options?.length && !given?.text?.trim();
132
+ });
133
+ if (unanswered)
134
+ return {
135
+ code: 'invalid_answer',
136
+ message: `question ${unanswered.id} needs an answer (required)`,
137
+ };
138
+ return undefined;
139
+ };
140
+
141
+ /** How answer `answer` to decision `asked` reads: the option's label, `null` for a dismissal, or per question its
142
+ * options' labels and its text ("Header: A, B; other text"). */
143
+ export const answerSummary = (asked: Asked, answer: Answer): string | null => {
144
+ if (answer === null) return null;
145
+ if (typeof answer === 'string')
146
+ return asked.options?.find((each) => each.id === answer)?.label ?? answer;
147
+ const questions = asked.questions ?? [];
148
+ return answer.answers
149
+ .map((each) => {
150
+ const question = questions.find((one) => one.id === each.question);
151
+ const labels = (each.options ?? []).map(
152
+ (id) => question?.options.find((option) => option.id === id)?.label ?? id,
153
+ );
154
+ const said = [...labels, ...(each.text?.trim() ? [each.text.trim()] : [])].join(', ');
155
+ if (!said) return '';
156
+ const name = question?.header ?? (questions.length > 1 ? question?.question : undefined);
157
+ return name ? `${name}: ${said}` : said;
158
+ })
159
+ .filter(Boolean)
160
+ .join('; ');
161
+ };
162
+
163
+ /** The body of `POST /sessions/answer` that gives decision `decision` the answer `answer`. */
164
+ export const answerBody = (decision: string, answer: Answer) =>
165
+ answer !== null && typeof answer === 'object'
166
+ ? { decision, answers: answer.answers }
167
+ : { decision, option: answer };
@@ -0,0 +1,166 @@
1
+ // A session's branch from its page (research-083): its Git button (`@bridge/session-ui/git-actions`) acts on its branch's
2
+ // folder, and archiving the branch's last session offers to delete that folder (never one with work not committed or not pushed; the git branch
3
+ // stays). Both go through the project's Branches routes (`/_bridge/host/branches/…`, `project-branches.ts`), as the
4
+ // Branches screen does: the same checks, the owner's page.
5
+ // ponytail: cleanup is asked, never automatic (merged, inactive, unchanged): its rules are bridge#348.
6
+ import * as React from 'react';
7
+ import {
8
+ Button,
9
+ Dialog,
10
+ DialogBody,
11
+ DialogContent,
12
+ DialogDescription,
13
+ DialogFooter,
14
+ DialogHeader,
15
+ DialogTitle,
16
+ readJson,
17
+ useToast,
18
+ } from '@bridge/ui';
19
+ import {
20
+ GitActions,
21
+ branchesRoute,
22
+ useBranch,
23
+ type BranchesAnswer,
24
+ } from '@bridge/session-ui/git-actions';
25
+
26
+ const post = async (slug: string, node: string, action: string, body: Record<string, unknown>) =>
27
+ readJson(
28
+ await fetch(branchesRoute(slug, node, action), {
29
+ method: 'POST',
30
+ headers: { 'content-type': 'application/json' },
31
+ body: JSON.stringify(body),
32
+ }),
33
+ );
34
+
35
+ /** The Git button of session `session`'s branch `branch` (project `node`), in its header: its label and action from the
36
+ * branch's state, read again after each turn (`refresh`) and when the page gets the focus back. `pullRequestOpen`: the
37
+ * session knows an open pull request of its own (research-086), one Bridge did not record (the agent's `gh pr create`,
38
+ * github.com): the button offers Push, not Create PR again. `onGitAnswer`: after each Git action's answer. */
39
+ export function BranchActions({
40
+ slug,
41
+ node,
42
+ branch,
43
+ session,
44
+ refresh,
45
+ pullRequestOpen = false,
46
+ onGitAnswer,
47
+ }: {
48
+ slug: string;
49
+ node: string;
50
+ branch: string;
51
+ session: string;
52
+ refresh?: unknown;
53
+ pullRequestOpen?: boolean;
54
+ onGitAnswer?: () => void;
55
+ }) {
56
+ const [state, take] = useBranch(slug, node, branch, refresh);
57
+ if (!state) return null;
58
+ return (
59
+ <GitActions
60
+ slug={slug}
61
+ node={node}
62
+ branch={pullRequestOpen && !state.prOpen ? { ...state, prOpen: true } : state}
63
+ session={session}
64
+ onAnswer={(answer) => {
65
+ take(answer);
66
+ onGitAnswer?.();
67
+ }}
68
+ />
69
+ );
70
+ }
71
+
72
+ /** The folder cleanup an archive offers: the branch, and why its folder must stay, if it must. */
73
+ export interface Cleanup {
74
+ slug: string;
75
+ node: string;
76
+ name: string;
77
+ folder: string;
78
+ kept?: string;
79
+ }
80
+
81
+ /** What archiving a session on `branch` offers, once it was its branch's last session: its folder, kept (and why) when it
82
+ * holds work not committed or not pushed, or is active; `undefined` when the branch has no folder of its own. */
83
+ export const cleanupOf = async (
84
+ slug: string,
85
+ node: string,
86
+ branch: string,
87
+ ): Promise<Cleanup | undefined> => {
88
+ // The host's own answer: typed once where it is read.
89
+ const view = (await readJson(
90
+ await fetch(branchesRoute(slug, node), { cache: 'no-store' }),
91
+ )) as BranchesAnswer;
92
+ const found = view.branches.find((each) => each.name === branch && !each.main);
93
+ if (!found) return undefined;
94
+ const why = [
95
+ found.dirty > 0 && `${found.dirty} uncommitted file${found.dirty === 1 ? '' : 's'}`,
96
+ found.unpushed > 0 && `${found.unpushed} unpushed commit${found.unpushed === 1 ? '' : 's'}`,
97
+ ].filter(Boolean);
98
+ const kept = why.length
99
+ ? `it holds ${why.join(' and ')}: ${found.dirty > 0 ? 'commit and push' : 'push'} ${found.dirty + found.unpushed === 1 ? 'it' : 'them'} first.`
100
+ : found.active
101
+ ? 'Bridge runs code from it: activate another branch first.'
102
+ : undefined;
103
+ return { slug, node, name: found.name, folder: found.folder, ...(kept && { kept }) };
104
+ };
105
+
106
+ /** Asks whether to delete the folder of the branch whose last session was archived; says why it stays when it must. */
107
+ export function CleanupDialog({
108
+ offer,
109
+ onClose,
110
+ }: {
111
+ offer: Cleanup | undefined;
112
+ onClose: () => void;
113
+ }) {
114
+ const { toast } = useToast();
115
+ const remove = async (each: Cleanup) => {
116
+ onClose();
117
+ try {
118
+ await post(each.slug, each.node, 'remove', { name: each.name });
119
+ toast({ title: 'Folder deleted', description: `${each.name} stays in git.` });
120
+ } catch (cause) {
121
+ toast({
122
+ variant: 'error',
123
+ title: 'Folder kept',
124
+ description: cause instanceof Error ? cause.message : String(cause),
125
+ });
126
+ }
127
+ };
128
+ return (
129
+ <Dialog
130
+ open={!!offer}
131
+ onOpenChange={(open) => {
132
+ if (!open) onClose();
133
+ }}
134
+ >
135
+ <DialogContent>
136
+ <DialogHeader>
137
+ <DialogTitle>
138
+ {offer?.kept ? 'Its folder stays' : 'Delete the branch’s folder too?'}
139
+ </DialogTitle>
140
+ </DialogHeader>
141
+ <DialogBody className="pb-3">
142
+ <DialogDescription>
143
+ {offer &&
144
+ (offer.kept
145
+ ? `No session works on ${offer.name} now. Its folder is kept: ${offer.kept}`
146
+ : `No session works on ${offer.name} now. Its folder (${offer.folder}) can go; the git branch stays.`)}
147
+ </DialogDescription>
148
+ </DialogBody>
149
+ <DialogFooter className="justify-end gap-2">
150
+ {offer?.kept ? (
151
+ <Button variant="primary" autoFocus onClick={onClose}>
152
+ OK
153
+ </Button>
154
+ ) : (
155
+ <>
156
+ <Button onClick={onClose}>Keep folder</Button>
157
+ <Button variant="destructive" autoFocus onClick={() => offer && void remove(offer)}>
158
+ Delete folder
159
+ </Button>
160
+ </>
161
+ )}
162
+ </DialogFooter>
163
+ </DialogContent>
164
+ </Dialog>
165
+ );
166
+ }