Windows: official port -- UCRT static build, UTF-8 throughout, Low IL sandbox, ncurses TUI, installer; v0.6.0
Build
* cross build switches to pkgsCross.ucrt64 (shell-win.nix); curl (Schannel),
winpthreads and ncurses 6.6 are linked statically, so the release is
cst-agent.exe + busybox.exe (busybox-w32 Unicode) with no extra DLLs
* windres embeds a manifest with activeCodePage=UTF-8 and a version resource
* ncurses 6.6 Windows console driver patches (mouse button state, A_DIM,
wide-char declarations): scripts/patches/
* scripts/bootstrap_msys2.sh builds the same release natively in MSYS2
UCRT64; PR #1's MINGW64 notes now point there
* vendor/tre-regex (musl's TRE) provides <regex.h> on MinGW
UTF-8
* paths cross the system call boundary as UTF-16 (*W APIs); console code
pages set to 65001 and restored on exit; files are read and written in
binary mode
* child output that is not valid UTF-8 is decoded from the console, OEM or
ANSI system code page
* read_file hides CR; edit_file, apply_patch and write_file keep CRLF line
endings and a UTF-8 BOM
OS layer and processes
* os_dir_* and cst_fnmatch replace the POSIX-only directory walks in
subagent, plugins, skills, undo and fs_tools; realpath / path_under and
symlink rejection work on Windows
* every child goes through CreateProcessW with its own environment block
inside a Job Object, so timeouts and Esc end the whole process tree
Sandbox (auto mode, "auto · lowil")
* run_shell runs with a restricted Low integrity token; the workspace gets
an inheritable Low label once, the sandbox TEMP is labeled Low, and the
credentials file gets a no-read-up label
* drive roots, the profile and system folders are never labeled
* network commands still ask, since Low IL does not block the network;
Access denied and MSYS2's 0xc0000142 offer a rerun outside the sandbox
* /sandbox lists labeled folders, /sandbox reset-labels restores them
TUI
* raster console fonts are switched to Consolas / NSimSun while running
* the home logo falls back to text when the console font lacks U+2580
* mouse drag copy goes to the Windows clipboard
Distribution
* scripts/install_windows.ps1 installs a Gitea release into
%LOCALAPPDATA%\Programs\cst-agent and adds it to the user PATH;
cst-agent-update.cmd reruns it; scripts/release_windows.sh uploads the
zip with the token taken from the environment
* scripts/run_windows.bat is gone; docs/README-windows.md is rewritten
Tests
* new test_lowil, test_win_utf8 and test_os_dir; tests made portable
(cst_test_util.h)
* scripts/win_test.sh and scripts/winvm/ run the suite on English and
Chinese Windows Server VMs as Administrator, a standard user and a
Chinese user name: 29/29 on all six
This commit is contained in:
+20
-21
@@ -6,7 +6,6 @@
|
||||
#include "cst_agent.h"
|
||||
#include "os_compat.h"
|
||||
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -45,7 +44,7 @@ int cst_agent_store_ensure(const char *workspace) {
|
||||
char gi[OS_PATH_MAX];
|
||||
if (os_path_join(gi, sizeof(gi), base, ".gitignore") == 0 &&
|
||||
OS_ACCESS(gi, OS_F_OK) != 0) {
|
||||
FILE *fp = fopen(gi, "w");
|
||||
FILE *fp = fopen(gi, "wb");
|
||||
if (fp) {
|
||||
fputs("*\n", fp);
|
||||
fclose(fp);
|
||||
@@ -97,7 +96,7 @@ int cst_agent_store_set_current(const char *workspace, const char *id) {
|
||||
return -1;
|
||||
if (os_path_join(path, sizeof(path), dir, "CURRENT") != 0)
|
||||
return -1;
|
||||
FILE *fp = fopen(path, "w");
|
||||
FILE *fp = fopen(path, "wb");
|
||||
if (!fp)
|
||||
return -1;
|
||||
fprintf(fp, "%s\n", id);
|
||||
@@ -113,7 +112,7 @@ int cst_agent_store_get_current(const char *workspace, char *id_out,
|
||||
return -1;
|
||||
if (os_path_join(path, sizeof(path), dir, "CURRENT") != 0)
|
||||
return -1;
|
||||
FILE *fp = fopen(path, "r");
|
||||
FILE *fp = fopen(path, "rb");
|
||||
if (!fp)
|
||||
return -1;
|
||||
if (!fgets(id_out, (int)id_sz, fp)) {
|
||||
@@ -159,7 +158,7 @@ int cst_agent_store_list(const char *workspace, char ids[][128], int max_ids) {
|
||||
char dir[OS_PATH_MAX];
|
||||
if (cst_agent_store_dir(workspace, dir, sizeof(dir)) != 0)
|
||||
return 0;
|
||||
DIR *d = opendir(dir);
|
||||
os_dir_t *d = os_dir_open(dir);
|
||||
if (!d)
|
||||
return 0;
|
||||
typedef struct {
|
||||
@@ -168,23 +167,23 @@ int cst_agent_store_list(const char *workspace, char ids[][128], int max_ids) {
|
||||
} ent_t;
|
||||
ent_t *ents = calloc((size_t)max_ids * 4, sizeof(ent_t));
|
||||
int n = 0, cap = max_ids * 4;
|
||||
struct dirent *de;
|
||||
while ((de = readdir(d)) != NULL) {
|
||||
size_t len = strlen(de->d_name);
|
||||
if (len < 7 || strcmp(de->d_name + len - 6, ".jsonl") != 0)
|
||||
const os_dirent_t *de;
|
||||
while ((de = os_dir_next(d)) != NULL) {
|
||||
size_t len = strlen(de->name);
|
||||
if (len < 7 || strcmp(de->name + len - 6, ".jsonl") != 0)
|
||||
continue;
|
||||
if (n >= cap)
|
||||
break;
|
||||
snprintf(ents[n].id, sizeof(ents[n].id), "%.*s", (int)(len - 6),
|
||||
de->d_name);
|
||||
de->name);
|
||||
char full[OS_PATH_MAX];
|
||||
if (os_path_join(full, sizeof(full), dir, de->d_name) != 0)
|
||||
if (os_path_join(full, sizeof(full), dir, de->name) != 0)
|
||||
continue;
|
||||
struct stat st;
|
||||
ents[n].mtime = (stat(full, &st) == 0) ? st.st_mtime : 0;
|
||||
n++;
|
||||
}
|
||||
closedir(d);
|
||||
os_dir_close(d);
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = i + 1; j < n; j++) {
|
||||
if (ents[j].mtime > ents[i].mtime) {
|
||||
@@ -218,7 +217,7 @@ int cst_agent_store_title_set(const char *workspace, const char *id,
|
||||
return -1;
|
||||
if (!title || !title[0])
|
||||
return remove(p) == 0 || errno == ENOENT ? 0 : -1;
|
||||
FILE *fp = fopen(p, "w");
|
||||
FILE *fp = fopen(p, "wb");
|
||||
if (!fp)
|
||||
return -1;
|
||||
for (const char *c = title; *c; c++)
|
||||
@@ -255,7 +254,7 @@ int cst_agent_store_info(const char *workspace, const char *id,
|
||||
info->mtime = (long long)st.st_mtime;
|
||||
char tp[OS_PATH_MAX];
|
||||
if (side_path(workspace, id, ".title", tp, sizeof(tp)) == 0) {
|
||||
FILE *tf = fopen(tp, "r");
|
||||
FILE *tf = fopen(tp, "rb");
|
||||
if (tf) {
|
||||
if (fgets(info->title, sizeof(info->title), tf)) {
|
||||
size_t n = strlen(info->title);
|
||||
@@ -265,7 +264,7 @@ int cst_agent_store_info(const char *workspace, const char *id,
|
||||
fclose(tf);
|
||||
}
|
||||
}
|
||||
FILE *fp = fopen(p, "r");
|
||||
FILE *fp = fopen(p, "rb");
|
||||
if (!fp)
|
||||
return 0;
|
||||
size_t cap = 1 << 16;
|
||||
@@ -311,16 +310,16 @@ int cst_agent_store_delete(const char *workspace, const char *id) {
|
||||
remove(p);
|
||||
/* sub-agent transcripts live in <id>/ */
|
||||
if (side_path(workspace, id, "", p, sizeof(p)) == 0) {
|
||||
DIR *d = opendir(p);
|
||||
os_dir_t *d = os_dir_open(p);
|
||||
if (d) {
|
||||
struct dirent *de;
|
||||
while ((de = readdir(d)) != NULL) {
|
||||
const os_dirent_t *de;
|
||||
while ((de = os_dir_next(d)) != NULL) {
|
||||
char f[OS_PATH_MAX];
|
||||
if (strncmp(de->d_name, "sub-", 4) == 0 &&
|
||||
os_path_join(f, sizeof(f), p, de->d_name) == 0)
|
||||
if (strncmp(de->name, "sub-", 4) == 0 &&
|
||||
os_path_join(f, sizeof(f), p, de->name) == 0)
|
||||
remove(f);
|
||||
}
|
||||
closedir(d);
|
||||
os_dir_close(d);
|
||||
rmdir(p);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user