You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR fully implements the TypeScript SDK for the Agentic Cognitive Firewall, mirroring the architecture and wire protocol of the Python reference implementation. It establishes robust IPC communication with the Go sidecar over Unix Domain Sockets and Windows Named Pipes.
Key Changes
Core Models (models.ts): Implemented all shared domain models including the Decision enum (ALLOW, SANITISE, BLOCK), RiskContext, SanitiseResult, and the custom FirewallError exception hierarchy.
IPC Protocol (frame.ts): Engineered the low-level byte framing encoder/decoder. Guaranteed replay-attack prevention by signing every request payload with an HMAC-SHA256 hash and a 16-byte cryptographically secure nonce using Node's native crypto module.
Transport (transport.ts): Built an asynchronous transport layer leveraging Node.js net.createConnection to communicate directly with the Sidecar's socket path, complete with exponential backoff and retry limits.
Firewall SDK (firewall.ts): Implemented the main developer-facing Firewall class and asynchronous hook interfaces (onPrompt, onContext, onToolCall, onMemory).
Zero Dependencies: Intentionally omitted the optional Python-side ML Semantic Scanner to ensure the TypeScript SDK remains incredibly lightweight and fully dependency-free.
Validation
tsc compilation passes cleanly against strict mode.
Comprehensive Unit Tests (tests/frame.test.ts) using Node's native node:test verify correct packet serialization and deserialization.
Thanks for the PR. And this is a really needed extension to have support for TypeScript.
Few things needed to be addressed before merging :
Fix the retry-exhaustion bug in transport.ts (Transport.send()) — when all 3 connection attempts fail, the code falls into the unconditional throw err; inside the catch block, so the raw Node socket error is thrown instead of the intended FirewallConnectionError. The wrapped error after the loop is dead code and can never run. Callers who catch (FirewallConnectionError) to handle "sidecar unreachable" won't catch anything. Fix: don't throw err when retries are exhausted — let the loop fall through (or break) so the wrapped error at the bottom actually fires. (Compare transport.py, which never re-raises inside the retry branch.)
Wire up real tests, or update the PR description. package.json's test script (node --test tests/) points at a tests/ folder this PR doesn't create — npm test fails immediately. The added test_firewall.ts sits at the package root (excluded by tsconfig.json), has no assertions or test runner, requires a live sidecar + env var to run manually, and swallows failures via console.error without ever failing the process. This doesn't match the PR description's "E2E Socket Integration tests" claim. Please either add real assertion-based tests + a typescript CI job (there's currently none — only go/integration/python run in CI), or adjust the description.
Tighten any types, since this SDK sits on a security boundary:
onToolCall(name: string, params: any) → should be Record<string, unknown> (matches the original stub's documented signature).
RiskContext.payload: any / signals: any[] → a typed Signal interface would catch shape mistakes at compile time.
(Non-blocking, worth a follow-up issue) No connection/request timeout in connectAndSend — if the sidecar accepts the connection but never responds, the call hangs indefinitely, which blocks the agent on every hook call. Same gap exists in the Python SDK, so probably a shared follow-up rather than something to fix here.
Thanks for the detailed review! I've pushed a new commit addressing the requested changes:
Fixed the retry exhaustion logic in Transport.send() so it now falls through to FirewallConnectionError after retries are exhausted instead of re-throwing the raw Node socket error.
Added assertion-based TypeScript unit tests, updated the test configuration, and wired them into the CI workflow.
Tightened the public API types by replacing the remaining any usages with unknown/Record<string, unknown> and introducing a typed Signal interface.
Updated the PR description to accurately reflect the current test coverage.
I left the connection/request timeout unchanged since it was noted as a non-blocking follow-up and to remain consistent with the current Python SDK.
I'd appreciate another review when you have a chance. Thanks!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fully implements the TypeScript SDK for the Agentic Cognitive Firewall, mirroring the architecture and wire protocol of the Python reference implementation. It establishes robust IPC communication with the Go sidecar over Unix Domain Sockets and Windows Named Pipes.
Key Changes
models.ts): Implemented all shared domain models including theDecisionenum (ALLOW,SANITISE,BLOCK),RiskContext,SanitiseResult, and the customFirewallErrorexception hierarchy.frame.ts): Engineered the low-level byte framing encoder/decoder. Guaranteed replay-attack prevention by signing every request payload with an HMAC-SHA256 hash and a 16-byte cryptographically secure nonce using Node's nativecryptomodule.transport.ts): Built an asynchronous transport layer leveraging Node.jsnet.createConnectionto communicate directly with the Sidecar's socket path, complete with exponential backoff and retry limits.firewall.ts): Implemented the main developer-facingFirewallclass and asynchronous hook interfaces (onPrompt,onContext,onToolCall,onMemory).Validation
tsccompilation passes cleanly against strict mode.tests/frame.test.ts) using Node's nativenode:testverify correct packet serialization and deserialization.