feat: parliament daemon, login gate, peer context sync (0.9.13)
Login claims the chair, writes a session ticket, and starts a background service for discovery plus revision-based context sync. Password Realm opens require --login (or CST_REALM_PASSWORD); --service/--service-stop manage the resident agent. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+68
-2
@@ -1,7 +1,9 @@
|
||||
#include "cst_agent.h"
|
||||
#include "cst_ext.h"
|
||||
#include "cst_models.h"
|
||||
#include "cst_parliament.h"
|
||||
#include "cst_parliament_cli.h"
|
||||
#include "cst_realm.h"
|
||||
#include "cst_tools.h"
|
||||
#include "cst_version.h"
|
||||
#include "cst_webui.h"
|
||||
@@ -50,7 +52,10 @@ static void usage(const char *argv0) {
|
||||
" --no-orchestrate override workspace orchestration setting\n"
|
||||
" --realm-new create Realm file keys (legacy/dev)\n"
|
||||
" --realm-password-init create password-derived Realm (no sk on disk)\n"
|
||||
" --login unlock with password; this device becomes chair\n"
|
||||
" --login unlock; claim chair; start parliament service\n"
|
||||
" --service run parliament service (discover+context sync)\n"
|
||||
" --service-fg same as --service, stay in foreground\n"
|
||||
" --service-stop stop the parliament background service\n"
|
||||
" --new-project ID replace all parliament context for a new project\n"
|
||||
" --realm-enroll ID enroll this instance under the Realm\n"
|
||||
" --realm-label S display label for enroll/login\n"
|
||||
@@ -374,7 +379,8 @@ int main(int argc, char **argv) {
|
||||
int new_session = 0, do_list = 0, do_migrate = 0;
|
||||
const char *resume_id = NULL;
|
||||
int do_realm_new = 0, do_realm_enroll = 0, do_peer_listen = 0, do_peer_dial = 0,
|
||||
do_discover = 0, do_realm_pw_init = 0, do_login = 0, do_new_project = 0;
|
||||
do_discover = 0, do_realm_pw_init = 0, do_login = 0, do_new_project = 0,
|
||||
do_service = 0, do_service_fg = 0, do_service_stop = 0;
|
||||
const char *realm_enroll_id = NULL, *realm_label = NULL;
|
||||
const char *peer_dial_spec = NULL, *parliament_instance = NULL;
|
||||
const char *new_project_id = NULL;
|
||||
@@ -439,6 +445,9 @@ int main(int argc, char **argv) {
|
||||
{"realm-password-init", no_argument, 0, 0x118},
|
||||
{"login", no_argument, 0, 0x119},
|
||||
{"new-project", required_argument, 0, 0x11a},
|
||||
{"service", no_argument, 0, 0x11b},
|
||||
{"service-fg", no_argument, 0, 0x11c},
|
||||
{"service-stop", no_argument, 0, 0x11d},
|
||||
{0, 0, 0, 0}};
|
||||
int c;
|
||||
while ((c = getopt_long(argc, argv, "w:s:b:k:m:P:r:n:T:Hp:dahVNcR:LyA:C:e:M:",
|
||||
@@ -492,6 +501,15 @@ int main(int argc, char **argv) {
|
||||
do_new_project = 1;
|
||||
new_project_id = optarg;
|
||||
break;
|
||||
case 0x11b:
|
||||
do_service = 1;
|
||||
break;
|
||||
case 0x11c:
|
||||
do_service_fg = 1;
|
||||
break;
|
||||
case 0x11d:
|
||||
do_service_stop = 1;
|
||||
break;
|
||||
case 'w':
|
||||
snprintf(cfg.workspace_root, sizeof(cfg.workspace_root), "%s", optarg);
|
||||
break;
|
||||
@@ -675,6 +693,22 @@ int main(int argc, char **argv) {
|
||||
curl_global_cleanup();
|
||||
return rc;
|
||||
}
|
||||
if (do_service_stop) {
|
||||
int rc = cst_parliament_cli_service_stop();
|
||||
curl_global_cleanup();
|
||||
return rc;
|
||||
}
|
||||
if (do_service || do_service_fg) {
|
||||
const char *pw = getenv("CST_REALM_PASSWORD");
|
||||
const char *iid = parliament_instance ? parliament_instance
|
||||
: getenv("CST_INSTANCE_ID");
|
||||
if (!iid || !iid[0])
|
||||
iid = "chair-local";
|
||||
int rc = cst_parliament_cli_service(pw, iid, discover_peer_port,
|
||||
do_service_fg);
|
||||
curl_global_cleanup();
|
||||
return rc;
|
||||
}
|
||||
if (do_realm_enroll) {
|
||||
int rc = cst_parliament_cli_realm_enroll(realm_enroll_id, realm_label);
|
||||
curl_global_cleanup();
|
||||
@@ -715,6 +749,38 @@ int main(int argc, char **argv) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Password Realm: interactive/agent open requires a chair login session. */
|
||||
{
|
||||
char rdir[OS_PATH_MAX];
|
||||
if (cst_realm_dir(rdir, sizeof(rdir)) == 0 &&
|
||||
cst_realm_is_password_mode(rdir) && !cst_parliament_session_ok(NULL, 0)) {
|
||||
const char *pw = getenv("CST_REALM_PASSWORD");
|
||||
if (pw && pw[0]) {
|
||||
const char *iid = parliament_instance ? parliament_instance
|
||||
: getenv("CST_INSTANCE_ID");
|
||||
if (!iid || !iid[0])
|
||||
iid = "chair-local";
|
||||
char err[256];
|
||||
char *hand =
|
||||
cst_parliament_login(pw, iid, realm_label, err, sizeof(err));
|
||||
if (!hand) {
|
||||
fprintf(stderr, "%s\n", err[0] ? err : "login required");
|
||||
curl_global_cleanup();
|
||||
return 1;
|
||||
}
|
||||
free(hand);
|
||||
(void)cst_parliament_daemon_start(pw, iid, discover_peer_port, err,
|
||||
sizeof(err));
|
||||
} else {
|
||||
fprintf(stderr,
|
||||
"password Realm active: run --login (or set "
|
||||
"CST_REALM_PASSWORD) before opening the agent\n");
|
||||
curl_global_cleanup();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (do_list) {
|
||||
int rc = list_sessions(cfg.workspace_root);
|
||||
curl_global_cleanup();
|
||||
|
||||
Reference in New Issue
Block a user