@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/framing.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Line framing + envelope construction/verification shared by the host and
|
|
3
|
+
* the TS plugin SDK (spec §1–§2 lineage, hardened per ADR 0002 D3).
|
|
4
|
+
*
|
|
5
|
+
* Framing: one JSON object per line, `\n`-delimited, UTF-8, 8 MiB cap.
|
|
6
|
+
* Envelope: `{protocolVersion, pluginId, pluginVersion, type, seq, payload,
|
|
7
|
+
* digest}` with `digest = sha256(canonical({type, seq, payload}))`.
|
|
8
|
+
*/
|
|
9
|
+
import { isJsonValue, sha256Canonical } from '@gate-forge/core';
|
|
10
|
+
import { FrameJsonError, ProtocolVersionError, SchemaError, UnknownPluginError, UnknownTypeError, } from './codes.js';
|
|
11
|
+
import { MESSAGE_TYPES, PAYLOAD_SCHEMAS, PROTOCOL_VERSION, firstIssueText } from './schema.js';
|
|
12
|
+
/** Splits an accumulated stdout buffer into complete lines. */
|
|
13
|
+
export function extractLines(buffer) {
|
|
14
|
+
const lines = [];
|
|
15
|
+
let start = 0;
|
|
16
|
+
for (let i = 0; i < buffer.length; i++) {
|
|
17
|
+
if (buffer[i] === 0x0a) {
|
|
18
|
+
lines.push(buffer.subarray(start, i));
|
|
19
|
+
start = i + 1;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return { lines, rest: buffer.subarray(start) };
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Parses one raw stdout line into a JSON object. Fails closed with
|
|
26
|
+
* `E_FRAME_JSON` on empty lines, invalid JSON, and non-object frames.
|
|
27
|
+
*/
|
|
28
|
+
export function parseLine(raw, frameNo, expect) {
|
|
29
|
+
const text = raw.toString('utf8');
|
|
30
|
+
if (text.trim().length === 0) {
|
|
31
|
+
throw new FrameJsonError(`frame ${frameNo}: empty line where ${expect} expected`, {
|
|
32
|
+
frameNo,
|
|
33
|
+
rawLine: text,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
let parsed;
|
|
37
|
+
try {
|
|
38
|
+
parsed = JSON.parse(text);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
42
|
+
throw new FrameJsonError(`frame ${frameNo}: line is not valid JSON (${reason}); ` +
|
|
43
|
+
'plugin printed non-protocol output on stdout', { frameNo, rawLine: text });
|
|
44
|
+
}
|
|
45
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
46
|
+
const got = parsed === null ? 'null' : Array.isArray(parsed) ? 'array' : typeof parsed;
|
|
47
|
+
throw new FrameJsonError(`frame ${frameNo}: valid JSON but not an object (got ${got}) where ${expect} expected`, { frameNo, rawLine: text });
|
|
48
|
+
}
|
|
49
|
+
return parsed;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Verifies the transport envelope of a received frame: mandatory fields,
|
|
53
|
+
* protocol version, catalog membership, pinned identity, seq order, and
|
|
54
|
+
* digest. Fails closed with the code matching the first violated rule.
|
|
55
|
+
* Returns the narrowed envelope (payload still unvalidated).
|
|
56
|
+
*/
|
|
57
|
+
export function verifyEnvelope(frame, frameNo, ctx) {
|
|
58
|
+
const ctxOut = { frameNo };
|
|
59
|
+
const foundKeys = Object.keys(frame).sort().join(', ');
|
|
60
|
+
for (const field of [
|
|
61
|
+
'protocolVersion',
|
|
62
|
+
'pluginId',
|
|
63
|
+
'pluginVersion',
|
|
64
|
+
'type',
|
|
65
|
+
'seq',
|
|
66
|
+
'payload',
|
|
67
|
+
'digest',
|
|
68
|
+
]) {
|
|
69
|
+
if (!(field in frame)) {
|
|
70
|
+
throw new SchemaError(`frame ${frameNo}: required envelope field "${field}" is missing; found keys [${foundKeys}]`, ctxOut);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const { protocolVersion, pluginId, pluginVersion, type, seq, payload, digest } = frame;
|
|
74
|
+
if (typeof protocolVersion !== 'number' || !Number.isInteger(protocolVersion)) {
|
|
75
|
+
throw new SchemaError(`frame ${frameNo}: envelope field "protocolVersion" must be an integer, got ${JSON.stringify(protocolVersion)}`, ctxOut);
|
|
76
|
+
}
|
|
77
|
+
if (protocolVersion !== PROTOCOL_VERSION) {
|
|
78
|
+
throw new ProtocolVersionError(`frame ${frameNo}: envelope protocolVersion=${JSON.stringify(protocolVersion)} ` +
|
|
79
|
+
`but the host speaks ${PROTOCOL_VERSION}`, ctxOut);
|
|
80
|
+
}
|
|
81
|
+
if (typeof pluginId !== 'string' || pluginId.length === 0) {
|
|
82
|
+
throw new SchemaError(`frame ${frameNo}: envelope field "pluginId" must be a non-empty string, got ${JSON.stringify(pluginId)}`, ctxOut);
|
|
83
|
+
}
|
|
84
|
+
if (pluginId !== ctx.pinnedId) {
|
|
85
|
+
throw new UnknownPluginError(`frame ${frameNo}: pluginId ${JSON.stringify(pluginId)} but this session pinned ` +
|
|
86
|
+
`${JSON.stringify(ctx.pinnedId)}; refusing the frame`, ctxOut);
|
|
87
|
+
}
|
|
88
|
+
if (typeof pluginVersion !== 'string' || pluginVersion.length === 0) {
|
|
89
|
+
throw new SchemaError(`frame ${frameNo}: envelope field "pluginVersion" must be a non-empty string, got ${JSON.stringify(pluginVersion)}`, ctxOut);
|
|
90
|
+
}
|
|
91
|
+
if (pluginVersion !== ctx.pinnedVersion) {
|
|
92
|
+
throw new UnknownPluginError(`frame ${frameNo}: pluginVersion ${JSON.stringify(pluginVersion)} but this session pinned ` +
|
|
93
|
+
`${JSON.stringify(ctx.pinnedVersion)} (pluginId ${JSON.stringify(ctx.pinnedId)}); refusing the frame`, ctxOut);
|
|
94
|
+
}
|
|
95
|
+
if (typeof type !== 'string' || !MESSAGE_TYPES.includes(type)) {
|
|
96
|
+
throw new UnknownTypeError(`frame ${frameNo}: unknown message type ${JSON.stringify(type)}; known types: ${MESSAGE_TYPES.join(', ')}`, ctxOut);
|
|
97
|
+
}
|
|
98
|
+
if (typeof seq !== 'number' || !Number.isInteger(seq) || seq < 1) {
|
|
99
|
+
throw new SchemaError(`frame ${frameNo} (type ${type}): envelope field "seq" must be an integer >= 1, got ${JSON.stringify(seq)}`, ctxOut);
|
|
100
|
+
}
|
|
101
|
+
if (seq !== ctx.expectedSeq) {
|
|
102
|
+
throw new SchemaError(`frame ${frameNo} (type ${type}): seq ${seq} but expected ${ctx.expectedSeq} ` +
|
|
103
|
+
'(frames must arrive strictly in order, one seq per message)', ctxOut);
|
|
104
|
+
}
|
|
105
|
+
if (typeof digest !== 'string' || !/^[0-9a-f]{64}$/.test(digest)) {
|
|
106
|
+
throw new SchemaError(`frame ${frameNo} (type ${type}): envelope field "digest" must be 64 lowercase hex chars, ` +
|
|
107
|
+
`got ${JSON.stringify(digest)}`, ctxOut);
|
|
108
|
+
}
|
|
109
|
+
const computed = sha256Canonical({ type, seq, payload });
|
|
110
|
+
if (digest !== computed) {
|
|
111
|
+
throw new SchemaError(`frame ${frameNo} (type ${type}): digest mismatch: expected ${computed}, got ${digest} ` +
|
|
112
|
+
'(digest = sha256(canonical({type, seq, payload})))', ctxOut);
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
116
|
+
pluginId,
|
|
117
|
+
pluginVersion,
|
|
118
|
+
type: type,
|
|
119
|
+
seq,
|
|
120
|
+
payload,
|
|
121
|
+
digest,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Validates a verified envelope's payload against the per-type schema.
|
|
126
|
+
* Throws `E_SCHEMA` with the first failing field path on mismatch.
|
|
127
|
+
*/
|
|
128
|
+
export function verifyPayload(envelope, frameNo) {
|
|
129
|
+
const schema = PAYLOAD_SCHEMAS[envelope.type];
|
|
130
|
+
const result = schema.safeParse(envelope.payload);
|
|
131
|
+
if (!result.success) {
|
|
132
|
+
throw new SchemaError(`frame ${frameNo} (type ${envelope.type}): invalid payload at "${firstIssueText(result.error)}"`, { frameNo });
|
|
133
|
+
}
|
|
134
|
+
return result.data;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Builds one outgoing frame (this side's identity + seq) and serializes it
|
|
138
|
+
* as a newline-terminated JSON line with the canonical digest.
|
|
139
|
+
*/
|
|
140
|
+
export function encodeFrame(identity, type, seq, payload) {
|
|
141
|
+
const digest = sha256Canonical({ type, seq, payload });
|
|
142
|
+
const frame = {
|
|
143
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
144
|
+
pluginId: identity.pluginId,
|
|
145
|
+
pluginVersion: identity.pluginVersion,
|
|
146
|
+
type,
|
|
147
|
+
seq,
|
|
148
|
+
payload,
|
|
149
|
+
digest,
|
|
150
|
+
};
|
|
151
|
+
return `${JSON.stringify(frame)}\n`;
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=framing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"framing.js","sourceRoot":"","sources":["../src/framing.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,WAAW,EAAE,eAAe,EAAkB,MAAM,kBAAkB,CAAC;AAChF,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,WAAW,EACX,kBAAkB,EAClB,gBAAgB,GAEjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,gBAAgB,EAAE,cAAc,EAAoB,MAAM,aAAa,CAAC;AAajH,+DAA+D;AAC/D,MAAM,UAAU,YAAY,CAAC,MAAc;IACzC,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;YACvB,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;YACtC,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC;QAChB,CAAC;IACH,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;AACjD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,GAAW,EAAE,OAAe,EAAE,MAAc;IACpE,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAClC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,cAAc,CAAC,SAA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CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,QAAqD,EAAE,IAAiB,EAAE,GAAW,EAAE,OAAkB;IACnI,MAAM,MAAM,GAAG,eAAe,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;IACvD,MAAM,KAAK,GAAG;QACZ,eAAe,EAAE,gBAAgB;QACjC,QAAQ,EAAE,QAAQ,CAAC,QAAQ;QAC3B,aAAa,EAAE,QAAQ,CAAC,aAAa;QACrC,IAAI;QACJ,GAAG;QACH,OAAO;QACP,MAAM;KACP,CAAC;IACF,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC;AACtC,CAAC"}
|
package/dist/host.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type DiscoveryOutcome } from './schema.js';
|
|
2
|
+
/** Default per-phase watchdog budgets. */
|
|
3
|
+
export declare const DEFAULT_TIMEOUTS: Required<Pick<PluginTimeouts, 'handshakeMs' | 'requestMs' | 'shutdownMs'>>;
|
|
4
|
+
/** Watchdog budgets, all individually overridable for tests. */
|
|
5
|
+
export interface PluginTimeouts {
|
|
6
|
+
/** Time budget for the plugin's first `hello` frame. */
|
|
7
|
+
handshakeMs: number;
|
|
8
|
+
/** Time budget for each `result`/`error` response. */
|
|
9
|
+
requestMs: number;
|
|
10
|
+
/** Time budget for `bye` and for the exit after it. */
|
|
11
|
+
shutdownMs: number;
|
|
12
|
+
}
|
|
13
|
+
/** Options for {@link PluginSession}. */
|
|
14
|
+
export interface PluginSpawnOptions {
|
|
15
|
+
/** Full argv of the plugin subprocess, e.g. `['node', 'plugin.js', root]`. */
|
|
16
|
+
command: readonly string[];
|
|
17
|
+
/** Expected pluginId — pinned at the handshake, enforced on every frame. */
|
|
18
|
+
pluginId: string;
|
|
19
|
+
/** Expected pluginVersion — pinned at the handshake, enforced on every frame. */
|
|
20
|
+
pluginVersion: string;
|
|
21
|
+
/** Working directory for the subprocess (default: process cwd). */
|
|
22
|
+
cwd?: string;
|
|
23
|
+
/** Full environment for the subprocess (default: inherit). */
|
|
24
|
+
env?: NodeJS.ProcessEnv;
|
|
25
|
+
/** Watchdog budgets (default: {@link DEFAULT_TIMEOUTS}). */
|
|
26
|
+
timeouts?: Partial<PluginTimeouts>;
|
|
27
|
+
/** Line cap in bytes (default: 8 MiB). */
|
|
28
|
+
maxLineBytes?: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* One persistent plugin subprocess: one spawn, many discovers (lock-step),
|
|
32
|
+
* one shutdown handshake. Any protocol violation fails the session closed:
|
|
33
|
+
* the plugin is killed and a typed {@link ProtocolFailure} is thrown whose
|
|
34
|
+
* `message` is a single-cause diagnostic.
|
|
35
|
+
*/
|
|
36
|
+
export declare class PluginSession {
|
|
37
|
+
#private;
|
|
38
|
+
constructor(options: PluginSpawnOptions);
|
|
39
|
+
/**
|
|
40
|
+
* Performs the handshake: reads and validates `hello` (pinning
|
|
41
|
+
* protocolVersion, pluginId, pluginVersion) and answers `ready`.
|
|
42
|
+
*/
|
|
43
|
+
start(): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Sends one `discover` and awaits the matching `result`/`error`.
|
|
46
|
+
* Lock-step: at most one discover may be outstanding per session.
|
|
47
|
+
*/
|
|
48
|
+
discover(paths: readonly string[]): Promise<DiscoveryOutcome>;
|
|
49
|
+
/**
|
|
50
|
+
* Shutdown handshake: `shutdown` → `bye` → exit 0. Nonzero exit or a
|
|
51
|
+
* hang after a clean bye is `E_EXIT_STATUS`.
|
|
52
|
+
*/
|
|
53
|
+
shutdown(): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Best-effort teardown: kills the plugin if it is still running and
|
|
56
|
+
* waits for it to exit. Never throws; safe to call multiple times and
|
|
57
|
+
* after any failure.
|
|
58
|
+
*/
|
|
59
|
+
dispose(): Promise<void>;
|
|
60
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B;;;;OAIG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAmN/B"}
|
package/dist/host.js
ADDED
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GPP/3 host (engine side): spawns a plugin subprocess, performs the
|
|
3
|
+
* pinned handshake, drives lock-step discover requests over a persistent
|
|
4
|
+
* session, and tears the plugin down via the shutdown handshake.
|
|
5
|
+
*
|
|
6
|
+
* Hardening (ADR 0002 D3): newline-delimited JSON framing with an 8 MiB
|
|
7
|
+
* line cap, one outstanding request at a time, per-read watchdog timeouts
|
|
8
|
+
* followed by SIGKILL, schema-generated payload validation, per-message
|
|
9
|
+
* digest verification, and fail-closed teardown on every violation with a
|
|
10
|
+
* single-cause actionable diagnostic — never a stack dump.
|
|
11
|
+
*
|
|
12
|
+
* Spec lineage: spikes/plugin-protocol/spec.md (GPP/1), hardened per
|
|
13
|
+
* docs/decisions/0002-plugin-boundary.md.
|
|
14
|
+
*/
|
|
15
|
+
import { spawn } from 'node:child_process';
|
|
16
|
+
import { EofError, ExitStatusError, FrameJsonError, PluginError, ProtocolFailure, SchemaError, TimeoutError, } from './codes.js';
|
|
17
|
+
import { encodeFrame, extractLines, parseLine, verifyEnvelope, verifyPayload } from './framing.js';
|
|
18
|
+
import { REQUIRED_CAPABILITY, } from './schema.js';
|
|
19
|
+
/** Default per-phase watchdog budgets. */
|
|
20
|
+
export const DEFAULT_TIMEOUTS = {
|
|
21
|
+
handshakeMs: 10_000,
|
|
22
|
+
requestMs: 10_000,
|
|
23
|
+
shutdownMs: 5_000,
|
|
24
|
+
};
|
|
25
|
+
const STDERR_TAIL_LINES = 10;
|
|
26
|
+
/**
|
|
27
|
+
* One persistent plugin subprocess: one spawn, many discovers (lock-step),
|
|
28
|
+
* one shutdown handshake. Any protocol violation fails the session closed:
|
|
29
|
+
* the plugin is killed and a typed {@link ProtocolFailure} is thrown whose
|
|
30
|
+
* `message` is a single-cause diagnostic.
|
|
31
|
+
*/
|
|
32
|
+
export class PluginSession {
|
|
33
|
+
#pinnedId;
|
|
34
|
+
#pinnedVersion;
|
|
35
|
+
#timeouts;
|
|
36
|
+
#maxLineBytes;
|
|
37
|
+
#proc;
|
|
38
|
+
#state = 'handshaking';
|
|
39
|
+
#sendSeq = 0;
|
|
40
|
+
#expectedPeerSeq = 1;
|
|
41
|
+
#framesReceived = 0;
|
|
42
|
+
#requestCounter = 0;
|
|
43
|
+
#outstanding = null;
|
|
44
|
+
#killed = false;
|
|
45
|
+
#buffer = Buffer.alloc(0);
|
|
46
|
+
#lineQueue = [];
|
|
47
|
+
#pending = null;
|
|
48
|
+
#exitInfo = null;
|
|
49
|
+
#stderrLines = [];
|
|
50
|
+
#stderrFragment = '';
|
|
51
|
+
constructor(options) {
|
|
52
|
+
if (options.command.length === 0 || typeof options.command[0] !== 'string') {
|
|
53
|
+
throw new Error('PluginSession: options.command must be a non-empty argv array');
|
|
54
|
+
}
|
|
55
|
+
this.#pinnedId = options.pluginId;
|
|
56
|
+
this.#pinnedVersion = options.pluginVersion;
|
|
57
|
+
this.#timeouts = { ...DEFAULT_TIMEOUTS, ...options.timeouts };
|
|
58
|
+
this.#maxLineBytes = options.maxLineBytes ?? 8 * 1024 * 1024;
|
|
59
|
+
this.#proc = spawn(options.command[0], options.command.slice(1), {
|
|
60
|
+
cwd: options.cwd,
|
|
61
|
+
env: options.env,
|
|
62
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
63
|
+
});
|
|
64
|
+
// EPIPE when the plugin died mid-write: the next read surfaces E_EOF.
|
|
65
|
+
this.#proc.stdin?.on('error', () => { });
|
|
66
|
+
this.#proc.stdout?.on('data', (chunk) => this.#onStdout(chunk));
|
|
67
|
+
this.#proc.stderr?.on('data', (chunk) => this.#onStderr(chunk));
|
|
68
|
+
this.#proc.once('close', (code, signal) => this.#onClose(code, signal));
|
|
69
|
+
}
|
|
70
|
+
// -- Handshake -----------------------------------------------------------
|
|
71
|
+
/**
|
|
72
|
+
* Performs the handshake: reads and validates `hello` (pinning
|
|
73
|
+
* protocolVersion, pluginId, pluginVersion) and answers `ready`.
|
|
74
|
+
*/
|
|
75
|
+
async start() {
|
|
76
|
+
try {
|
|
77
|
+
const received = await this.#receive('hello', this.#timeouts.handshakeMs, { kind: 'hello' });
|
|
78
|
+
const { capabilities } = received.payload;
|
|
79
|
+
if (!capabilities.includes(REQUIRED_CAPABILITY)) {
|
|
80
|
+
throw new SchemaError(`hello (frame ${received.frameNo}): capabilities ${JSON.stringify(capabilities)} ` +
|
|
81
|
+
`lack "${REQUIRED_CAPABILITY}", which the host requires`, { frameNo: received.frameNo });
|
|
82
|
+
}
|
|
83
|
+
this.#state = 'open';
|
|
84
|
+
this.#send('ready', {});
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
this.#ensureDead();
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// -- Discovery -----------------------------------------------------------
|
|
92
|
+
/**
|
|
93
|
+
* Sends one `discover` and awaits the matching `result`/`error`.
|
|
94
|
+
* Lock-step: at most one discover may be outstanding per session.
|
|
95
|
+
*/
|
|
96
|
+
async discover(paths) {
|
|
97
|
+
if (this.#state !== 'open') {
|
|
98
|
+
throw new Error(`PluginSession.discover(): session is not open (state: ${this.#state})`);
|
|
99
|
+
}
|
|
100
|
+
if (this.#outstanding !== null) {
|
|
101
|
+
throw new Error(`PluginSession.discover(): lock-step violation — request ${this.#outstanding} is still outstanding`);
|
|
102
|
+
}
|
|
103
|
+
const requestId = `req-${++this.#requestCounter}`;
|
|
104
|
+
this.#outstanding = requestId;
|
|
105
|
+
try {
|
|
106
|
+
this.#send('discover', { requestId, paths: [...paths] });
|
|
107
|
+
const received = await this.#receive(`result or error for request ${JSON.stringify(requestId)}`, this.#timeouts.requestMs, { kind: 'request', requestId });
|
|
108
|
+
const payload = received.payload;
|
|
109
|
+
if (received.type === 'error') {
|
|
110
|
+
const scope = payload.requestId !== undefined ? 'an error for request' : 'a fatal session error';
|
|
111
|
+
throw new PluginError(`frame ${received.frameNo}: plugin reported ${scope} ${JSON.stringify(requestId)}: ` +
|
|
112
|
+
`code=${JSON.stringify(payload.code)} message=${JSON.stringify(payload.message)}`, { frameNo: received.frameNo });
|
|
113
|
+
}
|
|
114
|
+
if (payload.requestId !== requestId) {
|
|
115
|
+
throw new SchemaError(`frame ${received.frameNo} (type result): requestId ${JSON.stringify(payload.requestId)} ` +
|
|
116
|
+
`does not match outstanding request ${JSON.stringify(requestId)}`, { frameNo: received.frameNo });
|
|
117
|
+
}
|
|
118
|
+
for (const signal of payload.classificationSignals ?? []) {
|
|
119
|
+
if (signal.detector.id !== this.#pinnedId ||
|
|
120
|
+
signal.detector.version !== this.#pinnedVersion) {
|
|
121
|
+
throw new SchemaError(`frame ${received.frameNo} (type result): classification signal detector ` +
|
|
122
|
+
`${JSON.stringify(signal.detector.id)}@${JSON.stringify(signal.detector.version)} ` +
|
|
123
|
+
`is not authorized for plugin ${JSON.stringify(this.#pinnedId)}@${JSON.stringify(this.#pinnedVersion)}`, { frameNo: received.frameNo });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
resources: payload.resources ?? [],
|
|
128
|
+
unresolved: payload.unresolved ?? [],
|
|
129
|
+
findings: payload.findings ?? [],
|
|
130
|
+
classificationSignals: payload.classificationSignals ?? [],
|
|
131
|
+
...(payload.scannedPaths !== undefined ? { scannedPaths: payload.scannedPaths } : {}),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
this.#ensureDead();
|
|
136
|
+
throw error;
|
|
137
|
+
}
|
|
138
|
+
finally {
|
|
139
|
+
this.#outstanding = null;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// -- Shutdown ------------------------------------------------------------
|
|
143
|
+
/**
|
|
144
|
+
* Shutdown handshake: `shutdown` → `bye` → exit 0. Nonzero exit or a
|
|
145
|
+
* hang after a clean bye is `E_EXIT_STATUS`.
|
|
146
|
+
*/
|
|
147
|
+
async shutdown() {
|
|
148
|
+
if (this.#state !== 'open') {
|
|
149
|
+
throw new Error(`PluginSession.shutdown(): session is not open (state: ${this.#state})`);
|
|
150
|
+
}
|
|
151
|
+
this.#state = 'shutting-down';
|
|
152
|
+
try {
|
|
153
|
+
this.#send('shutdown', {});
|
|
154
|
+
await this.#receive('bye', this.#timeouts.shutdownMs, { kind: 'bye' });
|
|
155
|
+
const exit = await this.#waitExit(this.#timeouts.shutdownMs);
|
|
156
|
+
if (exit === null) {
|
|
157
|
+
this.#kill();
|
|
158
|
+
await this.#waitClose();
|
|
159
|
+
throw new ExitStatusError(`plugin did not exit within ${this.#timeouts.shutdownMs}ms after a clean bye; killed (SIGKILL)`);
|
|
160
|
+
}
|
|
161
|
+
if (exit.signal !== null) {
|
|
162
|
+
throw new ExitStatusError(`plugin terminated by signal ${exit.signal} after a clean bye (expected exit 0)`);
|
|
163
|
+
}
|
|
164
|
+
if (exit.code !== 0) {
|
|
165
|
+
throw new ExitStatusError(`plugin exited with code ${exit.code} after a clean bye (expected 0)`);
|
|
166
|
+
}
|
|
167
|
+
this.#state = 'closed';
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
this.#ensureDead();
|
|
171
|
+
throw error;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Best-effort teardown: kills the plugin if it is still running and
|
|
176
|
+
* waits for it to exit. Never throws; safe to call multiple times and
|
|
177
|
+
* after any failure.
|
|
178
|
+
*/
|
|
179
|
+
async dispose() {
|
|
180
|
+
this.#ensureDead();
|
|
181
|
+
await this.#waitClose();
|
|
182
|
+
}
|
|
183
|
+
// -- Frame I/O -----------------------------------------------------------
|
|
184
|
+
#onStdout(chunk) {
|
|
185
|
+
this.#buffer = this.#buffer.length === 0 ? chunk : Buffer.concat([this.#buffer, chunk]);
|
|
186
|
+
if (this.#buffer.length > this.#maxLineBytes) {
|
|
187
|
+
const frameNo = this.#framesReceived + 1;
|
|
188
|
+
this.#failPending(new FrameJsonError(`frame ${frameNo}: line exceeds the ${Math.floor(this.#maxLineBytes / (1024 * 1024))} MiB cap ` +
|
|
189
|
+
`(${this.#buffer.length} bytes without a newline)`, { frameNo }));
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const { lines, rest } = extractLines(this.#buffer);
|
|
193
|
+
this.#buffer = rest;
|
|
194
|
+
for (const line of lines)
|
|
195
|
+
this.#deliverLine(line);
|
|
196
|
+
}
|
|
197
|
+
#onStderr(chunk) {
|
|
198
|
+
this.#stderrFragment += chunk.toString('utf8');
|
|
199
|
+
const parts = this.#stderrFragment.split('\n');
|
|
200
|
+
this.#stderrFragment = parts.pop() ?? '';
|
|
201
|
+
for (const part of parts) {
|
|
202
|
+
if (part.trim().length > 0)
|
|
203
|
+
this.#stderrLines.push(part.trim());
|
|
204
|
+
}
|
|
205
|
+
if (this.#stderrLines.length > STDERR_TAIL_LINES) {
|
|
206
|
+
this.#stderrLines = this.#stderrLines.slice(-STDERR_TAIL_LINES);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
#onClose(code, signal) {
|
|
210
|
+
this.#exitInfo = { code, signal };
|
|
211
|
+
this.#state = 'closed';
|
|
212
|
+
const pending = this.#pending;
|
|
213
|
+
if (pending) {
|
|
214
|
+
clearTimeout(pending.timer);
|
|
215
|
+
this.#pending = null;
|
|
216
|
+
pending.reject(this.#eofFailure('the expected frame'));
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
#deliverLine(line) {
|
|
220
|
+
const pending = this.#pending;
|
|
221
|
+
if (pending) {
|
|
222
|
+
clearTimeout(pending.timer);
|
|
223
|
+
this.#pending = null;
|
|
224
|
+
pending.resolve(line);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
this.#lineQueue.push(line);
|
|
228
|
+
}
|
|
229
|
+
#failPending(error) {
|
|
230
|
+
this.#kill();
|
|
231
|
+
const pending = this.#pending;
|
|
232
|
+
if (pending) {
|
|
233
|
+
clearTimeout(pending.timer);
|
|
234
|
+
this.#pending = null;
|
|
235
|
+
pending.reject(error);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
// No read outstanding: drop buffered state so a later read cannot
|
|
239
|
+
// observe the poisoned line; the session is dead regardless.
|
|
240
|
+
this.#buffer = Buffer.alloc(0);
|
|
241
|
+
this.#lineQueue = [];
|
|
242
|
+
}
|
|
243
|
+
#readLine(expect, timeoutMs) {
|
|
244
|
+
const queued = this.#lineQueue.shift();
|
|
245
|
+
if (queued !== undefined)
|
|
246
|
+
return Promise.resolve(queued);
|
|
247
|
+
if (this.#exitInfo !== null)
|
|
248
|
+
return Promise.reject(this.#eofFailure(expect));
|
|
249
|
+
return new Promise((resolve, reject) => {
|
|
250
|
+
let pending;
|
|
251
|
+
const timer = setTimeout(() => {
|
|
252
|
+
if (this.#pending !== pending)
|
|
253
|
+
return;
|
|
254
|
+
this.#pending = null;
|
|
255
|
+
this.#kill();
|
|
256
|
+
reject(new TimeoutError(`no ${expect} within ${timeoutMs}ms; plugin killed (SIGKILL) after the watchdog expired`));
|
|
257
|
+
}, timeoutMs);
|
|
258
|
+
pending = { resolve, reject, timer };
|
|
259
|
+
this.#pending = pending;
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Reads, parses, envelope-verifies, state-checks, and payload-validates
|
|
264
|
+
* the next plugin frame. Every failure path tears the session down.
|
|
265
|
+
*/
|
|
266
|
+
async #receive(expect, timeoutMs, expected) {
|
|
267
|
+
try {
|
|
268
|
+
const raw = await this.#readLine(expect, timeoutMs);
|
|
269
|
+
const frameNo = ++this.#framesReceived;
|
|
270
|
+
const frame = parseLine(raw, frameNo, expect);
|
|
271
|
+
const envelope = verifyEnvelope(frame, frameNo, {
|
|
272
|
+
pinnedId: this.#pinnedId,
|
|
273
|
+
pinnedVersion: this.#pinnedVersion,
|
|
274
|
+
expectedSeq: this.#expectedPeerSeq,
|
|
275
|
+
});
|
|
276
|
+
this.#expectedPeerSeq = envelope.seq + 1;
|
|
277
|
+
this.#checkExpectation(envelope.type, frameNo, expected);
|
|
278
|
+
const payload = verifyPayload(envelope, frameNo);
|
|
279
|
+
return { type: envelope.type, payload, frameNo };
|
|
280
|
+
}
|
|
281
|
+
catch (error) {
|
|
282
|
+
if (error instanceof ProtocolFailure) {
|
|
283
|
+
// EofError/TimeoutError already imply death; frame-level failures
|
|
284
|
+
// must tear the plugin down too (fail closed, never continue).
|
|
285
|
+
this.#ensureDead();
|
|
286
|
+
}
|
|
287
|
+
throw error;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
#checkExpectation(type, frameNo, expected) {
|
|
291
|
+
const context = { frameNo };
|
|
292
|
+
switch (expected.kind) {
|
|
293
|
+
case 'hello':
|
|
294
|
+
if (type !== 'hello') {
|
|
295
|
+
throw new SchemaError(`frame ${frameNo}: first frame must have type "hello", got ${JSON.stringify(type)}`, context);
|
|
296
|
+
}
|
|
297
|
+
return;
|
|
298
|
+
case 'request':
|
|
299
|
+
if (type !== 'result' && type !== 'error') {
|
|
300
|
+
throw new SchemaError(`frame ${frameNo}: expected "result" or "error" for request ` +
|
|
301
|
+
`${JSON.stringify(expected.requestId)}, got type ${JSON.stringify(type)}`, context);
|
|
302
|
+
}
|
|
303
|
+
return;
|
|
304
|
+
case 'bye':
|
|
305
|
+
if (type !== 'bye') {
|
|
306
|
+
throw new SchemaError(`frame ${frameNo}: expected "bye" after shutdown, got type ${JSON.stringify(type)}`, context);
|
|
307
|
+
}
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
#eofFailure(expect) {
|
|
312
|
+
const exit = this.#exitInfo;
|
|
313
|
+
const exitText = exit === null
|
|
314
|
+
? 'exit unknown'
|
|
315
|
+
: exit.code !== null
|
|
316
|
+
? `plugin exit code ${exit.code}`
|
|
317
|
+
: `terminated by signal ${exit.signal}`;
|
|
318
|
+
let detail = `plugin stream ended early (EOF) while waiting for ${expect}; ${exitText}; ` +
|
|
319
|
+
`${this.#framesReceived} complete frame(s) received`;
|
|
320
|
+
if (this.#stderrLines.length > 0) {
|
|
321
|
+
detail += `\n[plugin-protocol] plugin stderr tail:\n${this.#stderrLines.map((l) => ` ${l}`).join('\n')}`;
|
|
322
|
+
}
|
|
323
|
+
return new EofError(detail);
|
|
324
|
+
}
|
|
325
|
+
#send(type, payload) {
|
|
326
|
+
const seq = ++this.#sendSeq;
|
|
327
|
+
this.#proc.stdin?.write(encodeFrame({ pluginId: this.#pinnedId, pluginVersion: this.#pinnedVersion }, type, seq, payload));
|
|
328
|
+
}
|
|
329
|
+
#kill() {
|
|
330
|
+
if (this.#exitInfo === null && !this.#killed) {
|
|
331
|
+
this.#killed = true;
|
|
332
|
+
this.#proc.kill('SIGKILL');
|
|
333
|
+
}
|
|
334
|
+
this.#state = 'closed';
|
|
335
|
+
}
|
|
336
|
+
#ensureDead() {
|
|
337
|
+
this.#kill();
|
|
338
|
+
}
|
|
339
|
+
#waitExit(timeoutMs) {
|
|
340
|
+
if (this.#exitInfo !== null)
|
|
341
|
+
return Promise.resolve(this.#exitInfo);
|
|
342
|
+
return new Promise((resolve) => {
|
|
343
|
+
const timer = setTimeout(() => {
|
|
344
|
+
this.#proc.off('close', onClose);
|
|
345
|
+
resolve(null);
|
|
346
|
+
}, timeoutMs);
|
|
347
|
+
const onClose = (code, signal) => {
|
|
348
|
+
clearTimeout(timer);
|
|
349
|
+
resolve({ code, signal });
|
|
350
|
+
};
|
|
351
|
+
this.#proc.once('close', onClose);
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
#waitClose() {
|
|
355
|
+
if (this.#exitInfo !== null)
|
|
356
|
+
return Promise.resolve();
|
|
357
|
+
return new Promise((resolve) => {
|
|
358
|
+
this.#proc.once('close', () => resolve());
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
//# sourceMappingURL=host.js.map
|
package/dist/host.js.map
ADDED
|
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C,KAAK,CAAC,CAAC;gBACpB,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;YAC5B,CAAC,CAAC;YACF,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACpC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,UAAU;QACR,IAAI,IAAI,CAAC,SAAS,KAAK,IAAI;YAAE,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;QACtD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC7B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
export { FAILURE_CODES, ProtocolFailure, ProtocolVersionError, UnknownPluginError, FrameJsonError, UnknownTypeError, SchemaError, EofError, TimeoutError, PluginError, ExitStatusError, isProtocolFailure, formatDiagnostic, } from './codes.js';
|
|
20
|
+
export type { ProtocolFailureCode, FailureContext } from './codes.js';
|
|
21
|
+
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';
|
|
22
|
+
export type { MessageType, Finding, DiscoveryOutcome } from './schema.js';
|
|
23
|
+
export { extractLines, parseLine, verifyEnvelope, verifyPayload, encodeFrame, } from './framing.js';
|
|
24
|
+
export type { GppEnvelope, EnvelopeContext } from './framing.js';
|
|
25
|
+
export { PluginSession, DEFAULT_TIMEOUTS } from './host.js';
|
|
26
|
+
export type { PluginSpawnOptions, PluginTimeouts } from './host.js';
|
|
27
|
+
export { servePlugin } from './plugin.js';
|
|
28
|
+
export type { ServePluginOptions, DiscoverHandler, DiscoveryResult } from './plugin.js';
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAMH,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;AACpB,YAAY,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAMtE,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;AACrB,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAM1E,OAAO,EACL,YAAY,EACZ,SAAS,EACT,cAAc,EACd,aAAa,EACb,WAAW,GACZ,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAMjE,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC5D,YAAY,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAMpE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC"}
|