sugarai 3.6.0__tar.gz → 3.7.0.dev0__tar.gz

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.
Files changed (129) hide show
  1. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/PKG-INFO +19 -24
  2. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/README.md +18 -23
  3. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/pyproject.toml +1 -1
  4. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/integrations/opencode/client.py +23 -13
  5. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/main.py +235 -1
  6. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugarai.egg-info/PKG-INFO +19 -24
  7. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/tests/test_opencode_integration.py +410 -2
  8. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/LICENSE +0 -0
  9. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/setup.cfg +0 -0
  10. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/__init__.py +0 -0
  11. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/__version__.py +0 -0
  12. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/agent/__init__.py +0 -0
  13. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/agent/base.py +0 -0
  14. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/agent/hooks.py +0 -0
  15. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/agent/subagent_manager.py +0 -0
  16. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/agent/tools.py +0 -0
  17. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/billing/__init__.py +0 -0
  18. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/billing/api_keys.py +0 -0
  19. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/billing/tiers.py +0 -0
  20. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/billing/usage.py +0 -0
  21. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/config/__init__.py +0 -0
  22. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/config/issue_responder_config.py +0 -0
  23. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/config/prompt_config.py +0 -0
  24. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/core/__init__.py +0 -0
  25. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/core/loop.py +0 -0
  26. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/discovery/__init__.py +0 -0
  27. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/discovery/code_quality.py +0 -0
  28. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/discovery/error_monitor.py +0 -0
  29. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/discovery/github_watcher.py +0 -0
  30. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/discovery/test_coverage.py +0 -0
  31. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/executor/__init__.py +0 -0
  32. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/executor/agent_sdk_executor.py +0 -0
  33. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/executor/base.py +0 -0
  34. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/executor/claude_wrapper.py +0 -0
  35. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/executor/hooks.py +0 -0
  36. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/executor/structured_request.py +0 -0
  37. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/executor/thinking_display.py +0 -0
  38. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/integrations/__init__.py +0 -0
  39. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/integrations/github.py +0 -0
  40. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/integrations/opencode/__init__.py +0 -0
  41. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/integrations/opencode/config.py +0 -0
  42. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/integrations/opencode/injector.py +0 -0
  43. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/integrations/opencode/models.py +0 -0
  44. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/integrations/opencode/notifier.py +0 -0
  45. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/learning/__init__.py +0 -0
  46. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/learning/adaptive_scheduler.py +0 -0
  47. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/learning/feedback_processor.py +0 -0
  48. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/learning/learnings_writer.py +0 -0
  49. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/mcp/__init__.py +0 -0
  50. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/mcp/memory_server.py +0 -0
  51. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/mcp/server.py +0 -0
  52. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/mcp/task_server.py +0 -0
  53. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/memory/__init__.py +0 -0
  54. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/memory/embedder.py +0 -0
  55. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/memory/retriever.py +0 -0
  56. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/memory/store.py +0 -0
  57. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/memory/types.py +0 -0
  58. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/orchestration/__init__.py +0 -0
  59. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/orchestration/agent_router.py +0 -0
  60. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/orchestration/model_router.py +0 -0
  61. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/orchestration/task_orchestrator.py +0 -0
  62. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/profiles/__init__.py +0 -0
  63. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/profiles/base.py +0 -0
  64. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/profiles/default.py +0 -0
  65. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/profiles/issue_responder.py +0 -0
  66. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/quality_gates/__init__.py +0 -0
  67. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/quality_gates/coordinator.py +0 -0
  68. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/quality_gates/criteria_templates.py +0 -0
  69. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/quality_gates/diff_validator.py +0 -0
  70. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/quality_gates/evidence.py +0 -0
  71. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/quality_gates/failure_handler.py +0 -0
  72. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/quality_gates/functional_verifier.py +0 -0
  73. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/quality_gates/preflight_checks.py +0 -0
  74. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/quality_gates/success_criteria.py +0 -0
  75. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/quality_gates/test_validator.py +0 -0
  76. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/quality_gates/truth_enforcer.py +0 -0
  77. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/quality_gates/verification_gate.py +0 -0
  78. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/ralph/__init__.py +0 -0
  79. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/ralph/config.py +0 -0
  80. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/ralph/profile.py +0 -0
  81. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/ralph/signals.py +0 -0
  82. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/ralph/validator.py +0 -0
  83. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/storage/__init__.py +0 -0
  84. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/storage/issue_response_manager.py +0 -0
  85. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/storage/task_type_manager.py +0 -0
  86. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/storage/work_queue.py +0 -0
  87. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/triage/__init__.py +0 -0
  88. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/triage/capability_scanner.py +0 -0
  89. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/triage/complexity_analyzer.py +0 -0
  90. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/triage/triage_analyzer.py +0 -0
  91. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/utils/__init__.py +0 -0
  92. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/utils/git_operations.py +0 -0
  93. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/utils/toon_encoder.py +0 -0
  94. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/workflow/__init__.py +0 -0
  95. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugar/workflow/orchestrator.py +0 -0
  96. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugarai.egg-info/SOURCES.txt +0 -0
  97. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugarai.egg-info/dependency_links.txt +0 -0
  98. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugarai.egg-info/entry_points.txt +0 -0
  99. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugarai.egg-info/requires.txt +0 -0
  100. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/sugarai.egg-info/top_level.txt +0 -0
  101. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/tests/test_agent.py +0 -0
  102. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/tests/test_bash_permissions.py +0 -0
  103. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/tests/test_billing.py +0 -0
  104. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/tests/test_cli.py +0 -0
  105. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/tests/test_complexity_analyzer.py +0 -0
  106. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/tests/test_core_loop.py +0 -0
  107. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/tests/test_github_client.py +0 -0
  108. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/tests/test_goose_integration.py +0 -0
  109. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/tests/test_hold_functionality.py +0 -0
  110. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/tests/test_hooks.py +0 -0
  111. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/tests/test_issue_responder_cli.py +0 -0
  112. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/tests/test_issue_response_integration.py +0 -0
  113. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/tests/test_mcp_integration.py +0 -0
  114. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/tests/test_mcp_server.py +0 -0
  115. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/tests/test_mcp_task_server.py +0 -0
  116. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/tests/test_memory.py +0 -0
  117. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/tests/test_model_router.py +0 -0
  118. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/tests/test_orchestration.py +0 -0
  119. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/tests/test_profiles.py +0 -0
  120. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/tests/test_prompt_config.py +0 -0
  121. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/tests/test_quality_gates.py +0 -0
  122. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/tests/test_ralph.py +0 -0
  123. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/tests/test_storage.py +0 -0
  124. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/tests/test_subagent_manager.py +0 -0
  125. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/tests/test_task_hooks.py +0 -0
  126. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/tests/test_task_types.py +0 -0
  127. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/tests/test_thinking_capture.py +0 -0
  128. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/tests/test_toon_encoder.py +0 -0
  129. {sugarai-3.6.0 → sugarai-3.7.0.dev0}/tests/test_v3_benchmarks.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sugarai
3
- Version: 3.6.0
3
+ Version: 3.7.0.dev0
4
4
  Summary: 🍰 Sugar - The autonomous layer for AI coding agents. Manages task queues, runs 24/7, ships working code.
5
5
  Author-email: Steven Leggett <contact@roboticforce.io>
6
6
  License: AGPL-3.0-or-later
@@ -102,13 +102,10 @@ Sugar has **first-class integrations** with leading AI coding agents:
102
102
  claude mcp add sugar -- sugar mcp memory
103
103
  ```
104
104
 
105
- **OpenCode** - Native plugin with real-time notifications:
105
+ **OpenCode** - One-command setup with MCP integration:
106
106
  ```bash
107
- # Check integration status
108
- sugar opencode status
109
-
110
- # Test connection
111
- sugar opencode test
107
+ sugar opencode setup # Automatically configures OpenCode
108
+ # Then restart OpenCode
112
109
  ```
113
110
 
114
111
  Both integrations support **automatic memory injection** - Sugar injects relevant context (decisions, preferences, error patterns) into your AI sessions automatically.
@@ -393,37 +390,35 @@ Claude: "I'll create a Sugar task for the test fixes."
393
390
 
394
391
  ### OpenCode Integration
395
392
 
396
- Sugar has native bidirectional integration with [OpenCode](https://github.com/opencode-ai/opencode):
393
+ Sugar has native MCP integration with [OpenCode](https://github.com/opencode-ai/opencode):
397
394
 
398
395
  **Features:**
399
- - Real-time task notifications (start, complete, fail)
396
+ - MCP servers for task management and memory access
400
397
  - Automatic memory injection into OpenCode sessions
401
398
  - Context-aware memory retrieval based on current work
402
- - Learning capture from session outcomes
403
399
 
404
400
  **Quick Setup:**
405
401
  ```bash
406
- # Install OpenCode integration dependencies
407
- pipx inject sugarai aiohttp
402
+ # One-command setup - adds Sugar MCP servers to OpenCode config
403
+ sugar opencode setup
408
404
 
409
- # Check integration status
405
+ # Restart OpenCode to load the new servers
406
+ # Then verify:
410
407
  sugar opencode status
411
-
412
- # Test connection (requires OpenCode server running)
413
- sugar opencode test
414
-
415
- # Send a test notification
416
- sugar opencode notify "Hello from Sugar!" --title "Test" --level success
417
408
  ```
418
409
 
419
- **Environment Variables:**
410
+ The setup command automatically:
411
+ - Finds your OpenCode config file
412
+ - Adds `sugar-tasks` and `sugar-memory` MCP servers
413
+ - Preserves your existing configuration
414
+
415
+ **Options:**
420
416
  ```bash
421
- OPENCODE_SERVER_URL=http://localhost:4096 # OpenCode server URL
422
- SUGAR_OPENCODE_ENABLED=true # Enable/disable integration
417
+ sugar opencode setup --dry-run # Preview changes without applying
418
+ sugar opencode setup --yes # Non-interactive mode
419
+ sugar opencode setup --no-memory # Only add task server
423
420
  ```
424
421
 
425
- When Sugar executes tasks, it automatically sends notifications to OpenCode so you can track progress in real-time.
426
-
427
422
  ### MCP Server Integration
428
423
 
429
424
  Sugar provides MCP servers for Goose, Claude Code, Claude Desktop, and other MCP clients.
@@ -37,13 +37,10 @@ Sugar has **first-class integrations** with leading AI coding agents:
37
37
  claude mcp add sugar -- sugar mcp memory
38
38
  ```
39
39
 
40
- **OpenCode** - Native plugin with real-time notifications:
40
+ **OpenCode** - One-command setup with MCP integration:
41
41
  ```bash
42
- # Check integration status
43
- sugar opencode status
44
-
45
- # Test connection
46
- sugar opencode test
42
+ sugar opencode setup # Automatically configures OpenCode
43
+ # Then restart OpenCode
47
44
  ```
48
45
 
49
46
  Both integrations support **automatic memory injection** - Sugar injects relevant context (decisions, preferences, error patterns) into your AI sessions automatically.
@@ -328,37 +325,35 @@ Claude: "I'll create a Sugar task for the test fixes."
328
325
 
329
326
  ### OpenCode Integration
330
327
 
331
- Sugar has native bidirectional integration with [OpenCode](https://github.com/opencode-ai/opencode):
328
+ Sugar has native MCP integration with [OpenCode](https://github.com/opencode-ai/opencode):
332
329
 
333
330
  **Features:**
334
- - Real-time task notifications (start, complete, fail)
331
+ - MCP servers for task management and memory access
335
332
  - Automatic memory injection into OpenCode sessions
336
333
  - Context-aware memory retrieval based on current work
337
- - Learning capture from session outcomes
338
334
 
339
335
  **Quick Setup:**
340
336
  ```bash
341
- # Install OpenCode integration dependencies
342
- pipx inject sugarai aiohttp
337
+ # One-command setup - adds Sugar MCP servers to OpenCode config
338
+ sugar opencode setup
343
339
 
344
- # Check integration status
340
+ # Restart OpenCode to load the new servers
341
+ # Then verify:
345
342
  sugar opencode status
346
-
347
- # Test connection (requires OpenCode server running)
348
- sugar opencode test
349
-
350
- # Send a test notification
351
- sugar opencode notify "Hello from Sugar!" --title "Test" --level success
352
343
  ```
353
344
 
354
- **Environment Variables:**
345
+ The setup command automatically:
346
+ - Finds your OpenCode config file
347
+ - Adds `sugar-tasks` and `sugar-memory` MCP servers
348
+ - Preserves your existing configuration
349
+
350
+ **Options:**
355
351
  ```bash
356
- OPENCODE_SERVER_URL=http://localhost:4096 # OpenCode server URL
357
- SUGAR_OPENCODE_ENABLED=true # Enable/disable integration
352
+ sugar opencode setup --dry-run # Preview changes without applying
353
+ sugar opencode setup --yes # Non-interactive mode
354
+ sugar opencode setup --no-memory # Only add task server
358
355
  ```
359
356
 
360
- When Sugar executes tasks, it automatically sends notifications to OpenCode so you can track progress in real-time.
361
-
362
357
  ### MCP Server Integration
363
358
 
364
359
  Sugar provides MCP servers for Goose, Claude Code, Claude Desktop, and other MCP clients.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "sugarai"
7
- version = "3.6.0"
7
+ version = "3.7.0.dev0"
8
8
  description = "🍰 Sugar - The autonomous layer for AI coding agents. Manages task queues, runs 24/7, ships working code."
9
9
 
10
10
  readme = "README.md"
@@ -80,16 +80,24 @@ class OpenCodeClient:
80
80
  self._connected = False
81
81
 
82
82
  async def health_check(self) -> bool:
83
- """Check if OpenCode server is reachable."""
83
+ """
84
+ Check if OpenCode server is reachable.
85
+
86
+ Returns:
87
+ True if server is healthy
88
+
89
+ Raises:
90
+ aiohttp.ClientConnectorError: If server is unreachable
91
+ """
84
92
  if not self._session:
85
93
  return False
86
94
 
87
- try:
88
- async with self._session.get("/health") as resp:
89
- return resp.status == 200
90
- except Exception as e:
91
- logger.debug(f"Health check failed: {e}")
92
- return False
95
+ # Let connection errors propagate so callers can distinguish
96
+ # between "server not running" vs "server returned non-200"
97
+ async with self._session.get("/health") as resp:
98
+ if resp.status != 200:
99
+ logger.debug(f"Health check returned status {resp.status}")
100
+ return resp.status == 200
93
101
 
94
102
  # =========================================================================
95
103
  # Session Management
@@ -245,6 +253,9 @@ class OpenCodeClient:
245
253
 
246
254
  Returns:
247
255
  True if notification was sent
256
+
257
+ Raises:
258
+ aiohttp.ClientConnectorError: If server is unreachable
248
259
  """
249
260
  if not self._session:
250
261
  raise RuntimeError("Client not connected. Use async with context.")
@@ -255,12 +266,11 @@ class OpenCodeClient:
255
266
  "level": level.value,
256
267
  }
257
268
 
258
- try:
259
- async with self._session.post("/tui/notify", json=payload) as resp:
260
- return resp.status == 200
261
- except Exception as e:
262
- logger.debug(f"Notification failed: {e}")
263
- return False
269
+ # Let connection errors propagate so callers can handle appropriately
270
+ async with self._session.post("/tui/notify", json=payload) as resp:
271
+ if resp.status != 200:
272
+ logger.debug(f"Notification failed with status {resp.status}")
273
+ return resp.status == 200
264
274
 
265
275
  async def notify_task_completed(
266
276
  self,
@@ -4625,14 +4625,22 @@ def opencode_test(ctx, server):
4625
4625
  click.echo(f"🔗 Testing connection to {config.server_url}...")
4626
4626
 
4627
4627
  async def test_connection():
4628
+ import aiohttp
4629
+
4628
4630
  try:
4629
4631
  async with OpenCodeClient(config) as client:
4630
4632
  if await client.health_check():
4631
4633
  click.echo("✅ Connection successful!")
4632
4634
  return True
4633
4635
  else:
4634
- click.echo("❌ Server responded but health check failed")
4636
+ click.echo("❌ Server responded but health check failed (non-200 status)")
4637
+ click.echo(" Check that OpenCode is running correctly")
4635
4638
  return False
4639
+ except aiohttp.ClientConnectorError:
4640
+ click.echo("❌ Cannot connect to OpenCode server")
4641
+ click.echo(f" Is OpenCode running at {config.server_url}?")
4642
+ click.echo(" Start OpenCode first, then try again")
4643
+ return False
4636
4644
  except Exception as e:
4637
4645
  click.echo(f"❌ Connection failed: {e}")
4638
4646
  return False
@@ -4679,6 +4687,8 @@ def opencode_notify(ctx, message, title, level):
4679
4687
  }
4680
4688
 
4681
4689
  async def send_notification():
4690
+ import aiohttp
4691
+
4682
4692
  try:
4683
4693
  async with OpenCodeClient(config) as client:
4684
4694
  success = await client.notify(
@@ -4691,6 +4701,10 @@ def opencode_notify(ctx, message, title, level):
4691
4701
  else:
4692
4702
  click.echo("❌ Failed to send notification")
4693
4703
  return success
4704
+ except aiohttp.ClientConnectorError:
4705
+ click.echo("❌ Cannot connect to OpenCode server")
4706
+ click.echo(f" Is OpenCode running at {config.server_url}?")
4707
+ return False
4694
4708
  except Exception as e:
4695
4709
  click.echo(f"❌ Error: {e}")
4696
4710
  return False
@@ -4703,5 +4717,225 @@ def opencode_notify(ctx, message, title, level):
4703
4717
  sys.exit(1)
4704
4718
 
4705
4719
 
4720
+ @opencode.command("setup")
4721
+ @click.option("--yes", "-y", is_flag=True, help="Skip confirmation prompts")
4722
+ @click.option("--dry-run", is_flag=True, help="Show what would be changed without modifying files")
4723
+ @click.option("--config", "config_path", type=click.Path(), help="Path to OpenCode config file")
4724
+ @click.option("--memory/--no-memory", default=True, help="Include memory MCP server")
4725
+ @click.option("--tasks/--no-tasks", default=True, help="Include tasks MCP server")
4726
+ @click.pass_context
4727
+ def opencode_setup(ctx, yes, dry_run, config_path, memory, tasks):
4728
+ """Configure OpenCode to use Sugar's MCP servers
4729
+
4730
+ Automatically finds and updates your OpenCode config file to add
4731
+ Sugar's MCP servers for memory and task management.
4732
+
4733
+ Examples:
4734
+
4735
+ sugar opencode setup # Interactive setup
4736
+
4737
+ sugar opencode setup --yes # Non-interactive, apply changes
4738
+
4739
+ sugar opencode setup --dry-run # Preview changes without applying
4740
+ """
4741
+ import json
4742
+ import os
4743
+ import re
4744
+ from pathlib import Path
4745
+
4746
+ click.echo("🔗 OpenCode Setup for Sugar")
4747
+ click.echo("=" * 40)
4748
+
4749
+ # Find OpenCode config file
4750
+ def find_opencode_config():
4751
+ """Find OpenCode config file in order of precedence."""
4752
+ candidates = []
4753
+
4754
+ # Check explicit config path
4755
+ if config_path:
4756
+ return Path(config_path) if Path(config_path).exists() else None
4757
+
4758
+ # Check environment variable
4759
+ env_config = os.environ.get("OPENCODE_CONFIG")
4760
+ if env_config:
4761
+ candidates.append(Path(env_config))
4762
+
4763
+ env_config_dir = os.environ.get("OPENCODE_CONFIG_DIR")
4764
+ if env_config_dir:
4765
+ candidates.append(Path(env_config_dir) / "opencode.json")
4766
+ candidates.append(Path(env_config_dir) / "opencode.jsonc")
4767
+
4768
+ # Check project-local config
4769
+ candidates.extend([
4770
+ Path(".opencode") / "opencode.json",
4771
+ Path(".opencode") / "opencode.jsonc",
4772
+ ])
4773
+
4774
+ # Check user config directory
4775
+ home = Path.home()
4776
+ candidates.extend([
4777
+ home / ".config" / "opencode" / "opencode.json",
4778
+ home / ".config" / "opencode" / "opencode.jsonc",
4779
+ ])
4780
+
4781
+ for candidate in candidates:
4782
+ if candidate.exists():
4783
+ return candidate
4784
+
4785
+ return None
4786
+
4787
+ def parse_jsonc(content):
4788
+ """Parse JSON with comments (JSONC)."""
4789
+ # First try standard JSON - most configs won't have comments
4790
+ try:
4791
+ return json.loads(content)
4792
+ except json.JSONDecodeError:
4793
+ pass
4794
+
4795
+ # Fall back to JSONC parsing
4796
+ # Remove single-line comments (but not :// in URLs)
4797
+ # Match // only when preceded by whitespace or start of line
4798
+ content = re.sub(r'(?<![:])\s*//.*$', '', content, flags=re.MULTILINE)
4799
+ # Remove multi-line comments
4800
+ content = re.sub(r'/\*.*?\*/', '', content, flags=re.DOTALL)
4801
+ # Remove trailing commas before } or ]
4802
+ content = re.sub(r',(\s*[}\]])', r'\1', content)
4803
+ return json.loads(content)
4804
+
4805
+ def format_json(data):
4806
+ """Format JSON with nice indentation."""
4807
+ return json.dumps(data, indent=2)
4808
+
4809
+ # Find config
4810
+ config_file = find_opencode_config()
4811
+
4812
+ if not config_file:
4813
+ click.echo("\n❌ Could not find OpenCode config file")
4814
+ click.echo("\nLooked in:")
4815
+ click.echo(" - .opencode/opencode.json (project)")
4816
+ click.echo(" - ~/.config/opencode/opencode.json (user)")
4817
+ click.echo("\nTo create a config file:")
4818
+ click.echo(" mkdir -p ~/.config/opencode")
4819
+ click.echo(' echo \'{"$schema": "https://opencode.ai/config.json"}\' > ~/.config/opencode/opencode.json')
4820
+ click.echo("\nThen run: sugar opencode setup")
4821
+ sys.exit(1)
4822
+
4823
+ click.echo(f"\n📁 Found config: {config_file}")
4824
+
4825
+ # Read existing config
4826
+ try:
4827
+ content = config_file.read_text()
4828
+ if content.strip():
4829
+ config = parse_jsonc(content)
4830
+ else:
4831
+ config = {}
4832
+ except json.JSONDecodeError as e:
4833
+ click.echo(f"\n❌ Failed to parse config file: {e}")
4834
+ click.echo("Please fix the JSON syntax and try again")
4835
+ sys.exit(1)
4836
+ except Exception as e:
4837
+ click.echo(f"\n❌ Failed to read config file: {e}")
4838
+ sys.exit(1)
4839
+
4840
+ # Build MCP server configs
4841
+ mcp_servers = {}
4842
+
4843
+ if tasks:
4844
+ mcp_servers["sugar-tasks"] = {
4845
+ "type": "local",
4846
+ "command": ["sugar", "mcp", "tasks"]
4847
+ }
4848
+
4849
+ if memory:
4850
+ mcp_servers["sugar-memory"] = {
4851
+ "type": "local",
4852
+ "command": ["sugar", "mcp", "memory"]
4853
+ }
4854
+
4855
+ if not mcp_servers:
4856
+ click.echo("\n⚠️ No servers selected. Use --tasks and/or --memory")
4857
+ sys.exit(1)
4858
+
4859
+ # Check what's already configured
4860
+ existing_mcp = config.get("mcp", {})
4861
+ servers_to_add = {}
4862
+ servers_existing = []
4863
+
4864
+ for name, server_config in mcp_servers.items():
4865
+ if name in existing_mcp:
4866
+ servers_existing.append(name)
4867
+ else:
4868
+ servers_to_add[name] = server_config
4869
+
4870
+ if not servers_to_add:
4871
+ click.echo("\n✅ Sugar MCP servers already configured!")
4872
+ click.echo("\nConfigured servers:")
4873
+ for name in servers_existing:
4874
+ click.echo(f" • {name}")
4875
+ click.echo("\nRun 'sugar opencode test' to verify connectivity")
4876
+ sys.exit(0)
4877
+
4878
+ # Show what will be added
4879
+ click.echo("\n📦 Sugar MCP servers to add:")
4880
+ for name, server_config in servers_to_add.items():
4881
+ desc = "task queue management" if "tasks" in name else "memory/context system"
4882
+ click.echo(f" + {name} ({desc})")
4883
+
4884
+ if servers_existing:
4885
+ click.echo("\n✓ Already configured:")
4886
+ for name in servers_existing:
4887
+ click.echo(f" • {name}")
4888
+
4889
+ # Build new config
4890
+ new_config = config.copy()
4891
+ if "mcp" not in new_config:
4892
+ new_config["mcp"] = {}
4893
+ new_config["mcp"].update(servers_to_add)
4894
+
4895
+ # Show preview
4896
+ click.echo("\n📝 Config changes:")
4897
+ click.echo("-" * 40)
4898
+
4899
+ # Show just the mcp section that will be added
4900
+ preview = {"mcp": servers_to_add}
4901
+ click.echo(format_json(preview))
4902
+ click.echo("-" * 40)
4903
+
4904
+ if dry_run:
4905
+ click.echo("\n🔍 Dry run - no changes made")
4906
+ click.echo("\nFull config would be:")
4907
+ click.echo(format_json(new_config))
4908
+ sys.exit(0)
4909
+
4910
+ # Confirm
4911
+ if not yes:
4912
+ if not click.confirm("\nApply changes?", default=True):
4913
+ click.echo("Cancelled")
4914
+ sys.exit(0)
4915
+
4916
+ # Write config
4917
+ try:
4918
+ config_file.write_text(format_json(new_config) + "\n")
4919
+ click.echo(f"\n✅ Config updated: {config_file}")
4920
+ except Exception as e:
4921
+ click.echo(f"\n❌ Failed to write config: {e}")
4922
+ sys.exit(1)
4923
+
4924
+ # Success message
4925
+ click.echo("\n" + "=" * 40)
4926
+ click.echo("🎉 Setup complete!")
4927
+ click.echo("\nNext steps:")
4928
+ click.echo(" 1. Restart OpenCode to load the new MCP servers")
4929
+ click.echo(" 2. Run 'sugar opencode test' to verify connectivity")
4930
+ click.echo("\nIn OpenCode, you'll have access to Sugar tools:")
4931
+ if tasks:
4932
+ click.echo(" • sugar_add_task - Add tasks to the queue")
4933
+ click.echo(" • sugar_list_tasks - View queued tasks")
4934
+ click.echo(" • sugar_get_task - Get task details")
4935
+ if memory:
4936
+ click.echo(" • sugar_remember - Store memories")
4937
+ click.echo(" • sugar_recall - Search memories")
4938
+
4939
+
4706
4940
  if __name__ == "__main__":
4707
4941
  cli()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sugarai
3
- Version: 3.6.0
3
+ Version: 3.7.0.dev0
4
4
  Summary: 🍰 Sugar - The autonomous layer for AI coding agents. Manages task queues, runs 24/7, ships working code.
5
5
  Author-email: Steven Leggett <contact@roboticforce.io>
6
6
  License: AGPL-3.0-or-later
@@ -102,13 +102,10 @@ Sugar has **first-class integrations** with leading AI coding agents:
102
102
  claude mcp add sugar -- sugar mcp memory
103
103
  ```
104
104
 
105
- **OpenCode** - Native plugin with real-time notifications:
105
+ **OpenCode** - One-command setup with MCP integration:
106
106
  ```bash
107
- # Check integration status
108
- sugar opencode status
109
-
110
- # Test connection
111
- sugar opencode test
107
+ sugar opencode setup # Automatically configures OpenCode
108
+ # Then restart OpenCode
112
109
  ```
113
110
 
114
111
  Both integrations support **automatic memory injection** - Sugar injects relevant context (decisions, preferences, error patterns) into your AI sessions automatically.
@@ -393,37 +390,35 @@ Claude: "I'll create a Sugar task for the test fixes."
393
390
 
394
391
  ### OpenCode Integration
395
392
 
396
- Sugar has native bidirectional integration with [OpenCode](https://github.com/opencode-ai/opencode):
393
+ Sugar has native MCP integration with [OpenCode](https://github.com/opencode-ai/opencode):
397
394
 
398
395
  **Features:**
399
- - Real-time task notifications (start, complete, fail)
396
+ - MCP servers for task management and memory access
400
397
  - Automatic memory injection into OpenCode sessions
401
398
  - Context-aware memory retrieval based on current work
402
- - Learning capture from session outcomes
403
399
 
404
400
  **Quick Setup:**
405
401
  ```bash
406
- # Install OpenCode integration dependencies
407
- pipx inject sugarai aiohttp
402
+ # One-command setup - adds Sugar MCP servers to OpenCode config
403
+ sugar opencode setup
408
404
 
409
- # Check integration status
405
+ # Restart OpenCode to load the new servers
406
+ # Then verify:
410
407
  sugar opencode status
411
-
412
- # Test connection (requires OpenCode server running)
413
- sugar opencode test
414
-
415
- # Send a test notification
416
- sugar opencode notify "Hello from Sugar!" --title "Test" --level success
417
408
  ```
418
409
 
419
- **Environment Variables:**
410
+ The setup command automatically:
411
+ - Finds your OpenCode config file
412
+ - Adds `sugar-tasks` and `sugar-memory` MCP servers
413
+ - Preserves your existing configuration
414
+
415
+ **Options:**
420
416
  ```bash
421
- OPENCODE_SERVER_URL=http://localhost:4096 # OpenCode server URL
422
- SUGAR_OPENCODE_ENABLED=true # Enable/disable integration
417
+ sugar opencode setup --dry-run # Preview changes without applying
418
+ sugar opencode setup --yes # Non-interactive mode
419
+ sugar opencode setup --no-memory # Only add task server
423
420
  ```
424
421
 
425
- When Sugar executes tasks, it automatically sends notifications to OpenCode so you can track progress in real-time.
426
-
427
422
  ### MCP Server Integration
428
423
 
429
424
  Sugar provides MCP servers for Goose, Claude Code, Claude Desktop, and other MCP clients.