feat: add v2 task control and asynchronous isolated workers
This commit is contained in:
@@ -112,14 +112,17 @@ typedef struct {
|
||||
/* Sub-agents (task tool). */
|
||||
int depth; /* 0 = top-level; sub-agents run at 1 */
|
||||
int orchestrate; /* coordinator delegates write/shell work */
|
||||
struct cst_runtime *runtime; /* V2 task controller; parent-owned */
|
||||
int orchestrate_override; /* CLI: 1 force on, -1 force off */
|
||||
int subagent_steps, subagent_tasks, subagent_total;
|
||||
void *worker_budget; /* owned by the top-level agent */
|
||||
int (*request_gate)(void *); /* reserve budget before each HTTP attempt */
|
||||
void *request_gate_ud;
|
||||
unsigned long task_revision;
|
||||
char cache_namespace[128];
|
||||
int read_only; /* no write / shell tools */
|
||||
char tools_only[1024]; /* ",a,b," allowlist; empty = every tool */
|
||||
char worker_scope[2048]; /* isolated worker's JSON path allowlist */
|
||||
const char *role_prompt; /* role instructions (not owned) */
|
||||
char undo_sid[128]; /* snapshot into this session's undo... */
|
||||
char undo_tag[64]; /* ...under this turn tag (the parent's) */
|
||||
@@ -387,6 +390,8 @@ cst_session_t *cst_agent_session(cst_agent_t *a);
|
||||
const cst_agent_config_t *cst_agent_config(const cst_agent_t *a);
|
||||
cst_agent_config_t *cst_agent_config_mut(cst_agent_t *a);
|
||||
void cst_agent_request_cancel(cst_agent_t *a);
|
||||
int cst_agent_steer(cst_agent_t *a, const char *message, int readonly, int delegation);
|
||||
int cst_agent_control(cst_agent_t *a, int readonly, int delegation, int paused);
|
||||
int cst_agent_new_session(cst_agent_t *a, char *id_out, size_t id_sz);
|
||||
int cst_agent_switch_session(cst_agent_t *a, const char *id);
|
||||
/* Re-root the agent at another directory. Per-workspace state (permission
|
||||
|
||||
@@ -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
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef CST_WORKTREE_H
|
||||
#define CST_WORKTREE_H
|
||||
#include <stddef.h>
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/* files is a JSON array of workspace-relative paths. No caller index changes. */
|
||||
int cst_worktree_create(const char *workspace, const char *files, char *out,
|
||||
size_t out_sz, char *err, size_t err_sz);
|
||||
char *cst_worktree_diff(const char *workspace, const char *worktree, int integrate,
|
||||
int *code);
|
||||
int cst_worktree_path_allowed(const char *files, const char *relative_path);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -130,6 +130,9 @@ void os_set_cancel_flag(volatile int *flag);
|
||||
volatile int *os_get_cancel_flag(void);
|
||||
void os_set_run_timeout(int seconds); /* this thread; 0 = default */
|
||||
int os_get_run_timeout(void);
|
||||
typedef struct { void (*write)(const char *, size_t, void *); void *userdata; } os_output_observer_t;
|
||||
void os_set_output_observer(os_output_observer_t *observer);
|
||||
void os_observe_output(const char *data, size_t n);
|
||||
|
||||
/* Long-lived child with pipes on stdin/stdout (MCP servers). stderr goes
|
||||
* to stderr_path (NULL = discarded). env_add: "KEY=VALUE" entries added to
|
||||
|
||||
Reference in New Issue
Block a user