Skip to content

InferHaven/agent-skills / codetrain

codetrain

Flagged

CodeTrain is an open-source Socratic coding tutor with a local lesson page where the learner writes every line while the agent sets small steps, gives hints and reviews the work without putting the solution into the lesson. Use when the user wants to be taught/walked through code one tiny step at a time — triggers like "teach me this code", "walk me through this", "hold my hand", "explain step by step", "tutor me", "guide me through", "I want to learn this", or asks for a safe practice exercise to learn a concept.

FileKindSize
LICENSEother11.1 KB
NOTICEother768 B
README.mdmarkdown22.7 KB
SKILL.mdskill md20.1 KB
app/answer_guard.pyscript7.8 KB
app/checkpoint-hook.shexecutablescript1.2 KB
app/ctl.shexecutablescript4.5 KB
app/install-permissions.pyscript6.8 KB
app/patch.pyexecutablescript4.1 KB
app/profile.pyexecutablescript9.3 KB
app/server.pyexecutablescript23.1 KB
app/static/Archivo.woff2binary88.0 KB
app/static/JetBrainsMono.woff2binary30.7 KB
app/static/app.jsscript57.1 KB
app/static/docklint.jsscript4.3 KB
app/static/editor.jsscript4.4 KB
app/static/fonts-OFL.txtmarkdown9.0 KB
app/static/glossary.jsscript50.8 KB
app/static/index.htmlother8.0 KB
app/static/js-worker.jsscript3.9 KB
app/static/liveness.jsscript1.8 KB
app/static/logo-anim.svgother1.9 KB
app/static/prism.jsscript20.6 KB
app/static/prose.jsscript18.8 KB
app/static/pyodide-worker.jsscript7.0 KB
app/static/runner.jsscript4.5 KB
app/static/sheet.cssother32.7 KB
app/static/styles.cssother51.4 KB
app/static/theme-toggle.jsscript9.5 KB
app/static/theme.jsscript5.2 KB
app/static/visuals.jsscript14.8 KB
app/watch.shexecutablescript2.5 KB
install.shexecutablescript2.0 KB
references/session-protocol.mdmarkdown19.6 KB
references/spaced-repetition.mdmarkdown3.4 KB
references/teach-on-diff.mdmarkdown2.5 KB

app/static/runner.js

View on GitHub
/* CodeTrain — client-side runner.
   Dispatches code to a per-language web worker (Python via Pyodide, JS via a
   sandboxed worker), with a per-run timeout and lazy worker creation. Computes
   per-case pass/fail by deep-equality against each case's `expected`.

   The server never executes code; this all runs in the browser. Languages with
   no worker (bash, etc.) report unavailable so the UI falls back to Claude. */

// 20s, as on the study page: the Python worker is the same file, and its first numpy import
// downloads the package inside that run.
const RUN_TIMEOUT_MS = 20000;
const IDENT = /^[A-Za-z_$][\w$]*$/;

const WORKER_FILE = { python: "pyodide-worker.js", javascript: "js-worker.js", js: "js-worker.js" };
const pool = {};        // lang -> Worker
let reqId = 0;
const pending = {};     // id -> {resolve, reject, timer, onStatus}

const SHELL = new Set(["bash", "sh", "shell"]);
let _bashOk = null;       // server-side container runner availability (probed once)

export function runtimeLang(lang) {
  const l = (lang || "").toLowerCase();
  if (l === "python" || l === "py") return "python";
  if (l === "javascript" || l === "js" || l === "node") return "javascript";
  return null;            // bash handled server-side; others -> Claude-run
}
export async function probeBash() {
  try { const r = await fetch("/api/runtime", { cache: "no-store" }); _bashOk = !!(await r.json()).bash; }
  catch (e) { _bashOk = false; }
  return _bashOk;
}
export function runtimeAvailable(lang) {
  if (runtimeLang(lang)) return true;
  if (SHELL.has((lang || "").toLowerCase())) return !!_bashOk;
  return false;
}

function getWorker(lang) {
  if (pool[lang]) return pool[lang];
  const w = new Worker(WORKER_FILE[lang]);
  w.onmessage = (e) => {
    const { id, type, msg, result } = e.data || {};
    const p = pending[id];
    if (!p) return;
    if (type === "status") { if (p.onStatus) p.onStatus(msg); return; }
    clearTimeout(p.timer);
    delete pending[id];
    p.resolve(result);
  };
  w.onerror = (err) => {
    // a worker-level failure (e.g. CDN blocked) rejects all in-flight calls
    Object.keys(pending).forEach((id) => {
      const p = pending[id];
      clearTimeout(p.timer); delete pending[id];
      p.reject(new Error(err.message || "worker error"));
    });
    try { w.terminate(); } catch (e) {}
    delete pool[lang];
  };
  pool[lang] = w;
  return w;
}

function deepEqual(a, b) {
  if (a === b) return true;
  if (typeof a !== typeof b) return false;
  if (a && b && typeof a === "object") {
    const ka = Object.keys(a), kb = Object.keys(b);
    if (Array.isArray(a) !== Array.isArray(b)) return false;
    if (ka.length !== kb.length) return false;
    return ka.every((k) => deepEqual(a[k], b[k]));
  }
  return false;
}

/* runCode({lang, code, entry, cases, onStatus}) ->
   {stdout, stderr, cases:[{name, passed, got, expected, error}]} */
export async function runCode({ lang, code, entry, cases, onStatus }) {
  if (SHELL.has((lang || "").toLowerCase())) {            // real bash via sandboxed container (server)
    if (onStatus) onStatus("running in sandbox container…");
    const r = await fetch("/api/run", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ lang, code }) });
    const j = await r.json();
    if (j.error) throw new Error(j.error);
    const tail = j.exit ? "\n[exit " + j.exit + "]" : "";
    return { stdout: (j.stdout || "") + tail, stderr: j.stderr || "", cases: [] };
  }
  const rl = runtimeLang(lang);
  if (!rl) throw new Error("no client runtime for " + lang);
  if (entry && !IDENT.test(entry)) throw new Error("invalid entry name");
  const w = getWorker(rl);
  const id = ++reqId;

  const result = await new Promise((resolve, reject) => {
    const timer = setTimeout(() => {
      delete pending[id];
      try { w.terminate(); } catch (e) {}
      delete pool[rl];               // recreate next time (drops a hung loop)
      reject(new Error("timed out (possible infinite loop)"));
    }, RUN_TIMEOUT_MS);
    pending[id] = { resolve, reject, timer, onStatus };
    w.postMessage({ id, code, entry, cases: (cases || []).map((c) => ({ name: c.name, args: c.args || [] })) });
  });

  const merged = (result.cases || []).map((r, i) => {
    const expected = (cases && cases[i]) ? cases[i].expected : undefined;
    return {
      name: r.name || ("case " + (i + 1)),
      got: r.got,
      expected,
      error: r.error || null,
      passed: r.ok && deepEqual(r.got, expected),
    };
  });
  return { stdout: result.stdout || "", stderr: result.stderr || "", cases: merged };
}
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall