feat: 优化运行时判定
This commit is contained in:
26
README.md
26
README.md
@@ -85,8 +85,14 @@ Also delete config, logs, and the virtualenv:
|
||||
| `port` | Default `8765`. |
|
||||
| `device` | `auto`, `mps`, `cuda`, or `cpu`. `auto` falls through if warmup fails. |
|
||||
| `log_prompts` | Write the raw prompt into `data/routes.jsonl`. |
|
||||
| `request_timeout` | Seconds the hook waits for the service. Default `2.5`. |
|
||||
| `request_timeout` | Seconds the prompt hook waits for the service. Default `2.5`. |
|
||||
| `event_timeout` | Seconds a tool hook waits. Default `1.0`. |
|
||||
| `max_prompt_chars` | Max characters sent to the model. Longer prompts keep the head and tail. |
|
||||
| `trajectory` | Inject a short hint after tool calls, and before an edit of unread code. |
|
||||
| `gate` | Tighten risky Bash and edit calls. Never returns allow. |
|
||||
| `stop_check` | Ask the agent to verify after edits before it stops. |
|
||||
| `skills` | Suggest at most one installed skill on each user prompt. |
|
||||
| `skill_inject` | `suggest` names the skill. `content` attaches `SKILL.md` once per session. |
|
||||
|
||||
Restart after config or server changes: `laya-router restart`.
|
||||
|
||||
@@ -103,6 +109,20 @@ Every call is appended to `~/.laya-router/data/routes.jsonl` (timestamp, client,
|
||||
|
||||
If the service is down, the hook prints `{}` and exits 0. Codex and Claude Code continue. The error is appended to `~/.laya-router/logs/hook.log`.
|
||||
|
||||
## During a turn
|
||||
|
||||
The same hook command also listens for `PreToolUse`, `PostToolUse`, and `Stop`. The resident service keeps the session trace in memory.
|
||||
|
||||
- `PreToolUse` on Bash or an edit: a high risk is denied; a medium risk asks on Claude Code and warns on Codex, because Codex rejects `permissionDecision: ask`. An edit of a file that was not read gets a short hint.
|
||||
- `PostToolUse`: every Bash or edit checkpoint gets a short hint. The same hint is not repeated. Two failures in a row, or a high `is_stuck`, tells the agent to stop and replan. `Read`, `Grep`, and `Glob` are recorded and stay quiet.
|
||||
- `Stop`: if code changed and nothing verified it, the hook blocks once so the agent keeps going. `stop_hook_active` is always allowed through.
|
||||
|
||||
On `UserPromptSubmit`, a second pair of questions can name one installed skill. The roster is every `SKILL.md` under `~/.claude/skills`, `~/.codex/skills`, `~/.agents/skills`, the project skill directories, and Claude plugin install paths. A skill with `disable-model-invocation: true` is skipped. The first pass ranks the roster and gates on whether a skill is warranted. The second pass re-reads the top three. Either threshold below 0.30 suggests nothing.
|
||||
|
||||
`laya-mcp` exposes `laya_judge` over stdio. Allow `mcp__laya` in Claude Code if you want the agent to call it. Install registers it with `claude mcp add` and `codex mcp add` when those CLIs are on `PATH`.
|
||||
|
||||
The first Codex session must trust the new hook entries. Run `/hooks` again after upgrading.
|
||||
|
||||
## Develop
|
||||
|
||||
```bash
|
||||
@@ -115,7 +135,7 @@ Unit tests do not load the model. After the service is up, `laya-router route` r
|
||||
| --- | --- | --- |
|
||||
| `src/laya_router/questions.py` | Question text. Bump `QUESTIONS_VERSION` when the wording changes. | `laya-router restart` |
|
||||
| `src/laya_router/render.py` | Text injected into the agent | `laya-router restart`, then the next prompt |
|
||||
| `src/laya_router/hook.py` | Timeout, slash-command skip, fail-open | `laya-router restart`, then the next prompt |
|
||||
| `src/laya_router/hook.py` | Prompt and tool events, timeout, fail-open | `laya-router restart`, then the next prompt |
|
||||
| `src/laya_router/server.py` | Model load, `/route`, dashboard | `laya-router restart` |
|
||||
| `src/laya_router/dashboard.html` | Browser UI | `laya-router restart` |
|
||||
|
||||
@@ -129,7 +149,7 @@ The service has no authentication. It listens on `127.0.0.1` only. `/route` acce
|
||||
|
||||
`routes.jsonl` stores the raw prompt by default, including anything you paste into Codex or Claude Code. Set `log_prompts = false` to keep only a SHA-256. The runtime directory is `~/.laya-router/`, outside this repo. Do not commit it.
|
||||
|
||||
The installer rewrites `~/.codex/hooks.json` and merges a `UserPromptSubmit` entry into `~/.claude/settings.json`. That Claude file often holds API credentials. The tool preserves existing keys, writes a timestamped `*.bak-*` copy before changing a file, and removes only its own hook on uninstall. Read the diff before you publish a dotfile.
|
||||
The installer rewrites `~/.codex/hooks.json` and merges `UserPromptSubmit`, `PreToolUse`, `PostToolUse`, and `Stop` entries into `~/.claude/settings.json`. That Claude file often holds API credentials. The tool preserves existing keys, writes a timestamped `*.bak-*` copy before changing a file, and removes only its own hook on uninstall. Read the diff before you publish a dotfile.
|
||||
|
||||
A web page on another origin cannot read these responses: the server does not send `Access-Control-Allow-Origin`. Keep the default bind address anyway.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user