@bridgebrew/sessions 0.0.34 → 0.0.43
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/branch-name.ts +45 -0
- package/browser/branch-actions.tsx +26 -47
- package/browser/conversation.tsx +123 -3
- package/browser/details.tsx +408 -0
- package/browser/index.tsx +685 -497
- package/browser/mobile.tsx +118 -8
- package/browser/pull-request.tsx +9 -6
- package/browser/session-scheduled.tsx +6 -3
- package/browser/subagent-view.tsx +2 -2
- package/contract.ts +6 -0
- package/delegations.ts +6 -7
- package/package.json +51 -10
- package/server.ts +642 -236
- package/text.ts +9 -0
- package/browser/changes.tsx +0 -464
- package/git.ts +0 -318
package/branch-name.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// A session's branch name (research-083): from a model's answer (`type/topic`), else from the words of the message
|
|
2
|
+
// that asked for the work.
|
|
3
|
+
/** The letters NFKD leaves whole (no base letter and mark to split them into), spelled in plain Latin (plugins#217). */
|
|
4
|
+
const LETTERS: Record<string, string> = { ß: 'ss', æ: 'ae', œ: 'oe', ø: 'o', ł: 'l', đ: 'd', ð: 'd', þ: 'th', ı: 'i' };
|
|
5
|
+
/** `text` lowercase in plain Latin letters where it has them: those letters spelled out, then accents dropped
|
|
6
|
+
* (`Straße Łódź` → `strasse lodz`). */
|
|
7
|
+
export const foldLetters = (text: string) =>
|
|
8
|
+
text
|
|
9
|
+
// ʼn first: NFKD splits it into an apostrophe and `n`, which would split the word.
|
|
10
|
+
.replace(/ʼn/g, 'n')
|
|
11
|
+
// NFKD before the rest: it reveals letters (`Ǽ` → `Æ` + accent, `𝐒` → `S`) the table and the lowercase then see.
|
|
12
|
+
.normalize('NFKD')
|
|
13
|
+
.toLowerCase()
|
|
14
|
+
.replace(/[ßæœøłđðþı]/g, (letter) => LETTERS[letter] ?? letter)
|
|
15
|
+
.replace(/[\u0300-\u036f]/g, '');
|
|
16
|
+
|
|
17
|
+
/** A branch name from a message (research-083): its first words, lowercase, joined by `-`; empty when it has none.
|
|
18
|
+
* A URL gives none of them (plugins#73). The fallback of a model's name (`typedBranch`). */
|
|
19
|
+
export const branchSlug = (text: string) =>
|
|
20
|
+
foldLetters(text.replace(/\b[a-z][a-z0-9+.-]*:\/\/\S*/gi, ' '))
|
|
21
|
+
.replace(/['’]/g, '')
|
|
22
|
+
.split(/[^a-z0-9]+/)
|
|
23
|
+
.filter(Boolean)
|
|
24
|
+
.slice(0, 6)
|
|
25
|
+
// Whole words within 40 characters (a single longer word cut).
|
|
26
|
+
.reduce(
|
|
27
|
+
(name, word) =>
|
|
28
|
+
!name ? word.slice(0, 40) : name.length + 1 + word.length <= 40 ? `${name}-${word}` : name,
|
|
29
|
+
'',
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
/** The example of the prompt that asks a model for a branch name: never taken as its answer (plugins#110). */
|
|
33
|
+
export const BRANCH_EXAMPLE = 'fix/e2e-shards';
|
|
34
|
+
|
|
35
|
+
/** A model's answer as a `type/topic` branch name (`fix/login-timeout`), `undefined` when it is not one or is the prompt's
|
|
36
|
+
* own example (a model echoing it would name every branch the same). */
|
|
37
|
+
export const typedBranch = (answer: string) => {
|
|
38
|
+
// Its first line: a model may go on after the name (plugins#84).
|
|
39
|
+
const name = (answer.trim().split('\n')[0] ?? '').trim().replace(/^`+|`+$/g, '');
|
|
40
|
+
return name.length <= 40 &&
|
|
41
|
+
/^(feat|fix|chore|ci|docs|refactor|test)\/[a-z0-9]+(-[a-z0-9]+)*$/.test(name) &&
|
|
42
|
+
name !== BRANCH_EXAMPLE
|
|
43
|
+
? name
|
|
44
|
+
: undefined;
|
|
45
|
+
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
// A session's branch from its page (research-083):
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
1
|
+
// A session's branch from its page (research-083): archiving the branch's last session offers to delete that folder
|
|
2
|
+
// (never one with work not committed or not pushed; the git branch stays), through the project plugin's Branches
|
|
3
|
+
// routes (`/<slug>/api/project/branches/…`, bridgebrew/bridge#557), as the Branches screen does: the same checks, the
|
|
4
|
+
// owner's page. Its Git button is the `git` plugin's (`sessions.details`, bridge-plugins#256); `installGit` installs
|
|
5
|
+
// that plugin when the workspace lacks it.
|
|
5
6
|
// ponytail: cleanup is asked, never automatic (merged, inactive, unchanged): its rules are bridge#348.
|
|
6
7
|
import * as React from 'react';
|
|
7
8
|
import {
|
|
@@ -16,12 +17,17 @@ import {
|
|
|
16
17
|
readJson,
|
|
17
18
|
useToast,
|
|
18
19
|
} from '@bridge/ui';
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
|
|
21
|
+
/** What the project plugin's Branches route lists of a branch, the part read here. */
|
|
22
|
+
interface ListedBranch {
|
|
23
|
+
name: string;
|
|
24
|
+
folder: string;
|
|
25
|
+
main: boolean;
|
|
26
|
+
dirty: number;
|
|
27
|
+
unpushed: number;
|
|
28
|
+
active: boolean;
|
|
29
|
+
}
|
|
30
|
+
type BranchesRoute = (slug: string, node: string, action?: string) => string;
|
|
25
31
|
|
|
26
32
|
/** The project plugin's Branches route of project `node` in workspace `slug`, or one of its actions. */
|
|
27
33
|
export const branchesRoute: BranchesRoute = (slug, node, action) =>
|
|
@@ -36,43 +42,16 @@ const post = async (slug: string, node: string, action: string, body: Record<str
|
|
|
36
42
|
}),
|
|
37
43
|
);
|
|
38
44
|
|
|
39
|
-
/**
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
session,
|
|
48
|
-
refresh,
|
|
49
|
-
pullRequestOpen = false,
|
|
50
|
-
onGitAnswer,
|
|
51
|
-
}: {
|
|
52
|
-
slug: string;
|
|
53
|
-
node: string;
|
|
54
|
-
branch: string;
|
|
55
|
-
session: string;
|
|
56
|
-
refresh?: unknown;
|
|
57
|
-
pullRequestOpen?: boolean;
|
|
58
|
-
onGitAnswer?: () => void;
|
|
59
|
-
}) {
|
|
60
|
-
const [state, take] = useBranch(slug, node, branch, refresh, branchesRoute);
|
|
61
|
-
if (!state) return null;
|
|
62
|
-
return (
|
|
63
|
-
<GitActions
|
|
64
|
-
slug={slug}
|
|
65
|
-
node={node}
|
|
66
|
-
branch={pullRequestOpen && !state.prOpen ? { ...state, prOpen: true } : state}
|
|
67
|
-
session={session}
|
|
68
|
-
route={branchesRoute}
|
|
69
|
-
onAnswer={(answer) => {
|
|
70
|
-
take(answer);
|
|
71
|
-
onGitAnswer?.();
|
|
72
|
-
}}
|
|
73
|
-
/>
|
|
45
|
+
/** Installs the `git` plugin in workspace `slug` (the Plugins screen's own install). */
|
|
46
|
+
export const installGit = async (slug: string) => {
|
|
47
|
+
await readJson(
|
|
48
|
+
await fetch(`/_bridge/workspaces/${encodeURIComponent(slug)}/plugins/install`, {
|
|
49
|
+
method: 'POST',
|
|
50
|
+
headers: { 'content-type': 'application/json' },
|
|
51
|
+
body: JSON.stringify({ source: '@bridgebrew/git' }),
|
|
52
|
+
}),
|
|
74
53
|
);
|
|
75
|
-
}
|
|
54
|
+
};
|
|
76
55
|
|
|
77
56
|
/** The folder cleanup an archive offers: the branch, and why its folder must stay, if it must. */
|
|
78
57
|
export interface Cleanup {
|
|
@@ -93,7 +72,7 @@ export const cleanupOf = async (
|
|
|
93
72
|
// The project plugin's own answer: typed once where it is read.
|
|
94
73
|
const view = (await readJson(
|
|
95
74
|
await fetch(branchesRoute(slug, node), { cache: 'no-store' }),
|
|
96
|
-
)) as
|
|
75
|
+
)) as { branches: ListedBranch[] };
|
|
97
76
|
const found = view.branches.find((each) => each.name === branch && !each.main);
|
|
98
77
|
if (!found) return undefined;
|
|
99
78
|
const why = [
|
package/browser/conversation.tsx
CHANGED
|
@@ -325,6 +325,42 @@ function CodeBlock({ children }: { children?: React.ReactNode }) {
|
|
|
325
325
|
);
|
|
326
326
|
}
|
|
327
327
|
|
|
328
|
+
/** Open in editor from the conversation (bridge-plugins#253): an agent's link to a file of the session's folder opens it
|
|
329
|
+
* in the code editor (`label`: `Open in VS Code on mac-mini`), at its line; none on a phone, nor without an editor. */
|
|
330
|
+
export interface FileOpener {
|
|
331
|
+
folder: string;
|
|
332
|
+
label: string;
|
|
333
|
+
open: (target: FileTarget) => void;
|
|
334
|
+
/** About to be used (a link pointed at, focused): the editor read again. */
|
|
335
|
+
refresh?: () => void;
|
|
336
|
+
/** Not available from this page (another computer): the link says so (`label`), and `open` only explains. */
|
|
337
|
+
unavailable?: boolean;
|
|
338
|
+
}
|
|
339
|
+
export interface FileTarget {
|
|
340
|
+
path: string;
|
|
341
|
+
line?: number;
|
|
342
|
+
column?: number;
|
|
343
|
+
}
|
|
344
|
+
const FileLinks = React.createContext<FileOpener | null>(null);
|
|
345
|
+
/** The file a link names inside `folder`: an absolute path, its position after it (`a.ts:12`, `a.ts:12:3`) or in its
|
|
346
|
+
* fragment (`a.ts#L12`, `#L12C3`), a Windows one too (`C:\\w\\a.ts:12`); none for any other link (a page of this Bridge,
|
|
347
|
+
* a file elsewhere). */
|
|
348
|
+
export const fileTarget = (href: string, folder: string): FileTarget | undefined => {
|
|
349
|
+
const [raw = '', fragment = ''] = href.split('#', 2);
|
|
350
|
+
let path: string;
|
|
351
|
+
try {
|
|
352
|
+
// A Windows path (`C:\\w\\a.ts`) read with `/`, as its folder: Windows takes either.
|
|
353
|
+
path = decodeURI(raw).replaceAll('\\', '/');
|
|
354
|
+
} catch {
|
|
355
|
+
return undefined;
|
|
356
|
+
}
|
|
357
|
+
const base = folder.replaceAll('\\', '/').replace(/\/$/, '');
|
|
358
|
+
const at = /:(\d+)(?::(\d+))?$/.exec(path) ?? /^L(\d+)(?:C(\d+))?$/.exec(fragment);
|
|
359
|
+
if (at?.index !== undefined && at.input === path) path = path.slice(0, at.index);
|
|
360
|
+
if (!path.startsWith(`${base}/`) || path.split('/').includes('..')) return undefined;
|
|
361
|
+
return { path, ...(at && { line: Number(at[1]) }), ...(at?.[2] && { column: Number(at[2]) }) };
|
|
362
|
+
};
|
|
363
|
+
|
|
328
364
|
/** Markdown in the chat's type, GitHub's flavour (tables, bare URLs as links): no raw HTML (react-markdown escapes it),
|
|
329
365
|
* external links in a new tab, local images and videos shown (`media.tsx`). */
|
|
330
366
|
const markdown: Components = {
|
|
@@ -339,7 +375,25 @@ const markdown: Components = {
|
|
|
339
375
|
),
|
|
340
376
|
// A link of this Bridge stays an anchor without a target, which the shell's link rule follows (research-048: a plain
|
|
341
377
|
// click here, ⌘ or a middle click beside, ⌥ on a new desk); another opens in a new tab, which gets no `opener`.
|
|
342
|
-
a: ({ node: _node, ...props })
|
|
378
|
+
a: function Link({ node: _node, ...props }) {
|
|
379
|
+
const opener = React.useContext(FileLinks);
|
|
380
|
+
const file = opener && props.href ? fileTarget(props.href, opener.folder) : undefined;
|
|
381
|
+
if (opener && file)
|
|
382
|
+
return (
|
|
383
|
+
<a
|
|
384
|
+
{...props}
|
|
385
|
+
className="text-accent underline-offset-2 hover:underline"
|
|
386
|
+
title={opener.label}
|
|
387
|
+
aria-disabled={opener.unavailable || undefined}
|
|
388
|
+
data-open-in-editor
|
|
389
|
+
onPointerEnter={opener.refresh}
|
|
390
|
+
onFocus={opener.refresh}
|
|
391
|
+
onClick={(event) => {
|
|
392
|
+
event.preventDefault();
|
|
393
|
+
opener.open(file);
|
|
394
|
+
}}
|
|
395
|
+
/>
|
|
396
|
+
);
|
|
343
397
|
let internal = false;
|
|
344
398
|
if (typeof location !== 'undefined' && props.href) {
|
|
345
399
|
try {
|
|
@@ -381,7 +435,10 @@ const markdown: Components = {
|
|
|
381
435
|
),
|
|
382
436
|
};
|
|
383
437
|
const remarkPlugins = [remarkGfm];
|
|
384
|
-
|
|
438
|
+
// A link to a Windows path (`C:\\w\\a.ts`) is kept: react-markdown's filter reads `C:` as a scheme and drops it, and
|
|
439
|
+
// Open in editor reads it (`fileTarget`); a link to no file of the session stays inert (`c:` opens nothing).
|
|
440
|
+
const urlTransform = (url: string, key: string) =>
|
|
441
|
+
key === 'href' && /^[a-z]:[\\/]/i.test(url) ? url : mediaUrl(url, key, defaultUrlTransform);
|
|
385
442
|
/** The blinking caret after a streaming reply's last block (a pseudo-element: no text). */
|
|
386
443
|
const caret =
|
|
387
444
|
"[&>:last-child]:after:ml-0.5 [&>:last-child]:after:inline-block [&>:last-child]:after:h-[1em] [&>:last-child]:after:w-[0.45em] [&>:last-child]:after:translate-y-[0.15em] [&>:last-child]:after:animate-pulse [&>:last-child]:after:rounded-[1px] [&>:last-child]:after:bg-foreground [&>:last-child]:after:content-['']";
|
|
@@ -940,6 +997,8 @@ export interface ConversationProps {
|
|
|
940
997
|
onOpenChange?: ((path: string) => void) | undefined;
|
|
941
998
|
/** The session's lineage (./children.tsx): its children's cards, its parent; without it, none drawn. */
|
|
942
999
|
lineage?: Lineage | undefined;
|
|
1000
|
+
/** Its links to files of its folder open in the code editor (none: plain links). */
|
|
1001
|
+
openFile?: FileOpener | undefined;
|
|
943
1002
|
}
|
|
944
1003
|
|
|
945
1004
|
/** No child delegated in a turn: the same array each render. */
|
|
@@ -997,6 +1056,7 @@ export function Conversation({
|
|
|
997
1056
|
onDecisionShown,
|
|
998
1057
|
onOpenChange,
|
|
999
1058
|
lineage,
|
|
1059
|
+
openFile,
|
|
1000
1060
|
}: ConversationProps) {
|
|
1001
1061
|
/** Turns opened or folded by the user, by key: otherwise a completed turn is folded. */
|
|
1002
1062
|
const [unfolded, setUnfolded] = React.useState<Record<number, boolean>>({});
|
|
@@ -1050,6 +1110,22 @@ export function Conversation({
|
|
|
1050
1110
|
};
|
|
1051
1111
|
}, [events, cut]);
|
|
1052
1112
|
const subagents = React.useMemo(() => subagentsByTurn(turns, events), [turns, events]);
|
|
1113
|
+
// The same opener while its folder and label stay: a new one would redraw every link at each streamed delta.
|
|
1114
|
+
const openNow = React.useRef(openFile);
|
|
1115
|
+
openNow.current = openFile;
|
|
1116
|
+
const opener = React.useMemo(
|
|
1117
|
+
() =>
|
|
1118
|
+
openFile?.folder && openFile.label
|
|
1119
|
+
? {
|
|
1120
|
+
folder: openFile.folder,
|
|
1121
|
+
label: openFile.label,
|
|
1122
|
+
open: (target: FileTarget) => openNow.current?.open(target),
|
|
1123
|
+
refresh: () => openNow.current?.refresh?.(),
|
|
1124
|
+
...(openFile.unavailable && { unavailable: true }),
|
|
1125
|
+
}
|
|
1126
|
+
: null,
|
|
1127
|
+
[openFile?.folder, openFile?.label, openFile?.unavailable],
|
|
1128
|
+
);
|
|
1053
1129
|
const shownLive = React.useMemo(() => ownLive(live), [live]);
|
|
1054
1130
|
const last = turns.findLast((turn) => turn.start || turn.partial);
|
|
1055
1131
|
// Each turn's children (bridge#212): the delegations its calls made, else those made while it was the last started.
|
|
@@ -1060,6 +1136,7 @@ export function Conversation({
|
|
|
1060
1136
|
);
|
|
1061
1137
|
return (
|
|
1062
1138
|
<LineageContext.Provider value={lineage ?? null}>
|
|
1139
|
+
<FileLinks.Provider value={opener}>
|
|
1063
1140
|
<MediaWorkspace.Provider value={workspace}>
|
|
1064
1141
|
<MediaOrigins.Provider value={origins}>
|
|
1065
1142
|
<ol
|
|
@@ -1085,6 +1162,7 @@ export function Conversation({
|
|
|
1085
1162
|
</ol>
|
|
1086
1163
|
</MediaOrigins.Provider>
|
|
1087
1164
|
</MediaWorkspace.Provider>
|
|
1165
|
+
</FileLinks.Provider>
|
|
1088
1166
|
</LineageContext.Provider>
|
|
1089
1167
|
);
|
|
1090
1168
|
}
|
|
@@ -1830,6 +1908,48 @@ function Thought({ text, answered }: { text: string; answered: boolean }) {
|
|
|
1830
1908
|
|
|
1831
1909
|
/** The user's message: its images (`AttachedImages`), then a bubble, folded past about ten lines; its time, Copy and
|
|
1832
1910
|
* Reuse on hover. */
|
|
1911
|
+
/** A message's text cut around the mentions the composer writes (plugins#239): `@session:<id>`, `@path` with a `/`
|
|
1912
|
+
* or a `.` in it (`@someone`, `@README` stay text), and `@"path"` for one with a blank; the punctuation after one is
|
|
1913
|
+
* the text's. */
|
|
1914
|
+
export const mentionParts = (text: string) => {
|
|
1915
|
+
const parts: (string | { kind: 'file' | 'session'; value: string })[] = [];
|
|
1916
|
+
let at = 0;
|
|
1917
|
+
for (const found of text.matchAll(/(?<=^|\s)@(?:"([^"\n]+)"|(\S+?))(?=[.,;:!?)]*(?:\s|$))/g)) {
|
|
1918
|
+
const quoted = found[1];
|
|
1919
|
+
const value = quoted ?? found[2]!;
|
|
1920
|
+
const session = quoted ? undefined : /^session:([\w-]+)$/.exec(value)?.[1];
|
|
1921
|
+
if (!quoted && !session && !/[/.]/.test(value)) continue;
|
|
1922
|
+
if (found.index > at) parts.push(text.slice(at, found.index));
|
|
1923
|
+
parts.push(session ? { kind: 'session', value: session } : { kind: 'file', value });
|
|
1924
|
+
at = found.index + found[0].length;
|
|
1925
|
+
}
|
|
1926
|
+
if (at < text.length) parts.push(text.slice(at));
|
|
1927
|
+
return parts;
|
|
1928
|
+
};
|
|
1929
|
+
|
|
1930
|
+
/** A message's text, its mentions as chips. */
|
|
1931
|
+
function MentionText({ text }: { text: string }) {
|
|
1932
|
+
return mentionParts(text).map((part, index) =>
|
|
1933
|
+
typeof part === 'string' ? (
|
|
1934
|
+
part
|
|
1935
|
+
) : (
|
|
1936
|
+
<span
|
|
1937
|
+
key={index}
|
|
1938
|
+
data-mention={part.kind}
|
|
1939
|
+
title={part.kind === 'session' ? `Session ${part.value}` : part.value}
|
|
1940
|
+
className="inline-flex max-w-full items-center gap-1 rounded-control bg-surface px-1 align-bottom text-[13px]"
|
|
1941
|
+
>
|
|
1942
|
+
<Icon
|
|
1943
|
+
name={part.kind === 'session' ? 'message-square' : 'file'}
|
|
1944
|
+
size={12}
|
|
1945
|
+
className="shrink-0 text-muted"
|
|
1946
|
+
/>
|
|
1947
|
+
<span className="truncate">{part.value}</span>
|
|
1948
|
+
</span>
|
|
1949
|
+
),
|
|
1950
|
+
);
|
|
1951
|
+
}
|
|
1952
|
+
|
|
1833
1953
|
const UserMessage = React.memo(function UserMessage({
|
|
1834
1954
|
event,
|
|
1835
1955
|
onReuse,
|
|
@@ -1864,7 +1984,7 @@ const UserMessage = React.memo(function UserMessage({
|
|
|
1864
1984
|
!full && 'max-h-60 overflow-hidden',
|
|
1865
1985
|
)}
|
|
1866
1986
|
>
|
|
1867
|
-
{text}
|
|
1987
|
+
<MentionText text={text ?? ''} />
|
|
1868
1988
|
</div>
|
|
1869
1989
|
) : null}
|
|
1870
1990
|
{long && (
|