diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..56c638c --- /dev/null +++ b/.editorconfig @@ -0,0 +1,22 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.swift] +indent_style = space +indent_size = 4 + +[*.{yml,yaml}] +indent_style = space +indent_size = 2 + +[*.{json,toml}] +indent_style = space +indent_size = 2 + +[*.md] +trim_trailing_whitespace = false diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..97aba6d --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,8 @@ +# Default owners for everything +* @toon-format/swift-maintainers + +# Project governance and documentation +CODE_OF_CONDUCT.md @johannschopplich +CONTRIBUTING.md @johannschopplich +LICENSE @mattt +README.md @mattt diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 0000000..e3b18a6 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,81 @@ +name: Bug Report +description: Report a bug or unexpected behavior +labels: ["bug"] +body: + - type: markdown + attributes: + value: | + Thanks for taking the time to report a bug! + + - type: textarea + id: description + attributes: + label: Description + description: A clear description of what the bug is + placeholder: When I try to encode..., I expect..., but instead... + validations: + required: true + + - type: textarea + id: reproduction + attributes: + label: Reproduction Steps + description: Steps to reproduce the behavior + placeholder: | + 1. Import TOONEncoder + 2. Call encode() with... + 3. See error... + validations: + required: true + + - type: textarea + id: expected + attributes: + label: Expected Behavior + description: What you expected to happen + validations: + required: true + + - type: textarea + id: actual + attributes: + label: Actual Behavior + description: What actually happened (including error messages) + validations: + required: true + + - type: dropdown + id: version + attributes: + label: TOONEncoder Version + description: Which version of TOONEncoder are you using? + options: + - 0.2.0 (latest) + - 0.1.0 + - Other (please specify in Additional Context) + validations: + required: true + + - type: textarea + id: environment + attributes: + label: Environment + description: | + Please provide: + - Swift version + - Xcode version (if applicable) + - Platform (iOS, macOS, etc.) + - Operating system + placeholder: | + - Swift 6.0 + - Xcode 16.0 + - macOS 15.0 + - iOS 17.0 + validations: + required: true + + - type: textarea + id: additional + attributes: + label: Additional Context + description: Any other context about the problem (optional) diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 0000000..c30116f --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,48 @@ +name: Feature Request +description: Suggest a new feature or enhancement +labels: ["enhancement"] +body: + - type: markdown + attributes: + value: | + Thanks for suggesting a feature! + + - type: textarea + id: problem + attributes: + label: Problem Statement + description: What problem does this feature solve? + placeholder: As a user, I want to... because... + validations: + required: true + + - type: textarea + id: solution + attributes: + label: Proposed Solution + description: How would you like this to work? + placeholder: | + Add a new method/property that... + validations: + required: true + + - type: textarea + id: alternatives + attributes: + label: Alternatives Considered + description: What alternative solutions have you considered? + + - type: textarea + id: spec + attributes: + label: SPEC Compliance + description: | + Does this relate to the TOON specification? + If yes, please reference the relevant section. + placeholder: This relates to SPEC.md section... + + - type: textarea + id: additional + attributes: + label: Additional Context + description: Any other context, mockups, or examples diff --git a/.github/ISSUE_TEMPLATE/spec_compliance.yml b/.github/ISSUE_TEMPLATE/spec_compliance.yml new file mode 100644 index 0000000..0d519f0 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/spec_compliance.yml @@ -0,0 +1,66 @@ +name: SPEC Compliance Issue +description: Report a deviation from the TOON specification +labels: ["spec-compliance"] +body: + - type: markdown + attributes: + value: | + Report an issue where TOONEncoder doesn't comply with the official TOON spec. + + - type: input + id: spec-version + attributes: + label: SPEC Version + description: Which version of the TOON spec does this relate to? + placeholder: v3.0 + validations: + required: true + + - type: input + id: spec-section + attributes: + label: SPEC Section + description: Which section of SPEC.md is affected? + placeholder: "Section 7.1: Escaping (Encoding and Decoding)" + validations: + required: true + + - type: textarea + id: spec-requirement + attributes: + label: SPEC Requirement + description: What does the spec require? + placeholder: According to SPEC.md, the encoder should... + validations: + required: true + + - type: textarea + id: current-behavior + attributes: + label: Current Behavior + description: What does TOONEncoder currently do? + placeholder: Currently, TOONEncoder... + validations: + required: true + + - type: textarea + id: test-case + attributes: + label: Test Case + description: Provide a test case that demonstrates the issue + placeholder: | + ```swift + import TOONEncoder + let encoder = TOONEncoder() + let result = try encoder.encode(...) + // Expected: ... + // Actual: ... + ``` + validations: + required: true + + - type: textarea + id: additional + attributes: + label: Additional Context + description: Any other relevant information diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..a921b6e --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,122 @@ +## Description + + + +## Type of Change + + + +- [ ] Bug fix (non-breaking change that fixes an issue) +- [ ] New feature (non-breaking change that adds functionality) +- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) +- [ ] Documentation update +- [ ] Refactoring (no functional changes) +- [ ] Performance improvement +- [ ] Test coverage improvement + +## Related Issues + + + +Closes # + +## Changes Made + + + +- +- +- + +## SPEC Compliance + + + +- [ ] This PR implements/fixes spec compliance +- [ ] Spec section(s) affected: +- [ ] Spec version: + +## Testing + + + +- [ ] All existing tests pass +- [ ] Added new tests for changes +- [ ] Tested on Swift 6.0 +- [ ] Tested on Swift 6.1 +- [ ] Tested on Swift 6.2 + +### Test Output + +```bash +# Paste test output here +``` + +## Code Quality + + + +- [ ] Ran `swift test` - all tests pass +- [ ] Ran `swift-format` - code follows format guidelines +- [ ] Added documentation comments for public APIs +- [ ] Code follows Swift conventions + +## Checklist + + + +- [ ] My code follows the project's coding standards +- [ ] I have added documentation comments to new public APIs +- [ ] I have added tests that prove my fix/feature works +- [ ] New and existing tests pass locally +- [ ] I have updated documentation (README.md if needed) +- [ ] My changes do not introduce new dependencies (or are justified) +- [ ] I have maintained Swift 6.0+ compatibility +- [ ] I have reviewed the [TOON specification](https://github.com/toon-format/spec) for relevant sections + +## Performance Impact + + + +- [ ] No performance impact +- [ ] Performance improvement (describe below) +- [ ] Potential performance regression (describe and justify below) + + + +## Breaking Changes + + + +- [ ] No breaking changes +- [ ] Breaking changes (describe migration path below) + + + +## Screenshots / Examples + + + +```swift +// Example usage +``` + +Output: +``` +# Example output +``` + +## Additional Context + + + +## Checklist for Reviewers + + + +- [ ] Code changes are clear and well-documented +- [ ] Tests adequately cover the changes +- [ ] Documentation is updated +- [ ] No security concerns +- [ ] Follows TOON specification +- [ ] Backward compatible (or breaking changes are justified and documented) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..86f5534 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,85 @@ +# Contributor Covenant 3.0 Code of Conduct + +## Our Pledge + +We pledge to make our community welcoming, safe, and equitable for all. + +We are committed to fostering an environment that respects and promotes the dignity, rights, and contributions of all individuals, regardless of characteristics including race, ethnicity, caste, color, age, physical characteristics, neurodiversity, disability, sex or gender, gender identity or expression, sexual orientation, language, philosophy or religion, national or social origin, socio-economic position, level of education, or other status. The same privileges of participation are extended to everyone who participates in good faith and in accordance with this Covenant. + +## Encouraged Behaviors + +While acknowledging differences in social norms, we all strive to meet our community's expectations for positive behavior. We also understand that our words and actions may be interpreted differently than we intend based on culture, background, or native language. + +With these considerations in mind, we agree to behave mindfully toward each other and act in ways that center our shared values, including: + +1. Respecting the **purpose of our community**, our activities, and our ways of gathering. +2. Engaging **kindly and honestly** with others. +3. Respecting **different viewpoints** and experiences. +4. **Taking responsibility** for our actions and contributions. +5. Gracefully giving and accepting **constructive feedback**. +6. Committing to **repairing harm** when it occurs. +7. Behaving in other ways that promote and sustain the **well-being of our community**. + +## Restricted Behaviors + +We agree to restrict the following behaviors in our community. Instances, threats, and promotion of these behaviors are violations of this Code of Conduct. + +1. **Harassment.** Violating explicitly expressed boundaries or engaging in unnecessary personal attention after any clear request to stop. +2. **Character attacks.** Making insulting, demeaning, or pejorative comments directed at a community member or group of people. +3. **Stereotyping or discrimination.** Characterizing anyone's personality or behavior on the basis of immutable identities or traits. +4. **Sexualization.** Behaving in a way that would generally be considered inappropriately intimate in the context or purpose of the community. +5. **Violating confidentiality**. Sharing or acting on someone's personal or private information without their permission. +6. **Endangerment.** Causing, encouraging, or threatening violence or other harm toward any person or group. +7. Behaving in other ways that **threaten the well-being** of our community. + +### Other Restrictions + +1. **Misleading identity.** Impersonating someone else for any reason, or pretending to be someone else to evade enforcement actions. +2. **Failing to credit sources.** Not properly crediting the sources of content you contribute. +3. **Promotional materials**. Sharing marketing or other commercial content in a way that is outside the norms of the community. +4. **Irresponsible communication.** Failing to responsibly present content which includes, links or describes any other restricted behaviors. + +## Reporting an Issue + +Tensions can occur between community members even when they are trying their best to collaborate. Not every conflict represents a code of conduct violation, and this Code of Conduct reinforces encouraged behaviors and norms that can help avoid conflicts and minimize harm. + +When an incident does occur, it is important to report it promptly. To report a possible violation, please contact Johann Schopplich directly at hello@johannschopplich.com. + +Community Moderators take reports of violations seriously and will make every effort to respond in a timely manner. They will investigate all reports of code of conduct violations, reviewing messages, logs, and recordings, or interviewing witnesses and other participants. Community Moderators will keep investigation and enforcement actions as transparent as possible while prioritizing safety and confidentiality. In order to honor these values, enforcement actions are carried out in private with the involved parties, but communicating to the whole community may be part of a mutually agreed upon resolution. + +## Addressing and Repairing Harm + +**[NOTE: The remedies and repairs outlined below are suggestions based on best practices in code of conduct enforcement. If your community has its own established enforcement process, be sure to edit this section to describe your own policies.]** + +If an investigation by the Community Moderators finds that this Code of Conduct has been violated, the following enforcement ladder may be used to determine how best to repair harm, based on the incident's impact on the individuals involved and the community as a whole. Depending on the severity of a violation, lower rungs on the ladder may be skipped. + +1) Warning + 1) Event: A violation involving a single incident or series of incidents. + 2) Consequence: A private, written warning from the Community Moderators. + 3) Repair: Examples of repair include a private written apology, acknowledgement of responsibility, and seeking clarification on expectations. +2) Temporarily Limited Activities + 1) Event: A repeated incidence of a violation that previously resulted in a warning, or the first incidence of a more serious violation. + 2) Consequence: A private, written warning with a time-limited cooldown period designed to underscore the seriousness of the situation and give the community members involved time to process the incident. The cooldown period may be limited to particular communication channels or interactions with particular community members. + 3) Repair: Examples of repair may include making an apology, using the cooldown period to reflect on actions and impact, and being thoughtful about re-entering community spaces after the period is over. +3) Temporary Suspension + 1) Event: A pattern of repeated violation which the Community Moderators have tried to address with warnings, or a single serious violation. + 2) Consequence: A private written warning with conditions for return from suspension. In general, temporary suspensions give the person being suspended time to reflect upon their behavior and possible corrective actions. + 3) Repair: Examples of repair include respecting the spirit of the suspension, meeting the specified conditions for return, and being thoughtful about how to reintegrate with the community when the suspension is lifted. +4) Permanent Ban + 1) Event: A pattern of repeated code of conduct violations that other steps on the ladder have failed to resolve, or a violation so serious that the Community Moderators determine there is no way to keep the community safe with this person as a member. + 2) Consequence: Access to all community spaces, tools, and communication channels is removed. In general, permanent bans should be rarely used, should have strong reasoning behind them, and should only be resorted to if working through other remedies has failed to change the behavior. + 3) Repair: There is no possible repair in cases of this severity. + +This enforcement ladder is intended as a guideline. It does not limit the ability of Community Managers to use their discretion and judgment, in keeping with the best interests of our community. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public or other spaces. Examples of representing our community include using an official email address, posting via an official social media account, or acting as an appointed representative at an online or offline event. + +## Attribution + +This Code of Conduct is adapted from the Contributor Covenant, version 3.0, permanently available at [https://www.contributor-covenant.org/version/3/0/](https://www.contributor-covenant.org/version/3/0/). + +Contributor Covenant is stewarded by the Organization for Ethical Source and licensed under CC BY-SA 4.0. To view a copy of this license, visit [https://creativecommons.org/licenses/by-sa/4.0/](https://creativecommons.org/licenses/by-sa/4.0/) + +For answers to common questions about Contributor Covenant, see the FAQ at [https://www.contributor-covenant.org/faq](https://www.contributor-covenant.org/faq). Translations are provided at [https://www.contributor-covenant.org/translations](https://www.contributor-covenant.org/translations). Additional enforcement and community guideline resources can be found at [https://www.contributor-covenant.org/resources](https://www.contributor-covenant.org/resources). The enforcement ladder was inspired by the work of [Mozilla's code of conduct team](https://github.com/mozilla/inclusion). diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..e979434 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,127 @@ +# Contributing to TOONEncoder + +Thank you for your interest in contributing to the official Swift implementation of TOON! + +## Project Setup + +This project uses Swift Package Manager for dependency management and build automation. + +```bash +# Clone the repository +git clone https://github.com/toon-format/toon-swift.git +cd TOONEncoder + +# Build the project +swift build + +# Run tests +swift test + +# Generate Xcode project (optional) +swift package generate-xcodeproj +``` + +## Development Workflow + +1. **Fork the repository** and create a feature branch +2. **Make your changes** following the coding standards below +3. **Add tests** for any new functionality +4. **Ensure all tests pass** and follow existing patterns +5. **Submit a pull request** with a clear description + +### New Features + +1. **Open a discussion topic** about the new feature explaining the advantages or the motivation for this new feature. +2. **After approval** create an Issue linked to the discussion topic. +3. **Follow the development workflow** to implement the new feature. + +### Bugs + +1. **Open an issue** reporting the bug with detailed reproduction steps. + +## Coding Standards + +### Swift Version Support + +This project requires Swift 6.0 and above. + +### Code Style + +- Follow standard Swift coding conventions +- Use meaningful variable and method names +- Keep methods focused and concise +- Add documentation comments for public APIs +- Format code consistently using the `.swift-format` configuration + ```bash + # Format code (if you have swift-format installed) + swift-format format --in-place --recursive Sources/ Tests/ + ``` + +### Testing + +- All new features must include tests using Swift Testing framework +- Tests should cover edge cases and spec compliance +- Run the full test suite: + ```bash + swift test + + # Verbose output + swift test -v + ``` + +### Build Tasks + +Common Swift Package Manager commands you'll use: + +```bash +# Build the project +swift build + +# Run tests +swift test + +# Run tests with verbose output +swift test -v + +# Clean build artifacts +swift package clean + +# Generate Xcode project +swift package generate-xcodeproj +``` + +## SPEC Compliance + +All implementations must comply with the [TOON specification](https://github.com/toon-format/spec/blob/main/SPEC.md). + +Before submitting changes that affect encoding/decoding behavior: + +1. Verify against the official SPEC.md +2. Add tests for the specific spec sections you're implementing +3. Document any spec version requirements + +## Pull Request Guidelines + +- **Title**: Use a clear, descriptive title (e.g., "Add support for nested arrays", "Fix: Handle edge case in encoder") +- **Description**: Explain what changes you made and why +- **Tests**: Include tests for your changes +- **Documentation**: Update README or code comments if needed +- **Commits**: Use clear commit messages ([Conventional Commits](https://www.conventionalcommits.org/) preferred) + +## Communication + +- **GitHub Issues**: For bug reports and feature requests +- **GitHub Discussions**: For questions and general discussion +- **Pull Requests**: For code reviews and implementation discussion + +## Maintainers + +This project is maintained by: + +- [@mattt](https://github.com/mattt) + +For major architectural decisions, please open a discussion issue first. + +## License + +By contributing, you agree that your contributions will be licensed under the MIT License. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..7906948 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025-PRESENT Mattt (https://github.com/mattt) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/LICENSE.md b/LICENSE.md deleted file mode 100644 index 1d71543..0000000 --- a/LICENSE.md +++ /dev/null @@ -1,19 +0,0 @@ -Copyright 2025 Mattt (https://mat.tt) - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the "Software"), -to deal in the Software without restriction, including without limitation -the rights to use, copy, modify, merge, publish, distribute, sublicense, -and/or sell copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index 5543f71..a5c83ef 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,13 @@ -# TOONEncoder +# TOONEncoder – TOON Format for Swift -A Swift encoder for [TOON](https://github.com/toon-format/spec) (Token-Oriented Object Notation), -a compact format designed to reduce LLM token usage by 30–60% compared with JSON. +[![CI](https://github.com/toon-format/toon-swift/actions/workflows/ci.yml/badge.svg)](https://github.com/toon-format/toon-swift/actions) +[![Swift Version](https://img.shields.io/badge/swift-6.0+-orange.svg)](https://swift.org) +[![SPEC v3.0](https://img.shields.io/badge/spec-v3.0-fef3c0?labelColor=1b1b1f)](https://github.com/toon-format/spec) +[![License: MIT](https://img.shields.io/badge/license-MIT-fef3c0?labelColor=1b1b1f)](./LICENSE.md) + +Compact, human-readable serialization format for LLM contexts with **30-60% token reduction** vs JSON. Combines YAML-like indentation with CSV-like tabular arrays. Full compatibility with the [official TOON specification](https://github.com/toon-format/spec). + +**Key Features:** Minimal syntax • Tabular arrays for uniform data • Array length validation • Swift 6.0+ • Configurable delimiters • Key folding support. LLM tokens are expensive, and JSON is verbose. TOON saves tokens while remaining human-readable by @@ -58,13 +64,13 @@ Add the following to your `Package.swift` file: ```swift dependencies: [ - .package(url: "https://github.com/mattt/TOONEncoder.git", from: "0.2.0") + .package(url: "https://github.com/toon-format/toon-swift.git", from: "0.2.0") ] ``` ## Usage -### Basic Encoding +### Quick Start ```swift import TOONEncoder @@ -309,7 +315,30 @@ Check the supported TOON specification version: print(TOONEncoder.specVersion) // "3.0" ``` +## Contributing + +Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details on how to get started, coding standards, and the process for submitting pull requests. + +Before contributing, please review: +- [Code of Conduct](CODE_OF_CONDUCT.md) +- [TOON Specification](https://github.com/toon-format/spec/blob/main/SPEC.md) + +## Code of Conduct + +This project follows the [Contributor Covenant Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. Please report unacceptable behavior to hello@johannschopplich.com. + +## Project Status + +This library implements **TOON specification version 3.0** (2025-11-24) with full encoding support. + +See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines. + +## Documentation + +- [📜 TOON Spec](https://github.com/toon-format/spec) - Official specification +- [🐛 Issues](https://github.com/toon-format/toon-swift/issues) - Bug reports and features +- [🤝 Contributing](CONTRIBUTING.md) - Contribution guidelines + ## License -This project is available under the MIT license. -See the LICENSE file for more info. +MIT License – see [LICENSE.md](LICENSE.md) for details