Skip to content

Feature Request: Persist shell session state across SREGym> CLI commands #898

Closed

Description

@W-OK-E

This request partially stems from the testing I have been doing for #883 :) Keeping track of the namespaces, registries and IPs involved was slightly annoying and I found that the usual export VAR=VALUE method does not work in the SREGym> cli.

Currently, every SREGym> command is executed in a fresh shell process with no retained session state between commands which means workflows like the following do not behave as users typically expect from an interactive shell:

SREGym> export NS=astronomy-shop
SREGym> kubectl get pods -n $NS   # NS is lost

I am proposing a minor change for shell session state to persist across CLI commands in the dev/debug cli that would:

  • Preserve:
    • exported environment variables
    • shell function definitions
    • working directory ($PWD)
  • Restore this state before executing the next command

This would make a sequence of SREGym> commands behave much closer to a normal interactive shell session while still keeping each command isolated in its own subprocess.


Implementation Approach

Instead of maintaining a single long-lived piped shell process, the implementation snapshots shell state after each command and restores it before the next one.

After every command:

  • exported env vars are captured via:

    declare -px
  • shell functions via:

    declare -pf
  • current working directory via:

    $PWD

These are written to a per-PID temporary state file. Before the next command executes, the shell sources this state file to restore continuity.


Scope

This change would affect only the developer/debug CLI path (cli.py).

There would be no behavior changes for:

  • main.py
  • agent execution flows
  • non-interactive runtime behavior

If I have missed something here, or if there are other ways that already do what I am requesting for, or if this does not add much value to the current debugging state, please let me know. If the maintainers do approve, I you approve, I can go ahead and open a PR.

Activity

  1. Saadmrp1038 commented on Jun 20, 2026

    @Saadmrp1038
    Collaborator

    @W-OK-E It's interesting that you use it like this. I never run any commands in the cli session and just open another terminal window by the side. But yeah definitely worth adding this feature. Feel free to give a PR.

  2. tianyin commented on Jun 21, 2026

    @tianyin
    Contributor

    This could be a useful feature!

  3. W-OK-E commented on Jun 22, 2026

    @W-OK-E
    ContributorAuthor

    PR raised in #900

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions