patchrelay 0.2.0 → 0.3.0

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/dist/cli/data.js CHANGED
@@ -200,14 +200,10 @@ export class CliDataAccess {
200
200
  projectId: issue.projectId,
201
201
  linearIssueId: issue.linearIssueId,
202
202
  });
203
- this.db.issueControl.upsertIssueControl({
204
- projectId: issue.projectId,
205
- linearIssueId: issue.linearIssueId,
206
- desiredStage: stage,
203
+ this.db.workflowCoordinator.setIssueDesiredStage(issue.projectId, issue.linearIssueId, stage, {
207
204
  desiredReceiptId: receipt.id,
208
205
  lifecycleStatus: "queued",
209
206
  });
210
- this.db.issueWorkflows.setIssueDesiredStage(issue.projectId, issue.linearIssueId, stage, webhookId);
211
207
  const updated = this.db.issueWorkflows.getTrackedIssue(issue.projectId, issue.linearIssueId);
212
208
  return {
213
209
  issue: updated,
@@ -278,13 +274,19 @@ export class CliDataAccess {
278
274
  : {}),
279
275
  ...(row.latest_stage !== null
280
276
  ? { latestStage: row.latest_stage }
281
- : ledger?.mirroredStageRun
282
- ? { latestStage: ledger.mirroredStageRun.stage }
277
+ : ledger?.runLease
278
+ ? { latestStage: ledger.runLease.stage }
283
279
  : {}),
284
280
  ...(row.latest_stage_status !== null
285
281
  ? { latestStageStatus: String(row.latest_stage_status) }
286
- : ledger?.mirroredStageRun
287
- ? { latestStageStatus: ledger.mirroredStageRun.status }
282
+ : ledger?.runLease
283
+ ? {
284
+ latestStageStatus: ledger.runLease.status === "failed"
285
+ ? "failed"
286
+ : ledger.runLease.status === "completed" || ledger.runLease.status === "released" || ledger.runLease.status === "paused"
287
+ ? "completed"
288
+ : "running",
289
+ }
288
290
  : {}),
289
291
  updatedAt: String(row.updated_at),
290
292
  };
@@ -302,20 +304,16 @@ export class CliDataAccess {
302
304
  getLedgerIssueContext(projectId, linearIssueId) {
303
305
  const issueControl = this.db.issueControl.getIssueControl(projectId, linearIssueId);
304
306
  const runLease = issueControl?.activeRunLeaseId ? this.db.runLeases.getRunLease(issueControl.activeRunLeaseId) : undefined;
305
- const workspaceOwnership = issueControl?.activeWorkspaceOwnershipId
306
- ? this.db.workspaceOwnership.getWorkspaceOwnership(issueControl.activeWorkspaceOwnershipId)
307
- : undefined;
308
- const mirroredStageRun = issueControl?.activeRunLeaseId ? this.db.issueWorkflows.getStageRun(issueControl.activeRunLeaseId) : undefined;
309
307
  return {
310
308
  ...(issueControl ? { issueControl } : {}),
311
309
  ...(runLease ? { runLease } : {}),
312
- ...(workspaceOwnership ? { workspaceOwnership } : {}),
313
- ...(mirroredStageRun ? { mirroredStageRun } : {}),
314
310
  };
315
311
  }
316
312
  getActiveStageRunForIssue(issue, ledger) {
317
313
  const context = ledger ?? this.getLedgerIssueContext(issue.projectId, issue.linearIssueId);
318
- const activeStageRun = context.mirroredStageRun ?? this.synthesizeStageRunFromLease(context);
314
+ const activeStageRun = context.issueControl?.activeRunLeaseId
315
+ ? this.db.issueWorkflows.getStageRun(context.issueControl.activeRunLeaseId)
316
+ : undefined;
319
317
  if (!activeStageRun) {
320
318
  return undefined;
321
319
  }
@@ -323,59 +321,15 @@ export class CliDataAccess {
323
321
  ? activeStageRun
324
322
  : undefined;
325
323
  }
326
- synthesizeStageRunFromLease(ledger) {
327
- if (!ledger.runLease) {
328
- return undefined;
329
- }
330
- return {
331
- id: -ledger.runLease.id,
332
- pipelineRunId: 0,
333
- projectId: ledger.runLease.projectId,
334
- linearIssueId: ledger.runLease.linearIssueId,
335
- workspaceId: 0,
336
- stage: ledger.runLease.stage,
337
- status: ledger.runLease.status === "failed"
338
- ? "failed"
339
- : ledger.runLease.status === "completed" || ledger.runLease.status === "released" || ledger.runLease.status === "paused"
340
- ? "completed"
341
- : "running",
342
- triggerWebhookId: "ledger-active-run",
343
- workflowFile: ledger.runLease.workflowFile,
344
- promptText: ledger.runLease.promptText,
345
- ...(ledger.runLease.threadId ? { threadId: ledger.runLease.threadId } : {}),
346
- ...(ledger.runLease.parentThreadId ? { parentThreadId: ledger.runLease.parentThreadId } : {}),
347
- ...(ledger.runLease.turnId ? { turnId: ledger.runLease.turnId } : {}),
348
- startedAt: ledger.runLease.startedAt,
349
- ...(ledger.runLease.endedAt ? { endedAt: ledger.runLease.endedAt } : {}),
350
- };
351
- }
352
324
  getWorkspaceForIssue(issue, ledger) {
353
325
  const context = ledger ?? this.getLedgerIssueContext(issue.projectId, issue.linearIssueId);
354
- if (!context.issueControl?.activeRunLeaseId) {
355
- const activeWorkspace = this.db.issueWorkflows.getActiveWorkspaceForIssue(issue.projectId, issue.linearIssueId);
326
+ if (context.issueControl?.activeWorkspaceOwnershipId !== undefined) {
327
+ const activeWorkspace = this.db.issueWorkflows.getWorkspace(context.issueControl.activeWorkspaceOwnershipId);
356
328
  if (activeWorkspace) {
357
329
  return activeWorkspace;
358
330
  }
359
331
  }
360
- const workspaceOwnership = context.workspaceOwnership;
361
- if (!workspaceOwnership) {
362
- return this.db.issueWorkflows.getActiveWorkspaceForIssue(issue.projectId, issue.linearIssueId);
363
- }
364
- return {
365
- id: workspaceOwnership.id,
366
- projectId: workspaceOwnership.projectId,
367
- linearIssueId: workspaceOwnership.linearIssueId,
368
- branchName: workspaceOwnership.branchName,
369
- worktreePath: workspaceOwnership.worktreePath,
370
- status: workspaceOwnership.status === "released"
371
- ? "closed"
372
- : workspaceOwnership.status === "paused"
373
- ? "paused"
374
- : "active",
375
- ...(context.runLease?.threadId ? { lastThreadId: context.runLease.threadId } : {}),
376
- createdAt: workspaceOwnership.createdAt,
377
- updatedAt: workspaceOwnership.updatedAt,
378
- };
332
+ return this.db.issueWorkflows.getActiveWorkspaceForIssue(issue.projectId, issue.linearIssueId);
379
333
  }
380
334
  async connect(projectId) {
381
335
  return await this.requestJson("/api/oauth/linear/start", {