Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cmake/package.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ set(FLATBUFFERS_BUILD_FLATHASH OFF CACHE BOOL "" FORCE)
FetchContent_Declare(
kotatsu
GIT_REPOSITORY https://github.com/clice-io/kotatsu
GIT_TAG main
GIT_SHALLOW TRUE
GIT_TAG e024f3b427a554502c4aa015952800a03ca4384b
)

set(KOTA_ENABLE_ZEST ON)
Expand Down
2 changes: 1 addition & 1 deletion docs/en/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ String values support `${workspace}` substitution.

## IPC Protocol

The master and workers communicate using custom RPC messages defined in `src/server/protocol.h`. Each message type has a `RequestTraits` or `NotificationTraits` specialization that defines the method name and result type.
The master and workers communicate using custom RPC messages defined in `src/server/protocol/`. Each message type has a `RequestTraits` or `NotificationTraits` specialization that defines the method name and result type.

### Stateful Worker Messages

Expand Down
114 changes: 32 additions & 82 deletions src/clice.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,31 @@
#include <print>
#include <string>

#include "server/master_server.h"
#include "server/stateful_worker.h"
#include "server/stateless_worker.h"
#include "server/service/agentic.h"
#include "server/service/master_server.h"
#include "server/worker/stateful_worker.h"
#include "server/worker/stateless_worker.h"
#include "support/logging.h"

#include "kota/async/async.h"
#include "kota/deco/deco.h"
#include "kota/ipc/codec/json.h"
#include "kota/ipc/peer.h"
#include "kota/ipc/recording_transport.h"
#include "kota/ipc/transport.h"

namespace clice {

using kota::deco::decl::KVStyle;

struct Options {
DecoKV(style = KVStyle::JoinedOrSeparate,
help = "Running mode: pipe, socket, stateless-worker, stateful-worker",
help = "Running mode: pipe, socket, agentic, stateless-worker, stateful-worker",
required = false)
<std::string> mode;

DecoKV(style = KVStyle::JoinedOrSeparate, help = "Socket mode address", required = false)
<std::string> host = "127.0.0.1";

DecoKV(style = KVStyle::JoinedOrSeparate, help = "Socket mode port", required = false)
<int> port = 50051;
DecoKV(style = KVStyle::JoinedOrSeparate,
help = "Agentic TCP port (0 = disabled)",
required = false)
<int> port = 0;

DecoKV(style = KVStyle::JoinedOrSeparate,
names = {"--log-level", "--log-level="},
Expand All @@ -43,6 +41,11 @@ struct Options {
required = false)
<std::string> record;

DecoKV(style = KVStyle::JoinedOrSeparate,
help = "File path for agentic queries",
required = false)
<std::string> path;

// Internal options (passed from master to worker processes)
DecoKV(style = KVStyle::JoinedOrSeparate,
names = {"--worker-memory-limit", "--worker-memory-limit="},
Expand All @@ -68,9 +71,6 @@ struct Options {

int main(int argc, const char** argv) {
#ifndef _WIN32
// On POSIX systems, ignore SIGPIPE so that writing to a closed pipe
// (e.g. when the LSP client disconnects) returns EPIPE instead of
// killing the process. This is standard practice for pipe-based servers.
signal(SIGPIPE, SIG_IGN);
#endif

Expand Down Expand Up @@ -110,8 +110,6 @@ int main(int argc, const char** argv) {
return 1;
}

std::string self_path = argv[0];

auto& mode = *opts.mode;

auto worker_name = opts.worker_name.value_or("");
Expand All @@ -131,77 +129,29 @@ int main(int argc, const char** argv) {
log_dir);
}

if(mode == "pipe") {
clice::logging::stderr_logger("master", clice::logging::options);

kota::event_loop loop;

auto transport = kota::ipc::StreamTransport::open_stdio(loop);
if(!transport) {
LOG_ERROR("failed to open stdio transport");
return 1;
}

std::unique_ptr<kota::ipc::Transport> final_transport = std::move(*transport);
if(opts.record.has_value()) {
final_transport =
std::make_unique<kota::ipc::RecordingTransport>(std::move(final_transport),
*opts.record);
}

kota::ipc::JsonPeer peer(loop, std::move(final_transport));
clice::MasterServer server(loop, peer, std::move(self_path));
server.register_handlers();

loop.schedule(peer.run());
loop.run();
return 0;
if(mode == "pipe" || mode == "socket") {
clice::ServerOptions server_opts;
server_opts.mode = mode;
server_opts.host = opts.host.value_or("127.0.0.1");
server_opts.port = opts.port.value_or(0);
server_opts.self_path = argv[0];
server_opts.record = opts.record.value_or("");
return clice::run_server_mode(server_opts);
}

if(mode == "socket") {
clice::logging::stderr_logger("master", clice::logging::options);

kota::event_loop loop;

if(mode == "agentic") {
auto host = opts.host.value_or("127.0.0.1");
auto port = opts.port.value_or(50051);

auto acceptor = kota::tcp::listen(host, port, {}, loop);
if(!acceptor) {
LOG_ERROR("failed to listen on {}:{}", host, port);
auto port = opts.port.value_or(0);
auto path = opts.path.value_or("");
if(port <= 0) {
LOG_ERROR("--port is required for agentic mode");
return 1;
}

LOG_INFO("Listening on {}:{} ...", host, port);

auto task = [&]() -> kota::task<> {
auto client = co_await acceptor->accept();
if(!client.has_value()) {
LOG_ERROR("failed to accept connection");
loop.stop();
co_return;
}

LOG_INFO("Client connected");

std::unique_ptr<kota::ipc::Transport> transport =
std::make_unique<kota::ipc::StreamTransport>(std::move(client.value()));
if(opts.record.has_value()) {
transport = std::make_unique<kota::ipc::RecordingTransport>(std::move(transport),
*opts.record);
}
kota::ipc::JsonPeer peer(loop, std::move(transport));
clice::MasterServer server(loop, peer, std::string(self_path));
server.register_handlers();

co_await peer.run();
peer.close();
loop.stop();
};

loop.schedule(task());
loop.run();
return 0;
if(path.empty()) {
LOG_ERROR("--path is required for agentic mode");
return 1;
}
return clice::run_agentic_mode(host, port, path);
}

LOG_ERROR("unknown mode '{}'", mode);
Expand Down
4 changes: 0 additions & 4 deletions src/compile/tidy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,11 @@ tidy::ClangTidyOptions create_options() {
// include-cleaner is directly integrated in IncludeCleaner.cpp
"-misc-include-cleaner",

// ----- False Positives -----

// Check relies on seeing ifndef/define/endif directives,
// clangd doesn't replay those when using a preamble.
"-llvm-header-guard",
"-modernize-macro-to-enum",

// ----- Crashing Checks -----

// Check can choke on invalid (intermediate) c++
// code, which is often the case when clangd
// tries to build an AST.
Expand Down
2 changes: 0 additions & 2 deletions src/semantic/resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1111,8 +1111,6 @@ class PseudoInstantiator : public clang::TreeTransform<PseudoInstantiator> {
return Base::TransformDecltypeType(TLB, TL);
}

// --- State ---

private:
clang::Sema& sema;
clang::ASTContext& context;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "server/compile_graph.h"
#include "server/compiler/compile_graph.h"

#include <algorithm>

Expand Down
File renamed without changes.
Loading
Loading