Build a local terminal application for one operator that:
-
installs and runs Codex
-
connects a single Telegram bot to a single authorized Telegram chat
-
mirrors Codex terminal state to Telegram
-
records a replayable terminal log
-
exposes a debug mirror locally in the terminal/CLI
-
protects against:
- duplicate app instances
- stale lockfiles
- half-finished setup runs
- orphaned Codex child processes
Exactly one user is supported.
Store:
- one Telegram user ID
- one Telegram chat ID
- one bot token
- one active Codex session
- one local operator approval authority
No multi-user roles!
Tele-Cli should use a deterministic workspace layout for Codex work.
Rules:
- the direct 1:1 chat works in
workspace/ - each Telegram topic works in its own folder under
workspace/topics/ - each topic folder is its own Git repository and Git submodule
- durable workspace memory lives in committed files such as:
workspace/long_memory.mdworkspace/AGENT.mdworkspace/topics/<topic>/AGENT.md
- temporary Tele-Cli memory stays under
memory/and does not need to be committed
/new creates a fresh session, not a fresh workspace.
- Linux
- macOS
- Windows
The terminal setup wizard must do this in order:
- Check whether another app instance is already running
- Check whether a previous setup is already in progress or was interrupted
- Ask the operator how to resolve conflicts if found
- Detect whether
codexis installed - Detect whether
npmis installed - If
npmis missing, install it - If Codex is missing, install Codex
- Ask for Telegram bot token
- Validate Telegram connectivity
- Save config
- Enter service mode
The app must check whether npm is available in PATH.
The app must try to install it in an OS-appropriate way.
Support common package managers with detection:
aptdnfyumpacmanzypper
Use:
- Homebrew if available
- otherwise guide or automate installation of Homebrew only if explicitly enabled in config/design
V1 should use an installer strategy abstraction:
detect_package_manager()install_npm()install_codex()
This is cleaner than hardcoding shell commands all over the code.
After npm exists, install Codex.
The app must protect against multiple copies of:
- the main service
- the setup wizard
- the Codex child runtime for this app instance
Use a lock + PID metadata file in the app state directory.
Example stored metadata:
- PID
- hostname
- username
- process start time if available
- mode:
setuporservice - timestamp
- app version
- child Codex PID if active
When the app starts, it must check:
- Is there a lockfile?
- Does the PID still exist?
- Does the process appear to be this same app?
- Is it in setup mode or service mode?
- Is there an active Codex child attached to it?
The app must not blindly continue.
It must prompt the operator:
kill— terminate the conflicting app/Codex process if safely identifiableignore— continue without taking ownership- optionally
exit— safest choice, recommended to include
You asked for kill/ignore; I strongly recommend also supporting exit.
The setup wizard must not run twice at the same time.
Create a dedicated setup lock/state file.
It must contain:
-
status:
started,completed,failed,abandoned -
PID
-
timestamp
-
partial progress markers:
- npm installed?
- codex installed?
- telegram token saved?
- telegram validated?
If an existing setup state is found:
Prompt:
killignoreexit
Prompt:
resumerestartignoreexit
Even though you requested kill/ignore, for interrupted setup resume and restart are much better UX, so they should be added.
Whenever duplicate state or stale runtime state is detected, the app should not guess silently.
It should:
- inspect
- explain what it found
- ask the operator what to do
- execute the selected recovery action
- log that choice
Show:
- stored PID
- timestamp
- conclusion that process is no longer alive
Offer:
healorresumeby clearing stale lockignoreexit
Show:
- PID
- mode
- age
- whether Codex child exists
Offer:
killignoreexit
Show:
- partial setup progress
- what appears complete and incomplete
Offer:
resumerestartignoreexit
The app should detect Codex processes likely started by this app but whose parent app is gone.
Offer:
killadoptif implementation supports taking ownership safelyignore
For V1, kill and ignore are enough. adopt is optional.
Never kill arbitrary unrelated processes just because they contain the word codex.
The app must only auto-target processes that can be strongly linked to this app by one or more of:
- stored PID metadata
- same working directory marker
- same session metadata
- same wrapper command signature
- same state directory ownership
If ownership is uncertain:
- do not auto-kill
- warn the operator
- default to ignore/exit
Use these files in the app state directory:
app.lock— single service instance locksetup.lock— setup instance lockruntime.json— current runtime metadataauth.json— single authorized Telegram chat/userconfig.jsonor equivalentrecovery.log— recovery decisions and events
Only one Telegram chat can ever become the controlling chat in V1.
Any incoming Telegram message gets a 5-digit code.
If a different chat or user sends a message:
- deny control
- reply that this bot is already paired to another chat
- do not generate a new pairing code unless the operator explicitly resets pairing locally
A local terminal command should exist:
reset-auth
This clears the saved Telegram user/chat authorization and allows pairing again.
The service must detect these conflicts at runtime too:
- Telegram polling loop started twice
- Codex child started twice
- recorder started twice
- debug server started twice
Each subsystem should have an internal state machine and reject duplicate startup.
Example:
- if Codex session state is not
STOPPED, do not start a second one - if Telegram poller is already active, refuse second poller start
- exactly one Codex session
- exactly one Telegram controller chat
- exactly one debug mirror
- exactly one recorder
No parallel sessions.
V1 is complete only if all of the following are true:
- App runs on Linux and macOS.
- App detects missing npm.
- App can install npm using OS/package-manager-specific logic.
- App detects missing Codex and installs it.
- App prevents duplicate setup runs.
- App prevents duplicate service runs.
- App detects stale locks and interrupted setup state.
- App presents self-heal choices when conflicts are found.
- Self-heal includes at least
killandignore. - App supports one Telegram user/chat only.
- Once paired, other Telegram users cannot take control.
- App can recover from an interrupted prior setup without corrupting config.
- App never launches a second Codex child while one is already owned by the service.
- App keeps recovery/audit logs for kill/ignore/resume decisions.
- V1 is single-user, not multi-user.
- Target only Linux and macOS.
- Implement package-manager-aware npm installation.
- Protect both setup mode and service mode with separate locks.
- Add stale lock detection and interactive recovery.
- Prefer asking the operator over silently killing processes.
- Never kill an uncertain process match.
- Keep all recovery flows explicit and logged.
Another app instance appears to be running.
Show PID, age, mode.
Choices:
kill— terminate the existing instanceignore— continue without touching itexit
A previous setup did not finish.
Show completed steps.
Choices:
resumerestartignoreexit
A Codex process from a previous run may still be active.
Choices:
killignoreexit