Skip to content

feat(context): add semantic handshake gate [Story 483.1] - #717

Merged
rafaelscosta merged 1 commit into
mainfrom
issue-483-semantic-handshake-20260509
May 9, 2026
Merged

feat(context): add semantic handshake gate [Story 483.1]#717
rafaelscosta merged 1 commit into
mainfrom
issue-483-semantic-handshake-20260509

Conversation

@rafaelscosta

@rafaelscosta rafaelscosta commented May 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

Implements the first governed slice for issue #483: a deterministic Semantic Handshake contract engine plus a blocking IDS pre-execution gate.

  • Adds SemanticHandshakeEngine under SYNAPSE context runtime and exports it from aiox-core/core/synapse/context
  • Adds G5SemanticHandshakeGate for @dev pre-execution validation with blocker/warning semantics
  • Supports deterministic extraction for PostgreSQL, serverless local-state writes, absolute imports and no-eval constraints
  • Adds LLM-ready context message generation for future dev-loop injection
  • Adds epic/story package for [EPIC] Semantic Handshake: Closing the Context Drift Gap #483 and refreshes install manifest

Refs #483.

Validation

  • npm test -- --runTestsByPath tests/synapse/semantic-handshake-engine.test.js tests/core/ids/semantic-handshake-gate.test.js
  • npm test -- --runTestsByPath tests/synapse/hierarchical-context-manager.test.js tests/core/ids/verification-gates.test.js tests/synapse/semantic-handshake-engine.test.js tests/core/ids/semantic-handshake-gate.test.js
  • npx eslint .aiox-core/core/synapse/context/semantic-handshake-engine.js .aiox-core/core/ids/gates/g5-semantic-handshake.js tests/synapse/semantic-handshake-engine.test.js tests/core/ids/semantic-handshake-gate.test.js
  • npm run validate:manifest
  • npm run lint
  • npm run typecheck

Summary by CodeRabbit

  • New Features

    • Added a deterministic "Semantic Handshake" verification engine and a pre-execution gate (G5) that can block on BLOCKER violations and return override/correction guidance.
  • Documentation

    • Added runtime and epic/story docs describing usage, integration points, and expected reports.
  • Tests

    • Added comprehensive tests for the handshake engine and verification gate covering blocking, warnings, extraction, and correction prompts.

Review Change Stack

@vercel

vercel Bot commented May 9, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
aiox-core Ready Ready Preview, Comment May 9, 2026 7:22am

Request Review

@github-actions github-actions Bot added type: test Test coverage and quality area: core Core framework (.aios-core/core/) area: docs Documentation (docs/) labels May 9, 2026
@coderabbitai

coderabbitai Bot commented May 9, 2026

Copy link
Copy Markdown

Walkthrough

Adds a deterministic SemanticHandshakeEngine that derives and stores planning constraints, validates proposed code (no LLM calls), produces compliance reports/correction prompts, and a G5SemanticHandshakeGate that registers context constraints and blocks or warns on violations. Exports, README, EPIC/Story docs, manifest, and Jest tests included.

Changes

Semantic Handshake Engine and Verification Gate

Layer / File(s) Summary
Engine Data Shapes & Default Extractors
.aiox-core/core/synapse/context/semantic-handshake-engine.js
Defines ConstraintType, ConstraintSeverity, utility helpers, and DEFAULT_EXTRACTORS (Postgres, serverless FS, absolute imports, eval/new Function bans).
Constructor, Clone & Registration APIs
.aiox-core/core/synapse/context/semantic-handshake-engine.js
SemanticHandshakeEngine constructor, clone(), registerConstraints(), addConstraint(), getConstraints(), and clear() implement deterministic registration and storage.
Validation Core
.aiox-core/core/synapse/context/semantic-handshake-engine.js
Async validateExecutionIntent() normalizes intent (files/code), evaluates applicability, runs custom or default validators, and aggregates verified/skipped constraints and violations with blocking/warning separation.
Reporting & Context Message
.aiox-core/core/synapse/context/semantic-handshake-engine.js
generateComplianceReport(), buildCorrectionPrompt(), and toContextMessage() create human-readable reports, correction prompts, and system-role context messages with handshake metadata.
G5 Gate Implementation
.aiox-core/core/ids/gates/g5-semantic-handshake.js
G5SemanticHandshakeGate (exported with G5_DEFAULT_TIMEOUT_MS) initializes or accepts an engine, registers planning-derived constraints from IDS context, detects code presence, delegates validation, and returns structured pass/fail/override/opportunity payloads.
Public Exports / Barrel Modules
.aiox-core/core/ids/index.js, .aiox-core/core/synapse/context/index.js
Re-exports engine surface into synapse/context and re-exports G5SemanticHandshakeGate + G5_DEFAULT_TIMEOUT_MS from ids index; context index require usage adjusted to path.resolve.
Context README
.aiox-core/core/synapse/context/README.md
Documents SemanticHandshakeEngine purpose, deterministic usage example (registerConstraints(), validateExecutionIntent()), and integration hooks (addConstraint(), toContextMessage()).
Epic & Story Documentation
docs/stories/epic-483-semantic-handshake/*
Adds EPIC 483 and Story 483.1 with acceptance criteria, tasks, dev notes, and validation commands (Portuguese content included).
Install Manifest
.aiox-core/install-manifest.yaml
Updated generated metadata, file_count, and entries for new/changed engine, gate, index, and README files.
Test Suites
tests/synapse/semantic-handshake-engine.test.js, tests/core/ids/semantic-handshake-gate.test.js
Jest tests covering export surface, extractor-driven constraint registration, validation pass/fail ordering, blocking vs warning semantics, thrown-validator normalization, and gate integration/override behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

area: synapse, area: workflows

Suggested reviewers

  • Pedrovaleriolopez
  • oalanicolas
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a semantic handshake gate, which is the primary feature introduced in this PR that implements Story 483.1.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-483-semantic-handshake-20260509

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented May 9, 2026

Copy link
Copy Markdown
Contributor

📊 Coverage Report

Coverage report not available

📈 Full coverage report available in Codecov


Generated by PR Automation (Story 6.1)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
.aiox-core/core/synapse/context/index.js (1)

12-12: ⚡ Quick win

Use absolute import style for the new semantic-handshake export.

Line 12 adds a relative import, which diverges from the repository rule for JS/TS files.

🔧 Proposed fix
 'use strict';
 
+const path = require('path');
 const contextTracker = require('./context-tracker');
 const contextBuilder = require('./context-builder');
 const hierarchicalContext = require('./hierarchical-context-manager');
-const semanticHandshake = require('./semantic-handshake-engine');
+const semanticHandshake = require(path.resolve(__dirname, './semantic-handshake-engine.js'));

As per coding guidelines, Use absolute imports instead of relative imports in all code.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.aiox-core/core/synapse/context/index.js at line 12, The file index.js uses
a relative require for semanticHandshake (const semanticHandshake =
require('./semantic-handshake-engine')), violating the repo rule to use absolute
imports; update that require to the absolute module path used by the project
(e.g., require('core/synapse/context/semantic-handshake-engine') or the repo's
configured root alias) so the semanticHandshake import follows the
absolute-import convention.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.aiox-core/core/ids/gates/g5-semantic-handshake.js:
- Around line 32-39: The persistent SemanticHandshakeEngine instance
(this._engine) is being mutated by _registerContextConstraints during each
_doVerify run, causing constraints to leak between verifications; modify
_doVerify to avoid mutating the long-lived this._engine by creating a temporary
engine instance for each verification (e.g., clone or instantiate a new
SemanticHandshakeEngine using the base engine's configuration/constraints and
then apply context constraints) or ensure _registerContextConstraints returns a
new constraints array rather than pushing into this._engine; update references
to use the temp engine for the verification process (keeping this._engine
unchanged) and preserve backward compatibility by deriving the new engine from
the original this._engine/SemanticHandshakeEngine configuration.

In @.aiox-core/core/synapse/context/semantic-handshake-engine.js:
- Around line 260-265: The normalization code in the semantic-handshake engine
(the block computing const id = String(input.id || input.description)... ) can
produce an empty string (e.g., input.description === '---'), leading to silent
collisions in this._constraints; update the public API path that adds
constraints (where this normalization runs) to validate the normalized id and
reject the input if id === '' (throw a clear Error or return a rejection), so
the method that uses this normalization never inserts a constraint with an empty
key into this._constraints.
- Around line 425-433: In validateExecutionIntent, the call to
constraint.validator can throw and currently bubbles out; wrap the await
constraint.validator(...) call in a try/catch inside validateExecutionIntent,
and on catch construct a validator-result shaped object (e.g., mark as invalid
and include a single violation with type like "validator-error" and
message/details from the caught error) then pass that object to
this._normalizeValidatorResult(...) (still using
this._publicConstraint(constraint) for context); ensure the catch preserves
useful error context (error.message and stack) when creating the violation so
downstream logic receives a deterministic compliance result instead of an
exception.

---

Nitpick comments:
In @.aiox-core/core/synapse/context/index.js:
- Line 12: The file index.js uses a relative require for semanticHandshake
(const semanticHandshake = require('./semantic-handshake-engine')), violating
the repo rule to use absolute imports; update that require to the absolute
module path used by the project (e.g.,
require('core/synapse/context/semantic-handshake-engine') or the repo's
configured root alias) so the semanticHandshake import follows the
absolute-import convention.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7fcb60d9-4e0e-4a85-a80d-5ddb00a58a8b

📥 Commits

Reviewing files that changed from the base of the PR and between 7bd2029 and ed51ece.

📒 Files selected for processing (10)
  • .aiox-core/core/ids/gates/g5-semantic-handshake.js
  • .aiox-core/core/ids/index.js
  • .aiox-core/core/synapse/context/README.md
  • .aiox-core/core/synapse/context/index.js
  • .aiox-core/core/synapse/context/semantic-handshake-engine.js
  • .aiox-core/install-manifest.yaml
  • docs/stories/epic-483-semantic-handshake/EPIC-483-SEMANTIC-HANDSHAKE.md
  • docs/stories/epic-483-semantic-handshake/STORY-483.1-SEMANTIC-HANDSHAKE-CONTRACT-GATE.md
  • tests/core/ids/semantic-handshake-gate.test.js
  • tests/synapse/semantic-handshake-engine.test.js

Comment thread .aiox-core/core/ids/gates/g5-semantic-handshake.js
Comment thread .aiox-core/core/synapse/context/semantic-handshake-engine.js
Comment thread .aiox-core/core/synapse/context/semantic-handshake-engine.js

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
docs/stories/epic-483-semantic-handshake/EPIC-483-SEMANTIC-HANDSHAKE.md (1)

36-38: 💤 Low value

Optional: Consider varying the sentence structure in Non-Goals.

The three Non-Goals bullets all start with "Não". While this is grammatically correct, varying the sentence structure could improve readability. For example:

  • "Não importar o protótipo TypeScript..."
  • "A extração de restrições não deve depender de LLM..."
  • "Evitar reabrir PRs antigos fechados..."

This is purely a stylistic suggestion and does not affect the clarity of the documentation.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/stories/epic-483-semantic-handshake/EPIC-483-SEMANTIC-HANDSHAKE.md`
around lines 36 - 38, The three Non-Goals bullet points in the "Non-Goals"
section all begin with "Não", making them repetitive; rewrite them to vary
sentence structure while preserving meaning—for example change "Não importar o
protótipo TypeScript do anexo como código de produção." to a phrasing like
"Evitar importar o protótipo TypeScript do anexo como código de produção.",
change "Não depender de LLM para extrair restrições no primeiro slice." to "A
extração de restrições não deve depender de LLM no primeiro slice.", and change
"Não reabrir PRs antigos fechados; usar apenas evidência e padrões úteis." to
"Evitar reabrir PRs antigos fechados; usar apenas evidência e padrões úteis.";
update the three bullet lines in the Non-Goals list accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@docs/stories/epic-483-semantic-handshake/EPIC-483-SEMANTIC-HANDSHAKE.md`:
- Around line 36-38: The three Non-Goals bullet points in the "Non-Goals"
section all begin with "Não", making them repetitive; rewrite them to vary
sentence structure while preserving meaning—for example change "Não importar o
protótipo TypeScript do anexo como código de produção." to a phrasing like
"Evitar importar o protótipo TypeScript do anexo como código de produção.",
change "Não depender de LLM para extrair restrições no primeiro slice." to "A
extração de restrições não deve depender de LLM no primeiro slice.", and change
"Não reabrir PRs antigos fechados; usar apenas evidência e padrões úteis." to
"Evitar reabrir PRs antigos fechados; usar apenas evidência e padrões úteis.";
update the three bullet lines in the Non-Goals list accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ade5ef1f-7023-4e5c-9a53-c8820c03bd17

📥 Commits

Reviewing files that changed from the base of the PR and between ed51ece and be17cc6.

📒 Files selected for processing (10)
  • .aiox-core/core/ids/gates/g5-semantic-handshake.js
  • .aiox-core/core/ids/index.js
  • .aiox-core/core/synapse/context/README.md
  • .aiox-core/core/synapse/context/index.js
  • .aiox-core/core/synapse/context/semantic-handshake-engine.js
  • .aiox-core/install-manifest.yaml
  • docs/stories/epic-483-semantic-handshake/EPIC-483-SEMANTIC-HANDSHAKE.md
  • docs/stories/epic-483-semantic-handshake/STORY-483.1-SEMANTIC-HANDSHAKE-CONTRACT-GATE.md
  • tests/core/ids/semantic-handshake-gate.test.js
  • tests/synapse/semantic-handshake-engine.test.js
✅ Files skipped from review due to trivial changes (1)
  • .aiox-core/core/synapse/context/README.md
🚧 Files skipped from review as they are similar to previous changes (7)
  • .aiox-core/core/ids/index.js
  • tests/synapse/semantic-handshake-engine.test.js
  • .aiox-core/core/ids/gates/g5-semantic-handshake.js
  • .aiox-core/core/synapse/context/index.js
  • tests/core/ids/semantic-handshake-gate.test.js
  • .aiox-core/install-manifest.yaml
  • .aiox-core/core/synapse/context/semantic-handshake-engine.js

@rafaelscosta
rafaelscosta merged commit 96d7f59 into main May 9, 2026
40 checks passed
@rafaelscosta
rafaelscosta deleted the issue-483-semantic-handshake-20260509 branch May 9, 2026 07:28
@github-actions

github-actions Bot commented May 9, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 5.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

tuanmedeiros pushed a commit to tuanmedeiros/aios-core-synkraay that referenced this pull request Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Core framework (.aios-core/core/) area: docs Documentation (docs/) released type: test Test coverage and quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant