@wirecat/cli-base 0.0.0-stage → 0.21.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.
Files changed (201) hide show
  1. package/LICENSE +204 -0
  2. package/README.md +376 -2
  3. package/config/biome.base.json +56 -0
  4. package/config/cspell.json +57 -0
  5. package/config/lefthook.yml +34 -0
  6. package/config/rumdl.toml +9 -0
  7. package/config/tsconfig.base.json +21 -0
  8. package/config/tsconfig.scripts.json +13 -0
  9. package/config/tsconfig.test.json +11 -0
  10. package/config/vale/CliDocs/Filler.yml +9 -0
  11. package/config/vale/CliDocs/SentenceLength.yml +6 -0
  12. package/config/vale/Tg/Tone.yml +7 -0
  13. package/config/wirecat/LICENSE +204 -0
  14. package/config/wirecat/biome.base.json +56 -0
  15. package/config/wirecat/check.mjs +41 -0
  16. package/config/wirecat/cspell.json +80 -0
  17. package/config/wirecat/lefthook.yml +26 -0
  18. package/config/wirecat/manifest.json +23 -0
  19. package/config/wirecat/markdownlint.json +10 -0
  20. package/config/wirecat/rumdl.toml +9 -0
  21. package/dist/codegen/index.d.ts +12 -0
  22. package/dist/codegen/index.d.ts.map +1 -0
  23. package/dist/codegen/index.js +11 -0
  24. package/dist/codegen/index.js.map +1 -0
  25. package/dist/codegen/manifest.d.ts +47 -0
  26. package/dist/codegen/manifest.d.ts.map +1 -0
  27. package/dist/codegen/manifest.js +73 -0
  28. package/dist/codegen/manifest.js.map +1 -0
  29. package/dist/codegen/model.d.ts +146 -0
  30. package/dist/codegen/model.d.ts.map +1 -0
  31. package/dist/codegen/model.js +7 -0
  32. package/dist/codegen/model.js.map +1 -0
  33. package/dist/codegen/names.d.ts +4 -0
  34. package/dist/codegen/names.d.ts.map +1 -0
  35. package/dist/codegen/names.js +46 -0
  36. package/dist/codegen/names.js.map +1 -0
  37. package/dist/codegen/pipeline.d.ts +24 -0
  38. package/dist/codegen/pipeline.d.ts.map +1 -0
  39. package/dist/codegen/pipeline.js +193 -0
  40. package/dist/codegen/pipeline.js.map +1 -0
  41. package/dist/codegen/runtime.d.ts +24 -0
  42. package/dist/codegen/runtime.d.ts.map +1 -0
  43. package/dist/codegen/runtime.js +38 -0
  44. package/dist/codegen/runtime.js.map +1 -0
  45. package/dist/codegen/tree.d.ts +29 -0
  46. package/dist/codegen/tree.d.ts.map +1 -0
  47. package/dist/codegen/tree.js +87 -0
  48. package/dist/codegen/tree.js.map +1 -0
  49. package/dist/codegen/typescript.d.ts +6 -0
  50. package/dist/codegen/typescript.d.ts.map +1 -0
  51. package/dist/codegen/typescript.js +78 -0
  52. package/dist/codegen/typescript.js.map +1 -0
  53. package/dist/codegen/valibot.d.ts +10 -0
  54. package/dist/codegen/valibot.d.ts.map +1 -0
  55. package/dist/codegen/valibot.js +132 -0
  56. package/dist/codegen/valibot.js.map +1 -0
  57. package/dist/commands/index.d.ts +76 -0
  58. package/dist/commands/index.d.ts.map +1 -0
  59. package/dist/commands/index.js +62 -0
  60. package/dist/commands/index.js.map +1 -0
  61. package/dist/commands/page.d.ts +80 -0
  62. package/dist/commands/page.d.ts.map +1 -0
  63. package/dist/commands/page.js +100 -0
  64. package/dist/commands/page.js.map +1 -0
  65. package/dist/completion/index.d.ts +37 -0
  66. package/dist/completion/index.d.ts.map +1 -0
  67. package/dist/completion/index.js +87 -0
  68. package/dist/completion/index.js.map +1 -0
  69. package/dist/config.d.ts +20 -0
  70. package/dist/config.d.ts.map +1 -0
  71. package/dist/config.js +61 -0
  72. package/dist/config.js.map +1 -0
  73. package/dist/credentials.d.ts +48 -0
  74. package/dist/credentials.d.ts.map +1 -0
  75. package/dist/credentials.js +120 -0
  76. package/dist/credentials.js.map +1 -0
  77. package/dist/deadline.d.ts +14 -0
  78. package/dist/deadline.d.ts.map +1 -0
  79. package/dist/deadline.js +88 -0
  80. package/dist/deadline.js.map +1 -0
  81. package/dist/dev/bin.d.ts +3 -0
  82. package/dist/dev/bin.d.ts.map +1 -0
  83. package/dist/dev/bin.js +8 -0
  84. package/dist/dev/bin.js.map +1 -0
  85. package/dist/dev/main.d.ts +7 -0
  86. package/dist/dev/main.d.ts.map +1 -0
  87. package/dist/dev/main.js +149 -0
  88. package/dist/dev/main.js.map +1 -0
  89. package/dist/dev/next-version.d.ts +11 -0
  90. package/dist/dev/next-version.d.ts.map +1 -0
  91. package/dist/dev/next-version.js +33 -0
  92. package/dist/dev/next-version.js.map +1 -0
  93. package/dist/dev/slow-tests.d.ts +14 -0
  94. package/dist/dev/slow-tests.d.ts.map +1 -0
  95. package/dist/dev/slow-tests.js +17 -0
  96. package/dist/dev/slow-tests.js.map +1 -0
  97. package/dist/dev/test-matrix.d.ts +35 -0
  98. package/dist/dev/test-matrix.d.ts.map +1 -0
  99. package/dist/dev/test-matrix.js +93 -0
  100. package/dist/dev/test-matrix.js.map +1 -0
  101. package/dist/errors.d.ts +34 -0
  102. package/dist/errors.d.ts.map +1 -0
  103. package/dist/errors.js +36 -0
  104. package/dist/errors.js.map +1 -0
  105. package/dist/executable.d.ts +3 -0
  106. package/dist/executable.d.ts.map +1 -0
  107. package/dist/executable.js +41 -0
  108. package/dist/executable.js.map +1 -0
  109. package/dist/exit-codes.d.ts +11 -0
  110. package/dist/exit-codes.d.ts.map +1 -0
  111. package/dist/exit-codes.js +25 -0
  112. package/dist/exit-codes.js.map +1 -0
  113. package/dist/http/index.d.ts +20 -0
  114. package/dist/http/index.d.ts.map +1 -0
  115. package/dist/http/index.js +46 -0
  116. package/dist/http/index.js.map +1 -0
  117. package/dist/index.d.ts +20 -0
  118. package/dist/index.d.ts.map +1 -0
  119. package/dist/index.js +19 -0
  120. package/dist/index.js.map +1 -0
  121. package/dist/keyring.d.ts +27 -0
  122. package/dist/keyring.d.ts.map +1 -0
  123. package/dist/keyring.js +45 -0
  124. package/dist/keyring.js.map +1 -0
  125. package/dist/legacy-paths.d.ts +33 -0
  126. package/dist/legacy-paths.d.ts.map +1 -0
  127. package/dist/legacy-paths.js +128 -0
  128. package/dist/legacy-paths.js.map +1 -0
  129. package/dist/logger.d.ts +12 -0
  130. package/dist/logger.d.ts.map +1 -0
  131. package/dist/logger.js +7 -0
  132. package/dist/logger.js.map +1 -0
  133. package/dist/logging.d.ts +31 -0
  134. package/dist/logging.d.ts.map +1 -0
  135. package/dist/logging.js +58 -0
  136. package/dist/logging.js.map +1 -0
  137. package/dist/mcp/index.d.ts +32 -0
  138. package/dist/mcp/index.d.ts.map +1 -0
  139. package/dist/mcp/index.js +113 -0
  140. package/dist/mcp/index.js.map +1 -0
  141. package/dist/output-buffer.d.ts +16 -0
  142. package/dist/output-buffer.d.ts.map +1 -0
  143. package/dist/output-buffer.js +69 -0
  144. package/dist/output-buffer.js.map +1 -0
  145. package/dist/paths.d.ts +35 -0
  146. package/dist/paths.d.ts.map +1 -0
  147. package/dist/paths.js +45 -0
  148. package/dist/paths.js.map +1 -0
  149. package/dist/pretty.d.ts +12 -0
  150. package/dist/pretty.d.ts.map +1 -0
  151. package/dist/pretty.js +83 -0
  152. package/dist/pretty.js.map +1 -0
  153. package/dist/release/index.d.ts +38 -0
  154. package/dist/release/index.d.ts.map +1 -0
  155. package/dist/release/index.js +91 -0
  156. package/dist/release/index.js.map +1 -0
  157. package/dist/release/markdown.d.ts +36 -0
  158. package/dist/release/markdown.d.ts.map +1 -0
  159. package/dist/release/markdown.js +153 -0
  160. package/dist/release/markdown.js.map +1 -0
  161. package/dist/release/structure.d.ts +16 -0
  162. package/dist/release/structure.d.ts.map +1 -0
  163. package/dist/release/structure.js +74 -0
  164. package/dist/release/structure.js.map +1 -0
  165. package/dist/renderer.d.ts +34 -0
  166. package/dist/renderer.d.ts.map +1 -0
  167. package/dist/renderer.js +55 -0
  168. package/dist/renderer.js.map +1 -0
  169. package/dist/result-fields.d.ts +4 -0
  170. package/dist/result-fields.d.ts.map +1 -0
  171. package/dist/result-fields.js +56 -0
  172. package/dist/result-fields.js.map +1 -0
  173. package/dist/retry.d.ts +27 -0
  174. package/dist/retry.d.ts.map +1 -0
  175. package/dist/retry.js +26 -0
  176. package/dist/retry.js.map +1 -0
  177. package/dist/sanitize.d.ts +25 -0
  178. package/dist/sanitize.d.ts.map +1 -0
  179. package/dist/sanitize.js +52 -0
  180. package/dist/sanitize.js.map +1 -0
  181. package/dist/skill/index.d.ts +78 -0
  182. package/dist/skill/index.d.ts.map +1 -0
  183. package/dist/skill/index.js +190 -0
  184. package/dist/skill/index.js.map +1 -0
  185. package/dist/streams.d.ts +24 -0
  186. package/dist/streams.d.ts.map +1 -0
  187. package/dist/streams.js +26 -0
  188. package/dist/streams.js.map +1 -0
  189. package/dist/testing/index.d.ts +24 -0
  190. package/dist/testing/index.d.ts.map +1 -0
  191. package/dist/testing/index.js +29 -0
  192. package/dist/testing/index.js.map +1 -0
  193. package/dist/time.d.ts +21 -0
  194. package/dist/time.d.ts.map +1 -0
  195. package/dist/time.js +19 -0
  196. package/dist/time.js.map +1 -0
  197. package/dist/update/index.d.ts +76 -0
  198. package/dist/update/index.d.ts.map +1 -0
  199. package/dist/update/index.js +160 -0
  200. package/dist/update/index.js.map +1 -0
  201. package/package.json +126 -3
package/LICENSE ADDED
@@ -0,0 +1,204 @@
1
+ Copyright (c) 2026 Viacheslav Ptsarev
2
+
3
+
4
+ Apache License
5
+ Version 2.0, January 2004
6
+ http://www.apache.org/licenses/
7
+
8
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
9
+
10
+ 1. Definitions.
11
+
12
+ "License" shall mean the terms and conditions for use, reproduction,
13
+ and distribution as defined by Sections 1 through 9 of this document.
14
+
15
+ "Licensor" shall mean the copyright owner or entity authorized by
16
+ the copyright owner that is granting the License.
17
+
18
+ "Legal Entity" shall mean the union of the acting entity and all
19
+ other entities that control, are controlled by, or are under common
20
+ control with that entity. For the purposes of this definition,
21
+ "control" means (i) the power, direct or indirect, to cause the
22
+ direction or management of such entity, whether by contract or
23
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
24
+ outstanding shares, or (iii) beneficial ownership of such entity.
25
+
26
+ "You" (or "Your") shall mean an individual or Legal Entity
27
+ exercising permissions granted by this License.
28
+
29
+ "Source" form shall mean the preferred form for making modifications,
30
+ including but not limited to software source code, documentation
31
+ source, and configuration files.
32
+
33
+ "Object" form shall mean any form resulting from mechanical
34
+ transformation or translation of a Source form, including but
35
+ not limited to compiled object code, generated documentation,
36
+ and conversions to other media types.
37
+
38
+ "Work" shall mean the work of authorship, whether in Source or
39
+ Object form, made available under the License, as indicated by a
40
+ copyright notice that is included in or attached to the work
41
+ (an example is provided in the Appendix below).
42
+
43
+ "Derivative Works" shall mean any work, whether in Source or Object
44
+ form, that is based on (or derived from) the Work and for which the
45
+ editorial revisions, annotations, elaborations, or other modifications
46
+ represent, as a whole, an original work of authorship. For the purposes
47
+ of this License, Derivative Works shall not include works that remain
48
+ separable from, or merely link (or bind by name) to the interfaces of,
49
+ the Work and Derivative Works thereof.
50
+
51
+ "Contribution" shall mean any work of authorship, including
52
+ the original version of the Work and any modifications or additions
53
+ to that Work or Derivative Works thereof, that is intentionally
54
+ submitted to Licensor for inclusion in the Work by the copyright owner
55
+ or by an individual or Legal Entity authorized to submit on behalf of
56
+ the copyright owner. For the purposes of this definition, "submitted"
57
+ means any form of electronic, verbal, or written communication sent
58
+ to the Licensor or its representatives, including but not limited to
59
+ communication on electronic mailing lists, source code control systems,
60
+ and issue tracking systems that are managed by, or on behalf of, the
61
+ Licensor for the purpose of discussing and improving the Work, but
62
+ excluding communication that is conspicuously marked or otherwise
63
+ designated in writing by the copyright owner as "Not a Contribution."
64
+
65
+ "Contributor" shall mean Licensor and any individual or Legal Entity
66
+ on behalf of whom a Contribution has been received by Licensor and
67
+ subsequently incorporated within the Work.
68
+
69
+ 2. Grant of Copyright License. Subject to the terms and conditions of
70
+ this License, each Contributor hereby grants to You a perpetual,
71
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
72
+ copyright license to reproduce, prepare Derivative Works of,
73
+ publicly display, publicly perform, sublicense, and distribute the
74
+ Work and such Derivative Works in Source or Object form.
75
+
76
+ 3. Grant of Patent License. Subject to the terms and conditions of
77
+ this License, each Contributor hereby grants to You a perpetual,
78
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
79
+ (except as stated in this section) patent license to make, have made,
80
+ use, offer to sell, sell, import, and otherwise transfer the Work,
81
+ where such license applies only to those patent claims licensable
82
+ by such Contributor that are necessarily infringed by their
83
+ Contribution(s) alone or by combination of their Contribution(s)
84
+ with the Work to which such Contribution(s) was submitted. If You
85
+ institute patent litigation against any entity (including a
86
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
87
+ or a Contribution incorporated within the Work constitutes direct
88
+ or contributory patent infringement, then any patent licenses
89
+ granted to You under this License for that Work shall terminate
90
+ as of the date such litigation is filed.
91
+
92
+ 4. Redistribution. You may reproduce and distribute copies of the
93
+ Work or Derivative Works thereof in any medium, with or without
94
+ modifications, and in Source or Object form, provided that You
95
+ meet the following conditions:
96
+
97
+ (a) You must give any other recipients of the Work or
98
+ Derivative Works a copy of this License; and
99
+
100
+ (b) You must cause any modified files to carry prominent notices
101
+ stating that You changed the files; and
102
+
103
+ (c) You must retain, in the Source form of any Derivative Works
104
+ that You distribute, all copyright, patent, trademark, and
105
+ attribution notices from the Source form of the Work,
106
+ excluding those notices that do not pertain to any part of
107
+ the Derivative Works; and
108
+
109
+ (d) If the Work includes a "NOTICE" text file as part of its
110
+ distribution, then any Derivative Works that You distribute must
111
+ include a readable copy of the attribution notices contained
112
+ within such NOTICE file, excluding those notices that do not
113
+ pertain to any part of the Derivative Works, in at least one
114
+ of the following places: within a NOTICE text file distributed
115
+ as part of the Derivative Works; within the Source form or
116
+ documentation, if provided along with the Derivative Works; or,
117
+ within a display generated by the Derivative Works, if and
118
+ wherever such third-party notices normally appear. The contents
119
+ of the NOTICE file are for informational purposes only and
120
+ do not modify the License. You may add Your own attribution
121
+ notices within Derivative Works that You distribute, alongside
122
+ or as an addendum to the NOTICE text from the Work, provided
123
+ that such additional attribution notices cannot be construed
124
+ as modifying the License.
125
+
126
+ You may add Your own copyright statement to Your modifications and
127
+ may provide additional or different license terms and conditions
128
+ for use, reproduction, or distribution of Your modifications, or
129
+ for any such Derivative Works as a whole, provided Your use,
130
+ reproduction, and distribution of the Work otherwise complies with
131
+ the conditions stated in this License.
132
+
133
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
134
+ any Contribution intentionally submitted for inclusion in the Work
135
+ by You to the Licensor shall be under the terms and conditions of
136
+ this License, without any additional terms or conditions.
137
+ Notwithstanding the above, nothing herein shall supersede or modify
138
+ the terms of any separate license agreement you may have executed
139
+ with Licensor regarding such Contributions.
140
+
141
+ 6. Trademarks. This License does not grant permission to use the trade
142
+ names, trademarks, service marks, or product names of the Licensor,
143
+ except as required for reasonable and customary use in describing the
144
+ origin of the Work and reproducing the content of the NOTICE file.
145
+
146
+ 7. Disclaimer of Warranty. Unless required by applicable law or
147
+ agreed to in writing, Licensor provides the Work (and each
148
+ Contributor provides its Contributions) on an "AS IS" BASIS,
149
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
150
+ implied, including, without limitation, any warranties or conditions
151
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
152
+ PARTICULAR PURPOSE. You are solely responsible for determining the
153
+ appropriateness of using or redistributing the Work and assume any
154
+ risks associated with Your exercise of permissions under this License.
155
+
156
+ 8. Limitation of Liability. In no event and under no legal theory,
157
+ whether in tort (including negligence), contract, or otherwise,
158
+ unless required by applicable law (such as deliberate and grossly
159
+ negligent acts) or agreed to in writing, shall any Contributor be
160
+ liable to You for damages, including any direct, indirect, special,
161
+ incidental, or consequential damages of any character arising as a
162
+ result of this License or out of the use or inability to use the
163
+ Work (including but not limited to damages for loss of goodwill,
164
+ work stoppage, computer failure or malfunction, or any and all
165
+ other commercial damages or losses), even if such Contributor
166
+ has been advised of the possibility of such damages.
167
+
168
+ 9. Accepting Warranty or Additional Liability. While redistributing
169
+ the Work or Derivative Works thereof, You may choose to offer,
170
+ and charge a fee for, acceptance of support, warranty, indemnity,
171
+ or other liability obligations and/or rights consistent with this
172
+ License. However, in accepting such obligations, You may act only
173
+ on Your own behalf and on Your sole responsibility, not on behalf
174
+ of any other Contributor, and only if You agree to indemnify,
175
+ defend, and hold each Contributor harmless for any liability
176
+ incurred by, or claims asserted against, such Contributor by reason
177
+ of your accepting any such warranty or additional liability.
178
+
179
+ END OF TERMS AND CONDITIONS
180
+
181
+ APPENDIX: How to apply the Apache License to your work.
182
+
183
+ To apply the Apache License to your work, attach the following
184
+ boilerplate notice, with the fields enclosed by brackets "[]"
185
+ replaced with your own identifying information. (Don't include
186
+ the brackets!) The text should be enclosed in the appropriate
187
+ comment syntax for the file format. We also recommend that a
188
+ file or class name and description of purpose be included on the
189
+ same "printed page" as the copyright notice for easier
190
+ identification within third-party archives.
191
+
192
+ Copyright [yyyy] [name of copyright owner]
193
+
194
+ Licensed under the Apache License, Version 2.0 (the "License");
195
+ you may not use this file except in compliance with the License.
196
+ You may obtain a copy of the License at
197
+
198
+ http://www.apache.org/licenses/LICENSE-2.0
199
+
200
+ Unless required by applicable law or agreed to in writing, software
201
+ distributed under the License is distributed on an "AS IS" BASIS,
202
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
203
+ See the License for the specific language governing permissions and
204
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,377 @@
1
- # Temporary Holding Version
1
+ <img src="https://raw.githubusercontent.com/WireCatLabs/cli-base/main/docs/images/social-preview.png" alt="The foundation for agent-ready CLIs: output for people and machines, stable exit codes, keyring, testable clocks" width="100%">
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ # @wirecat/cli-base
4
+
5
+ The parts every command line tool needs and nobody enjoys writing twice: the two output streams,
6
+ a renderer for people and for machines, a closed error model with stable exit codes, the OS
7
+ keyring behind a testable seam, and injectable clocks.
8
+
9
+ Extracted from [`brazecli`](https://github.com/leemour/brazecli), where each piece earned its
10
+ shape, and shared with [`max-cli`](https://github.com/WireCatLabs/max-cli).
11
+
12
+ Published on npm and used by `max-cli`, `cli-messaging`, `tg-cli` and `brazecli`. What changed in
13
+ each version is in [`CHANGELOG.md`](CHANGELOG.md); how the package is put together and released is in
14
+ [`docs/dev/`](docs/dev/ARCHITECTURE.md).
15
+
16
+ ## The rule this package exists to keep
17
+
18
+ **In a machine mode, stdout carries data and nothing else.** No spinner, no `✓`, no warning, no
19
+ ANSI. Diagnostics go to stderr, in every mode including the pretty one. That is the contract a
20
+ script or an agent depends on, and `captureStreams` exists so a test can prove nothing leaked
21
+ across.
22
+
23
+ ```ts
24
+ import { captureStreams, createRenderer } from "@wirecat/cli-base"
25
+
26
+ const streams = captureStreams()
27
+ createRenderer({ format: "json", color: false, streams }).result({ chats: 2 })
28
+
29
+ streams.stdout // ['{"chats":2}']
30
+ streams.stderr // []
31
+ ```
32
+
33
+ ## What is in it
34
+
35
+ | | |
36
+ |---|---|
37
+ | `streams` | the stdout/stderr split, and the capture used to test it |
38
+ | `renderer` · `pretty` | `pretty` / `json` / `jsonl`; tables for lists, labelled lines for objects; `quiet` keeps only failures on stderr |
39
+ | `errors` · `exit-codes` | 14 closed error codes, one exit number each, so a script can branch on `$?` |
40
+ | `keyring` | `KeyringStore` with the system, memory and deliberately-broken implementations |
41
+ | `fieldsOf` · `projectFields` | validated field selection preserving list metadata and operation identifiers |
42
+ | `createOutputBuffer` | bounded UTF-8 output held until successful completion and resource cleanup |
43
+ | `createDeadline` | cooperative command cancellation with injected sleep and a parent abort signal |
44
+ | `time` | monotonic and wall clocks, and the one sleep that both timeouts and backoff use |
45
+ | `logger` | the four-method interface a host adapts Pino to — this package logs nothing itself |
46
+ | `paths` | config, state and cache in the XDG layout on Linux and macOS (`~/.config`, `~/.local/share`, `~/.cache`) and the `AppData` one on Windows, each overridable by environment variable; `migrateLegacyMacPaths` moves an older release's `~/Library` folders once |
47
+ | `config` | JSON config loading that names the bad field, and an atomic write that locks the directory down |
48
+ | `credentials` | environment → keyring → file, warning once and falling through when the keyring refuses |
49
+ | `logging` | a Pino adapter writing JSON lines with secrets redacted by field name; a file that cannot be written is reported to `onError`, never thrown |
50
+ | `retry` | full-jitter backoff, and the distinction between "no answer came" and "safe to repeat" |
51
+ | `/testing` | `captureStreams`, `memoryKeyring`, `brokenKeyring`, `fakeClock` |
52
+ | `/commands` | the command registry: `describeProgram`, `annotate`, `flatten` — see below |
53
+ | `/completion` | shell completion over the registry: `suggest`, `formatSuggestions` — see below |
54
+ | `/update` | keeping an install current: `installerOf`, `updateCommand`, `latestVersion`, `mayNotify`, `updateNotice`, `runUpdate` — see below |
55
+ | `/codegen` | build time: an official API description → types, Valibot schemas, an operation manifest and a coverage page — see below |
56
+ | `/release` | release time: `releaseCheck` and the checks it runs — changelog shape, links, package contents, version in step — see below |
57
+ | `/skill` | the CLI's SKILL.md for coding agents: `skillCommand` (`show`, `install`), `skillHint`, `skillResource` — see below |
58
+ | `/mcp` | local stdio MCP setup for Codex and Claude Code, plus a read-only handshake and tool-list probe |
59
+
60
+ **Nothing in the root export is HTTP.** Status classification, `Retry-After` parsing and the fetch
61
+ seam live in `@wirecat/cli-base/http`, so a CLI that speaks a socket never depends on a stack it
62
+ does not call:
63
+
64
+ ```ts
65
+ import { providerWaitMs, statusToCode } from "@wirecat/cli-base/http"
66
+ ```
67
+
68
+ **Portable command control stays independent of provider and store lifetimes.**
69
+ `fieldsOf("id,speaker.id")` parses up to 128 field paths; `projectFields(value, paths)` selects data
70
+ from objects or list items while preserving the list envelope and `operationId` / `sendId`.
71
+ `items.id` also works for bare objects and JSONL items. Unknown fields are omitted; parent selections
72
+ win over their children. Unsafe prototype paths are refused, including when paths are passed directly.
73
+
74
+ `createOutputBuffer({ maxOutputBytes })` retains raw output chunks until `flush(write)` or `discard()`.
75
+ Its default limit is 4 MiB; zero disables the limit. It counts actual UTF-8 bytes, including delimiters
76
+ the caller passes, and adds no newlines. Use a new buffer for each command and flush only after resource
77
+ cleanup succeeds; discard on failure. A flush consumes the buffer even when its writer throws.
78
+ The `bytes` property reports the cumulative accepted byte count. A writer failure can leave partial
79
+ output; buffering only guarantees no output before flushing.
80
+
81
+ Optional `{ fields, format: "json" | "jsonl" }` projects before counting bytes. With projection,
82
+ each `data(text)` must contain a complete JSON value or complete JSONL lines; fragments fail before
83
+ buffering. Without projection, arbitrary text chunks work. Hosts can instead project values before
84
+ rendering and buffer the renderer's raw text. For core renderers, pass the line delimiter explicitly
85
+ when adapting `Streams.data`: `data: (text) => buffer.data(text + "\n")`.
86
+
87
+ `createDeadline({ timeoutMs, signal, sleep })` supplies a command signal and `race(body)`. An omitted
88
+ timeout creates no timer; zero aborts synchronously without calling sleep, and the maximum is 2147483647 milliseconds.
89
+ Pass its signal to every cancellable operation and check it before writes. On timeout or parent
90
+ cancellation, `race` waits for the body to settle before rejecting, so a caller can safely close
91
+ resources afterwards. An operation ignoring its signal can delay completion; this helper never
92
+ abandons it in the background. A body's more precise `outcome_unknown` error survives interruption.
93
+ Call `dispose()` in `finally` to remove the timer and parent listener. There are no process signal
94
+ handlers, retries, automatic resource cleanup or HTTP behavior in these helpers.
95
+
96
+ **The command registry is `@wirecat/cli-base/commands`** — the whole command tree as data, like
97
+ `rails routes`, for an agent to read instead of `--help` and for generated documentation. It walks
98
+ the live [Commander](https://github.com/tj/commander.js) tree, so a command built in a loop from a
99
+ catalog appears exactly like a handwritten one; `annotate` adds what the tree cannot say. Commander
100
+ is a type here, not a runtime dependency — an optional peer, 15 or newer.
101
+
102
+ ```ts
103
+ import { annotate, describeProgram } from "@wirecat/cli-base/commands"
104
+
105
+ annotate(program.command("send"), { mutates: true, examples: ["max messages send 42 hi"] })
106
+ annotate(generated, { origin: "generated", operationId: "campaigns.list" })
107
+
108
+ describeProgram(program) // [{ path: ["send"], usage, origin, mutates, options: [...], commands: [...] }]
109
+ ```
110
+
111
+ Each option says whether it `takesValue` and, separately, whether it is `mandatory` — not
112
+ Commander's `required`, which means "takes a value when given" — plus its choices, default,
113
+ environment variable, the options it `conflicts` with and the values it `implies`.
114
+
115
+ **Shell completion is `@wirecat/cli-base/completion`**, built on the registry. `suggest` takes the
116
+ words typed so far and answers what may come next: a command, an action, an option, one of its
117
+ values, or an argument's values from a source the CLI hands in — a local cache, never the network,
118
+ because a shell calls it on every Tab. `formatSuggestions` writes the answer in the protocol of the
119
+ shell scripts [`@bomb.sh/tab`](https://github.com/bombshell-dev/tab) generates, so the CLI prints
120
+ those scripts with tab and answers `<cli> complete -- <words>` with this; cli-base itself does not
121
+ depend on tab.
122
+
123
+ ```ts
124
+ import { formatSuggestions, suggest } from "@wirecat/cli-base/completion"
125
+
126
+ const words = argv.slice(argv.indexOf("--") + 1)
127
+ streams.data(formatSuggestions(suggest({ commands, globalOptions, words, sources: { arguments: { chat: chatNames } } })))
128
+ ```
129
+
130
+ **Two traps worth knowing before you use the credential store.** The OS keyring is global: an entry
131
+ is addressed by service and account and knows nothing about which config directory asked for it, so
132
+ a throwaway config directory silently overwrites the real secret unless you pass `isolated: true`.
133
+ And a secret should never be handed to a logger in the first place — redaction by field name is the
134
+ second line of defence, not the first.
135
+
136
+ **Everything the environment knows can be passed in**: the clock, the sleep, the keyring, `env`,
137
+ `fetch` and the streams. The real ones are only defaults — `Credentials` without a `keyring` uses the
138
+ system keychain, `resolvePaths` without `env` reads `process.env`. Passing them is what makes a
139
+ timeout test finish instantly and a keyring test incapable of reaching a real keychain.
140
+
141
+ **Generating an API catalog is `@wirecat/cli-base/codegen`**, a build-time tool. It reads a
142
+ format-neutral `ApiModel` — operations with a transport binding (`http` method and path, or `rpc`
143
+ name), an `effect` (`read`, `write`, `destructive`) and how far the source can be trusted
144
+ (`contract`, `example`, `inferred`, `override`) — and writes committed files. It parses no file
145
+ format: the adapter from OpenAPI, Postman or anything else lives in the CLI that has that source,
146
+ so this adds no dependency. Generation stops, naming the problem, when two operations collide, an
147
+ operation is not classified as a read or a write, an override matches nothing, a reference points
148
+ nowhere or a construct cannot be expressed; it never drops an operation or falls back to `any`.
149
+
150
+ ```ts
151
+ import { generate, manifestGenerator, typesGenerator, valibotGenerator, writeArtifacts } from "@wirecat/cli-base/codegen"
152
+
153
+ const artifacts = generate(model, [typesGenerator({ path }), valibotGenerator({ path, typesImport }), manifestGenerator({ path })], {
154
+ overrides: { answerOnCallback: { effect: "write", reason: "a POST that edits a message" } },
155
+ banner: ["Source: spec/bot/schema.yaml", "Run: pnpm bot:generate"],
156
+ })
157
+ const stale = writeArtifacts(artifacts, { root, check: process.argv.includes("--check") })
158
+ ```
159
+
160
+ The generated schemas import `@wirecat/cli-base/codegen/runtime` at run time — a few number
161
+ helpers, not the generator. Numbers are expected from a lossless JSON parser (`lossless-json`): a
162
+ 64-bit integer comes out as its exact decimal string, and any other integer that does not fit a JS
163
+ number fails instead of rounding. Objects are loose, so a field the API added later passes through.
164
+ Unions retain every alternative, including recursive references and Boolean literals.
165
+ `definitionsGenerator` emits the same schema nodes for runtime input traversal; RPC parameters can be in the JSON body.
166
+ Enums and discriminated unions are **strict**: a value or subtype the snapshot does not know fails,
167
+ so decode a live stream (updates, webhooks) only where that is what you want.
168
+
169
+ **The schemas decode; they do not encode.** Their output carries an `int64` as a string, so sending
170
+ it back would put a string where the API expects a number. Validate a request with the schema, then
171
+ send the original lossless value.
172
+
173
+ **Keeping an install current is `@wirecat/cli-base/update`.** `installerOf(realpath(script))` says
174
+ which package manager put the CLI there — pnpm, npm or bun, measured on real installs — and
175
+ `updateCommand` gives the argv that updates it; a checkout or `npx` gets none. `latestVersion` asks
176
+ npm with a timeout and answers `undefined` on any failure. `mayNotify` says whether a person is at a
177
+ terminal to be told: never in JSON, a pipe, `--quiet`, `CI` or with `NO_UPDATE_NOTIFIER`.
178
+ `updateNotice` is the whole daily line: it stays silent when `update` or `complete` is anywhere on
179
+ the command line, asks npm at most once a day through a state file the CLI names, and returns the
180
+ sentence or `undefined` — it never throws. `runUpdate` starts the package manager with its output on
181
+ stderr (`spawnPlan` is the Windows `.cmd` rule). Nothing here updates or prints by itself — a CLI
182
+ holding somebody's credentials must not change itself unasked.
183
+
184
+ **A CLI's guide for coding agents is `@wirecat/cli-base/skill`.** `skillCommand(app, skillUrl,
185
+ environment)` is `<cli> skill show` — SKILL.md on stdout, even into a pipe, or `{ name, content }`
186
+ with `--json` — and `<cli> skill install [--for claude|agents|all]`, which writes it to
187
+ `~/.claude/skills/<appName>/` and `~/.agents/skills/<appName>/` with the CLI's version as
188
+ `metadata.version` in the frontmatter, refusing a file whose `name` is not `<appName>`. `environment` is the host's own renderer, streams and `env` for that invocation.
189
+ `skillHint` is one line, or `undefined`, for an agent (`AI_AGENT` or `CLAUDECODE` set) with no copy
190
+ installed or an older one, at most once a day, through the same state file as `updateNotice`; the
191
+ host prints it on stderr. `skillResource` is what an MCP server registers to serve the file as
192
+ `<command>://skill`, plus a line for its `instructions` — the SDK stays the host's.
193
+
194
+ **The release checks are `@wirecat/cli-base/release`** — everything about a release that a program
195
+ can decide. A check is `{ name, run }`, and `run` returns the problems it found, one line each; an
196
+ empty list is a pass. `releaseCheck(checks, { version, log })` runs them all, even after a failure,
197
+ prints `ok` or `FAIL` per check and returns how many failed — the caller exits. The checks every CLI
198
+ shares: `command(root, "pnpm", "lint")` for anything that passes by exiting 0, `notOnNpm`,
199
+ `packContents` against a list of what may ship, `changelogProblems` for the fixed headings and the
200
+ dated top section, `docsProblems` for dead links and anchors and the rules of the pages a user reads,
201
+ and `versionScript` — the whole of a `version:check` / `version:sync` script. Each CLI passes its
202
+ own headings, id prefixes and pages; the checks that belong to one messenger stay in that CLI.
203
+
204
+ ```ts
205
+ import { command, notOnNpm, packageVersion, releaseCheck } from "@wirecat/cli-base/release"
206
+
207
+ const version = packageVersion(root)
208
+ const failed = releaseCheck(
209
+ [
210
+ { name: "version not on npm", run: notOnNpm(root, "@wirecat/tg-cli", version) },
211
+ { name: "lint", run: command(root, "pnpm", "lint") },
212
+ ],
213
+ { version, log: console.log },
214
+ )
215
+ process.exit(failed === 0 ? 0 : 1)
216
+ ```
217
+
218
+ ## Where secrets actually go, per platform
219
+
220
+ The keyring is real on every desktop and absent on most servers, so the fallback is not an edge
221
+ case — it is the normal path in CI and containers. Checked against `@napi-rs/keyring` 2.1.0 on
222
+ 2026-09-19.
223
+
224
+ | Platform | Backing store | Needs installing |
225
+ |---|---|---|
226
+ | macOS | Keychain, via the Security framework | nothing — part of the OS |
227
+ | Windows | Credential Manager | nothing — part of the OS |
228
+ | Linux desktop (GNOME, KDE) | Secret Service over D-Bus — `gnome-keyring`, `kwallet` | nothing on a normal desktop; the keyring must be **unlocked** |
229
+ | Linux headless, container, WSL, CI | usually **nothing** — no session bus, no secrets daemon | falls back to a `0600` file, with one warning on stderr |
230
+ | FreeBSD | Secret Service, same as Linux | same |
231
+
232
+ **No compiler is involved.** The package ships prebuilt binaries for twelve platform triples —
233
+ macOS arm64/x64, Windows x64/ia32/arm64, Linux x64 and arm64 in both glibc and musl, armv7,
234
+ riscv64, FreeBSD x64 — so there is no Rust toolchain and no node-gyp on any mainstream target.
235
+ The Linux binary links only against libc: it speaks D-Bus itself rather than through libsecret,
236
+ so *libsecret is not a requirement* — a running Secret Service provider is.
237
+
238
+ Two consequences worth designing for rather than discovering:
239
+
240
+ - **`auto` is the right default and `file` must stay available.** `credentialStorage: "file"` skips
241
+ the keyring entirely, which is what a container wants and what a locked keyring makes necessary.
242
+ - **A locked Linux keyring can block on a prompt** rather than failing. That is the one case the
243
+ fallback does not rescue, and a CLI that hangs looks broken rather than locked.
244
+
245
+ ## Both runtimes
246
+
247
+ Node 22+ and Bun, and the Bun half is executed rather than assumed:
248
+
249
+ ```sh
250
+ pnpm test # vitest, Node
251
+ pnpm smoke:bun # the same exports, actually run under Bun
252
+ pnpm lint
253
+ pnpm typecheck
254
+ pnpm build
255
+ ```
256
+
257
+ The rest of the checks, and what each is for, are in [`docs/dev/TESTING.md`](docs/dev/TESTING.md).
258
+
259
+ ## Shared tooling
260
+
261
+ The configuration, development scripts and CI that every CLI on cli-base used to copy. A repository
262
+ takes each piece on its own.
263
+
264
+ **TypeScript.** Compiler options only; paths and file lists stay in the repository, because `tsc`
265
+ resolves them against the file that declares them.
266
+
267
+ ```jsonc
268
+ // tsconfig.json
269
+ {
270
+ "extends": "@wirecat/cli-base/tsconfig.base.json",
271
+ "compilerOptions": { "rootDir": "src", "outDir": "dist" },
272
+ "include": ["src/**/*.ts"],
273
+ "exclude": ["src/**/*.test.ts"]
274
+ }
275
+ // tsconfig.test.json — checks every file under src/, tests included, without emitting
276
+ { "extends": ["./tsconfig.json", "@wirecat/cli-base/tsconfig.test.json"] }
277
+ // tsconfig.scripts.json — checks scripts/
278
+ { "extends": ["./tsconfig.json", "@wirecat/cli-base/tsconfig.scripts.json"] }
279
+ ```
280
+
281
+ **Biome.** Formatter, linter and the rule that lets `scripts/` print. Your `files.includes` and
282
+ your own `overrides` (import boundaries) stay in your file; Biome adds them to the shared ones.
283
+ Write the specifier without `.json`: Biome reads anything ending in `.json` as a relative path.
284
+
285
+ ```json
286
+ { "extends": ["@wirecat/cli-base/biome"], "files": { "includes": ["**", "!**/dist", "!**/node_modules", "!pnpm-lock.yaml"] } }
287
+ ```
288
+
289
+ **lefthook.** Biome and gitleaks on staged files before a commit, `pnpm typecheck` before a push.
290
+ An extended file **overrides** your `lefthook.yml`; to change a shared hook, use `lefthook-local.yml`.
291
+
292
+ ```yaml
293
+ extends:
294
+ - node_modules/@wirecat/cli-base/config/lefthook.yml
295
+ ```
296
+
297
+ **`cli-dev`.** Installed with the package; `pnpm exec cli-dev help` lists the commands.
298
+
299
+ | Instead of | Run |
300
+ |---|---|
301
+ | `scripts/slow-tests.ts` | `cli-dev slow-tests [report] [count]` |
302
+ | `scripts/next-version.mjs` | `cli-dev next-version <wanted> <latest> <versions-json>` |
303
+ | `scripts/version.ts` | `cli-dev version [--sync] [--file src/version.ts]` |
304
+ | `scripts/docs-check.ts` | `cli-dev docs-check --rules scripts/release/checks.ts`, or `--ids CLI,MAX` with the English defaults |
305
+ | `scripts/test-matrix.ts` | `cli-dev test-matrix --program dist/program.js --untested scripts/test-matrix-untested.ts --name max [--check]` |
306
+
307
+ `--rules` names a module exporting `CHANGELOG` and `docsRules(root)`; `--program` one exporting
308
+ `createProgram`; `--untested` one exporting `UNTESTED`. A TypeScript module loads on Node 24 as it is.
309
+
310
+ **Docs.** Spelling, Markdown form and prose rules for the pages a user reads. The tools are your
311
+ own dev dependencies (`cspell`, `@cspell/dict-ru_ru`, `@cspell/dict-en-gb`, `rumdl`); the settings
312
+ and the shared word list are here. Code blocks and inline code are not spell-checked: commands and
313
+ options are checked against the program by the parity check.
314
+
315
+ ```jsonc
316
+ // cspell.json — the dictionaries resolve from your node_modules, so you import them yourself
317
+ {
318
+ "version": "0.2",
319
+ "import": ["@wirecat/cli-base/cspell", "@cspell/dict-en-gb/cspell-ext.json", "@cspell/dict-ru_ru/cspell-ext.json"],
320
+ "ignorePaths": ["docs/commands.md", "docs/dev/**", "CHANGELOG.md"],
321
+ "words": []
322
+ }
323
+ ```
324
+
325
+ ```sh
326
+ cspell --no-progress README.md "docs/*.md"
327
+ rumdl check --config node_modules/@wirecat/cli-base/config/rumdl.toml README.md docs/*.md
328
+ vale README.md docs/*.md # .vale.ini: StylesPath = node_modules/@wirecat/cli-base/config/vale
329
+ ```
330
+
331
+ `cli-dev docs-check --pages` adds the structure check: `docs/` against `docs/meta.json`, the
332
+ sidebar of [the docs portal](https://github.com/WireCatLabs/cli-docs/blob/main/docs/STRUCTURE.md).
333
+ Vale's styles are `CliDocs` (filler words, long sentences) and `Tg` (tg's tone: a Telegram client,
334
+ never "unofficial"); its rules warn rather than fail until they are tuned.
335
+
336
+ **CI.** Install, lint, typecheck, test with coverage, build, your extra checks, Bun, and a gitleaks
337
+ scan of the whole history. Jobs only your repository needs stay beside it in your `ci.yml`.
338
+
339
+ ```yaml
340
+ jobs:
341
+ ci:
342
+ uses: WireCatLabs/cli-base/.github/workflows/node-ci.yml@v<version>
343
+ with:
344
+ checks: |
345
+ pnpm docs:check
346
+ bun-run: pnpm build && pnpm smoke:bun # the default is pnpm smoke:bun
347
+ ```
348
+
349
+ Inputs: `node-version` (`"24"`), `checks` (shell lines run after the build), `bun` (`true`),
350
+ `bun-run`. The workflow is in the repository, not the package: pin a tag or a commit, not `main`.
351
+
352
+ ## Releasing
353
+
354
+ Raise `version` in `package.json` and date the `## Unreleased` section of
355
+ [`CHANGELOG.md`](CHANGELOG.md) as that version, through a pull request; merge it, then on `main`:
356
+
357
+ ```sh
358
+ bin/release
359
+ ```
360
+
361
+ It refuses a dirty tree, a branch other than `main` and a `main` that is not pushed. When npm already
362
+ has the version, or a higher one, it commits the next free version to `main` — the next minor for
363
+ `x.y.0`, the next patch otherwise — renames the changelog heading to match, and publishes that. Then it starts
364
+ [`release.yml`](.github/workflows/release.yml) and follows it. The workflow runs every check,
365
+ publishes through npm's [trusted publishing](https://docs.npmjs.com/trusted-publishers/) — no npm
366
+ token in GitHub, and npm attaches provenance — and tags `v<version>` only once npm shows the new version.
367
+
368
+ npm trusts the workflow **by file name**: the package's Trusted Publisher settings on npmjs.com name
369
+ `WireCatLabs` / `cli-base` / `release.yml`. Rename the file and publishing stops until they are updated.
370
+
371
+ `bin/release --local` is the fallback: it runs the same checks here and publishes with the npm token
372
+ from the keyring (`secret-tool`, service `npm`, account `leemour`) without printing it. The token
373
+ must be allowed to write `@wirecat/cli-base`, not only `@wirecat/max-cli`.
374
+
375
+ ## Licence
376
+
377
+ [Apache License 2.0](LICENSE).
@@ -0,0 +1,56 @@
1
+ {
2
+ "vcs": {
3
+ "enabled": true,
4
+ "clientKind": "git",
5
+ "useIgnoreFile": true
6
+ },
7
+ "formatter": {
8
+ "enabled": true,
9
+ "indentStyle": "space",
10
+ "indentWidth": 2,
11
+ "lineWidth": 120
12
+ },
13
+ "javascript": {
14
+ "formatter": {
15
+ "quoteStyle": "double",
16
+ "semicolons": "asNeeded",
17
+ "trailingCommas": "all",
18
+ "arrowParentheses": "always"
19
+ }
20
+ },
21
+ "linter": {
22
+ "enabled": true,
23
+ "rules": {
24
+ "preset": "recommended",
25
+ "style": {
26
+ "useConst": "error",
27
+ "noNonNullAssertion": "error"
28
+ },
29
+ "correctness": {
30
+ "noUnusedImports": "error",
31
+ "noUnusedVariables": "error"
32
+ },
33
+ "suspicious": {
34
+ "noExplicitAny": "error",
35
+ "noConsole": {
36
+ "level": "error",
37
+ "options": {
38
+ "allow": ["error"]
39
+ }
40
+ }
41
+ }
42
+ }
43
+ },
44
+ "overrides": [
45
+ {
46
+ "includes": ["scripts/**"],
47
+ "linter": {
48
+ "rules": {
49
+ "suspicious": {
50
+ "noConsole": "off"
51
+ }
52
+ }
53
+ }
54
+ }
55
+ ]
56
+ }