The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { |
| 2 | IssueLinkedThreadsResult, |
| 3 | IssueOperationError, |
| 4 | threadIssueKeysEqual, |
| 5 | type ThreadIssueKey, |
| 6 | } from "@t3tools/contracts"; |
| 7 | import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient"; |
| 8 | import * as Effect from "effect/Effect"; |
| 9 | import * as Schema from "effect/Schema"; |
| 10 | import * as SqlClient from "effect/sql/SqlClient"; |
| 11 | |
| 12 | const decodeLinkedThreads = Schema.decodeUnknownEffect(IssueLinkedThreadsResult); |
| 13 | |
| 14 | /** The threads an issue is linked to; the rows and filters `linkedThreads` uses for pull requests. */ |
| 15 | export const listLinkedIssueThreads = Effect.fn("listLinkedIssueThreads")( |
| 16 | function* (key: ThreadIssueKey) { |
| 17 | const sql = yield* SqlClient.SqlClient; |
| 18 | const rows = yield* sql<{ |
| 19 | id: string; |
| 20 | projectId: string; |
| 21 | title: string; |
| 22 | archivedAt: string | null; |
| 23 | settled: number; |
| 24 | tracker: ThreadIssueKey["tracker"]; |
| 25 | host: string; |
| 26 | scope: string; |
| 27 | key: string; |
| 28 | }>` |
| 29 | SELECT t.thread_id AS id, t.project_id AS "projectId", t.title, |
| 30 | t.archived_at AS "archivedAt", |
| 31 | (json_extract(t.payload_json, '$.settledAt') IS NOT NULL |
| 32 | OR json_extract(t.payload_json, '$.settledOverride') IS 'settled') AS settled, |
| 33 | json_extract(link.value, '$.tracker') AS tracker, |
| 34 | json_extract(link.value, '$.host') AS host, |
| 35 | json_extract(link.value, '$.scope') AS scope, |
| 36 | json_extract(link.value, '$.key') AS key, |
| 37 | t.updated_at AS "updatedAt" |
| 38 | FROM orchestration_v2_projection_threads AS t |
| 39 | JOIN json_each(t.payload_json, '$.issues') AS link |
| 40 | WHERE json_extract(link.value, '$.key') = ${key.key.trim()} |
| 41 | AND t.deleted_at IS NULL |
| 42 | AND json_extract(t.payload_json, '$.lineage.sideChat') IS NOT 1 |
| 43 | ORDER BY "updatedAt" DESC, id ASC |
| 44 | `.pipe(NodeSqliteClient.readOnly); |
| 45 | const threads = rows |
| 46 | .filter((row) => threadIssueKeysEqual(row, key)) |
| 47 | .map(({ id, projectId, title, archivedAt, settled }) => ({ |
| 48 | id, |
| 49 | projectId, |
| 50 | title, |
| 51 | archivedAt, |
| 52 | settled: settled === 1, |
| 53 | })); |
| 54 | return yield* decodeLinkedThreads({ threads }); |
| 55 | }, |
| 56 | Effect.mapError( |
| 57 | (cause) => |
| 58 | new IssueOperationError({ |
| 59 | operation: "linkedThreads", |
| 60 | detail: "Could not load linked threads.", |
| 61 | cause, |
| 62 | }), |
| 63 | ), |
| 64 | ); |