@deckflow/deckprobe-mcp 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 +22 -0
- package/README.md +244 -0
- package/dist/config.d.ts +28 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +59 -0
- package/dist/config.js.map +1 -0
- package/dist/engine/index.d.ts +11 -0
- package/dist/engine/index.d.ts.map +1 -0
- package/dist/engine/index.js +60 -0
- package/dist/engine/index.js.map +1 -0
- package/dist/engine/native.d.ts +21 -0
- package/dist/engine/native.d.ts.map +1 -0
- package/dist/engine/native.js +193 -0
- package/dist/engine/native.js.map +1 -0
- package/dist/engine/types.d.ts +52 -0
- package/dist/engine/types.d.ts.map +1 -0
- package/dist/engine/types.js +21 -0
- package/dist/engine/types.js.map +1 -0
- package/dist/engine/wasm.d.ts +23 -0
- package/dist/engine/wasm.d.ts.map +1 -0
- package/dist/engine/wasm.js +116 -0
- package/dist/engine/wasm.js.map +1 -0
- package/dist/errors.d.ts +26 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +25 -0
- package/dist/errors.js.map +1 -0
- package/dist/main.d.ts +3 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +68 -0
- package/dist/main.js.map +1 -0
- package/dist/paths.d.ts +9 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +34 -0
- package/dist/paths.js.map +1 -0
- package/dist/result.d.ts +28 -0
- package/dist/result.d.ts.map +1 -0
- package/dist/result.js +101 -0
- package/dist/result.js.map +1 -0
- package/dist/schemas.d.ts +59 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +53 -0
- package/dist/schemas.js.map +1 -0
- package/dist/server.d.ts +5 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +47 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/context.d.ts +7 -0
- package/dist/tools/context.d.ts.map +1 -0
- package/dist/tools/context.js +2 -0
- package/dist/tools/context.js.map +1 -0
- package/dist/tools/discovery.d.ts +4 -0
- package/dist/tools/discovery.d.ts.map +1 -0
- package/dist/tools/discovery.js +130 -0
- package/dist/tools/discovery.js.map +1 -0
- package/dist/tools/probe-batch.d.ts +4 -0
- package/dist/tools/probe-batch.d.ts.map +1 -0
- package/dist/tools/probe-batch.js +97 -0
- package/dist/tools/probe-batch.js.map +1 -0
- package/dist/tools/probe.d.ts +4 -0
- package/dist/tools/probe.d.ts.map +1 -0
- package/dist/tools/probe.js +45 -0
- package/dist/tools/probe.js.map +1 -0
- package/dist/version.d.ts +5 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +7 -0
- package/dist/version.js.map +1 -0
- package/package.json +71 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tenly Wu and DeckProbe contributors
|
|
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.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# DeckProbe MCP Server
|
|
4
|
+
|
|
5
|
+
**Let an agent ask what's inside a PDF, Office, or iWork file — without opening it.**
|
|
6
|
+
|
|
7
|
+
[](https://github.com/deckflow/deckprobe-mcp-server/actions/workflows/ci.yml)
|
|
8
|
+
[](https://www.npmjs.com/package/@deckflow/deckprobe-mcp)
|
|
9
|
+
[](LICENSE)
|
|
10
|
+
|
|
11
|
+
[Install](#install) · [Tools](#tools) · [Configuration](#configuration) · [Security](#security) · [How it works](#how-it-works) · [DeckProbe](https://github.com/deckflow/deckprobe)
|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
An [MCP](https://modelcontextprotocol.io) server that exposes
|
|
16
|
+
[DeckProbe](https://github.com/deckflow/deckprobe) — `ffprobe` for documents — as
|
|
17
|
+
four typed tools. Ask for page counts, slide counts, metadata, encryption and
|
|
18
|
+
macro signals, structure, or integrity, and get back bounded, deterministic JSON
|
|
19
|
+
with confidence, evidence, and measured I/O cost.
|
|
20
|
+
|
|
21
|
+
Nothing is rendered, no macro runs, no external reference is followed, and no
|
|
22
|
+
network connection is opened. It is safe to point at untrusted files.
|
|
23
|
+
|
|
24
|
+
```jsonc
|
|
25
|
+
// probe { "path": "deck.pptx", "targets": ["slide_count"], "view": "values" }
|
|
26
|
+
{
|
|
27
|
+
"schema_version": 2,
|
|
28
|
+
"status": "ok",
|
|
29
|
+
"driver": { "id": "powerpoint", "profile": "pptx" },
|
|
30
|
+
"values": { "powerpoint.slide_count": 31 },
|
|
31
|
+
"view": "values"
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Install
|
|
36
|
+
|
|
37
|
+
Nothing to install ahead of time — `npx` fetches the server and the engine
|
|
38
|
+
together.
|
|
39
|
+
|
|
40
|
+
**Claude Code**
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
claude mcp add deckprobe -- npx -y @deckflow/deckprobe-mcp
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**Claude Desktop, Cursor, VS Code, Zed, and anything else reading `mcpServers`**
|
|
47
|
+
|
|
48
|
+
```jsonc
|
|
49
|
+
{
|
|
50
|
+
"mcpServers": {
|
|
51
|
+
"deckprobe": {
|
|
52
|
+
"command": "npx",
|
|
53
|
+
"args": ["-y", "@deckflow/deckprobe-mcp"]
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
For a pinned install, `npm install -g @deckflow/deckprobe-mcp` and use
|
|
60
|
+
`deckprobe-mcp` as the command.
|
|
61
|
+
|
|
62
|
+
Requires Node.js 20 or newer. The engine binary arrives as a per-platform
|
|
63
|
+
optional dependency for macOS, Linux (glibc and musl), and Windows on x86-64 and
|
|
64
|
+
ARM64; anywhere else the server falls back to the same engine compiled to
|
|
65
|
+
WebAssembly, so `npx` works wherever Node does.
|
|
66
|
+
|
|
67
|
+
## Tools
|
|
68
|
+
|
|
69
|
+
| Tool | Use it for |
|
|
70
|
+
| --- | --- |
|
|
71
|
+
| `probe` | Everything about one document |
|
|
72
|
+
| `probe_batch` | Inventory or triage many documents in one call |
|
|
73
|
+
| `list_formats` | Which formats are supported, and where support stops |
|
|
74
|
+
| `list_targets` | The exact target names a format offers |
|
|
75
|
+
|
|
76
|
+
There is also one resource, `deckprobe://schema`, carrying the report JSON
|
|
77
|
+
Schema bundled with the running engine.
|
|
78
|
+
|
|
79
|
+
### `probe`
|
|
80
|
+
|
|
81
|
+
```jsonc
|
|
82
|
+
{
|
|
83
|
+
"path": "reports/q3.pptx",
|
|
84
|
+
"targets": ["@summary", "@security"], // presets, short names, or canonical names
|
|
85
|
+
"level": "metadata", // header | metadata | deep
|
|
86
|
+
"min_confidence": "high", // low | medium | high | exact
|
|
87
|
+
"target_confidence": { "slide_count": "exact" },
|
|
88
|
+
"view": "report", // report | values
|
|
89
|
+
"budget": { "max_physical_bytes": 8388608, "timeout_ms": 1000 }
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
`targets` accepts short names (`slide_count`), canonical names
|
|
94
|
+
(`powerpoint.slide_count`), and presets:
|
|
95
|
+
|
|
96
|
+
| Preset | Expands to |
|
|
97
|
+
| --- | --- |
|
|
98
|
+
| `@header` | Container identity only — format, size, extension match, encryption flag |
|
|
99
|
+
| `@summary` | Identity, common metadata, and primary structure |
|
|
100
|
+
| `@security` | Encryption, macros, signatures, external references, active content |
|
|
101
|
+
| `@structure` | Format-owned counts, names, and dimensions |
|
|
102
|
+
| `@assets` | Images, media, previews, fonts, embedded objects |
|
|
103
|
+
| `@quality` | Integrity, repair, extension match, conformance |
|
|
104
|
+
| `@format` | Every format-specific target at the active level |
|
|
105
|
+
| `@all` | Everything available at the active level |
|
|
106
|
+
|
|
107
|
+
`@summary` deliberately omits statistics that need a full-file read. A PDF's
|
|
108
|
+
`page_count` is the notable case — ask for it explicitly.
|
|
109
|
+
|
|
110
|
+
### `probe_batch`
|
|
111
|
+
|
|
112
|
+
```jsonc
|
|
113
|
+
{ "paths": ["a.pdf", "b.pptx", "c.xlsx"], "targets": ["@security"] }
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
One engine process handles the whole batch. Results come back in input order,
|
|
117
|
+
each with its own report or its own error, so one bad file never spoils the run.
|
|
118
|
+
Defaults to the compact `values` view. Literal paths only — expand globs
|
|
119
|
+
yourself.
|
|
120
|
+
|
|
121
|
+
### `list_formats` and `list_targets`
|
|
122
|
+
|
|
123
|
+
`list_targets` takes a `format` (`pdf`, `docx`, `xlsx`, `pptx`, `doc`, `xls`,
|
|
124
|
+
`ppt`, `key`, `numbers`, `pages`) and returns each target's aliases,
|
|
125
|
+
description, value type, minimum level, cost class, and selector membership.
|
|
126
|
+
Pass `detail: "full"` for the engine's complete report, including per-target
|
|
127
|
+
JSON Schema fragments and expanded selector lists.
|
|
128
|
+
|
|
129
|
+
Both are cached for the lifetime of the server process.
|
|
130
|
+
|
|
131
|
+
## Reading a report
|
|
132
|
+
|
|
133
|
+
The tool result is the engine's own schema-v2 envelope, unmodified. Two things
|
|
134
|
+
are worth knowing before consuming it:
|
|
135
|
+
|
|
136
|
+
- **`status: "partial"` is not a failure.** It means at least one requested
|
|
137
|
+
target could not be resolved at the requested confidence. It is named in
|
|
138
|
+
`execution.unresolved_targets`, and every other result still stands.
|
|
139
|
+
- **`confidence_score` is a fixed constant per label** (`0.4`, `0.7`, `0.95`,
|
|
140
|
+
`1.0`), not a calibrated probability. `0.95` does not mean the value is right
|
|
141
|
+
95% of the time.
|
|
142
|
+
|
|
143
|
+
Only results with status `resolved` or `estimated` carry a `value`. `unknown` is
|
|
144
|
+
common and usually means the document simply does not record that fact.
|
|
145
|
+
|
|
146
|
+
A failing call returns `isError` with the engine's error envelope plus one line
|
|
147
|
+
saying what to do about it. Failures the server itself raises before the engine
|
|
148
|
+
runs — a missing path, a directory, a path outside the allow-list, an exceeded
|
|
149
|
+
deadline — use the same envelope shape with an `MCP_`-prefixed code and
|
|
150
|
+
`origin: "mcp-server"`.
|
|
151
|
+
|
|
152
|
+
## Configuration
|
|
153
|
+
|
|
154
|
+
Every setting is an environment variable, set in your client's MCP config.
|
|
155
|
+
All are optional.
|
|
156
|
+
|
|
157
|
+
| Variable | Default | Meaning |
|
|
158
|
+
| --- | --- | --- |
|
|
159
|
+
| `DECKPROBE_MCP_BIN` | – | Engine binary to use instead of the bundled one |
|
|
160
|
+
| `DECKPROBE_MCP_ROOTS` | unrestricted | Allowed directories, separated like `PATH` |
|
|
161
|
+
| `DECKPROBE_MCP_TIMEOUT_MS` | `30000` | Hard per-call deadline on an engine process |
|
|
162
|
+
| `DECKPROBE_MCP_MAX_CONCURRENCY` | `4` | Concurrent engine processes |
|
|
163
|
+
| `DECKPROBE_MCP_MAX_BATCH` | `64` | Paths accepted by one `probe_batch` call |
|
|
164
|
+
|
|
165
|
+
```jsonc
|
|
166
|
+
{
|
|
167
|
+
"deckprobe": {
|
|
168
|
+
"command": "npx",
|
|
169
|
+
"args": ["-y", "@deckflow/deckprobe-mcp"],
|
|
170
|
+
"env": { "DECKPROBE_MCP_ROOTS": "/Users/me/Documents:/Users/me/Downloads" }
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Security
|
|
176
|
+
|
|
177
|
+
DeckProbe is built for untrusted input: bounded parsing, no renderer, no macro
|
|
178
|
+
interpreter, no external-reference resolution, and no network access. This
|
|
179
|
+
server adds two things on top.
|
|
180
|
+
|
|
181
|
+
- **Process isolation and a hard deadline.** Each probe runs in its own
|
|
182
|
+
short-lived process, killed if it outruns `DECKPROBE_MCP_TIMEOUT_MS`.
|
|
183
|
+
- **An optional read allow-list.** `DECKPROBE_MCP_ROOTS` pins the reachable
|
|
184
|
+
tree; paths are symlink-resolved before the check, so a link cannot step
|
|
185
|
+
around it. The default is unrestricted, matching the CLI the user could run
|
|
186
|
+
themselves — set it for shared or automated deployments.
|
|
187
|
+
|
|
188
|
+
Reports describe a document (metadata, counts, signals) rather than reproducing
|
|
189
|
+
its contents. Note that report values such as a document title are still
|
|
190
|
+
attacker-controlled strings: the server passes them through as JSON data and
|
|
191
|
+
never interpolates them into instructions, and a consumer should treat them the
|
|
192
|
+
same way.
|
|
193
|
+
|
|
194
|
+
Report a vulnerability privately as described in [SECURITY.md](SECURITY.md).
|
|
195
|
+
|
|
196
|
+
## How it works
|
|
197
|
+
|
|
198
|
+
```text
|
|
199
|
+
MCP client
|
|
200
|
+
│ JSON-RPC over stdio
|
|
201
|
+
▼
|
|
202
|
+
deckprobe-mcp ── validates arguments, resolves the path, maps the result
|
|
203
|
+
│ argv + stdout (one process per probe, or one --jsonl process per batch)
|
|
204
|
+
▼
|
|
205
|
+
DeckProbe engine ── plans the cheapest paths that answer the request
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
The server spawns the native DeckProbe CLI rather than calling the WebAssembly
|
|
209
|
+
build. The CLI reads only the byte ranges a probe plan needs, where the
|
|
210
|
+
WebAssembly path holds the whole file in memory, and a separate OS process both
|
|
211
|
+
isolates untrusted parsing and can be killed outright. The engine is chosen in
|
|
212
|
+
this order:
|
|
213
|
+
|
|
214
|
+
1. `DECKPROBE_MCP_BIN`
|
|
215
|
+
2. the binary that ships with this package's `@deckflow/deckprobe` dependency
|
|
216
|
+
3. `deckprobe` on `PATH`
|
|
217
|
+
4. the bundled WebAssembly engine
|
|
218
|
+
|
|
219
|
+
The resolved engine is logged to stderr at startup. stdout belongs to the MCP
|
|
220
|
+
transport and carries nothing else.
|
|
221
|
+
|
|
222
|
+
## MCP server or agent skill?
|
|
223
|
+
|
|
224
|
+
DeckProbe also ships an [Agent Skill](https://github.com/deckflow/deckprobe#use-from-a-coding-agent)
|
|
225
|
+
that teaches a shell-capable agent to use the CLI directly. Both teach the same
|
|
226
|
+
vocabulary. Use the skill when the agent has a shell and you want the CLI's full
|
|
227
|
+
surface; use this server when it does not, or when you want typed arguments
|
|
228
|
+
validated before the engine ever runs.
|
|
229
|
+
|
|
230
|
+
## Development
|
|
231
|
+
|
|
232
|
+
```sh
|
|
233
|
+
npm install
|
|
234
|
+
npm test # typecheck, lint, build, and the full suite
|
|
235
|
+
npm run test:watch
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Contributions are welcome — see [CONTRIBUTING.md](CONTRIBUTING.md). The design
|
|
239
|
+
rationale, including the alternatives that were rejected, is in
|
|
240
|
+
[docs/rfc.md](docs/rfc.md).
|
|
241
|
+
|
|
242
|
+
## License
|
|
243
|
+
|
|
244
|
+
MIT. See [LICENSE](LICENSE).
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare const DEFAULT_TIMEOUT_MS = 30000;
|
|
2
|
+
export declare const DEFAULT_MAX_CONCURRENCY = 4;
|
|
3
|
+
export declare const DEFAULT_MAX_BATCH = 64;
|
|
4
|
+
export interface Config {
|
|
5
|
+
/** Explicit engine binary, from `DECKPROBE_MCP_BIN`. */
|
|
6
|
+
readonly binOverride: string | undefined;
|
|
7
|
+
/** Allowed directory roots. Empty means unrestricted. */
|
|
8
|
+
readonly roots: readonly string[];
|
|
9
|
+
/** Hard per-call deadline on an engine process. */
|
|
10
|
+
readonly timeoutMs: number;
|
|
11
|
+
/** Maximum engine processes running at once, across every tool. */
|
|
12
|
+
readonly maxConcurrency: number;
|
|
13
|
+
/** Maximum paths accepted by one `probe_batch` call. */
|
|
14
|
+
readonly maxBatch: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Absolute, symlink-resolved form of a path. Roots and inputs are both put
|
|
18
|
+
* through this so an allow-list cannot be stepped around with a symlink, and
|
|
19
|
+
* so `/tmp` and `/private/tmp` compare equal on macOS.
|
|
20
|
+
*
|
|
21
|
+
* A path that does not exist yet cannot be resolved; the absolute form is
|
|
22
|
+
* returned instead and the caller's own existence check reports the problem.
|
|
23
|
+
*/
|
|
24
|
+
export declare function canonicalPath(path: string): string;
|
|
25
|
+
/** True when `target` is inside `root`, by path segment rather than string prefix. */
|
|
26
|
+
export declare function isInsideRoot(target: string, root: string): boolean;
|
|
27
|
+
export declare function loadConfig(env?: NodeJS.ProcessEnv): Config;
|
|
28
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,kBAAkB,QAAS,CAAC;AACzC,eAAO,MAAM,uBAAuB,IAAI,CAAC;AACzC,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC,MAAM,WAAW,MAAM;IACrB,wDAAwD;IACxD,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,yDAAyD;IACzD,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,mDAAmD;IACnD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,mEAAmE;IACnE,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,wDAAwD;IACxD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAYD;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAOlD;AAED,sFAAsF;AACtF,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAIlE;AAED,wBAAgB,UAAU,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,MAAM,CAoBvE"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { realpathSync } from "node:fs";
|
|
2
|
+
import { delimiter, isAbsolute, relative, resolve } from "node:path";
|
|
3
|
+
import { ConfigError } from "./errors.js";
|
|
4
|
+
export const DEFAULT_TIMEOUT_MS = 30_000;
|
|
5
|
+
export const DEFAULT_MAX_CONCURRENCY = 4;
|
|
6
|
+
export const DEFAULT_MAX_BATCH = 64;
|
|
7
|
+
function readPositiveInt(env, name, fallback) {
|
|
8
|
+
const raw = env[name];
|
|
9
|
+
if (raw === undefined || raw.trim() === "")
|
|
10
|
+
return fallback;
|
|
11
|
+
const parsed = Number(raw);
|
|
12
|
+
if (!Number.isSafeInteger(parsed) || parsed <= 0) {
|
|
13
|
+
throw new ConfigError(`${name} must be a positive integer, got ${JSON.stringify(raw)}`);
|
|
14
|
+
}
|
|
15
|
+
return parsed;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Absolute, symlink-resolved form of a path. Roots and inputs are both put
|
|
19
|
+
* through this so an allow-list cannot be stepped around with a symlink, and
|
|
20
|
+
* so `/tmp` and `/private/tmp` compare equal on macOS.
|
|
21
|
+
*
|
|
22
|
+
* A path that does not exist yet cannot be resolved; the absolute form is
|
|
23
|
+
* returned instead and the caller's own existence check reports the problem.
|
|
24
|
+
*/
|
|
25
|
+
export function canonicalPath(path) {
|
|
26
|
+
const absolute = resolve(path);
|
|
27
|
+
try {
|
|
28
|
+
return realpathSync(absolute);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return absolute;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** True when `target` is inside `root`, by path segment rather than string prefix. */
|
|
35
|
+
export function isInsideRoot(target, root) {
|
|
36
|
+
if (target === root)
|
|
37
|
+
return true;
|
|
38
|
+
const rel = relative(root, target);
|
|
39
|
+
return rel !== "" && !rel.startsWith("..") && !isAbsolute(rel);
|
|
40
|
+
}
|
|
41
|
+
export function loadConfig(env = process.env) {
|
|
42
|
+
const rawRoots = env.DECKPROBE_MCP_ROOTS;
|
|
43
|
+
const roots = rawRoots === undefined || rawRoots.trim() === ""
|
|
44
|
+
? []
|
|
45
|
+
: rawRoots
|
|
46
|
+
.split(delimiter)
|
|
47
|
+
.map((entry) => entry.trim())
|
|
48
|
+
.filter((entry) => entry !== "")
|
|
49
|
+
.map(canonicalPath);
|
|
50
|
+
const binOverride = env.DECKPROBE_MCP_BIN?.trim();
|
|
51
|
+
return {
|
|
52
|
+
binOverride: binOverride === "" ? undefined : binOverride,
|
|
53
|
+
roots,
|
|
54
|
+
timeoutMs: readPositiveInt(env, "DECKPROBE_MCP_TIMEOUT_MS", DEFAULT_TIMEOUT_MS),
|
|
55
|
+
maxConcurrency: readPositiveInt(env, "DECKPROBE_MCP_MAX_CONCURRENCY", DEFAULT_MAX_CONCURRENCY),
|
|
56
|
+
maxBatch: readPositiveInt(env, "DECKPROBE_MCP_MAX_BATCH", DEFAULT_MAX_BATCH),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=config.js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js";
|
|
3
|
+
export type { Budget, Confidence, Engine, EngineOutcome, ProbeLevel, ProbeRequest, ProbeView, } from "./types.js";
|
|
4
|
+
export { errorCodeOf, exitCodeOf, isRecord } from "./types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Picks the engine, in the order documented in the README:
|
|
7
|
+
* `DECKPROBE_MCP_BIN`, then the binary that came with the `@deckflow/deckprobe`
|
|
8
|
+
* dependency, then `deckprobe` on PATH, then the WebAssembly fallback.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createEngine(config: Config): Promise<Engine>;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/engine/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAG3C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAGzC,YAAY,EACV,MAAM,EACN,UAAU,EACV,MAAM,EACN,aAAa,EACb,UAAU,EACV,YAAY,EACZ,SAAS,GACV,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAiB/D;;;;GAIG;AACH,wBAAsB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAgBlE"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
import { ConfigError } from "../errors.js";
|
|
7
|
+
import { NativeEngine } from "./native.js";
|
|
8
|
+
import { WasmEngine } from "./wasm.js";
|
|
9
|
+
export { errorCodeOf, exitCodeOf, isRecord } from "./types.js";
|
|
10
|
+
const require = createRequire(import.meta.url);
|
|
11
|
+
/**
|
|
12
|
+
* Picks the engine, in the order documented in the README:
|
|
13
|
+
* `DECKPROBE_MCP_BIN`, then the binary that came with the `@deckflow/deckprobe`
|
|
14
|
+
* dependency, then `deckprobe` on PATH, then the WebAssembly fallback.
|
|
15
|
+
*/
|
|
16
|
+
export async function createEngine(config) {
|
|
17
|
+
if (config.binOverride) {
|
|
18
|
+
if (!(await isRunnable(config.binOverride))) {
|
|
19
|
+
throw new ConfigError(`DECKPROBE_MCP_BIN=${config.binOverride} is not a runnable DeckProbe binary`);
|
|
20
|
+
}
|
|
21
|
+
return new NativeEngine(config.binOverride, config);
|
|
22
|
+
}
|
|
23
|
+
const packaged = await resolvePackagedBinary();
|
|
24
|
+
if (packaged)
|
|
25
|
+
return new NativeEngine(packaged, config);
|
|
26
|
+
if (await isRunnable("deckprobe"))
|
|
27
|
+
return new NativeEngine("deckprobe", config);
|
|
28
|
+
return new WasmEngine();
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Resolves the per-platform optional dependency the same way the upstream npm
|
|
32
|
+
* launcher does, by reusing its own platform table — including the musl/glibc
|
|
33
|
+
* detection an independent copy of the table would get wrong.
|
|
34
|
+
*/
|
|
35
|
+
async function resolvePackagedBinary() {
|
|
36
|
+
try {
|
|
37
|
+
const packageRoot = dirname(require.resolve("@deckflow/deckprobe/package.json"));
|
|
38
|
+
const platformsUrl = pathToFileURL(join(packageRoot, "bin", "platforms.js"));
|
|
39
|
+
const platforms = (await import(platformsUrl.href));
|
|
40
|
+
const platform = platforms.currentPlatform();
|
|
41
|
+
if (!platform)
|
|
42
|
+
return undefined;
|
|
43
|
+
const dependencyRoot = dirname(require.resolve(`${platforms.packageName(platform)}/package.json`));
|
|
44
|
+
const binary = join(dependencyRoot, "bin", platforms.binaryName(platform));
|
|
45
|
+
return existsSync(binary) ? binary : undefined;
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
// No platform package for this OS/arch, an install that skipped optional
|
|
49
|
+
// dependencies, or an upstream layout change. Fall through to PATH.
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function isRunnable(binary) {
|
|
54
|
+
return new Promise((settle) => {
|
|
55
|
+
const child = spawn(binary, ["--version"], { stdio: "ignore" });
|
|
56
|
+
child.on("error", () => settle(false));
|
|
57
|
+
child.on("close", (code) => settle(code === 0));
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/engine/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGzC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAWvC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE/D,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAe/C;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,MAAc;IAC/C,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;QACvB,IAAI,CAAC,CAAC,MAAM,UAAU,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC;YAC5C,MAAM,IAAI,WAAW,CACnB,qBAAqB,MAAM,CAAC,WAAW,qCAAqC,CAC7E,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ACnB,CAAC;AACH,CAAC;AAED,SAAS,UAAU,CAAC,MAAc;IAChC,OAAO,IAAI,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;QAC5B,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,WAAW,CAAC,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;QAChE,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACvC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Config } from "../config.js";
|
|
2
|
+
import type { Engine, EngineOutcome, ProbeRequest } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Every option DeckProbe is given comes from here, in `--long=value` form so a
|
|
5
|
+
* target or format name can never be read as a flag. The document path is
|
|
6
|
+
* passed after `--` for the same reason.
|
|
7
|
+
*/
|
|
8
|
+
export declare function probeArgs(request: ProbeRequest): string[];
|
|
9
|
+
export declare class NativeEngine implements Engine {
|
|
10
|
+
#private;
|
|
11
|
+
readonly kind: "native";
|
|
12
|
+
readonly description: string;
|
|
13
|
+
constructor(binary: string, config: Config);
|
|
14
|
+
version(): Promise<string>;
|
|
15
|
+
probe(path: string, request: ProbeRequest): Promise<EngineOutcome>;
|
|
16
|
+
probeBatch(paths: readonly string[], request: ProbeRequest): Promise<EngineOutcome[]>;
|
|
17
|
+
formats(): Promise<EngineOutcome>;
|
|
18
|
+
targets(format: string): Promise<EngineOutcome>;
|
|
19
|
+
schema(): Promise<EngineOutcome>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=native.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../../src/engine/native.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAuCtE;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,EAAE,CAsBzD;AAED,qBAAa,YAAa,YAAW,MAAM;;IACzC,QAAQ,CAAC,IAAI,EAAG,QAAQ,CAAU;IAClC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;gBAMjB,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAOpC,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAK1B,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;IAKlE,UAAU,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAsBrF,OAAO,IAAI,OAAO,CAAC,aAAa,CAAC;IAIjC,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAI/C,MAAM,IAAI,OAAO,CAAC,aAAa,CAAC;CAoHvC"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { ServerError } from "../errors.js";
|
|
3
|
+
import { exitCodeOf } from "./types.js";
|
|
4
|
+
/** Guards against an engine that never stops writing. Reports stay far below this. */
|
|
5
|
+
const MAX_OUTPUT_BYTES = 16 * 1024 * 1024;
|
|
6
|
+
/** Grace period between the polite stop and the hard kill on a timeout. */
|
|
7
|
+
const KILL_GRACE_MS = 2_000;
|
|
8
|
+
class Semaphore {
|
|
9
|
+
#available;
|
|
10
|
+
#waiting = [];
|
|
11
|
+
constructor(permits) {
|
|
12
|
+
this.#available = permits;
|
|
13
|
+
}
|
|
14
|
+
async run(task) {
|
|
15
|
+
if (this.#available > 0) {
|
|
16
|
+
this.#available -= 1;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
await new Promise((release) => this.#waiting.push(release));
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
return await task();
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
const next = this.#waiting.shift();
|
|
26
|
+
if (next)
|
|
27
|
+
next();
|
|
28
|
+
else
|
|
29
|
+
this.#available += 1;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Every option DeckProbe is given comes from here, in `--long=value` form so a
|
|
35
|
+
* target or format name can never be read as a flag. The document path is
|
|
36
|
+
* passed after `--` for the same reason.
|
|
37
|
+
*/
|
|
38
|
+
export function probeArgs(request) {
|
|
39
|
+
const args = [];
|
|
40
|
+
for (const target of request.targets ?? [])
|
|
41
|
+
args.push(`--targets=${target}`);
|
|
42
|
+
if (request.level)
|
|
43
|
+
args.push(`--probe-level=${request.level}`);
|
|
44
|
+
if (request.min_confidence)
|
|
45
|
+
args.push(`--minimum-confidence=${request.min_confidence}`);
|
|
46
|
+
for (const [target, confidence] of Object.entries(request.target_confidence ?? {})) {
|
|
47
|
+
args.push(`--target-confidence=${target}=${confidence}`);
|
|
48
|
+
}
|
|
49
|
+
if (request.view === "values")
|
|
50
|
+
args.push("--view=values");
|
|
51
|
+
const budget = request.budget;
|
|
52
|
+
if (budget?.max_physical_bytes !== undefined) {
|
|
53
|
+
args.push(`--probe-size=${budget.max_physical_bytes}`);
|
|
54
|
+
}
|
|
55
|
+
if (budget?.max_expanded_bytes !== undefined) {
|
|
56
|
+
args.push(`--max-expanded-bytes=${budget.max_expanded_bytes}`);
|
|
57
|
+
}
|
|
58
|
+
if (budget?.max_archive_entries !== undefined) {
|
|
59
|
+
args.push(`--max-archive-entries=${budget.max_archive_entries}`);
|
|
60
|
+
}
|
|
61
|
+
if (budget?.timeout_ms !== undefined)
|
|
62
|
+
args.push(`--timeout-ms=${budget.timeout_ms}`);
|
|
63
|
+
return args;
|
|
64
|
+
}
|
|
65
|
+
export class NativeEngine {
|
|
66
|
+
kind = "native";
|
|
67
|
+
description;
|
|
68
|
+
#binary;
|
|
69
|
+
#timeoutMs;
|
|
70
|
+
#semaphore;
|
|
71
|
+
constructor(binary, config) {
|
|
72
|
+
this.#binary = binary;
|
|
73
|
+
this.#timeoutMs = config.timeoutMs;
|
|
74
|
+
this.#semaphore = new Semaphore(config.maxConcurrency);
|
|
75
|
+
this.description = `native CLI at ${binary}`;
|
|
76
|
+
}
|
|
77
|
+
async version() {
|
|
78
|
+
const { stdout } = await this.#exec(["--version"]);
|
|
79
|
+
return stdout.trim();
|
|
80
|
+
}
|
|
81
|
+
async probe(path, request) {
|
|
82
|
+
const { code, stdout, stderr } = await this.#exec([...probeArgs(request), "--", path]);
|
|
83
|
+
return { exitCode: code, json: this.#parse(stdout, stderr, code) };
|
|
84
|
+
}
|
|
85
|
+
async probeBatch(paths, request) {
|
|
86
|
+
const records = paths.map((path) => JSON.stringify({ path })).join("\n");
|
|
87
|
+
const { stdout, stderr, code } = await this.#exec(["--jsonl", ...probeArgs(request)], `${records}\n`);
|
|
88
|
+
const lines = stdout.split("\n").filter((line) => line.trim() !== "");
|
|
89
|
+
if (lines.length !== paths.length) {
|
|
90
|
+
throw new ServerError("MCP_ENGINE_FAILURE", `expected ${paths.length} JSONL results, received ${lines.length}` +
|
|
91
|
+
`${stderr.trim() ? ` (stderr: ${truncate(stderr.trim(), 400)})` : ""}`);
|
|
92
|
+
}
|
|
93
|
+
return lines.map((line) => {
|
|
94
|
+
const json = this.#parse(line, stderr, code);
|
|
95
|
+
return { exitCode: exitCodeOf(json), json };
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
async formats() {
|
|
99
|
+
return this.#discovery(["formats"]);
|
|
100
|
+
}
|
|
101
|
+
async targets(format) {
|
|
102
|
+
return this.#discovery(["targets", "--format", format]);
|
|
103
|
+
}
|
|
104
|
+
async schema() {
|
|
105
|
+
return this.#discovery(["schema"]);
|
|
106
|
+
}
|
|
107
|
+
async #discovery(args) {
|
|
108
|
+
const { code, stdout, stderr } = await this.#exec(args);
|
|
109
|
+
return { exitCode: code, json: this.#parse(stdout, stderr, code) };
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* DeckProbe writes one JSON value to stdout for every outcome, success or
|
|
113
|
+
* failure, and never uses stderr for results. Anything else means the binary
|
|
114
|
+
* is not the one we think it is, so stderr is surfaced for diagnosis.
|
|
115
|
+
*/
|
|
116
|
+
#parse(stdout, stderr, code) {
|
|
117
|
+
try {
|
|
118
|
+
return JSON.parse(stdout);
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
const detail = stderr.trim() || stdout.trim() || "(no output)";
|
|
122
|
+
throw new ServerError("MCP_ENGINE_FAILURE", `engine exited with status ${code} and did not write a JSON report: ${truncate(detail, 800)}`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
#exec(args, stdin) {
|
|
126
|
+
return this.#semaphore.run(() => new Promise((settle, fail) => {
|
|
127
|
+
const child = spawn(this.#binary, args, { stdio: ["pipe", "pipe", "pipe"] });
|
|
128
|
+
let stdout = "";
|
|
129
|
+
let stderr = "";
|
|
130
|
+
let overflowed = false;
|
|
131
|
+
let timedOut = false;
|
|
132
|
+
let hardKill;
|
|
133
|
+
const deadline = setTimeout(() => {
|
|
134
|
+
timedOut = true;
|
|
135
|
+
child.kill("SIGTERM");
|
|
136
|
+
hardKill = setTimeout(() => child.kill("SIGKILL"), KILL_GRACE_MS);
|
|
137
|
+
}, this.#timeoutMs);
|
|
138
|
+
const done = () => {
|
|
139
|
+
clearTimeout(deadline);
|
|
140
|
+
if (hardKill)
|
|
141
|
+
clearTimeout(hardKill);
|
|
142
|
+
};
|
|
143
|
+
child.stdout.setEncoding("utf8");
|
|
144
|
+
child.stderr.setEncoding("utf8");
|
|
145
|
+
child.stdout.on("data", (chunk) => {
|
|
146
|
+
if (stdout.length + chunk.length > MAX_OUTPUT_BYTES) {
|
|
147
|
+
overflowed = true;
|
|
148
|
+
child.kill("SIGKILL");
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
stdout += chunk;
|
|
152
|
+
});
|
|
153
|
+
child.stderr.on("data", (chunk) => {
|
|
154
|
+
if (stderr.length < 64 * 1024)
|
|
155
|
+
stderr += chunk;
|
|
156
|
+
});
|
|
157
|
+
child.on("error", (error) => {
|
|
158
|
+
done();
|
|
159
|
+
fail(new ServerError("MCP_ENGINE_FAILURE", `cannot run the DeckProbe engine at ${this.#binary}: ${error.message}`));
|
|
160
|
+
});
|
|
161
|
+
child.on("close", (code, signal) => {
|
|
162
|
+
done();
|
|
163
|
+
if (timedOut) {
|
|
164
|
+
fail(new ServerError("MCP_TIMEOUT", `the probe exceeded the ${this.#timeoutMs} ms server deadline and was stopped`, "Raise DECKPROBE_MCP_TIMEOUT_MS, or lower the probe level or budget so the engine finishes sooner."));
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (overflowed) {
|
|
168
|
+
fail(new ServerError("MCP_ENGINE_FAILURE", `the engine wrote more than ${MAX_OUTPUT_BYTES} bytes and was stopped`));
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (code === null) {
|
|
172
|
+
fail(new ServerError("MCP_ENGINE_FAILURE", `the engine was killed by signal ${signal}`));
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
settle({ code, stdout, stderr });
|
|
176
|
+
});
|
|
177
|
+
if (stdin !== undefined) {
|
|
178
|
+
child.stdin.on("error", () => {
|
|
179
|
+
// A record-level failure can close stdin before the last write
|
|
180
|
+
// lands. The exit status and stdout still carry the outcome.
|
|
181
|
+
});
|
|
182
|
+
child.stdin.end(stdin);
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
child.stdin.end();
|
|
186
|
+
}
|
|
187
|
+
}));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function truncate(text, limit) {
|
|
191
|
+
return text.length <= limit ? text : `${text.slice(0, limit)}…`;
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=native.js.map
|