@bridgebrew/project 0.0.0-stage → 0.0.2
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/LICENSE +21 -0
- package/branches.ts +1220 -0
- package/browser/branches.tsx +642 -0
- package/browser/browser.tsx +265 -0
- package/browser/mobile.tsx +62 -0
- package/browser/new-project.tsx +185 -0
- package/browser/overview.tsx +192 -0
- package/browser/project.d.ts +60 -0
- package/browser/sources.tsx +310 -0
- package/browser/tsconfig.json +15 -0
- package/names.ts +28 -0
- package/package.json +108 -4
- package/server.ts +338 -0
- package/tsconfig.json +1 -0
- package/README.md +0 -3
package/package.json
CHANGED
|
@@ -1,6 +1,110 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bridgebrew/project",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "A project is a folder of work with its bridge.yml, and a node with its own sessions: code, documents, anything; Bridge plugins can be made there too.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"bridge-plugin"
|
|
8
|
+
],
|
|
9
|
+
"type": "module",
|
|
10
|
+
"files": [
|
|
11
|
+
"*.json",
|
|
12
|
+
"*.ts",
|
|
13
|
+
"browser/",
|
|
14
|
+
"!**/*.test.ts",
|
|
15
|
+
"!**/*.test.tsx"
|
|
16
|
+
],
|
|
17
|
+
"bridge": {
|
|
18
|
+
"kind": "application",
|
|
19
|
+
"title": "Projects",
|
|
20
|
+
"icon": "folder",
|
|
21
|
+
"domain": "development",
|
|
22
|
+
"server": "./server.ts",
|
|
23
|
+
"browser": "./browser/browser.tsx",
|
|
24
|
+
"requires": {
|
|
25
|
+
"storage": {}
|
|
26
|
+
},
|
|
27
|
+
"screen": [
|
|
28
|
+
{
|
|
29
|
+
"id": "overview",
|
|
30
|
+
"title": "Overview",
|
|
31
|
+
"icon": "layout-dashboard",
|
|
32
|
+
"home": true,
|
|
33
|
+
"view": false
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"id": "projects",
|
|
37
|
+
"title": "Projects",
|
|
38
|
+
"icon": "folder",
|
|
39
|
+
"mobile": true
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"id": "branches",
|
|
43
|
+
"title": "Branches",
|
|
44
|
+
"icon": "git-branch",
|
|
45
|
+
"view": false
|
|
46
|
+
}
|
|
47
|
+
],
|
|
48
|
+
"tools": {
|
|
49
|
+
"new_project": {
|
|
50
|
+
"description": "Create a project in this Bridge workspace: a folder of work (code, documents, anything) with its bridge.yml, listed in its parent's, and a node with its own sessions. Give its name: the folder is created in the parent project's projects/ folder (the workspace's at the root); git: true makes it a repository of its own; clone: <git url> clones that repository there instead, its parent's bridge.yml naming it by URL and commit. Give a path instead for an existing folder inside the parent's. Answers { node }. A Bridge plugin made in a project goes in its plugins/<name> folder: bridge plugin init plugins/<name>, run in the project's folder, writes it and its line in bridge.yml; Bridge installs it and activates it on the project at once.",
|
|
51
|
+
"method": "POST",
|
|
52
|
+
"path": "/projects/new",
|
|
53
|
+
"input": {
|
|
54
|
+
"type": "object",
|
|
55
|
+
"properties": {
|
|
56
|
+
"name": {
|
|
57
|
+
"type": "string",
|
|
58
|
+
"description": "The project's folder name, created in the parent project's projects/ folder."
|
|
59
|
+
},
|
|
60
|
+
"path": {
|
|
61
|
+
"type": "string",
|
|
62
|
+
"description": "Instead of name: an existing folder inside the parent project's folder."
|
|
63
|
+
},
|
|
64
|
+
"title": {
|
|
65
|
+
"type": "string",
|
|
66
|
+
"description": "The project's title; its folder name by default."
|
|
67
|
+
},
|
|
68
|
+
"git": {
|
|
69
|
+
"type": "boolean",
|
|
70
|
+
"description": "With name: the new folder is a git repository of its own (else it shares its parent's, if any)."
|
|
71
|
+
},
|
|
72
|
+
"clone": {
|
|
73
|
+
"type": "string",
|
|
74
|
+
"description": "With name: a git URL cloned into the parent project's projects/<name> folder instead of an empty folder."
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
"additionalProperties": false
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
"deadlines": {
|
|
82
|
+
"/projects/new": 120000,
|
|
83
|
+
"/branches/new": 120000,
|
|
84
|
+
"/branches/activate": 120000,
|
|
85
|
+
"/branches/commit": 120000,
|
|
86
|
+
"/branches/push": 120000,
|
|
87
|
+
"/branches/pull": 120000,
|
|
88
|
+
"/branches/pr": 120000,
|
|
89
|
+
"/branches/remove": 120000
|
|
90
|
+
},
|
|
91
|
+
"provenance": "official"
|
|
92
|
+
},
|
|
93
|
+
"dependencies": {
|
|
94
|
+
"zod": "4.6.5"
|
|
95
|
+
},
|
|
96
|
+
"peerDependencies": {
|
|
97
|
+
"@bridge/session-ui": ">=0.0.1",
|
|
98
|
+
"@bridge/ui": ">=0.0.1",
|
|
99
|
+
"cordis": "4.0.0-rc.11",
|
|
100
|
+
"react": "19.3.0"
|
|
101
|
+
},
|
|
102
|
+
"releaseStage": "dev",
|
|
103
|
+
"scripts": {
|
|
104
|
+
"test": "node ../bridge/node_modules/vitest/vitest.mjs run --config ../scripts/vitest.config.ts",
|
|
105
|
+
"typecheck": "bridge plugin check ."
|
|
106
|
+
},
|
|
107
|
+
"engines": {
|
|
108
|
+
"bridge": ">=0.0.1-nightly.20261118.2"
|
|
109
|
+
}
|
|
110
|
+
}
|
package/server.ts
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
// The project plugin (foundation, AD-24, research-061): a project is a folder with its `bridge.yml`, listed in its
|
|
2
|
+
// parent's (the workspace's root `bridge.yml`, or another project's), and a node the host makes for it. The host writes
|
|
3
|
+
// the files and makes the node (`bridgeNodes.newProject`); this plugin keeps the node's folder facet `project/folder`
|
|
4
|
+
// over `bridge/node`, `{ path, title }`, which sessions and docs read: set when it makes a project, and for every project
|
|
5
|
+
// the files list (made by hand, by the CLI) at its start and at each read of the list. No approval: the workspace is a
|
|
6
|
+
// zone of trust (O1); what a project's `bridge.yml` lists is applied by the host.
|
|
7
|
+
// `GET /projects` lists them: `{ id, title, path, project }`, `project` the key chain (`vinyl`, `vinyl/archive`), and
|
|
8
|
+
// projects made before `bridge.yml` (a facet only) as `{ id, title, path }`; `?git=1` adds each one's `git` state when
|
|
9
|
+
// its folder is in a repository (`{ own, top, branch?, changes, remote? }`, research-061 slice 4), and `GET
|
|
10
|
+
// /projects/workspace` gives the workspace folder's `{ path, git? }`. `POST /projects/new` `{ name, title?,
|
|
11
|
+
// parent? }` (the `new_project` tool agents reach through the workspace's MCP server) makes `<parent's folder>/projects/
|
|
12
|
+
// <name>/`; `{ path }` instead takes an existing folder inside the parent's (also `POST /projects`, made when missing
|
|
13
|
+
// there only). `parent`: a node (the request's by default), the project made under its nearest project. With `name`,
|
|
14
|
+
// `git: true` makes its folder a repository of its own, and `clone: <git url>` clones it there instead (bridge#126),
|
|
15
|
+
// the parent's `bridge.yml` naming it by URL and commit. A refusal of a folder outside the parent's gives its `remote`
|
|
16
|
+
// in `details` when it is a clone, so the screen offers to clone it there. `GET /projects/folders?node=&path=` lists
|
|
17
|
+
// the folders inside the folder of node's nearest project (`path` relative to it), for choosing an existing one.
|
|
18
|
+
import { readdirSync, realpathSync } from 'node:fs';
|
|
19
|
+
import { isAbsolute, join, relative, resolve } from 'node:path';
|
|
20
|
+
import type { Context } from 'cordis';
|
|
21
|
+
import { z } from 'zod';
|
|
22
|
+
import { createBranches, processGit, type GitHubLike } from './branches.ts';
|
|
23
|
+
|
|
24
|
+
const folder = z.strictObject({ path: z.string(), title: z.string() });
|
|
25
|
+
type Folder = z.infer<typeof folder>;
|
|
26
|
+
const addBody = z.strictObject({
|
|
27
|
+
path: z.string(),
|
|
28
|
+
title: z.string().optional(),
|
|
29
|
+
parent: z.string().optional(),
|
|
30
|
+
});
|
|
31
|
+
const newBody = z.union([
|
|
32
|
+
addBody,
|
|
33
|
+
z.strictObject({
|
|
34
|
+
name: z.string(),
|
|
35
|
+
title: z.string().optional(),
|
|
36
|
+
parent: z.string().optional(),
|
|
37
|
+
git: z.boolean().optional(),
|
|
38
|
+
clone: z.string().min(1).optional(),
|
|
39
|
+
}),
|
|
40
|
+
]);
|
|
41
|
+
/** How long a model may take to write a commit message or a pull request's texts (Sessions' own route's deadline). */
|
|
42
|
+
const WRITE_MS = 120_000;
|
|
43
|
+
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
44
|
+
typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
45
|
+
/** Folders never offered as a project: Bridge's and tools' own. */
|
|
46
|
+
const hidden = new Set(['node_modules', '.git', '.bridge']);
|
|
47
|
+
|
|
48
|
+
export const name = 'project';
|
|
49
|
+
export const inject = ['router', 'storage', 'nodes', 'bridgeNodes', 'processes', 'workspace'];
|
|
50
|
+
|
|
51
|
+
/** A 4xx the route answers itself (the router's `clientError` brand). */
|
|
52
|
+
const refused = (code: string, message: string, status = 400, details?: object) =>
|
|
53
|
+
Object.assign(new Error(message), {
|
|
54
|
+
code,
|
|
55
|
+
status,
|
|
56
|
+
...(details && { details }),
|
|
57
|
+
[Symbol.for('bridge.clientError')]: true,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
export async function apply(ctx: Context) {
|
|
61
|
+
const facets = await ctx.storage.facets(ctx, {
|
|
62
|
+
name: 'folder',
|
|
63
|
+
target: 'bridge/node',
|
|
64
|
+
schema: folder,
|
|
65
|
+
version: 1,
|
|
66
|
+
});
|
|
67
|
+
/** Whether node `id` or a node above it is archived. */
|
|
68
|
+
const archived = (id: string) => ctx.nodes.ancestors(id)?.some((each) => each.archived) ?? true;
|
|
69
|
+
|
|
70
|
+
/** The projects the files list, each node's facet set when missing or moved; with `git`, their git state. */
|
|
71
|
+
const listed = async (git = false) => {
|
|
72
|
+
const projects = (await ctx.bridgeNodes.projects({ git })).filter(
|
|
73
|
+
(each): each is typeof each & { node: string } =>
|
|
74
|
+
each.project !== '' && each.node !== undefined && ctx.nodes.has(each.node),
|
|
75
|
+
);
|
|
76
|
+
for (const { node, folder: path, title } of projects) {
|
|
77
|
+
const facet: Folder | undefined = await facets.get(node);
|
|
78
|
+
if (facet?.path !== path) await facets.set(ctx, node, { path, title });
|
|
79
|
+
}
|
|
80
|
+
return projects;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
ctx.router.route(ctx, {
|
|
84
|
+
method: 'GET',
|
|
85
|
+
path: '/projects',
|
|
86
|
+
description:
|
|
87
|
+
'The projects of this workspace: [{ id, title, path, project }], project its key chain; older ones made before bridge.yml without it',
|
|
88
|
+
query: z.object({ git: z.literal('1').optional() }),
|
|
89
|
+
handle: async ({ query }) => {
|
|
90
|
+
const projects = await listed(query.get('git') === '1');
|
|
91
|
+
const known = new Set(projects.map(({ node }) => node));
|
|
92
|
+
const titles = new Map(ctx.nodes.list().map((node) => [node.id, node.title]));
|
|
93
|
+
const rows = projects
|
|
94
|
+
.filter(({ node }) => !archived(node))
|
|
95
|
+
.map(({ node, folder: path, project, git }) => ({
|
|
96
|
+
id: node,
|
|
97
|
+
title: titles.get(node) ?? project,
|
|
98
|
+
path,
|
|
99
|
+
project,
|
|
100
|
+
...(git && { git }),
|
|
101
|
+
}));
|
|
102
|
+
// Projects made before bridge.yml: a node with the facet only.
|
|
103
|
+
const older = (
|
|
104
|
+
await Promise.all(
|
|
105
|
+
ctx.nodes
|
|
106
|
+
.list()
|
|
107
|
+
.filter(({ id }) => !known.has(id) && !archived(id))
|
|
108
|
+
.map(async (node) => {
|
|
109
|
+
const facet: Folder | undefined = await facets.get(node.id);
|
|
110
|
+
return facet ? [{ id: node.id, title: node.title, path: facet.path }] : [];
|
|
111
|
+
}),
|
|
112
|
+
)
|
|
113
|
+
).flat();
|
|
114
|
+
return [...rows, ...older];
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
ctx.router.route(ctx, {
|
|
119
|
+
method: 'GET',
|
|
120
|
+
path: '/projects/workspace',
|
|
121
|
+
description:
|
|
122
|
+
'The workspace folder: { path, git? }, git its state when it is in a repository ({ own, top, branch?, changes, remote? })',
|
|
123
|
+
handle: async () => {
|
|
124
|
+
const root = (await ctx.bridgeNodes.projects({ git: true })).find(
|
|
125
|
+
({ project }) => project === '',
|
|
126
|
+
);
|
|
127
|
+
return { path: root?.folder ?? null, ...(root?.git && { git: root.git }) };
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
ctx.router.route(ctx, {
|
|
132
|
+
method: 'GET',
|
|
133
|
+
path: '/projects/folders',
|
|
134
|
+
description:
|
|
135
|
+
"The folders inside the folder of node's nearest project, path relative to it: { root, path, folders: [{ name, path, project? }] }, project the title of one that is a project already",
|
|
136
|
+
query: z.object({ node: z.string().optional(), path: z.string().optional() }),
|
|
137
|
+
handle: async ({ query, node: here }) => {
|
|
138
|
+
const node = query.get('node') ?? here;
|
|
139
|
+
if (!ctx.nodes.has(node)) throw refused('node_unknown', `no node ${node}`);
|
|
140
|
+
const projects = await ctx.bridgeNodes.projects();
|
|
141
|
+
const chain = ctx.nodes.ancestors(node)?.map(({ id }) => id) ?? [];
|
|
142
|
+
const nearest =
|
|
143
|
+
chain
|
|
144
|
+
.map((id) => projects.find((each) => (each.project === '' ? 'root' : each.node) === id))
|
|
145
|
+
.find((each) => each !== undefined) ?? projects.find(({ project }) => project === '');
|
|
146
|
+
if (!nearest) throw refused('no_folder', 'this workspace has no folder');
|
|
147
|
+
const root = nearest.folder;
|
|
148
|
+
const dir = resolve(root, query.get('path') ?? '');
|
|
149
|
+
const inside = relative(root, dir);
|
|
150
|
+
/** Inside `root` as written and once links are followed (a link to `/` is not inside). */
|
|
151
|
+
const within = (from: string, to: string) => {
|
|
152
|
+
const path = relative(from, to);
|
|
153
|
+
return !path.startsWith('..') && !isAbsolute(path);
|
|
154
|
+
};
|
|
155
|
+
let real;
|
|
156
|
+
try {
|
|
157
|
+
real = realpathSync(dir);
|
|
158
|
+
} catch {
|
|
159
|
+
throw refused('invalid_folder', `not a folder: ${dir}`, 404);
|
|
160
|
+
}
|
|
161
|
+
if (!within(root, dir) || !within(realpathSync(root), real))
|
|
162
|
+
throw refused('invalid_folder', `${dir} is not inside ${root}`);
|
|
163
|
+
let entries;
|
|
164
|
+
try {
|
|
165
|
+
entries = readdirSync(real, { withFileTypes: true });
|
|
166
|
+
} catch {
|
|
167
|
+
throw refused('invalid_folder', `not a folder: ${dir}`, 404);
|
|
168
|
+
}
|
|
169
|
+
const titles = new Map(projects.map(({ folder: path, title }) => [path, title]));
|
|
170
|
+
const folders = entries
|
|
171
|
+
.filter(
|
|
172
|
+
(each) => each.isDirectory() && !hidden.has(each.name) && !each.name.startsWith('.'),
|
|
173
|
+
)
|
|
174
|
+
.map(({ name: entry }) => {
|
|
175
|
+
const path = join(dir, entry);
|
|
176
|
+
const project = titles.get(path);
|
|
177
|
+
return { name: entry, path, ...(project !== undefined && { project }) };
|
|
178
|
+
})
|
|
179
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
180
|
+
return { root, path: inside, folders };
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
/** `POST /projects`, or with `create` `POST /projects/new` (the `new_project` tool). */
|
|
185
|
+
const add =
|
|
186
|
+
(create: boolean) =>
|
|
187
|
+
async ({ body, node: here }: { body?: Uint8Array | undefined; node: string }) => {
|
|
188
|
+
let input;
|
|
189
|
+
try {
|
|
190
|
+
input = (create ? newBody : addBody).safeParse(
|
|
191
|
+
JSON.parse(new TextDecoder().decode(body ?? new Uint8Array())),
|
|
192
|
+
);
|
|
193
|
+
} catch {}
|
|
194
|
+
if (!input?.success)
|
|
195
|
+
throw refused(
|
|
196
|
+
'invalid_body',
|
|
197
|
+
create
|
|
198
|
+
? 'POST /projects/new takes { name, title?, parent?, git?, clone? } or { path, title?, parent? }'
|
|
199
|
+
: 'POST /projects takes { path, title?, parent? }',
|
|
200
|
+
);
|
|
201
|
+
const { title, parent = here } = input.data;
|
|
202
|
+
if (!ctx.nodes.has(parent)) throw refused('node_unknown', `no node ${parent}`);
|
|
203
|
+
if (!ctx.nodes.isActive(name, parent))
|
|
204
|
+
throw refused('plugin_inactive', `${name} is not active on node ${parent}`, 403);
|
|
205
|
+
let made;
|
|
206
|
+
try {
|
|
207
|
+
made = await ctx.bridgeNodes.newProject({
|
|
208
|
+
parent,
|
|
209
|
+
create,
|
|
210
|
+
...('path' in input.data
|
|
211
|
+
? { folder: input.data.path }
|
|
212
|
+
: {
|
|
213
|
+
name: input.data.name,
|
|
214
|
+
...(input.data.git && { git: true }),
|
|
215
|
+
...(input.data.clone !== undefined && { clone: input.data.clone }),
|
|
216
|
+
}),
|
|
217
|
+
...(title !== undefined && { title }),
|
|
218
|
+
});
|
|
219
|
+
} catch (error) {
|
|
220
|
+
// The host's refusal carries its code (`invalid_name`, `invalid_folder`, `folder_taken`).
|
|
221
|
+
const data: unknown =
|
|
222
|
+
typeof error === 'object' && error !== null ? Reflect.get(error, 'data') : undefined;
|
|
223
|
+
const code: unknown =
|
|
224
|
+
typeof data === 'object' && data !== null ? Reflect.get(data, 'code') : undefined;
|
|
225
|
+
const remote: unknown =
|
|
226
|
+
typeof data === 'object' && data !== null ? Reflect.get(data, 'remote') : undefined;
|
|
227
|
+
if (typeof code === 'string')
|
|
228
|
+
throw refused(
|
|
229
|
+
code,
|
|
230
|
+
error instanceof Error ? error.message : String(error),
|
|
231
|
+
code === 'folder_taken' ? 409 : 400,
|
|
232
|
+
typeof remote === 'string' ? { remote } : undefined,
|
|
233
|
+
);
|
|
234
|
+
throw error;
|
|
235
|
+
}
|
|
236
|
+
await facets.set(ctx, made.node, { path: made.folder, title: made.title });
|
|
237
|
+
return {
|
|
238
|
+
node: { id: made.node, title: made.title, path: made.folder, project: made.project },
|
|
239
|
+
};
|
|
240
|
+
};
|
|
241
|
+
ctx.router.route(ctx, {
|
|
242
|
+
method: 'POST',
|
|
243
|
+
path: '/projects',
|
|
244
|
+
description:
|
|
245
|
+
"Add an existing folder inside the parent project's folder as a project: listed in its bridge.yml, its node made; answers { node }",
|
|
246
|
+
input: addBody,
|
|
247
|
+
handle: add(false),
|
|
248
|
+
});
|
|
249
|
+
ctx.router.route(ctx, {
|
|
250
|
+
method: 'POST',
|
|
251
|
+
path: '/projects/new',
|
|
252
|
+
description:
|
|
253
|
+
"Create a project: its folder `name` in the parent project's projects/ folder (or a `path` inside it), its bridge.yml, its node; answers { node }",
|
|
254
|
+
input: newBody,
|
|
255
|
+
handle: add(true),
|
|
256
|
+
});
|
|
257
|
+
// A project's branches (./branches.ts, bridgebrew/bridge#557): the Branches screen's routes, never an agent's (the
|
|
258
|
+
// person's own screen), and the `projectBranches` service Sessions makes a session's branch with.
|
|
259
|
+
const branches = createBranches({
|
|
260
|
+
slug: ctx.workspace.slug,
|
|
261
|
+
dataDir: join(ctx.workspace.dataDir, name),
|
|
262
|
+
git: processGit(ctx),
|
|
263
|
+
projects: () => ctx.bridgeNodes.projects(),
|
|
264
|
+
codeFrom: (input) => ctx.bridgeNodes.codeFrom(input),
|
|
265
|
+
follow: (input) => ctx.bridgeNodes.follow(input),
|
|
266
|
+
install: (folder) => ctx.bridgeNodes.install({ folder }),
|
|
267
|
+
removeWorktree: (input) => ctx.bridgeNodes.removeWorktree(input),
|
|
268
|
+
pluginsRepository: (plugins) => ctx.bridgeNodes.pluginsRepository({ plugins }),
|
|
269
|
+
write: async (node, prompt, sessions) => {
|
|
270
|
+
const response = await ctx.router.dispatch(
|
|
271
|
+
{
|
|
272
|
+
method: 'POST',
|
|
273
|
+
key: 'sessions',
|
|
274
|
+
path: '/sessions/write',
|
|
275
|
+
query: new URLSearchParams(),
|
|
276
|
+
headers: { 'x-bridge-node': node, 'content-type': 'application/json' },
|
|
277
|
+
body: new TextEncoder().encode(JSON.stringify({ prompt, sessions })),
|
|
278
|
+
actor: 'user',
|
|
279
|
+
},
|
|
280
|
+
AbortSignal.timeout(WRITE_MS),
|
|
281
|
+
);
|
|
282
|
+
if (!('body' in response)) {
|
|
283
|
+
response.abort();
|
|
284
|
+
throw new Error('Sessions answered a stream');
|
|
285
|
+
}
|
|
286
|
+
const body: unknown = response.body ? JSON.parse(response.body) : undefined;
|
|
287
|
+
const text = isRecord(body) ? body.text : undefined;
|
|
288
|
+
if (response.status === 200 && typeof text === 'string') return text;
|
|
289
|
+
const error = isRecord(body) && isRecord(body.error) ? body.error.message : undefined;
|
|
290
|
+
throw new Error(typeof error === 'string' ? error : `Sessions did not write it (${response.status})`);
|
|
291
|
+
},
|
|
292
|
+
github: () => {
|
|
293
|
+
const service: unknown = ctx.get('github', false);
|
|
294
|
+
return isRecord(service) &&
|
|
295
|
+
typeof service.repositoryOfFolder === 'function' &&
|
|
296
|
+
typeof service.pullRequestsForBranch === 'function' &&
|
|
297
|
+
typeof service.rest === 'function'
|
|
298
|
+
? // oxlint-disable-next-line bridge/no-new-unchecked-cast -- its three functions checked above, `github`'s own service
|
|
299
|
+
(service as unknown as GitHubLike)
|
|
300
|
+
: undefined;
|
|
301
|
+
},
|
|
302
|
+
});
|
|
303
|
+
const nodeOf = (query: URLSearchParams, here: string) => query.get('node') || here;
|
|
304
|
+
ctx.router.route(ctx, {
|
|
305
|
+
method: 'GET',
|
|
306
|
+
path: '/branches',
|
|
307
|
+
agent: false,
|
|
308
|
+
description: "A git project's branches (?node=): { project, github, hostLevel?, branches, jobs? }",
|
|
309
|
+
query: z.object({ node: z.string().optional() }),
|
|
310
|
+
handle: async ({ query, node }) => branches.view(nodeOf(query, node)),
|
|
311
|
+
});
|
|
312
|
+
for (const action of ['new', 'activate', 'commit', 'push', 'pull', 'pr', 'remove'])
|
|
313
|
+
ctx.router.route(ctx, {
|
|
314
|
+
method: 'POST',
|
|
315
|
+
path: `/branches/${action}`,
|
|
316
|
+
agent: false,
|
|
317
|
+
description: `${action} on a git project's branch (?node=): the branches after it, and { result }`,
|
|
318
|
+
query: z.object({ node: z.string().optional() }),
|
|
319
|
+
handle: async ({ query, node, body }) => {
|
|
320
|
+
let input: unknown = {};
|
|
321
|
+
try {
|
|
322
|
+
input = JSON.parse(new TextDecoder().decode(body ?? new Uint8Array()) || '{}');
|
|
323
|
+
} catch {}
|
|
324
|
+
try {
|
|
325
|
+
return await branches.act(nodeOf(query, node), action, isRecord(input) ? input : {});
|
|
326
|
+
} catch (error) {
|
|
327
|
+
throw refused('refused', error instanceof Error ? error.message : String(error), 409);
|
|
328
|
+
}
|
|
329
|
+
},
|
|
330
|
+
});
|
|
331
|
+
ctx.provide('projectBranches', {
|
|
332
|
+
newBranch: branches.newBranch,
|
|
333
|
+
branchForPlugins: branches.branchForPlugins,
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
// Every project the files list has its facet from the start (one made by hand while this plugin was stopped).
|
|
337
|
+
await listed().catch(() => {});
|
|
338
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "extends": "./.bridge/tsconfig.json" }
|
package/README.md
DELETED