pecta-proxy 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 +201 -0
- package/README.md +87 -0
- package/dist/bin/pecta-proxy.d.ts +3 -0
- package/dist/bin/pecta-proxy.d.ts.map +1 -0
- package/dist/bin/pecta-proxy.js +7 -0
- package/dist/bin/pecta-proxy.js.map +1 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.d.ts.map +1 -0
- package/dist/src/cli.js +61 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/jsonrpc.d.ts +45 -0
- package/dist/src/jsonrpc.d.ts.map +1 -0
- package/dist/src/jsonrpc.js +56 -0
- package/dist/src/jsonrpc.js.map +1 -0
- package/dist/src/line-buffer.d.ts +16 -0
- package/dist/src/line-buffer.d.ts.map +1 -0
- package/dist/src/line-buffer.js +46 -0
- package/dist/src/line-buffer.js.map +1 -0
- package/dist/src/logger.d.ts +23 -0
- package/dist/src/logger.d.ts.map +1 -0
- package/dist/src/logger.js +61 -0
- package/dist/src/logger.js.map +1 -0
- package/dist/src/pipeline.d.ts +26 -0
- package/dist/src/pipeline.d.ts.map +1 -0
- package/dist/src/pipeline.js +66 -0
- package/dist/src/pipeline.js.map +1 -0
- package/dist/src/proxy.d.ts +23 -0
- package/dist/src/proxy.d.ts.map +1 -0
- package/dist/src/proxy.js +134 -0
- package/dist/src/proxy.js.map +1 -0
- package/package.json +33 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Support. While redistributing the Work or
|
|
166
|
+
Derivative Works thereof, You may choose to offer, and charge a
|
|
167
|
+
fee for, acceptance of support, warranty, indemnity, or other
|
|
168
|
+
liability obligations and/or rights consistent with this License.
|
|
169
|
+
However, in accepting such obligations, You may act only on Your
|
|
170
|
+
own behalf and on Your sole responsibility, not on behalf of any
|
|
171
|
+
other Contributor, and only if You agree to indemnify, defend, and
|
|
172
|
+
hold each Contributor harmless for any liability incurred by, or
|
|
173
|
+
claims asserted against, such Contributor by reason of your accepting
|
|
174
|
+
any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Pecta
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# pecta-proxy
|
|
2
|
+
|
|
3
|
+
> Wrap any MCP server with quality gates that block dangerous tool calls before they reach the user.
|
|
4
|
+
|
|
5
|
+
`pecta-proxy` spawns an MCP server as a subprocess, intercepts every JSON-RPC `tools/call` response, runs Pecta gates over it, and either forwards the original response or replaces it with a `-32000` error if a gate fails.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx pecta-proxy <command> [args...]
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or install globally:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install -g pecta-proxy
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quickstart — local mode (no key required)
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npx pecta-proxy --verbose npx -y @modelcontextprotocol/server-filesystem /tmp
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
When a tool call returns an `rm -rf` or path-traversal payload, the proxy replaces the response with a structured error and logs the decision to `~/.pecta/logs/YYYY-MM-DD.jsonl`.
|
|
26
|
+
|
|
27
|
+
## With cloud telemetry
|
|
28
|
+
|
|
29
|
+
Get a publishable key from [pecta.ai](https://pecta.ai) (or `pnpm --filter @pecta/api admin issue-key` if you're self-hosting), then:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npx pecta-proxy --key pk_live_xxx node my-mcp-server.js
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Evaluations show up in your dashboard at `dashboard.pecta.ai` and feed into the agent's portable reputation score.
|
|
36
|
+
|
|
37
|
+
## Claude Desktop config
|
|
38
|
+
|
|
39
|
+
Edit `~/Library/Application Support/Claude/claude_desktop_config.json`:
|
|
40
|
+
|
|
41
|
+
```json
|
|
42
|
+
{
|
|
43
|
+
"mcpServers": {
|
|
44
|
+
"filesystem": {
|
|
45
|
+
"command": "npx",
|
|
46
|
+
"args": [
|
|
47
|
+
"-y", "pecta-proxy",
|
|
48
|
+
"--key", "pk_live_xxx",
|
|
49
|
+
"npx", "-y", "@modelcontextprotocol/server-filesystem", "/Users/me/Documents"
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Flags
|
|
57
|
+
|
|
58
|
+
| Flag | Default | Description |
|
|
59
|
+
|------|---------|-------------|
|
|
60
|
+
| `--key <key>` | none | Publishable Pecta key for cloud telemetry. Without it, the proxy still gates locally and writes to `~/.pecta/logs/`. |
|
|
61
|
+
| `--dry-run` | off | Log every gate decision but always forward the original response. |
|
|
62
|
+
| `--verbose` | off | Print one-line summary per evaluation to stderr. |
|
|
63
|
+
| `--timeout <ms>` | 50 | Total gate budget per response. |
|
|
64
|
+
| `--max-message-size <bytes>` | 1048576 | Drop JSON-RPC messages larger than this. |
|
|
65
|
+
| `--agent-id <id>` | `mcp-proxy` | Agent identifier reported to telemetry. |
|
|
66
|
+
|
|
67
|
+
## How blocking works
|
|
68
|
+
|
|
69
|
+
When gates fail, the proxy returns a JSON-RPC error to the upstream client:
|
|
70
|
+
|
|
71
|
+
```json
|
|
72
|
+
{
|
|
73
|
+
"jsonrpc": "2.0",
|
|
74
|
+
"id": 7,
|
|
75
|
+
"error": {
|
|
76
|
+
"code": -32000,
|
|
77
|
+
"message": "pecta: tool call blocked by quality gate",
|
|
78
|
+
"data": { "gates": [{ "name": "filesystem", "reason": "destructive rm command detected" }] }
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Use `--dry-run` to observe blocking decisions in production before flipping them on.
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
Apache-2.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pecta-proxy.d.ts","sourceRoot":"","sources":["../../bin/pecta-proxy.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { run } from '../src/cli.js';
|
|
3
|
+
run().then((code) => process.exit(code), (err) => {
|
|
4
|
+
process.stderr.write(`pecta-proxy: fatal: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
5
|
+
process.exit(1);
|
|
6
|
+
});
|
|
7
|
+
//# sourceMappingURL=pecta-proxy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pecta-proxy.js","sourceRoot":"","sources":["../../bin/pecta-proxy.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,GAAG,EAAE,CAAC,IAAI,CACR,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAC5B,CAAC,GAAY,EAAE,EAAE;IACf,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,uBAAuB,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAC5E,CAAC;IACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"AAQA,wBAAsB,GAAG,CAAC,IAAI,GAAE,MAAM,EAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,CAkExE"}
|
package/dist/src/cli.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { createEngine, gates, PectaTelemetry } from '@pecta/core';
|
|
3
|
+
import { runProxy } from './proxy.js';
|
|
4
|
+
import { JsonlLogger } from './logger.js';
|
|
5
|
+
const DEFAULT_TIMEOUT_MS = 50;
|
|
6
|
+
const DEFAULT_MAX_MESSAGE_SIZE = 1_048_576;
|
|
7
|
+
export async function run(argv = process.argv) {
|
|
8
|
+
const program = new Command();
|
|
9
|
+
program
|
|
10
|
+
.name('pecta-proxy')
|
|
11
|
+
.description('Run Pecta quality gates over an MCP server\'s tools/call responses')
|
|
12
|
+
.argument('<command>', 'command to spawn (e.g. node, npx)')
|
|
13
|
+
.argument('[args...]', 'arguments forwarded to the command')
|
|
14
|
+
.option('--key <key>', 'Pecta API key (pk_live_...) for cloud telemetry')
|
|
15
|
+
.option('--dry-run', 'log gate decisions but always forward responses', false)
|
|
16
|
+
.option('--verbose', 'write gate decisions to stderr', false)
|
|
17
|
+
.option('--timeout <ms>', 'total gate timeout in ms', (v) => parseIntPositive(v, 'timeout'), DEFAULT_TIMEOUT_MS)
|
|
18
|
+
.option('--config <path>', 'path to pecta.config.json (reserved)')
|
|
19
|
+
.option('--max-message-size <bytes>', 'max JSON-RPC message size', (v) => parseIntPositive(v, 'max-message-size'), DEFAULT_MAX_MESSAGE_SIZE)
|
|
20
|
+
.option('--agent-id <id>', 'agent identifier reported to Pecta', 'mcp-proxy')
|
|
21
|
+
.allowExcessArguments(true)
|
|
22
|
+
.passThroughOptions();
|
|
23
|
+
program.parse(argv);
|
|
24
|
+
const opts = program.opts();
|
|
25
|
+
const [command, ...args] = program.args;
|
|
26
|
+
if (!command) {
|
|
27
|
+
program.error('error: missing required argument <command>');
|
|
28
|
+
return 2;
|
|
29
|
+
}
|
|
30
|
+
const engine = createEngine({
|
|
31
|
+
gates: [gates.filesystem(), gates.pii(), gates.content()],
|
|
32
|
+
timeout: opts.timeout,
|
|
33
|
+
});
|
|
34
|
+
const logger = new JsonlLogger();
|
|
35
|
+
void logger.rotate();
|
|
36
|
+
let telemetry;
|
|
37
|
+
if (opts.key) {
|
|
38
|
+
telemetry = new PectaTelemetry({ publishableKey: opts.key });
|
|
39
|
+
}
|
|
40
|
+
const exitCode = await runProxy({
|
|
41
|
+
command,
|
|
42
|
+
args,
|
|
43
|
+
engine,
|
|
44
|
+
agentId: opts.agentId,
|
|
45
|
+
dryRun: opts.dryRun,
|
|
46
|
+
verbose: opts.verbose,
|
|
47
|
+
maxMessageSize: opts.maxMessageSize,
|
|
48
|
+
...(telemetry ? { telemetry } : {}),
|
|
49
|
+
logger,
|
|
50
|
+
});
|
|
51
|
+
await telemetry?.shutdown();
|
|
52
|
+
return exitCode;
|
|
53
|
+
}
|
|
54
|
+
function parseIntPositive(value, label) {
|
|
55
|
+
const n = Number.parseInt(value, 10);
|
|
56
|
+
if (!Number.isFinite(n) || n <= 0) {
|
|
57
|
+
throw new Error(`pecta-proxy: --${label} must be a positive integer, got "${value}"`);
|
|
58
|
+
}
|
|
59
|
+
return n;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,MAAM,wBAAwB,GAAG,SAAS,CAAC;AAE3C,MAAM,CAAC,KAAK,UAAU,GAAG,CAAC,OAAiB,OAAO,CAAC,IAAI;IACrD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAE9B,OAAO;SACJ,IAAI,CAAC,aAAa,CAAC;SACnB,WAAW,CAAC,oEAAoE,CAAC;SACjF,QAAQ,CAAC,WAAW,EAAE,mCAAmC,CAAC;SAC1D,QAAQ,CAAC,WAAW,EAAE,oCAAoC,CAAC;SAC3D,MAAM,CAAC,aAAa,EAAE,iDAAiD,CAAC;SACxE,MAAM,CAAC,WAAW,EAAE,iDAAiD,EAAE,KAAK,CAAC;SAC7E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G,EAAE,CAAC,CAAC;IAC/D,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC;QAC9B,OAAO;QACP,IAAI;QACJ,MAAM;QACN,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,cAAc,EAAE,IAAI,CAAC,cAAc;QACnC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACnC,MAAM;KACP,CAAC,CAAC;IAEH,MAAM,SAAS,EAAE,QAAQ,EAAE,CAAC;IAC5B,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAa,EAAE,KAAa;IACpD,MAAM,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACrC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CAAC,kBAAkB,KAAK,qCAAqC,KAAK,GAAG,CAAC,CAAC;IACxF,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON-RPC 2.0 parsing helpers, defensive enough to run on untrusted child
|
|
3
|
+
* stdout. Every parse is wrapped in try/catch — malformed input returns null
|
|
4
|
+
* rather than throwing.
|
|
5
|
+
*/
|
|
6
|
+
export interface JsonRpcRequest {
|
|
7
|
+
jsonrpc: '2.0';
|
|
8
|
+
id: number | string;
|
|
9
|
+
method: string;
|
|
10
|
+
params?: unknown;
|
|
11
|
+
}
|
|
12
|
+
export interface JsonRpcNotification {
|
|
13
|
+
jsonrpc: '2.0';
|
|
14
|
+
method: string;
|
|
15
|
+
params?: unknown;
|
|
16
|
+
}
|
|
17
|
+
export interface JsonRpcSuccessResponse {
|
|
18
|
+
jsonrpc: '2.0';
|
|
19
|
+
id: number | string | null;
|
|
20
|
+
result: unknown;
|
|
21
|
+
}
|
|
22
|
+
export interface JsonRpcErrorResponse {
|
|
23
|
+
jsonrpc: '2.0';
|
|
24
|
+
id: number | string | null;
|
|
25
|
+
error: {
|
|
26
|
+
code: number;
|
|
27
|
+
message: string;
|
|
28
|
+
data?: unknown;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export type JsonRpcResponse = JsonRpcSuccessResponse | JsonRpcErrorResponse;
|
|
32
|
+
export type JsonRpcMessage = JsonRpcRequest | JsonRpcNotification | JsonRpcResponse;
|
|
33
|
+
declare const TOOL_CALL_METHOD = "tools/call";
|
|
34
|
+
export declare function parseMessage(data: string): JsonRpcMessage | null;
|
|
35
|
+
export declare function isRequest(msg: JsonRpcMessage): msg is JsonRpcRequest;
|
|
36
|
+
export declare function isNotification(msg: JsonRpcMessage): msg is JsonRpcNotification;
|
|
37
|
+
export declare function isResponse(msg: JsonRpcMessage): msg is JsonRpcResponse;
|
|
38
|
+
export declare function isToolCallRequest(msg: JsonRpcMessage): msg is JsonRpcRequest & {
|
|
39
|
+
method: typeof TOOL_CALL_METHOD;
|
|
40
|
+
};
|
|
41
|
+
/** Pull the `name` field out of a tools/call request's params. */
|
|
42
|
+
export declare function extractToolName(req: JsonRpcRequest): string | undefined;
|
|
43
|
+
export declare function buildErrorResponse(id: number | string | null, code: number, message: string, data?: unknown): JsonRpcErrorResponse;
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=jsonrpc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonrpc.d.ts","sourceRoot":"","sources":["../../src/jsonrpc.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,MAAM,EA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,MAAM,GAAG,SAAS,CAKvE;AAED,wBAAgB,kBAAkB,CAChC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,EAC1B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,OAAO,GACb,oBAAoB,CAMtB"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON-RPC 2.0 parsing helpers, defensive enough to run on untrusted child
|
|
3
|
+
* stdout. Every parse is wrapped in try/catch — malformed input returns null
|
|
4
|
+
* rather than throwing.
|
|
5
|
+
*/
|
|
6
|
+
const TOOL_CALL_METHOD = 'tools/call';
|
|
7
|
+
export function parseMessage(data) {
|
|
8
|
+
if (!data || data.length === 0)
|
|
9
|
+
return null;
|
|
10
|
+
let parsed;
|
|
11
|
+
try {
|
|
12
|
+
parsed = JSON.parse(data);
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
18
|
+
return null;
|
|
19
|
+
const obj = parsed;
|
|
20
|
+
if (obj['jsonrpc'] !== '2.0')
|
|
21
|
+
return null;
|
|
22
|
+
return obj;
|
|
23
|
+
}
|
|
24
|
+
export function isRequest(msg) {
|
|
25
|
+
const m = msg;
|
|
26
|
+
return (typeof m['method'] === 'string' &&
|
|
27
|
+
m['id'] !== undefined &&
|
|
28
|
+
(typeof m['id'] === 'string' || typeof m['id'] === 'number'));
|
|
29
|
+
}
|
|
30
|
+
export function isNotification(msg) {
|
|
31
|
+
const m = msg;
|
|
32
|
+
return typeof m['method'] === 'string' && m['id'] === undefined;
|
|
33
|
+
}
|
|
34
|
+
export function isResponse(msg) {
|
|
35
|
+
const m = msg;
|
|
36
|
+
return ('result' in m || 'error' in m) && 'id' in m && typeof m['method'] !== 'string';
|
|
37
|
+
}
|
|
38
|
+
export function isToolCallRequest(msg) {
|
|
39
|
+
return isRequest(msg) && msg.method === TOOL_CALL_METHOD;
|
|
40
|
+
}
|
|
41
|
+
/** Pull the `name` field out of a tools/call request's params. */
|
|
42
|
+
export function extractToolName(req) {
|
|
43
|
+
const params = req.params;
|
|
44
|
+
if (!params || typeof params !== 'object' || Array.isArray(params))
|
|
45
|
+
return undefined;
|
|
46
|
+
const name = params['name'];
|
|
47
|
+
return typeof name === 'string' ? name : undefined;
|
|
48
|
+
}
|
|
49
|
+
export function buildErrorResponse(id, code, message, data) {
|
|
50
|
+
return {
|
|
51
|
+
jsonrpc: '2.0',
|
|
52
|
+
id,
|
|
53
|
+
error: data !== undefined ? { code, message, data } : { code, message },
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=jsonrpc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonrpc.js","sourceRoot":"","sources":["../../src/jsonrpc.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA8BH,MAAM,gBAAgB,GAAG,YAAY,CAAC;AAEtC,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAC5C,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAC;IACxF,MAAM,GAAG,GAAG,MAAiC,CAAC;IAC9C,IAAI,GAAG,CAAC,SAAS,CAAC,KAAK,KAAK;QAAE,OAAO,IAAI,CAAC;IAC1C,OAAO,GAAgC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,G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AM,UAAU,kBAAkB,CAChC,EAA0B,EAC1B,IAAY,EACZ,OAAe,EACf,IAAc;IAEd,OAAO;QACL,OAAO,EAAE,KAAK;QACd,EAAE;QACF,KAAK,EAAE,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE;KACxE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Splits arriving stdio chunks on '\n'. Caps a single message at `max` bytes
|
|
3
|
+
* — when a line grows past that without a newline, the buffer is dropped.
|
|
4
|
+
*/
|
|
5
|
+
export declare class LineBuffer {
|
|
6
|
+
private readonly max;
|
|
7
|
+
private buf;
|
|
8
|
+
constructor(max: number);
|
|
9
|
+
push(chunk: string): {
|
|
10
|
+
lines: string[];
|
|
11
|
+
oversized: number;
|
|
12
|
+
};
|
|
13
|
+
/** Force-flush any trailing partial buffer (e.g. on stream end). */
|
|
14
|
+
flush(): string[];
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=line-buffer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"line-buffer.d.ts","sourceRoot":"","sources":["../../src/line-buffer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,UAAU;IAGT,OAAO,CAAC,QAAQ,CAAC,GAAG;IAFhC,OAAO,CAAC,GAAG,CAAM;gBAEY,GAAG,EAAE,MAAM;IAMxC,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,EAAE,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE;IAwB3D,oEAAoE;IACpE,KAAK,IAAI,MAAM,EAAE;CAMlB"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Splits arriving stdio chunks on '\n'. Caps a single message at `max` bytes
|
|
3
|
+
* — when a line grows past that without a newline, the buffer is dropped.
|
|
4
|
+
*/
|
|
5
|
+
export class LineBuffer {
|
|
6
|
+
max;
|
|
7
|
+
buf = '';
|
|
8
|
+
constructor(max) {
|
|
9
|
+
this.max = max;
|
|
10
|
+
if (!Number.isFinite(max) || max <= 0) {
|
|
11
|
+
throw new Error('pecta:LineBuffer: max must be positive');
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
push(chunk) {
|
|
15
|
+
this.buf += chunk;
|
|
16
|
+
const lines = [];
|
|
17
|
+
let oversized = 0;
|
|
18
|
+
while (true) {
|
|
19
|
+
const nl = this.buf.indexOf('\n');
|
|
20
|
+
if (nl === -1) {
|
|
21
|
+
if (this.buf.length > this.max) {
|
|
22
|
+
oversized++;
|
|
23
|
+
this.buf = '';
|
|
24
|
+
}
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
const line = this.buf.slice(0, nl);
|
|
28
|
+
this.buf = this.buf.slice(nl + 1);
|
|
29
|
+
if (line.length > this.max) {
|
|
30
|
+
oversized++;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
lines.push(line);
|
|
34
|
+
}
|
|
35
|
+
return { lines, oversized };
|
|
36
|
+
}
|
|
37
|
+
/** Force-flush any trailing partial buffer (e.g. on stream end). */
|
|
38
|
+
flush() {
|
|
39
|
+
if (this.buf.length === 0)
|
|
40
|
+
return [];
|
|
41
|
+
const out = this.buf.length > this.max ? [] : [this.buf];
|
|
42
|
+
this.buf = '';
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=line-buffer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"line-buffer.js","sourceRoot":"","sources":["../../src/line-buffer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,OAAO,UAAU;IAGQ;IAFrB,GAAG,GAAG,EAAE,CAAC;IAEjB,YAA6B,GAAW;QAAX,QAAG,GAAH,G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M,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACzD,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;QACd,OAAO,GAAG,CAAC;IACb,CAAC;CACF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface JsonlLoggerOptions {
|
|
2
|
+
dir?: string;
|
|
3
|
+
retentionDays?: number;
|
|
4
|
+
/** Inject a clock for tests. */
|
|
5
|
+
now?: () => number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Append-only JSONL logger. One file per UTC day. Auto-rotates files older
|
|
9
|
+
* than retentionDays. Never throws — errors go silently to stderr.
|
|
10
|
+
*/
|
|
11
|
+
export declare class JsonlLogger {
|
|
12
|
+
private readonly dir;
|
|
13
|
+
private readonly retentionDays;
|
|
14
|
+
private readonly now;
|
|
15
|
+
private ensureDirOnce;
|
|
16
|
+
constructor(opts?: JsonlLoggerOptions);
|
|
17
|
+
log(entry: Record<string, unknown>): Promise<void>;
|
|
18
|
+
/** Delete .jsonl files older than retentionDays. Safe to call repeatedly. */
|
|
19
|
+
rotate(): Promise<void>;
|
|
20
|
+
private ensureDir;
|
|
21
|
+
private todayKey;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,kBAAkB;IACjC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gCAAgC;IAChC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;IACnC,OAAO,CAAC,aAAa,CAA8B;gBAEvC,IAAI,GAAE,kBAAuB;IAMnC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAYxD,6EAA6E;IACvE,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;YAoBf,SAAS;IAOvB,OAAO,CAAC,QAAQ;CAGjB"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { mkdir, appendFile, readdir, stat, unlink } from 'node:fs/promises';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
const DEFAULT_DIR = path.join(homedir(), '.pecta', 'logs');
|
|
5
|
+
const RETENTION_DAYS = 7;
|
|
6
|
+
const MS_PER_DAY = 86_400_000;
|
|
7
|
+
/**
|
|
8
|
+
* Append-only JSONL logger. One file per UTC day. Auto-rotates files older
|
|
9
|
+
* than retentionDays. Never throws — errors go silently to stderr.
|
|
10
|
+
*/
|
|
11
|
+
export class JsonlLogger {
|
|
12
|
+
dir;
|
|
13
|
+
retentionDays;
|
|
14
|
+
now;
|
|
15
|
+
ensureDirOnce = null;
|
|
16
|
+
constructor(opts = {}) {
|
|
17
|
+
this.dir = opts.dir ?? DEFAULT_DIR;
|
|
18
|
+
this.retentionDays = opts.retentionDays ?? RETENTION_DAYS;
|
|
19
|
+
this.now = opts.now ?? Date.now;
|
|
20
|
+
}
|
|
21
|
+
async log(entry) {
|
|
22
|
+
try {
|
|
23
|
+
await this.ensureDir();
|
|
24
|
+
const file = path.join(this.dir, `${this.todayKey()}.jsonl`);
|
|
25
|
+
await appendFile(file, `${JSON.stringify(entry)}\n`, 'utf8');
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
process.stderr.write(`pecta-proxy: log write failed: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** Delete .jsonl files older than retentionDays. Safe to call repeatedly. */
|
|
32
|
+
async rotate() {
|
|
33
|
+
try {
|
|
34
|
+
await this.ensureDir();
|
|
35
|
+
const files = await readdir(this.dir);
|
|
36
|
+
const cutoff = this.now() - this.retentionDays * MS_PER_DAY;
|
|
37
|
+
await Promise.all(files.map(async (f) => {
|
|
38
|
+
if (!f.endsWith('.jsonl'))
|
|
39
|
+
return;
|
|
40
|
+
const fp = path.join(this.dir, f);
|
|
41
|
+
const s = await stat(fp);
|
|
42
|
+
if (s.mtimeMs < cutoff) {
|
|
43
|
+
await unlink(fp);
|
|
44
|
+
}
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
// never throw from a logger
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async ensureDir() {
|
|
52
|
+
if (!this.ensureDirOnce) {
|
|
53
|
+
this.ensureDirOnce = mkdir(this.dir, { recursive: true }).then(() => undefined);
|
|
54
|
+
}
|
|
55
|
+
await this.ensureDirOnce;
|
|
56
|
+
}
|
|
57
|
+
todayKey() {
|
|
58
|
+
return new Date(this.now()).toISOString().slice(0, 10);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;AAC3D,MAAM,cAAc,GAAG,CAAC,CAAC;AACzB,MAAM,UAAU,GAAG,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,CACf,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;gBACpB,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;oBAAE,OAAO;gBAClC,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;gBAClC,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,CAAC;gBACzB,IAAI,CAAC,CAAC,OAAO,GAAG,MAAM,EAAE,CAAC;oBACvB,MAAM,MAAM,CAAC,EAAE,CAAC,CAAC;gBACnB,CAAC;YACH,CAAC,CAAC,CACH,CAAC;QACJ,CAAC;QAAC,MAAM,CAAC;YACP,4BAA4B;QAC9B,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,SAAS;QACrB,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;YACxB,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAClF,CAAC;QACD,MAAM,IAAI,CAAC,aAAa,CAAC;IAC3B,CAAC;IAEO,QAAQ;QACd,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACzD,CAAC;CACF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Engine, EvaluationResult } from '@pecta/core';
|
|
2
|
+
export interface PipelineOptions {
|
|
3
|
+
engine: Engine;
|
|
4
|
+
/** Treat agent identifier surfaced to telemetry as this string. */
|
|
5
|
+
agentId: string;
|
|
6
|
+
/** Forward the original response even when gates fail. Just log. */
|
|
7
|
+
dryRun?: boolean;
|
|
8
|
+
/** Called for every evaluation — used for logging + telemetry. */
|
|
9
|
+
onEvaluation?: (result: EvaluationResult, blocked: boolean, toolName?: string) => void;
|
|
10
|
+
}
|
|
11
|
+
export declare class ProxyPipeline {
|
|
12
|
+
private readonly opts;
|
|
13
|
+
private readonly pending;
|
|
14
|
+
constructor(opts: PipelineOptions);
|
|
15
|
+
/** Inspect a parent→child line; record tools/call requests so we can match the response. */
|
|
16
|
+
onIncomingLine(line: string): void;
|
|
17
|
+
/**
|
|
18
|
+
* Inspect a child→parent line. Returns the line to forward — possibly a
|
|
19
|
+
* synthetic JSON-RPC error response when gates fail and dryRun is off.
|
|
20
|
+
*/
|
|
21
|
+
onOutgoingLine(line: string): Promise<string>;
|
|
22
|
+
/** Number of in-flight tools/call requests we are tracking. */
|
|
23
|
+
get pendingSize(): number;
|
|
24
|
+
private runGates;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=pipeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../../src/pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAU5D,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,mEAAmE;IACnE,OAAO,EAAE,MAAM,CAAC;IAChB,oEAAoE;IACpE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,kEAAkE;IAClE,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,gBAAgB,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;CACxF;AASD,qBAAa,aAAa;IAGZ,OAAO,CAAC,QAAQ,CAAC,IAAI;IAFjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA2C;gBAEtC,IAAI,EAAE,eAAe;IAElD,4FAA4F;IAC5F,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAUlC;;;OAGG;IACG,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAwBnD,+DAA+D;IAC/D,IAAI,WAAW,IAAI,MAAM,CAExB;YAEa,QAAQ;CAcvB"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { buildErrorResponse, extractToolName, isResponse, isToolCallRequest, parseMessage, } from './jsonrpc.js';
|
|
2
|
+
const PECTA_ERROR_CODE = -32000;
|
|
3
|
+
export class ProxyPipeline {
|
|
4
|
+
opts;
|
|
5
|
+
pending = new Map();
|
|
6
|
+
constructor(opts) {
|
|
7
|
+
this.opts = opts;
|
|
8
|
+
}
|
|
9
|
+
/** Inspect a parent→child line; record tools/call requests so we can match the response. */
|
|
10
|
+
onIncomingLine(line) {
|
|
11
|
+
const msg = parseMessage(line);
|
|
12
|
+
if (!msg)
|
|
13
|
+
return;
|
|
14
|
+
if (!isToolCallRequest(msg))
|
|
15
|
+
return;
|
|
16
|
+
this.pending.set(msg.id, {
|
|
17
|
+
toolName: extractToolName(msg),
|
|
18
|
+
startedAt: Date.now(),
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Inspect a child→parent line. Returns the line to forward — possibly a
|
|
23
|
+
* synthetic JSON-RPC error response when gates fail and dryRun is off.
|
|
24
|
+
*/
|
|
25
|
+
async onOutgoingLine(line) {
|
|
26
|
+
const msg = parseMessage(line);
|
|
27
|
+
if (!msg)
|
|
28
|
+
return line; // unparseable / non-JSON-RPC: forward as-is
|
|
29
|
+
if (!isResponse(msg))
|
|
30
|
+
return line;
|
|
31
|
+
if (msg.id === null)
|
|
32
|
+
return line;
|
|
33
|
+
const pending = this.pending.get(msg.id);
|
|
34
|
+
if (!pending)
|
|
35
|
+
return line;
|
|
36
|
+
this.pending.delete(msg.id);
|
|
37
|
+
const result = await this.runGates(msg, pending);
|
|
38
|
+
const blocked = !result.passed && this.opts.dryRun !== true;
|
|
39
|
+
this.opts.onEvaluation?.(result, blocked, pending.toolName);
|
|
40
|
+
if (!blocked)
|
|
41
|
+
return line;
|
|
42
|
+
const replacement = buildErrorResponse(msg.id, PECTA_ERROR_CODE, 'pecta: tool call blocked by quality gate', { gates: failingGateSummary(result) });
|
|
43
|
+
return JSON.stringify(replacement);
|
|
44
|
+
}
|
|
45
|
+
/** Number of in-flight tools/call requests we are tracking. */
|
|
46
|
+
get pendingSize() {
|
|
47
|
+
return this.pending.size;
|
|
48
|
+
}
|
|
49
|
+
async runGates(msg, pending) {
|
|
50
|
+
const m = msg;
|
|
51
|
+
const output = m.result !== undefined ? m.result : m.error;
|
|
52
|
+
const latency_ms = Date.now() - pending.startedAt;
|
|
53
|
+
return this.opts.engine.evaluate({
|
|
54
|
+
agent_id: this.opts.agentId,
|
|
55
|
+
...(pending.toolName ? { tool: pending.toolName } : {}),
|
|
56
|
+
output,
|
|
57
|
+
latency_ms,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function failingGateSummary(result) {
|
|
62
|
+
return result.gates
|
|
63
|
+
.filter((g) => !g.passed && g.skipped !== true)
|
|
64
|
+
.map((g) => (g.reason !== undefined ? { name: g.name, reason: g.reason } : { name: g.name }));
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=pipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../../src/pipeline.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,UAAU,EACV,iBAAiB,EACjB,YAAY,GAEb,MAAM,cAAc,CAAC;AAYtB,MAAM,gBAAgB,GAAG,CAAC,KAAK,CAAC;AAOhC,MAAM,OAAO,aAAa;IAGK;IAFZ,OAAO,GAAG,IAAI,GAAG,EAAgC,CAAC;IAEnE,YAA6B,IAAqB;QAArB,SAAI,GAAJ,IAAI,CAAiB;IAAG,CAAC;IAEtD,4FAA4F;IAC5F,cAAc,CAAC,IAAY;QACzB,MAAM,GAAG,GAAG,YAAY,CAA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CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AAClG,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Engine, PectaTelemetry } from '@pecta/core';
|
|
2
|
+
import type { JsonlLogger } from './logger.js';
|
|
3
|
+
export interface RunProxyOptions {
|
|
4
|
+
command: string;
|
|
5
|
+
args: string[];
|
|
6
|
+
engine: Engine;
|
|
7
|
+
agentId: string;
|
|
8
|
+
dryRun?: boolean;
|
|
9
|
+
verbose?: boolean;
|
|
10
|
+
maxMessageSize?: number;
|
|
11
|
+
telemetry?: PectaTelemetry;
|
|
12
|
+
logger?: JsonlLogger;
|
|
13
|
+
/** Override stdio for tests. Defaults to the parent process streams. */
|
|
14
|
+
stdin?: NodeJS.ReadableStream;
|
|
15
|
+
stdout?: NodeJS.WritableStream;
|
|
16
|
+
stderr?: NodeJS.WritableStream;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Spawn an MCP server as a child process and run gates on its tools/call
|
|
20
|
+
* responses. Resolves with the child's exit code.
|
|
21
|
+
*/
|
|
22
|
+
export declare function runProxy(opts: RunProxyOptions): Promise<number>;
|
|
23
|
+
//# sourceMappingURL=proxy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../src/proxy.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAoB,cAAc,EAAE,MAAM,aAAa,CAAC;AAE5E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,wEAAwE;IACxE,KAAK,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC;CAChC;AAID;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CA+B/D"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { LineBuffer } from './line-buffer.js';
|
|
3
|
+
import { ProxyPipeline } from './pipeline.js';
|
|
4
|
+
const DEFAULT_MAX_MESSAGE_SIZE = 1_048_576; // 1 MiB
|
|
5
|
+
/**
|
|
6
|
+
* Spawn an MCP server as a child process and run gates on its tools/call
|
|
7
|
+
* responses. Resolves with the child's exit code.
|
|
8
|
+
*/
|
|
9
|
+
export function runProxy(opts) {
|
|
10
|
+
const max = opts.maxMessageSize ?? DEFAULT_MAX_MESSAGE_SIZE;
|
|
11
|
+
const stdin = opts.stdin ?? process.stdin;
|
|
12
|
+
const stdout = opts.stdout ?? process.stdout;
|
|
13
|
+
const stderr = opts.stderr ?? process.stderr;
|
|
14
|
+
const pipeline = new ProxyPipeline({
|
|
15
|
+
engine: opts.engine,
|
|
16
|
+
agentId: opts.agentId,
|
|
17
|
+
...(opts.dryRun !== undefined ? { dryRun: opts.dryRun } : {}),
|
|
18
|
+
onEvaluation: (result, blocked, toolName) => {
|
|
19
|
+
handleEvaluation(result, blocked, toolName, opts, stderr);
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
const child = spawn(opts.command, opts.args, { stdio: ['pipe', 'pipe', 'inherit'] });
|
|
23
|
+
wireStdin(stdin, child, pipeline, max, stderr);
|
|
24
|
+
wireStdout(child, stdout, pipeline, max, stderr);
|
|
25
|
+
wireSignals(child);
|
|
26
|
+
return new Promise((resolve) => {
|
|
27
|
+
child.on('error', (err) => {
|
|
28
|
+
stderr.write(`pecta-proxy: child failed to spawn: ${err.message}\n`);
|
|
29
|
+
resolve(1);
|
|
30
|
+
});
|
|
31
|
+
child.on('exit', (code, signal) => {
|
|
32
|
+
if (signal)
|
|
33
|
+
stderr.write(`pecta-proxy: child exited via ${signal}\n`);
|
|
34
|
+
resolve(code ?? 0);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function wireStdin(stdin, child, pipeline, max, stderr) {
|
|
39
|
+
const buffer = new LineBuffer(max);
|
|
40
|
+
stdin.on('data', (chunk) => {
|
|
41
|
+
const text = typeof chunk === 'string' ? chunk : chunk.toString('utf8');
|
|
42
|
+
const { lines, oversized } = buffer.push(text);
|
|
43
|
+
if (oversized > 0) {
|
|
44
|
+
stderr.write(`pecta-proxy: dropped ${oversized} oversized inbound message(s)\n`);
|
|
45
|
+
}
|
|
46
|
+
for (const line of lines) {
|
|
47
|
+
pipeline.onIncomingLine(line);
|
|
48
|
+
child.stdin?.write(`${line}\n`);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
stdin.on('end', () => {
|
|
52
|
+
for (const line of buffer.flush()) {
|
|
53
|
+
pipeline.onIncomingLine(line);
|
|
54
|
+
child.stdin?.write(`${line}\n`);
|
|
55
|
+
}
|
|
56
|
+
child.stdin?.end();
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function wireStdout(child, stdout, pipeline, max, stderr) {
|
|
60
|
+
const buffer = new LineBuffer(max);
|
|
61
|
+
// Serialize gate evaluation per-line so output ordering matches input.
|
|
62
|
+
let queue = Promise.resolve();
|
|
63
|
+
const handle = (chunk) => {
|
|
64
|
+
const text = typeof chunk === 'string' ? chunk : chunk.toString('utf8');
|
|
65
|
+
const { lines, oversized } = buffer.push(text);
|
|
66
|
+
if (oversized > 0) {
|
|
67
|
+
stderr.write(`pecta-proxy: dropped ${oversized} oversized outbound message(s)\n`);
|
|
68
|
+
}
|
|
69
|
+
for (const line of lines) {
|
|
70
|
+
queue = queue.then(async () => {
|
|
71
|
+
try {
|
|
72
|
+
const out = await pipeline.onOutgoingLine(line);
|
|
73
|
+
stdout.write(`${out}\n`);
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
stderr.write(`pecta-proxy: pipeline error: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
77
|
+
stdout.write(`${line}\n`);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
child.stdout?.on('data', handle);
|
|
83
|
+
child.stdout?.on('end', () => {
|
|
84
|
+
for (const tail of buffer.flush()) {
|
|
85
|
+
queue = queue.then(async () => {
|
|
86
|
+
try {
|
|
87
|
+
const out = await pipeline.onOutgoingLine(tail);
|
|
88
|
+
stdout.write(`${out}\n`);
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
stdout.write(`${tail}\n`);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function wireSignals(child) {
|
|
98
|
+
const forward = (sig) => () => {
|
|
99
|
+
try {
|
|
100
|
+
child.kill(sig);
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// child may already be gone
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
process.once('SIGTERM', forward('SIGTERM'));
|
|
107
|
+
process.once('SIGINT', forward('SIGINT'));
|
|
108
|
+
}
|
|
109
|
+
function handleEvaluation(result, blocked, toolName, opts, stderr) {
|
|
110
|
+
if (opts.verbose) {
|
|
111
|
+
const summary = result.gates
|
|
112
|
+
.map((g) => `${g.name}=${g.skipped ? 'skip' : g.passed ? 'pass' : 'FAIL'}`)
|
|
113
|
+
.join(' ');
|
|
114
|
+
stderr.write(`pecta-proxy: ${blocked ? 'BLOCKED' : 'allowed'} tool=${toolName ?? '?'} ${summary} (${result.total_latency_ms.toFixed(1)}ms)\n`);
|
|
115
|
+
}
|
|
116
|
+
opts.telemetry?.track(result);
|
|
117
|
+
if (opts.logger) {
|
|
118
|
+
void opts.logger.log({
|
|
119
|
+
timestamp: result.timestamp,
|
|
120
|
+
agent_id: result.agent_id,
|
|
121
|
+
tool: toolName,
|
|
122
|
+
passed: result.passed,
|
|
123
|
+
blocked,
|
|
124
|
+
total_latency_ms: result.total_latency_ms,
|
|
125
|
+
gates: result.gates.map((g) => ({
|
|
126
|
+
name: g.name,
|
|
127
|
+
passed: g.passed,
|
|
128
|
+
...(g.reason ? { reason: g.reason } : {}),
|
|
129
|
+
...(g.skipped ? { skipped: true } : {}),
|
|
130
|
+
})),
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=proxy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../src/proxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAqB,MAAM,oBAAoB,CAAC;AAE9D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAkB9C,MAAM,wBAAwB,GAAG,SAAS,CAAC,CAAC,QAAQ;AAEpD;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAqB;IAC5C,MAAM,GAAG,GAAG,IAAI,CAAC,cAAc,IAAI,wBAAwB,CAAC;IAC5D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC;IAC1C,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC;IAC7C,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC;IAE7C,MAAM,QAAQ,GAAG,IAAI,aAAa,CAAC;QACjC,MAAM,EAAE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gates on tool call responses",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"pecta-proxy": "./dist/bin/pecta-proxy.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"README.md",
|
|
12
|
+
"LICENSE"
|
|
13
|
+
],
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@modelcontextprotocol/sdk": "^1.0.4",
|
|
16
|
+
"commander": "^12.1.0",
|
|
17
|
+
"@pecta/core": "0.1.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/node": "^22.7.5",
|
|
21
|
+
"typescript": "^5.6.3",
|
|
22
|
+
"vitest": "^2.1.3"
|
|
23
|
+
},
|
|
24
|
+
"license": "Apache-2.0",
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsc && chmod +x dist/bin/pecta-proxy.js",
|
|
30
|
+
"test": "vitest run",
|
|
31
|
+
"clean": "rm -rf dist"
|
|
32
|
+
}
|
|
33
|
+
}
|