feat: add v2 task control and asynchronous isolated workers

This commit is contained in:
WHC
2026-10-20 14:46:57 +08:00
parent 143dba203b
commit d971cb02b0
26 changed files with 1590 additions and 66 deletions
+42
View File
@@ -0,0 +1,42 @@
#ifndef CST_RUNTIME_H
#define CST_RUNTIME_H
#include "cst_agent.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct cst_runtime cst_runtime_t;
typedef int (*cst_job_fn)(void *data, volatile int *cancel, cst_tool_result_t *result);
typedef void (*cst_job_free_fn)(void *data);
cst_runtime_t *cst_runtime_open(const char *session_path);
void cst_runtime_close(cst_runtime_t *r);
unsigned long cst_runtime_begin(cst_runtime_t *r, const char *goal);
unsigned long cst_runtime_revision(cst_runtime_t *r);
int cst_runtime_steer(cst_runtime_t *r, const char *message, int readonly, int delegation);
char *cst_runtime_take_steering(cst_runtime_t *r);
int cst_runtime_controls(cst_runtime_t *r, int readonly, int delegation, int paused);
int cst_runtime_check(cst_runtime_t *r, unsigned long revision, int mutating, int delegate);
void cst_runtime_cancel(cst_runtime_t *r, const char *source, int force);
char *cst_runtime_evidence(cst_runtime_t *r, const char *tool, int exit_code,
const char *output, int mutating);
int cst_runtime_finish(cst_runtime_t *r, const char *status, const char *summary,
int action, char *err, size_t err_sz);
char *cst_runtime_json(cst_runtime_t *r);
int cst_job_start(cst_runtime_t *r, const char *kind, const char *resource,
int interruptible, cst_job_fn fn, void *data,
cst_job_free_fn destroy, char *id, size_t id_sz);
/* Waits at most timeout_ms; output is a JSON snapshot, not a destructive read. */
char *cst_job_read(cst_runtime_t *r, const char *id, int timeout_ms);
int cst_job_cancel(cst_runtime_t *r, const char *id, int force, const char *source);
int cst_runtime_jobs_pending(cst_runtime_t *r);
int cst_runtime_current_jobs_pending(cst_runtime_t *r);
int cst_runtime_resource_busy(cst_runtime_t *r, const char *resource);
int cst_runtime_wait(cst_runtime_t *r, int timeout_ms);
/* Model tools, shared by every front end. */
int cst_runtime_register_tools(void);
struct cst_tool_ctx;
int cst_runtime_shell(const struct cst_tool_ctx *ctx, const ctl_tool_call_t *call,
cst_tool_result_t *result);
#ifdef __cplusplus
}
#endif
#endif