( sourceId: string, env: NodeJS.ProcessEnv = process.env, allowReclone = false, fetchRows: (env: NodeJS.ProcessEnv) => GbrainSourceRow[] = fetchSources, )
| 283 | * first, is the primary protection against the race that caused the loss. |
| 284 | */ |
| 285 | export function decideCodeSync( |
| 286 | sourceId: string, |
| 287 | env: NodeJS.ProcessEnv = process.env, |
| 288 | allowReclone = false, |
| 289 | fetchRows: (env: NodeJS.ProcessEnv) => GbrainSourceRow[] = fetchSources, |
| 290 | ): SyncDecision { |
| 291 | let rows: GbrainSourceRow[]; |
| 292 | try { |
| 293 | rows = fetchRows(env); |
| 294 | } catch { |
| 295 | return { allow: true, reason: "sources unreadable; proceeding (sync read is non-destructive)" }; |
| 296 | } |
| 297 | const row = rows.find((r) => r.id === sourceId); |
| 298 | if (row?.config?.remote_url && !allowReclone) { |
| 299 | return { |
| 300 | allow: false, |
| 301 | reason: |
| 302 | `source "${sourceId}" is URL-managed (remote_url set); sync may auto-reclone and ` + |
| 303 | `delete the working tree. Re-run /sync-gbrain with --allow-reclone to proceed.`, |
| 304 | }; |
| 305 | } |
| 306 | return { allow: true, reason: "no remote_url, or reclone explicitly allowed" }; |
| 307 | } |
no test coverage detected