@straiffi/archon 1.2.16 → 1.2.17

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.
@@ -5,9 +5,9 @@
5
5
  <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
7
  <title>Archon</title>
8
- <script type="module" crossorigin src="/assets/index-BpEzCfrc.js"></script>
8
+ <script type="module" crossorigin src="/assets/index-C6bFOIoo.js"></script>
9
9
  <link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-BYbx6iT9.js">
10
- <link rel="modulepreload" crossorigin href="/assets/dropdown-menu-CHiEwVjq.js">
10
+ <link rel="modulepreload" crossorigin href="/assets/dropdown-menu-DDo1cQ39.js">
11
11
  <link rel="stylesheet" crossorigin href="/assets/index-U0-u592N.css">
12
12
  </head>
13
13
  <body>
@@ -1068,6 +1068,25 @@ const serializeBundleRow = (projectId, bundle) => {
1068
1068
  : null,
1069
1069
  };
1070
1070
  };
1071
+ const serializeGitHubPullRequestSummary = (pullRequest) => {
1072
+ return {
1073
+ provider: 'github',
1074
+ number: pullRequest.number,
1075
+ url: pullRequest.url,
1076
+ title: pullRequest.title,
1077
+ state: pullRequest.state,
1078
+ base_branch: pullRequest.baseBranch,
1079
+ head_branch: pullRequest.headBranch,
1080
+ last_synced_at: null,
1081
+ };
1082
+ };
1083
+ const createOrFindGitHubPullRequest = async (config, input) => {
1084
+ const existingPullRequest = await findOpenGitHubPullRequest(config, {
1085
+ headBranch: input.headBranch,
1086
+ baseBranch: input.baseBranch,
1087
+ });
1088
+ return existingPullRequest ?? await createGitHubPullRequest(config, input);
1089
+ };
1071
1090
  const upsertBundlePullRequestFromGitHub = (projectId, bundleId, config, pullRequest) => {
1072
1091
  return upsertBundlePullRequest({
1073
1092
  bundleId,
@@ -2740,11 +2759,7 @@ app.post('/bundles/:id/pull-request', async (req, res) => {
2740
2759
  }
2741
2760
  console.info(`[integrations] github pr create attempt project=${result.project.id} bundle=${bundle.id} branch=${bundle.branch}`);
2742
2761
  try {
2743
- const existingPullRequest = await findOpenGitHubPullRequest(githubConfig, {
2744
- headBranch: bundle.branch,
2745
- baseBranch,
2746
- });
2747
- const nextPullRequest = existingPullRequest ?? await createGitHubPullRequest(githubConfig, {
2762
+ const nextPullRequest = await createOrFindGitHubPullRequest(githubConfig, {
2748
2763
  title,
2749
2764
  body,
2750
2765
  baseBranch,
@@ -4362,6 +4377,100 @@ app.post('/projects/:id/git-commit-message', async (req, res) => {
4362
4377
  return res.status(500).json({ error: getErrorMessage(error) || 'Unable to generate a commit message right now.' });
4363
4378
  }
4364
4379
  });
4380
+ app.post('/projects/:id/pull-request-description', async (req, res) => {
4381
+ const project = getProjectById(req.params.id);
4382
+ if (!project) {
4383
+ return res.status(404).json({ error: 'Not found' });
4384
+ }
4385
+ const workspace = resolveProjectTargetGitWorkspace(project);
4386
+ if ('error' in workspace) {
4387
+ return res.status(workspace.status).json({ error: workspace.error });
4388
+ }
4389
+ if (workspace.target_kind !== 'repo_root') {
4390
+ return res.status(409).json({ error: 'Pull request descriptions for bundle targets should use the bundle route.' });
4391
+ }
4392
+ if (!project.helper_model) {
4393
+ return res.status(409).json({ error: 'Set a helper model in project settings before generating a PR description.' });
4394
+ }
4395
+ const title = asTrimmedString(req.body?.title);
4396
+ const commitSubjects = Array.isArray(req.body?.commit_subjects)
4397
+ ? req.body.commit_subjects
4398
+ .filter((value) => typeof value === 'string')
4399
+ .map((value) => value.trim())
4400
+ .filter(Boolean)
4401
+ : [];
4402
+ try {
4403
+ const rawDescription = await runLightweightPrompt({
4404
+ tool: 'opencode',
4405
+ model: project.helper_model,
4406
+ variant: project.helper_variant,
4407
+ }, buildPullRequestDescriptionPrompt({
4408
+ title,
4409
+ ticketTitles: [],
4410
+ commitSubjects,
4411
+ }), workspace.cwd);
4412
+ const description = normalizeGeneratedPullRequestDescription(rawDescription);
4413
+ if (!description) {
4414
+ return res.status(500).json({ error: 'Unable to generate a pull request description right now.' });
4415
+ }
4416
+ return res.json({ description });
4417
+ }
4418
+ catch (error) {
4419
+ return res.status(500).json({ error: getErrorMessage(error) || 'Unable to generate a pull request description right now.' });
4420
+ }
4421
+ });
4422
+ app.post('/projects/:id/pull-request', async (req, res) => {
4423
+ const project = getProjectById(req.params.id);
4424
+ if (!project) {
4425
+ return res.status(404).json({ error: 'Not found' });
4426
+ }
4427
+ const workspace = resolveProjectTargetGitWorkspace(project);
4428
+ if ('error' in workspace) {
4429
+ return res.status(workspace.status).json({ error: workspace.error });
4430
+ }
4431
+ if (workspace.target_kind !== 'repo_root') {
4432
+ return res.status(409).json({ error: 'Pull requests for bundle targets should use the bundle route.' });
4433
+ }
4434
+ const githubConfig = getGitHubConnectionConfig(project.id);
4435
+ if (!githubConfig) {
4436
+ return res.status(400).json({ error: 'GitHub is not connected for this project.' });
4437
+ }
4438
+ const title = asTrimmedString(req.body?.title);
4439
+ const body = typeof req.body?.body === 'string' ? req.body.body.trim() : '';
4440
+ const baseBranch = asTrimmedString(req.body?.base_branch) || githubConfig.default_base_branch || '';
4441
+ if (!title) {
4442
+ return res.status(400).json({ error: 'title is required' });
4443
+ }
4444
+ if (!baseBranch) {
4445
+ return res.status(400).json({ error: 'A base branch is required before creating a pull request.' });
4446
+ }
4447
+ if (workspace.branch === baseBranch) {
4448
+ return res.status(409).json({ error: 'Choose a different base branch before creating a pull request.' });
4449
+ }
4450
+ const gitStatus = getGitStatus(workspace.cwd, workspace.branch, workspace.project);
4451
+ if ((gitStatus.ahead ?? 0) > 0 || !hasGitHubRemoteBranch(workspace.cwd, workspace.branch)) {
4452
+ return res.status(409).json({ error: 'Push the branch before creating a pull request.' });
4453
+ }
4454
+ console.info(`[integrations] github project-target pr create attempt project=${project.id} branch=${workspace.branch}`);
4455
+ try {
4456
+ const nextPullRequest = await createOrFindGitHubPullRequest(githubConfig, {
4457
+ title,
4458
+ body,
4459
+ baseBranch,
4460
+ headBranch: workspace.branch,
4461
+ });
4462
+ return res.json({
4463
+ pull_request: serializeGitHubPullRequestSummary(nextPullRequest),
4464
+ });
4465
+ }
4466
+ catch (error) {
4467
+ console.warn(`[integrations] github project-target pr create failed project=${project.id} branch=${workspace.branch}`, error);
4468
+ if (error instanceof GitHubApiError) {
4469
+ return res.status(error.status).json({ error: error.publicMessage });
4470
+ }
4471
+ return res.status(502).json({ error: 'Unable to create the GitHub pull request right now.' });
4472
+ }
4473
+ });
4365
4474
  app.post('/projects/:id/git-push', async (req, res) => {
4366
4475
  const project = getProjectById(req.params.id);
4367
4476
  if (!project) {