feat(dictionary): add dictionary search, synonyms, and examples adapters#241
Conversation
Astro-Han
left a comment
There was a problem hiding this comment.
Solid use of the free Dictionary API — clean YAML pipelines. A few issues:
URL encoding missing
${{ args.word }} is interpolated directly into the URL path. Words with spaces or special characters (e.g. ice cream, C#) will break the request. The template engine has a urlencode filter — use ${{ args.word | urlencode }}. Affects all 3 YAML files.
search.yaml — chained || doesn't work as expected
phonetic: "${{ item.phonetic || item.phonetics?.[0]?.text || item.phonetics?.[1]?.text || '' }}"The template engine's || handler only evaluates the left side of the first ||; the rest is returned as a literal string. When item.phonetic is empty, the output will show item.phonetics?.[0]?.text || ... as text instead of the actual value. Single || with a literal (e.g. item.x || 'N/A') works fine, but chained || with expressions doesn't. Wrapping in an IIFE (like synonyms.yaml and examples.yaml already do) would fix this.
word should be positional
Per CONTRIBUTING.md, the main target arg should use positional: true. opencli dictionary search serendipity is more natural than --word serendipity.
Tests
No E2E tests. Per TESTING.md, browser: false public commands should have entries in public-commands.test.ts.
|
Thanks for the thorough review! I've applied all your suggestions:
Everything is committed and running perfectly. |
… encoding, enhanced phonetic parsing, and new E2E tests.
48f8d11 to
ef574ea
Compare
Description
This PR introduces the powerful new Dictionary adapter to OpenCLI. It leverages the completely free, public
api.dictionaryapi.devrobust JSON endpoint to bring a reliable spell checker, dictionary, and thesaurus straight into the developer terminal.Commands Added (
opencli dictionary):search- Get the phonetic pronunciation, part of speech, and primary definition of any word (e.g.,opencli dictionary search --word "serendipity").synonyms- Extract up to 5 related synonyms for a given word by scrubbing the entire JSON definitions tree.examples- Find real-world sentence usage examples for complex vocabulary (falls back elegantly if a word lacks examples).Implementation Note: The YAML dataset extraction mappings were custom-built using recursive ES6 IIFEs to safely traverse variable-depth JSON nodes. This guarantees 100% crash protection against unpredictable empty arrays in the Dictionary API.
Related issue: N/A
Type of Change
Checklist
opencli validate)READMEintegration and VitePress docs)Documentation (if adding/modifying an adapter)
docs/adapters/(docs/adapters/browser/dictionary.md)docs/adapters/index.mdtabledocs/.vitepress/config.mtsScreenshots / Output