@gate-forge/plugin-protocol 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/README.md +187 -0
- package/dist/codes.d.ts +77 -0
- package/dist/codes.d.ts.map +1 -0
- package/dist/codes.js +115 -0
- package/dist/codes.js.map +1 -0
- package/dist/framing.d.ts +60 -0
- package/dist/framing.d.ts.map +1 -0
- package/dist/framing.js +153 -0
- package/dist/framing.js.map +1 -0
- package/dist/host.d.ts +61 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +362 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin.d.ts +44 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +133 -0
- package/dist/plugin.js.map +1 -0
- package/dist/schema.d.ts +176 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +142 -0
- package/dist/schema.js.map +1 -0
- package/package.json +41 -0
- package/python/gateforge_plugin/__init__.py +265 -0
- package/python/gateforge_plugin/__pycache__/__init__.cpython-312.pyc +0 -0
- package/python/gateforge_plugin/__pycache__/__init__.cpython-314.pyc +0 -0
- package/python/plugins/reference_detector.py +132 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @gate-forge/plugin-protocol — GPP/3, the hardened subprocess plugin
|
|
3
|
+
* protocol (ADR 0002 D3; GPP/3 signal transport per ADR 0003 D6).
|
|
4
|
+
*
|
|
5
|
+
* Surface:
|
|
6
|
+
* - {@link PluginSession}: the engine-side host (one spawn, many lock-step
|
|
7
|
+
* discovers, watchdog + kill, shutdown handshake).
|
|
8
|
+
* - {@link servePlugin}: the TypeScript plugin SDK.
|
|
9
|
+
* - zod payload schemas for every message (`src/schema.ts`); GPP/3 adds
|
|
10
|
+
* mandatory `classificationSignals` on `result` payloads.
|
|
11
|
+
* - typed failure classes for every E_* code (`src/codes.ts`).
|
|
12
|
+
* - Python client + reference plugin under `python/`.
|
|
13
|
+
*
|
|
14
|
+
* Lineage: spikes/plugin-protocol/spec.md (GPP/1), hardened with
|
|
15
|
+
* pluginVersion pinning, per-message digests, and schema-generated
|
|
16
|
+
* validation per docs/decisions/0002-plugin-boundary.md; GPP/3 clean
|
|
17
|
+
* cutover per docs/decisions/0003-automatic-conservative-classification.md.
|
|
18
|
+
*/
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
// Failure codes, typed errors, diagnostics
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
export { FAILURE_CODES, ProtocolFailure, ProtocolVersionError, UnknownPluginError, FrameJsonError, UnknownTypeError, SchemaError, EofError, TimeoutError, PluginError, ExitStatusError, isProtocolFailure, formatDiagnostic, } from './codes.js';
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
// Message catalog, payload schemas (pin #5)
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
export { PROTOCOL_VERSION, MAX_FRAME_BYTES, MESSAGE_TYPES, REQUIRED_CAPABILITY, SIGNAL_CAPABILITY, HelloPayloadSchema, ReadyPayloadSchema, DiscoverPayloadSchema, ResultPayloadSchema, ErrorPayloadSchema, ShutdownPayloadSchema, ByePayloadSchema, PAYLOAD_SCHEMAS, FindingSchema, firstIssueText, } from './schema.js';
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
// Framing + envelope verification
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
export { extractLines, parseLine, verifyEnvelope, verifyPayload, encodeFrame, } from './framing.js';
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
// Host (engine side)
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
export { PluginSession, DEFAULT_TIMEOUTS } from './host.js';
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
// Plugin SDK (TS side)
|
|
37
|
+
// ---------------------------------------------------------------------------
|
|
38
|
+
export { servePlugin } from './plugin.js';
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,8EAA8E;AAC9E,2CAA2C;AAC3C,8EAA8E;AAE9E,OAAO,EACL,aAAa,EACb,eAAe,EACf,oBAAoB,EACpB,kBAAkB,EAClB,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AAGpB,8EAA8E;AAC9E,4CAA4C;AAC5C,8EAA8E;AAE9E,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,cAAc,GACf,MAAM,aAAa,CAAC;AAGrB,8EAA8E;AAC9E,kCAAkC;AAClC,8EAA8E;AAE9E,OAAO,EACL,YAAY,EACZ,SAAS,EACT,cAAc,EACd,aAAa,EACb,WAAW,GACZ,MAAM,cAAc,CAAC;AAGtB,8EAA8E;AAC9E,qBAAqB;AACrB,8EAA8E;AAE9E,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAG5D,8EAA8E;AAC9E,uBAAuB;AACvB,8EAA8E;AAE9E,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type JsonValue } from '@gate-forge/core';
|
|
2
|
+
import { PROTOCOL_VERSION } from './schema.js';
|
|
3
|
+
/** What a plugin's discover handler must return (GPP/3 contract). */
|
|
4
|
+
export interface DiscoveryResult {
|
|
5
|
+
resources: JsonValue[];
|
|
6
|
+
unresolved: JsonValue[];
|
|
7
|
+
findings: JsonValue[];
|
|
8
|
+
/** Classification-signal facts (ADR 0003 D6); `[]` when unsupported. */
|
|
9
|
+
classificationSignals: JsonValue[];
|
|
10
|
+
/**
|
|
11
|
+
* Optional coverage evidence: repo-root-relative files the handler
|
|
12
|
+
* actually examined successfully. Omitted ⇒ coverage unknown ⇒ the
|
|
13
|
+
* host's complete-scan attestation fails closed.
|
|
14
|
+
*/
|
|
15
|
+
scannedPaths?: JsonValue[];
|
|
16
|
+
}
|
|
17
|
+
/** User-implemented discovery callback. Throw to answer with an `error` frame. */
|
|
18
|
+
export type DiscoverHandler = (paths: readonly string[]) => Promise<DiscoveryResult> | DiscoveryResult;
|
|
19
|
+
/** Options for {@link servePlugin}. */
|
|
20
|
+
export interface ServePluginOptions {
|
|
21
|
+
/** This plugin's declared identity (echoed on every frame). */
|
|
22
|
+
pluginId: string;
|
|
23
|
+
/** This plugin's declared version (pinned by the host at the handshake). */
|
|
24
|
+
pluginVersion: string;
|
|
25
|
+
/** Declared capabilities (default: `['discover']`). */
|
|
26
|
+
capabilities?: readonly string[];
|
|
27
|
+
/** Byte source for host frames (default: `process.stdin`). */
|
|
28
|
+
input?: AsyncIterable<Uint8Array>;
|
|
29
|
+
/** Sink for plugin frames (default: `process.stdout`). */
|
|
30
|
+
output?: {
|
|
31
|
+
write(chunk: Uint8Array | string): unknown;
|
|
32
|
+
};
|
|
33
|
+
/** Line cap in bytes (default: 8 MiB). */
|
|
34
|
+
maxLineBytes?: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Runs the plugin side of a GPP/3 session until the host sends `shutdown`
|
|
38
|
+
* (answered with `bye`) or closes stdin. Throws a {@link ProtocolFailure}
|
|
39
|
+
* if the host violates the protocol (after emitting a session-fatal
|
|
40
|
+
* `error` frame so the host can name the cause).
|
|
41
|
+
*/
|
|
42
|
+
export declare function servePlugin(handler: DiscoverHandler, options: ServePluginOptions): Promise<void>;
|
|
43
|
+
export { PROTOCOL_VERSION };
|
|
44
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAWA,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAG/D,OAAO,EAAE,gBAAgB,EAAyC,MAAM,aAAa,CAAC;AAEtF,qEAAqE;AACrE,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,SAAS,EAAE,CAAC;IACvB,UAAU,EAAE,SAAS,EAAE,CAAC;IACxB,QAAQ,EAAE,SAAS,EAAE,CAAC;IACtB,wEAAwE;IACxE,qBAAqB,EAAE,SAAS,EAAE,CAAC;IACnC;;;;OAIG;IACH,YAAY,CAAC,EAAE,SAAS,EAAE,CAAC;CAC5B;AAED,kFAAkF;AAClF,MAAM,MAAM,eAAe,GAAG,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,KAAK,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,CAAC;AAEvG,uCAAuC;AACvC,MAAM,WAAW,kBAAkB;IACjC,+DAA+D;IAC/D,QAAQ,EAAE,MAAM,CAAC;IACjB,4EAA4E;IAC5E,aAAa,EAAE,MAAM,CAAC;IACtB,uDAAuD;IACvD,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,8DAA8D;IAC9D,KAAK,CAAC,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;IAClC,0DAA0D;IAC1D,MAAM,CAAC,EAAE;QAAE,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IACxD,0CAA0C;IAC1C,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAKD;;;;;GAKG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAoHtG;AAOD,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GPP/3 plugin SDK (TypeScript side): the reference client for plugin
|
|
3
|
+
* authors. Performs the `hello`/`ready` handshake, validates host frames
|
|
4
|
+
* (protocolVersion, pinned identity, seq order, digest), answers
|
|
5
|
+
* `discover` requests through a user handler, and completes the
|
|
6
|
+
* `shutdown`/`bye` handshake.
|
|
7
|
+
*
|
|
8
|
+
* I/O is injectable so the SDK can be driven in-process by tests; in a
|
|
9
|
+
* real plugin it runs over `process.stdin`/`process.stdout`.
|
|
10
|
+
*/
|
|
11
|
+
import { createInterface } from 'node:readline';
|
|
12
|
+
import { isJsonValue } from '@gate-forge/core';
|
|
13
|
+
import { FrameJsonError, ProtocolFailure, SchemaError } from './codes.js';
|
|
14
|
+
import { encodeFrame, extractLines, parseLine, verifyEnvelope, verifyPayload } from './framing.js';
|
|
15
|
+
import { PROTOCOL_VERSION, REQUIRED_CAPABILITY } from './schema.js';
|
|
16
|
+
/** Message types a plugin may legally receive from the host. */
|
|
17
|
+
const HOST_TYPES = ['ready', 'discover', 'shutdown'];
|
|
18
|
+
/**
|
|
19
|
+
* Runs the plugin side of a GPP/3 session until the host sends `shutdown`
|
|
20
|
+
* (answered with `bye`) or closes stdin. Throws a {@link ProtocolFailure}
|
|
21
|
+
* if the host violates the protocol (after emitting a session-fatal
|
|
22
|
+
* `error` frame so the host can name the cause).
|
|
23
|
+
*/
|
|
24
|
+
export async function servePlugin(handler, options) {
|
|
25
|
+
const identity = { pluginId: options.pluginId, pluginVersion: options.pluginVersion };
|
|
26
|
+
const capabilities = options.capabilities ?? [REQUIRED_CAPABILITY];
|
|
27
|
+
const maxLineBytes = options.maxLineBytes ?? 8 * 1024 * 1024;
|
|
28
|
+
const write = (line) => {
|
|
29
|
+
options.output?.write(line);
|
|
30
|
+
};
|
|
31
|
+
let seq = 0;
|
|
32
|
+
let frameNo = 0;
|
|
33
|
+
const send = (type, payload) => {
|
|
34
|
+
write(encodeFrame(identity, type, ++seq, payload));
|
|
35
|
+
};
|
|
36
|
+
// Fail closed: emit a session-fatal error frame (valid envelope, so the
|
|
37
|
+
// host's digest check passes and it can name the plugin's cause), then
|
|
38
|
+
// surface the failure to the caller.
|
|
39
|
+
const fatal = (failure) => {
|
|
40
|
+
try {
|
|
41
|
+
write(encodeFrame(identity, 'error', ++seq, {
|
|
42
|
+
code: failure.code,
|
|
43
|
+
message: failure.message,
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// stdout is gone; the throw below still reports the cause.
|
|
48
|
+
}
|
|
49
|
+
throw failure;
|
|
50
|
+
};
|
|
51
|
+
send('hello', { capabilities: [...capabilities] });
|
|
52
|
+
let expectedSeq = 1;
|
|
53
|
+
let buffer = Buffer.alloc(0);
|
|
54
|
+
for await (const chunk of options.input ?? processStdin()) {
|
|
55
|
+
const buf = Buffer.from(chunk);
|
|
56
|
+
buffer = buffer.length === 0 ? buf : Buffer.concat([buffer, buf]);
|
|
57
|
+
if (buffer.length > maxLineBytes) {
|
|
58
|
+
fatal(new FrameJsonError(`host frame exceeds the ${Math.floor(maxLineBytes / (1024 * 1024))} MiB cap ` +
|
|
59
|
+
`(${buffer.length} bytes without a newline)`, { frameNo: frameNo + 1 }));
|
|
60
|
+
}
|
|
61
|
+
const { lines, rest } = extractLines(buffer);
|
|
62
|
+
buffer = rest;
|
|
63
|
+
for (const raw of lines) {
|
|
64
|
+
frameNo += 1;
|
|
65
|
+
let envelope;
|
|
66
|
+
try {
|
|
67
|
+
envelope = verifyEnvelope(parseLine(raw, frameNo, 'a host frame'), frameNo, {
|
|
68
|
+
pinnedId: options.pluginId,
|
|
69
|
+
pinnedVersion: options.pluginVersion,
|
|
70
|
+
expectedSeq,
|
|
71
|
+
});
|
|
72
|
+
if (!HOST_TYPES.includes(envelope.type)) {
|
|
73
|
+
throw new SchemaError(`frame ${frameNo}: host sent plugin-only message type ${JSON.stringify(envelope.type)}`, { frameNo });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (error instanceof ProtocolFailure)
|
|
78
|
+
fatal(error);
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
const payload = verifyPayload(envelope, frameNo);
|
|
82
|
+
expectedSeq = envelope.seq + 1;
|
|
83
|
+
switch (envelope.type) {
|
|
84
|
+
case 'ready':
|
|
85
|
+
continue;
|
|
86
|
+
case 'discover': {
|
|
87
|
+
const { requestId, paths } = payload;
|
|
88
|
+
try {
|
|
89
|
+
const result = await handler(paths);
|
|
90
|
+
for (const key of ['resources', 'unresolved', 'findings', 'classificationSignals']) {
|
|
91
|
+
if (!isJsonValue(result[key])) {
|
|
92
|
+
throw new SchemaError(`discover handler returned non-JSON "${key}"`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// Optional coverage evidence (ADR 0003 D4): pass through the
|
|
96
|
+
// handler's reported scanned paths when it provides them.
|
|
97
|
+
const scannedPaths = result.scannedPaths;
|
|
98
|
+
if (scannedPaths !== undefined && !isJsonValue(scannedPaths)) {
|
|
99
|
+
throw new SchemaError('discover handler returned non-JSON "scannedPaths"');
|
|
100
|
+
}
|
|
101
|
+
send('result', {
|
|
102
|
+
requestId,
|
|
103
|
+
resources: result.resources,
|
|
104
|
+
unresolved: result.unresolved,
|
|
105
|
+
findings: result.findings,
|
|
106
|
+
classificationSignals: result.classificationSignals,
|
|
107
|
+
...(scannedPaths !== undefined ? { scannedPaths } : {}),
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
// Request-scoped failure: the session stays alive; the host
|
|
112
|
+
// decides whether to continue.
|
|
113
|
+
send('error', {
|
|
114
|
+
requestId,
|
|
115
|
+
code: 'E_PLUGIN_INTERNAL',
|
|
116
|
+
message: error instanceof Error ? error.message : String(error),
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
case 'shutdown':
|
|
122
|
+
send('bye', {});
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/** Reads the process stdin line-by-line (default input). */
|
|
129
|
+
async function* processStdin() {
|
|
130
|
+
yield* createInterface({ input: process.stdin, crlfDelay: Infinity });
|
|
131
|
+
}
|
|
132
|
+
export { PROTOCOL_VERSION };
|
|
133
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,WAAW,EAAkB,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACnG,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAoB,MAAM,aAAa,CAAC;AAoCtF,gEAAgE;AAChE,MAAM,UAAU,GAA2B,CAAC,OAAO,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;AAE7E;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,OAAwB,EAAE,OAA2B;IACrF,MAAM,QAAQ,GAAG,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,aAAa,EAAE,OAAO,CAAC,aAAa,EAAE,CAAC;IACtF,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAA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L,CAAC;oBAAC,OAAO,KAAK,EAAE,CAAC;wBACf,4DAA4D;wBAC5D,+BAA+B;wBAC/B,IAAI,CAAC,OAAO,EAAE;4BACZ,SAAS;4BACT,IAAI,EAAE,mBAAmB;4BACzB,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;yBAChE,CAAC,CAAC;oBACL,CAAC;oBACD,SAAS;gBACX,CAAC;gBACD,KAAK,UAAU;oBACb,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;oBAChB,OAAO;YACX,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC;AAED,4DAA4D;AAC5D,KAAK,SAAS,CAAC,CAAC,YAAY;IAC1B,KAAK,CAAC,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAyC,CAAC;AAChH,CAAC;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GPP/3 message catalog and payload schemas (Interface pin #5).
|
|
3
|
+
*
|
|
4
|
+
* Every frame is `{protocolVersion: 3, pluginId, pluginVersion, type, seq,
|
|
5
|
+
* payload, digest}` with `digest = sha256(canonical({type, seq, payload}))`
|
|
6
|
+
* over the GF-canonical-JSON of @gate-forge/core (pin #1).
|
|
7
|
+
*
|
|
8
|
+
* GPP/3 (ADR 0003 D6) adds `classificationSignals` to the `result`
|
|
9
|
+
* payload — INSIDE the digest-checked envelope, never beside it. There
|
|
10
|
+
* is no unversioned optional-field compatibility: a GPP/2 peer fails
|
|
11
|
+
* closed at the handshake with `E_PROTOCOL_VERSION` naming both
|
|
12
|
+
* versions, and a GPP/3 peer omitting the field fails `E_SCHEMA`.
|
|
13
|
+
*
|
|
14
|
+
* Payload validation is schema-generated: every payload type below has a
|
|
15
|
+
* zod schema and is validated on receive; any failure is `E_SCHEMA` with a
|
|
16
|
+
* single-cause path/message diagnostic. The result payload matches the
|
|
17
|
+
* frozen @gate-forge/core `Resource`, `UnresolvedReason`, and
|
|
18
|
+
* `ClassificationSignal` shapes.
|
|
19
|
+
*/
|
|
20
|
+
import { z } from 'zod';
|
|
21
|
+
import { ClassificationSignalSchema, ResourceSchema, UnresolvedReasonSchema } from '@gate-forge/core';
|
|
22
|
+
/** The GPP version this package speaks. Handshakes pin this value. */
|
|
23
|
+
export declare const PROTOCOL_VERSION = 3;
|
|
24
|
+
/**
|
|
25
|
+
* Capability a GPP/3 plugin declares when its discovery handler emits
|
|
26
|
+
* classification signals. The host does NOT require it — a detector
|
|
27
|
+
* that discovers resources but cannot emit signals stays valid and its
|
|
28
|
+
* resources fall back to conservative classification defaults.
|
|
29
|
+
*/
|
|
30
|
+
export declare const SIGNAL_CAPABILITY = "classification-signals";
|
|
31
|
+
/** Maximum bytes per stdout line, enforced while framing (GPP/1 lineage). */
|
|
32
|
+
export declare const MAX_FRAME_BYTES: number;
|
|
33
|
+
/** Message catalog: every legal envelope `type`. */
|
|
34
|
+
export declare const MESSAGE_TYPES: readonly ["hello", "ready", "discover", "result", "error", "shutdown", "bye"];
|
|
35
|
+
/** Union of catalog message types. */
|
|
36
|
+
export type MessageType = (typeof MESSAGE_TYPES)[number];
|
|
37
|
+
/**
|
|
38
|
+
* Detector finding (discovery-spike lineage, e.g. `DUPLICATE_TABLE_NAME`):
|
|
39
|
+
* a non-resource observation a detector makes about the scanned sources.
|
|
40
|
+
*/
|
|
41
|
+
export declare const FindingSchema: z.ZodObject<{
|
|
42
|
+
code: z.ZodString;
|
|
43
|
+
detail: z.ZodString;
|
|
44
|
+
locations: z.ZodArray<z.ZodObject<{
|
|
45
|
+
file: z.ZodString;
|
|
46
|
+
line: z.ZodNumber;
|
|
47
|
+
col: z.ZodNumber;
|
|
48
|
+
}, z.core.$strict>>;
|
|
49
|
+
}, z.core.$strict>;
|
|
50
|
+
/** Inferred finding shape. */
|
|
51
|
+
export type Finding = z.infer<typeof FindingSchema>;
|
|
52
|
+
/** The complete discovery output a plugin returns for one request. */
|
|
53
|
+
export interface DiscoveryOutcome {
|
|
54
|
+
resources: z.infer<typeof ResourceSchema>[];
|
|
55
|
+
unresolved: z.infer<typeof UnresolvedReasonSchema>[];
|
|
56
|
+
findings: Finding[];
|
|
57
|
+
classificationSignals: z.infer<typeof ClassificationSignalSchema>[];
|
|
58
|
+
/**
|
|
59
|
+
* Repo-root-relative files the plugin actually examined successfully.
|
|
60
|
+
* Coverage evidence for the complete-scan attestation: the host unions
|
|
61
|
+
* these across successful plugins and fails closed when the union does
|
|
62
|
+
* not cover the requested scope. A plugin that omits the field leaves
|
|
63
|
+
* coverage unknown — which fails closed.
|
|
64
|
+
*/
|
|
65
|
+
scannedPaths?: string[];
|
|
66
|
+
}
|
|
67
|
+
/** `hello` (plugin → host, mandatory first frame): declared capabilities. */
|
|
68
|
+
export declare const HelloPayloadSchema: z.ZodObject<{
|
|
69
|
+
capabilities: z.ZodArray<z.ZodString>;
|
|
70
|
+
}, z.core.$strict>;
|
|
71
|
+
/** `ready` (host → plugin): empty payload; identity is pinned in the envelope. */
|
|
72
|
+
export declare const ReadyPayloadSchema: z.ZodObject<{}, z.core.$strict>;
|
|
73
|
+
/** `discover` (host → plugin): lock-step request over repo-relative paths. */
|
|
74
|
+
export declare const DiscoverPayloadSchema: z.ZodObject<{
|
|
75
|
+
requestId: z.ZodString;
|
|
76
|
+
paths: z.ZodArray<z.ZodString>;
|
|
77
|
+
}, z.core.$strict>;
|
|
78
|
+
/** `result` (plugin → host): exactly one per discover, echoing `requestId`. */
|
|
79
|
+
export declare const ResultPayloadSchema: z.ZodObject<{
|
|
80
|
+
requestId: z.ZodString;
|
|
81
|
+
resources: z.ZodArray<z.ZodObject<{
|
|
82
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
83
|
+
id: z.ZodString;
|
|
84
|
+
kind: z.ZodString;
|
|
85
|
+
source: z.ZodString;
|
|
86
|
+
location: z.ZodObject<{
|
|
87
|
+
file: z.ZodString;
|
|
88
|
+
line: z.ZodNumber;
|
|
89
|
+
col: z.ZodNumber;
|
|
90
|
+
}, z.core.$strict>;
|
|
91
|
+
detectorVersion: z.ZodString;
|
|
92
|
+
attributes: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
93
|
+
}, z.core.$strict>>;
|
|
94
|
+
unresolved: z.ZodArray<z.ZodObject<{
|
|
95
|
+
code: z.ZodString;
|
|
96
|
+
detail: z.ZodString;
|
|
97
|
+
location: z.ZodObject<{
|
|
98
|
+
file: z.ZodString;
|
|
99
|
+
line: z.ZodNumber;
|
|
100
|
+
col: z.ZodNumber;
|
|
101
|
+
}, z.core.$strict>;
|
|
102
|
+
}, z.core.$strict>>;
|
|
103
|
+
findings: z.ZodArray<z.ZodObject<{
|
|
104
|
+
code: z.ZodString;
|
|
105
|
+
detail: z.ZodString;
|
|
106
|
+
locations: z.ZodArray<z.ZodObject<{
|
|
107
|
+
file: z.ZodString;
|
|
108
|
+
line: z.ZodNumber;
|
|
109
|
+
col: z.ZodNumber;
|
|
110
|
+
}, z.core.$strict>>;
|
|
111
|
+
}, z.core.$strict>>;
|
|
112
|
+
classificationSignals: z.ZodArray<z.ZodObject<{
|
|
113
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
114
|
+
target: z.ZodObject<{
|
|
115
|
+
resourceName: z.ZodOptional<z.ZodString>;
|
|
116
|
+
resourceId: z.ZodOptional<z.ZodString>;
|
|
117
|
+
symbol: z.ZodOptional<z.ZodString>;
|
|
118
|
+
}, z.core.$strict>;
|
|
119
|
+
dimension: z.ZodEnum<{
|
|
120
|
+
exposure: "exposure";
|
|
121
|
+
plane: "plane";
|
|
122
|
+
identity: "identity";
|
|
123
|
+
"lifecycle.create": "lifecycle.create";
|
|
124
|
+
"lifecycle.read": "lifecycle.read";
|
|
125
|
+
"lifecycle.update": "lifecycle.update";
|
|
126
|
+
"lifecycle.delete": "lifecycle.delete";
|
|
127
|
+
"delete-semantics": "delete-semantics";
|
|
128
|
+
"archive-state": "archive-state";
|
|
129
|
+
"adapter-binding": "adapter-binding";
|
|
130
|
+
internality: "internality";
|
|
131
|
+
}>;
|
|
132
|
+
assertion: z.ZodUnion<readonly [z.ZodString, z.ZodBoolean, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>]>;
|
|
133
|
+
basis: z.ZodEnum<{
|
|
134
|
+
"code-positive": "code-positive";
|
|
135
|
+
"code-negative-closed-world": "code-negative-closed-world";
|
|
136
|
+
declaration: "declaration";
|
|
137
|
+
"organization-policy": "organization-policy";
|
|
138
|
+
}>;
|
|
139
|
+
source: z.ZodString;
|
|
140
|
+
location: z.ZodObject<{
|
|
141
|
+
file: z.ZodString;
|
|
142
|
+
line: z.ZodNumber;
|
|
143
|
+
col: z.ZodNumber;
|
|
144
|
+
}, z.core.$strict>;
|
|
145
|
+
detector: z.ZodObject<{
|
|
146
|
+
id: z.ZodString;
|
|
147
|
+
version: z.ZodString;
|
|
148
|
+
}, z.core.$strict>;
|
|
149
|
+
}, z.core.$strict>>;
|
|
150
|
+
scannedPaths: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
151
|
+
}, z.core.$strict>;
|
|
152
|
+
/**
|
|
153
|
+
* `error` (both directions). Request-scoped (plugin answers one discover):
|
|
154
|
+
* carries `requestId`. Session-fatal: no `requestId`; the sender considers
|
|
155
|
+
* the session unrecoverable and terminates afterwards.
|
|
156
|
+
*/
|
|
157
|
+
export declare const ErrorPayloadSchema: z.ZodObject<{
|
|
158
|
+
requestId: z.ZodOptional<z.ZodString>;
|
|
159
|
+
code: z.ZodString;
|
|
160
|
+
message: z.ZodString;
|
|
161
|
+
}, z.core.$strict>;
|
|
162
|
+
/** `shutdown` (host → plugin): empty payload. */
|
|
163
|
+
export declare const ShutdownPayloadSchema: z.ZodObject<{}, z.core.$strict>;
|
|
164
|
+
/** `bye` (plugin → host): mandatory reply to shutdown, then exit 0. */
|
|
165
|
+
export declare const ByePayloadSchema: z.ZodObject<{}, z.core.$strict>;
|
|
166
|
+
/** Payload schema for each catalog message type. */
|
|
167
|
+
export declare const PAYLOAD_SCHEMAS: Record<MessageType, z.ZodType>;
|
|
168
|
+
/** The capability the host requires of every plugin. */
|
|
169
|
+
export declare const REQUIRED_CAPABILITY = "discover";
|
|
170
|
+
/**
|
|
171
|
+
* Renders the first zod issue of a failed payload parse as a single-cause
|
|
172
|
+
* field path + message (`resources[0].id: Required`). Only the first issue
|
|
173
|
+
* is reported — diagnostics name one cause, not a list.
|
|
174
|
+
*/
|
|
175
|
+
export declare function firstIssueText(error: z.ZodError): string;
|
|
176
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,0BAA0B,EAE1B,cAAc,EACd,sBAAsB,EACvB,MAAM,kBAAkB,CAAC;AAE1B,sEAAsE;AACtE,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAElC;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,2BAA2B,CAAC;AAE1D,6EAA6E;AAC7E,eAAO,MAAM,eAAe,QAAkB,CAAC;AAE/C,oDAAoD;AACpD,eAAO,MAAM,aAAa,+EAQhB,CAAC;AAEX,sCAAsC;AACtC,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AAEzD;;;GAGG;AACH,eAAO,MAAM,aAAa;;;;;;;;kBASf,CAAC;AAEZ,8BAA8B;AAC9B,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAA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
+
*
|
|
4
|
+
* Every frame is `{protocolVersion: 3, pluginId, pluginVersion, type, seq,
|
|
5
|
+
* payload, digest}` with `digest = sha256(canonical({type, seq, payload}))`
|
|
6
|
+
* over the GF-canonical-JSON of @gate-forge/core (pin #1).
|
|
7
|
+
*
|
|
8
|
+
* GPP/3 (ADR 0003 D6) adds `classificationSignals` to the `result`
|
|
9
|
+
* payload — INSIDE the digest-checked envelope, never beside it. There
|
|
10
|
+
* is no unversioned optional-field compatibility: a GPP/2 peer fails
|
|
11
|
+
* closed at the handshake with `E_PROTOCOL_VERSION` naming both
|
|
12
|
+
* versions, and a GPP/3 peer omitting the field fails `E_SCHEMA`.
|
|
13
|
+
*
|
|
14
|
+
* Payload validation is schema-generated: every payload type below has a
|
|
15
|
+
* zod schema and is validated on receive; any failure is `E_SCHEMA` with a
|
|
16
|
+
* single-cause path/message diagnostic. The result payload matches the
|
|
17
|
+
* frozen @gate-forge/core `Resource`, `UnresolvedReason`, and
|
|
18
|
+
* `ClassificationSignal` shapes.
|
|
19
|
+
*/
|
|
20
|
+
import { z } from 'zod';
|
|
21
|
+
import { ClassificationSignalSchema, LocationSchema, ResourceSchema, UnresolvedReasonSchema, } from '@gate-forge/core';
|
|
22
|
+
/** The GPP version this package speaks. Handshakes pin this value. */
|
|
23
|
+
export const PROTOCOL_VERSION = 3;
|
|
24
|
+
/**
|
|
25
|
+
* Capability a GPP/3 plugin declares when its discovery handler emits
|
|
26
|
+
* classification signals. The host does NOT require it — a detector
|
|
27
|
+
* that discovers resources but cannot emit signals stays valid and its
|
|
28
|
+
* resources fall back to conservative classification defaults.
|
|
29
|
+
*/
|
|
30
|
+
export const SIGNAL_CAPABILITY = 'classification-signals';
|
|
31
|
+
/** Maximum bytes per stdout line, enforced while framing (GPP/1 lineage). */
|
|
32
|
+
export const MAX_FRAME_BYTES = 8 * 1024 * 1024; // 8 MiB
|
|
33
|
+
/** Message catalog: every legal envelope `type`. */
|
|
34
|
+
export const MESSAGE_TYPES = [
|
|
35
|
+
'hello',
|
|
36
|
+
'ready',
|
|
37
|
+
'discover',
|
|
38
|
+
'result',
|
|
39
|
+
'error',
|
|
40
|
+
'shutdown',
|
|
41
|
+
'bye',
|
|
42
|
+
];
|
|
43
|
+
/**
|
|
44
|
+
* Detector finding (discovery-spike lineage, e.g. `DUPLICATE_TABLE_NAME`):
|
|
45
|
+
* a non-resource observation a detector makes about the scanned sources.
|
|
46
|
+
*/
|
|
47
|
+
export const FindingSchema = z
|
|
48
|
+
.object({
|
|
49
|
+
/** Short stable finding code, e.g. `DUPLICATE_ROUTE`. */
|
|
50
|
+
code: z.string().min(1),
|
|
51
|
+
/** Single-cause human explanation. */
|
|
52
|
+
detail: z.string().min(1),
|
|
53
|
+
/** Source locations the finding points at. */
|
|
54
|
+
locations: z.array(LocationSchema).min(1),
|
|
55
|
+
})
|
|
56
|
+
.strict();
|
|
57
|
+
/** `hello` (plugin → host, mandatory first frame): declared capabilities. */
|
|
58
|
+
export const HelloPayloadSchema = z
|
|
59
|
+
.object({
|
|
60
|
+
/** Non-empty capability list; the host requires `discover`. */
|
|
61
|
+
capabilities: z.array(z.string().min(1)).min(1),
|
|
62
|
+
})
|
|
63
|
+
.strict();
|
|
64
|
+
/** `ready` (host → plugin): empty payload; identity is pinned in the envelope. */
|
|
65
|
+
export const ReadyPayloadSchema = z.object({}).strict();
|
|
66
|
+
/** `discover` (host → plugin): lock-step request over repo-relative paths. */
|
|
67
|
+
export const DiscoverPayloadSchema = z
|
|
68
|
+
.object({
|
|
69
|
+
/** Host-generated id echoed by the response (`result`/`error`). */
|
|
70
|
+
requestId: z.string().min(1),
|
|
71
|
+
/** Repo-root-relative paths to scan; no absolute paths, no `..`. */
|
|
72
|
+
paths: z.array(z.string().min(1)).min(1),
|
|
73
|
+
})
|
|
74
|
+
.strict();
|
|
75
|
+
/** `result` (plugin → host): exactly one per discover, echoing `requestId`. */
|
|
76
|
+
export const ResultPayloadSchema = z
|
|
77
|
+
.object({
|
|
78
|
+
/** Echoes the outstanding discover's `requestId`. */
|
|
79
|
+
requestId: z.string().min(1),
|
|
80
|
+
/** Discovered resources (@gate-forge/core Resource shape). */
|
|
81
|
+
resources: z.array(ResourceSchema),
|
|
82
|
+
/** Reasons discovery could not proceed for parts of the input. */
|
|
83
|
+
unresolved: z.array(UnresolvedReasonSchema),
|
|
84
|
+
/** Non-resource observations (duplicates, ambiguities). */
|
|
85
|
+
findings: z.array(FindingSchema),
|
|
86
|
+
/**
|
|
87
|
+
* Classification-signal facts (GPP/3, ADR 0003 D6). Mandatory since
|
|
88
|
+
* the version bump — detectors without signal support send `[]`.
|
|
89
|
+
*/
|
|
90
|
+
classificationSignals: z.array(ClassificationSignalSchema),
|
|
91
|
+
/**
|
|
92
|
+
* Repo-root-relative files the plugin actually examined successfully
|
|
93
|
+
* (coverage evidence for the complete-scan attestation). Optional on
|
|
94
|
+
* the wire; a plugin that omits it leaves coverage unknown, which
|
|
95
|
+
* fails closed in the host's attestation.
|
|
96
|
+
*/
|
|
97
|
+
scannedPaths: z.array(z.string().min(1)).optional(),
|
|
98
|
+
})
|
|
99
|
+
.strict();
|
|
100
|
+
/**
|
|
101
|
+
* `error` (both directions). Request-scoped (plugin answers one discover):
|
|
102
|
+
* carries `requestId`. Session-fatal: no `requestId`; the sender considers
|
|
103
|
+
* the session unrecoverable and terminates afterwards.
|
|
104
|
+
*/
|
|
105
|
+
export const ErrorPayloadSchema = z
|
|
106
|
+
.object({
|
|
107
|
+
requestId: z.string().min(1).optional(),
|
|
108
|
+
/** Plugin-side failure code, e.g. `E_PLUGIN_INTERNAL`. */
|
|
109
|
+
code: z.string().min(1),
|
|
110
|
+
/** Single-cause human explanation (no stack dumps). */
|
|
111
|
+
message: z.string().min(1),
|
|
112
|
+
})
|
|
113
|
+
.strict();
|
|
114
|
+
/** `shutdown` (host → plugin): empty payload. */
|
|
115
|
+
export const ShutdownPayloadSchema = z.object({}).strict();
|
|
116
|
+
/** `bye` (plugin → host): mandatory reply to shutdown, then exit 0. */
|
|
117
|
+
export const ByePayloadSchema = z.object({}).strict();
|
|
118
|
+
/** Payload schema for each catalog message type. */
|
|
119
|
+
export const PAYLOAD_SCHEMAS = {
|
|
120
|
+
hello: HelloPayloadSchema,
|
|
121
|
+
ready: ReadyPayloadSchema,
|
|
122
|
+
discover: DiscoverPayloadSchema,
|
|
123
|
+
result: ResultPayloadSchema,
|
|
124
|
+
error: ErrorPayloadSchema,
|
|
125
|
+
shutdown: ShutdownPayloadSchema,
|
|
126
|
+
bye: ByePayloadSchema,
|
|
127
|
+
};
|
|
128
|
+
/** The capability the host requires of every plugin. */
|
|
129
|
+
export const REQUIRED_CAPABILITY = 'discover';
|
|
130
|
+
/**
|
|
131
|
+
* Renders the first zod issue of a failed payload parse as a single-cause
|
|
132
|
+
* field path + message (`resources[0].id: Required`). Only the first issue
|
|
133
|
+
* is reported — diagnostics name one cause, not a list.
|
|
134
|
+
*/
|
|
135
|
+
export function firstIssueText(error) {
|
|
136
|
+
const issue = error.issues[0];
|
|
137
|
+
if (!issue)
|
|
138
|
+
return 'unknown validation failure';
|
|
139
|
+
const path = issue.path.map(String).join('.');
|
|
140
|
+
return path.length > 0 ? `${path}: ${issue.message}` : issue.message;
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,0BAA0B,EAC1B,cAAc,EACd,cAAc,EACd,sBAAsB,GACvB,MAAM,kBAAkB,CAAC;AAE1B,sEAAsE;AACtE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAElC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,wBAAwB,CAAC;AAE1D,6EAA6E;AAC7E,MAAM,CAAC,MAA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AM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;AAEtD,oDAAoD;AACpD,MAAM,CAAC,MAAM,eAAe,GAAmC;IAC7D,KAAK,EAAE,kBAAkB;IACzB,KAAK,EAAE,kBAAkB;IACzB,QAAQ,EAAE,qBAAqB;IAC/B,MAAM,EAAE,mBAAmB;IAC3B,KAAK,EAAE,kBAAkB;IACzB,QAAQ,EAAE,qBAAqB;IAC/B,GAAG,EAAE,gBAAgB;CACtB,CAAC;AAEF,wDAAwD;AACxD,MAAM,CAAC,MAAM,mBAAmB,GAAG,UAAU,CAAC;AAE9C;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,KAAiB;IAC9C,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC9B,IAAI,CAAC,KAAK;QAAE,OAAO,4BAA4B,CAAC;IAChD,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC9C,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC;AACvE,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gate-forge/plugin-protocol",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"description": "GPP/3 subprocess plugin protocol: TS host library, TS plugin SDK, zod payload schemas, Python reference client.",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=20"
|
|
9
|
+
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"python"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc -p tsconfig.build.json",
|
|
22
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
23
|
+
"test": "vitest run"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@gate-forge/core": "^0.1.0",
|
|
27
|
+
"zod": "^4.1.5"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/umiddey/gateforge.git",
|
|
35
|
+
"directory": "packages/plugin-protocol"
|
|
36
|
+
},
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/umiddey/gateforge/issues"
|
|
39
|
+
},
|
|
40
|
+
"homepage": "https://github.com/umiddey/gateforge#readme"
|
|
41
|
+
}
|