Skip to content

Commit 69e30f7

Browse files
authored
feat: add session-aware history commands (ghistory, lhistory) (#111)
Add two new CLI commands for command history with session metadata: - ghistory: global history across all sessions - ghistory N: show last N entries - ghistory -s <session_id>: filter by session - lhistory: local history for current session only - lhistory N: show last N entries Implementation details: - Add session identity fields (session_id, session_tty, session_start) to DATA struct in CLIcore.h and CLIcore_standalone.h - Create ~/.milk_history_log as append-only TSV file recording every command with: timestamp, session_id, terminal, command - Session ID format: <processname>-<PID> (e.g., milk-12345) - Structured log runs alongside readline history (no opt-in needed) - Existing ~/.milk_history (readline) remains unchanged
1 parent 3b0be87 commit 69e30f7

5 files changed

Lines changed: 424 additions & 0 deletions

File tree

src/cli/CLIcore/CLIcore.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,9 @@ errno_t runCLI(int argc, char *argv[], char *promptstring)
521521
// Load persistent command history
522522
cli_history_load();
523523

524+
// Initialize structured history log
525+
cli_history_log_init();
526+
524527
// Load persistent bookmarks
525528
cli_bookmark_load();
526529

@@ -1348,6 +1351,24 @@ void runCLI_cmd_init()
13481351
"fhist",
13491352
"cli_fhist()");
13501353

1354+
RegisterCLIcommand(
1355+
"ghistory",
1356+
__FILE__,
1357+
cli_ghistory,
1358+
"global history (all sessions)",
1359+
"[N] [-s <session_id>]",
1360+
"ghistory 50",
1361+
"cli_ghistory()");
1362+
1363+
RegisterCLIcommand(
1364+
"lhistory",
1365+
__FILE__,
1366+
cli_lhistory,
1367+
"local history (current session)",
1368+
"[N]",
1369+
"lhistory",
1370+
"cli_lhistory()");
1371+
13511372
RegisterCLIcommand(
13521373
"fparam",
13531374
__FILE__,

src/cli/CLIcore/CLIcore.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,13 @@ typedef struct
380380
int CMDexecuted;
381381
errno_t CMDerrstatus;
382382

383+
// SESSION IDENTITY
384+
// =================================================
385+
386+
char session_id[64];
387+
char session_tty[64];
388+
struct timespec session_start;
389+
383390
// MODULES
384391
// =================================================
385392

0 commit comments

Comments
 (0)