pumuki-ast-hooks 5.5.1 → 5.5.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pumuki-ast-hooks",
3
- "version": "5.5.1",
3
+ "version": "5.5.3",
4
4
  "description": "Enterprise-grade AST Intelligence System with multi-platform support (iOS, Android, Backend, Frontend) and Feature-First + DDD + Clean Architecture enforcement. Includes dynamic violations API for intelligent querying.",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -676,8 +676,11 @@ async function handleMcpMessage(message) {
676
676
  try {
677
677
  const request = JSON.parse(message);
678
678
 
679
- if ((typeof request.id === 'undefined' || request.id === null) && request.method?.startsWith('notifications/')) {
680
- return null;
679
+ // Handle notifications (no id) - don't send response
680
+ if (typeof request.id === 'undefined' || request.id === null) {
681
+ if (request.method === 'initialized' || request.method?.startsWith('notifications/')) {
682
+ return null;
683
+ }
681
684
  }
682
685
 
683
686
  if (request.method === 'initialize') {
@@ -964,17 +967,31 @@ async function handleMcpMessage(message) {
964
967
  }
965
968
  }
966
969
 
970
+ // Flag to track if MCP has been initialized
971
+ let mcpInitialized = false;
972
+
967
973
  // Start protocol handler
968
- protocolHandler.start(handleMcpMessage);
974
+ protocolHandler.start(async (message) => {
975
+ const response = await handleMcpMessage(message);
976
+
977
+ // Start polling loops ONLY after receiving 'initialized' notification from Windsurf
978
+ if (!mcpInitialized && message.includes('"method":"initialized"')) {
979
+ mcpInitialized = true;
980
+ process.stderr.write(`[MCP] Received 'initialized' - starting background loops\n`);
981
+ startPollingLoops();
982
+ }
983
+
984
+ return response;
985
+ });
969
986
 
970
987
  // Log MCP ready
971
988
  process.stderr.write(`[MCP] Server ready for ${REPO_ROOT}\n`);
972
989
 
973
990
  /**
974
- * Polling loop for background notifications and automations
975
- * IMPORTANT: Delayed start to avoid blocking MCP initialization handshake
991
+ * Start polling loops for background notifications and automations
992
+ * Called ONLY after MCP handshake is complete
976
993
  */
977
- setTimeout(() => {
994
+ function startPollingLoops() {
978
995
  setInterval(async () => {
979
996
  try {
980
997
  const now = Date.now();
@@ -1135,4 +1152,4 @@ setTimeout(() => {
1135
1152
  if (process.env.DEBUG) console.error('[MCP] Auto-commit error:', error);
1136
1153
  }
1137
1154
  }, AUTO_COMMIT_INTERVAL);
1138
- }, 2000); // Delay 2 seconds to allow MCP handshake to complete first
1155
+ }
@@ -11,6 +11,9 @@ class McpProtocolHandler {
11
11
  }
12
12
 
13
13
  start(messageHandler) {
14
+ // Log that we're starting
15
+ process.stderr.write('[MCP] Protocol handler starting...\n');
16
+
14
17
  this.inputStream.on('data', (chunk) => {
15
18
  const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk), 'utf8');
16
19
  void this._handleChunk(buf, messageHandler);
@@ -25,6 +28,9 @@ class McpProtocolHandler {
25
28
  if (this.logger) this.logger.error('MCP_STDIN_ERROR', { error: err.message });
26
29
  process.exit(1);
27
30
  });
31
+
32
+ // Log that we're ready
33
+ process.stderr.write('[MCP] Protocol handler ready\n');
28
34
  }
29
35
 
30
36
  async _handleChunk(chunk, messageHandler) {