|
| 1 | +--- |
| 2 | +name: add-algorithm |
| 3 | +description: "Add or update a cryptography algorithm in this repo, including source/algorithms layout, deterministic tests, optional WebAssembly support, and source/entry-point export wiring. Use when scaffolding a new algorithm, extending an existing one, or deciding whether main.c and verify-wasm updates are required." |
| 4 | +argument-hint: "Algorithm name, API shape, examples, and whether wasm is required" |
| 5 | +--- |
| 6 | + |
| 7 | +# Add Algorithm |
| 8 | + |
| 9 | +Use this skill to add a new algorithm or extend an existing one without breaking the repository's deterministic API, TypeScript fallback behavior, or package export surface. |
| 10 | + |
| 11 | +## When To Use |
| 12 | + |
| 13 | +- Add a brand-new algorithm under `source/algorithms/<name>/`. |
| 14 | +- Update an existing algorithm while preserving public behavior. |
| 15 | +- Decide whether a change needs wasm support now or should stay TypeScript-only. |
| 16 | +- Wire a new algorithm into `source/entry-point.ts`. |
| 17 | + |
| 18 | +## Required Inputs |
| 19 | + |
| 20 | +- Algorithm folder name in kebab-case. |
| 21 | +- Exported function name and signature. |
| 22 | +- Expected inputs, outputs, and at least one concrete example. |
| 23 | +- Whether wasm support is required, optional, or explicitly out of scope. |
| 24 | +- Any constraints on bigint behavior, determinism, or educational CLI usage. |
| 25 | + |
| 26 | +## Success Criteria |
| 27 | + |
| 28 | +- The algorithm lives under `source/algorithms/<name>/` with the expected repo folder shape. |
| 29 | +- `index.ts` remains the source of truth and default export. |
| 30 | +- `index.test.ts` covers deterministic nominal and edge-case behavior. |
| 31 | +- `source/entry-point.ts` exports the algorithm intentionally. |
| 32 | +- If wasm is added, TypeScript fallback still works safely and `scripts/verify-wasm.js` stays in sync. |
| 33 | +- No generated `.wasm` artifacts are committed. |
| 34 | + |
| 35 | +## Procedure |
| 36 | + |
| 37 | +1. Clarify scope before writing code. |
| 38 | + Confirm the algorithm name, function signature, expected examples, and whether the request is for library code only or also affects prompt-driven CLI flows. |
| 39 | + |
| 40 | +2. Inspect nearby algorithm folders for a matching pattern. |
| 41 | + Reuse the existing shape: `index.ts` for implementation, `index.test.ts` for tests, and optional `main.c` for wasm. |
| 42 | + |
| 43 | +3. Implement the TypeScript path first. |
| 44 | + Keep the algorithm deterministic, preserve stable parameter semantics, and use `@/` imports for shared utilities. Do not route internal imports through `@/entry-point`. |
| 45 | + |
| 46 | +4. Add or update tests beside the implementation. |
| 47 | + Cover representative inputs, edge conditions, and any regression cases from the request. Prefer stronger assertions over weaker or broader snapshots. |
| 48 | + |
| 49 | +5. Decide on wasm support explicitly. |
| 50 | + If wasm is not required or would complicate correctness, keep the implementation in TypeScript only. |
| 51 | + If wasm is required, add `main.c`, integrate it through the shared helpers in `source/shared/wasm.ts`, and keep the TypeScript path as a safe fallback when loading or ABI expectations fail. |
| 52 | + |
| 53 | +6. Update repository integration points. |
| 54 | + Add the named export in `source/entry-point.ts`. |
| 55 | + If wasm was added, update the expected export mapping in `scripts/verify-wasm.js` in the same change. |
| 56 | + |
| 57 | +7. Validate with the smallest correct command set. |
| 58 | + Run `npm run test` for all algorithm changes. |
| 59 | + If wasm behavior changed, run `npm run build:wasm:strict && npm run build:wasm:check && npm run test -- --runInBand`. |
| 60 | + Use `npm run build` when the change affects package exports or build integration. |
| 61 | + |
| 62 | +8. Report the change clearly. |
| 63 | + Summarize what changed, why wasm was or was not included, how fallback behavior is preserved, and what commands were run. |
| 64 | + |
| 65 | +## Decision Points |
| 66 | + |
| 67 | +### When To Add `main.c` |
| 68 | + |
| 69 | +- Add it when the request explicitly needs wasm acceleration now. |
| 70 | +- Add it when an existing algorithm already has a wasm path that must stay parity-checked. |
| 71 | +- Skip it when correctness, determinism, or delivery speed would be better served by a TypeScript-only implementation. |
| 72 | + |
| 73 | +### When To Touch CLI Code |
| 74 | + |
| 75 | +- Update CLI or prompt-layer code only if the user asks for interactive exposure or the algorithm must be reachable through existing command flows. |
| 76 | +- Otherwise keep the change limited to `source/algorithms/` and `source/entry-point.ts`. |
| 77 | + |
| 78 | +## Guardrails |
| 79 | + |
| 80 | +- Keep behavior deterministic for every public algorithm API. |
| 81 | +- Treat `build/` as generated output, not source. |
| 82 | +- Keep changes minimal and co-located in the algorithm folder whenever possible. |
| 83 | +- Do not change public API names unless explicitly requested. |
| 84 | +- Do not commit generated `.wasm` files. |
| 85 | + |
| 86 | +## Output Expectations |
| 87 | + |
| 88 | +- `source/algorithms/<name>/index.ts` |
| 89 | +- `source/algorithms/<name>/index.test.ts` |
| 90 | +- Optional `source/algorithms/<name>/main.c` |
| 91 | +- `source/entry-point.ts` |
| 92 | +- Optional `scripts/verify-wasm.js` |
| 93 | + |
| 94 | +## Completion Checklist |
| 95 | + |
| 96 | +- Function name, signature, and export are intentional. |
| 97 | +- Tests cover nominal behavior and edge cases. |
| 98 | +- Wasm decision is explicit and justified. |
| 99 | +- Fallback behavior remains valid if wasm is unavailable. |
| 100 | +- Verification commands were run and reported. |
0 commit comments