( requestId: string, resolution: PermissionResolution, teamName?: string, )
| 358 | * Writes the resolution to resolved/, removes from pending/ |
| 359 | */ |
| 360 | export async function resolvePermission( |
| 361 | requestId: string, |
| 362 | resolution: PermissionResolution, |
| 363 | teamName?: string, |
| 364 | ): Promise<boolean> { |
| 365 | const team = teamName || getTeamName() |
| 366 | if (!team) { |
| 367 | logForDebugging('[PermissionSync] No team name available') |
| 368 | return false |
| 369 | } |
| 370 | |
| 371 | await ensurePermissionDirsAsync(team) |
| 372 | |
| 373 | const pendingPath = getPendingRequestPath(team, requestId) |
| 374 | const resolvedPath = getResolvedRequestPath(team, requestId) |
| 375 | const lockFilePath = join(getPendingDir(team), '.lock') |
| 376 | |
| 377 | await writeFile(lockFilePath, '', 'utf-8') |
| 378 | |
| 379 | let release: (() => Promise<void>) | undefined |
| 380 | try { |
| 381 | release = await lockfile.lock(lockFilePath) |
| 382 | |
| 383 | // Read the pending request |
| 384 | let content: string |
| 385 | try { |
| 386 | content = await readFile(pendingPath, 'utf-8') |
| 387 | } catch (e: unknown) { |
| 388 | const code = getErrnoCode(e) |
| 389 | if (code === 'ENOENT') { |
| 390 | logForDebugging( |
| 391 | `[PermissionSync] Pending request not found: ${requestId}`, |
| 392 | ) |
| 393 | return false |
| 394 | } |
| 395 | throw e |
| 396 | } |
| 397 | |
| 398 | const parsed = SwarmPermissionRequestSchema().safeParse(jsonParse(content)) |
| 399 | if (!parsed.success) { |
| 400 | logForDebugging( |
| 401 | `[PermissionSync] Invalid pending request ${requestId}: ${parsed.error.message}`, |
| 402 | ) |
| 403 | return false |
| 404 | } |
| 405 | |
| 406 | const request = parsed.data |
| 407 | |
| 408 | // Update the request with resolution data |
| 409 | const resolvedRequest: SwarmPermissionRequest = { |
| 410 | ...request, |
| 411 | status: resolution.decision === 'approved' ? 'approved' : 'rejected', |
| 412 | resolvedBy: resolution.resolvedBy, |
| 413 | resolvedAt: Date.now(), |
| 414 | feedback: resolution.feedback, |
| 415 | updatedInput: resolution.updatedInput, |
| 416 | permissionUpdates: resolution.permissionUpdates, |
| 417 | } |
nothing calls this directly
no test coverage detected