Skip to content

Conversation

@korotn3v
Copy link

@korotn3v korotn3v commented Mar 25, 2025

Knowledge Extractor component

This component add to ishell functionality to capture user actions, save them into session history, ability to create structured markdown protocols from this history and group them by tags. And ability to reuse this knowledges in the future by adding them to AI's context at the problem solving.

Session capturing

A singleton class, SessionTracker, has been created to handle logging into an SQLite database. It is responsible for recording:

  • A non-blocking PTY hooks both the user’s shell actions and the AI assistant’s interactions in real time.
  • Every command, response, timestamp, exit code, and assistant interactions is recorded as an atomic interaction block, stripped of ANSI escape sequences for clean downstream processing.
  • The tracker starts automatically when iShell launches and remains invisible to the user.

Persistant storage

  • Captured actions and interactions are written to a SQLite database by default
  • Core tables sessions, commands, interactions, bookmarks and knowledge base
  • All writes are wrapped in class SessionTracker

Usage of knowledge base

  • markdown comand to operate with knowladges in system mode
  • supported flags to add new knowladge, add them to groups and add to assistant context
  • it provide new functionality about creating, saving, tagging, showing and adding to context protocols of knowledge

Tried to implement different situations:
- user query to agent
- agent response
- commands in system_mode
What done:
- agent chat
- system commands logs
- bash commands logs(but it doesnt work)
@korotn3v korotn3v requested a review from krinkin March 25, 2025 01:39
Copy link
Contributor

@krinkin krinkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider to refactor logging (add logger for the whole project)


class SessionTracker {
public:
enum class EventType {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments?


void openLogFile();

sqlite3 *db;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to use some prefix for members

// interactions -- table for user chat with agent
// commands -- bash commands
// system_commands -- commands in system mode
const char *schemaSql = R"SQL(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract sql code from cpp

resolved BOOLEAN DEFAULT 0,
FOREIGN KEY(session_id) REFERENCES sessions(session_id)
);
CREATE TABLE IF NOT EXISTS commands (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think on joining this two tables

int handle_input();

static void handle_pty_input(int fd, char ch);
void handle_pty_input(int fd, char ch);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

const std::pair<std::string, std::string> bookmark = bookmark_manager->get_bookmark(alias);
bookmark_manager->agency_manager->session_history.push_back(bookmark);
std::cout << bookmark.second << "\n";
SessionTracker::get().finalizeCommand(0, "Alias executed: " + alias);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider to define names and values for different error codes


void TerminalMultiplexer::handle_pty_input(const int fd, const char ch) {
if (ch == '\n') {
SessionTracker::get().logEvent(SessionTracker::EventType::ShellCommand, current_command);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be a separated method like update_command

@korotn3v korotn3v changed the base branch from main to add-history-support April 1, 2025 01:19
@korotn3v korotn3v requested a review from krinkin April 9, 2025 16:07
… full support of logging command and its output
void resize();
void run_terminal();
int handle_screen_output(Screen &screen, int fd) const;
int handle_screen_output(Screen &screen, int fd);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done it because i want to call non-const method to collect command output and change variable last_command_finished

@korotn3v korotn3v changed the title Session history knowledge extractor May 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants