Skip to content

Commit a589d0b

Browse files
kvzclaude
andcommitted
Add cross-language verification infrastructure
- scripts/verify.ts: Native TypeScript (Node 25+), Docker-based verification - Content-based caching in .cache/verify/ for fast re-runs - Support for PHP, Go, Python, Ruby, C via Docker containers - yarn verify / yarn verify:php commands Rewrite MAINTAINER_PLAN.md with ambitious 5-phase roadmap: 1. Verification Infrastructure (current) 2. Modernization (ESM, Vitest) 3. TypeScript 4. Expansion (more functions) 5. Documentation & Website 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 985e03e commit a589d0b

4 files changed

Lines changed: 552 additions & 80 deletions

File tree

.claude/MAINTAINER_PLAN.md

Lines changed: 169 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,101 @@
11
# Locutus Maintenance Plan
22

33
**Last Updated:** 2026-01-06
4-
**Philosophy:** Quality over quantity. Curate with taste.
4+
**Philosophy:** Quality over quantity. Verify against reality. Curate with taste.
55

66
---
77

8-
## Project Overview
8+
## Vision
99

10-
Locutus is a JavaScript library that ports standard library functions from PHP, Go, Python, Ruby, and C. The project has **373+ functions** (primarily PHP), focusing on complex implementations that provide real value beyond native JavaScript.
10+
Locutus is **the** reference implementation for cross-language standard library functions in JavaScript. Every function should be:
1111

12-
### Current Status
13-
- **Tests:** 910 passing
14-
- **Linting:** Biome (migrated from ESLint + Prettier)
15-
- **Build:** Babel 6 (legacy, migration planned)
16-
- **Package Manager:** Yarn 4.12.0
12+
1. **Verified** - Tested against actual language runtimes (not just JS unit tests)
13+
2. **Documented** - Clear examples, edge cases, and differences from native
14+
3. **Typed** - Full TypeScript definitions
15+
4. **Modern** - ESM, tree-shakeable, zero dependencies
1716

1817
---
1918

20-
## Known Issues & Licensing
19+
## Current State
2120

22-
### BC Math LGPL Licensing (Issue #473)
21+
| Metric | Value |
22+
|--------|-------|
23+
| Functions | 394 with examples |
24+
| Tests | 910 passing |
25+
| Linting | Biome (25 warnings, 11 in LGPL code) |
26+
| Build | Babel 6 (legacy) |
27+
| Types | Basic index.d.ts |
28+
| Languages | PHP (primary), Go, Python, Ruby, C |
2329

24-
The following files contain code derived from PHP's bcmath extension, which is LGPL licensed:
30+
---
31+
32+
## Roadmap
33+
34+
### Phase 1: Verification Infrastructure (Current)
35+
36+
**Goal:** Every function verified against actual language runtime via Docker.
37+
38+
- [x] Create `scripts/verify.ts` - TypeScript, native Node execution
39+
- [x] Content-based caching in `.cache/verify/`
40+
- [ ] Docker containers for PHP, Go, Python, Ruby, C
41+
- [ ] JS-to-native code transpilation for each language
42+
- [ ] CI integration - fail if verification diverges
43+
- [ ] Badge: "Verified against PHP 8.3"
44+
45+
**Commands:**
46+
```bash
47+
yarn verify # Verify all (uses cache)
48+
yarn verify php # Verify PHP only
49+
yarn verify --no-cache # Force re-verification
50+
```
51+
52+
### Phase 2: Modernization
53+
54+
**Goal:** Modern toolchain, ESM-first, tree-shakeable.
55+
56+
- [ ] Migrate Babel 6 → native ESM (Node 20+)
57+
- [ ] Migrate Mocha → Vitest
58+
- [ ] Dual CJS/ESM exports
59+
- [ ] Publish as `locutus@3.0.0` with breaking changes
60+
- [ ] Drop Node < 20 support
61+
62+
### Phase 3: TypeScript
63+
64+
**Goal:** Full type safety, better DX.
65+
66+
- [ ] Convert `src/_util/` to TypeScript
67+
- [ ] Generate types from JSDoc in function files
68+
- [ ] Per-function type exports: `import type { SprintfArgs } from 'locutus/php/strings/sprintf'`
69+
- [ ] Strict mode compatible
70+
71+
### Phase 4: Expansion
2572

26-
- `src/php/_helpers/_bc.js` - Core bcmath implementation
27-
- `website/source/php/_helpers/_bc.html` - Documentation
73+
**Goal:** Best-in-class coverage for target languages.
2874

29-
**Status:** This code has LGPL copyleft implications. Users of locutus who include these BC math functions may need to comply with LGPL requirements for that portion of their codebase.
75+
**PHP Priority Functions:**
76+
- [ ] `preg_match_all` - regex with captures
77+
- [ ] `DateTime` class methods
78+
- [ ] `array_column` improvements
79+
- [ ] `password_hash` / `password_verify`
3080

31-
**Affected functions:**
32-
- `bcadd`, `bcsub`, `bcmul`, `bcdiv`, `bccomp`, `bcround`, `bcscale`
81+
**Go Expansion:**
82+
- [ ] `fmt.Sprintf` with full verb support
83+
- [ ] `time.Parse` / `time.Format`
84+
- [ ] `regexp` package
85+
- [ ] `encoding/json` with struct tags
3386

34-
**Recommendation for users:** If LGPL compliance is a concern, avoid importing the `bc*` functions. The rest of locutus is MIT licensed.
87+
**Python Expansion:**
88+
- [ ] `datetime` module
89+
- [ ] `re` module
90+
- [ ] `collections` (Counter, defaultdict)
91+
- [ ] `itertools`
92+
93+
### Phase 5: Documentation & Website
94+
95+
- [ ] Auto-generate docs from source
96+
- [ ] Interactive playground (run in browser)
97+
- [ ] Search by function name or behavior
98+
- [ ] "Rosetta Stone" - same function across all languages
3599

36100
---
37101

@@ -40,108 +104,133 @@ The following files contain code derived from PHP's bcmath extension, which is L
40104
### Quick Commands
41105

42106
```bash
43-
yarn check # Format, lint, type-check, test (run after changes)
44-
yarn test # Full test suite
45-
yarn lint # Biome check
46-
yarn fix:biome # Auto-fix linting issues
47-
yarn build # Build everything
107+
yarn check # Format + lint + test (run after changes)
108+
yarn verify # Cross-language verification
109+
yarn test # Full test suite
110+
yarn lint # Biome check
111+
yarn fix:biome # Auto-fix
48112
```
49113

50114
### Adding a New Function
51115

52-
1. Create file: `src/{language}/{category}/{function_name}.js`
53-
2. Add header comments with examples (these become tests)
54-
3. Run: `yarn build:tests && yarn test`
55-
4. Run: `yarn check` to verify formatting
116+
1. **Check it's worth adding:**
117+
- Non-trivial implementation?
118+
- Not available in modern JS?
119+
- Verified against actual language?
120+
121+
2. **Create the file:**
122+
```bash
123+
# src/{language}/{category}/{function_name}.js
124+
touch src/php/strings/new_function.js
125+
```
126+
127+
3. **Add header with examples:**
128+
```javascript
129+
module.exports = function new_function(arg) {
130+
// discuss at: https://locutus.io/php/new_function/
131+
// original by: Your Name
132+
// example 1: new_function('test')
133+
// returns 1: 'expected'
134+
135+
// Implementation...
136+
}
137+
```
138+
139+
4. **Verify and test:**
140+
```bash
141+
yarn verify php/strings/new_function
142+
yarn build:tests && yarn test
143+
yarn check
144+
```
56145

57146
### Commit Guidelines
58147

59-
- Get something merged before doing more work
60-
- Keep PRs focused and small
148+
- Small, focused PRs
61149
- Run `yarn check` before committing
150+
- Merge early, iterate often
62151

63152
---
64153

65-
## Strategic Priorities
154+
## Quality Standards
66155

67-
### Priority 1: Code Quality
68-
- Zero biome warnings (suppress only when necessary with comments)
69-
- Remove trivial wrapper functions
70-
- Verify implementations against actual languages
156+
### Zero Tolerance
157+
- Failing tests
158+
- Biome errors
159+
- Unverified implementations (eventually)
71160

72-
### Priority 2: Modernization (Planned)
73-
- Vitest migration (from Mocha)
74-
- TypeScript migration (gradual)
75-
- ESM support
161+
### Acceptable Warnings
162+
- LGPL code (`_bc.js`) - can't modify
163+
- Intentional eval/new Function (with biome-ignore comment)
164+
- Style warnings in complex algorithms
76165

77-
### Priority 3: Community
78-
- Respond to PRs/issues within a week
79-
- Regular releases (monthly patches)
166+
### Curation Rules
80167

81-
---
168+
**Worth porting:**
169+
- Complex: `sprintf`, `strtotime`, `serialize`, `date`
170+
- Language-specific quirks: `array_merge` vs `array_merge_recursive`
171+
- Educational: showing PHP's type coercion
172+
173+
**Skip:**
174+
- Direct wrappers: `strlen``s.length`
175+
- Modern JS equivalents: `Array.includes`, `Object.keys`
176+
- Trivial math: `abs`, `ceil`, `floor`
82177

83-
## Curation Guidelines
178+
---
84179

85-
### Functions Worth Porting (High Value)
86-
- Complex implementations: `sprintf`, `strtotime`, `serialize`, `date`
87-
- PHP-specific behavior: `array_merge_recursive`, `json_encode` options
88-
- Educational value: showing language differences
180+
## Licensing
89181

90-
### Functions to Avoid (Low Value)
91-
- Direct wrappers (`strlen` = `s.length`)
92-
- Functions in modern JS (`Array.includes`, etc.)
93-
- Trivial transformations
182+
- **MIT** - Everything except BC Math
183+
- **LGPL-2.1** - `src/php/_helpers/_bc.js` and `src/php/bc/*`
94184

95-
### Before Adding a Function, Ask:
96-
1. Does this provide value beyond native JS?
97-
2. Is the implementation non-trivial?
98-
3. Have you verified against actual PHP/Go/Python?
185+
See [LICENSE](../LICENSE) for details.
99186

100187
---
101188

102-
## Changelog
189+
## Open Items
103190

104-
### 2026-01-06 - Biome Migration
105-
- Migrated from ESLint + Prettier to Biome
106-
- Removed 12 ESLint/Prettier dependencies
107-
- Fixed variable scoping issues in 6 files after auto-fix
108-
- Added `yarn check` command for quick validation
109-
110-
### 2026-01-06 - Initial Setup
111-
- Fixed 5 failing tests
112-
- Expanded Go, Python, Ruby, C coverage
113-
- Created TypeScript definitions
114-
- Updated yarn to 4.12.0
115-
- Added knip for unused code detection
191+
### PR #477 - composer.json
192+
Status: Open, needs clarification
193+
194+
### Issue #473 - LGPL
195+
Status: **Resolved** - Documented in LICENSE, README, source files
116196

117197
---
118198

119199
## Lessons Learned
120200

121-
1. **Biome's unsafe fixes can break code** - Variable declarations with multiple variables (`let i, j = 0`) get split incorrectly. Always run tests after auto-fix.
201+
1. **Verify against reality** - Unit tests aren't enough. Run actual PHP/Go/Python.
122202

123-
2. **Keep one plan document** - Don't create multiple strategy docs. Revise this one.
203+
2. **Don't duplicate infrastructure** - Check `src/_util/` before creating new tools.
124204

125-
3. **Merge before adding more** - Get changes merged before piling on more work.
205+
3. **Document in the right place** - LICENSE, README, SPDX headers. Not just issues.
126206

127-
4. **Clean up thoroughly** - After migrations, remove ALL traces (including suppression comments).
207+
4. **Biome unsafe fixes break code** - Always test after auto-fix.
128208

129-
5. **eval() is sometimes necessary** - For PHP function ports like `json_decode`, `create_function`, `is_callable`, eval is legitimately needed. Suppress the warning with a comment explaining why.
209+
5. **eval() is sometimes necessary** - Suppress with explanation, don't fight it.
130210

131-
6. **Document licensing in the right places** - Don't just comment on issues. Update LICENSE, README, and add SPDX headers to affected files.
211+
6. **Keep one plan** - Revise this document, don't create new ones.
132212

133-
7. **Don't duplicate existing infrastructure** - Check src/_util/ before creating new scripts. The test generation and parsing utilities already exist.
213+
7. **Merge often** - Small PRs, fast iteration.
134214

135215
---
136216

137-
## Open Items
217+
## Changelog
138218

139-
### PR #477 - composer.json
140-
Status: Open, awaiting clarification on use case
219+
### 2026-01-06 - Cross-Language Verification
220+
- Created `scripts/verify.ts` with Docker support
221+
- Content-based caching for fast re-runs
222+
- Native TypeScript (Node 25+)
223+
224+
### 2026-01-06 - LGPL Documentation
225+
- Added LGPL exception to LICENSE
226+
- Added License section to README
227+
- Added SPDX headers to `_bc.js`
141228

142-
### Issue #473 - LGPL in _bc.js
143-
Status: **Resolved.** LGPL licensing now documented in LICENSE, README, and _bc.js header.
229+
### 2026-01-06 - Biome Migration
230+
- Migrated from ESLint + Prettier
231+
- Reduced warnings from 41 to 25
232+
- Added `yarn check` command
144233

145234
---
146235

147-
*Review and update this document regularly.*
236+
*This is a living document. Update it regularly.*

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ website/node_modules/
2525
website/public
2626
website/vendor/bundle/
2727
website/vendor/cache/
28+
.cache/

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
"test:languages:noskip": "yarn build:tests:noskip && cross-env DEBUG='locutus:*' mocha --require babel-register --reporter spec 'src/**/*.mocha.js' 'test/**/test-*.js'",
4444
"test:languages": "yarn build:tests && cross-env DEBUG='locutus:*' mocha --require babel-register --reporter spec 'src/**/*.mocha.js' 'test/**/test-*.js'",
4545
"test:module": "babel-node test/module/module.js",
46+
"verify": "node scripts/verify.ts",
47+
"verify:php": "node scripts/verify.ts php",
4648
"test:util": "mocha --require babel-register --reporter spec test/util/",
4749
"test": "npm-run-all test:languages test:util test:module",
4850
"website:install": "cd website && yarn",

0 commit comments

Comments
 (0)