candycore/sugar-crush
最新稳定版本:v0.2.0
Composer 安装命令:
composer create-project candycore/sugar-crush
包简介
Chat-shell TUI for AI coding assistants — port of charmbracelet/crush. Pluggable Backend interface (ship your own Anthropic / OpenAI / Ollama / shell-out adapter). Markdown rendering of replies via CandyShine, scrollback viewport via SugarBits, input area via SugarBits TextArea.
README 文档
README
SugarCrush
Chat-shell TUI for AI coding assistants — port of charmbracelet/crush. Pluggable backends (ship your own Anthropic / OpenAI / Ollama / shell-out adapter), Markdown rendering of replies via CandyShine, scrollback above a fixed input box.
┌─ SugarCrush ───────────────────────────────────────┐
│ user> explain fiber-based scheduling in PHP │
│ │
│ assistant │
│ ## Fibers (PHP 8.1+) │
│ │
│ Fibers are cooperative units of execution … │
└────────────────────────────────────────────────────┘
┌────────────────────────────────────────────────────┐
│ > how do they relate to ReactPHP?█ │
└────────────────────────────────────────────────────┘
Enter to send · Esc / ^C to quit
Run it
composer install ./bin/sugarcrush
By default it ships with EchoBackend so the binary is runnable offline (the assistant just echoes what you typed). To wire it to a real LLM, set $SUGARCRUSH_BACKEND_CMD to a command that reads JSON history on stdin and writes the reply to stdout:
export SUGARCRUSH_BACKEND_CMD=~/bin/anthropic-stream.sh ./bin/sugarcrush
Sample wrapper script (Anthropic)
#!/usr/bin/env bash # ~/bin/anthropic-stream.sh payload=$(jq -nc --argjson h "$(cat)" \ '{model: "claude-opus-4-7", max_tokens: 4096, messages: $h}') curl -sN https://api.anthropic.com/v1/messages \ -H "x-api-key: $ANTHROPIC_API_KEY" \ -H "anthropic-version: 2023-06-01" \ -H "content-type: application/json" \ -d "$payload" \ | jq -r '.content[0].text'
chmod +x ~/bin/anthropic-stream.sh and you're done.
The wrapper-script approach is deliberate: keeps the PHP package network-dep-free, lets you swap providers without changing PHP code, and makes prompt-engineering iteration as fast as editing a shell script.
Writing a custom Backend
If you'd rather skip the shell-out dance and integrate the SDK directly, implement the Backend interface in PHP:
use SugarCraft\Crush\{Backend, Chat, Message}; final class MyBackend implements Backend { public function complete(array $history): Message { $reply = /* your call here, returning a string */; return Message::assistant($reply); } } (new Program(new Chat(backend: new MyBackend())))->run();
Architecture
| File | Role |
|---|---|
Role enum |
system / user / assistant — matches every API's wire vocab |
Message |
VO: role, content, createdAt; toWire() for adapters |
Backend interface |
complete(list<Message>): Message |
Backend\EchoBackend |
Offline default — echoes the last user message |
Backend\CommandBackend |
Shells out via proc_open; JSON history → stdin → stdout reply |
AssistantMsg |
Internal Msg — fires when a backend completion arrives |
Chat |
SugarCraft Model — history, input buffer, inFlight gate |
Renderer |
Pure view fn — CandyShine-rendered scrollback + input box |
Test plan
- 21 tests / 43 assertions
Message: factories, wire shape, custom timestampsEchoBackend: echoes most recent user, handles empty historyCommandBackend: history is JSON-piped to stdin, exit code surfaced as error message, missing command handled gracefullyChat: type accumulation, space, UTF-8-aware backspace, Enter submits + clears + arms inFlight, empty submit no-op, AssistantMsg appends + clears inFlight, keystrokes ignored while inFlight, Esc quits, full echo round-trip via the realEchoBackend
Status
Phase 9+ entry #17 — first cut. Single-shot replies (no streaming yet); StreamingBackend interface is the obvious follow-up. Markdown rendering, persistent input buffer, and the inFlight gate are all wired.
candycore/sugar-crush 适用场景与选型建议
candycore/sugar-crush 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 05 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「chat」 「ai」 「crush」 「openai」 「llm」 「tui」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 candycore/sugar-crush 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 candycore/sugar-crush 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 candycore/sugar-crush 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This simple PHP class allows you to easily generate Smartsupp.com JS chat code.
Client for the REST API plugin of the OpenFire Server
PHP 8.0+ OpenAI API client with fully typed/documented requests+responses models, guzzle and symfony/http-client support and async/parallel requests.
Estimate AI API costs before making expensive calls
A powerful package that seamlessly integrates OpenAI's advanced AI capabilities into your Laravel applications. This package offers quick setup and intuitive configuration to leverage AI models for chat, embeddings, and more.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 44
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-05-07
