agent-finance-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.
Files changed (48) hide show
  1. package/Cargo.lock +2632 -0
  2. package/Cargo.toml +31 -0
  3. package/LICENSE-APACHE +202 -0
  4. package/LICENSE-MIT +21 -0
  5. package/README.md +119 -0
  6. package/bin/agent-finance.js +27 -0
  7. package/npm/check-binary-links.js +50 -0
  8. package/npm/check-package.js +39 -0
  9. package/npm/create-platform-package.js +90 -0
  10. package/npm/platform.js +33 -0
  11. package/npm/postinstall.js +62 -0
  12. package/npm/resolve-binary.js +38 -0
  13. package/package.json +54 -0
  14. package/skills/core-full.md +74 -0
  15. package/skills/core.md +59 -0
  16. package/skills/futures.md +18 -0
  17. package/skills/history-indicators.md +42 -0
  18. package/skills/price.md +40 -0
  19. package/skills/providers.md +25 -0
  20. package/skills/research-data.md +34 -0
  21. package/src/app.rs +642 -0
  22. package/src/cache.rs +67 -0
  23. package/src/cli.rs +651 -0
  24. package/src/history.rs +150 -0
  25. package/src/http.rs +76 -0
  26. package/src/indicators.rs +82 -0
  27. package/src/lib.rs +15 -0
  28. package/src/main.rs +4 -0
  29. package/src/model.rs +347 -0
  30. package/src/output.rs +544 -0
  31. package/src/page_read.rs +443 -0
  32. package/src/price.rs +255 -0
  33. package/src/providers/binance_futures.rs +342 -0
  34. package/src/providers/capabilities.rs +322 -0
  35. package/src/providers/cnbc.rs +302 -0
  36. package/src/providers/mod.rs +117 -0
  37. package/src/providers/robinhood.rs +580 -0
  38. package/src/providers/sec_edgar.rs +399 -0
  39. package/src/providers/stooq/catalog.rs +159 -0
  40. package/src/providers/stooq.rs +904 -0
  41. package/src/providers/yahoo.rs +836 -0
  42. package/src/research/fetchers.rs +111 -0
  43. package/src/research/highlights.rs +345 -0
  44. package/src/research/mod.rs +943 -0
  45. package/src/research/tests.rs +42 -0
  46. package/src/skills.rs +58 -0
  47. package/src/stream.rs +356 -0
  48. package/src/time.rs +21 -0
package/Cargo.toml ADDED
@@ -0,0 +1,31 @@
1
+ [package]
2
+ name = "agent-finance-cli"
3
+ version = "0.1.0"
4
+ edition = "2024"
5
+ license = "MIT OR Apache-2.0"
6
+ repository = "https://github.com/M4n5ter/agent-finance-cli"
7
+ description = "AI Agent-first CLI for no-key financial market data and research context."
8
+
9
+ [[bin]]
10
+ name = "agent-finance"
11
+ path = "src/main.rs"
12
+
13
+ [dependencies]
14
+ anyhow = "1.0.102"
15
+ base64 = "0.22.1"
16
+ chrono = "0.4.45"
17
+ chrono-tz = "0.10.4"
18
+ clap = { version = "4.6.1", features = ["derive"] }
19
+ csv = "1.4.0"
20
+ futures-util = "0.3.32"
21
+ prost = "0.14.4"
22
+ rustls = { version = "0.23.40", default-features = false, features = ["ring", "std", "tls12"] }
23
+ serde = { version = "1.0.228", features = ["derive"] }
24
+ serde_json = "1.0.150"
25
+ tokio-tungstenite = { version = "0.29.0", features = ["rustls-tls-webpki-roots"] }
26
+ tokio = { version = "1.52.3", features = ["macros", "rt-multi-thread"] }
27
+ url = "2.5.8"
28
+ zip = { version = "8.6.0", default-features = false, features = ["deflate"] }
29
+ scraper = "0.27.0"
30
+ wreq = { version = "6.0.0-rc.29", default-features = false, features = ["cookies", "deflate", "gzip", "json", "socks", "system-proxy", "tokio-rt", "webpki-roots"] }
31
+ wreq-util = "3.0.0-rc.12"
package/LICENSE-APACHE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/LICENSE-MIT ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 M4n5ter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,119 @@
1
+ # agent-finance-cli
2
+
3
+ AI Agent-first CLI for no-key financial market data and research context.
4
+
5
+ `agent-finance` is designed for human-operated AI agents: the CLI can print its own task-specific skills, then provide current quotes, regular/pre/post/overnight session splits, OHLCV history, local indicators, proxy futures data, no-key research payloads, URL text extraction, provider capability notes, polling, and Yahoo WebSocket streams.
6
+
7
+ If you are an AI Agent, start here:
8
+
9
+ ```bash
10
+ agent-finance skills get core
11
+ agent-finance skills list
12
+ ```
13
+
14
+ ## Install
15
+
16
+ From npm:
17
+
18
+ ```bash
19
+ npm install -g agent-finance-cli
20
+ ```
21
+
22
+ The npm package installs a prebuilt binary for supported platforms. Rust is not required for the normal npm install path.
23
+
24
+ If no prebuilt package is available for the current platform, npm falls back to a local source build. That fallback requires Rust/Cargo plus the native toolchain needed by `wreq`/BoringSSL: CMake, Clang/Clang++, libclang, and binutils.
25
+
26
+ From GitHub:
27
+
28
+ ```bash
29
+ cargo install --git https://github.com/M4n5ter/agent-finance-cli
30
+ ```
31
+
32
+ From a checkout:
33
+
34
+ ```bash
35
+ cargo run --bin agent-finance -- skills get core
36
+ cargo run --bin agent-finance -- price CRDO
37
+ ```
38
+
39
+ Future distribution targets include crates.io and Homebrew.
40
+
41
+ ## Common Commands
42
+
43
+ ```bash
44
+ # Current observable price + regular-market basis.
45
+ agent-finance price CRDO
46
+ agent-finance price CRDO MRVL --json
47
+
48
+ # Precise regular/pre/post/overnight/provider split.
49
+ agent-finance sessions CRDO
50
+ agent-finance sessions LITE --proxy-symbol LITEUSDT
51
+
52
+ # History, indicators, futures/proxy data, and streams.
53
+ agent-finance history CRDO --range 1mo --interval 1d
54
+ agent-finance history CRDO --range 5d --interval 1m --session extended --adjustment raw --no-actions
55
+ agent-finance indicators CRDO MRVL --limit 120
56
+ agent-finance futures SPCXUSDT
57
+ agent-finance stream CRDO --messages 5
58
+ agent-finance watch CRDO --interval-seconds 15 --iterations 4
59
+
60
+ # No-key research and discovery.
61
+ agent-finance fundamentals CRDO
62
+ agent-finance fundamentals CRDO --provider sec-edgar
63
+ agent-finance analysis CRDO
64
+ agent-finance options CRDO --provider robinhood --count 80
65
+ agent-finance ownership CRDO
66
+ agent-finance events CRDO --provider sec-edgar
67
+ agent-finance news CRDO
68
+ agent-finance read-url "https://www.sec.gov/Archives/edgar/data/0001807794/000162828026014017/crdo-20260131.htm"
69
+ agent-finance search "optical interconnect"
70
+ agent-finance screen day_gainers
71
+ agent-finance providers
72
+ ```
73
+
74
+ ## Agent Skills
75
+
76
+ The CLI ships Markdown skills so an AI Agent can learn the exact command surface for the installed version:
77
+
78
+ ```bash
79
+ agent-finance skills list
80
+ agent-finance skills get core --full
81
+ agent-finance skills get price
82
+ agent-finance skills get research-data
83
+ agent-finance skills get providers
84
+ agent-finance skills get history-indicators
85
+ agent-finance skills get futures
86
+ ```
87
+
88
+ ## Data Source Rules
89
+
90
+ - `price SYMBOL` is the default answer to "what is it trading at now?" It returns the current observable price, session, regular-market basis, and local/UTC timestamps.
91
+ - `sessions SYMBOL` is for explicit regular/pre/post/overnight/provider comparisons.
92
+ - `history` defaults to adjusted prices and includes corporate actions unless disabled.
93
+ - `providers` is the source-of-truth capability matrix. Do not infer coverage from provider names.
94
+ - Binance futures / TradFi perps are derivative/proxy prices. They are useful for 24h price discovery, but they are not the legal equity, broker fill, or pre-IPO ownership price.
95
+ - `read-url` is an extraction fallback using direct/Jina/Defuddle readers. It is not a login-capable browser.
96
+ - Dynamic, login-gated, screenshot-sensitive, or noisy pages should be verified with a real browser tool. `agent-browser` and `opencli` are examples, not dependencies.
97
+
98
+ ## Network Defaults
99
+
100
+ `agent-finance` respects explicit and environment proxy configuration:
101
+
102
+ ```bash
103
+ agent-finance --proxy socks5h://127.0.0.1:7890 price CRDO
104
+ agent-finance --no-proxy price CRDO
105
+ ```
106
+
107
+ Proxy precedence:
108
+
109
+ 1. `--proxy`
110
+ 2. `AGENT_FINANCE_PROXY`
111
+ 3. `ALL_PROXY`
112
+ 4. `HTTPS_PROXY`
113
+ 5. `HTTP_PROXY`
114
+
115
+ No proxy is hardcoded by default.
116
+
117
+ SEC EDGAR requests use `AGENT_FINANCE_SEC_USER_AGENT` when set, otherwise a project-level user agent.
118
+
119
+ Disclaimer: this tool is not investment advice; data may be delayed, incomplete, or wrong, and users must verify important facts and follow source terms.
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { spawnSync } = require("node:child_process");
4
+
5
+ const { resolveBinary } = require("../npm/resolve-binary");
6
+
7
+ const binary = resolveBinary();
8
+
9
+ if (!binary) {
10
+ console.error(
11
+ "agent-finance binary was not found. Reinstall agent-finance-cli, or install Rust/Cargo so the npm fallback build can run.",
12
+ );
13
+ process.exit(127);
14
+ }
15
+
16
+ const result = spawnSync(binary, process.argv.slice(2), { stdio: "inherit" });
17
+
18
+ if (result.error) {
19
+ console.error(result.error.message);
20
+ process.exit(1);
21
+ }
22
+
23
+ if (result.signal) {
24
+ process.kill(process.pid, result.signal);
25
+ }
26
+
27
+ process.exit(result.status ?? 1);
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require("node:fs");
4
+ const path = require("node:path");
5
+ const { spawnSync } = require("node:child_process");
6
+
7
+ const binary = path.resolve(process.argv[2] || "");
8
+ if (!binary || !fs.existsSync(binary)) {
9
+ fail(`binary does not exist: ${binary || "<missing>"}`);
10
+ }
11
+
12
+ const platform = process.platform;
13
+
14
+ if (platform === "linux") {
15
+ run("file", [binary]);
16
+ run("ldd", [binary]);
17
+ run("readelf", ["-d", binary]);
18
+ } else if (platform === "darwin") {
19
+ run("file", [binary]);
20
+ run("otool", ["-L", binary]);
21
+ } else if (platform === "win32") {
22
+ run(binary, ["--help"]);
23
+ const dumpbin = spawnSync("where", ["dumpbin"], { encoding: "utf8" });
24
+ if (dumpbin.status === 0) {
25
+ run("dumpbin", ["/DEPENDENTS", binary]);
26
+ } else {
27
+ console.log("dumpbin is unavailable; executable smoke test completed");
28
+ }
29
+ } else {
30
+ run(binary, ["--help"]);
31
+ console.log(`no platform-specific dynamic-link checker for ${platform}`);
32
+ }
33
+
34
+ function run(command, args) {
35
+ const result = spawnSync(command, args, { encoding: "utf8" });
36
+ if (result.stdout) {
37
+ process.stdout.write(result.stdout);
38
+ }
39
+ if (result.stderr) {
40
+ process.stderr.write(result.stderr);
41
+ }
42
+ if (result.status !== 0) {
43
+ fail(`${command} ${args.join(" ")} failed with status ${result.status}`);
44
+ }
45
+ }
46
+
47
+ function fail(message) {
48
+ console.error(message);
49
+ process.exit(1);
50
+ }
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require("node:fs");
4
+ const path = require("node:path");
5
+
6
+ const { PACKAGES } = require("./platform");
7
+
8
+ const root = path.resolve(__dirname, "..");
9
+ const packageJson = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
10
+ const optional = packageJson.optionalDependencies || {};
11
+ const expectedPackages = Object.values(PACKAGES).sort();
12
+ const optionalPackages = Object.keys(optional).sort();
13
+
14
+ assertArrayEquals(optionalPackages, expectedPackages, "optionalDependencies must match platform map");
15
+
16
+ for (const packageName of expectedPackages) {
17
+ if (optional[packageName] !== packageJson.version) {
18
+ fail(`${packageName} version must match root package version ${packageJson.version}`);
19
+ }
20
+ }
21
+
22
+ for (const file of ["bin/", "npm/", "src/", "skills/", "Cargo.toml", "Cargo.lock"]) {
23
+ if (!packageJson.files.includes(file)) {
24
+ fail(`package.json files must include ${file}`);
25
+ }
26
+ }
27
+
28
+ console.log("npm package metadata is consistent");
29
+
30
+ function assertArrayEquals(actual, expected, message) {
31
+ if (actual.length !== expected.length || actual.some((value, index) => value !== expected[index])) {
32
+ fail(`${message}\nactual: ${JSON.stringify(actual)}\nexpected: ${JSON.stringify(expected)}`);
33
+ }
34
+ }
35
+
36
+ function fail(message) {
37
+ console.error(message);
38
+ process.exit(1);
39
+ }
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require("node:fs");
4
+ const path = require("node:path");
5
+
6
+ const { executableName } = require("./platform");
7
+
8
+ const options = parseArgs(process.argv.slice(2));
9
+ const root = path.resolve(__dirname, "..");
10
+ const rootPackage = readJson(path.join(root, "package.json"));
11
+ const packageName = required(options, "package");
12
+ const os = required(options, "os");
13
+ const cpu = required(options, "cpu");
14
+ const binary = path.resolve(required(options, "binary"));
15
+ const outDir = path.resolve(required(options, "out"));
16
+
17
+ if (!fs.existsSync(binary)) {
18
+ fail(`binary does not exist: ${binary}`);
19
+ }
20
+
21
+ fs.rmSync(outDir, { recursive: true, force: true });
22
+ fs.mkdirSync(path.join(outDir, "bin"), { recursive: true });
23
+
24
+ const targetBinary = path.join(outDir, "bin", executableName(os));
25
+ fs.copyFileSync(binary, targetBinary);
26
+ fs.chmodSync(targetBinary, 0o755);
27
+
28
+ for (const file of ["LICENSE-MIT", "LICENSE-APACHE"]) {
29
+ fs.copyFileSync(path.join(root, file), path.join(outDir, file));
30
+ }
31
+
32
+ fs.writeFileSync(
33
+ path.join(outDir, "README.md"),
34
+ `# ${packageName}\n\nPrebuilt ${os}/${cpu} binary package for \`agent-finance-cli\`.\n\nInstall the main package instead:\n\n\`\`\`bash\nnpm install -g agent-finance-cli\n\`\`\`\n`,
35
+ );
36
+
37
+ writeJson(path.join(outDir, "package.json"), {
38
+ name: packageName,
39
+ version: rootPackage.version,
40
+ description: `Prebuilt ${os}/${cpu} binary for agent-finance-cli.`,
41
+ license: rootPackage.license,
42
+ repository: rootPackage.repository,
43
+ homepage: rootPackage.homepage,
44
+ bugs: rootPackage.bugs,
45
+ os: [os],
46
+ cpu: [cpu],
47
+ bin: {
48
+ "agent-finance": `bin/${executableName(os)}`,
49
+ },
50
+ files: ["bin/", "README.md", "LICENSE-MIT", "LICENSE-APACHE"],
51
+ publishConfig: {
52
+ access: "public",
53
+ },
54
+ });
55
+
56
+ console.log(`created ${packageName} in ${outDir}`);
57
+
58
+ function parseArgs(args) {
59
+ const parsed = {};
60
+ for (let index = 0; index < args.length; index += 2) {
61
+ const key = args[index];
62
+ const value = args[index + 1];
63
+ if (!key?.startsWith("--") || value === undefined) {
64
+ fail(`invalid arguments: ${args.join(" ")}`);
65
+ }
66
+ parsed[key.slice(2)] = value;
67
+ }
68
+ return parsed;
69
+ }
70
+
71
+ function required(options, name) {
72
+ const value = options[name];
73
+ if (!value) {
74
+ fail(`missing --${name}`);
75
+ }
76
+ return value;
77
+ }
78
+
79
+ function readJson(file) {
80
+ return JSON.parse(fs.readFileSync(file, "utf8"));
81
+ }
82
+
83
+ function writeJson(file, value) {
84
+ fs.writeFileSync(file, `${JSON.stringify(value, null, 2)}\n`);
85
+ }
86
+
87
+ function fail(message) {
88
+ console.error(message);
89
+ process.exit(1);
90
+ }
@@ -0,0 +1,33 @@
1
+ const path = require("node:path");
2
+
3
+ const PACKAGES = {
4
+ "darwin-arm64": "agent-finance-cli-darwin-arm64",
5
+ "darwin-x64": "agent-finance-cli-darwin-x64",
6
+ "linux-arm64": "agent-finance-cli-linux-arm64",
7
+ "linux-x64": "agent-finance-cli-linux-x64",
8
+ "win32-x64": "agent-finance-cli-win32-x64",
9
+ };
10
+
11
+ function platformKey(platform = process.platform, arch = process.arch) {
12
+ return `${platform}-${arch}`;
13
+ }
14
+
15
+ function platformPackageName(platform = process.platform, arch = process.arch) {
16
+ return PACKAGES[platformKey(platform, arch)];
17
+ }
18
+
19
+ function executableName(platform = process.platform) {
20
+ return platform === "win32" ? "agent-finance.exe" : "agent-finance";
21
+ }
22
+
23
+ function localBuildBinary(root, platform = process.platform) {
24
+ return path.join(root, "target", "release", executableName(platform));
25
+ }
26
+
27
+ module.exports = {
28
+ PACKAGES,
29
+ executableName,
30
+ localBuildBinary,
31
+ platformKey,
32
+ platformPackageName,
33
+ };
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { spawnSync } = require("node:child_process");
4
+ const path = require("node:path");
5
+
6
+ const { localBuildBinary, platformKey, platformPackageName } = require("./platform");
7
+ const { resolveBinary } = require("./resolve-binary");
8
+
9
+ const root = path.resolve(__dirname, "..");
10
+
11
+ if (resolveBinary({ silent: true })) {
12
+ process.exit(0);
13
+ }
14
+
15
+ const packageName = platformPackageName();
16
+ if (!packageName) {
17
+ console.error(`agent-finance-cli does not publish a prebuilt binary for ${platformKey()}.`);
18
+ } else {
19
+ console.error(`Prebuilt package ${packageName} was not installed.`);
20
+ }
21
+ console.error("Falling back to local Rust build.");
22
+ console.error(
23
+ "Local builds require Rust/Cargo plus a native toolchain for wreq/BoringSSL, including CMake, Clang/Clang++, libclang, and binutils.",
24
+ );
25
+
26
+ const env = {
27
+ ...process.env,
28
+ CC: process.env.CC || "clang",
29
+ CXX: process.env.CXX || "clang++",
30
+ };
31
+
32
+ const result = spawnSync("cargo", ["build", "--release", "--locked"], {
33
+ cwd: root,
34
+ env,
35
+ stdio: "inherit",
36
+ });
37
+
38
+ if (result.error) {
39
+ if (result.error.code === "ENOENT") {
40
+ console.error("agent-finance-cli requires Rust/Cargo to build during npm install.");
41
+ console.error("Install Rust from https://rustup.rs/ and then reinstall this package.");
42
+ console.error("Also install CMake, Clang/Clang++, libclang, and binutils for local fallback builds.");
43
+ process.exit(127);
44
+ }
45
+ console.error(result.error.message);
46
+ process.exit(1);
47
+ }
48
+
49
+ if (result.signal) {
50
+ process.kill(process.pid, result.signal);
51
+ }
52
+
53
+ if (result.status !== 0) {
54
+ process.exit(result.status ?? 1);
55
+ }
56
+
57
+ if (!resolveBinary({ silent: true }) && !require("node:fs").existsSync(localBuildBinary(root))) {
58
+ console.error("Cargo build completed but agent-finance binary was not found.");
59
+ process.exit(1);
60
+ }
61
+
62
+ process.exit(0);