Skip to content

Instantly share code, notes, and snippets.

Magma Calculator Service Implementation Plan

For Claude: REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.

Goal: Build a containerized REST API that executes Magma code in an nsjail sandbox and returns parsed results as JSON.

Architecture: Single FastAPI app behind uvicorn with TLS. Each request spawns nsjail -> magma -w -n as a subprocess. In-memory IP rate limiting. CORS for browser access from GitHub Pages frontend.

Tech Stack: Python 3.11, FastAPI, uvicorn, pydantic-settings, pytest, httpx (test client), Docker, nsjail

MAGMA Repository Structure for Git

Overview

Flatten the SVN-era Prog/ wrapper, convert SVN directory copies to proper Git refs, and reorganize for clarity.

Current → New Mapping

Current Path New Path Notes
#!/bin/bash
# clone-proper.sh - Clone MAGMA SVN with proper tags/branches as git refs
#
# This creates a git-svn clone where:
# - / (root) is the trunk, excluding Tags/Export/Branches
# - Main branch contains: Prog/, Doc/, Web/
# - Tags/* become refs/remotes/svn/tags/*
# - Branches/* become refs/remotes/svn/branches/*
# - Export/* become refs/remotes/svn/export/*
#
<SPConfig xmlns="urn:mace:shibboleth:3.0:native:sp:config"
xmlns:conf="urn:mace:shibboleth:3.0:native:sp:config"
clockSkew="180">
<OutOfProcess tranLogFormat="%u|%s|%IDP|%i|%ac|%t|%attr|%n|%b|%E|%S|%SS|%L|%UA|%a" />
<!--
By default, in-memory StorageService, ReplayCache, ArtifactMap, and SessionCache
are used. See example-shibboleth2.xml for samples of explicitly configuring them.
-->
<SPConfig xmlns="urn:mace:shibboleth:3.0:native:sp:config"
xmlns:conf="urn:mace:shibboleth:3.0:native:sp:config"
clockSkew="180">
<OutOfProcess tranLogFormat="%u|%s|%IDP|%i|%ac|%t|%attr|%n|%b|%E|%S|%SS|%L|%UA|%a" />
<!--
By default, in-memory StorageService, ReplayCache, ArtifactMap, and SessionCache
are used. See example-shibboleth2.xml for samples of explicitly configuring them.
-->
12:[9,82,95]:10000:235
7:[93,-68,-44]:10000:231
11:[113,82,13]:10000:223
12:[24,3,64]:10000:219
11:[112,3,61]:10000:219
3:[18,27,-14]:10000:218
3:[18,-27,14]:10000:218
2:[18,41,14]:10000:218
2:[18,-41,-14]:10000:218
1:[72,36,-7]:10000:218
.
├── Branches
│   ├── allan
│   │   └── DB
│   ├── damien_eval
│   │   └── src
│   ├── eran-modfrmalg
│   │   ├── Doc
│   │   ├── package
│   │   └── test
.
├── Branches
│   ├── allan
│   ├── damien_eval
│   ├── eran-modfrmalg
│   ├── geoff_ecdb_big
│   ├── geoff_ring_matp
│   ├── geoff_structure_create
│   ├── nicole
│   ├── nicole-tests
.
├── __pycache__
│ └── magma_style_fixer.cpython-313.pyc
├── bug.m
├── build_magma.sh
├── defaultdict.m
├── defaultdict_package.m
├── Doc
│ ├── Info
│ │ ├── info_alg_geo_crv.txt
This file has been truncated, but you can view the full file.
x^21+12*x^20-383*x^19-5341*x^18+51176*x^17+945678*x^16-1992550*x^15-83203629*x^14-153392797*x^13+3576451184*x^12+17666115156*x^11-49255598083*x^10-577222173005*x^9-1058541151977*x^8+4272348391906*x^7+25555999076133*x^6+57869555739281*x^5+71377146109307*x^4+50298760425520*x^3+19485484039101*x^2+3679352032728*x+255666047707:x^21-147*x^19-33*x^18+9261*x^17+4158*x^16-325454*x^15-218295*x^14+6945330*x^13+6166822*x^12-91582911*x^11-100851303*x^10+722612872*x^9+953023050*x^8-3089829141*x^7-4872498305*x^6+5515835724*x^5+11494178850*x^4-664069200*x^3-9270518544*x^2-5003803035*x-755920325:0.210:0.390:true:0.150