@bridgebrew/sessions 0.0.27 → 0.0.28
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/browser/branch-actions.tsx +10 -5
- package/browser/index.tsx +1 -1
- package/package.json +2 -2
- package/server.ts +27 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// A session's branch from its page (research-083): its Git button (`@bridge/session-ui/git-actions`) acts on its branch's
|
|
2
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 (
|
|
4
|
-
// Branches screen does: the same checks, the owner's page.
|
|
3
|
+
// stays). Both go through the project plugin's Branches routes (`/<slug>/api/project/branches/…`, bridgebrew/bridge#557),
|
|
4
|
+
// as the Branches screen does: the same checks, the owner's page.
|
|
5
5
|
// ponytail: cleanup is asked, never automatic (merged, inactive, unchanged): its rules are bridge#348.
|
|
6
6
|
import * as React from 'react';
|
|
7
7
|
import {
|
|
@@ -18,11 +18,15 @@ import {
|
|
|
18
18
|
} from '@bridge/ui';
|
|
19
19
|
import {
|
|
20
20
|
GitActions,
|
|
21
|
-
branchesRoute,
|
|
22
21
|
useBranch,
|
|
23
22
|
type BranchesAnswer,
|
|
23
|
+
type BranchesRoute,
|
|
24
24
|
} from '@bridge/session-ui/git-actions';
|
|
25
25
|
|
|
26
|
+
/** The project plugin's Branches route of project `node` in workspace `slug`, or one of its actions. */
|
|
27
|
+
export const branchesRoute: BranchesRoute = (slug, node, action) =>
|
|
28
|
+
`/${encodeURIComponent(slug)}/api/project/branches${action ? `/${action}` : ''}?node=${encodeURIComponent(node)}`;
|
|
29
|
+
|
|
26
30
|
const post = async (slug: string, node: string, action: string, body: Record<string, unknown>) =>
|
|
27
31
|
readJson(
|
|
28
32
|
await fetch(branchesRoute(slug, node, action), {
|
|
@@ -53,7 +57,7 @@ export function BranchActions({
|
|
|
53
57
|
pullRequestOpen?: boolean;
|
|
54
58
|
onGitAnswer?: () => void;
|
|
55
59
|
}) {
|
|
56
|
-
const [state, take] = useBranch(slug, node, branch, refresh);
|
|
60
|
+
const [state, take] = useBranch(slug, node, branch, refresh, branchesRoute);
|
|
57
61
|
if (!state) return null;
|
|
58
62
|
return (
|
|
59
63
|
<GitActions
|
|
@@ -61,6 +65,7 @@ export function BranchActions({
|
|
|
61
65
|
node={node}
|
|
62
66
|
branch={pullRequestOpen && !state.prOpen ? { ...state, prOpen: true } : state}
|
|
63
67
|
session={session}
|
|
68
|
+
route={branchesRoute}
|
|
64
69
|
onAnswer={(answer) => {
|
|
65
70
|
take(answer);
|
|
66
71
|
onGitAnswer?.();
|
|
@@ -85,7 +90,7 @@ export const cleanupOf = async (
|
|
|
85
90
|
node: string,
|
|
86
91
|
branch: string,
|
|
87
92
|
): Promise<Cleanup | undefined> => {
|
|
88
|
-
// The
|
|
93
|
+
// The project plugin's own answer: typed once where it is read.
|
|
89
94
|
const view = (await readJson(
|
|
90
95
|
await fetch(branchesRoute(slug, node), { cache: 'no-store' }),
|
|
91
96
|
)) as BranchesAnswer;
|
package/browser/index.tsx
CHANGED
|
@@ -224,7 +224,7 @@ const useBranches = (slug: string, node: string, startNew = false) => {
|
|
|
224
224
|
choose(undefined);
|
|
225
225
|
if (node === 'root') return;
|
|
226
226
|
fetch(
|
|
227
|
-
|
|
227
|
+
`/${encodeURIComponent(slug)}/api/project/branches?node=${encodeURIComponent(node)}`,
|
|
228
228
|
{ cache: 'no-store' },
|
|
229
229
|
)
|
|
230
230
|
.then((res) => (res.ok ? readJson(res) : undefined))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bridgebrew/sessions",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.28",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Conversations with agents, in the workspace or in a project, through the Profile.",
|
|
6
6
|
"keywords": [
|
|
@@ -1027,6 +1027,6 @@
|
|
|
1027
1027
|
},
|
|
1028
1028
|
"releaseStage": "dev",
|
|
1029
1029
|
"engines": {
|
|
1030
|
-
"bridge": ">=0.0.1-nightly.20261118.
|
|
1030
|
+
"bridge": ">=0.0.1-nightly.20261118.2"
|
|
1031
1031
|
}
|
|
1032
1032
|
}
|
package/server.ts
CHANGED
|
@@ -229,6 +229,11 @@ const attachment = z.strictObject({
|
|
|
229
229
|
size: z.number().int().positive(),
|
|
230
230
|
});
|
|
231
231
|
type Attachment = z.infer<typeof attachment>;
|
|
232
|
+
/** The project plugin's `projectBranches` service (bridgebrew/bridge#557), never imported: what Sessions uses of it. */
|
|
233
|
+
interface ProjectBranches {
|
|
234
|
+
newBranch(input: { node: string; name: string; existing?: boolean }): Promise<{ name: string; folder: string }>;
|
|
235
|
+
branchForPlugins(input: { plugins: string[]; name: string }): Promise<{ repository: string; name: string; folder: string }>;
|
|
236
|
+
}
|
|
232
237
|
/** What the gallery keeps, by a file's extension: the images and videos a browser shows (never SVG: it would run). */
|
|
233
238
|
const PIN_TYPES = {
|
|
234
239
|
'.png': 'image/png',
|
|
@@ -1250,10 +1255,13 @@ export async function apply(ctx: Context, config?: unknown) {
|
|
|
1250
1255
|
/** A new branch `name` of the project on `node` (research-083), made by the host as the Branches screen makes one
|
|
1251
1256
|
* (its worktree under `.worktrees/`, installed); `name` numbered when taken. */
|
|
1252
1257
|
const makeBranch = async (node: string, name: string, temporary = false) => {
|
|
1253
|
-
const service =
|
|
1258
|
+
const service = projectBranches();
|
|
1254
1259
|
const project = node === 'root' ? undefined : await folderOf(node);
|
|
1255
1260
|
if (!service || project === undefined)
|
|
1256
|
-
throw refused(
|
|
1261
|
+
throw refused(
|
|
1262
|
+
'branches_unavailable',
|
|
1263
|
+
service ? `node ${node} has no branches here` : 'branches need Projects 0.0.2 or later in this workspace: install or update it (Plugins)',
|
|
1264
|
+
);
|
|
1257
1265
|
try {
|
|
1258
1266
|
const made = await service.newBranch({ node, name: await freeBranch(run, project, name) });
|
|
1259
1267
|
return { ...made, ...(temporary && { temporary: true as const }) };
|
|
@@ -1484,7 +1492,7 @@ export async function apply(ctx: Context, config?: unknown) {
|
|
|
1484
1492
|
const kept =
|
|
1485
1493
|
project !== undefined &&
|
|
1486
1494
|
(await run(project, ['branch', '--list', branch.name])).stdout.trim() !== '';
|
|
1487
|
-
const service =
|
|
1495
|
+
const service = projectBranches();
|
|
1488
1496
|
if (!kept || !service)
|
|
1489
1497
|
throw new Error(
|
|
1490
1498
|
`branch ${branch.name} is gone: its folder ${branch.folder}${kept ? ' cannot be made again here' : ' and its git branch were deleted'}; start a new session`,
|
|
@@ -1838,6 +1846,16 @@ export async function apply(ctx: Context, config?: unknown) {
|
|
|
1838
1846
|
/** The host's per-session MCP tokens: optional (not in `inject`), so a host without them still loads this plugin, its
|
|
1839
1847
|
* sessions' MCP calls then running as `agent`. */
|
|
1840
1848
|
const bridgeMcp = () => ctx.get('bridgeMcp', false) as Context['bridgeMcp'] | undefined;
|
|
1849
|
+
/** The project plugin's branches (bridgebrew/bridge#557): a session's branch and a child's are made there. */
|
|
1850
|
+
const projectBranches = () => {
|
|
1851
|
+
const service: unknown = ctx.get('projectBranches', false);
|
|
1852
|
+
return isRecord(service) &&
|
|
1853
|
+
typeof service.newBranch === 'function' &&
|
|
1854
|
+
typeof service.branchForPlugins === 'function'
|
|
1855
|
+
? // oxlint-disable-next-line bridge/no-new-unchecked-cast -- its two functions checked above, project's own service
|
|
1856
|
+
(service as unknown as ProjectBranches)
|
|
1857
|
+
: undefined;
|
|
1858
|
+
};
|
|
1841
1859
|
/** A new MCP token for session `id`, `undefined` without the service or when the host refused (logged): the session
|
|
1842
1860
|
* then opens without one. Not claimed yet (`claim`). */
|
|
1843
1861
|
const issueToken = async (id: string, worktree?: string) => {
|
|
@@ -4424,9 +4442,14 @@ export async function apply(ctx: Context, config?: unknown) {
|
|
|
4424
4442
|
// A child's own worktree (S7): added by the host, as `stage_add` adds one.
|
|
4425
4443
|
addWorktree: async (input) => {
|
|
4426
4444
|
const service = bridgeMcp();
|
|
4445
|
+
const branches = projectBranches();
|
|
4427
4446
|
if (!service) throw refused('worktrees_unavailable', 'this Bridge cannot add a worktree');
|
|
4447
|
+
if (!branches)
|
|
4448
|
+
throw refused('worktrees_unavailable', "a child's own branch needs Projects 0.0.2 or later in this workspace: install or update it (Plugins)");
|
|
4428
4449
|
try {
|
|
4429
|
-
|
|
4450
|
+
// Its branch made by the project plugin, in the checkout the plugins run from; the stage chooses it.
|
|
4451
|
+
const made = await branches.branchForPlugins({ plugins: input.plugins, name: input.branch });
|
|
4452
|
+
return await service.addWorktree({ branch: made.name, plugins: input.plugins, existing: true });
|
|
4430
4453
|
} catch (error) {
|
|
4431
4454
|
throw refused('worktree_refused', error instanceof Error ? error.message : String(error));
|
|
4432
4455
|
}
|