fix: send VSCodium hook output to vibe-acp stdin for proper integration

The VSCodium extension uses vibe-acp which communicates with the Vibe core via
stdin/stdout. The Vibe core in the extension does NOT automatically trigger
hhooks, so we need to monitor journal files and inject hook messages.

This fix:
- Uses subprocess.Popen to keep vibe-acp's stdin pipe open
- Writes hook output directly to vibe-acp's stdin
- Allows the Vibe core to process and display hook messages properly
- Avoids breaking the ACP protocol

The hook output format (system_message JSON) is recognized by the Vibe core,
which displays it as the last line in the chat after each assistant turn.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
user
2026-10-25 16:58:41 +01:00
parent 1e85c9b895
commit 89c615d908
+31 -4
View File
@@ -456,6 +456,9 @@ REAL_ACP = "{backup_acp}"
HOOKS_DIR = Path("{hooks_dir}")
HOOKS_CONFIG = HOOKS_DIR / "hooks.toml"
# Global reference to the vibe-acp process
vibe_acp_process = None
class TurnCompletionHandler(FileSystemEventHandler):
def on_created(self, event):
self._check_journal(event)
@@ -500,7 +503,15 @@ class TurnCompletionHandler(FileSystemEventHandler):
timeout=30
)
if result.stdout:
print(result.stdout, end='', flush=True)
# Send hook output to vibe-acp's stdin instead of printing to stdout
# This prevents breaking the ACP protocol
try:
if vibe_acp_process and vibe_acp_process.stdin:
vibe_acp_process.stdin.write(result.stdout)
vibe_acp_process.stdin.flush()
except Exception:
# If we can't write to stdin, print to stderr for debugging
print(result.stdout, end='', flush=True, file=sys.stderr)
except Exception as e:
print(f"Hook error: {{e}}", file=sys.stderr)
@@ -520,20 +531,36 @@ def start_monitor():
return observer
def main():
global vibe_acp_process
observer = start_monitor()
try:
result = subprocess.run(
# Start the real vibe-acp with stdin as a pipe so we can write to it
vibe_acp_process = subprocess.Popen(
[REAL_ACP] + sys.argv[1:],
stdin=subprocess.PIPE,
stdout=sys.stdout,
stderr=sys.stderr
stderr=sys.stderr,
bufsize=1,
universal_newlines=True
)
sys.exit(result.returncode)
# Wait for vibe-acp to complete
vibe_acp_process.wait()
sys.exit(vibe_acp_process.returncode)
except KeyboardInterrupt:
if vibe_acp_process:
vibe_acp_process.terminate()
observer.stop()
sys.exit(0)
finally:
observer.stop()
observer.join()
if vibe_acp_process:
try:
vibe_acp_process.stdin.close()
except:
pass
if __name__ == "__main__":
main()