@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
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pulling a failing Actions run's logs into something a prompt can carry.
|
|
3
|
+
*
|
|
4
|
+
* Two decisions worth stating.
|
|
5
|
+
*
|
|
6
|
+
* FAILED JOBS ONLY, VIA THE PER-JOB ENDPOINT. The run-level endpoint hands back
|
|
7
|
+
* a zip of every job's log, including the twelve that passed. Listing the jobs
|
|
8
|
+
* and fetching only the failed ones is one extra request and avoids unzipping
|
|
9
|
+
* megabytes to throw almost all of it away.
|
|
10
|
+
*
|
|
11
|
+
* THE TAIL, NOT THE HEAD. A CI log's first 500 lines are dependency
|
|
12
|
+
* installation; the failure is at the end. Truncating from the front is the one
|
|
13
|
+
* way to produce a log excerpt that contains no information about the failure,
|
|
14
|
+
* so this keeps the tail and says how much it dropped.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type { CheckLogBundle } from '$shared/types/work';
|
|
18
|
+
import { apiBaseOf, githubRequest, GitHubError, type GitHubCredentials } from './client';
|
|
19
|
+
import { debug } from '$shared/utils/logger';
|
|
20
|
+
|
|
21
|
+
/** Total log text handed to the model, across every failed job in the run. */
|
|
22
|
+
const TOTAL_LOG_BUDGET = 24 * 1024;
|
|
23
|
+
/** Per job, so one catastrophic job cannot crowd out the other three. */
|
|
24
|
+
const PER_JOB_BUDGET = 12 * 1024;
|
|
25
|
+
const LOG_TIMEOUT_MS = 30_000;
|
|
26
|
+
|
|
27
|
+
interface GitHubJob {
|
|
28
|
+
id: number;
|
|
29
|
+
name: string;
|
|
30
|
+
conclusion: string | null;
|
|
31
|
+
status: string;
|
|
32
|
+
html_url: string | null;
|
|
33
|
+
steps?: { name: string; conclusion: string | null; number: number }[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Fetch one job's log as text.
|
|
38
|
+
*
|
|
39
|
+
* `redirect: 'manual'` is not a detail. GitHub answers with a 302 to a signed
|
|
40
|
+
* storage URL, and that URL carries its own credentials in the query string.
|
|
41
|
+
* Following automatically would replay our `Authorization: Bearer` header at a
|
|
42
|
+
* third-party host — leaking the token to a service that has no business seeing
|
|
43
|
+
* it, and which will reject the request for having two credentials anyway.
|
|
44
|
+
*/
|
|
45
|
+
async function fetchJobLog(credentials: GitHubCredentials, jobId: number): Promise<string> {
|
|
46
|
+
const url = `${apiBaseOf(credentials)}/actions/jobs/${jobId}/logs`;
|
|
47
|
+
|
|
48
|
+
const response = await fetch(url, {
|
|
49
|
+
headers: {
|
|
50
|
+
Accept: 'application/vnd.github+json',
|
|
51
|
+
Authorization: `Bearer ${credentials.token}`,
|
|
52
|
+
'X-GitHub-Api-Version': '2022-11-28',
|
|
53
|
+
'User-Agent': 'clopen'
|
|
54
|
+
},
|
|
55
|
+
redirect: 'manual',
|
|
56
|
+
signal: AbortSignal.timeout(LOG_TIMEOUT_MS)
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
if (response.status >= 300 && response.status < 400) {
|
|
60
|
+
const location = response.headers.get('location');
|
|
61
|
+
if (!location) throw new GitHubError('GitHub returned a redirect with no location', response.status, 'error');
|
|
62
|
+
const followed = await fetch(location, { signal: AbortSignal.timeout(LOG_TIMEOUT_MS) });
|
|
63
|
+
if (!followed.ok) {
|
|
64
|
+
throw new GitHubError(`Could not download the job log (HTTP ${followed.status})`, followed.status, 'error');
|
|
65
|
+
}
|
|
66
|
+
return followed.text();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!response.ok) {
|
|
70
|
+
// Logs expire, and a repo can disable log retention entirely. Both are
|
|
71
|
+
// normal states, not failures of this feature.
|
|
72
|
+
throw new GitHubError(
|
|
73
|
+
response.status === 410
|
|
74
|
+
? 'These logs have expired and are no longer stored by GitHub'
|
|
75
|
+
: `Could not read the job log (HTTP ${response.status})`,
|
|
76
|
+
response.status,
|
|
77
|
+
response.status === 401 ? 'auth' : 'error'
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return response.text();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Keep the last `limit` bytes, cut on a line boundary, and say what was dropped. */
|
|
85
|
+
function keepTail(text: string, limit: number): { text: string; truncated: boolean } {
|
|
86
|
+
if (text.length <= limit) return { text, truncated: false };
|
|
87
|
+
const tail = text.slice(text.length - limit);
|
|
88
|
+
const firstNewline = tail.indexOf('\n');
|
|
89
|
+
const body = firstNewline >= 0 ? tail.slice(firstNewline + 1) : tail;
|
|
90
|
+
const droppedLines = text.slice(0, text.length - body.length).split('\n').length;
|
|
91
|
+
return {
|
|
92
|
+
text: `… ${droppedLines} earlier line${droppedLines === 1 ? '' : 's'} omitted …\n${body}`,
|
|
93
|
+
truncated: true
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Actions prefixes every line with an ISO timestamp and wraps output in
|
|
99
|
+
* `##[group]` markers. Both are pure noise in a prompt and together they are
|
|
100
|
+
* roughly a quarter of the bytes, which is a quarter of the budget spent on
|
|
101
|
+
* nothing.
|
|
102
|
+
*/
|
|
103
|
+
function stripActionsNoise(text: string): string {
|
|
104
|
+
return text
|
|
105
|
+
.split('\n')
|
|
106
|
+
.map((line) => line.replace(/^\d{4}-\d{2}-\d{2}T[\d:.]+Z\s?/, ''))
|
|
107
|
+
.filter((line) => !/^##\[(group|endgroup)\]/.test(line))
|
|
108
|
+
.join('\n')
|
|
109
|
+
.trimEnd();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Logs for the failed jobs of one run, budgeted and annotated.
|
|
114
|
+
*
|
|
115
|
+
* Returns a bundle even when every job's log has expired: the run name and the
|
|
116
|
+
* list of failed steps still tell the agent what broke, and an empty answer
|
|
117
|
+
* would look like the feature not working.
|
|
118
|
+
*/
|
|
119
|
+
export async function buildRunLogBundle(
|
|
120
|
+
credentials: GitHubCredentials,
|
|
121
|
+
locator: string,
|
|
122
|
+
runId: string,
|
|
123
|
+
runName: string
|
|
124
|
+
): Promise<CheckLogBundle> {
|
|
125
|
+
const jobs = await githubRequest<{ jobs: GitHubJob[] }>(
|
|
126
|
+
credentials,
|
|
127
|
+
`/repos/${locator}/actions/runs/${runId}/jobs?per_page=100`,
|
|
128
|
+
{ noCache: true }
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
const failed = (jobs.data?.jobs ?? []).filter(
|
|
132
|
+
(job) => job.conclusion === 'failure' || job.conclusion === 'timed_out'
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
if (failed.length === 0) {
|
|
136
|
+
return {
|
|
137
|
+
runId,
|
|
138
|
+
runName,
|
|
139
|
+
text: 'The run reported a failure but no individual job failed — this is usually a cancelled or infrastructure-level failure.',
|
|
140
|
+
truncated: false
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const sections: string[] = [];
|
|
145
|
+
let used = 0;
|
|
146
|
+
let truncated = false;
|
|
147
|
+
|
|
148
|
+
for (const job of failed) {
|
|
149
|
+
const failedSteps = (job.steps ?? [])
|
|
150
|
+
.filter((step) => step.conclusion === 'failure')
|
|
151
|
+
.map((step) => step.name);
|
|
152
|
+
|
|
153
|
+
const header = failedSteps.length > 0
|
|
154
|
+
? `### Job "${job.name}" — failed at: ${failedSteps.join(', ')}`
|
|
155
|
+
: `### Job "${job.name}" — failed`;
|
|
156
|
+
|
|
157
|
+
if (used >= TOTAL_LOG_BUDGET) {
|
|
158
|
+
sections.push(`${header}\n(log omitted — the earlier jobs used the available context)`);
|
|
159
|
+
truncated = true;
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
let body: string;
|
|
164
|
+
try {
|
|
165
|
+
const raw = stripActionsNoise(await fetchJobLog(credentials, job.id));
|
|
166
|
+
const limit = Math.min(PER_JOB_BUDGET, TOTAL_LOG_BUDGET - used);
|
|
167
|
+
const clipped = keepTail(raw, limit);
|
|
168
|
+
if (clipped.truncated) truncated = true;
|
|
169
|
+
body = clipped.text;
|
|
170
|
+
used += clipped.text.length;
|
|
171
|
+
} catch (error) {
|
|
172
|
+
debug.warn('work', `Could not read log for job ${job.id}:`, error);
|
|
173
|
+
body = `(log unavailable: ${error instanceof Error ? error.message : String(error)})`;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
sections.push(`${header}\n\n\`\`\`\n${body}\n\`\`\``);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return { runId, runName, text: sections.join('\n\n'), truncated };
|
|
180
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turning a git remote into a repository locator.
|
|
3
|
+
*
|
|
4
|
+
* This is what makes the binding automatic, and it is the one place where being
|
|
5
|
+
* wrong is silently destructive rather than loudly broken: bind to the wrong
|
|
6
|
+
* repository and "start work" opens someone else's issue, while a pull request
|
|
7
|
+
* targets a repository nobody meant.
|
|
8
|
+
*
|
|
9
|
+
* The Enterprise Server cases matter as much as the github.com ones, because a
|
|
10
|
+
* host check that ignores the account's base URL would claim every remote on
|
|
11
|
+
* earth.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { describe, it, expect } from 'bun:test';
|
|
15
|
+
|
|
16
|
+
import { githubWorkAdapter } from './adapter';
|
|
17
|
+
|
|
18
|
+
const dotCom: Record<string, string> = {};
|
|
19
|
+
const enterprise: Record<string, string> = { baseUrl: 'https://ghe.example.com' };
|
|
20
|
+
|
|
21
|
+
const parse = (url: string, credentials = dotCom) =>
|
|
22
|
+
githubWorkAdapter.locatorFromRemote(url, credentials);
|
|
23
|
+
|
|
24
|
+
describe('locatorFromRemote — github.com', () => {
|
|
25
|
+
it('reads an scp-style remote', () => {
|
|
26
|
+
expect(parse('git@github.com:acme/web.git')).toBe('acme/web');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('reads an https remote, with or without .git', () => {
|
|
30
|
+
expect(parse('https://github.com/acme/web.git')).toBe('acme/web');
|
|
31
|
+
expect(parse('https://github.com/acme/web')).toBe('acme/web');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('reads an ssh:// remote', () => {
|
|
35
|
+
expect(parse('ssh://git@github.com/acme/web.git')).toBe('acme/web');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('tolerates a trailing slash', () => {
|
|
39
|
+
expect(parse('https://github.com/acme/web/')).toBe('acme/web');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('keeps only owner/repo from a deeper URL', () => {
|
|
43
|
+
expect(parse('https://github.com/acme/web/tree/main/src')).toBe('acme/web');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('rejects a URL that names no repository', () => {
|
|
47
|
+
expect(parse('https://github.com/acme')).toBeNull();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('rejects another vendor', () => {
|
|
51
|
+
expect(parse('git@gitlab.com:acme/web.git')).toBeNull();
|
|
52
|
+
expect(parse('https://bitbucket.org/acme/web.git')).toBeNull();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('rejects a host that merely ends with the right name', () => {
|
|
56
|
+
// `evilgithub.com` must not match `github.com` — a suffix check here would
|
|
57
|
+
// bind a project to an attacker-controlled remote.
|
|
58
|
+
expect(parse('https://evilgithub.com/acme/web.git')).toBeNull();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('rejects rubbish rather than throwing', () => {
|
|
62
|
+
expect(parse('')).toBeNull();
|
|
63
|
+
expect(parse('not a url')).toBeNull();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('locatorFromRemote — Enterprise Server', () => {
|
|
68
|
+
it('reads a remote on the configured instance', () => {
|
|
69
|
+
expect(parse('git@ghe.example.com:acme/web.git', enterprise)).toBe('acme/web');
|
|
70
|
+
expect(parse('https://ghe.example.com/acme/web.git', enterprise)).toBe('acme/web');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('does not claim github.com remotes', () => {
|
|
74
|
+
// An enterprise account has no business answering for a public repo: its
|
|
75
|
+
// token cannot read it, and binding would produce 404s that read as
|
|
76
|
+
// permission problems.
|
|
77
|
+
expect(parse('git@github.com:acme/web.git', enterprise)).toBeNull();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('accepts a base URL that already points at the API root', () => {
|
|
81
|
+
expect(parse('git@ghe.example.com:acme/web.git', { baseUrl: 'https://ghe.example.com/api/v3' }))
|
|
82
|
+
.toBe('acme/web');
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('is case-insensitive about the host', () => {
|
|
86
|
+
expect(parse('git@GitHub.com:acme/web.git')).toBe('acme/web');
|
|
87
|
+
});
|
|
88
|
+
});
|