feat(scheduler-sim-repl-verbosity): task 6.2 - implement dynamic REPL prompt

Adds repl_build_prompt(), building the readline() prompt fresh each
loop iteration: the plain "(sim) " before any session begins, else
"(sim session=<N> t=<ISO8601-ts>) " using the bare session count (not
+1, matching info session's convention) and the existing
repl_format_ts_human(). Both of task 6.1's tests pass.

repl.c grew 808->852 lines (6.5% over the 800-line cap). Review
empirically tried extracting repl_build_prompt() into a new
repl_prompt.c: it works, but requires updating 19 sibling white-box
test files' #include lists, and even then repl.c only drops to 814
lines - still over cap. Given the function is a small 15-line
formatter and the split doesn't even achieve compliance, accepted in
place rather than forcing disproportionate churn.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YAWMhfRJFnmmnG8h97yUDd
This commit is contained in:
Rongsong Shen 2026-09-02 16:14:52 +00:00
parent 99fa45c41a
commit da6ba96eb4
No known key found for this signature in database
GPG key ID: 5BCDAAE0123E9FE2
3 changed files with 48 additions and 2 deletions

View file

@ -422,6 +422,42 @@ static bool repl_dispatch(xce_sched_sim_driver_t* sim, const char* line)
return false;
}
/*
* repl_build_prompt (scheduler-sim-repl-verbosity spec, task 6.2, design.md's
* "REPL Prompt Context" component, Req 5.5) - builds this iteration's
* readline() prompt into `buf` (bufsz-bounded): the plain XCE_REPL_PROMPT
* ("(sim) ") if no session has completed yet (rs->session_count == 0, the
* same zero-initialized value repl_state_ensure()'s calloc already
* guarantees), else "(sim session=<N> t=<ISO8601-ts>) " using the BARE
* rs->session_count -- deliberately NOT +1, unlike repl_print_event_summary()
* (repl_break.c)'s unrelated mid-stream convention, which labels events
* echoed before the session containing them has finished/incremented the
* count. This prompt is only ever shown AFTER a step/continue has already
* returned control (i.e. after xce_repl_on_begin_round() for the
* just-finished session has run), so the bare count is the session that
* just completed -- the same number `info session` would report right now.
* The timestamp reuses xce_core_now(&sim->core)/repl_format_ts_human()
* verbatim (no new time source, no raw-epoch-ns component). A read-only
* formatter -- never blocks, never mutates sim/sim->repl_state -- so it is
* safe to call fresh on every loop iteration (never cached).
*/
static void repl_build_prompt(xce_sched_sim_driver_t* sim, char* buf,
size_t bufsz)
{
xce_sched_repl_state_t* rs = sim->repl_state;
char ts_human[32];
if ((rs == NULL) || (rs->session_count == 0)) {
snprintf(buf, bufsz, "%s", XCE_REPL_PROMPT);
return;
}
repl_format_ts_human(xce_core_now(&(sim->core)), ts_human,
sizeof(ts_human));
snprintf(buf, bufsz, "(sim session=%llu t=%s) ",
(unsigned long long)rs->session_count, ts_human);
}
/*
* repl_command_loop - the blocking prompt loop itself: readline() the
* `(sim) ` prompt, add_history() on non-blank input (same convention
@ -433,11 +469,19 @@ static bool repl_dispatch(xce_sched_sim_driver_t* sim, const char* line)
* that case either. Non-static (repl_internal.h) -- repl_break.c's
* breakpoint-hit hooks re-enter it directly, the same way
* xce_repl_post_session_check() below already does for a `step N` pause.
* The prompt itself is rebuilt fresh (repl_build_prompt()) immediately
* before every readline() call, never cached across iterations, since the
* session count/timestamp it shows can change between prompts (task 6.2,
* Req 5.5).
*/
void repl_command_loop(xce_sched_sim_driver_t* sim)
{
for (;;) {
char* line = readline(XCE_REPL_PROMPT);
char prompt[64];
char* line;
repl_build_prompt(sim, prompt, sizeof(prompt));
line = readline(prompt);
if (line == NULL) {
repl_cmd_quit(sim); /* never returns */