@myrialabs/clopen 0.4.36 → 0.4.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.
- package/README.md +2 -2
- package/backend/auth/permissions.ts +14 -0
- package/backend/bootstrap.ts +16 -0
- package/backend/database/crypto/envelope.test.ts +93 -0
- package/backend/database/crypto/envelope.ts +127 -0
- package/backend/database/crypto/index.ts +22 -0
- package/backend/database/crypto/master-key.ts +129 -0
- package/backend/database/crypto/secret-columns.ts +147 -0
- package/backend/database/migrations/071_create_notes_tables.ts +90 -0
- package/backend/database/migrations/072_encrypt_stored_secrets.ts +107 -0
- package/backend/database/migrations/073_create_integration_tables.ts +119 -0
- package/backend/database/migrations/074_create_work_tables.ts +94 -0
- package/backend/database/migrations/index.ts +28 -0
- package/backend/database/queries/db-client-connection-queries.ts +23 -12
- package/backend/database/queries/engine-queries.ts +23 -10
- package/backend/database/queries/index.ts +6 -1
- package/backend/database/queries/integration-queries.ts +297 -0
- package/backend/database/queries/mcp-server-queries.ts +38 -11
- package/backend/database/queries/note-queries.test.ts +190 -0
- package/backend/database/queries/note-queries.ts +269 -0
- package/backend/database/queries/profile-queries.ts +1 -1
- package/backend/database/queries/ssh-connection-queries.ts +19 -8
- package/backend/database/queries/work-queries.ts +210 -0
- package/backend/engine/docs/artifacts.md +22 -9
- package/backend/files/os-clipboard.test.ts +209 -0
- package/backend/files/os-clipboard.ts +567 -0
- package/backend/git/conflict-state.test.ts +396 -0
- package/backend/git/git-executor.ts +6 -0
- package/backend/git/git-parser.ts +144 -48
- package/backend/git/git-service.ts +727 -57
- package/backend/git/push-target.test.ts +264 -0
- package/backend/http/integration-hooks.ts +42 -0
- package/backend/http/notes-images.test.ts +228 -0
- package/backend/http/notes-images.ts +196 -0
- package/backend/index.ts +9 -0
- package/backend/integrations/accounts.ts +229 -0
- package/backend/integrations/health.ts +146 -0
- package/backend/integrations/index.ts +36 -0
- package/backend/integrations/projections/index.ts +120 -0
- package/backend/integrations/projections/mcp-projector.test.ts +204 -0
- package/backend/integrations/projections/mcp-projector.ts +159 -0
- package/backend/integrations/projections/types.ts +51 -0
- package/backend/integrations/registry/define.ts +38 -0
- package/backend/integrations/registry/index.ts +56 -0
- package/backend/integrations/registry/providers/context7.ts +44 -0
- package/backend/integrations/registry/providers/firecrawl.ts +41 -0
- package/backend/integrations/registry/providers/github.ts +78 -0
- package/backend/integrations/registry/types.ts +96 -0
- package/backend/integrations/webhooks/gateway.ts +160 -0
- package/backend/integrations/webhooks/verify.ts +65 -0
- package/backend/mcp/README.md +25 -3
- package/backend/mcp/external/config.ts +35 -1
- package/backend/mcp/index.ts +1 -1
- package/backend/mcp/internal/config.ts +1 -1
- package/backend/notes/access.test.ts +82 -0
- package/backend/notes/access.ts +27 -0
- package/backend/notes/storage.test.ts +77 -0
- package/backend/notes/storage.ts +114 -0
- package/backend/permissions/service.ts +2 -2
- package/backend/profiles/service.ts +1 -1
- package/backend/project/status-manager.ts +20 -0
- package/backend/projects/project-cleanup.ts +6 -0
- package/backend/work/bindings.ts +124 -0
- package/backend/work/index.ts +42 -0
- package/backend/work/prompts.ts +150 -0
- package/backend/work/providers/github/actions-logs.ts +180 -0
- package/backend/work/providers/github/adapter.test.ts +88 -0
- package/backend/work/providers/github/adapter.ts +1255 -0
- package/backend/work/providers/github/client.ts +280 -0
- package/backend/work/providers/github/list-range.test.ts +158 -0
- package/backend/work/providers/github/token-kind.test.ts +42 -0
- package/backend/work/pull-requests.ts +242 -0
- package/backend/work/registry.ts +27 -0
- package/backend/work/service.ts +436 -0
- package/backend/work/start-work.test.ts +71 -0
- package/backend/work/start-work.ts +232 -0
- package/backend/work/types.ts +180 -0
- package/backend/ws/files/clipboard.ts +78 -0
- package/backend/ws/files/index.ts +5 -0
- package/backend/ws/git/branch-name.ts +6 -5
- package/backend/ws/git/branch.ts +43 -1
- package/backend/ws/git/commit-message.ts +13 -10
- package/backend/ws/git/conflict.ts +106 -3
- package/backend/ws/git/diff-budget.test.ts +125 -0
- package/backend/ws/git/diff-budget.ts +279 -0
- package/backend/ws/git/log.ts +25 -0
- package/backend/ws/git/remote.ts +75 -1
- package/backend/ws/index.ts +11 -1
- package/backend/ws/integrations/crud.ts +219 -0
- package/backend/ws/integrations/index.ts +22 -0
- package/backend/ws/mcp/crud.ts +25 -1
- package/backend/ws/notes/index.ts +278 -0
- package/backend/ws/profiles/crud.ts +1 -1
- package/backend/ws/work/actions.ts +206 -0
- package/backend/ws/work/context.ts +51 -0
- package/backend/ws/work/crud.ts +347 -0
- package/backend/ws/work/index.ts +17 -0
- package/backend/ws/work/pull-requests.ts +177 -0
- package/backend/ws/work/schemas.ts +226 -0
- package/dist/assets/{index-Bg-SUCFg.js → index-CyH7fSbR.js} +1 -1
- package/dist/assets/{index-Cz4YpHVi.js → index-DSHIANSy.js} +1 -1
- package/dist/assets/main-D2IOjftb.css +1 -0
- package/dist/assets/main-DM-tHKbW.js +1152 -0
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/shared/constants/engine-tools.ts +1 -1
- package/shared/constants/tool-icons.ts +33 -0
- package/shared/types/database/schema.ts +41 -0
- package/shared/types/git.ts +123 -0
- package/shared/types/integrations.ts +140 -0
- package/shared/types/stores/settings.ts +8 -0
- package/shared/types/work.ts +426 -0
- package/shared/utils/logger.ts +3 -0
- package/dist/assets/main-9G7IpQpK.css +0 -1
- package/dist/assets/main-BofFsH8E.js +0 -1085
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* - profiles:available / project-default (non-admin)
|
|
8
8
|
*
|
|
9
9
|
* A Profile bundles references to existing artifacts (Skills, Commands,
|
|
10
|
-
* Subagents,
|
|
10
|
+
* Subagents, Integrations) by slug plus an optional per-engine allow/deny
|
|
11
11
|
* overlay. Nothing is duplicated — see `backend/profiles`. Admin gating lives in
|
|
12
12
|
* `backend/auth/permissions.ts`; the picker/default-read routes stay non-admin
|
|
13
13
|
* (choosing a profile for a session is a run choice like the model).
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two actions that turn a work item into work.
|
|
3
|
+
*
|
|
4
|
+
* work:start-work item → worktree + branch + session + first prompt
|
|
5
|
+
* work:checks CI runs for a branch
|
|
6
|
+
* work:check-logs a failing run's logs, composed into a chat prompt
|
|
7
|
+
*
|
|
8
|
+
* Both return TEXT for the client to send rather than sending it themselves.
|
|
9
|
+
* The chat pipeline is driven from the browser — it owns which session is
|
|
10
|
+
* active, the streaming state and the optimistic message — and a second, silent
|
|
11
|
+
* path that injects messages from the backend would race with all three.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { t } from 'elysia';
|
|
15
|
+
import { createRouter } from '$shared/utils/ws-server';
|
|
16
|
+
import { gitService } from '$backend/git/git-service';
|
|
17
|
+
import { buildCheckLogPrompt, workService, startWork } from '$backend/work';
|
|
18
|
+
import { serializeWorktree } from '../worktrees/crud';
|
|
19
|
+
import { worktreeQueries } from '$backend/database/queries';
|
|
20
|
+
import { ws } from '$backend/utils/ws';
|
|
21
|
+
import type { EngineType } from '$shared/types/unified';
|
|
22
|
+
import { resolveWorkProject } from './context';
|
|
23
|
+
import { announceWorkChanged } from './crud';
|
|
24
|
+
import {
|
|
25
|
+
CHECK_RUN_SCHEMA,
|
|
26
|
+
COMMIT_DETAIL_SCHEMA,
|
|
27
|
+
COMMIT_SCHEMA,
|
|
28
|
+
FILE_CHANGE_SCHEMA,
|
|
29
|
+
KIND_SCHEMA
|
|
30
|
+
} from './schemas';
|
|
31
|
+
import { debug } from '$shared/utils/logger';
|
|
32
|
+
|
|
33
|
+
const ENGINE_SCHEMA = t.Union([
|
|
34
|
+
t.Literal('claude-code'),
|
|
35
|
+
t.Literal('opencode'),
|
|
36
|
+
t.Literal('copilot'),
|
|
37
|
+
t.Literal('codex'),
|
|
38
|
+
t.Literal('qwen'),
|
|
39
|
+
t.Literal('pi'),
|
|
40
|
+
t.Literal('cline'),
|
|
41
|
+
t.Literal('cursor')
|
|
42
|
+
]);
|
|
43
|
+
|
|
44
|
+
/** The branch the caller is looking at, when it did not name one. */
|
|
45
|
+
async function currentBranchOf(root: string): Promise<string> {
|
|
46
|
+
const branches = await gitService.getBranches(root);
|
|
47
|
+
if (!branches.current || branches.detached) {
|
|
48
|
+
throw new Error('This workspace is not on a branch');
|
|
49
|
+
}
|
|
50
|
+
return branches.current;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const workActionsHandler = createRouter()
|
|
54
|
+
.http('work:start-work', {
|
|
55
|
+
data: t.Object({
|
|
56
|
+
projectId: t.Optional(t.String()),
|
|
57
|
+
accountId: t.String({ minLength: 1 }),
|
|
58
|
+
kind: KIND_SCHEMA,
|
|
59
|
+
id: t.String({ minLength: 1 }),
|
|
60
|
+
engine: ENGINE_SCHEMA
|
|
61
|
+
}),
|
|
62
|
+
response: t.Object({
|
|
63
|
+
worktreeId: t.String(),
|
|
64
|
+
worktreeName: t.String(),
|
|
65
|
+
sessionId: t.String(),
|
|
66
|
+
branch: t.String(),
|
|
67
|
+
prompt: t.String(),
|
|
68
|
+
transitionedTo: t.Union([t.String(), t.Null()]),
|
|
69
|
+
transitionError: t.Union([t.String(), t.Null()]),
|
|
70
|
+
needsSetup: t.Boolean()
|
|
71
|
+
})
|
|
72
|
+
}, async ({ data, conn }) => {
|
|
73
|
+
const { projectId } = resolveWorkProject(conn, data.projectId);
|
|
74
|
+
const userId = ws.getUserId(conn);
|
|
75
|
+
|
|
76
|
+
const result = await startWork({
|
|
77
|
+
projectId,
|
|
78
|
+
accountId: data.accountId,
|
|
79
|
+
kind: data.kind,
|
|
80
|
+
itemId: data.id,
|
|
81
|
+
engine: data.engine as EngineType,
|
|
82
|
+
userId
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// The worktree list and the session list both just changed for everyone in
|
|
86
|
+
// the project, and the person who clicked is about to switch into both.
|
|
87
|
+
ws.emit.project(projectId, 'worktrees:changed', {
|
|
88
|
+
projectId,
|
|
89
|
+
worktrees: worktreeQueries.getByProjectId(projectId).map(serializeWorktree)
|
|
90
|
+
});
|
|
91
|
+
announceWorkChanged(projectId);
|
|
92
|
+
|
|
93
|
+
debug.log('work', `Started work on ${data.kind} ${data.id} in worktree ${result.worktreeId}`);
|
|
94
|
+
return result;
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
.http('work:checks', {
|
|
98
|
+
data: t.Object({
|
|
99
|
+
projectId: t.Optional(t.String()),
|
|
100
|
+
accountId: t.String({ minLength: 1 }),
|
|
101
|
+
branch: t.Optional(t.String())
|
|
102
|
+
}),
|
|
103
|
+
response: t.Object({
|
|
104
|
+
branch: t.String(),
|
|
105
|
+
runs: t.Array(CHECK_RUN_SCHEMA)
|
|
106
|
+
})
|
|
107
|
+
}, async ({ data, conn }) => {
|
|
108
|
+
const { projectId, root } = resolveWorkProject(conn, data.projectId);
|
|
109
|
+
|
|
110
|
+
const branch = data.branch?.trim() || (await currentBranchOf(root));
|
|
111
|
+
return { branch, runs: await workService.listChecks(projectId, data.accountId, branch) };
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
.http('work:check-logs', {
|
|
115
|
+
data: t.Object({
|
|
116
|
+
projectId: t.Optional(t.String()),
|
|
117
|
+
accountId: t.String({ minLength: 1 }),
|
|
118
|
+
runId: t.String({ minLength: 1 }),
|
|
119
|
+
branch: t.String({ minLength: 1 }),
|
|
120
|
+
runUrl: t.String()
|
|
121
|
+
}),
|
|
122
|
+
response: t.Object({
|
|
123
|
+
runName: t.String(),
|
|
124
|
+
/** The logs themselves, so they can be READ here rather than only sent. */
|
|
125
|
+
text: t.String(),
|
|
126
|
+
prompt: t.String(),
|
|
127
|
+
truncated: t.Boolean()
|
|
128
|
+
})
|
|
129
|
+
}, async ({ data, conn }) => {
|
|
130
|
+
const { projectId } = resolveWorkProject(conn, data.projectId);
|
|
131
|
+
const bundle = await workService.fetchCheckLogs(projectId, data.accountId, data.runId);
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
runName: bundle.runName,
|
|
135
|
+
text: bundle.text,
|
|
136
|
+
prompt: buildCheckLogPrompt(bundle, {
|
|
137
|
+
locator: workService.describeBinding(projectId, data.accountId) ?? 'this repository',
|
|
138
|
+
branch: data.branch,
|
|
139
|
+
runUrl: data.runUrl
|
|
140
|
+
}),
|
|
141
|
+
truncated: bundle.truncated
|
|
142
|
+
};
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
.http('work:pr-commits', {
|
|
146
|
+
data: t.Object({
|
|
147
|
+
projectId: t.Optional(t.String()),
|
|
148
|
+
accountId: t.String({ minLength: 1 }),
|
|
149
|
+
id: t.String({ minLength: 1 })
|
|
150
|
+
}),
|
|
151
|
+
response: t.Array(COMMIT_SCHEMA)
|
|
152
|
+
}, async ({ data, conn }) => {
|
|
153
|
+
const { projectId } = resolveWorkProject(conn, data.projectId);
|
|
154
|
+
return workService.listCommits(projectId, data.accountId, data.id);
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* One commit, opened.
|
|
159
|
+
*
|
|
160
|
+
* Separate from `pr-commits` because it costs a request per commit and the
|
|
161
|
+
* list is read far more often than any single commit is opened.
|
|
162
|
+
*/
|
|
163
|
+
.http('work:commit-detail', {
|
|
164
|
+
data: t.Object({
|
|
165
|
+
projectId: t.Optional(t.String()),
|
|
166
|
+
accountId: t.String({ minLength: 1 }),
|
|
167
|
+
sha: t.String({ minLength: 1, maxLength: 100 })
|
|
168
|
+
}),
|
|
169
|
+
response: COMMIT_DETAIL_SCHEMA
|
|
170
|
+
}, async ({ data, conn }) => {
|
|
171
|
+
const { projectId } = resolveWorkProject(conn, data.projectId);
|
|
172
|
+
return workService.commitDetail(projectId, data.accountId, data.sha);
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
.http('work:file-content', {
|
|
176
|
+
data: t.Object({
|
|
177
|
+
projectId: t.Optional(t.String()),
|
|
178
|
+
accountId: t.String({ minLength: 1 }),
|
|
179
|
+
path: t.String({ minLength: 1, maxLength: 1000 }),
|
|
180
|
+
ref: t.String({ minLength: 1, maxLength: 250 }),
|
|
181
|
+
/** Preferred address: it survives forks, deletions and gone branches. */
|
|
182
|
+
blobSha: t.Optional(t.String({ maxLength: 100 }))
|
|
183
|
+
}),
|
|
184
|
+
response: t.Object({ content: t.String(), truncated: t.Boolean() })
|
|
185
|
+
}, async ({ data, conn }) => {
|
|
186
|
+
const { projectId } = resolveWorkProject(conn, data.projectId);
|
|
187
|
+
return workService.fetchFileContent(
|
|
188
|
+
projectId,
|
|
189
|
+
data.accountId,
|
|
190
|
+
data.path,
|
|
191
|
+
data.ref,
|
|
192
|
+
data.blobSha
|
|
193
|
+
);
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
.http('work:pr-files', {
|
|
197
|
+
data: t.Object({
|
|
198
|
+
projectId: t.Optional(t.String()),
|
|
199
|
+
accountId: t.String({ minLength: 1 }),
|
|
200
|
+
id: t.String({ minLength: 1 })
|
|
201
|
+
}),
|
|
202
|
+
response: t.Array(FILE_CHANGE_SCHEMA)
|
|
203
|
+
}, async ({ data, conn }) => {
|
|
204
|
+
const { projectId } = resolveWorkProject(conn, data.projectId);
|
|
205
|
+
return workService.listFiles(projectId, data.accountId, data.id);
|
|
206
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which project an issues route acts on.
|
|
3
|
+
*
|
|
4
|
+
* The surface lives in More Tools, and More Tools is global — a user looking at
|
|
5
|
+
* project A should be able to read project B's issues without leaving their
|
|
6
|
+
* session. So every route takes an OPTIONAL `projectId` and falls back to the
|
|
7
|
+
* connection's current one, rather than reading the connection and nothing else.
|
|
8
|
+
*
|
|
9
|
+
* Access is still checked per call. `projectId` arriving from the client is a
|
|
10
|
+
* request, not a permission: `requireProjectAccess` is what decides.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type { WSConnection } from '$shared/utils/ws-server';
|
|
14
|
+
import type { Project } from '$shared/types/database/schema';
|
|
15
|
+
import { ws } from '$backend/utils/ws';
|
|
16
|
+
import { resolveWorktreeRoot } from '$backend/worktrees';
|
|
17
|
+
import { requireProjectAccess } from '../access';
|
|
18
|
+
|
|
19
|
+
export interface IssueProjectContext {
|
|
20
|
+
projectId: string;
|
|
21
|
+
project: Project;
|
|
22
|
+
/**
|
|
23
|
+
* The tree git commands run against.
|
|
24
|
+
*
|
|
25
|
+
* Worktree-aware ONLY for the project the connection is actually viewing: a
|
|
26
|
+
* worktree belongs to a session, and resolving another project's root
|
|
27
|
+
* through this connection's worktree id would run git in the wrong tree —
|
|
28
|
+
* or in one that does not exist.
|
|
29
|
+
*/
|
|
30
|
+
root: string;
|
|
31
|
+
/** True when this is the project the user is currently working in. */
|
|
32
|
+
isCurrent: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function resolveWorkProject(conn: WSConnection, projectId?: string): IssueProjectContext {
|
|
36
|
+
const current = ws.getProjectId(conn);
|
|
37
|
+
const target = (projectId ?? '').trim() || current;
|
|
38
|
+
const project = requireProjectAccess(conn, target);
|
|
39
|
+
|
|
40
|
+
if (target !== current) {
|
|
41
|
+
return { projectId: target, project, root: project.path, isCurrent: false };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const resolved = resolveWorktreeRoot(target, ws.getWorktreeId(conn));
|
|
45
|
+
return {
|
|
46
|
+
projectId: target,
|
|
47
|
+
project,
|
|
48
|
+
root: resolved.path || project.path,
|
|
49
|
+
isCurrent: true
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading and changing work items.
|
|
3
|
+
*
|
|
4
|
+
* work:sources which connected accounts serve a project
|
|
5
|
+
* work:list work items for one source
|
|
6
|
+
* work:get one item, with body, comments and mergeability
|
|
7
|
+
* work:states the states an item can be moved to
|
|
8
|
+
* work:comment add a comment
|
|
9
|
+
* work:comment-update edit one
|
|
10
|
+
* work:comment-delete delete one
|
|
11
|
+
* work:transition change state
|
|
12
|
+
* work:assignees who this repository can assign to
|
|
13
|
+
* work:set-assignees replace an item's assignees
|
|
14
|
+
* work:create-issue open a new issue
|
|
15
|
+
* work:set-binding point a project at a different repository
|
|
16
|
+
* work:set-config per-binding behaviour (transitions, branch template)
|
|
17
|
+
*
|
|
18
|
+
* NOT admin-gated, unlike `integrations:*`. The distinction is what the route
|
|
19
|
+
* can reach: an integrations route changes a credential every project and every
|
|
20
|
+
* engine depends on, while these routes act inside one project the caller was
|
|
21
|
+
* already granted access to — the same reasoning that leaves `git:push` open.
|
|
22
|
+
*
|
|
23
|
+
* Every route takes an optional `projectId`, because this surface is global.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { t } from 'elysia';
|
|
27
|
+
import { createRouter } from '$shared/utils/ws-server';
|
|
28
|
+
import { workService } from '$backend/work';
|
|
29
|
+
import { DEFAULT_BRANCH_TEMPLATE } from '$shared/types/work';
|
|
30
|
+
import type { CommentSource, WorkItemKind, WorkItemState } from '$shared/types/work';
|
|
31
|
+
import { ws } from '$backend/utils/ws';
|
|
32
|
+
import { resolveWorkProject } from './context';
|
|
33
|
+
import {
|
|
34
|
+
BINDING_CONFIG_SCHEMA,
|
|
35
|
+
COMMENT_SCHEMA,
|
|
36
|
+
COMMENT_SOURCE_SCHEMA,
|
|
37
|
+
KIND_SCHEMA,
|
|
38
|
+
RATE_LIMIT_SCHEMA,
|
|
39
|
+
SOURCE_SCHEMA,
|
|
40
|
+
WORK_ITEM_DETAIL_SCHEMA,
|
|
41
|
+
WORK_ITEM_SCHEMA
|
|
42
|
+
} from './schemas';
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Tell a project's viewers that one of its sources changed.
|
|
46
|
+
*
|
|
47
|
+
* Project-scoped rather than global: a binding belongs to one project, and two
|
|
48
|
+
* people looking at different projects have no reason to refetch because of
|
|
49
|
+
* each other.
|
|
50
|
+
*/
|
|
51
|
+
export function announceWorkChanged(projectId: string): void {
|
|
52
|
+
ws.emit.project(projectId, 'work:changed', { projectId });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const STATE_FILTER_SCHEMA = t.Union([t.Literal('open'), t.Literal('closed'), t.Literal('all')]);
|
|
56
|
+
|
|
57
|
+
/** Present on every route in this surface. Empty means "the current project". */
|
|
58
|
+
const PROJECT_FIELD = { projectId: t.Optional(t.String()) };
|
|
59
|
+
|
|
60
|
+
export const workCrudHandler = createRouter()
|
|
61
|
+
.http('work:sources', {
|
|
62
|
+
data: t.Object({ ...PROJECT_FIELD }),
|
|
63
|
+
response: t.Array(SOURCE_SCHEMA)
|
|
64
|
+
}, async ({ data, conn }) => {
|
|
65
|
+
const { projectId, project } = resolveWorkProject(conn, data.projectId);
|
|
66
|
+
// The MAIN project path, not the viewed worktree: a worktree is a copy and
|
|
67
|
+
// carries the same remotes, but the project is what the binding belongs to
|
|
68
|
+
// and reading it from a tree that may have been deleted is a race.
|
|
69
|
+
return workService.listSources(projectId, project.path);
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
.http('work:list', {
|
|
73
|
+
data: t.Object({
|
|
74
|
+
...PROJECT_FIELD,
|
|
75
|
+
accountId: t.String({ minLength: 1 }),
|
|
76
|
+
kind: KIND_SCHEMA,
|
|
77
|
+
state: STATE_FILTER_SCHEMA,
|
|
78
|
+
mineOnly: t.Boolean(),
|
|
79
|
+
author: t.Optional(t.String()),
|
|
80
|
+
labels: t.Optional(t.Array(t.String(), { maxItems: 20 })),
|
|
81
|
+
since: t.Optional(t.String()),
|
|
82
|
+
until: t.Optional(t.String()),
|
|
83
|
+
search: t.Optional(t.String()),
|
|
84
|
+
page: t.Optional(t.Number({ minimum: 1, maximum: 100 }))
|
|
85
|
+
}),
|
|
86
|
+
response: t.Object({
|
|
87
|
+
items: t.Array(WORK_ITEM_SCHEMA),
|
|
88
|
+
rateLimit: t.Union([RATE_LIMIT_SCHEMA, t.Null()]),
|
|
89
|
+
hasMore: t.Boolean(),
|
|
90
|
+
nextPage: t.Union([t.Number(), t.Null()])
|
|
91
|
+
})
|
|
92
|
+
}, async ({ data, conn }) => {
|
|
93
|
+
const { projectId } = resolveWorkProject(conn, data.projectId);
|
|
94
|
+
return workService.list(projectId, data.accountId, {
|
|
95
|
+
kind: data.kind as WorkItemKind,
|
|
96
|
+
state: data.state as WorkItemState,
|
|
97
|
+
mineOnly: data.mineOnly,
|
|
98
|
+
...(data.author && { author: data.author }),
|
|
99
|
+
...(data.labels?.length && { labels: data.labels }),
|
|
100
|
+
...(data.since && { since: data.since }),
|
|
101
|
+
...(data.until && { until: data.until }),
|
|
102
|
+
...(data.search && { search: data.search }),
|
|
103
|
+
...(data.page && { page: data.page })
|
|
104
|
+
});
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
.http('work:labels', {
|
|
108
|
+
data: t.Object({
|
|
109
|
+
...PROJECT_FIELD,
|
|
110
|
+
accountId: t.String({ minLength: 1 })
|
|
111
|
+
}),
|
|
112
|
+
response: t.Array(t.String())
|
|
113
|
+
}, async ({ data, conn }) => {
|
|
114
|
+
const { projectId } = resolveWorkProject(conn, data.projectId);
|
|
115
|
+
return workService.listLabels(projectId, data.accountId);
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
.http('work:update-item', {
|
|
119
|
+
data: t.Object({
|
|
120
|
+
...PROJECT_FIELD,
|
|
121
|
+
accountId: t.String({ minLength: 1 }),
|
|
122
|
+
kind: KIND_SCHEMA,
|
|
123
|
+
id: t.String({ minLength: 1 }),
|
|
124
|
+
title: t.Optional(t.String({ minLength: 1, maxLength: 400 })),
|
|
125
|
+
body: t.Optional(t.String({ maxLength: 65_536 }))
|
|
126
|
+
}),
|
|
127
|
+
response: t.Object({ ok: t.Boolean() })
|
|
128
|
+
}, async ({ data, conn }) => {
|
|
129
|
+
const { projectId } = resolveWorkProject(conn, data.projectId);
|
|
130
|
+
await workService.updateItem(
|
|
131
|
+
projectId,
|
|
132
|
+
data.accountId,
|
|
133
|
+
data.kind as WorkItemKind,
|
|
134
|
+
data.id,
|
|
135
|
+
{
|
|
136
|
+
...(data.title !== undefined && { title: data.title }),
|
|
137
|
+
...(data.body !== undefined && { body: data.body })
|
|
138
|
+
}
|
|
139
|
+
);
|
|
140
|
+
announceWorkChanged(projectId);
|
|
141
|
+
return { ok: true };
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
.http('work:get', {
|
|
145
|
+
data: t.Object({
|
|
146
|
+
...PROJECT_FIELD,
|
|
147
|
+
accountId: t.String({ minLength: 1 }),
|
|
148
|
+
kind: KIND_SCHEMA,
|
|
149
|
+
id: t.String({ minLength: 1 })
|
|
150
|
+
}),
|
|
151
|
+
response: WORK_ITEM_DETAIL_SCHEMA
|
|
152
|
+
}, async ({ data, conn }) => {
|
|
153
|
+
const { projectId } = resolveWorkProject(conn, data.projectId);
|
|
154
|
+
return workService.get(projectId, data.accountId, data.kind as WorkItemKind, data.id);
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
.http('work:states', {
|
|
158
|
+
data: t.Object({
|
|
159
|
+
...PROJECT_FIELD,
|
|
160
|
+
accountId: t.String({ minLength: 1 }),
|
|
161
|
+
kind: KIND_SCHEMA
|
|
162
|
+
}),
|
|
163
|
+
response: t.Array(t.Object({
|
|
164
|
+
value: t.String(),
|
|
165
|
+
label: t.String(),
|
|
166
|
+
category: t.Union([t.Literal('open'), t.Literal('closed'), t.Literal('merged'), t.Literal('draft')])
|
|
167
|
+
}))
|
|
168
|
+
}, async ({ data, conn }) => {
|
|
169
|
+
const { projectId } = resolveWorkProject(conn, data.projectId);
|
|
170
|
+
return workService.listStates(projectId, data.accountId, data.kind as WorkItemKind);
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
.http('work:comment', {
|
|
174
|
+
data: t.Object({
|
|
175
|
+
...PROJECT_FIELD,
|
|
176
|
+
accountId: t.String({ minLength: 1 }),
|
|
177
|
+
kind: KIND_SCHEMA,
|
|
178
|
+
id: t.String({ minLength: 1 }),
|
|
179
|
+
body: t.String({ minLength: 1, maxLength: 65_536 })
|
|
180
|
+
}),
|
|
181
|
+
response: COMMENT_SCHEMA
|
|
182
|
+
}, async ({ data, conn }) => {
|
|
183
|
+
const { projectId } = resolveWorkProject(conn, data.projectId);
|
|
184
|
+
const comment = await workService.comment(
|
|
185
|
+
projectId,
|
|
186
|
+
data.accountId,
|
|
187
|
+
data.kind as WorkItemKind,
|
|
188
|
+
data.id,
|
|
189
|
+
data.body
|
|
190
|
+
);
|
|
191
|
+
announceWorkChanged(projectId);
|
|
192
|
+
return comment;
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
.http('work:comment-update', {
|
|
196
|
+
data: t.Object({
|
|
197
|
+
...PROJECT_FIELD,
|
|
198
|
+
accountId: t.String({ minLength: 1 }),
|
|
199
|
+
commentId: t.String({ minLength: 1 }),
|
|
200
|
+
source: COMMENT_SOURCE_SCHEMA,
|
|
201
|
+
body: t.String({ minLength: 1, maxLength: 65_536 })
|
|
202
|
+
}),
|
|
203
|
+
response: COMMENT_SCHEMA
|
|
204
|
+
}, async ({ data, conn }) => {
|
|
205
|
+
const { projectId } = resolveWorkProject(conn, data.projectId);
|
|
206
|
+
const comment = await workService.updateComment(
|
|
207
|
+
projectId,
|
|
208
|
+
data.accountId,
|
|
209
|
+
{ id: data.commentId, source: data.source as CommentSource },
|
|
210
|
+
data.body
|
|
211
|
+
);
|
|
212
|
+
announceWorkChanged(projectId);
|
|
213
|
+
return comment;
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
.http('work:comment-delete', {
|
|
217
|
+
data: t.Object({
|
|
218
|
+
...PROJECT_FIELD,
|
|
219
|
+
accountId: t.String({ minLength: 1 }),
|
|
220
|
+
commentId: t.String({ minLength: 1 }),
|
|
221
|
+
source: COMMENT_SOURCE_SCHEMA
|
|
222
|
+
}),
|
|
223
|
+
response: t.Object({ ok: t.Boolean() })
|
|
224
|
+
}, async ({ data, conn }) => {
|
|
225
|
+
const { projectId } = resolveWorkProject(conn, data.projectId);
|
|
226
|
+
await workService.deleteComment(projectId, data.accountId, {
|
|
227
|
+
id: data.commentId,
|
|
228
|
+
source: data.source as CommentSource
|
|
229
|
+
});
|
|
230
|
+
announceWorkChanged(projectId);
|
|
231
|
+
return { ok: true };
|
|
232
|
+
})
|
|
233
|
+
|
|
234
|
+
.http('work:transition', {
|
|
235
|
+
data: t.Object({
|
|
236
|
+
...PROJECT_FIELD,
|
|
237
|
+
accountId: t.String({ minLength: 1 }),
|
|
238
|
+
kind: KIND_SCHEMA,
|
|
239
|
+
id: t.String({ minLength: 1 }),
|
|
240
|
+
state: t.String({ minLength: 1 })
|
|
241
|
+
}),
|
|
242
|
+
response: t.Object({ ok: t.Boolean() })
|
|
243
|
+
}, async ({ data, conn }) => {
|
|
244
|
+
const { projectId } = resolveWorkProject(conn, data.projectId);
|
|
245
|
+
await workService.transition(
|
|
246
|
+
projectId,
|
|
247
|
+
data.accountId,
|
|
248
|
+
data.kind as WorkItemKind,
|
|
249
|
+
data.id,
|
|
250
|
+
data.state
|
|
251
|
+
);
|
|
252
|
+
announceWorkChanged(projectId);
|
|
253
|
+
return { ok: true };
|
|
254
|
+
})
|
|
255
|
+
|
|
256
|
+
.http('work:assignees', {
|
|
257
|
+
data: t.Object({
|
|
258
|
+
...PROJECT_FIELD,
|
|
259
|
+
accountId: t.String({ minLength: 1 })
|
|
260
|
+
}),
|
|
261
|
+
response: t.Array(t.String())
|
|
262
|
+
}, async ({ data, conn }) => {
|
|
263
|
+
const { projectId } = resolveWorkProject(conn, data.projectId);
|
|
264
|
+
return workService.listAssignees(projectId, data.accountId);
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
.http('work:set-assignees', {
|
|
268
|
+
data: t.Object({
|
|
269
|
+
...PROJECT_FIELD,
|
|
270
|
+
accountId: t.String({ minLength: 1 }),
|
|
271
|
+
kind: KIND_SCHEMA,
|
|
272
|
+
id: t.String({ minLength: 1 }),
|
|
273
|
+
logins: t.Array(t.String(), { maxItems: 10 })
|
|
274
|
+
}),
|
|
275
|
+
response: t.Object({ ok: t.Boolean() })
|
|
276
|
+
}, async ({ data, conn }) => {
|
|
277
|
+
const { projectId } = resolveWorkProject(conn, data.projectId);
|
|
278
|
+
await workService.setAssignees(
|
|
279
|
+
projectId,
|
|
280
|
+
data.accountId,
|
|
281
|
+
data.kind as WorkItemKind,
|
|
282
|
+
data.id,
|
|
283
|
+
data.logins
|
|
284
|
+
);
|
|
285
|
+
announceWorkChanged(projectId);
|
|
286
|
+
return { ok: true };
|
|
287
|
+
})
|
|
288
|
+
|
|
289
|
+
.http('work:create-issue', {
|
|
290
|
+
data: t.Object({
|
|
291
|
+
...PROJECT_FIELD,
|
|
292
|
+
accountId: t.String({ minLength: 1 }),
|
|
293
|
+
title: t.String({ minLength: 1, maxLength: 400 }),
|
|
294
|
+
body: t.String({ maxLength: 65_536 }),
|
|
295
|
+
assignees: t.Array(t.String(), { maxItems: 10 }),
|
|
296
|
+
labels: t.Array(t.String(), { maxItems: 20 })
|
|
297
|
+
}),
|
|
298
|
+
response: WORK_ITEM_SCHEMA
|
|
299
|
+
}, async ({ data, conn }) => {
|
|
300
|
+
const { projectId } = resolveWorkProject(conn, data.projectId);
|
|
301
|
+
const item = await workService.createIssue(projectId, data.accountId, {
|
|
302
|
+
title: data.title,
|
|
303
|
+
body: data.body,
|
|
304
|
+
assignees: data.assignees,
|
|
305
|
+
labels: data.labels
|
|
306
|
+
});
|
|
307
|
+
announceWorkChanged(projectId);
|
|
308
|
+
return item;
|
|
309
|
+
})
|
|
310
|
+
|
|
311
|
+
.http('work:set-binding', {
|
|
312
|
+
data: t.Object({
|
|
313
|
+
...PROJECT_FIELD,
|
|
314
|
+
accountId: t.String({ minLength: 1 }),
|
|
315
|
+
locator: t.String({ minLength: 1, maxLength: 200 })
|
|
316
|
+
}),
|
|
317
|
+
response: t.Object({ ok: t.Boolean() })
|
|
318
|
+
}, async ({ data, conn }) => {
|
|
319
|
+
const { projectId } = resolveWorkProject(conn, data.projectId);
|
|
320
|
+
workService.setBinding(projectId, data.accountId, data.locator);
|
|
321
|
+
announceWorkChanged(projectId);
|
|
322
|
+
return { ok: true };
|
|
323
|
+
})
|
|
324
|
+
|
|
325
|
+
.http('work:set-config', {
|
|
326
|
+
data: t.Object({
|
|
327
|
+
...PROJECT_FIELD,
|
|
328
|
+
accountId: t.String({ minLength: 1 }),
|
|
329
|
+
config: BINDING_CONFIG_SCHEMA
|
|
330
|
+
}),
|
|
331
|
+
response: t.Object({ ok: t.Boolean() })
|
|
332
|
+
}, async ({ data, conn }) => {
|
|
333
|
+
const { projectId } = resolveWorkProject(conn, data.projectId);
|
|
334
|
+
workService.setBindingConfig(projectId, data.accountId, {
|
|
335
|
+
transitionOnStartWork: data.config.transitionOnStartWork,
|
|
336
|
+
transitionOnPrOpen: data.config.transitionOnPrOpen,
|
|
337
|
+
// An empty template would render every branch name to the fallback,
|
|
338
|
+
// which looks like the template silently not working.
|
|
339
|
+
branchTemplate: data.config.branchTemplate.trim() || DEFAULT_BRANCH_TEMPLATE
|
|
340
|
+
});
|
|
341
|
+
announceWorkChanged(projectId);
|
|
342
|
+
return { ok: true };
|
|
343
|
+
})
|
|
344
|
+
|
|
345
|
+
.emit('work:changed', t.Object({
|
|
346
|
+
projectId: t.String()
|
|
347
|
+
}));
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Work surface routes — issues, pull requests and CI.
|
|
3
|
+
*
|
|
4
|
+
* Importing `$backend/work` is what registers the providers, so merging this
|
|
5
|
+
* router into the app is also what makes GitHub exist. That is deliberate: a
|
|
6
|
+
* surface with no routes has no adapters to register either.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { createRouter } from '$shared/utils/ws-server';
|
|
10
|
+
import { workCrudHandler } from './crud';
|
|
11
|
+
import { workActionsHandler } from './actions';
|
|
12
|
+
import { workPullRequestHandler } from './pull-requests';
|
|
13
|
+
|
|
14
|
+
export const workRouter = createRouter()
|
|
15
|
+
.merge(workCrudHandler)
|
|
16
|
+
.merge(workActionsHandler)
|
|
17
|
+
.merge(workPullRequestHandler);
|