wity-cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,55 @@
1
+ Apache License
2
+
3
+ Version 2.0, January 2004
4
+
5
+ http://www.apache.org/licenses/
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
16
+
17
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
18
+
19
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
20
+
21
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
22
+
23
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
24
+
25
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
26
+
27
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
28
+
29
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
30
+
31
+ 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
32
+
33
+ 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
34
+
35
+ 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
36
+
37
+ You must give any other recipients of the Work or Derivative Works a copy of this License; and
38
+
39
+ You must cause any modified files to carry prominent notices stating that You changed the files; and
40
+
41
+ You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
42
+
43
+ If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
44
+
45
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
46
+
47
+ 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
48
+
49
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
50
+
51
+ 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
52
+
53
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
54
+
55
+ END OF TERMS AND CONDITIONS
package/README.md ADDED
@@ -0,0 +1,186 @@
1
+ # Wity CLI
2
+
3
+ Ask [Wity](https://wity.alphanimble.com) typed questions about any text, from your terminal. Get a probability for every answer, and use it in scripts through exit codes.
4
+
5
+ ```sh
6
+ cat email.txt | wity noul "Is this a phishing message?"
7
+ ```
8
+
9
+ Needs Node.js 22.13 or newer.
10
+
11
+ ```sh
12
+ npm install -g wity-cli
13
+ ```
14
+
15
+ ## API key
16
+
17
+ ```sh
18
+ wity api-key set wity_… # save a key from wity.alphanimble.com/console/keys
19
+ wity api-key set # or paste it at a hidden prompt
20
+ wity api-key set --stdin < key.txt # or pipe it in, for CI and scripts
21
+ wity api-key show # which key is in use, and does it work
22
+ wity api-key remove # remove the saved key from this computer
23
+ wity doctor # check the key, storage and connection
24
+ ```
25
+
26
+ 1. Create a key on the [keys page](https://wity.alphanimble.com/console/keys).
27
+ 2. Run `wity api-key set wity_…` with your key. Or run `wity api-key set` alone and paste the key at the prompt. Nothing shows while you paste.
28
+ 3. The CLI checks the key with a free call, then saves it.
29
+
30
+ **Scripts and CI.** `wity api-key set --stdin` reads the key from stdin instead of a prompt: `wity api-key set --stdin < key.txt`, or `echo "$KEY" | wity api-key set --stdin`. Or skip saving a key and set `WITY_API_KEY`.
31
+
32
+ **A new key.** Running `wity api-key set` again replaces the saved key.
33
+
34
+ **Removing a key.** `wity api-key remove` only removes the key from this computer. The key keeps working, because the same key may run somewhere else. Revoke it on the keys page if you need to.
35
+
36
+ **How the key is kept safe.**
37
+ - The key is saved in the OS keychain (macOS Keychain, Windows Credential Manager, or the Secret Service on Linux). Without one, it goes in `~/.config/wity/credentials.json`, readable only by you. `WITY_CREDENTIAL_STORE=keychain` or `=file` picks one.
38
+ - A key typed in the command (`wity api-key set wity_…`) is saved in your shell history. The prompt and `--stdin` keep it out.
39
+ - `WITY_API_KEY` wins over a saved key. `wity api-key show` says which one is in use.
40
+ - A key is saved for one API address, and never sent to another. Redirects are never followed.
41
+
42
+ ## Ask
43
+
44
+ ```sh
45
+ wity noul "Is this urgent?" --text "Server is down for all customers"
46
+ wity choice "Which team handles this?" -o billing="Payments and refunds" -o technical="Bugs and outages" --file ticket.txt
47
+ wity score "How upset is the customer?" -l Calm -l Annoyed -l Angry --text "Where is my order?!"
48
+ ```
49
+
50
+ The text comes from `--text`, `--file` (`-` for stdin), or a pipe. Up to 32,000 characters.
51
+
52
+ | Flag | What it does |
53
+ |---|---|
54
+ | `-r, --reasoning off\|auto\|always` | When Wity thinks before answering. The API default is `auto`. |
55
+ | `--max-latency <ms>` | Cap the time per request, 200 to 120000. |
56
+ | `--json` | Print the full response. This is the default when output is piped. |
57
+ | `--field <path>` | Print one value, like `noul`, `choice` or `probabilities.billing`. |
58
+ | `--fail-under <n>` | Exit with 10 if the answer is under `n` (see below). |
59
+ | `--expect <id>` | `choice` only: exit with 10 unless this option wins. |
60
+ | `--dry-run` | Print the request without sending it. Needs no key. |
61
+ | `--code [ts\|curl]` | Print the request as TypeScript (with the SDK) and as curl, instead of sending it. Needs no key. |
62
+ | `--if-yes`, `--if-no` | `noul` only: describe what yes and no mean. |
63
+
64
+ `--fail-under` compares:
65
+
66
+ - for `noul`, the probability of yes
67
+ - for `choice`, the probability of the winner, or of `--expect` if given
68
+ - for `score`, the score itself, on the level scale (0 is the lowest level)
69
+
70
+ Probabilities add up to 1, but they aren't calibrated. Treat them as how sure Wity is, not as exact odds.
71
+
72
+ ## Several questions at once
73
+
74
+ `wity ask` sends every question in a YAML or JSON file in one call. The questions use the API's own shape.
75
+
76
+ ```yaml
77
+ # questions.yaml
78
+ state: My card was charged twice, and I need one refund before Friday. # optional: or use --text, --file, a pipe
79
+ reasoning: auto # optional
80
+ questions:
81
+ team:
82
+ type: choice
83
+ instructions: Which team should handle this ticket?
84
+ criteria:
85
+ billing: Payments, charges and refunds
86
+ technical: Bugs, errors and outages
87
+ other: Anything else
88
+ urgent:
89
+ type: noul
90
+ instructions: Does the customer need this soon?
91
+ upset:
92
+ type: score
93
+ instructions: How upset is the customer?
94
+ criteria: [Calm, Annoyed, Angry]
95
+ ```
96
+
97
+ ```sh
98
+ wity ask questions.yaml
99
+ wity ask questions.yaml --file ticket.txt --field team.choice
100
+ ```
101
+
102
+ - `state` can also be an object, which Wity reads as JSON.
103
+ - Every problem in the file is listed before anything is sent.
104
+ - `--reasoning` and `--max-latency` override the file.
105
+
106
+ ## Generate
107
+
108
+ `wity generate` writes short text, up to 512 tokens. With `--shape`, it writes JSON that matches a JSON Schema.
109
+
110
+ ```sh
111
+ wity generate "The one-sentence reply to send" --file ticket.txt
112
+ wity generate "Origin city and seat" --text "LISBOA (LIS) -> BER, seat 23C" --shape ticket.schema.json
113
+ ```
114
+
115
+ - On a terminal it prints the text, then time and cost.
116
+ - Piped, it prints only the text, or with `--shape` only the JSON. Use `--json` for the whole response.
117
+ - If Wity hits `--max-tokens` (default 128), it says so. With `--shape`, it exits with 1, because the JSON isn't complete.
118
+ - Check generated text before you act on it. It can say things that aren't in the input.
119
+
120
+ ## Playground
121
+
122
+ Run `wity` with no arguments, or `wity playground --file ticket.txt`, to try questions live.
123
+
124
+ - Type or paste the text, pick a question type, and press Enter to ask.
125
+ - Tab moves between fields. ← → changes the type and reasoning.
126
+ - Ctrl+T shows the request as code. Esc quits.
127
+ - Every Enter is a real, billed call. The header shows the running cost.
128
+
129
+ ## AI agents (MCP)
130
+
131
+ `wity mcp serve` gives AI apps Wity as tools: `wity_noul`, `wity_choice`, `wity_score`, `wity_ask` and `wity_generate`. Set a key first with `wity api-key set`, or set `WITY_API_KEY`.
132
+
133
+ ```sh
134
+ claude mcp add wity -- wity mcp serve --max-spend 1 # Claude Code
135
+ ```
136
+
137
+ For Claude Desktop, Cursor and other apps, add this to their MCP settings:
138
+
139
+ ```json
140
+ {
141
+ "mcpServers": {
142
+ "wity": { "command": "wity", "args": ["mcp", "serve", "--max-spend", "1"] }
143
+ }
144
+ }
145
+ ```
146
+
147
+ - It talks over stdin and stdout only, and opens no network port.
148
+ - No tool takes a key, or can set or remove one. The key never appears in tool output.
149
+ - `--max-spend` stops paid calls after that many dollars in one session, in case an agent gets stuck in a loop.
150
+
151
+ ## Exit codes
152
+
153
+ | Code | Meaning |
154
+ |---|---|
155
+ | 0 | OK |
156
+ | 1 | The API or network failed |
157
+ | 2 | Bad flags or input. Nothing was billed. |
158
+ | 3 | No API key, or the key was refused |
159
+ | 10 | Answered, but failed `--fail-under` or `--expect` |
160
+ | 130 | Cancelled with Ctrl+C |
161
+
162
+ ```sh
163
+ if wity noul "Does this diff touch billing code?" --file change.diff --fail-under 0.5 >/dev/null; then
164
+ echo "Needs a billing reviewer"
165
+ fi
166
+ ```
167
+
168
+ ## Settings
169
+
170
+ | Variable | What |
171
+ |---|---|
172
+ | `WITY_API_KEY` | Use this key instead of the saved one. |
173
+ | `WITY_BASE_URL` | Use another API address (also `--base-url`). https only, except localhost. |
174
+ | `WITY_CREDENTIAL_STORE` | `auto` (default), `keychain` or `file`. |
175
+ | `WITY_LOG_LEVEL` | `debug`, `info`, `warn` (default), `error` or `off`. Logs go to stderr. They never include the key or your text. |
176
+ | `NO_COLOR`, `FORCE_COLOR` | Turn colours off or on. |
177
+
178
+ ## Developing
179
+
180
+ ```sh
181
+ npm install
182
+ npm run dev -- noul "Is this spam?" --text "..." # build, then run
183
+ npm run check # typecheck, lint, tests, build, audit
184
+ ```
185
+
186
+ The tests run offline against a fake Wity server, with real responses in `test/fixtures/`. They never touch your keychain or saved key.