Add collaborative LaTeX macro safety guard#393
Open
karollooool wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a self-contained “collaborative LaTeX macro safety guard” slice that evaluates collaborative Markdown/LaTeX macro packets for safety risks (unsafe macros, recursion, external resources, locked-section holds) and produces deterministic JSON/Markdown/SVG demo artifacts.
Changes:
- Introduces a dependency-free evaluator (
evaluateMacroPacket) and report renderers (Markdown/SVG) for collaborative macro safety gating. - Adds synthetic sample packets plus a demo script that generates deterministic report artifacts.
- Adds a minimal Node-based test and an optional ffmpeg script to render a demo video card.
Reviewed changes
Copilot reviewed 10 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Links the new safety-guard module from the repo root README. |
| collaborative-latex-macro-safety-guard/index.js | Core policy, packet evaluation checks, and Markdown/SVG report rendering. |
| collaborative-latex-macro-safety-guard/sample-data.js | Synthetic “ready / blocked / needs_review” packets used by demo/tests. |
| collaborative-latex-macro-safety-guard/test.js | Node assert-based tests covering evaluator decisions and renderers. |
| collaborative-latex-macro-safety-guard/demo.js | Generates deterministic JSON/MD/SVG report artifacts into reports/. |
| collaborative-latex-macro-safety-guard/scripts/render-demo-video.js | Optional ffmpeg-driven MP4 rendering for demo output. |
| collaborative-latex-macro-safety-guard/package.json | Adds scripts (check, test, demo, demo:video) for the module. |
| collaborative-latex-macro-safety-guard/README.md | Documents scope, requirement mapping, and how to run validation/demo. |
| collaborative-latex-macro-safety-guard/reports/demo.json | Committed deterministic demo report output (JSON). |
| collaborative-latex-macro-safety-guard/reports/demo.md | Committed deterministic demo report output (Markdown). |
| collaborative-latex-macro-safety-guard/reports/demo.svg | Committed deterministic demo report output (SVG). |
Comments suppressed due to low confidence (1)
collaborative-latex-macro-safety-guard/index.js:390
findMacroCycle()returnsvisitedwhen the traversal exceedsmaxDepth(i.e., no cycle found within the limit). Because callers treat any non-empty return as a cycle, this will raiseRECURSIVE_MACRO_EXPANSIONfalse positives for long-but-acyclic macro chains. Consider returning an empty array on depth exhaustion (or emitting a distinct "depth limit exceeded" warning/check code).
if (visited.includes(nextName)) {
return [...visited, nextName];
}
current = macroMap.get(nextName);
}
return visited;
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "\\url", | ||
| ], | ||
| rawHtmlPattern: /<\s*(script|iframe|object|embed|link|meta|style)\b/i, | ||
| externalUrlPattern: /https?:\/\/([^)\s"']+)/gi, |
Comment on lines
+374
to
+389
| const visited = []; | ||
| let current = startMacro; | ||
| for (let depth = 0; depth <= maxDepth; depth += 1) { | ||
| visited.push(current.name); | ||
| const nextName = [...macroMap.keys()].find((name) => | ||
| current.body.includes(name), | ||
| ); | ||
| if (!nextName) { | ||
| return []; | ||
| } | ||
| if (visited.includes(nextName)) { | ||
| return [...visited, nextName]; | ||
| } | ||
| current = macroMap.get(nextName); | ||
| } | ||
| return visited; |
Comment on lines
+322
to
+325
| function checkLockedSection(packet, addCheck, addIssue) { | ||
| const lockedBlocks = packet.blocks.filter((block) => block.locked); | ||
| const hasRenderRisk = packet.macros.some( | ||
| (macro) => !macro.approved || macro.body.includes("\\href"), |
| function escapeDrawtext(value) { | ||
| return String(value) | ||
| .replaceAll("\\", "\\\\") | ||
| .replaceAll(":", "\\:") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
/claim #12
Summary
Adds a self-contained collaborative LaTeX macro safety guard for the real-time collaborative research editor.
This slice validates synchronized Markdown/LaTeX editor packets before live preview or named-version export by checking:
Non-overlap
This targets collaborative LaTeX/KaTeX macro render safety. It does not implement a broad editor foundation, operation replay, offline conflict handling, notebook workbench/kernel lease, reference formatting or reference merge, authorship governance, freeze/recovery, discussion sidebar, autosave, round-trip fidelity, review decision gates, task dependency, equation/figure anchors, presence privacy/liveness, accessibility, manuscript evidence binding, embargo release, or notification visibility.
Safety
collaborative-latex-macro-safety-guard/sample-data.jsDemo artifacts
collaborative-latex-macro-safety-guard/reports/demo.jsoncollaborative-latex-macro-safety-guard/reports/demo.mdcollaborative-latex-macro-safety-guard/reports/demo.svgcollaborative-latex-macro-safety-guard/reports/demo.mp4Validation
npm run checknpm testnpm run demonpm run demo:videowithFFMPEG_PATHpointing to a temporaryffmpeg-staticbinary outside the repoffmpeg -v error -i collaborative-latex-macro-safety-guard/reports/demo.mp4 -f null -git diff --checkgit diff --cached --checkrg -n "token|secret|password|private key|BEGIN|sk-|ghp_|github_pat|wallet|seed phrase" README.md collaborative-latex-macro-safety-guard-> no matchesAI-assisted with Codex; reviewed and locally verified before submission.