@stealthmark/cli 0.0.0-stage → 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 +202 -0
- package/NOTICE +4 -0
- package/README.md +85 -2
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +96 -0
- package/dist/bin.js.map +1 -0
- package/dist/commands/init.d.ts +18 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +124 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/verify.d.ts +12 -0
- package/dist/commands/verify.d.ts.map +1 -0
- package/dist/commands/verify.js +101 -0
- package/dist/commands/verify.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/package.json +53 -4
package/LICENSE
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/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,86 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @stealthmark/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Command-line tool that scaffolds StealthMark middleware and checks a site for a StealthMark agent manifest.
|
|
4
|
+
|
|
5
|
+
> Detects only agents that identify themselves. It does not detect stealth bots and is not a security control.
|
|
6
|
+
|
|
7
|
+
Part of the [StealthMark](https://stealthmark.io) SDK.
|
|
8
|
+
|
|
9
|
+
> **Status:** v0.1.0, not published to npm yet. The `npm install` and `npx` commands below will work once it is published; until then build from source as described in the [repository README](https://github.com/Gastonchevarria/stealthmark-sdk#status).
|
|
10
|
+
|
|
11
|
+
## Usage from source
|
|
12
|
+
|
|
13
|
+
Until the first npm release, run the CLI from a built clone of the repository:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# in a clone of the repository
|
|
17
|
+
npm install && npm run build
|
|
18
|
+
|
|
19
|
+
# then, in your project
|
|
20
|
+
node /path/to/stealthmark-sdk/packages/cli/dist/bin.js init
|
|
21
|
+
node /path/to/stealthmark-sdk/packages/cli/dist/bin.js verify https://your-site.example
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Installation (after the first npm release)
|
|
25
|
+
|
|
26
|
+
Run directly without installing via `npx`:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npx @stealthmark/cli init
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Or install globally:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install -g @stealthmark/cli
|
|
36
|
+
stealthmark init
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Requires Node.js 20 or newer.
|
|
40
|
+
|
|
41
|
+
## Commands
|
|
42
|
+
|
|
43
|
+
### `stealthmark init`
|
|
44
|
+
Detects Next.js or Express/Fastify and writes a starter middleware file. For Next.js App Router projects it lists `app/api/**/route.ts` handlers as capabilities; for Express and Fastify it writes `capabilities: []` and you declare them yourself. It never invents capabilities, pricing or human-approval flags. If no Next.js, Express or Fastify project is detected it writes nothing and exits with an error.
|
|
45
|
+
|
|
46
|
+
| Detected | File written | Next step |
|
|
47
|
+
| :--- | :--- | :--- |
|
|
48
|
+
| Next.js | `middleware.ts` (or `src/middleware.ts`) | Install `@stealthmark/next`, restart the dev server, open `/.well-known/agent.json` |
|
|
49
|
+
| Express | `stealthmark.middleware.ts`, exports `stealthmarkMiddleware` | Install `@stealthmark/express`, add `app.use(stealthmarkMiddleware)` before your routes |
|
|
50
|
+
| Fastify | `stealthmark.middleware.ts`, exports `stealthmarkHook` | Install `@stealthmark/express`, add `fastify.addHook('preHandler', stealthmarkHook)` |
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# In your Next.js, Express or Fastify project root:
|
|
54
|
+
npx @stealthmark/cli init
|
|
55
|
+
|
|
56
|
+
# Specify a custom display name:
|
|
57
|
+
npx @stealthmark/cli init --name "My SaaS API"
|
|
58
|
+
|
|
59
|
+
# Overwrite existing middleware file:
|
|
60
|
+
npx @stealthmark/cli init --force
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### `stealthmark verify https://your-site.example`
|
|
64
|
+
Checks whether a site serves a StealthMark agent manifest. Three checks: `/.well-known/agent.json` returns 200 JSON with `name`, `protocol` and a `capabilities` array; `/` answers `Accept: application/agent+json` with content type `application/agent+json`; the response carries the `x-stealthmark-shield` marker header. It does not validate the schema and does not prove that agents are detected or metered. A site that serves its own manifest without StealthMark fails the third check. The URL is required.
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
npx @stealthmark/cli verify https://your-site.example
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Output:
|
|
71
|
+
```
|
|
72
|
+
Checking https://your-site.example for a StealthMark agent manifest...
|
|
73
|
+
|
|
74
|
+
PASS Manifest at /.well-known/agent.json: HTTP 200, manifest for "Your Site" with 3 capabilities
|
|
75
|
+
PASS Manifest via Accept: application/agent+json: HTTP 200, Content-Type: application/agent+json; charset=utf-8
|
|
76
|
+
PASS x-stealthmark-shield header: x-stealthmark-shield: ACTIVE
|
|
77
|
+
|
|
78
|
+
=======================================================
|
|
79
|
+
All 3 checks passed.
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The command exits with code 0 when all checks pass and 1 otherwise.
|
|
83
|
+
|
|
84
|
+
## License
|
|
85
|
+
|
|
86
|
+
Apache 2.0, see [LICENSE](./LICENSE) and [NOTICE](./NOTICE).
|
package/dist/bin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":""}
|
package/dist/bin.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
3
|
+
// @stealthmark/cli — Binary Executable
|
|
4
|
+
// CLI interface for stealthmark init and verify
|
|
5
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
6
|
+
import { runInit } from './commands/init.js';
|
|
7
|
+
import { runVerify } from './commands/verify.js';
|
|
8
|
+
const VERSION = '0.1.0';
|
|
9
|
+
function printHelp() {
|
|
10
|
+
console.log(`
|
|
11
|
+
StealthMark CLI (v${VERSION})
|
|
12
|
+
Command-line tool that scaffolds StealthMark middleware and checks a site for a StealthMark agent manifest.
|
|
13
|
+
|
|
14
|
+
Usage:
|
|
15
|
+
stealthmark <command> [options]
|
|
16
|
+
|
|
17
|
+
Commands:
|
|
18
|
+
init [options] Write a starter StealthMark middleware file (Next.js, Express or Fastify)
|
|
19
|
+
verify <url> Check whether a site serves a StealthMark agent manifest
|
|
20
|
+
--version, -v Show version
|
|
21
|
+
--help, -h Show this help message
|
|
22
|
+
|
|
23
|
+
Options (for init):
|
|
24
|
+
--name <siteName> Specify site name for the manifest
|
|
25
|
+
--force Overwrite existing middleware file
|
|
26
|
+
|
|
27
|
+
Examples:
|
|
28
|
+
stealthmark init
|
|
29
|
+
stealthmark verify https://your-site.example
|
|
30
|
+
`);
|
|
31
|
+
}
|
|
32
|
+
async function main() {
|
|
33
|
+
const args = process.argv.slice(2);
|
|
34
|
+
const command = args[0];
|
|
35
|
+
if (!command || command === '--help' || command === '-h') {
|
|
36
|
+
printHelp();
|
|
37
|
+
process.exit(0);
|
|
38
|
+
}
|
|
39
|
+
if (command === '--version' || command === '-v') {
|
|
40
|
+
console.log(`v${VERSION}`);
|
|
41
|
+
process.exit(0);
|
|
42
|
+
}
|
|
43
|
+
if (command === 'init') {
|
|
44
|
+
const force = args.includes('--force');
|
|
45
|
+
const nameIdx = args.indexOf('--name');
|
|
46
|
+
const name = nameIdx !== -1 ? args[nameIdx + 1] : undefined;
|
|
47
|
+
console.log('Detecting framework and scanning API routes...');
|
|
48
|
+
const result = runInit({ cwd: process.cwd(), name, force });
|
|
49
|
+
if (result.success) {
|
|
50
|
+
console.log(result.message);
|
|
51
|
+
console.log(`Framework: ${result.framework}`);
|
|
52
|
+
console.log(`Capabilities discovered: ${result.capabilitiesCount}`);
|
|
53
|
+
console.log('\nNext steps:');
|
|
54
|
+
for (const step of result.nextSteps) {
|
|
55
|
+
console.log(` - ${step}`);
|
|
56
|
+
}
|
|
57
|
+
process.exit(0);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
console.error(result.message);
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (command === 'verify') {
|
|
65
|
+
const targetUrl = args[1];
|
|
66
|
+
if (!targetUrl) {
|
|
67
|
+
console.error('Usage: stealthmark verify <url>');
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
console.log(`Checking ${targetUrl} for a StealthMark agent manifest...\n`);
|
|
71
|
+
const report = await runVerify(targetUrl);
|
|
72
|
+
for (const check of report.checks) {
|
|
73
|
+
const icon = check.passed ? 'PASS' : 'FAIL';
|
|
74
|
+
console.log(`${icon} ${check.name}: ${check.details}`);
|
|
75
|
+
}
|
|
76
|
+
const total = report.checks.length;
|
|
77
|
+
const failed = report.checks.filter((c) => !c.passed).length;
|
|
78
|
+
console.log('\n=======================================================');
|
|
79
|
+
if (report.overallPassed) {
|
|
80
|
+
console.log(`All ${total} checks passed.`);
|
|
81
|
+
process.exit(0);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
console.log(`${failed} of ${total} checks failed. See https://stealthmark.io/docs.`);
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
console.error(`Unknown command: ${command}`);
|
|
89
|
+
printHelp();
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
92
|
+
main().catch((err) => {
|
|
93
|
+
console.error('Fatal CLI error:', err instanceof Error ? err.message : err);
|
|
94
|
+
process.exit(1);
|
|
95
|
+
});
|
|
96
|
+
//# sourceMappingURL=bin.js.map
|
package/dist/bin.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AAEA,sEAAsE;AACtE,uCAAuC;AACvC,gDAAgD;AAChD,sEAAsE;AAEtE,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,MAAM,OAAO,GAAG,OAAO,CAAC;AAExB,SAAS,SAAS;IAChB,OAAO,CAAC,GAAG,CAAC;oBACM,OAAO;;;;;;;;;;;;;;;;;;;CAmB1B,CAAC,CAAC;AACH,CAAC;AAED,KAAK,UAAU,IAAI;IACjB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACnC,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IAExB,IAAI,CAAC,OAAO,IAAI,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACzD,SAAS,EAAE,CAAC;QACZ,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,IAAI,OAAO,KAAK,WAAW,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,CAAC,GAAG,CAAC,IAAI,OAAO,EAAE,CAAC,CAAC;QAC3B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,IAAI,OAAO,KAAK,MAAM,EAAE,CAAC;QACvB,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,C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AC,KAAK,CAAC,kBAAkB,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAC5E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type Framework = 'next' | 'express' | 'fastify' | 'unknown';
|
|
2
|
+
export interface InitOptions {
|
|
3
|
+
cwd?: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
force?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface InitResult {
|
|
8
|
+
success: boolean;
|
|
9
|
+
framework: Framework;
|
|
10
|
+
filePath: string;
|
|
11
|
+
capabilitiesCount: number;
|
|
12
|
+
message: string;
|
|
13
|
+
/** Framework-specific steps the user still has to do by hand */
|
|
14
|
+
nextSteps: string[];
|
|
15
|
+
}
|
|
16
|
+
export declare function detectFramework(cwd: string): Framework;
|
|
17
|
+
export declare function runInit(options?: InitOptions): InitResult;
|
|
18
|
+
//# sourceMappingURL=init.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;AAEnE,MAAM,WAAW,WAAW;IAC1B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,SAAS,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,gEAAgE;IAChE,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB;AAgBD,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAmBtD;AAaD,wBAAgB,OAAO,CAAC,OAAO,GAAE,WAAgB,GAAG,UAAU,CAsF7D"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
2
|
+
// @stealthmark/cli — init command
|
|
3
|
+
// Writes a starter StealthMark middleware file for Next.js, Express or Fastify
|
|
4
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
5
|
+
import * as fs from 'fs';
|
|
6
|
+
import * as path from 'path';
|
|
7
|
+
import { discoverCapabilities } from '@stealthmark/core';
|
|
8
|
+
function readPackageJson(cwd) {
|
|
9
|
+
try {
|
|
10
|
+
return JSON.parse(fs.readFileSync(path.join(cwd, 'package.json'), 'utf8'));
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function detectFramework(cwd) {
|
|
17
|
+
const pkg = readPackageJson(cwd);
|
|
18
|
+
if (pkg) {
|
|
19
|
+
const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
20
|
+
if (allDeps['next'])
|
|
21
|
+
return 'next';
|
|
22
|
+
if (allDeps['express'])
|
|
23
|
+
return 'express';
|
|
24
|
+
if (allDeps['fastify'])
|
|
25
|
+
return 'fastify';
|
|
26
|
+
}
|
|
27
|
+
if (fs.existsSync(path.join(cwd, 'next.config.js')) ||
|
|
28
|
+
fs.existsSync(path.join(cwd, 'next.config.mjs')) ||
|
|
29
|
+
fs.existsSync(path.join(cwd, 'next.config.ts'))) {
|
|
30
|
+
return 'next';
|
|
31
|
+
}
|
|
32
|
+
return 'unknown';
|
|
33
|
+
}
|
|
34
|
+
function frameworkLabel(framework) {
|
|
35
|
+
switch (framework) {
|
|
36
|
+
case 'next':
|
|
37
|
+
return 'Next.js';
|
|
38
|
+
case 'express':
|
|
39
|
+
return 'Express';
|
|
40
|
+
case 'fastify':
|
|
41
|
+
return 'Fastify';
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export function runInit(options = {}) {
|
|
45
|
+
const cwd = options.cwd || process.cwd();
|
|
46
|
+
const framework = detectFramework(cwd);
|
|
47
|
+
if (framework === 'unknown') {
|
|
48
|
+
return {
|
|
49
|
+
success: false,
|
|
50
|
+
framework,
|
|
51
|
+
filePath: '',
|
|
52
|
+
capabilitiesCount: 0,
|
|
53
|
+
message: 'No Next.js, Express or Fastify project detected. No file was written.',
|
|
54
|
+
nextSteps: [],
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const siteName = options.name || readPackageJson(cwd)?.name || 'My App';
|
|
58
|
+
const discoveredCaps = framework === 'next' ? discoverCapabilities({ rootDir: cwd }) : [];
|
|
59
|
+
const capsCode = JSON.stringify(discoveredCaps, null, 2);
|
|
60
|
+
const targetPath = framework === 'next'
|
|
61
|
+
? fs.existsSync(path.join(cwd, 'src'))
|
|
62
|
+
? path.join(cwd, 'src', 'middleware.ts')
|
|
63
|
+
: path.join(cwd, 'middleware.ts')
|
|
64
|
+
: path.join(cwd, 'stealthmark.middleware.ts');
|
|
65
|
+
if (fs.existsSync(targetPath) && !options.force) {
|
|
66
|
+
return {
|
|
67
|
+
success: false,
|
|
68
|
+
framework,
|
|
69
|
+
filePath: targetPath,
|
|
70
|
+
capabilitiesCount: discoveredCaps.length,
|
|
71
|
+
message: `File already exists at ${targetPath}. Use --force to overwrite.`,
|
|
72
|
+
nextSteps: [],
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
let template;
|
|
76
|
+
let nextSteps;
|
|
77
|
+
if (framework === 'next') {
|
|
78
|
+
template = `import { stealthmark } from '@stealthmark/next';
|
|
79
|
+
|
|
80
|
+
export default stealthmark({
|
|
81
|
+
siteName: ${JSON.stringify(siteName)},
|
|
82
|
+
capabilities: ${capsCode},
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
export const config = {
|
|
86
|
+
matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
|
|
87
|
+
};
|
|
88
|
+
`;
|
|
89
|
+
nextSteps = ['Install @stealthmark/next, then restart your dev server and open /.well-known/agent.json'];
|
|
90
|
+
}
|
|
91
|
+
else if (framework === 'fastify') {
|
|
92
|
+
template = `import { stealthmarkFastify } from '@stealthmark/express';
|
|
93
|
+
|
|
94
|
+
export const stealthmarkHook = stealthmarkFastify({
|
|
95
|
+
siteName: ${JSON.stringify(siteName)},
|
|
96
|
+
capabilities: ${capsCode},
|
|
97
|
+
});
|
|
98
|
+
`;
|
|
99
|
+
nextSteps = [
|
|
100
|
+
'Install @stealthmark/express',
|
|
101
|
+
"Register the hook before your routes: fastify.addHook('preHandler', stealthmarkHook)",
|
|
102
|
+
];
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
template = `import { stealthmark } from '@stealthmark/express';
|
|
106
|
+
|
|
107
|
+
export const stealthmarkMiddleware = stealthmark({
|
|
108
|
+
siteName: ${JSON.stringify(siteName)},
|
|
109
|
+
capabilities: ${capsCode},
|
|
110
|
+
});
|
|
111
|
+
`;
|
|
112
|
+
nextSteps = ['Install @stealthmark/express', 'Add app.use(stealthmarkMiddleware) before your routes'];
|
|
113
|
+
}
|
|
114
|
+
fs.writeFileSync(targetPath, template, 'utf8');
|
|
115
|
+
return {
|
|
116
|
+
success: true,
|
|
117
|
+
framework,
|
|
118
|
+
filePath: targetPath,
|
|
119
|
+
capabilitiesCount: discoveredCaps.length,
|
|
120
|
+
message: `Generated ${frameworkLabel(framework)} StealthMark middleware at ${targetPath}`,
|
|
121
|
+
nextSteps,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,kCAAkC;AAClC,+EAA+E;AAC/E,sEAAsE;AAEtE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ificationCheck {
|
|
2
|
+
name: string;
|
|
3
|
+
passed: boolean;
|
|
4
|
+
details: string;
|
|
5
|
+
}
|
|
6
|
+
export interface VerificationReport {
|
|
7
|
+
targetUrl: string;
|
|
8
|
+
checks: VerificationCheck[];
|
|
9
|
+
overallPassed: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function runVerify(targetUrl: string): Promise<VerificationReport>;
|
|
12
|
+
//# sourceMappingURL=verify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../src/commands/verify.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,iBAAiB,EAAE,CAAC;IAC5B,aAAa,EAAE,OAAO,CAAC;CACxB;AAgGD,wBAAsB,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAa9E"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
2
|
+
// @stealthmark/cli — verify command
|
|
3
|
+
// Checks whether a live URL serves a StealthMark agent manifest
|
|
4
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
5
|
+
const REQUEST_TIMEOUT_MS = 10_000;
|
|
6
|
+
const MANIFEST_CHECK = 'Manifest at /.well-known/agent.json';
|
|
7
|
+
const NEGOTIATION_CHECK = 'Manifest via Accept: application/agent+json';
|
|
8
|
+
const MARKER_CHECK = 'x-stealthmark-shield header';
|
|
9
|
+
function errorMessage(err) {
|
|
10
|
+
return err instanceof Error ? err.message : String(err);
|
|
11
|
+
}
|
|
12
|
+
function capabilityCount(count) {
|
|
13
|
+
return `${count} ${count === 1 ? 'capability' : 'capabilities'}`;
|
|
14
|
+
}
|
|
15
|
+
function get(baseUrl, pathname, accept) {
|
|
16
|
+
return fetch(new URL(pathname, baseUrl), {
|
|
17
|
+
headers: { Accept: accept },
|
|
18
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function isRecord(value) {
|
|
22
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
23
|
+
}
|
|
24
|
+
async function checkManifestFile(baseUrl) {
|
|
25
|
+
try {
|
|
26
|
+
const res = await get(baseUrl, '/.well-known/agent.json', 'application/json');
|
|
27
|
+
if (!res.ok) {
|
|
28
|
+
return { name: MANIFEST_CHECK, passed: false, details: `HTTP ${res.status}: /.well-known/agent.json was not found` };
|
|
29
|
+
}
|
|
30
|
+
const contentType = res.headers.get('content-type') || '';
|
|
31
|
+
if (!contentType.includes('json')) {
|
|
32
|
+
return { name: MANIFEST_CHECK, passed: false, details: `Content-Type is ${contentType || 'missing'}, expected JSON` };
|
|
33
|
+
}
|
|
34
|
+
let json;
|
|
35
|
+
try {
|
|
36
|
+
json = JSON.parse(await res.text());
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return { name: MANIFEST_CHECK, passed: false, details: 'Response is not JSON' };
|
|
40
|
+
}
|
|
41
|
+
if (!isRecord(json) || typeof json.name !== 'string' || typeof json.protocol !== 'string' || !Array.isArray(json.capabilities)) {
|
|
42
|
+
return {
|
|
43
|
+
name: MANIFEST_CHECK,
|
|
44
|
+
passed: false,
|
|
45
|
+
details: 'JSON found, but it is missing name, protocol or a capabilities array',
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
name: MANIFEST_CHECK,
|
|
50
|
+
passed: true,
|
|
51
|
+
details: `HTTP ${res.status}, manifest for "${json.name}" with ${capabilityCount(json.capabilities.length)}`,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
return { name: MANIFEST_CHECK, passed: false, details: `Network error: ${errorMessage(err)}` };
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async function checkNegotiation(baseUrl) {
|
|
59
|
+
let res;
|
|
60
|
+
try {
|
|
61
|
+
res = await get(baseUrl, '/', 'application/agent+json');
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
const details = `Network error: ${errorMessage(err)}`;
|
|
65
|
+
return [
|
|
66
|
+
{ name: NEGOTIATION_CHECK, passed: false, details },
|
|
67
|
+
{ name: MARKER_CHECK, passed: false, details },
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
const contentType = res.headers.get('content-type') || '';
|
|
71
|
+
const marker = res.headers.get('x-stealthmark-shield');
|
|
72
|
+
const negotiated = res.ok && contentType.includes('application/agent+json');
|
|
73
|
+
return [
|
|
74
|
+
{
|
|
75
|
+
name: NEGOTIATION_CHECK,
|
|
76
|
+
passed: negotiated,
|
|
77
|
+
details: negotiated
|
|
78
|
+
? `HTTP ${res.status}, Content-Type: ${contentType}`
|
|
79
|
+
: `Expected HTTP 200 with application/agent+json, received HTTP ${res.status} with ${contentType || 'no content type'}`,
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: MARKER_CHECK,
|
|
83
|
+
passed: Boolean(marker),
|
|
84
|
+
details: marker ? `x-stealthmark-shield: ${marker}` : 'Header missing',
|
|
85
|
+
},
|
|
86
|
+
];
|
|
87
|
+
}
|
|
88
|
+
export async function runVerify(targetUrl) {
|
|
89
|
+
const normalizedUrl = targetUrl.replace(/\/$/, '');
|
|
90
|
+
const [manifestCheck, negotiationChecks] = await Promise.all([
|
|
91
|
+
checkManifestFile(normalizedUrl),
|
|
92
|
+
checkNegotiation(normalizedUrl),
|
|
93
|
+
]);
|
|
94
|
+
const checks = [manifestCheck, ...negotiationChecks];
|
|
95
|
+
return {
|
|
96
|
+
targetUrl: normalizedUrl,
|
|
97
|
+
checks,
|
|
98
|
+
overallPassed: checks.every((c) => c.passed),
|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ClB,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC;YACvB,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,yBAAyB,MAAM,EAAE,CAAC,CAAC,CAAC,gBAAgB;SACvE;KACF,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,SAAiB;IAC/C,MAAM,aAAa,GAAG,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACnD,MAAM,CAAC,aAAa,EAAE,iBAAiB,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAC3D,iBAAiB,CAAC,aAAa,CAAC;QAChC,gBAAgB,CAAC,aAAa,CAAC;KAChC,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,CAAC,aAAa,EAAE,GAAG,iBAAiB,CAAC,CAAC;IAErD,OAAO;QACL,SAAS,EAAE,aAAa;QACxB,MAAM;QACN,aAAa,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;KAC7C,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACjH,OAAO,EAAE,SAAS,EAAE,KAAK,iBAAiB,EAAE,KAAK,kBAAkB,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
2
|
+
// @stealthmark/cli — Public Library Exports
|
|
3
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
4
|
+
export { runInit, detectFramework } from './commands/init.js';
|
|
5
|
+
export { runVerify } from './commands/verify.js';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,4CAA4C;AAC5C,sEAAsE;AAEtE,OAAO,EAAE,OAAO,EAAE,eAAe,EAAqD,MAAM,oBAAoB,CAAC;AACjH,OAAO,EAAE,SAAS,EAAmD,MAAM,sBAAsB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stealthmark/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CLI that scaffolds StealthMark middleware for Next.js, Express and Fastify and checks whether a site serves a StealthMark agent manifest",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"bin": {
|
|
9
|
+
"stealthmark": "./dist/bin.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"README.md",
|
|
14
|
+
"LICENSE",
|
|
15
|
+
"NOTICE"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc --project tsconfig.build.json && chmod +x dist/bin.js",
|
|
19
|
+
"dev": "tsc --project tsconfig.build.json --watch",
|
|
20
|
+
"test": "vitest run",
|
|
21
|
+
"typecheck": "tsc --noEmit",
|
|
22
|
+
"clean": "rm -rf dist tsconfig.build.tsbuildinfo"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"stealthmark",
|
|
26
|
+
"cli",
|
|
27
|
+
"ai-agents",
|
|
28
|
+
"agent-manifest",
|
|
29
|
+
"scaffold"
|
|
30
|
+
],
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/Gastonchevarria/stealthmark-sdk.git",
|
|
34
|
+
"directory": "packages/cli"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://stealthmark.io",
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=20"
|
|
39
|
+
},
|
|
40
|
+
"author": "Gaston Chevarria <gaston_ch27@hotmail.com>",
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@stealthmark/core": "^0.1.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/node": "^22.0.0",
|
|
46
|
+
"typescript": "^5.7.0",
|
|
47
|
+
"vitest": "^4.1.11"
|
|
48
|
+
},
|
|
49
|
+
"bugs": {
|
|
50
|
+
"url": "https://github.com/Gastonchevarria/stealthmark-sdk/issues"
|
|
51
|
+
},
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public"
|
|
54
|
+
}
|
|
55
|
+
}
|