定制 carmelosantana/coqui-toolkit-webserver 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

carmelosantana/coqui-toolkit-webserver

Composer 安装命令:

composer require carmelosantana/coqui-toolkit-webserver

包简介

Web server toolkit for Coqui — serve workspace files over HTTP via PHP's built-in server

README 文档

README

Web server toolkit for Coqui. Gives agents the ability to serve workspace files over HTTP using PHP's built-in web server, with gzip compression, URL rewrites, directory listings, and structured request logging.

Requirements

  • PHP 8.4+
  • POSIX extensions (posix_kill, posix_getpid) — standard on Linux/macOS

Installation

composer require coquibot/coqui-toolkit-webserver

When installed alongside Coqui, the toolkit is auto-discovered via Composer's extra.php-agents.toolkits -- no manual registration needed.

Tools Provided

webserver

Manage web server instances that serve workspace files over HTTP.

Parameter Type Required Description
action enum Yes start, stop, restart, status, list, stop_all
docroot string For start Directory to serve, relative to workspace (e.g. "public", "site/build")
port integer No Port to listen on (auto-detected from 8000 if omitted)
host string No Bind address (default: 127.0.0.1)
name string No Server instance name (auto-generated if omitted)
gzip boolean No Enable gzip compression (default: true)
directory_listing boolean No Enable directory listings (default: false)
php_enabled boolean No Allow PHP file execution (default: true)
rewrites object No URL rewrite rules as regex pattern to replacement map

webserver_log

Query request logs for debugging and monitoring.

Parameter Type Required Description
action enum Yes tail, search, stats, clear
name string No Server instance name (default server if omitted)
limit integer No Max entries to return (default: 20 for tail, 50 for search)
path string No Filter by request path (partial match, for search)
method enum No Filter by HTTP method (GET, POST, etc., for search)
status integer No Filter by status code (for search)

Agent Workflow

  1. Create content files in a workspace directory
  2. webserver action start with docroot pointing to that directory
  3. Access the returned URL in a browser or with browser tools
  4. webserver_log action tail to check incoming requests
  5. webserver_log action stats to see traffic patterns
  6. webserver action stop when done

Features

Gzip Compression

Enabled by default. Compresses text-based responses (HTML, CSS, JS, JSON, SVG, XML) when the client accepts gzip encoding. Only compresses files larger than 1KB.

URL Rewrites

Pass regex-based rewrite rules to transform URLs before file resolution. Common patterns:

// SPA fallback — serve index.html for all non-API routes
{"^(?!/api).*$": "/index.html"}

// Route API requests through a PHP script
{"^/api/(.*)$": "/api.php?route=$1"}

Only the first matching rule is applied per request.

Directory Listings

Disabled by default. When enabled, the server generates a clean HTML directory listing when a directory is requested and no index file exists. Hidden files (starting with .) are excluded.

PHP Execution

Enabled by default. The server executes .php files placed in the docroot using PHP's built-in server handler. When disabled, .php files return 403 Forbidden.

Request Logging

Every request is logged to a per-instance SQLite database at .workspace/webserver/{name}.db. Logs include timestamp, method, path, query string, status code, response size, duration, user agent, and client IP.

Multiple Servers

Run multiple servers concurrently by specifying different name values. Each server has its own port, docroot, configuration, and log database.

Security

  • Localhost only: Servers bind to 127.0.0.1 by default. Use host: "0.0.0.0" to allow network access (use with caution).
  • Workspace sandboxing: Only files within the workspace directory can be served. Path traversal attempts are blocked.
  • Sensitive file blocking: .env, .git/, .workspace/, vendor/, node_modules/, *.db, *.sqlite, *.log, *.pid, *.pem, *.key, composer.json, composer.lock, package.json are automatically blocked (403 Forbidden).
  • Process isolation: Each server runs as a separate PHP process with no access to Coqui internals.
  • File size limit: Files larger than 50MB return 413 Content Too Large.
  • Security headers: X-Content-Type-Options: nosniff, X-Frame-Options: SAMEORIGIN, X-XSS-Protection are set on all responses.

Architecture

WebServerToolkit (ToolkitInterface)
    |
    +-- WebServerTool (server lifecycle: start/stop/restart/status/list)
    |       |
    |       +-- WebServerRunner (process management: proc_open, PID files, SIGTERM/SIGKILL)
    |
    +-- WebServerLogTool (log queries: tail/search/stats/clear)
            |
            +-- WebServerLogStore (SQLite request log: read/write/aggregate)

Router Script (src/Resources/router.php)
    - Runs inside the separate `php -S` process
    - Handles static files, PHP execution, gzip, rewrites, directory listings
    - Writes to SQLite log database directly
    - No access to Coqui internals

Workspace Files

At runtime, server data is stored in .workspace/webserver/:

.workspace/webserver/
    {name}.pid              # PID of running server process
    {name}.json             # Server metadata (port, host, docroot, options, started_at)
    {name}-router.php       # Copy of the router script with env-based config
    {name}-rewrites.json    # Rewrite rules (if configured)
    {name}.db               # SQLite request log database
    {name}.log              # Server stdout/stderr output

Standalone Usage

<?php

declare(strict_types=1);

use CoquiBot\Toolkits\Webserver\WebServerToolkit;

require __DIR__ . '/vendor/autoload.php';

$toolkit = WebServerToolkit::fromEnv();

foreach ($toolkit->tools() as $tool) {
    echo $tool->name() . ': ' . $tool->description() . PHP_EOL;
}

// Start a server
$server = $toolkit->tools()[0];
$result = $server->execute([
    'action' => 'start',
    'docroot' => 'public',
    'port' => 8080,
]);
echo $result->content;

Development

git clone https://github.com/AgentCoqui/coqui-toolkit-webserver.git
cd coqui-toolkit-webserver
composer install

Run tests

./vendor/bin/pest

Static analysis

./vendor/bin/phpstan analyse

License

MIT

carmelosantana/coqui-toolkit-webserver 适用场景与选型建议

carmelosantana/coqui-toolkit-webserver 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「http」 「toolkit」 「webserver」 「static-files」 「php-agents」 「coqui」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 carmelosantana/coqui-toolkit-webserver 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 carmelosantana/coqui-toolkit-webserver 我们能提供哪些服务?
定制开发 / 二次开发

基于 carmelosantana/coqui-toolkit-webserver 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 32
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-08