samagotchi 0.189.0 → 0.190.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +35 -1
- data/docs/architecture.md +4 -1
- data/docs/cli.md +17 -6
- data/docs/configuration.md +1 -0
- data/docs/guardrails.md +20 -8
- data/docs/internals/attached-context.md +4 -1
- data/docs/internals/engine.md +18 -2
- data/docs/pages.md +3 -2
- data/docs/scheduling.md +99 -5
- data/docs/sub-agent.md +1 -1
- data/lib/samagotchi/bundles/guardrails/guardrails/rules.yml +15 -0
- data/lib/samagotchi/bundles/guardrails/manifest.yml +2 -2
- data/lib/samagotchi/bundles/schedules/manifest.yml +4 -4
- data/lib/samagotchi/bundles/schedules/scripts/schedules.rb +13 -3
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/config.rb +2 -0
- data/lib/samagotchi/context_fetch.rb +9 -3
- data/lib/samagotchi/engine/models.rb +6 -4
- data/lib/samagotchi/engine/turn_end.rb +20 -2
- data/lib/samagotchi/engine.rb +5 -1
- data/lib/samagotchi/failure_line.rb +43 -0
- data/lib/samagotchi/guardrail_wiring.rb +3 -1
- data/lib/samagotchi/guardrails/chi_dirs.rb +20 -5
- data/lib/samagotchi/guardrails/parent_approvals.rb +1 -1
- data/lib/samagotchi/guardrails/protected_paths.rb +8 -4
- data/lib/samagotchi/guardrails/shell_paths.rb +16 -2
- data/lib/samagotchi/guardrails/targets.rb +1 -1
- data/lib/samagotchi/guardrails/verdict.rb +5 -3
- data/lib/samagotchi/image_store.rb +4 -0
- data/lib/samagotchi/last_turn.rb +2 -1
- data/lib/samagotchi/llm/utf8_scrub.rb +26 -0
- data/lib/samagotchi/llm_context_view.rb +6 -0
- data/lib/samagotchi/model_profile.rb +4 -1
- data/lib/samagotchi/pages/runtime.rb +4 -3
- data/lib/samagotchi/reply_wait.rb +1 -1
- data/lib/samagotchi/schedule_command.rb +99 -5
- data/lib/samagotchi/schedule_display.rb +21 -5
- data/lib/samagotchi/schedules/condition_part.rb +312 -0
- data/lib/samagotchi/schedules/edit_part.rb +27 -3
- data/lib/samagotchi/schedules/notices_part.rb +8 -2
- data/lib/samagotchi/schedules/protection_part.rb +10 -0
- data/lib/samagotchi/schedules/prune_part.rb +79 -0
- data/lib/samagotchi/schedules.rb +57 -82
- data/lib/samagotchi/system_one/self_protect.rb +4 -2
- data/lib/samagotchi/tools/cancel_schedule.rb +27 -2
- data/lib/samagotchi/tools/execute.rb +5 -1
- data/lib/samagotchi/tools/list_schedules.rb +1 -0
- data/lib/samagotchi/tools/task_runtime.rb +6 -0
- data/lib/samagotchi/turn_endings.rb +14 -2
- data/lib/samagotchi/turn_flow.rb +2 -1
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/public/stream_handlers.js +8 -0
- data/lib/samagotchi/web/session_hub.rb +16 -5
- data/lib/samagotchi/worker.rb +6 -4
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f4402302a9a90677b9393d78fae32bb1c8213213a268ce1a3f12c955ef90dc6c
|
|
4
|
+
data.tar.gz: 2b8c88cea8b95af6322c909bab6f2f51e9ed7e271074f30982f0fa811583938a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 85843a002d4fca2b1d2bc05b62e90c21636b948b26e519359b735033f0d0038fb44bb10a67522ffe10391bfde8eacb4a9a73ceee0283ef83b862c5700135f072
|
|
7
|
+
data.tar.gz: aac37870c1e2de7a62c8f83a0c8ee81d1c2fd2f710fff9a0f3241c6ae1da8420a3d08d7620d963c3491126f73356c6ef7133d8bc19e79533e2ef6e0335107ffe
|
data/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,39 @@ and commands may change between minor versions. How releases are made:
|
|
|
8
8
|
|
|
9
9
|
## [Unreleased]
|
|
10
10
|
|
|
11
|
+
## [0.190.0] - 2026-11-26
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- `chi schedule add|edit --if CMD` (and `edit --no-if`): the tick runs CMD in the session's folder before a firing;
|
|
16
|
+
exit 0 fires as before, any other exit is a quiet "not needed" that uses no budget; a condition that can't run or
|
|
17
|
+
times out counts as a failure (`schedule.condition_timeout_seconds`, default 30). Only from your own terminal:
|
|
18
|
+
chi's tools can't set it, and every chi that ticks must be this one or newer (an older one leaves such a schedule
|
|
19
|
+
alone) ([docs/scheduling.md](docs/scheduling.md#conditions---if)).
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
|
|
23
|
+
- `schedules.json` is a protected path for chi's file tools, and a shell command naming it asks (shell-touches-chi).
|
|
24
|
+
With the guardrails bundle (0.9.4), `chi schedule add|edit … --if` from chi's shell asks you every time
|
|
25
|
+
(`chi-schedule-if`: no parent agent or System 1 may allow it). Run `chi update`.
|
|
26
|
+
- The schedules bundle (0.1.1): the Schedules page has an If column (a schedule's `--if` command).
|
|
27
|
+
|
|
28
|
+
### Fixed
|
|
29
|
+
|
|
30
|
+
- A finished background task whose output had non-ASCII text (accents, dashes, ✓) no longer fails its wake turn;
|
|
31
|
+
`task_wait` and a handed-over `execute` show such output as is.
|
|
32
|
+
- A turn that fails because of chi itself (not the model's host) says so on the web, in the terminal and on
|
|
33
|
+
`-p --non-interactive`'s stderr: "turn failed: chi error: <message> (<Class>); details in samagotchi.log", where
|
|
34
|
+
the log has where it failed. Its `error_kind` (`chi send --wait --format json`, a schedule's last result) is
|
|
35
|
+
`chi_error`. A turn that fails before it begins (its session can't be saved) now shows that line too, instead of
|
|
36
|
+
nothing.
|
|
37
|
+
- Raw bytes in a conversation (a tool's output that isn't valid UTF-8) no longer fail the next turn on any model
|
|
38
|
+
host; such text goes to the model with the bad bytes replaced. `execute` returns a command's output as valid UTF-8.
|
|
39
|
+
- `chi schedule list` says how many entries of `schedules.json` can't be read and how to remove one, instead of
|
|
40
|
+
hiding them; chi's `cancel_schedule` tool can remove such an entry by its exact id.
|
|
41
|
+
|
|
42
|
+
Update with `chi update` (guardrails 0.9.4, schedules 0.1.1).
|
|
43
|
+
|
|
11
44
|
## [0.189.0] - 2026-11-25
|
|
12
45
|
|
|
13
46
|
### Added
|
|
@@ -6918,7 +6951,8 @@ and long-lived sessions.
|
|
|
6918
6951
|
- A macOS desktop helper (`chi desktop install`): a "Send to chi" Service and a
|
|
6919
6952
|
hotkey panel that send selected text or the clipboard to your sessions.
|
|
6920
6953
|
|
|
6921
|
-
[Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.
|
|
6954
|
+
[Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.190.0...HEAD
|
|
6955
|
+
[0.190.0]: https://github.com/dm1try/samagotchi/compare/v0.189.0...v0.190.0
|
|
6922
6956
|
[0.189.0]: https://github.com/dm1try/samagotchi/compare/v0.188.0...v0.189.0
|
|
6923
6957
|
[0.188.0]: https://github.com/dm1try/samagotchi/compare/v0.187.0...v0.188.0
|
|
6924
6958
|
[0.187.0]: https://github.com/dm1try/samagotchi/compare/v0.186.0...v0.187.0
|
data/docs/architecture.md
CHANGED
|
@@ -649,7 +649,10 @@ credit held by in-flight requests, retried after 20 s), `OutOfCredits` (any othe
|
|
|
649
649
|
402), `ServerError`, `AuthError`, `BadRequest` (`context_overflow?`) or `ProtocolError`. Engine keeps the turn's
|
|
650
650
|
conversation (the prompt plus completed tool iterations) and emits
|
|
651
651
|
`:turn_failed` with `error_kind:`, `retryable:`, `host:` and a one-line
|
|
652
|
-
`summary:`, which the attached TUI, a one-shot's stderr and the web show.
|
|
652
|
+
`summary:`, which the attached TUI, a one-shot's stderr and the web show. Any other error
|
|
653
|
+
is chi's own (`TurnEndings.chi_error?`): `error_kind: chi_error` and the summary "chi error:
|
|
654
|
+
<message> (<Class>); details in samagotchi.log", unless it tells the user what to change
|
|
655
|
+
(`UserError`: an image the turn can't use, no model), whose message is the line.
|
|
653
656
|
|
|
654
657
|
**Usage and models.** A turn's token counts are `SessionMetrics`', read from the
|
|
655
658
|
stream events (server counts, else a chars/4 estimate). Model lists are `LLM::ModelInfo`
|
data/docs/cli.md
CHANGED
|
@@ -466,6 +466,8 @@ chi schedule enable 4b7e9a
|
|
|
466
466
|
chi schedule cancel 4b7e9a # delete it (by id, a unique prefix, or its title)
|
|
467
467
|
chi schedule edit 4b7e9a --weekday 2 --time 08:30 # change it in place: only the flags given
|
|
468
468
|
chi schedule edit "Monday audit" -m "Audit the open PRs and the queue" --max-skips 24
|
|
469
|
+
chi schedule add --session 3f9a1c2e --every 5m -m "Check in" --if "$HOME/.local/bin/anything-to-do"
|
|
470
|
+
chi schedule edit 4b7e9a --no-if # fire at every occurrence again
|
|
469
471
|
```
|
|
470
472
|
|
|
471
473
|
Every `list` row names its schedule: the `--title` it was given, or, when it has
|
|
@@ -475,7 +477,10 @@ widest name among the rows printed, so the columns after it line up. `--format j
|
|
|
475
477
|
carries `title` as it is stored (`null` with no title) and the whole `prompt`, and the
|
|
476
478
|
quoted stand-in only as `name`; with it `state` (`on`, `firing`, `off`) and `off_reason`
|
|
477
479
|
([scheduling.md](scheduling.md#skip-not-failure)). The `list_schedules` tool names a
|
|
478
|
-
schedule the same way.
|
|
480
|
+
schedule the same way. An entry of `schedules.json` that doesn't read isn't a row: one line
|
|
481
|
+
after the rows counts them and names the first five ids, "2 schedules can't be read (e1f2a3b4,
|
|
482
|
+
…): chi schedule cancel ID removes one" (one with no id: "fix or remove it in schedules.json");
|
|
483
|
+
under `--format json` that line goes to stderr and stdout stays the JSON list.
|
|
479
484
|
|
|
480
485
|
`add` needs a target (`--session ID`, or `--continues ID` for the same session)
|
|
481
486
|
and exactly one recurrence kind — `--every 45m|2h|1d`, `--weekday 1..7` with
|
|
@@ -483,13 +488,19 @@ and exactly one recurrence kind — `--every 45m|2h|1d`, `--weekday 1..7` with
|
|
|
483
488
|
`--title` names it, `--mode chain|same` picks the mode (chain by default),
|
|
484
489
|
`--catch-up once|none` what an overdue entry does, `--keep-links N` how many chain
|
|
485
490
|
links stay behind the head (`0` keeps all), and `--max-failures` / `--max-skips`
|
|
486
|
-
how many consecutive failures or busy targets disable it.
|
|
487
|
-
|
|
488
|
-
|
|
491
|
+
how many consecutive failures or busy targets disable it. `--if CMD` gates each
|
|
492
|
+
firing on a shell command run in the session's folder first: exit 0 fires, 1 to 125 is
|
|
493
|
+
a quiet "not needed" (the next occurrence, nothing counted), anything else a failure
|
|
494
|
+
([Conditions](scheduling.md#conditions---if)); it is yours alone: inside a chi session
|
|
495
|
+
`--if` and `--no-if` exit 2, and the line after `add`'s says every ticker must be newer
|
|
496
|
+
than 0.189.0. A blank or over-16-KiB
|
|
497
|
+
prompt, two recurrence kinds, a `scratch` target, a `--weekday` without
|
|
498
|
+
`--time`, and `--if` on a `--date` one-off (or a blank, multi-line or over-1-KiB
|
|
499
|
+
CMD) are all refused with exit 2.
|
|
489
500
|
|
|
490
501
|
`edit ID` changes a schedule in place and prints its updated `list` row: `--title`,
|
|
491
502
|
`-m|--prompt`, one whole recurrence (as `add`'s: `--time` alone is refused),
|
|
492
|
-
`--catch-up
|
|
503
|
+
`--catch-up`, the three budgets and `--if CMD` / `--no-if` (not both), checked as `add` checks them; only the flags given
|
|
493
504
|
change, and the skip and failure counters, `enabled` and the history stay (it adds one
|
|
494
505
|
`edited` row naming the fields). The session and the mode don't change: `--session`,
|
|
495
506
|
`--continues` and `--mode` are refused ("cancel it and add a new one"). A new
|
|
@@ -502,7 +513,7 @@ say what another schedule of the chain says (its new title, or its new prompt an
|
|
|
502
513
|
recurrence); a missing id exits 1.
|
|
503
514
|
|
|
504
515
|
`tick` prints one line per entry it touched (`fired`, `skipped`, `missed`,
|
|
505
|
-
`failed`, or `would fire` under `--dry-run`), with the reason; nothing due prints
|
|
516
|
+
`failed`, `not-needed` for a condition that said no, or `would fire` under `--dry-run`), with the reason; nothing due prints
|
|
506
517
|
`no schedules due`, and a tick that finds the lock held by another prints `no
|
|
507
518
|
schedules due (another tick holds the lock)` — both exit 0, so a crontab line
|
|
508
519
|
that runs every five minutes is quiet. `run-now`, `enable`, `disable` and `cancel`
|
data/docs/configuration.md
CHANGED
|
@@ -2323,6 +2323,7 @@ column says so, a `--kebab-name` flag. The maps (`hosts:`, `models:`,
|
|
|
2323
2323
|
| `schedule.default_catch_up` | `once` | | An overdue schedule fires once at the next tick (`once`) or moves to its next occurrence (`none`). |
|
|
2324
2324
|
| `schedule.max_per_session` | `10` | | Enabled schedules one chain may hold. `schedule_task` (and `chi schedule add`) refuse past it, so a routine that re-schedules itself cannot pile up entries. |
|
|
2325
2325
|
| `schedule.max_total` | `50` | | Enabled schedules this machine may hold, across every chain. |
|
|
2326
|
+
| `schedule.condition_timeout_seconds` | `30` | | How long a schedule's condition (`chi schedule add --if CMD`) may run, 1 to 300 seconds; one that runs longer is killed and counts as a failure. See [Conditions](scheduling.md#conditions---if). |
|
|
2326
2327
|
| `image.max_side` | `1568` | | See "Images". |
|
|
2327
2328
|
| `image.max_bytes` | `3750000` | | See "Images". |
|
|
2328
2329
|
| `image.max_per_request` | `20` | | See "Images". |
|
data/docs/guardrails.md
CHANGED
|
@@ -6,7 +6,7 @@ loops (native and chat hosts). The verdict is **allow**, **ask** or
|
|
|
6
6
|
voter. Of two asks the first one names the rule, except a rule only the
|
|
7
7
|
user may allow (`chi-config`, `chi-home`, `chi-shim`, `chi-hooks`, `shell-touches-chi`,
|
|
8
8
|
`chi-context-cmd`, `chi-broadcast`, `prompt-memory-write`, `model-overlay-write`,
|
|
9
|
-
`chi-answer-piped`, `chi-answer-http`, `bundle-secrets-shell`): it takes over, and only the
|
|
9
|
+
`chi-answer-piped`, `chi-answer-http`, `bundle-secrets-shell`, `chi-schedule-if`): it takes over, and only the
|
|
10
10
|
scopes both asks offer are offered. When a second YAML rule with another id asks about the same call (`git merge y && git push`), no
|
|
11
11
|
[rule grant](#approvals) answers it and none is offered.
|
|
12
12
|
|
|
@@ -253,7 +253,8 @@ the user's alone (`user_only`): `chi answer` and the worker refuse the allow
|
|
|
253
253
|
with `only the user can allow it`. The same holds for the guardrails bundle's
|
|
254
254
|
other user-only rules (`chi-context-cmd`, `chi-broadcast`,
|
|
255
255
|
`prompt-memory-write`, `model-overlay-write`, and `chi-answer-piped` /
|
|
256
|
-
`chi-answer-http`, which answer a grandchild's question as the user
|
|
256
|
+
`chi-answer-http`, which answer a grandchild's question as the user,
|
|
257
|
+
`chi-schedule-if`, a schedule's condition the tick runs unattended), and core's
|
|
257
258
|
`bundle-secrets-shell` (a command naming a bundle's secrets).
|
|
258
259
|
|
|
259
260
|
`child-boundary` isn't one of them: an ask before a delegate child acts outside
|
|
@@ -354,8 +355,11 @@ with `writes: true` (symlinks resolved; see
|
|
|
354
355
|
[attached context](context.md) sources (`<state dir>/context/`: a
|
|
355
356
|
source's command runs later, outside the gate; `chi context` changes them),
|
|
356
357
|
a peer's [mailbox](peers.md) (`<state dir>/mailbox/`: chi's own tools never
|
|
357
|
-
write a peer's messages or pairing, `chi-mailbox`; `chi peer` does)
|
|
358
|
-
|
|
358
|
+
write a peer's messages or pairing, `chi-mailbox`; `chi peer` does),
|
|
359
|
+
[System 1's saved runs](system-one.md) (`<state dir>/system_one/`)
|
|
360
|
+
and the [schedules](scheduling.md) file (`<state dir>/schedules.json`,
|
|
361
|
+
`chi-schedules`: a schedule's prompt and its [condition](scheduling.md#conditions---if)
|
|
362
|
+
run unattended, the condition outside the guardrails; `chi schedule` changes it);
|
|
359
363
|
- ask (once or for the session): `config.yml`, `home.json` (the [chi home](configuration.md#the-chi-home): the Ruby every chi launch boots), the chi shim (`$XDG_STATE_HOME/samagotchi/bin/chi`, the `chi` every tool runs: `chi-shim`) and the plain hooks dir.
|
|
360
364
|
|
|
361
365
|
`execute` can still reach them; the guardrails bundle asks about shell
|
|
@@ -1231,8 +1235,9 @@ ask](#approvals) on the call, is judged and logged but always goes to the user):
|
|
|
1231
1235
|
or a YAML list, read like `guardrails.small_models`. Nothing is auto-allowed
|
|
1232
1236
|
by default: the user names the rules they want;
|
|
1233
1237
|
3. the rule is not one of the three that let an agent answer chi's own
|
|
1234
|
-
questions — `chi-answer-piped`, `chi-answer-http`, `chi-broadcast` —
|
|
1235
|
-
|
|
1238
|
+
questions — `chi-answer-piped`, `chi-answer-http`, `chi-broadcast` — nor
|
|
1239
|
+
`chi-schedule-if` (a schedule's condition, which the tick runs unattended,
|
|
1240
|
+
is the owner's): these are never auto-allowed, even when listed
|
|
1236
1241
|
(`SystemOne::SelfProtect::NEVER_AUTO`);
|
|
1237
1242
|
4. the call does not change chi itself (`SystemOne::SelfProtect.refuse?`), by
|
|
1238
1243
|
its own set of chi's dirs (`Guardrails::ChiDirs.self_protect`: the dirs whose
|
|
@@ -1371,9 +1376,16 @@ route around a deny. In both modes it asks before `git push`, `reset --hard`,
|
|
|
1371
1376
|
`clean -f`, `branch -D`, `filter-branch`/`filter-repo`; `rm -rf` on `/`, `~`,
|
|
1372
1377
|
`$HOME` or `..` paths, unless every target is inside a tmp folder; `curl … |
|
|
1373
1378
|
sh` and `base64 -d … | sh`; shell commands that name a path in chi's config,
|
|
1374
|
-
hooks, approvals, bundles
|
|
1379
|
+
hooks, approvals, bundles, attached context sources, the peer mailbox,
|
|
1380
|
+
System 1's saved runs or `schedules.json`, or chi's state dir itself (a
|
|
1381
|
+
`cp`/`mv`/`rsync` naming only the dir lands a file there), or a `.git/hooks`
|
|
1375
1382
|
(`shell-touches-chi`, `touches: chi_dirs`), unless they only read
|
|
1376
|
-
(`skip_read_only`); `chi
|
|
1383
|
+
(`skip_read_only`); `chi schedule add|edit … --if CMD` and `--no-if`
|
|
1384
|
+
(`chi-schedule-if`, once at a time and only by the user, never System 1: the
|
|
1385
|
+
tick runs CMD later, unattended and outside the guardrails, and `chi schedule`
|
|
1386
|
+
refuses the flag inside a session; the rule also sees `chi --remote NAME
|
|
1387
|
+
schedule`, quoted words, continuations and `xargs chi schedule add|edit`; see
|
|
1388
|
+
[Conditions](scheduling.md#conditions---if)); `chi context add … --cmd` (`chi-context-cmd`, once at a
|
|
1377
1389
|
time: a command chi will run every few minutes outside the guardrails; see
|
|
1378
1390
|
[Attached context](context.md#safety); the rule also sees `chi --remote NAME context add`, and a remote's `context push`
|
|
1379
1391
|
reaches its session with the trust of its chi web token, as your own `chi context push` does there); `chi broadcast` (`chi-broadcast`,
|
|
@@ -87,7 +87,10 @@ cancel kills the group), cwd the session's folder (a project source: the project
|
|
|
87
87
|
the arbiter between workers and the CLI: the loser gets `:busy`, and `fresh_within` is checked again under the lock,
|
|
88
88
|
so a project source shared by several workers is fetched once per interval. The `Outcome` status says what happened
|
|
89
89
|
(`:new :same :error :busy :fresh :cancelled :gone`); a cancelled fetch records nothing (a leaving worker isn't the
|
|
90
|
-
source failing). `chi context refresh` and the candidates' first fetch use the same entry.
|
|
90
|
+
source failing). `chi context refresh` and the candidates' first fetch use the same entry. `ContextFetch.run_command`
|
|
91
|
+
is also a schedule condition's runner (`Schedules::ConditionPart`, [scheduling.md](../scheduling.md#conditions---if)):
|
|
92
|
+
its `Run#status` is the command's `Process::Status` only when it ended on its own within the cap (nil after a
|
|
93
|
+
timeout, the cap or a cancel), so a TERM trap's exit 0 is never read as a pass.
|
|
91
94
|
|
|
92
95
|
A pushed source has no poller. `chi context push` writes the snapshot from its own process; the worker finds it
|
|
93
96
|
through `ContextAbsorber#store_signature` (names and mtimes of the files in the two folders, `subscriptions.json`
|
data/docs/internals/engine.md
CHANGED
|
@@ -115,7 +115,19 @@ StandardError in run_turn:
|
|
|
115
115
|
→ else end_turn(turn, "failed", save: true) (a failing save logged, turn_end_save_failed): failed_messages keeps
|
|
116
116
|
the loop's partial conversation (both loops LLM::FailedTurn.attach it), else turn.messages, with
|
|
117
117
|
TurnNote.failed at the tail; :turn_failed {error_class, message, duration_ms, + error_kind, retryable, host,
|
|
118
|
-
summary for a provider error}; re-raised
|
|
118
|
+
summary for a provider error; + error_kind: :chi_error, summary for chi's own}; re-raised
|
|
119
|
+
The line (FailureLine.for, via TurnEndings.failure_line: one builder for the event's summary, the note, the reload's line and the
|
|
120
|
+
one-shot's stderr): a provider error's summary; a UserError's message (ImageStore::Error,
|
|
121
|
+
ModelProfile::MissingModel: the user's to change, no error_kind); else chi's own (TurnEndings.chi_error?):
|
|
122
|
+
"chi error: <message's first line> (<Class>); details in samagotchi.log", logged ERROR turn chi_error with its
|
|
123
|
+
backtrace (Log.exception). retryable stays unset for it; a parent's wait, ParentReport and a schedule's last
|
|
124
|
+
result read error_kind "chi_error" as any other kind.
|
|
125
|
+
|
|
126
|
+
Before the Engine's turn (Worker#run_engine_turn: begin_turn, the checkpoint, the running save):
|
|
127
|
+
→ session still running, no :turn_failed sent: Engine#fail_turn_not_begun sets it idle, records last_turn and
|
|
128
|
+
emits :turn_failed from TurnEndings#failed_event (the same line), with no :turn_started before it; logged
|
|
129
|
+
ERROR worker turn_not_begun with its backtrace. The web draws its line only when no turn runs
|
|
130
|
+
(stream_handlers.js turn_failed); the Bridge's TurnAccumulator, with no turn, keeps nothing of it
|
|
119
131
|
|
|
120
132
|
Interrupt (Ctrl-C; a one-shot only, a worker traps INT):
|
|
121
133
|
→ turn.ended: re-raised only
|
|
@@ -221,6 +233,10 @@ loop:
|
|
|
221
233
|
one is logged `tool_direct_deferred`.
|
|
222
234
|
- The conversation goes out in the OpenAI wire format (`wire_messages`); `AnthropicMessages` translates it again
|
|
223
235
|
(`LLM::AnthropicWire`). Each call's result is its own tool message, paired by `tool_call_id`.
|
|
236
|
+
- Raw bytes in the history (a BINARY or invalid UTF-8 String) never fail a request: every loop's request starts at
|
|
237
|
+
`LLMContextView#messages` (`wire_messages`, the native prompt and its warm-up), which reads such an entry as UTF-8
|
|
238
|
+
and scrubs it first (`LLM::Utf8Scrub.messages`; a copy, the saved entry stays; the same Array when none needs it),
|
|
239
|
+
before any regex pass (`Steer.wire_text`'s forged-frame quoting). The body's own scrub (`Utf8Scrub.call`) stays.
|
|
224
240
|
- The first system message carries `cache_split:` (`SystemPrompt#stable_length`); where the adapters put cache
|
|
225
241
|
breakpoints is prompt-caching.md's and anthropic.md's.
|
|
226
242
|
- **Reasoning sent back** (`reasoning_content`) follows `TurnSettings#reasoning_history` (`ReasoningHistory.resolve`,
|
|
@@ -531,7 +547,7 @@ Turn events (the main ones; `events.rb` keeps the shared sets):
|
|
|
531
547
|
| `:guardrail_warning` | a guardrails line | `{message}` |
|
|
532
548
|
| `:turn_completed` | normal end | `{turn_id, result, turn_summary, display_pending}`, plus `verify`, `verdict`, `revises` when there are; the SSE frame omits `result` |
|
|
533
549
|
| `:turn_canceled` | Stop, hook stop, Ctrl-C, signal | `{turn_id, cancellation_reason, cancelled_by?, duration_ms}` |
|
|
534
|
-
| `:turn_failed` | an error | `{turn_id, error_class, message, duration_ms, error_kind?, retryable?, host?, summary?}` |
|
|
550
|
+
| `:turn_failed` | an error (also before a turn began: `Engine#fail_turn_not_begun`, no `:turn_started`) | `{turn_id, error_class, message, duration_ms, error_kind?, retryable?, host?, summary?}` |
|
|
535
551
|
| `:answer_display` | after the after_turn hooks (observers only) | `{display, refs?}` |
|
|
536
552
|
|
|
537
553
|
### Origins and authors
|
data/docs/pages.md
CHANGED
|
@@ -88,8 +88,9 @@ it. On an older chi `runtime` is a `NameError`, and the run fails with it (the l
|
|
|
88
88
|
of its prompt in quotes), `title`, `mode`, `prompt`, `recurrence_words`, `next_due`, `last_fired`, `last_result`,
|
|
89
89
|
`enabled`, `state` (`on`, `firing` or `off`), `off_reason` (`owner`, `skips`, `failures`, `done`, `missed` or
|
|
90
90
|
`off`; nil unless off), `skips`, `max_skips`, `failures`, `max_failures`, `skip_window`, `anchor`, `head`,
|
|
91
|
-
`created_at`,
|
|
92
|
-
|
|
91
|
+
`created_at`, `history`: its runs, oldest first, each with `at`, `status`, `detail` and `session_id`, and
|
|
92
|
+
`condition`: its `--if CMD` as `{"cmd", "by", "set_at"}`, nil for none ([Conditions](scheduling.md#conditions---if)).
|
|
93
|
+
Times are ISO 8601 UTC strings, nil when there is none.
|
|
93
94
|
- `runtime.schedules.rows`: every schedule as a table row (all but `history`): `ui.table runtime.schedules.rows,
|
|
94
95
|
columns: { "name" => "Name", "state" => "State" }`.
|
|
95
96
|
- `.warning`: `chi schedule list`'s warning when nothing ticks the schedules, else nil; `.unreadable_ids`: the id of
|
data/docs/scheduling.md
CHANGED
|
@@ -19,8 +19,9 @@ against, never rewritten: the chain's root and the id you remember), `head` (the
|
|
|
19
19
|
chain's current link, re-anchored after every firing: the link a chain continue
|
|
20
20
|
made, or the session a `same` turn was queued into), `mode`,
|
|
21
21
|
`prompt`, `recurrence`, `catch_up`, `keep_links`, `max_failures`, `max_skips`,
|
|
22
|
-
`next_due` (UTC ISO), `last_fired`, `last_result`, `failures`, `skips
|
|
23
|
-
`enabled
|
|
22
|
+
`next_due` (UTC ISO), `last_fired`, `last_result`, `failures`, `skips`,
|
|
23
|
+
`enabled` and `condition` (your `--if CMD`, [Conditions](#conditions---if); `null` for
|
|
24
|
+
none).
|
|
24
25
|
|
|
25
26
|
<a id="reminder-vs-schedule"></a>## Reminder or schedule?
|
|
26
27
|
|
|
@@ -239,7 +240,8 @@ disabled: Heartbeat", "skipped 12 times: <the last reason>" and the `chi schedul
|
|
|
239
240
|
enable <id>` that turns it back on; a tap opens its session. The tick leaves a notice
|
|
240
241
|
on the entry in `schedules.json` (`disabled_notice`) and a running chi web pushes it:
|
|
241
242
|
right after its own tick, and within `schedule.tick_interval_minutes` for another
|
|
242
|
-
ticker's, with `schedule.auto_tick` off too
|
|
243
|
+
ticker's, with `schedule.auto_tick` off too (a look that finds a tick holding the lock
|
|
244
|
+
tries again at the next scan, not an interval later). Only chi web pushes, so with no chi web
|
|
243
245
|
running the notice waits for one; a notice more than a day old, or one whose schedule
|
|
244
246
|
you enabled again, is dropped unpushed, and `chi schedule enable` clears it. It shows
|
|
245
247
|
even with a chi web page in front and waits a day for a phone that is offline. Two chi
|
|
@@ -266,7 +268,10 @@ and recurrence, or the same title — is refused too, naming its id, so a routin
|
|
|
266
268
|
tells each of its links to "make sure the Monday audit is scheduled" cannot multiply
|
|
267
269
|
itself. `schedule_task`, `list_schedules` and `cancel_schedule` see only schedules of
|
|
268
270
|
the calling session's chain (`all: true` steps outside it); `chi schedule list` is
|
|
269
|
-
always the machine-wide view. An
|
|
271
|
+
always the machine-wide view. An entry that doesn't read (`list` counts it, "chi schedule
|
|
272
|
+
cancel ID removes one") is cancelled by its exact id with `chi schedule cancel ID`, and by
|
|
273
|
+
`cancel_schedule` when its stored `anchor` or `head` is a link of the chain; one with
|
|
274
|
+
neither (its chain can't be told) only with `all: true`. An id, prefix or title that matches more than one entry
|
|
270
275
|
is refused with exit 2, naming the matches.
|
|
271
276
|
|
|
272
277
|
The tick's lock covers the file only, never the action: the clock advances before
|
|
@@ -283,6 +288,95 @@ And a `chi schedule add` from a terminal never waits on an archive or a recap wa
|
|
|
283
288
|
own retry loop follows a continue a human made between our resolve and its lock
|
|
284
289
|
instead of racing it.
|
|
285
290
|
|
|
291
|
+
## Conditions (`--if`)
|
|
292
|
+
|
|
293
|
+
`chi schedule add … --if CMD` (and `chi schedule edit ID --if CMD`, `--no-if` to drop
|
|
294
|
+
it) gates a schedule on a shell command: at each due tick chi runs CMD first, and the
|
|
295
|
+
firing happens only when CMD says it is needed. A heartbeat, say, a chain firing every
|
|
296
|
+
few minutes, can ask "is there anything to do?" first, so that most ticks cost no model
|
|
297
|
+
turn.
|
|
298
|
+
|
|
299
|
+
```
|
|
300
|
+
chi schedule add --session ab12 --every 5m -m "Check in" --if "$HOME/.local/bin/anything-to-do"
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
What the exit status means:
|
|
304
|
+
|
|
305
|
+
| CMD | the tick |
|
|
306
|
+
|---|---|
|
|
307
|
+
| exits 0 | goes on as without a condition: the busy check, then the firing |
|
|
308
|
+
| exits 1 to 125 | **not needed**: `next_due` moves to the next occurrence, `last_result` is `not needed: exit N: <its first line of stdout, else its last of stderr>`, the tick prints `not-needed`; nothing else changes (no skip or failure counted, no history row, the chain's one firing per tick left to its other schedules) |
|
|
309
|
+
| exits 126 or 127 (not executable, not found), dies by a signal, runs past `schedule.condition_timeout_seconds` (default 30, at most 300), prints more than 1 MiB, or can't start (the session's folder is gone) | a **failure** (`condition: <why>`), counted toward `max_failures` like any other, the occurrence kept for the next tick: a broken condition turns the schedule off after 3 ticks (about 15 minutes at a 5 minute tick), with the phone notification. Failures reset only when the schedule fires (or you enable it): a gate that seldom says yes adds up errors that come days apart, and three of them turn it off |
|
|
310
|
+
|
|
311
|
+
The order, per due schedule with a condition: its target resolves (a gone or archived
|
|
312
|
+
one fails as without a condition), then `catch_up: none` a whole cycle late is
|
|
313
|
+
`missed`, then the condition's answer, then the busy check. So a busy target spends no
|
|
314
|
+
skip on an occurrence that wasn't needed.
|
|
315
|
+
|
|
316
|
+
How it runs: `sh -c CMD` in the target session's folder, in its own process group
|
|
317
|
+
(a timeout kills the whole group), stdin closed, with the ticker's environment
|
|
318
|
+
scrubbed of Ruby's and Bundler's variables (`SpawnEnv`), plus
|
|
319
|
+
`SAMAGOTCHI_SCHEDULE_ID`, `SAMAGOTCHI_SCHEDULE_TITLE` and `SAMAGOTCHI_SCHEDULE_SESSION`
|
|
320
|
+
(the session it acts on) and never `SAMAGOTCHI_PARENT_SESSION`. Treat the title (and the
|
|
321
|
+
session id) as untrusted input in a gate script: the model may change a schedule's title
|
|
322
|
+
(`chi schedule edit --title` isn't owner-only), so quote it and never `eval` it. It gets the ticker's
|
|
323
|
+
environment: cron's PATH is thin, so name commands by absolute path, and the project's
|
|
324
|
+
mise tools aren't set up (wrap CMD in `mise exec --` when it needs them). It inherits
|
|
325
|
+
what the ticker's environment holds, secrets included. Each due condition runs once, in
|
|
326
|
+
turn, before the tick takes the schedule lock (a slow CMD never holds `chi schedule
|
|
327
|
+
add` or a firing's record up), and the tick's clock moves on by the time they took.
|
|
328
|
+
When the lock is taken, an answer counts only for the condition, the `next_due` and the
|
|
329
|
+
failure count it ran for (so two tickers count one occurrence's error once): an edit, a run-now or another ticker in between leaves the schedule as it is
|
|
330
|
+
and the next tick asks again. So CMD should be cheap, read-only and safe to run twice
|
|
331
|
+
(cron and chi web ticking at once may both run it). A schedule whose target is busy
|
|
332
|
+
runs CMD at every tick until it fires.
|
|
333
|
+
|
|
334
|
+
`chi schedule run-now` fires without asking CMD; `tick --dry-run` doesn't run it
|
|
335
|
+
(`would fire every 5m · if CMD (not run)`). `chi schedule show` has it as `if: CMD
|
|
336
|
+
(set from the CLI <time>; timeout 30 s; run-now skips it)`, `list` adds ` if: CMD`, and
|
|
337
|
+
`list --format json` gives `condition` as `{cmd, by, set_at}`. A `--date` one-off takes
|
|
338
|
+
none (it fires once; edit it to `--every` or `--weekday` first); one that has one anyway
|
|
339
|
+
(an older chi's `edit --date`) fails each tick, "conditions don't apply to a one-off",
|
|
340
|
+
without running CMD, until its budget turns it off.
|
|
341
|
+
|
|
342
|
+
**Only you set one.** CMD runs unattended and outside the
|
|
343
|
+
[guardrails](guardrails.md), so a condition is the owner's alone:
|
|
344
|
+
- `chi schedule … --if` / `--no-if` inside a chi session (any agent's shell:
|
|
345
|
+
`SAMAGOTCHI_PARENT_SESSION` is set) exits 2: "a schedule's condition is set only
|
|
346
|
+
from your own terminal";
|
|
347
|
+
- the `schedule_task` tool has no condition (and `list_schedules` only shows it);
|
|
348
|
+
- with the guardrails bundle, a shell command that runs `chi schedule add|edit … --if`
|
|
349
|
+
asks you every time (`chi-schedule-if`: no parent agent and no System 1 may allow
|
|
350
|
+
it), and `schedules.json` is a protected path: chi's file tools can't write it
|
|
351
|
+
(`chi-schedules`), and a shell command naming it asks (`shell-touches-chi`).
|
|
352
|
+
These are an accident guard, not a sandbox (chi's guardrails are for a model you trust
|
|
353
|
+
not to try): the in-session refusal and the user-only rule stop an accidental or casual
|
|
354
|
+
set, not a determined evasion. A command that unsets the session marker (`env -u
|
|
355
|
+
SAMAGOTCHI_PARENT_SESSION`) and spells the flag so the rule's text doesn't see it (quoting
|
|
356
|
+
or a backslash inside `--if`, a variable) gets through, as it does for `chi context add
|
|
357
|
+
--cmd`; so does a script that edits the file without naming it. A page script runs
|
|
358
|
+
without the session markers too ([pages.md](pages.md): a page is code you trust), so a
|
|
359
|
+
model-written page that runs `chi schedule … --if` sets one when you open it. Keep CMD itself out of the model's reach too: a gate script
|
|
360
|
+
inside a project the model edits is one it can change, and the tick then runs what the
|
|
361
|
+
model wrote. `add` and `edit --if` warn when CMD's first word is a relative path (it
|
|
362
|
+
resolves in the session's folder) or a script inside the session's folder or any git
|
|
363
|
+
work tree: "warning: the model can edit this script; keep a gate outside your projects
|
|
364
|
+
(an absolute path, e.g. under ~/.local/bin)". It is a warning, not a refusal; a command
|
|
365
|
+
on PATH (`test -f …`, `gh …`) gets none.
|
|
366
|
+
|
|
367
|
+
**Every ticker must be new enough.** A chi of 0.189.0 or older (0.189.0 shipped without them) doesn't know
|
|
368
|
+
conditions and would fire such a schedule unasked, so chi stores a schedule with a
|
|
369
|
+
condition with `next_due: null` and the real time under `condition_next_due`: an older
|
|
370
|
+
chi never finds it due (it reads it, lists it with no next time, keeps its sessions
|
|
371
|
+
from retention, and enables, disables and cancels it), and a newer one reads the real
|
|
372
|
+
time back. `add` and `edit --if` say so: "every chi that ticks (chi web, cron) must be
|
|
373
|
+
newer than 0.189.0; an older one leaves this schedule alone". After updating chi,
|
|
374
|
+
restart chi web and point cron at the new chi, or the schedule waits. One leak remains:
|
|
375
|
+
an older chi's `run-now`, or its `edit` of the recurrence, writes a real `next_due`,
|
|
376
|
+
and an older ticker then fires the schedule unconditionally until a newer chi writes
|
|
377
|
+
the file again (one tick in a mixed setup). A condition set by anything but the CLI
|
|
378
|
+
(`by` other than `cli`, a later chi's) fails closed: counted as a failure, never run.
|
|
379
|
+
|
|
286
380
|
## Keeping the chain short
|
|
287
381
|
|
|
288
382
|
`keep_links` (default `schedule.default_keep_links`, `0` keeps all) is how many
|
|
@@ -384,7 +478,7 @@ schedule that is off and why ("turned off by you", "skipped 12 times (≈1 h at
|
|
|
384
478
|
tick): busy", "failed 3 times: …", "one-off, done") with the `chi schedule enable ID`
|
|
385
479
|
that turns it back on (for a spent one-off, which has no next time, a `chi schedule
|
|
386
480
|
edit ID --date …` first); each entry of `schedules.json` that can't be read with the
|
|
387
|
-
`chi schedule cancel ID` that removes it; a table of every schedule (on and firing
|
|
481
|
+
`chi schedule cancel ID` that removes it; a table of every schedule (its If column the `--if` command; on and firing
|
|
388
482
|
first by next due, those with none last, then off; times in this machine's zone) and the recent runs, newest
|
|
389
483
|
first. It is read-only: ask chi, or use `chi schedule`, to change one. What it shows is
|
|
390
484
|
as of its last run: Refresh to update. A `schedules.json` that isn't JSON fails the
|
data/docs/sub-agent.md
CHANGED
|
@@ -126,7 +126,7 @@ Exit codes, both commands:
|
|
|
126
126
|
| 3 | `waiting_for_owner` | (a participant's wait, `chi --remote NAME send --wait` with their link's token) their turn waits on the session's owner: a question or an approval it raised, or the owner's step-limit Continue; wait again |
|
|
127
127
|
| 4 | `running` | `--timeout` passed; the turn goes on, wait again |
|
|
128
128
|
| 1 | `refused` | the queued turn was refused before it ran, no turn ran for it: `cancel_reason` `max_wakes` (an agent's message as a visitor, past `session.max_wakes`: [driver and visitor](#an-agents-messages-driver-and-visitor)), or for a participant's wait `revoked` (their link was revoked or expired), `outdated` (their link is an older chi's read-only one) or `cap_reached` (they spent their cap) |
|
|
129
|
-
| 1 | `failed`, `canceled`, `limit`, `removed`, `no_answer`, `error`, `worker_gone`, `stopped` | `detail` says what happened (`limit`: the turn ran out of steps and nobody can be asked, e.g. an older worker; `chi send ID -m '/continue yes'` continues it, except under `guardrails.parent_answers: hard`, where a parent's `/continue yes` is refused as its `chi answer --option Continue` is; `removed`: the `--queue` message waited for was taken back before it ran, no turn ran for it). `failed` adds `error_kind` (the provider error's kind: `credits`, `credits_held`, `rate_limited`, `server`, `auth`, `connection`,
|
|
129
|
+
| 1 | `failed`, `canceled`, `limit`, `removed`, `no_answer`, `error`, `worker_gone`, `stopped` | `detail` says what happened (`limit`: the turn ran out of steps and nobody can be asked, e.g. an older worker; `chi send ID -m '/continue yes'` continues it, except under `guardrails.parent_answers: hard`, where a parent's `/continue yes` is refused as its `chi answer --option Continue` is; `removed`: the `--queue` message waited for was taken back before it ran, no turn ran for it). `failed` adds `error_kind` (the provider error's kind: `credits`, `credits_held`, `rate_limited`, `server`, `auth`, `connection`, …; `chi_error` when chi itself failed, see samagotchi.log) and `retryable` when known; `canceled` adds `cancel_reason` (`user`: a Stop in the web; `session_stopped`: a session stop, `chi sessions stop` or the web's; `worker_stopped`: the turn waited for (a `--queue` message's, a message's to an idle session, the running turn a message merged into or a plain `--wait` saw running) died with its worker (detail "its worker exited mid-turn"), settled by the next one; `hook`; `ctrl_c`; `manual`) and `stopped_by` (the hook that stopped it, e.g. `loop-guard`) when known |
|
|
130
130
|
| 2 | (no JSON) | usage error, or an option the question doesn't offer |
|
|
131
131
|
| 130 | `running` | Ctrl-C; the turn goes on |
|
|
132
132
|
|
|
@@ -164,6 +164,21 @@ rules:
|
|
|
164
164
|
scopes: [once]
|
|
165
165
|
reason: attaches a command chi will run every few minutes, outside the guardrails
|
|
166
166
|
|
|
167
|
+
# ── a schedule's condition: a shell command the tick runs unattended ──
|
|
168
|
+
# chi schedule add|edit --if CMD (and --no-if) is the owner's: the tick
|
|
169
|
+
# runs CMD later, outside the guardrails, and chi schedule refuses the
|
|
170
|
+
# flag inside a session (SAMAGOTCHI_PARENT_SESSION), which an agent can
|
|
171
|
+
# unset. This asks every time, and only the user may allow it (core's
|
|
172
|
+
# PROTECTED_RULES; System 1 never: NEVER_AUTO). The same shapes as
|
|
173
|
+
# chi-context-cmd: quoted words, continuations, --if=…, --remote NAME
|
|
174
|
+
# before the word, and xargs chi schedule add|edit whatever it is fed.
|
|
175
|
+
- id: chi-schedule-if
|
|
176
|
+
tool: shell
|
|
177
|
+
command: '\bchi["'']?(?:[\s\\]+["'']?--remote(?:=|["'']?[\s\\]+["'']?)[^\s"''\\;&|]+["'']?)*[\s\\]+["'']?schedule["'']?[\s\\]+["'']?(?:add|edit)\b(?:[^\n]|\\\n)*[\s"''\\]--(?:no-)?if(?:[\s="''\\]|$)|\bxargs\b[^;&|\n]*\bchi["'']?(?:[\s\\]+["'']?--remote(?:=|["'']?[\s\\]+["'']?)[^\s"''\\;&|]+["'']?)*[\s\\]+["'']?schedule["'']?[\s\\]+["'']?(?:add|edit)\b'
|
|
178
|
+
verdict: ask
|
|
179
|
+
scopes: [once]
|
|
180
|
+
reason: sets a shell command chi's schedule tick runs unattended, outside the guardrails
|
|
181
|
+
|
|
167
182
|
# ── chi broadcast: for the user, not an agent ─────────────────────────
|
|
168
183
|
# chi broadcast refuses to run inside a session (SAMAGOTCHI_PARENT_SESSION
|
|
169
184
|
# is set there), but an agent can unset that; this asks every time, and
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: guardrails
|
|
3
|
-
version: 0.9.
|
|
3
|
+
version: 0.9.4
|
|
4
4
|
scope: system
|
|
5
|
-
description: Optional default guardrail rules (git push/rewrites, rm -rf wide, curl | sh, git hooks, chi's own config and attached context from the shell, chi context add --cmd, chi broadcast, answering chi around chi answer, removing a memory, writing a memory that reaches the system prompt (identity, model notes) or a model overlay; in strict mode also git rebase and writes and git in another checkout outside the session's repo), asks only small models get (git checkout --/restore, git stash drop), and a note for the model
|
|
5
|
+
description: Optional default guardrail rules (git push/rewrites, rm -rf wide, curl | sh, git hooks, chi's own config and attached context from the shell, chi context add --cmd, chi schedule --if, chi broadcast, answering chi around chi answer, removing a memory, writing a memory that reaches the system prompt (identity, model notes) or a model overlay; in strict mode also git rebase and writes and git in another checkout outside the session's repo), asks only small models get (git checkout --/restore, git stash drop), and a note for the model
|
|
6
6
|
trust_level: reviewed
|
|
7
7
|
# models: in small-models.yml (guardrails.small_models) needs 0.8.1; git: in rules.yml needs 0.17.0;
|
|
8
8
|
# a rule's memory: key (memory-remove) needs 0.36.0, and its overlay and prompt values (model-overlay-write,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: schedules
|
|
3
|
-
version: 0.1.
|
|
3
|
+
version: 0.1.1
|
|
4
4
|
scope: system
|
|
5
5
|
description: "A Schedules page in chi web (#/p/schedules, chi page run schedules): every durable schedule, why one is off and how to turn it on, and the recent runs; read-only"
|
|
6
6
|
trust_level: reviewed
|
|
7
|
-
#
|
|
8
|
-
requires_chi: ">= 0.
|
|
7
|
+
# runtime.schedules' condition (the If column) is new in the next chi (release:bump sets the floor)
|
|
8
|
+
requires_chi: ">= 0.190.0"
|
|
9
9
|
scripts:
|
|
10
|
-
schedules.rb: sha256:
|
|
10
|
+
schedules.rb: sha256:ac1bf79cb3df54511c0263cd7dde7e671f853a66c932606c8e2a235835afb44d
|
|
11
11
|
pages: [schedules.rb]
|
|
@@ -93,6 +93,16 @@ def turn_on(schedule)
|
|
|
93
93
|
"to run it again: `chi schedule edit #{schedule.id} --date YYYY-MM-DDTHH:MM`, then `chi schedule enable #{schedule.id}`"
|
|
94
94
|
end
|
|
95
95
|
|
|
96
|
+
# The If column: the owner's `--if CMD` (chi runs it before each firing;
|
|
97
|
+
# a "not needed" moves the schedule to its next time), cut; nil for none.
|
|
98
|
+
def if_words(schedule)
|
|
99
|
+
condition = schedule.condition
|
|
100
|
+
return nil if condition.nil?
|
|
101
|
+
|
|
102
|
+
cmd = condition.is_a?(Hash) ? condition["cmd"] : nil
|
|
103
|
+
cmd.is_a?(String) ? cut(cmd, NAME_CHARS) : "(can't be read)"
|
|
104
|
+
end
|
|
105
|
+
|
|
96
106
|
def unreadable_lines(ids)
|
|
97
107
|
lines = ids.compact.map do |id|
|
|
98
108
|
# An id too long to show can't be given to cancel either.
|
|
@@ -132,13 +142,13 @@ page "Schedules" do |ui|
|
|
|
132
142
|
{ "name" => schedule.name, "state" => state_words(schedule), "when" => schedule.recurrence_words,
|
|
133
143
|
"next" => clock(schedule.next_due), "last_run" => clock(schedule.last_fired), "last_result" => schedule.last_result,
|
|
134
144
|
"skips" => "#{schedule.skips}/#{schedule.max_skips}", "failures" => "#{schedule.failures}/#{schedule.max_failures}",
|
|
135
|
-
"mode" => schedule.mode, "id" => schedule.id.to_s[0, 8] }
|
|
145
|
+
"if" => if_words(schedule), "mode" => schedule.mode, "id" => schedule.id.to_s[0, 8] }
|
|
136
146
|
end
|
|
137
147
|
more = ordered.size - rows.size
|
|
138
148
|
ui.text "Schedules#{"\n\nThe first #{SCHEDULE_ROWS}; #{more} more in `chi schedule list --all`." if more.positive?}"
|
|
139
149
|
ui.table rows, columns: { "name" => "Name", "state" => "State", "when" => "When", "next" => "Next", "last_run" => "Last run",
|
|
140
|
-
"last_result" => "Last result", "skips" => "Skips", "failures" => "Failures", "
|
|
141
|
-
"id" => "ID" },
|
|
150
|
+
"last_result" => "Last result", "skips" => "Skips", "failures" => "Failures", "if" => "If",
|
|
151
|
+
"mode" => "Mode", "id" => "ID" },
|
|
142
152
|
key: %w[state next]
|
|
143
153
|
|
|
144
154
|
runs = list.entries.flat_map { |schedule| schedule.history.map { |run| [schedule, run] } }
|
data/lib/samagotchi/config.rb
CHANGED
|
@@ -180,6 +180,8 @@ module Samagotchi
|
|
|
180
180
|
# What one chain and one machine may hold, so a routine that re-schedules itself cannot multiply its entries.
|
|
181
181
|
Entry.new(key: "schedule.max_per_session", yaml_path: %w[schedule max_per_session], type: :integer, default: 10, expose: %i[env config], lifecycle: :next_cli_run),
|
|
182
182
|
Entry.new(key: "schedule.max_total", yaml_path: %w[schedule max_total], type: :integer, default: 50, expose: %i[env config], lifecycle: :next_cli_run),
|
|
183
|
+
# How long a schedule's condition (--if CMD) may run before it is killed and counted as a failure (1..300).
|
|
184
|
+
Entry.new(key: "schedule.condition_timeout_seconds", yaml_path: %w[schedule condition_timeout_seconds], type: :integer, default: 30, expose: %i[env config], lifecycle: :next_cli_run),
|
|
183
185
|
|
|
184
186
|
# Images sent to a model (ImageStore): the long side they are downscaled
|
|
185
187
|
# to, the most bytes one may take (bigger → re-encoded as jpeg), and how
|
|
@@ -35,8 +35,13 @@ module Samagotchi
|
|
|
35
35
|
# replaced while it ran: nothing recorded for it).
|
|
36
36
|
Outcome = Data.define(:status, :snapshot, :error)
|
|
37
37
|
# What the command did: +output+ its stdout, +error+ nil or why it
|
|
38
|
-
# failed, +cancelled+ the caller stopped it
|
|
39
|
-
|
|
38
|
+
# failed, +cancelled+ the caller stopped it, +status+ its
|
|
39
|
+
# Process::Status when it ended on its own within the cap (nil when it
|
|
40
|
+
# was stopped: a timeout, the cap, a cancel; or never ran), so a caller
|
|
41
|
+
# telling exit codes apart never reads a TERM trap's exit 0 as a pass.
|
|
42
|
+
Run = Data.define(:output, :error, :stderr, :cancelled, :status) do
|
|
43
|
+
def initialize(output:, error:, stderr:, cancelled:, status: nil) = super
|
|
44
|
+
end
|
|
40
45
|
|
|
41
46
|
module_function
|
|
42
47
|
|
|
@@ -137,9 +142,10 @@ module Samagotchi
|
|
|
137
142
|
|
|
138
143
|
# Checked again once the reader is done: a command that exits before
|
|
139
144
|
# wait's next tick never gets an over from it.
|
|
145
|
+
ended = error.nil? && !out_reader.over?
|
|
140
146
|
error = OVER_CAP if out_reader.over?
|
|
141
147
|
error ||= exit_error(status, stderr_text)
|
|
142
|
-
Run.new(output: out_reader.text, error: error, stderr: stderr_text, cancelled: false)
|
|
148
|
+
Run.new(output: out_reader.text, error: error, stderr: stderr_text, cancelled: false, status: ended ? status : nil)
|
|
143
149
|
rescue SystemCallError => e
|
|
144
150
|
Run.new(output: nil, error: "couldn't run it: #{e.message}", stderr: "", cancelled: false)
|
|
145
151
|
ensure
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "../config"
|
|
4
4
|
require_relative "../effective_model"
|
|
5
|
+
require_relative "../failure_line"
|
|
5
6
|
require_relative "../llm/backend"
|
|
6
7
|
require_relative "../llm/errors"
|
|
7
8
|
require_relative "../log"
|
|
@@ -91,12 +92,13 @@ module Samagotchi
|
|
|
91
92
|
end
|
|
92
93
|
private :record_prompt_parts
|
|
93
94
|
|
|
94
|
-
# A failed turn's one line (the error's
|
|
95
|
-
#
|
|
96
|
-
# "host main" alone
|
|
95
|
+
# A failed turn's one line (FailureLine.for: the error's
|
|
96
|
+
# #summary, else "chi error: …"). A host's failure under an alias says
|
|
97
|
+
# what the alias became (HostRegistry#alias_note): "host main" alone
|
|
98
|
+
# doesn't tell --model splash's user it was splash.
|
|
97
99
|
# @return [String]
|
|
98
100
|
def failure_summary(error)
|
|
99
|
-
summary =
|
|
101
|
+
summary = FailureLine.for(error)
|
|
100
102
|
return summary unless error.is_a?(LLM::ProviderError) && error.host
|
|
101
103
|
|
|
102
104
|
note = @host_registry.alias_note(effective_model_name)
|