Metadata-Version: 2.4
Name: moiryx-code
Version: 0.1.0a1
Summary: Interactive session host for applications built with Moiryx.
Author: Moiryx contributors
License-Expression: MIT
Project-URL: Repository, https://github.com/kamilsz713/moiryx-code
Project-URL: Issues, https://github.com/kamilsz713/moiryx-code/issues
Keywords: agents,llm,tui,sessions,moiryx
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Typing :: Typed
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: moiryx>=0.1.0a2
Requires-Dist: pydantic<3,>=2.12
Requires-Dist: textual<8,>=1
Provides-Extra: dev
Requires-Dist: build<2,>=1.3; extra == "dev"
Requires-Dist: mypy<2,>=1.11; extra == "dev"
Requires-Dist: pytest<10,>=8.3; extra == "dev"
Requires-Dist: pytest-asyncio<2,>=1; extra == "dev"
Requires-Dist: ruff<0.16,>=0.15; extra == "dev"
Dynamic: license-file

# Moiryx Code

Moiryx Code is a terminal interface for applications built with
[Moiryx](https://github.com/kamilsz713/moiryx). It provides the conversation
UI, persistent sessions, context limits, compaction, cancellation, and JSONL
output. Your handler decides which agents and tools to run.

This is an alpha release. Expect small API and configuration changes before
the first stable version.

## Install

Moiryx Code requires Python 3.11 or newer.

```console
python -m pip install --pre moiryx-code
```

## Try it without a model

The offline example uses a deterministic handler. It needs no API key, model,
or network connection after installation.

```console
git clone https://github.com/kamilsz713/moiryx-code.git
cd moiryx-code
python -m venv .venv
```

Activate `.venv` with `source .venv/bin/activate` on macOS or Linux, or with
`.venv\Scripts\Activate.ps1` in PowerShell. Then run:

```console
python -m pip install -e .
python -m moiryx_code --cwd examples/offline_project
```

On Windows, `run-offline.cmd` can replace the last command.

## Add it to a Moiryx project

Moiryx Code loads a handler from the `extensions.code` section of
`moiryx.yaml`:

```yaml
providers:
  local:
    type: openai_compatible
    base_url: http://127.0.0.1:8080/v1

models:
  chat:
    provider: local
    model: local-model

extensions:
  code:
    handler: app:handler
    state_dir: .moiryx/code
    session:
      context_budget_tokens: 32768
      auto_compact: false
```

The handler receives the current request and active conversation context. It
returns an async stream of runtime events and must finish with `Final`.

```python
from moiryx import Agent
from moiryx.messages import AssistantMessage, UserMessage
from moiryx_code import Context, Final, Request, Status


class Handler:
    def __init__(self) -> None:
        self.agent = Agent("agents/chat.md")

    async def __call__(self, request: Request, context: Context):
        history = [
            UserMessage(message.content)
            if message.role == "user"
            else AssistantMessage(message.content)
            for message in context.messages
        ]
        if context.summary:
            summary = UserMessage(f"Conversation summary:\n{context.summary}")
            history.insert(0, summary)

        yield Status(message="Thinking")
        answer = await self.agent(request.prompt, history=history)
        yield Final(content=str(answer))

    async def aclose(self) -> None:
        await self.agent.aclose()


handler = Handler()
```

Agent and tool lifecycle events emitted by Moiryx appear in the same event
stream. `Final` is reserved for the handler response.

## Sessions and context

Sessions are stored in SQLite under the configured `state_dir`. Raw messages
are retained when context is cleared or compacted.

Automatic compaction requires a separate Moiryx agent:

```yaml
extensions:
  code:
    handler: app:handler
    session:
      auto_compact: true
      context_budget_tokens: 32768
      compact_at: 0.72
      keep_recent_tokens: 12000
      compact_agent: agents/compact.md
```

Compaction runs before the next turn after the active context reaches the
configured threshold. The recent tail remains verbatim; older messages are
replaced in the active context by the summary.

## Commands

| Command | Action |
| --- | --- |
| `/new` | Start a new session |
| `/resume ID` | Open a stored session |
| `/sessions` | List stored sessions |
| `/compact` | Compact the current context |
| `/clear` | Clear active context without deleting history |
| `/context` | Show estimated context use |
| `/help` | Show the command list |
| `/quit` | Exit |

Typing `/` opens the command picker. Use the arrow keys to select an entry and
Tab to complete it. `Ctrl+C` cancels a running turn and exits when idle.

For scripts and CI, run one prompt without the TUI:

```console
moiryx-code --cwd path/to/project run "Inspect this repository" --jsonl
```

## Development

```console
python -m pip install -e ".[dev]"
python scripts/check.py
python -m build
python scripts/audit_artifacts.py dist
```

The `shell` tool provided by Moiryx is not a security sandbox. Only enable it
for agents and workspaces you trust.

## License

MIT
