(repoId: string, taskId: string)
| 182 | } |
| 183 | |
| 184 | async function readTask(repoId: string, taskId: string): Promise<OpenADETask> { |
| 185 | const documentId = `code:task:${taskId}` |
| 186 | const [meta, events, comments, deviceEnvironments, preview] = await Promise.all([ |
| 187 | storage.readMapObject(documentId, "task:meta"), |
| 188 | storage.readOrderedArray<Record<string, unknown>>(documentId, "task:events"), |
| 189 | storage.readOrderedArray<Record<string, unknown>>(documentId, "task:comments"), |
| 190 | storage.readOrderedArray<Record<string, unknown>>(documentId, "task:deviceEnvironments"), |
| 191 | readTaskList(repoId).then((tasks) => tasks.find((task) => task.id === taskId)), |
| 192 | ]) |
| 193 | |
| 194 | if (!meta) { |
| 195 | if (!preview) throw new Error(`Task ${taskId} not found`) |
| 196 | return { |
| 197 | id: preview.id, |
| 198 | repoId, |
| 199 | slug: preview.slug, |
| 200 | title: preview.title, |
| 201 | description: "", |
| 202 | isolationStrategy: { type: "head" }, |
| 203 | closed: preview.closed, |
| 204 | unavailableReason: "Task data is unavailable on the desktop host.", |
| 205 | deviceEnvironments: [], |
| 206 | events: [], |
| 207 | comments: [], |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | const metaId = stringValue(meta.id) |
| 212 | if (metaId !== taskId) { |
| 213 | throw new Error(`Task document ${taskId} has mismatched metadata id ${metaId || "<empty>"}`) |
| 214 | } |
| 215 | |
| 216 | return { |
| 217 | id: metaId, |
| 218 | repoId: stringValue(meta.repoId, repoId), |
| 219 | slug: stringValue(meta.slug, preview?.slug ?? ""), |
| 220 | title: stringValue(meta.title, preview?.title ?? "Untitled task"), |
| 221 | description: stringValue(meta.description), |
| 222 | isolationStrategy: isRecord(meta.isolationStrategy) |
| 223 | ? (meta.isolationStrategy as OpenADETask["isolationStrategy"]) |
| 224 | : { type: "head" }, |
| 225 | enabledMcpServerIds: Array.isArray(meta.enabledMcpServerIds) |
| 226 | ? meta.enabledMcpServerIds.filter((id): id is string => typeof id === "string") |
| 227 | : undefined, |
| 228 | sessionIds: stringRecord(meta.sessionIds), |
| 229 | queuedTurns: queuedTurns(meta.queuedTurns), |
| 230 | cancelledPlanEventId: optionalString(meta.cancelledPlanEventId), |
| 231 | deviceEnvironments: (deviceEnvironments ?? []) as unknown as OpenADETask["deviceEnvironments"], |
| 232 | closed: optionalBoolean(meta.closed), |
| 233 | events: events ?? [], |
| 234 | comments: comments ?? [], |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | async function listDataDocuments(): Promise<string[]> { |
| 239 | return storage.listDocuments() |
nothing calls this directly
no test coverage detected