samagotchi 0.172.1 → 0.173.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 +31 -1
- data/docs/architecture.md +16 -5
- data/docs/cli.md +2 -1
- data/docs/configuration.md +1 -1
- data/docs/internals/background-tasks.md +19 -6
- data/docs/internals/bridge.md +2 -2
- data/docs/internals/engine.md +2 -1
- data/docs/internals/participants.md +67 -9
- data/docs/internals/remote-sessions.md +1 -1
- data/docs/internals/web-frontend.md +11 -6
- data/docs/plugins.md +3 -1
- data/docs/sessions.md +2 -2
- data/docs/testing.md +26 -10
- data/lib/samagotchi/bridge.rb +3 -2
- data/lib/samagotchi/bundle_command/try/sandbox.rb +2 -2
- data/lib/samagotchi/bundles/core/manifest.yml +2 -2
- data/lib/samagotchi/bundles/slow-commands/manifest.yml +3 -3
- data/lib/samagotchi/bundles/slow-commands/plugin.rb +3 -3
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/engine/participants.rb +2 -2
- data/lib/samagotchi/engine.rb +0 -1
- data/lib/samagotchi/file_ref.rb +3 -5
- data/lib/samagotchi/guardrails/participant_refusal.rb +1 -1
- data/lib/samagotchi/memory_usage.rb +2 -1
- data/lib/samagotchi/message_parts.rb +5 -3
- data/lib/samagotchi/objectives_backing.rb +6 -10
- data/lib/samagotchi/parent_report.rb +1 -1
- data/lib/samagotchi/participant_prompts.rb +101 -0
- data/lib/samagotchi/participant_turn_mode.rb +1 -1
- data/lib/samagotchi/project_env.rb +7 -5
- data/lib/samagotchi/prompt_history.rb +2 -2
- data/lib/samagotchi/send_command/parent_gate.rb +2 -2
- data/lib/samagotchi/send_command.rb +4 -4
- data/lib/samagotchi/session_command_catalog.rb +210 -0
- data/lib/samagotchi/session_commands.rb +12 -183
- data/lib/samagotchi/session_manager/lifecycle.rb +5 -4
- data/lib/samagotchi/session_manager.rb +2 -1
- data/lib/samagotchi/session_stores.rb +2 -0
- data/lib/samagotchi/spawn_env.rb +75 -0
- data/lib/samagotchi/task_files.rb +51 -0
- data/lib/samagotchi/task_transcript.rb +67 -0
- data/lib/samagotchi/task_watch.rb +8 -6
- data/lib/samagotchi/terminal_ui/attached_loop/composer.rb +3 -3
- data/lib/samagotchi/terminal_ui/attached_loop/questions.rb +2 -2
- data/lib/samagotchi/terminal_ui/attached_loop.rb +3 -3
- data/lib/samagotchi/terminal_ui/input_support.rb +1 -1
- data/lib/samagotchi/testing/boundary.rb +5 -0
- data/lib/samagotchi/tool_activity.rb +63 -79
- data/lib/samagotchi/tool_names.rb +179 -0
- data/lib/samagotchi/tool_view.rb +3 -5
- data/lib/samagotchi/tools/ask_user_question.rb +2 -1
- data/lib/samagotchi/tools/builtins.rb +1 -1
- data/lib/samagotchi/tools/cancel_reminder.rb +2 -1
- data/lib/samagotchi/tools/cancel_schedule.rb +3 -1
- data/lib/samagotchi/tools/context_read.rb +2 -1
- data/lib/samagotchi/tools/delegate.rb +2 -1
- data/lib/samagotchi/tools/delegate_result.rb +2 -1
- data/lib/samagotchi/tools/edit.rb +2 -1
- data/lib/samagotchi/tools/execute.rb +22 -28
- data/lib/samagotchi/tools/forget_outputs.rb +2 -1
- data/lib/samagotchi/tools/list_reminders.rb +2 -1
- data/lib/samagotchi/tools/list_schedules.rb +3 -1
- data/lib/samagotchi/tools/list_sessions.rb +2 -1
- data/lib/samagotchi/tools/memory.rb +3 -2
- data/lib/samagotchi/tools/objectives_tool.rb +5 -4
- data/lib/samagotchi/tools/read.rb +2 -1
- data/lib/samagotchi/tools/register_reminder.rb +2 -1
- data/lib/samagotchi/tools/schedule_task.rb +3 -1
- data/lib/samagotchi/tools/send_note.rb +2 -1
- data/lib/samagotchi/tools/task_create.rb +2 -1
- data/lib/samagotchi/tools/task_get.rb +2 -1
- data/lib/samagotchi/tools/task_list.rb +2 -1
- data/lib/samagotchi/tools/task_runtime.rb +34 -154
- data/lib/samagotchi/tools/task_stop.rb +2 -1
- data/lib/samagotchi/tools/task_wait.rb +3 -2
- data/lib/samagotchi/tools/web_fetch.rb +2 -1
- data/lib/samagotchi/tools/write.rb +2 -1
- data/lib/samagotchi/turn_checkpoint.rb +1 -1
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +38 -36
- data/lib/samagotchi/web/message_display.rb +1 -7
- data/lib/samagotchi/web/participant_access.rb +12 -4
- data/lib/samagotchi/web/participant_history.rb +68 -0
- data/lib/samagotchi/web/participant_images.rb +2 -1
- data/lib/samagotchi/web/participant_show.rb +5 -5
- data/lib/samagotchi/web/participants_admin.rb +1 -1
- data/lib/samagotchi/web/public/app.js +11 -9
- data/lib/samagotchi/web/public/card_registry.js +248 -0
- data/lib/samagotchi/web/public/cards_offscreen.js +3 -3
- data/lib/samagotchi/web/public/cards_place.js +8 -2
- data/lib/samagotchi/web/public/history_shape.js +1 -2
- data/lib/samagotchi/web/public/participant_history.js +27 -0
- data/lib/samagotchi/web/public/question_cards.js +1 -15
- data/lib/samagotchi/web/public/reload_check.js +90 -72
- data/lib/samagotchi/web/public/session_view.js +6 -1
- data/lib/samagotchi/web/public/stage_asking.js +6 -20
- data/lib/samagotchi/web/public/stage_view.js +2 -2
- data/lib/samagotchi/web/public/stage_waiting.js +4 -10
- data/lib/samagotchi/web/public/task_stop.js +1 -1
- data/lib/samagotchi/web/push_routes.rb +1 -1
- data/lib/samagotchi/web/reload_check_route.rb +5 -2
- data/lib/samagotchi/web/request_body.rb +72 -0
- data/lib/samagotchi/web/server.rb +70 -0
- data/lib/samagotchi/web/session_access_routes.rb +13 -11
- data/lib/samagotchi/web/session_control.rb +21 -15
- data/lib/samagotchi/web/session_create.rb +2 -1
- data/lib/samagotchi/web/session_show.rb +8 -8
- data/lib/samagotchi/web/viewer.rb +7 -2
- data/lib/samagotchi/web/working_set_routes.rb +3 -3
- data/lib/samagotchi/worker.rb +49 -182
- data/lib/samagotchi/worker_exit_claim.rb +102 -0
- data/lib/samagotchi/worker_participant_gate.rb +156 -0
- data/lib/samagotchi/worker_task_wakes.rb +2 -2
- metadata +13 -1
data/docs/sessions.md
CHANGED
|
@@ -41,7 +41,7 @@ A new session field is one `Session::FIELDS` row, plus a `SessionSetup` member w
|
|
|
41
41
|
|
|
42
42
|
**A worker killed mid-turn:** while a turn runs, its worker keeps it on disk (`TurnCheckpoint`): the session file has the turn so far (the prompt from the turn's start, then the finished tool steps and lines merged into it) and `interrupted_turn: {id, started_at, at, iteration, enqueued_id}` (`enqueued_id`: the input the turn runs, so any process can tell which turn is running; a continue turn carries its offer turn's), written as the turn starts, at the loop's first iteration boundary and then at most every 10 s (`updated_at` moves with it). The turn's end saves the real messages without the mark. A worker that died without ending its turn (SIGKILL, a crash of the process) leaves the mark, and loses what came after its last written boundary: at most the last 10 s of steps, plus the step in flight. Each checkpoint write also saves the turn's metrics so far to `analytics.json` (tokens, speeds, timings, its finished tool calls), as the record a killed turn leaves: canceled, `cancellation_reason: worker_stopped`; the turn's own end writes over it. The next worker to start for the session (a `chi send`, `--resume`, `--attach`, the web), or a `chi --resume ID -p TEXT --non-interactive` run, settles the turn before anything else (`TurnCheckpoint.settle`, log `interrupted_turn_settled`): a note `the previous turn was cancelled (worker-stopped) after Ns` goes at the tail, the status goes idle and the mark goes; `last_turn` stays the previous turn's (a new one saved before the turn a `chi send --wait` woke the worker for would end that wait at once); the dead turn's end is recorded under its `enqueued_id` instead, in `<id>/input/settled/<enqueued_id>` (a `last_turn` record: canceled, `cancel_reason: worker_stopped`), which only a wait for that very turn reads (`chi send --queue --wait`, a `chi send --wait -m` to an idle session or `--new`, `chi send --wait ID --turn`, a continue's wait): it ends `canceled` with `cancel_reason: worker_stopped`, detail "its worker exited mid-turn", instead of timing out. A wake or reminder turn's settle is recorded under its worker-minted `wake-…` id the same way, and a message merged into a turn as a steer follows that turn's id (`input/merged/`). A wait with no turn id that saw the turn running ends the same way when the settle comes (`chi send --wait ID` with no message on a turn with no id, such as a 0.156 worker's reminder turn), unless an input still waits or was claimed since: an unmerged message runs as its own turn next, and that turn's end is the answer. A reply the turn wrote before its worker died is still its answer. The session shows the turn's prompt and steps with that note; the dead turn is not run again, and the model reads on its next turn that it was cut.
|
|
43
43
|
|
|
44
|
-
**Stopping a worker:** `chi sessions stop ID` marks the session stopped (an `<id>/stopped` file holding when, `{"at"}`, not a session.json field, which a worker saving at that moment would write over; a resume removes it), sends its worker TERM, then CONT (a stopped worker, SIGSTOP or Ctrl-Z, runs its TERM handler only once continued, so it leaves at once instead of outliving the wait), and waits (up to 10 s) until the worker has let go of `owner.lock`. A running turn is canceled over the Bridge first, with reason `session_stopped` (the turn's line ends "(session stopped)", its note says `cancelled (session-stopped)`, and a command it was running says "stopped as the session was stopped"; a bare signal to the worker makes it "stopped by a signal to chi"; an older worker takes the reason as `manual`); the TERM stops whatever still runs as a Stop with reason `signal` and saves it (a spawned worker traps TERM, HUP and INT: `WorkerSignals`; a turn not ended within 3 s, 0.5 s after a stop or a second signal, is cut and the session saved as it was), and a stopped worker still saves its kept turn, since the marker, not the saved status, says stopped. Any TERM, HUP or INT does the same to a worker outside a stop: it leaves (log `worker stop reason=signal`) and the next send wakes a new one, so a `chi --resume ID` right after spawns a fresh worker. That is also how to restart a worker still running an older chi, which the attached terminal reports when a command or a question dismiss gets a 404, and the web when an answer, a dismiss, a command or a cancel does (`501 not_supported`; `BridgeClient.stale_worker_message`). A command this chi has that the older worker doesn't (`/llm-context`, the web's ⚙ panel, against a 0.39.0 worker) says the same, not `not a session command` (`
|
|
44
|
+
**Stopping a worker:** `chi sessions stop ID` marks the session stopped (an `<id>/stopped` file holding when, `{"at"}`, not a session.json field, which a worker saving at that moment would write over; a resume removes it), sends its worker TERM, then CONT (a stopped worker, SIGSTOP or Ctrl-Z, runs its TERM handler only once continued, so it leaves at once instead of outliving the wait), and waits (up to 10 s) until the worker has let go of `owner.lock`. A running turn is canceled over the Bridge first, with reason `session_stopped` (the turn's line ends "(session stopped)", its note says `cancelled (session-stopped)`, and a command it was running says "stopped as the session was stopped"; a bare signal to the worker makes it "stopped by a signal to chi"; an older worker takes the reason as `manual`); the TERM stops whatever still runs as a Stop with reason `signal` and saves it (a spawned worker traps TERM, HUP and INT: `WorkerSignals`; a turn not ended within 3 s, 0.5 s after a stop or a second signal, is cut and the session saved as it was), and a stopped worker still saves its kept turn, since the marker, not the saved status, says stopped. Any TERM, HUP or INT does the same to a worker outside a stop: it leaves (log `worker stop reason=signal`) and the next send wakes a new one, so a `chi --resume ID` right after spawns a fresh worker. That is also how to restart a worker still running an older chi, which the attached terminal reports when a command or a question dismiss gets a 404, and the web when an answer, a dismiss, a command or a cancel does (`501 not_supported`; `BridgeClient.stale_worker_message`). A command this chi has that the older worker doesn't (`/llm-context`, the web's ⚙ panel, against a 0.39.0 worker) says the same, not `not a session command` (`SessionCommandCatalog.builtin_name`); a typo keeps its `400 unknown_command`. The web's `POST /api/sessions/:id/stop` waits the same way, for 2 s (the page's Stop shows the stop at once), or for the body's `wait` up to the same 10 s (`SessionManager::STOP_WAIT`): `chi --remote NAME sessions stop` sends it, so it waits as long as here. Before that stop, the page's `stop session` button asks what the worker still has that the user can stop: `GET /api/sessions/:id/holds` (owner-only) answers the worker's `holds` — the same list the exit ask's 409 carries — always an array, empty when there is no live worker, one from before the route, or one that did not answer. With something, a sheet (a bottom sheet on a phone, a popover at the button otherwise — `stop_sheet.js`) lists them, at most three of a kind named and `+N more`, and offers **Stop all** (`POST /api/sessions/:id/holds/stop` → `HoldStop#stop_all`, then the stop), **Stop session only** (the stop exactly as it was) or **Cancel**. Nothing to ask about is the plain confirm, one tap as before. Both buttons stay because a stop only TERMs the worker: its reminders die with it (a stop also deletes a restart's `reminders.json` no successor took yet, so a later resume doesn't bring them back), while a background task and a delegate are their own processes and keep running. A command sent during a turn that waits for its end (`/model X`, `!cmd`; see *Typing during a turn* in [cli.md](cli.md)) and hasn't run when the worker leaves (a stop, a crash) is answered `command_ran {status: "dropped"}`, so no UI keeps showing it waiting.
|
|
45
45
|
|
|
46
46
|
**Deleting a session:** `chi sessions delete ID...`, `/exit --delete` in a terminal and the Web UI's delete all go through `SessionManager.delete_session`: it resolves a unique prefix, removes `<id>.json` and the whole `<id>/` dir, and returns what it removed. A session a one-turn `chi --non-interactive` run has (`owner.lock` kind `tui`) is always refused. One a worker runs is refused unless the caller asks to stop it: then it stops the worker as `chi sessions stop` does and deletes once `owner.lock` is free (`--force` on the CLI, 10 s; the web page always, 2 s; `/exit --delete` after the worker agreed to exit, 10 s). A worker that outlives the wait leaves the session in place. A session whose worker is being started (the `<id>/starting` marker) is refused or stopped the same way, and the files go while the delete holds `owner.lock`, so a worker can't take the session in the middle; a worker that still had it loaded doesn't write it back. The web's route is `DELETE /api/sessions/:id?force=true` (the page sends `force`; without it a live worker's session is 409 `worker_running`, as the CLI without `--force`; 200 `{status: "deleted", session_id, stopped}`; 409 `owned_by_tui` or `still_stopping`; 404).
|
|
47
47
|
|
|
@@ -493,7 +493,7 @@ mise.toml pins Ruby 3.4 gets that `ruby`, `gem` and `bundle` in its tools while
|
|
|
493
493
|
`.config/mise/`, `mise/`, `.mise/`) are secrets to them, as `.env` is.
|
|
494
494
|
- **What tools still drop**: every `execute`, task, `!cmd`, context source and MCP server takes no `RUBYOPT`, `RUBYLIB`, or what `bundle exec` sets
|
|
495
495
|
(`BUNDLE_GEMFILE`, `BUNDLE_LOCKFILE`, `BUNDLE_BIN_PATH`, `BUNDLER_VERSION`, `BUNDLER_SETUP`: `BundlerEnv`) from the project's mise env: it runs without `RUBYLIB` and Bundler's
|
|
496
|
-
variables, and with the worker's own `RUBYOPT`, Bundler's part removed (`
|
|
496
|
+
variables, and with the worker's own `RUBYOPT`, Bundler's part removed (`SpawnEnv`).
|
|
497
497
|
- **`chi` in a tool** stays the home's: with a chi home the tools' PATH starts with `$XDG_STATE_HOME/samagotchi/bin`,
|
|
498
498
|
a dir holding only a `chi` script that boots the home (rewritten at each worker start when the home changed; it
|
|
499
499
|
unsets `RUBYOPT`, `RUBYLIB`, `RUBYGEMS_GEMDEPS`, `GEMRC` and `BUNDLE*` before it runs, so a `bundle exec` around it
|
data/docs/testing.md
CHANGED
|
@@ -231,16 +231,21 @@ Each level owns its own share; a detail is asserted once, at the lowest level th
|
|
|
231
231
|
A turn cut mid-way while a card waits is `stage_cuts_parity.test.js`'s: the scenarios in `spec/shared/stage_cuts/`
|
|
232
232
|
(written from `spec/support/stage_cut_scenarios.rb` by `spec/web/session_show_cuts_spec.rb`, which folds the events
|
|
233
233
|
to each cut into a worker's snapshot and sends it through `Web::SessionShow`; `UPDATE_STAGE_CUTS=1` rewrites them)
|
|
234
|
-
are drawn live to the cut (question cards included
|
|
234
|
+
are drawn live to the cut (question cards included; a turn-end cut, which each scenario has, after the stage's
|
|
235
|
+
hand-off: where a finished turn's questions land and the reply they keep) and reloaded from the cut's show, and the stage (`stageShape`:
|
|
235
236
|
its cards, the docked ones, the lead-in bubbles, the card in front, the one that shows and the pager, the fold) and
|
|
236
237
|
the history compared; a known difference is listed in its `EXPECTED`, by scenario, cut and field (one gone fails
|
|
237
|
-
too;
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
(`test.use({ stageCheck: true })`, a fixture in `spec/e2e/support/fixtures.js
|
|
238
|
+
too; one today: `checkin_approval/turn end`, where a reload can't tell when a card stopped asking), and on both pages `stage_waiting.js`'s cards agree with the slots, one docked card showing. `STAGE_CUTS_DEBUG=1` prints each cut's differences. The cuts also
|
|
239
|
+
feed `card_registry.test.js` (every cut: its events against its show seeded and replayed) and
|
|
240
|
+
`reload_check.test.js` (the turn-end cuts: the opt-in reload check, live against the read, says same). Both
|
|
241
|
+
harnesses build their page with `spec/web/public/live_page.js`. The stage's drift check (the
|
|
242
|
+
registry against the slots: no entry without its waiting card, no waiting card without its entry) is the tests' own:
|
|
243
|
+
`stage_cuts_parity.test.js` runs it after every live event and at each cut, and `stage.spec.js` at each test's end
|
|
244
|
+
(`test.use({ stageCheck: true })`, a fixture in `spec/e2e/support/fixtures.js`, reading the registry off
|
|
245
|
+
`#turnStage.chiWaiting()`). The data-vs-node cross-check (`card_kinds.js warnDiffers`) warns "stage: waiting …":
|
|
246
|
+
`spec/web/public/waiting_warnings.js` (`failOnWaitingWarnings`, called by `stage_view.test.js` and
|
|
247
|
+
`stage_cuts_parity.test.js`; under `npm test`'s one process it covers the files loaded after them too) fails a test
|
|
248
|
+
that warned, and the e2e's stage check fails on such a console warning too.
|
|
244
249
|
`spec/shared/turn_ranges.json` (`UPDATE_TURN_RANGES=1 bundle exec rspec spec/bridge/turn_ranges_spec.rb`) pins
|
|
245
250
|
`Bridge::TurnRanges`' turns, their record pairing, the items as the show stamps them and each turn's drawing end;
|
|
246
251
|
timing.test.js checks `turnGroups` (stamps only) against it. Each scenario's
|
|
@@ -553,14 +558,17 @@ real tasks under each strategy (needs a model; costs tokens): [internals/llm-con
|
|
|
553
558
|
## The stage perf probe
|
|
554
559
|
|
|
555
560
|
`script/stage-perf-probe` (`PROBE_MACHINE=<label>` names the machine; `--keep` leaves its folder, `--headed` shows
|
|
556
|
-
the browser
|
|
561
|
+
the browser, `--reload-check` turns `web.reload_check` on: `reload:compare` times the check's compare, `reload:posted`
|
|
562
|
+
the hand-off to its post, and the posted counts are printed) times the web page's stage on a big session: `script/stage_perf_probe/session.rb` writes 300 finished
|
|
557
563
|
turns with 60 plugin cards and 40 answered questions through chi's own writers (TurnAccumulator's drawings, CardStore,
|
|
558
564
|
`Session#save`; CardStore keeps its cap of 20, the rest are in the drawings), then `probe.js` opens it in chi web
|
|
559
565
|
(the e2e fake model, isolated `HOME` and `XDG_*` under `tmp/stage-probe-*`) at `/?stage_probe=1` (`stage_probe.js`:
|
|
560
566
|
the flag is kept for the tab in sessionStorage, `chi_stage_probe`, so a reload or a hash jump keeps it;
|
|
561
567
|
`?stage_probe=0` drops it; `<body data-stage-probe="1">` works too, for that page only), runs one turn that asks a question and an approval, reloads while the question waits and answers
|
|
562
568
|
both. It prints JSON: `stage:refresh` n/p50/p95/max (ms), the session's open (the hash to the last answer drawn),
|
|
563
|
-
tap→settled per card, reload→card drawn
|
|
569
|
+
tap→settled per card, reload→card drawn, the JS heap after a GC before the open, after it and after the turn, and the
|
|
570
|
+
cards as data (`card_registry.js`): `cards:apply` per card event, `cards:seed` per read, and the registry's entries and
|
|
571
|
+
JSON bytes after the open and after the turn (`globalThis.chiCardRegistry`, only while probing). Its
|
|
564
572
|
`session.drawn` counts what the open drew: all 300 answers and 60 cards, but only the answered questions CardStore
|
|
565
573
|
still lists (8: its cap keeps the newest 20 cards and questions together, and a finished turn's question is drawn from
|
|
566
574
|
that list alone). Bounded:
|
|
@@ -661,3 +669,11 @@ names from elsewhere checked), one-off host pairs (`ToolRun` in `tool_response.r
|
|
|
661
669
|
autoloads that load whole (`SessionManager`, `Objectives`, `Config`), and `Plugin::Http`'s (its base file
|
|
662
670
|
loads the reopening file only inside a method, and that file requires the base file first). The summary counts the entries that
|
|
663
671
|
matched and those that match nothing: delete a stale one.
|
|
672
|
+
|
|
673
|
+
**The thin client load budgets.** `spec/require_cycle_spec.rb` loads the attached TUI's files
|
|
674
|
+
(`terminal_ui/attach_launcher`, `attached_loop`) and chi web's (`web/app`) in a fresh ruby and fails when either
|
|
675
|
+
loads the turn loop (`kernel_loop`), the bundle updater (`memory_bundle/shipped_update`), or a tool that runs:
|
|
676
|
+
`tools/execute`, `tools/builtins`, `tools/task_runtime`. A client that needs a tool's name or result text reads
|
|
677
|
+
`ToolNames`; one that needs a session command's name or the built-ins' registry reads `SessionCommandCatalog`;
|
|
678
|
+
task files and transcripts are `TaskFiles` and `TaskTranscript`. A require that breaks a budget is a sign the
|
|
679
|
+
reader wants one of those, not the class.
|
data/lib/samagotchi/bridge.rb
CHANGED
|
@@ -42,6 +42,7 @@ require_relative "worker_link"
|
|
|
42
42
|
require_relative "relay_verifier"
|
|
43
43
|
require_relative "relay_watcher"
|
|
44
44
|
require_relative "reply_wait"
|
|
45
|
+
require_relative "task_transcript"
|
|
45
46
|
require_relative "tools/task_runtime"
|
|
46
47
|
|
|
47
48
|
module Samagotchi
|
|
@@ -929,9 +930,9 @@ module Samagotchi
|
|
|
929
930
|
# "task_id:" line of its own).
|
|
930
931
|
def own_task_ids
|
|
931
932
|
running = Array(@accumulator.current_turn&.dig(:parts)).filter_map do |part|
|
|
932
|
-
|
|
933
|
+
TaskTranscript.created_id(part[:tool], part[:output]) if part[:kind] == "tool"
|
|
933
934
|
end
|
|
934
|
-
|
|
935
|
+
TaskTranscript.created_ids_in(@engine.messages_checkpoint) | running
|
|
935
936
|
end
|
|
936
937
|
|
|
937
938
|
# Answer the pending question. A past +deadline+ (see #handle_post_turn):
|
|
@@ -17,7 +17,7 @@ require_relative "../../sandbox_layout"
|
|
|
17
17
|
require_relative "../../session"
|
|
18
18
|
require_relative "../../session_manager"
|
|
19
19
|
require_relative "../../tools/task_record"
|
|
20
|
-
require_relative "../../
|
|
20
|
+
require_relative "../../task_files"
|
|
21
21
|
|
|
22
22
|
module Samagotchi
|
|
23
23
|
class BundleCommand
|
|
@@ -194,7 +194,7 @@ module Samagotchi
|
|
|
194
194
|
end
|
|
195
195
|
|
|
196
196
|
def leftover_tasks
|
|
197
|
-
pattern = File.join(work_dir,
|
|
197
|
+
pattern = File.join(work_dir, TaskFiles::TASKS_DIR, "*", TaskFiles::METADATA_FILENAME)
|
|
198
198
|
Dir.glob(pattern).filter_map do |file|
|
|
199
199
|
record = Tools::TaskRecord.from_file(JSON.parse(File.read(file)))
|
|
200
200
|
record.pid if record&.running? && same_process?(record)
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: core
|
|
3
|
-
version: 0.4.
|
|
3
|
+
version: 0.4.4
|
|
4
4
|
scope: system
|
|
5
5
|
description: "Recommended safety set"
|
|
6
6
|
trust_level: reviewed
|
|
7
7
|
# Its members' highest floor (work-cap's: ctx.usage, raised at the release)
|
|
8
|
-
requires_chi: ">= 0.
|
|
8
|
+
requires_chi: ">= 0.173.0"
|
|
9
9
|
includes:
|
|
10
10
|
- loop-guard
|
|
11
11
|
- check-in
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: slow-commands
|
|
3
|
-
version: 0.2.
|
|
3
|
+
version: 0.2.6
|
|
4
4
|
scope: system
|
|
5
5
|
description: "Remembers commands that ran past the execute limit in a project; the next identical execute is denied once a turn with advice to run it with task_create and task_wait; /slow-commands lists and forgets them"
|
|
6
6
|
trust_level: reviewed
|
|
7
7
|
plugin:
|
|
8
8
|
file: plugin.rb
|
|
9
|
-
sha256: sha256:
|
|
9
|
+
sha256: sha256:255bd833b7012f5e6d4597b97e9510f91da61eef13539ba4de2c0baece44964e
|
|
10
10
|
# Execute::HANDED_OVER, read when the plugin loads (0.59.0); after_tool_call's
|
|
11
11
|
# call:, elapsed_ms: and result: (0.57.0)
|
|
12
|
-
requires_chi: ">= 0.
|
|
12
|
+
requires_chi: ">= 0.173.0"
|
|
13
13
|
# config.yml bundles: slow-commands: (another key warns; an older chi ignores this)
|
|
14
14
|
settings: [mode, warn_ratio, ttl_days]
|
|
@@ -67,7 +67,7 @@ require "samagotchi/atomic_file"
|
|
|
67
67
|
require "samagotchi/config"
|
|
68
68
|
require "samagotchi/guardrails/shell_lex"
|
|
69
69
|
require "samagotchi/tools/execute"
|
|
70
|
-
require "samagotchi/
|
|
70
|
+
require "samagotchi/task_files"
|
|
71
71
|
|
|
72
72
|
class Plugin
|
|
73
73
|
SOURCE = "bundle slow-commands"
|
|
@@ -406,7 +406,7 @@ class Plugin
|
|
|
406
406
|
def task_duration(ctx, key)
|
|
407
407
|
roots = [ctx.cwd, project_of(ctx)].uniq
|
|
408
408
|
records = roots.flat_map do |root|
|
|
409
|
-
Dir.glob(File.join(root, Samagotchi::
|
|
409
|
+
Dir.glob(File.join(root, Samagotchi::TaskFiles::TASKS_DIR, "*", "task.json"))
|
|
410
410
|
end.uniq
|
|
411
411
|
found = records.filter_map { |path| finished_task(path, ctx, key) }
|
|
412
412
|
found.max_by(&:first)&.last
|
|
@@ -416,7 +416,7 @@ class Plugin
|
|
|
416
416
|
def finished_task(path, ctx, key)
|
|
417
417
|
record = JSON.parse(File.read(path))
|
|
418
418
|
exit_code = record["exit_code_path"].to_s
|
|
419
|
-
exit_code = File.join(File.dirname(path), Samagotchi::
|
|
419
|
+
exit_code = File.join(File.dirname(path), Samagotchi::TaskFiles::EXIT_CODE_FILENAME) unless File.absolute_path?(exit_code)
|
|
420
420
|
return nil unless File.file?(exit_code) && File.read(exit_code).strip == "0"
|
|
421
421
|
|
|
422
422
|
command = self.class.normalize(record["command"], cwd: record["cwd"], project: key[0], base: ctx.cwd)
|
|
@@ -23,7 +23,7 @@ module Samagotchi
|
|
|
23
23
|
# Whether a participant's pair turn must stop, read before each of its
|
|
24
24
|
# generations (#guard_participant_spend): author ("p:<id>") → why (their
|
|
25
25
|
# link ended, or they passed their cap), nil while it may go on. The
|
|
26
|
-
# Worker sets it (
|
|
26
|
+
# Worker sets it (WorkerParticipantGate#turn_stop); without one (a one-shot)
|
|
27
27
|
# nothing is checked mid-turn.
|
|
28
28
|
attr_writer :participant_stop
|
|
29
29
|
|
|
@@ -34,7 +34,7 @@ module Samagotchi
|
|
|
34
34
|
# plugins' stop path (cost-cap's, work-cap's), with its notice. A
|
|
35
35
|
# generation's own cost is known only once it ends, so a turn can pass
|
|
36
36
|
# the cap by its last generation. The turn-start check is the Worker's
|
|
37
|
-
# (
|
|
37
|
+
# (WorkerParticipantGate#refusal).
|
|
38
38
|
# @param context [TurnContext] the running turn's (the loop's)
|
|
39
39
|
def guard_participant_spend(context)
|
|
40
40
|
author = context&.author
|
data/lib/samagotchi/engine.rb
CHANGED
|
@@ -29,7 +29,6 @@ require_relative "context_window"
|
|
|
29
29
|
require_relative "kernel_loop"
|
|
30
30
|
require_relative "reprefill_meter"
|
|
31
31
|
require_relative "tools/builtins"
|
|
32
|
-
require_relative "tools/task_runtime"
|
|
33
32
|
require_relative "tools/tool_index"
|
|
34
33
|
require_relative "tools/tool_surface"
|
|
35
34
|
require_relative "peer_sources"
|
data/lib/samagotchi/file_ref.rb
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative "
|
|
4
|
-
require_relative "tools/write"
|
|
5
|
-
require_relative "tools/edit"
|
|
3
|
+
require_relative "tool_names"
|
|
6
4
|
|
|
7
5
|
module Samagotchi
|
|
8
6
|
# A ref to the file a read/write/edit call touched, for a UI to trace it
|
|
@@ -20,7 +18,7 @@ module Samagotchi
|
|
|
20
18
|
class FileRef
|
|
21
19
|
KIND = "file"
|
|
22
20
|
|
|
23
|
-
TOOLS = [
|
|
21
|
+
TOOLS = [ToolNames::Read::NAME, ToolNames::Write::NAME, ToolNames::Edit::NAME].freeze
|
|
24
22
|
|
|
25
23
|
# @param cwd [String, nil] the session's working directory; without one
|
|
26
24
|
# a relative path gets no ref (an absolute or ~ path still does)
|
|
@@ -30,7 +28,7 @@ module Samagotchi
|
|
|
30
28
|
def self.for(tool_name, call, cwd:)
|
|
31
29
|
return nil unless TOOLS.include?(tool_name) && call.is_a?(Hash)
|
|
32
30
|
|
|
33
|
-
path = absolute((tool_name ==
|
|
31
|
+
path = absolute((tool_name == ToolNames::Read::NAME ? call[:content] : call[:path]).to_s.strip, cwd)
|
|
34
32
|
return nil unless path
|
|
35
33
|
|
|
36
34
|
line = positive(call[:start_line])
|
|
@@ -8,7 +8,7 @@ module Samagotchi
|
|
|
8
8
|
# participant's turn this chi doesn't run under the owner's rules: no
|
|
9
9
|
# current invite (an older chi's read-only one, no grant at all), a
|
|
10
10
|
# Verify fresh child saved for a read-only turn, or no session. The
|
|
11
|
-
# worker refuses such a turn before it starts (
|
|
11
|
+
# worker refuses such a turn before it starts (WorkerParticipantGate#refusal);
|
|
12
12
|
# this is the fail-closed fallback should one start anyway: every call is
|
|
13
13
|
# denied, nobody is asked. A no-op for the owner's turns.
|
|
14
14
|
class ParticipantRefusal
|
|
@@ -11,6 +11,7 @@ require_relative "working_set"
|
|
|
11
11
|
require_relative "file_ref"
|
|
12
12
|
require_relative "tool_response"
|
|
13
13
|
require_relative "tool_output_cut"
|
|
14
|
+
require_relative "tool_names"
|
|
14
15
|
require_relative "model_overlay"
|
|
15
16
|
require_relative "tools/memory"
|
|
16
17
|
|
|
@@ -38,7 +39,7 @@ module Samagotchi
|
|
|
38
39
|
# The memory scopes, project first, as `chi memory ls` reports them.
|
|
39
40
|
SCOPES = Tools::VALID_SCOPES
|
|
40
41
|
MEMORY_READ = Tools::MemoryRead::NAME
|
|
41
|
-
FILE_READ =
|
|
42
|
+
FILE_READ = ToolNames::Read::NAME
|
|
42
43
|
|
|
43
44
|
# One memory read at least once in the sessions counted: its tokens (the
|
|
44
45
|
# results' size) and reads, +cut_reads+ of them returned a cut result,
|
|
@@ -5,7 +5,8 @@ require_relative "tool_call_parser"
|
|
|
5
5
|
require_relative "tool_activity"
|
|
6
6
|
require_relative "tool_row_fields"
|
|
7
7
|
require_relative "llm/native_tool_normalizer"
|
|
8
|
-
require_relative "
|
|
8
|
+
require_relative "tool_names"
|
|
9
|
+
require_relative "tools/builtin_calls"
|
|
9
10
|
require_relative "image_store"
|
|
10
11
|
require_relative "llm_context_edit"
|
|
11
12
|
require_relative "token_usage"
|
|
@@ -65,14 +66,15 @@ module Samagotchi
|
|
|
65
66
|
|
|
66
67
|
# @param message [Hash] a saved model message (symbol or string keys)
|
|
67
68
|
# @param responses [Array<Hash>] the tool_response messages after it
|
|
68
|
-
# @param registry [Tools::Registry] the session's tools
|
|
69
|
+
# @param registry [Tools::Registry, #[]] the session's tools; the
|
|
70
|
+
# built-ins' names alone by default (ToolNames::BuiltinRegistry)
|
|
69
71
|
# @param cwd [String, nil] the session's working directory (a file
|
|
70
72
|
# tool's title is relative to it)
|
|
71
73
|
# @param marks [Hash{String => Hash}] the session's edit marks by
|
|
72
74
|
# output id (.edit_marks)
|
|
73
75
|
# @return [Hash, nil] { thinking:, tools: [{ tool:, params:, title:,
|
|
74
76
|
# output:, output_truncated:, images:, tool_id:, edit: }] } with only what it found; nil for nothing
|
|
75
|
-
def for_message(message, responses, registry:
|
|
77
|
+
def for_message(message, responses, registry: ToolNames::BuiltinRegistry, cwd: nil, marks: {})
|
|
76
78
|
return nil unless something?(message)
|
|
77
79
|
|
|
78
80
|
content = field(message, :content).to_s
|
|
@@ -3,11 +3,7 @@
|
|
|
3
3
|
require_relative "steer"
|
|
4
4
|
require_relative "tool_activity"
|
|
5
5
|
require_relative "tool_response"
|
|
6
|
-
require_relative "
|
|
7
|
-
require_relative "tools/execute"
|
|
8
|
-
require_relative "tools/objectives_tool"
|
|
9
|
-
require_relative "tools/task_wait"
|
|
10
|
-
require_relative "tools/write"
|
|
6
|
+
require_relative "tool_names"
|
|
11
7
|
|
|
12
8
|
module Samagotchi
|
|
13
9
|
module Objectives
|
|
@@ -37,7 +33,7 @@ module Samagotchi
|
|
|
37
33
|
class Backing
|
|
38
34
|
OK = "ok"
|
|
39
35
|
FAILED = "failed"
|
|
40
|
-
CHANGES = [
|
|
36
|
+
CHANGES = [ToolNames::Edit::NAME, ToolNames::Write::NAME].freeze
|
|
41
37
|
|
|
42
38
|
# +runs+ the move's turn's paired runs before it (LLMContextStale.paired_runs'),
|
|
43
39
|
# in order; +state+ the move's.
|
|
@@ -58,7 +54,7 @@ module Samagotchi
|
|
|
58
54
|
edited_after = false
|
|
59
55
|
end
|
|
60
56
|
end
|
|
61
|
-
unbacked = state ==
|
|
57
|
+
unbacked = state == ToolNames::ObjectivesTool::DONE && !command.nil? && (command == FAILED || edited_after)
|
|
62
58
|
new(edits: edits, command: command, edited_after_command: edited_after, unbacked: unbacked)
|
|
63
59
|
end
|
|
64
60
|
|
|
@@ -79,7 +75,7 @@ module Samagotchi
|
|
|
79
75
|
# an execute that finished ok (a failed, denied, stopped one isn't; one
|
|
80
76
|
# handed over as a task still runs, and isn't either).
|
|
81
77
|
def self.work?(run)
|
|
82
|
-
edit?(run) || (run.call[:name].to_s ==
|
|
78
|
+
edit?(run) || (run.call[:name].to_s == ToolNames::Execute::NAME && command_status(run) == OK)
|
|
83
79
|
end
|
|
84
80
|
|
|
85
81
|
def self.edit?(run)
|
|
@@ -95,12 +91,12 @@ module Samagotchi
|
|
|
95
91
|
# a waiting message) or that waited on nothing (an Error:).
|
|
96
92
|
def self.command_status(run)
|
|
97
93
|
name = run.call[:name].to_s
|
|
98
|
-
return nil unless [
|
|
94
|
+
return nil unless [ToolNames::Execute::NAME, ToolNames::TaskWait::NAME].include?(name)
|
|
99
95
|
return nil if ToolResponse.interrupted_text?(run.text)
|
|
100
96
|
|
|
101
97
|
text = ToolActivity.saved_result_text(run.text)
|
|
102
98
|
return nil if ToolActivity.guardrail_denied?(text)
|
|
103
|
-
return task_status(text) if name ==
|
|
99
|
+
return task_status(text) if name == ToolNames::TaskWait::NAME
|
|
104
100
|
return nil if ToolActivity.handed_over?(name, text)
|
|
105
101
|
|
|
106
102
|
case ToolActivity.tool_activity_status(text, name, command: run.call[:content])
|
|
@@ -76,7 +76,7 @@ module Samagotchi
|
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
# The reasons a worker refuses a participant's queued turn
|
|
79
|
-
# (
|
|
79
|
+
# (WorkerParticipantGate#refusal), as its settled record's cancel_reason.
|
|
80
80
|
REFUSED_LINES = { "revoked" => ParticipantMessages::TOKEN_ENDED,
|
|
81
81
|
"outdated" => ParticipantMessages::TOKEN_OUTDATED,
|
|
82
82
|
"cap_reached" => ParticipantMessages::CAP_REACHED }.freeze
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require_relative "atomic_file"
|
|
5
|
+
require_relative "grants"
|
|
6
|
+
require_relative "log"
|
|
7
|
+
require_relative "prompt_history"
|
|
8
|
+
|
|
9
|
+
module Samagotchi
|
|
10
|
+
# Each participant's own prompts in one session, the list their
|
|
11
|
+
# composer's ↑/↓ walks (chi web's ParticipantHistory serves it, redacted,
|
|
12
|
+
# to that grant only). Written by chi web when it accepts a participant's
|
|
13
|
+
# turn, never derived from a message, a body field or an author the page
|
|
14
|
+
# sends; the owner's PromptHistory (the machine-wide file) is never
|
|
15
|
+
# written or read for a participant.
|
|
16
|
+
#
|
|
17
|
+
# participant_prompts.json in the session folder (beside
|
|
18
|
+
# participants.json, not in images/), 0600, written whole (AtomicFile):
|
|
19
|
+
# {prompts: {<grant id>: [text, …]}}, oldest first. At most LIMIT per
|
|
20
|
+
# grant; a text over MAX_ENTRY_BYTES isn't recorded (a cut prompt
|
|
21
|
+
# recalled and re-sent would be another message). Keys are grant ids
|
|
22
|
+
# (Grants::ID_RE) still known to the grants store: an append drops the
|
|
23
|
+
# others. A file that doesn't read is never written over (Log.warn) and
|
|
24
|
+
# reads as no entries; the owner can delete it. Callers serialize
|
|
25
|
+
# read-then-write themselves (chi web's @participant_prompts_mutex).
|
|
26
|
+
# See docs/internals/participants.md.
|
|
27
|
+
module ParticipantPrompts
|
|
28
|
+
FILE = "participant_prompts.json"
|
|
29
|
+
LIMIT = PromptHistory::LIMIT
|
|
30
|
+
MAX_ENTRY_BYTES = 16 * 1024
|
|
31
|
+
|
|
32
|
+
# What the file holds: +prompts+ grant id => [String] (only ID_RE keys,
|
|
33
|
+
# only String entries); +broken+ when it doesn't read.
|
|
34
|
+
State = Data.define(:prompts, :broken)
|
|
35
|
+
BROKEN = State.new(prompts: {}.freeze, broken: true)
|
|
36
|
+
|
|
37
|
+
module_function
|
|
38
|
+
|
|
39
|
+
# @return [State]
|
|
40
|
+
def read(dir)
|
|
41
|
+
path = File.join(dir, FILE)
|
|
42
|
+
return State.new(prompts: {}, broken: false) unless File.exist?(path)
|
|
43
|
+
|
|
44
|
+
data = JSON.parse(File.read(path))
|
|
45
|
+
raise TypeError, "not an object" unless data.is_a?(Hash)
|
|
46
|
+
|
|
47
|
+
prompts = data.fetch("prompts", {})
|
|
48
|
+
raise TypeError, "prompts not an object" unless prompts.is_a?(Hash)
|
|
49
|
+
|
|
50
|
+
kept = prompts.each_with_object({}) do |(grant_id, list), out|
|
|
51
|
+
next unless grant_id?(grant_id)
|
|
52
|
+
|
|
53
|
+
out[grant_id] = list.is_a?(Array) ? list.grep(String) : []
|
|
54
|
+
end
|
|
55
|
+
State.new(prompts: kept, broken: false)
|
|
56
|
+
rescue JSON::ParserError, SystemCallError, TypeError => e
|
|
57
|
+
Log.warn(:web, "participant_prompts_unreadable", file: path, msg: e.message)
|
|
58
|
+
BROKEN
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# +grant_id+'s prompts, oldest first: a new array of theirs only; []
|
|
62
|
+
# for an unknown grant, a bad id or a broken file.
|
|
63
|
+
# @return [Array<String>]
|
|
64
|
+
def entries(dir, grant_id)
|
|
65
|
+
return [] unless grant_id?(grant_id)
|
|
66
|
+
|
|
67
|
+
read(dir).prompts.fetch(grant_id, []).dup
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# The text as it would be kept (PromptHistory.normalize's), nil when it
|
|
71
|
+
# isn't kept: empty, or over MAX_ENTRY_BYTES.
|
|
72
|
+
# @return [String, nil]
|
|
73
|
+
def recordable(text)
|
|
74
|
+
line = PromptHistory.normalize([text]).first
|
|
75
|
+
line if line && line.bytesize <= MAX_ENTRY_BYTES
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Records +text+ as +grant_id+'s newest prompt, keeping its last LIMIT;
|
|
79
|
+
# the lists of grants not in +live_grant_ids+ are dropped. A broken
|
|
80
|
+
# file, a bad grant id or a text #recordable refuses writes nothing.
|
|
81
|
+
# @param live_grant_ids [Array<String>] the session's grants the grants
|
|
82
|
+
# store still knows (active or not yet swept)
|
|
83
|
+
# @return [Boolean] whether it was recorded
|
|
84
|
+
def append(dir, grant_id:, text:, live_grant_ids:)
|
|
85
|
+
return false unless grant_id?(grant_id)
|
|
86
|
+
|
|
87
|
+
line = recordable(text) or return false
|
|
88
|
+
state = read(dir)
|
|
89
|
+
return false if state.broken
|
|
90
|
+
|
|
91
|
+
live = Array(live_grant_ids) | [grant_id]
|
|
92
|
+
prompts = state.prompts.slice(*live)
|
|
93
|
+
prompts[grant_id] = (prompts.fetch(grant_id, []) + [line]).last(LIMIT)
|
|
94
|
+
body = { "prompts" => prompts }
|
|
95
|
+
AtomicFile.write(File.join(dir, FILE), "#{JSON.pretty_generate(body)}\n", perm: 0o600)
|
|
96
|
+
true
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def grant_id?(grant_id) = grant_id.is_a?(String) && Grants::ID_RE.match?(grant_id)
|
|
100
|
+
end
|
|
101
|
+
end
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
module Samagotchi
|
|
4
4
|
# Whether a participant's turn runs here, and why not: the one decision
|
|
5
|
-
# the worker (
|
|
5
|
+
# the worker (WorkerParticipantGate#refusal, before the turn starts and
|
|
6
6
|
# before each of its generations) and the guardrails
|
|
7
7
|
# (GuardrailWiring#participant_turn_mode, the turn's mode) both take.
|
|
8
8
|
# :pair — it runs, under the owner's guardrails (PairBoundary);
|
|
@@ -63,7 +63,7 @@ module Samagotchi
|
|
|
63
63
|
# would trust, and remember, an untrusted repo's mise.toml); CI too.
|
|
64
64
|
MISE_UNSET = %w[MISE_YES CI].freeze
|
|
65
65
|
TIMEOUT = 5
|
|
66
|
-
# What execute and tasks set themselves (
|
|
66
|
+
# What execute and tasks set themselves (SpawnEnv's
|
|
67
67
|
# sanitized env): never taken from the project's.
|
|
68
68
|
TOOLS_DROP = BundlerEnv::CHILD_RUBY
|
|
69
69
|
|
|
@@ -111,20 +111,22 @@ module Samagotchi
|
|
|
111
111
|
def install!(overlay) = @current = overlay
|
|
112
112
|
|
|
113
113
|
# #current's env for a tool's spawn, less what every tool runs without
|
|
114
|
-
# (
|
|
114
|
+
# (SpawnEnv::SANITIZED_ENV_KEYS: RUBYOPT, RUBYLIB, Bundler's).
|
|
115
115
|
# @return [Hash{String=>String, nil}]
|
|
116
116
|
def tools_env = current.env.except(*TOOLS_DROP)
|
|
117
117
|
|
|
118
118
|
# The whole env change for a command chi starts for the session outside
|
|
119
119
|
# execute (MCP servers, context sources): what execute spawns over
|
|
120
|
-
# (
|
|
120
|
+
# (SpawnEnv.sanitized_spawn_env: chi's own RUBYOPT without
|
|
121
121
|
# bundler/setup, no RUBYLIB or Bundler variables), then #tools_env. One
|
|
122
122
|
# env for every command, so a worker run from a checkout under `bundle
|
|
123
123
|
# exec` hands none of them its Gemfile.
|
|
124
124
|
# @return [Hash{String=>String, nil}]
|
|
125
125
|
def spawn_env
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
# Lazily: bin/chi loads this file for #take_orig!, and spawn_env's
|
|
127
|
+
# child_env requires this file.
|
|
128
|
+
require_relative "spawn_env"
|
|
129
|
+
SpawnEnv.sanitized_spawn_env.merge(tools_env)
|
|
128
130
|
end
|
|
129
131
|
|
|
130
132
|
# Specs: back to NONE.
|
|
@@ -6,7 +6,7 @@ require "fileutils"
|
|
|
6
6
|
require_relative "atomic_file"
|
|
7
7
|
require_relative "config"
|
|
8
8
|
require_relative "paths"
|
|
9
|
-
require_relative "
|
|
9
|
+
require_relative "session_command_catalog"
|
|
10
10
|
|
|
11
11
|
module Samagotchi
|
|
12
12
|
# The prompts typed at a chi prompt, kept for ↑ across launches: one
|
|
@@ -81,7 +81,7 @@ module Samagotchi
|
|
|
81
81
|
|
|
82
82
|
# A `!command` worth recalling; `!rollback` isn't one.
|
|
83
83
|
def shell_line?(line)
|
|
84
|
-
line.to_s.start_with?(
|
|
84
|
+
line.to_s.start_with?(SessionCommandCatalog::SHELL_BANG_PREFIX) && line.to_s.strip != SessionCommandCatalog::ROLLBACK_COMMAND
|
|
85
85
|
end
|
|
86
86
|
|
|
87
87
|
def normalize(list)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "../session"
|
|
4
4
|
require_relative "../session_chain"
|
|
5
|
-
require_relative "../
|
|
5
|
+
require_relative "../session_command_catalog"
|
|
6
6
|
require_relative "../parent_answers_command"
|
|
7
7
|
require_relative "../turn_flow"
|
|
8
8
|
require_relative "../guardrails/parent_approvals"
|
|
@@ -49,7 +49,7 @@ module Samagotchi
|
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
# Whether +prompt+ is a /parent-answers line.
|
|
52
|
-
def self.parent_answers_line?(prompt) =
|
|
52
|
+
def self.parent_answers_line?(prompt) = SessionCommandCatalog.builtin_registry.lookup(prompt)&.id == :parent_answers
|
|
53
53
|
|
|
54
54
|
# Whether +prompt+ is a /parent-answers line that loosens one of
|
|
55
55
|
# +values+ (targets' own parent_answers).
|
|
@@ -5,7 +5,7 @@ require_relative "delivery"
|
|
|
5
5
|
require_relative "terminal_ui/formatting"
|
|
6
6
|
require_relative "session"
|
|
7
7
|
require_relative "worker_link"
|
|
8
|
-
require_relative "
|
|
8
|
+
require_relative "session_command_catalog"
|
|
9
9
|
require_relative "parent_answers_command"
|
|
10
10
|
require_relative "session_inbox"
|
|
11
11
|
require_relative "session_manager"
|
|
@@ -734,8 +734,8 @@ module Samagotchi
|
|
|
734
734
|
# (a bundle's too).
|
|
735
735
|
def command_like?(text) = text.to_s.lstrip.start_with?("/", "!")
|
|
736
736
|
|
|
737
|
-
# @return [Commands::Registry::Entry, nil]
|
|
738
|
-
def local_command(text) =
|
|
737
|
+
# @return [Commands::Registry::Entry, nil] SessionCommandCatalog.ui_only_entry
|
|
738
|
+
def local_command(text) = SessionCommandCatalog.ui_only_entry(text)
|
|
739
739
|
|
|
740
740
|
# A UI-only command: nothing is sent (with --new, no session is created
|
|
741
741
|
# either). /stats points at its model-free reader and names the session;
|
|
@@ -761,7 +761,7 @@ module Samagotchi
|
|
|
761
761
|
CLI::Exit::FAILED
|
|
762
762
|
end
|
|
763
763
|
|
|
764
|
-
def local_refusal(name, id) =
|
|
764
|
+
def local_refusal(name, id) = SessionCommandCatalog.ui_only_refusal(name, id, runner: "chi send", remote: @access.invocation.remote)
|
|
765
765
|
|
|
766
766
|
# --wait after a message that ran as a session command: no reply comes
|
|
767
767
|
# for it. Its output shows where the session is open.
|