samagotchi 0.171.0 → 0.172.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 +33 -1
- data/bin/chi +6 -4
- data/docs/architecture.md +24 -7
- data/docs/bundles.md +4 -21
- data/docs/cli.md +50 -80
- data/docs/configuration.md +11 -13
- data/docs/context.md +5 -6
- data/docs/guardrails.md +57 -96
- data/docs/hooks.md +3 -4
- data/docs/internals/attached-context.md +6 -7
- data/docs/internals/background-tasks.md +4 -3
- data/docs/internals/bridge.md +29 -3
- data/docs/internals/engine.md +21 -9
- data/docs/internals/objectives.md +3 -5
- data/docs/internals/participants.md +118 -143
- data/docs/internals/prompt-caching.md +4 -5
- data/docs/internals/web-frontend.md +33 -14
- data/docs/internals/working-set.md +7 -5
- data/docs/memory.md +1 -1
- data/docs/plugins.md +2 -16
- data/docs/scheduling.md +1 -1
- data/docs/sessions.md +15 -49
- data/docs/sub-agent.md +2 -2
- data/docs/system-one.md +2 -2
- data/docs/testing.md +56 -7
- data/lib/samagotchi/bridge/card_store.rb +1 -0
- data/lib/samagotchi/bridge/sse_writer.rb +1 -0
- data/lib/samagotchi/bridge/turn_accumulator.rb +0 -1
- data/lib/samagotchi/bridge.rb +26 -9
- data/lib/samagotchi/bridge_client/event_stream.rb +2 -0
- data/lib/samagotchi/bundle_command/test_run.rb +1 -0
- data/lib/samagotchi/bundle_command/try/run.rb +1 -0
- data/lib/samagotchi/bundles/coordinator/manifest.yml +4 -5
- data/lib/samagotchi/bundles/coordinator/plugin.rb +6 -79
- data/lib/samagotchi/bundles/coordinator/skill_coordinator.md +1 -16
- data/lib/samagotchi/bundles/github-pr/manifest.yml +2 -2
- data/lib/samagotchi/bundles/github-pr/plugin.rb +0 -1
- data/lib/samagotchi/bundles/inline-widgets/manifest.yml +2 -2
- data/lib/samagotchi/bundles/inline-widgets/plugin.rb +4 -5
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/client_id.rb +126 -67
- data/lib/samagotchi/command_intake.rb +15 -3
- data/lib/samagotchi/compat.rb +6 -1
- data/lib/samagotchi/context_candidate_choice.rb +1 -3
- data/lib/samagotchi/context_candidates.rb +3 -4
- data/lib/samagotchi/continue_offer.rb +9 -2
- data/lib/samagotchi/delivery.rb +23 -12
- data/lib/samagotchi/empty_answer_error.rb +5 -0
- data/lib/samagotchi/engine/cards.rb +3 -0
- data/lib/samagotchi/engine/context_judge.rb +5 -3
- data/lib/samagotchi/engine/events.rb +4 -0
- data/lib/samagotchi/engine/hooks.rb +3 -0
- data/lib/samagotchi/engine/messages.rb +5 -0
- data/lib/samagotchi/engine/model_settings.rb +2 -0
- data/lib/samagotchi/engine/models.rb +10 -0
- data/lib/samagotchi/engine/objectives.rb +6 -0
- data/lib/samagotchi/engine/participants.rb +18 -14
- data/lib/samagotchi/engine/plugins.rb +8 -0
- data/lib/samagotchi/engine/questions.rb +3 -0
- data/lib/samagotchi/engine/recap.rb +1 -0
- data/lib/samagotchi/engine/session.rb +4 -0
- data/lib/samagotchi/engine/side_requests.rb +9 -0
- data/lib/samagotchi/engine/steering.rb +2 -0
- data/lib/samagotchi/engine/toolkit.rb +5 -0
- data/lib/samagotchi/engine/turn_end.rb +7 -0
- data/lib/samagotchi/engine/turn_helpers.rb +8 -0
- data/lib/samagotchi/engine/verify.rb +2 -0
- data/lib/samagotchi/engine.rb +3 -2
- data/lib/samagotchi/grants.rb +28 -22
- data/lib/samagotchi/guardrail_wiring.rb +23 -18
- data/lib/samagotchi/guardrails/approval_use.rb +59 -0
- data/lib/samagotchi/guardrails/approvals.rb +9 -11
- data/lib/samagotchi/guardrails/child_boundary.rb +1 -0
- data/lib/samagotchi/guardrails/gate.rb +10 -5
- data/lib/samagotchi/guardrails/implicit_writers.rb +1 -0
- data/lib/samagotchi/guardrails/pair_boundary.rb +6 -6
- data/lib/samagotchi/guardrails/participant_refusal.rb +33 -0
- data/lib/samagotchi/guardrails/review_paths.rb +2 -3
- data/lib/samagotchi/guardrails.rb +1 -1
- data/lib/samagotchi/llm_context_strategy.rb +2 -0
- data/lib/samagotchi/objectives.rb +1 -4
- data/lib/samagotchi/objectives_audit.rb +1 -1
- data/lib/samagotchi/objectives_track.rb +1 -1
- data/lib/samagotchi/owner_prompt.rb +3 -6
- data/lib/samagotchi/parent_report.rb +1 -0
- data/lib/samagotchi/participant_messages.rb +9 -4
- data/lib/samagotchi/participant_turn_mode.rb +50 -0
- data/lib/samagotchi/participants.rb +21 -12
- data/lib/samagotchi/participants_watch.rb +2 -2
- data/lib/samagotchi/plugin/api.rb +2 -2
- data/lib/samagotchi/plugin/attached_context.rb +1 -1
- data/lib/samagotchi/plugin/context.rb +0 -4
- data/lib/samagotchi/plugin/sessions.rb +1 -25
- data/lib/samagotchi/run_options.rb +2 -3
- data/lib/samagotchi/send_command.rb +10 -10
- data/lib/samagotchi/session.rb +0 -3
- data/lib/samagotchi/session_access/contract.rb +1 -10
- data/lib/samagotchi/session_access/local.rb +10 -23
- data/lib/samagotchi/session_access/remote.rb +9 -20
- data/lib/samagotchi/session_access.rb +12 -16
- data/lib/samagotchi/session_chain.rb +4 -6
- data/lib/samagotchi/session_commands.rb +6 -3
- data/lib/samagotchi/session_continue.rb +1 -2
- data/lib/samagotchi/session_manager/delivery.rb +25 -5
- data/lib/samagotchi/session_manager/lifecycle.rb +12 -0
- data/lib/samagotchi/session_manager/listing.rb +5 -0
- data/lib/samagotchi/session_manager/spawn.rb +2 -2
- data/lib/samagotchi/session_manager/worker_command.rb +9 -0
- data/lib/samagotchi/session_participants.rb +12 -8
- data/lib/samagotchi/session_review.rb +5 -7
- data/lib/samagotchi/session_stores.rb +3 -3
- data/lib/samagotchi/share_command.rb +10 -12
- data/lib/samagotchi/share_terms.rb +41 -0
- data/lib/samagotchi/steer.rb +8 -14
- data/lib/samagotchi/system_prompt.rb +16 -25
- data/lib/samagotchi/terminal_ui/attach_launcher.rb +2 -1
- data/lib/samagotchi/terminal_ui/attached_loop/exit_commands.rb +1 -0
- data/lib/samagotchi/terminal_ui/attached_loop/queueing.rb +1 -0
- data/lib/samagotchi/terminal_ui/attached_loop/sending.rb +2 -0
- data/lib/samagotchi/terminal_ui/formatting.rb +15 -17
- data/lib/samagotchi/terminal_ui/participant_commands.rb +2 -2
- data/lib/samagotchi/terminal_ui/status_row.rb +2 -2
- data/lib/samagotchi/terminal_ui.rb +1 -2
- data/lib/samagotchi/testing/sessions.rb +2 -10
- data/lib/samagotchi/tool_runner.rb +8 -9
- data/lib/samagotchi/toolkit.rb +4 -22
- data/lib/samagotchi/toolkit_suggest.rb +3 -3
- data/lib/samagotchi/tools/deferred_tools.rb +1 -0
- data/lib/samagotchi/tools/execute.rb +11 -45
- data/lib/samagotchi/tools/leftovers.rb +122 -0
- data/lib/samagotchi/tools/memory.rb +70 -26
- data/lib/samagotchi/tools/task_get.rb +1 -0
- data/lib/samagotchi/tools/task_list.rb +3 -2
- data/lib/samagotchi/tools/task_record.rb +6 -4
- data/lib/samagotchi/tools/task_runtime.rb +199 -20
- data/lib/samagotchi/tools/task_wait.rb +4 -3
- data/lib/samagotchi/turn_context.rb +1 -1
- data/lib/samagotchi/turn_origin.rb +1 -1
- data/lib/samagotchi/turn_stages/context_judge.rb +4 -4
- data/lib/samagotchi/turn_stages/objectives.rb +2 -2
- data/lib/samagotchi/turn_stages/toolkit_suggestion.rb +2 -2
- data/lib/samagotchi/update_hint.rb +3 -1
- data/lib/samagotchi/verify_fresh.rb +1 -1
- data/lib/samagotchi/verify_fresh_origin.rb +13 -11
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +3 -5
- data/lib/samagotchi/web/participant_access.rb +14 -18
- data/lib/samagotchi/web/participant_review.rb +3 -4
- data/lib/samagotchi/web/participant_show.rb +4 -3
- data/lib/samagotchi/web/participant_view.rb +3 -3
- data/lib/samagotchi/web/participants_admin.rb +21 -40
- data/lib/samagotchi/web/public/app.js +5 -47
- data/lib/samagotchi/web/public/data.js +2 -10
- data/lib/samagotchi/web/public/delivery_line.js +17 -60
- data/lib/samagotchi/web/public/index.html +10 -30
- data/lib/samagotchi/web/public/live_turn.js +1 -1
- data/lib/samagotchi/web/public/owner_claim.js +2 -2
- data/lib/samagotchi/web/public/participant_bar.js +4 -5
- data/lib/samagotchi/web/public/participant_names.js +14 -10
- data/lib/samagotchi/web/public/participants_panel.js +29 -62
- data/lib/samagotchi/web/public/reload_check.js +2 -3
- data/lib/samagotchi/web/public/send_turn.js +4 -23
- data/lib/samagotchi/web/public/session_actions.js +4 -45
- data/lib/samagotchi/web/public/session_fields.js +0 -1
- data/lib/samagotchi/web/public/session_state.js +0 -3
- data/lib/samagotchi/web/public/session_view.js +2 -3
- data/lib/samagotchi/web/public/settings_panel.js +4 -18
- data/lib/samagotchi/web/public/stage_answer.js +56 -0
- data/lib/samagotchi/web/public/stage_asking.js +1 -1
- data/lib/samagotchi/web/public/stage_cloud.js +93 -0
- data/lib/samagotchi/web/public/stage_dom.js +100 -0
- data/lib/samagotchi/web/public/stage_handoff.js +154 -0
- data/lib/samagotchi/web/public/stage_pager.js +59 -0
- data/lib/samagotchi/web/public/stage_quiet_clock.js +52 -0
- data/lib/samagotchi/web/public/stage_view.js +90 -411
- data/lib/samagotchi/web/public/start_page.js +12 -33
- data/lib/samagotchi/web/public/start_settings.js +24 -78
- data/lib/samagotchi/web/public/start_toolkit.js +6 -10
- data/lib/samagotchi/web/public/stream_handlers.js +1 -9
- data/lib/samagotchi/web/public/turn_block.js +3 -7
- data/lib/samagotchi/web/public/turn_events.js +15 -6
- data/lib/samagotchi/web/public/turn_pieces.js +3 -4
- data/lib/samagotchi/web/public/viewer_self.js +8 -2
- data/lib/samagotchi/web/qr.rb +1 -1
- data/lib/samagotchi/web/session_control.rb +3 -1
- data/lib/samagotchi/web/session_create.rb +5 -71
- data/lib/samagotchi/web/session_summary.rb +1 -4
- data/lib/samagotchi/web/verify_fresh_routes.rb +8 -7
- data/lib/samagotchi/web/viewer.rb +3 -3
- data/lib/samagotchi/worker.rb +16 -14
- data/lib/samagotchi/worker_inbound.rb +4 -3
- data/lib/samagotchi/worker_link.rb +17 -0
- data/lib/samagotchi/working_set.rb +87 -28
- metadata +13 -8
- data/lib/samagotchi/guardrails/review_boundary.rb +0 -99
- data/lib/samagotchi/participant_mode.rb +0 -86
- data/lib/samagotchi/review_apply.rb +0 -131
- data/lib/samagotchi/review_command.rb +0 -123
- data/lib/samagotchi/review_start.rb +0 -196
- data/lib/samagotchi/web/public/review_apply.js +0 -34
- data/lib/samagotchi/web/public/review_start.js +0 -55
data/docs/context.md
CHANGED
|
@@ -361,7 +361,7 @@ text. The source itself stays with its old link; forks do not carry this text.
|
|
|
361
361
|
`chi send --new --continues` and the web's Continue toast say the same in a
|
|
362
362
|
few words, and `chi context ls` marks a session's source that stays
|
|
363
363
|
(`· stays`; `--format json` has the derived `movable`). Project sources are
|
|
364
|
-
shared already, and a
|
|
364
|
+
shared already, and a delegate takes none.
|
|
365
365
|
|
|
366
366
|
A push into a continued session is refused, nothing written, with the next
|
|
367
367
|
link's id (`chi context push` exits 1; chi web answers 410
|
|
@@ -413,7 +413,7 @@ How a mention counts:
|
|
|
413
413
|
- nothing inside a fenced code block: a pasted log's `#412` isn't you asking.
|
|
414
414
|
|
|
415
415
|
Only the session's owner counts: a participant's message, a steer, a note or
|
|
416
|
-
a reminder never attaches anything
|
|
416
|
+
a reminder never attaches anything.
|
|
417
417
|
A bundle usually proposes from an init task that finishes while your first
|
|
418
418
|
turn runs; when it does, the prompts you already wrote count too, and a hit
|
|
419
419
|
is attached at once (its note comes with your next turn).
|
|
@@ -433,8 +433,7 @@ candidates (attached when the session's owner mentions one):
|
|
|
433
433
|
|
|
434
434
|
You can also choose yourself: `/context attach NAME` attaches a proposed
|
|
435
435
|
candidate (its why: "you attached it"), `/context decline NAME` declines it.
|
|
436
|
-
Both are the session owner's (a participant can't send a `/` line,
|
|
437
|
-
review session refuses them); an unknown name, or one attached or declined
|
|
436
|
+
Both are the session owner's (a participant can't send a `/` line); an unknown name, or one attached or declined
|
|
438
437
|
already, is an error that says so. They are what the judge's card's buttons
|
|
439
438
|
run (see [On mode](#on-mode)).
|
|
440
439
|
|
|
@@ -465,7 +464,7 @@ context:
|
|
|
465
464
|
What it asks, and when:
|
|
466
465
|
|
|
467
466
|
- **One ask per candidate**, at the start of each of your own turns (never a
|
|
468
|
-
participant's, never
|
|
467
|
+
participant's, never on a Continue), after the
|
|
469
468
|
toolkit suggestion. A candidate proposed while your turn runs (github-pr's
|
|
470
469
|
usual case) is asked about right then, on your prompts so far.
|
|
471
470
|
- **What it sees:** the candidate's title (and description, when the bundle
|
|
@@ -556,7 +555,7 @@ It needs [`gh`](https://cli.github.com), logged in (`gh auth login`).
|
|
|
556
555
|
"#42 <the PR's title>": nothing reaches the agent until you mention it
|
|
557
556
|
in a prompt (`#42`, the branch's name, or the PR's URL). Then it is
|
|
558
557
|
attached in that same turn ("Why: you mentioned #42"). Not in a `chi
|
|
559
|
-
scratch` session
|
|
558
|
+
scratch` session, and quietly nothing without `gh`, a
|
|
560
559
|
login, a repository or an open PR. A delegate child gets the proposal too
|
|
561
560
|
(its task may name the PR). At a turn's start more than 5 minutes after
|
|
562
561
|
its last look, the bundle looks again, beside the turn (a branch switched
|
data/docs/guardrails.md
CHANGED
|
@@ -13,8 +13,8 @@ Who votes, in order:
|
|
|
13
13
|
|
|
14
14
|
1. `before_tool_call` hooks (Ruby; see [Hooks](hooks.md#guardrails-from-a-hook)).
|
|
15
15
|
2. Core checks (`GuardrailWiring#checks`): a required guardrail that failed to load, then (a participant's turn only)
|
|
16
|
-
[the
|
|
17
|
-
[the
|
|
16
|
+
[the pair boundary](#a-participants-pair-boundary) (or, for a turn this chi doesn't run under the owner's rules,
|
|
17
|
+
[the refusal seat](#a-participants-turn-without-a-current-invite)), then protected paths, then (a `chi scratch` session only)
|
|
18
18
|
writes to the memories folder (rule `scratch-session`), then (a delegate child only)
|
|
19
19
|
[the child boundary](#a-delegate-childs-boundary).
|
|
20
20
|
3. YAML rules: `config.yml`'s `guardrails:` section, then installed bundles' rule files (by bundle name).
|
|
@@ -114,6 +114,11 @@ answers it, since it is keyed on the whole command you saw: `git branch -D x &&
|
|
|
114
114
|
once, session and repo, while `git merge y && git push` offers once, as `git-merge` offers only once and its rule.
|
|
115
115
|
Two rules with one id (a config.yml copy of a bundle's rule) are one rule; a core ask followed by a rule's (the
|
|
116
116
|
[child boundary's](#a-delegate-childs-boundary)) keeps its own scopes.
|
|
117
|
+
|
|
118
|
+
Which stored approvals an ask may use is decided in one place, `Guardrails::ApprovalUse` (before `Gate#settle_ask`
|
|
119
|
+
looks in the store): an owner's ask uses every scope; a [participant's turn](#a-participants-pair-boundary) and a
|
|
120
|
+
[delegate child's boundary](#a-delegate-childs-boundary) use only this session's own `session` entries; a fresh ask
|
|
121
|
+
(`Verdict#fresh_ask`) uses none.
|
|
117
122
|
The file is a versioned store (`{"version": 1, "approvals": [...]}`, `Approvals::FORMAT`); a write keeps its version,
|
|
118
123
|
the keys this chi doesn't know and an entry with no `scope`. A bare list of entries, as chi 0.166 and before wrote it,
|
|
119
124
|
is read and converted to a versioned store on the next write. Chi 0.165 and before set a versioned store aside, so restart their sessions
|
|
@@ -305,16 +310,20 @@ sub-agent](sub-agent.md)) tell them to use `chi answer` only.
|
|
|
305
310
|
|
|
306
311
|
A message that is a session command (`/model x`, `!cmd`, `!rollback`) runs as the command only when a person sends
|
|
307
312
|
it: a web tab, an attached chi TUI, `chi send` (yours, or one a model runs from `execute`: the trust model above), a
|
|
308
|
-
|
|
313
|
+
session's own first prompt, and `chi answer`'s lines (`cli:answer`: a parent agent's `/continue yes` and
|
|
309
314
|
`/parent-answers`), which may send any session command, with the same trust as `chi send`.
|
|
310
315
|
`!cmd` runs its shell line with no rule or ask (it is yours), so from anyone else it is refused: a delegating parent's
|
|
311
316
|
task or follow-up, a schedule's firing (both modes), a plugin's message, a context or task wake. Chi web's Bridge answers
|
|
312
317
|
`403 command_not_permitted` with one message, an input file's line shows as the command's error, and nothing runs.
|
|
313
318
|
Their `/word` line is plain text: the model reads it. `delegate`, `schedule_task` and `chi schedule add` refuse a task
|
|
314
319
|
or prompt that starts with `!` with the same message, so the model can rewrite it. A participant's command is refused
|
|
315
|
-
as before ([their
|
|
316
|
-
|
|
317
|
-
`
|
|
320
|
+
as before ([their boundary](#a-participants-pair-boundary)). A message that names no sender (an input file from an
|
|
321
|
+
older chi, a Bridge `POST /turn` without `client_id`) is nobody's: its `/word` line is text, its `!` line refused
|
|
322
|
+
(`ClientId::NONE` is never the owner's). The rule is `CommandIntake` (`lib/samagotchi/command_intake.rb`, on
|
|
323
|
+
`ClientId.owner?`), asked by `Bridge#handle_post_turn`, `WorkerInbound#queue_as_command` and `Bridge#handle_command`
|
|
324
|
+
(`POST /command`, a UI's or a card's explicit command line): that route must name its sender (without `client_id` 400
|
|
325
|
+
`missing_client_id`), and from any other sender (a participant, a delegate, a plugin, an unknown id) it answers 403
|
|
326
|
+
`command_not_permitted` (`CommandIntake::COMMAND_REFUSED`; a `!` line's is `REFUSED`) and runs nothing.
|
|
318
327
|
|
|
319
328
|
## Protected paths
|
|
320
329
|
|
|
@@ -373,83 +382,42 @@ under its own `env:` (its `$TMPDIR`, `$HOME`, `GIT_DIR`, …): either one naming
|
|
|
373
382
|
redefines the shell (`BASH_ENV`, `BASH_FUNC_cat%%`, `CDPATH`, …, as under `skip_read_only` below) always asks, even
|
|
374
383
|
for `cat a.txt` in the child's own folder: what it runs is in no word of the command. The answer is once or for the child's
|
|
375
384
|
session only: a repo or rule answer would hold in every worktree, for every
|
|
376
|
-
child, so a stored repo or rule approval doesn't let it through either. Its
|
|
385
|
+
child, so a stored repo or rule approval doesn't let it through either (`ApprovalUse::SESSION_ONLY_RULES`). Its
|
|
377
386
|
ask goes before the rules, so with the guardrails bundle in strict mode the
|
|
378
387
|
card still names `child-boundary`. The parent (never a delegate), forks and
|
|
379
388
|
ordinary sessions don't get it. Like the rules it reads command text: a
|
|
380
389
|
`sh -c` body, a script or `$(…)` isn't looked into.
|
|
381
390
|
|
|
382
|
-
## A participant's
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
`Guardrails::
|
|
391
|
-
|
|
392
|
-
protected paths and the rules (`GuardrailWiring#checks`; a deny is sticky, so no later vote turns it into a
|
|
393
|
-
question), and it
|
|
394
|
-
**denies, never asks**: nobody on the participant's side may approve, and the
|
|
395
|
-
owner's approval would give the participant's text the owner's tools. A
|
|
396
|
-
participant's turn may call only the `review` kit's tools:
|
|
397
|
-
|
|
398
|
-
- `read`, under the session's project root (the work tree top of its folder)
|
|
399
|
-
and never a secret: chi's state and config dirs (sessions, the grants, the
|
|
400
|
-
web token, memories and their `.bundles`, `config.yml`, hooks, and a
|
|
401
|
-
`hooks.hooks_dir` configured outside the config dir), `~/.ssh`,
|
|
402
|
-
`~/.gnupg`, `~/.aws`, and the project's `.env*`, `.netrc`, `*.pem`, `*.key`,
|
|
403
|
-
`*.p12`, anything named `credentials` (`.git-credentials` too), `.npmrc`,
|
|
404
|
-
`.pypirc`, ssh keys (`id_rsa`, `id_ed25519`, …), `*.tfstate`,
|
|
405
|
-
`secrets.yml`/`.json`, `.docker/config.json`, `.kube/config` and any config
|
|
406
|
-
under `.git` (a submodule's too). The path is checked as given and as it
|
|
407
|
-
resolves, so a symlink in the project to `~/.ssh` is `~/.ssh`, and
|
|
408
|
-
`node_modules/foo/../../.config/gh/hosts.yml` with `foo` a link to `~/src/foo`
|
|
409
|
-
is `~/.config/gh/hosts.yml` ([How paths resolve](#how-paths-resolve)). A session
|
|
410
|
-
whose folder is the home folder or above it reads nothing.
|
|
411
|
-
- `memory_read` with `scope: project` (a read without a scope would fall back
|
|
412
|
-
to the system memories). The prompt's preloaded memories and the memory
|
|
413
|
-
index are in the system prompt anyway: a review session should start
|
|
414
|
-
without personal ones.
|
|
415
|
-
|
|
416
|
-
Everything else is denied with "a participant's review turn may only read …",
|
|
417
|
-
and the model is told to propose the change as text or a diff for the owner
|
|
418
|
-
to apply: `write`, `edit`, `memory_write`, `execute`, the task tools,
|
|
419
|
-
`delegate`, `send_note`, `list_sessions`, `register_reminder` (it would fire
|
|
420
|
-
an owner turn later), `web_fetch`, `context_read`, `ask_user_question`,
|
|
421
|
-
`forget_outputs` (it would replace the owner's earlier tool outputs with the
|
|
422
|
-
participant's note, which later owner turns would read as their own), and
|
|
423
|
-
every plugin or MCP tool, including through `call_tool` (a built-in reached
|
|
424
|
-
through `call_tool` is checked as that built-in). The session's declared tools
|
|
425
|
-
stay its own (no prompt rebuild per author), so the model may still try a
|
|
426
|
-
write; the turn's header ("This turn may only read") keeps that rare.
|
|
427
|
-
|
|
428
|
-
The kit is `Toolkit::REVIEW`, a frozen built-in: config's `toolkit.kits.review`
|
|
429
|
-
is refused with one message ([configuration](configuration.md#toolkits)), so
|
|
430
|
-
config can't widen the boundary. Hooks still run on a participant's turn, with
|
|
431
|
-
the owner's power ([hooks](hooks.md#participants-turns)); a hook that rewrites a
|
|
432
|
-
call is checked on the call it leaves.
|
|
391
|
+
## A participant's turn without a current invite
|
|
392
|
+
|
|
393
|
+
chi runs no read-only turn: no turn an older chi ran read-only may run with tool rights here. The worker refuses a
|
|
394
|
+
participant's turn whose invite is an older chi's (a grant or `participants.json` entry without `mode: pair`), a Verify
|
|
395
|
+
fresh child saved for a read-only turn, a participant with no invite at all, and a participant's turn in the owner's
|
|
396
|
+
own Verify fresh child (the parent's participants are the parent's), before it starts; one function decides it for the
|
|
397
|
+
worker and the guardrails alike (`ParticipantTurnMode`)
|
|
398
|
+
([participants](internals/participants.md#turns)). Should such a turn start anyway, its seat in
|
|
399
|
+
`GuardrailWiring#checks` is `Guardrails::ParticipantRefusal` (rule `participant-refused`, source `core`): every call
|
|
400
|
+
is denied, nobody is asked, in every mode and with `guardrails.enabled: false`.
|
|
433
401
|
|
|
434
402
|
## A participant's pair boundary
|
|
435
403
|
|
|
436
|
-
A participant's turn
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
(`
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
`
|
|
444
|
-
|
|
445
|
-
|
|
404
|
+
A participant's turn acts with the session's tools under the owner's
|
|
405
|
+
guardrails, as the owner's own turns do: the rules and the protected paths
|
|
406
|
+
apply, and an ask goes to the owner. Of the owner's stored approvals only this
|
|
407
|
+
session's own ("Allow … for the session") answer its asks
|
|
408
|
+
(`Guardrails::ApprovalUse`): a call the owner allowed in this repo or for a
|
|
409
|
+
rule asks the owner again, on a card.
|
|
410
|
+
Every invite is stamped `mode: pair`; the turn's mode is decided once at its
|
|
411
|
+
start (`ParticipantTurnMode` via `GuardrailWiring#participant_turn_mode`, into the turn's
|
|
412
|
+
`TurnContext#participant_mode`), and it runs only on a worker that names the
|
|
413
|
+
`pair_turns` feature.
|
|
446
414
|
|
|
447
415
|
`Guardrails::PairBoundary` (rule `pair-boundary`, source `core`) sits in the
|
|
448
|
-
|
|
416
|
+
participant boundary's seat in `GuardrailWiring#checks`, in every mode (also with
|
|
449
417
|
`guardrails.enabled: false`), and **denies, never asks**, each with its own
|
|
450
418
|
message:
|
|
451
419
|
|
|
452
|
-
- secrets, read or written:
|
|
420
|
+
- secrets, read or written: `ReviewPaths`' denylist (chi's state and
|
|
453
421
|
config dirs, so `grants.json`, the web token and every `participants.json`;
|
|
454
422
|
`~/.ssh`, `~/.gnupg`, `~/.aws`, `~/.config/gh`, `~/.config/fish`,
|
|
455
423
|
`~/.config/git`, `~/Library/LaunchAgents`, `~/.local/bin`; the home's shell
|
|
@@ -685,7 +653,7 @@ A command that makes a link asks too, wherever it points (`ln`, `link`, `cp
|
|
|
685
653
|
a link the same command makes is judged before the link exists, so `ln -s ..
|
|
686
654
|
up && cat up/…` can't be read for what it reaches.
|
|
687
655
|
A session whose folder is the home folder or above it has no project to
|
|
688
|
-
keep the turn in (`ReviewPaths.home_root
|
|
656
|
+
keep the turn in (`ReviewPaths.home_root?`): every
|
|
689
657
|
write there asks.
|
|
690
658
|
|
|
691
659
|
A participant's ask names them on the owner's card ("Sam's turn asks: approve
|
|
@@ -699,7 +667,7 @@ cap or their link was revoked or expired
|
|
|
699
667
|
|
|
700
668
|
The trust model is a team's (everyone invited is trusted): the boundary is an
|
|
701
669
|
**accident guard** for secrets and the owner's voice, not containment of a
|
|
702
|
-
hostile participant
|
|
670
|
+
hostile participant. A participant's turn can still reach, through
|
|
703
671
|
the owner's rules: `web_fetch` (an open egress path: what the turn can read it
|
|
704
672
|
can send out in a URL), plugin and MCP tools, `memory_read` and `context_read`,
|
|
705
673
|
`list_sessions` (the owner's other sessions' titles), chi web by a name the
|
|
@@ -716,17 +684,16 @@ delegate child chi web starts for an unclear verdict) runs a participant's
|
|
|
716
684
|
check under **the boundary that participant has in the parent**. A verdict a
|
|
717
685
|
participant recorded is always checked again as them, even when the owner
|
|
718
686
|
clicks (the claim is their text; their link must still be live), so it never
|
|
719
|
-
runs with the owner's rules or System 1's auto-allows. The mode is
|
|
720
|
-
at
|
|
721
|
-
|
|
722
|
-
inside `ReviewBoundary` (read only), `pair` inside `PairBoundary`.
|
|
687
|
+
runs with the owner's rules or System 1's auto-allows. The mode is saved on the
|
|
688
|
+
child at its start (`verify_fresh.mode`: `pair`, every live grant's); a child an
|
|
689
|
+
older chi saved `review` is refused, never run.
|
|
723
690
|
`GuardrailWiring#begin_turn` reads the saved mode and never looks it up again,
|
|
724
691
|
and every turn of the child carries the participant as its author, whoever
|
|
725
692
|
started it, so the boundary can't fall away for a turn the owner typed into it
|
|
726
693
|
or for an author lookup that finds nobody (the child has no
|
|
727
694
|
`participants.json`; revoke and cap read the parent's). It fails closed: a
|
|
728
|
-
`verify_fresh` field that doesn't read is a participant nobody has,
|
|
729
|
-
|
|
695
|
+
`verify_fresh` field that doesn't read is a participant nobody has, whose turns
|
|
696
|
+
are refused. `ChildBoundary` applies on top, as for every
|
|
730
697
|
delegate child, and its asks go to the owner (once only, as a participant's
|
|
731
698
|
do; System 1 skips them). The owner's own fresh child is an ordinary delegate
|
|
732
699
|
child: the owner's turns, `ChildBoundary`.
|
|
@@ -931,7 +898,7 @@ name too) is always outside, in the repo or a tmp folder alike
|
|
|
931
898
|
#### How paths resolve
|
|
932
899
|
|
|
933
900
|
Every path check (protected paths, `outside_repo`, `touches`, `rm`, `memory:
|
|
934
|
-
prompt`, the child
|
|
901
|
+
prompt`, the child and pair boundaries, System 1's own-files test)
|
|
935
902
|
resolves paths with `Guardrails::PathResolve` (the map below):
|
|
936
903
|
|
|
937
904
|
- `..` is taken the kernel's way (`.expand`): after a symlinked folder it
|
|
@@ -1168,7 +1135,7 @@ user's **earlier asks they answered** (`SystemOne::Similar`) — this rule in
|
|
|
1168
1135
|
this repository first, then this rule anywhere, then any answered ask, ranked
|
|
1169
1136
|
by how many words the logged call shares with this one, ties going to the
|
|
1170
1137
|
newest. Reading the log is best-effort, so a log that cannot be read simply
|
|
1171
|
-
offers no examples. A participant's turn
|
|
1138
|
+
offers no examples. A participant's turn is never judged:
|
|
1172
1139
|
there is no user there to ask, and its asks go to the owner. The judgment runs before the card appears, so an ask is
|
|
1173
1140
|
slower by up to `timeout_ms` (2000 ms by default).
|
|
1174
1141
|
|
|
@@ -1494,7 +1461,7 @@ else goes to chi's own rules. It needs nah installed; see its README for the set
|
|
|
1494
1461
|
|
|
1495
1462
|
## Participants' text in later turns
|
|
1496
1463
|
|
|
1497
|
-
A participant's message (
|
|
1464
|
+
A participant's message (see
|
|
1498
1465
|
[internals/participants.md](internals/participants.md#attribution)) stays in
|
|
1499
1466
|
the history, so later **owner** turns read it. chi marks it: the wire header
|
|
1500
1467
|
above it says it is a participant's and not the owner's instruction, and the
|
|
@@ -1502,21 +1469,15 @@ system prompt says the same while the session has participants. Owner turns
|
|
|
1502
1469
|
keep every guardrail. But an owner turn that says "do what Alex said" hands
|
|
1503
1470
|
Alex's text the owner's tools: the model will act on it as the owner asked.
|
|
1504
1471
|
That is the residual risk, documented rather than engineered away: on a
|
|
1505
|
-
session with sensitive tools, quote
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
convinces the model still meets the boundary (containment over detection). In
|
|
1515
|
-
a working session it acts, by design ([the pair boundary](#a-participants-pair-boundary)):
|
|
1516
|
-
invite only people you would let type in your session, under your guardrails. What it can do
|
|
1517
|
-
is make the model *say* what the history holds: a review turn's model sees the
|
|
1518
|
-
whole conversation, earlier tool outputs included, so start a review in a
|
|
1519
|
-
fresh session (or a continue), not on a working session full of outputs. A
|
|
1472
|
+
session with sensitive tools, quote what you want done in your own turn
|
|
1473
|
+
instead. A quote lowers the risk, it doesn't remove it: your line still asks
|
|
1474
|
+
the model to act on what it quotes, with your tools, so read it before you send
|
|
1475
|
+
it.
|
|
1476
|
+
|
|
1477
|
+
Within its own turn a participant's text acts, by design ([the pair boundary](#a-participants-pair-boundary)):
|
|
1478
|
+
invite only people you would let type in your session, under your guardrails. It can also make the model *say*
|
|
1479
|
+
what the history holds: a participant's turn sees the whole conversation, earlier tool outputs included, so invite
|
|
1480
|
+
them to a fresh session (or a continue) when the history holds what they shouldn't read. A
|
|
1520
1481
|
line of a participant's text that looks like one of chi's own headers goes
|
|
1521
1482
|
out quoted (`(quoted) [Steer from the user, …]`), under the real one, in any
|
|
1522
1483
|
case and after any spaces (chi's context-note and task frames too). The owner's
|
data/docs/hooks.md
CHANGED
|
@@ -76,13 +76,12 @@ cheap).
|
|
|
76
76
|
|
|
77
77
|
## Participants' turns
|
|
78
78
|
|
|
79
|
-
A [participant's](internals/participants.md#turns) turn
|
|
79
|
+
A [participant's](internals/participants.md#turns) turn fires the same hooks, and
|
|
80
80
|
every event of it carries `author: "p:<id>"` (the owner's carry no `author:` key, as before); a plugin reads the
|
|
81
|
-
same as `ctx.turn_author` (nil for the owner's turns and between turns).
|
|
82
|
-
comes from who wrote the turn, not from `ParticipantMode`. **A hook runs with the owner's power whatever the
|
|
81
|
+
same as `ctx.turn_author` (nil for the owner's turns and between turns). `author:` comes from who wrote the turn. **A hook runs with the owner's power whatever the
|
|
83
82
|
author**: it may read, write and run what the owner's chi may, and `notify`, `ask_user` and `steer` reach the
|
|
84
83
|
owner. A bundle that acts on a turn's text (a prompt rewrite, a fetch of what it names) should check `author:`
|
|
85
|
-
first: the text may be a participant's. The participant's boundary (the
|
|
84
|
+
first: the text may be a participant's. The participant's boundary (the pair one) checks a tool call
|
|
86
85
|
after the hooks, on the call they leave.
|
|
87
86
|
|
|
88
87
|
## What a hook can do: the runtime
|
|
@@ -125,8 +125,7 @@ name (or whose hint is its URL) is attached, *declined* while the declined marke
|
|
|
125
125
|
|
|
126
126
|
- **Mention.** `mention_in` / `pattern_for` implement the user-facing rules (whole tokens, `#N` ≥ 10 or after
|
|
127
127
|
"PR", branch names ≥ 6 chars with `/ - _`, exact URLs, fenced code blanked). Only `OwnerPrompt` texts count
|
|
128
|
-
(`owner_texts`), so a participant's message, a steer, a note or a reminder never attaches anything
|
|
129
|
-
session skips all of it.
|
|
128
|
+
(`owner_texts`), so a participant's message, a steer, a note or a reminder never attaches anything.
|
|
130
129
|
- **Where it runs.** `before_turn` (from `Worker#run_prompt` before the absorb, and a `--non-interactive` one-shot's turn start, `TerminalUI`): attach
|
|
131
130
|
each proposed candidate the owner's prompts so far mention (`attach` writes a session `Source` through
|
|
132
131
|
`source_for`: a URL resolves through `ContextProviders`, else the candidate's own `cmd`), then `first_fetch` them
|
|
@@ -148,9 +147,9 @@ nothing, so the next owner prompt asks again.
|
|
|
148
147
|
|
|
149
148
|
The driver is the turn stage `TurnStages::ContextJudge` (`turn_stages/context_judge.rb`), not the judge:
|
|
150
149
|
`Engine#prepare_turn` calls its `start(turn, recorder:)` after the toolkit suggestion settled and before `apply_toolkit!` (an owner
|
|
151
|
-
turn's start; skipped for participants
|
|
150
|
+
turn's start; skipped for participants and a Continue), and `Engine#judge_late_candidates` (a proposal
|
|
152
151
|
after the prompts) gives its `late_candidates` the session, the owner's messages, the recorder and the sessions dir
|
|
153
|
-
(none of it read with no session
|
|
152
|
+
(none of it read with no session); both make one pass (docs/internals/engine.md, "Turn stages").
|
|
154
153
|
It first logs status changes (`ContextCandidatesLog.look`), returns at `mode: off`, builds the due `Job`s, and hands
|
|
155
154
|
them to `SideJudgments` (`:context` kind: one thread, one batch per session at a time), asked at once on any host,
|
|
156
155
|
the model's own server too.
|
|
@@ -161,7 +160,7 @@ session source with `JUDGE_WHY`, no probability in the model-visible why), *offe
|
|
|
161
160
|
is still proposed, since the user may have chosen while it was asked. Cards are shown through the stage's choice
|
|
162
161
|
lambda, which holds them while a turn runs; `run_turn`'s ensure shows them after `release_turn`
|
|
163
162
|
(`show_cards_after_turn`). `choose` is the `/context attach|decline` command's body (`SessionCommands`), shared by the
|
|
164
|
-
card's buttons
|
|
163
|
+
card's buttons. An attach only writes the session folder: its note comes with the next between-turn delivery, never into a
|
|
165
164
|
running turn.
|
|
166
165
|
|
|
167
166
|
`ContextCandidatesLog` is `context_candidates.jsonl` beside the sessions folder (a `SideJudgments.log`: 0600, one
|
|
@@ -209,8 +208,8 @@ The refusal side: a push into a session that has been continued is refused with
|
|
|
209
208
|
|---|---|
|
|
210
209
|
| Absorb at all | the conversation has started (`conversation_started?`), or `before_turn: true`; the session isn't stopped on disk |
|
|
211
210
|
| A wake turn | `context.wake`; `WorkerWakes#context_open?`; `CONTEXT_WAKE_WINDOW`; nothing queued and no exit requested; peer: `context.peer_turns`, `peer_open?` |
|
|
212
|
-
| Mention attach | `OwnerPrompt.turn?` (owner author
|
|
213
|
-
| Judge | `context.candidates.mode` `audit`/`on` (default `off`); a System 1 client configured; not a participant's turn,
|
|
211
|
+
| Mention attach | `OwnerPrompt.turn?` (owner author) |
|
|
212
|
+
| Judge | `context.candidates.mode` `audit`/`on` (default `off`); a System 1 client configured; not a participant's turn, scratch session or Continue |
|
|
214
213
|
| Command source defined by the agent | `chi-context-cmd` guardrails rule asks, always; a parent agent can't approve it for a child |
|
|
215
214
|
| Writes to the store | `ProtectedPaths` denies the file tools |
|
|
216
215
|
|
|
@@ -18,12 +18,13 @@ Recommended workflow:
|
|
|
18
18
|
Behavior:
|
|
19
19
|
|
|
20
20
|
- `execute`, `task_create` and the `!cmd` shell bang run the command in a non-login shell: `/bin/sh -c` on Linux; on macOS, when `/bin/zsh` is there, `/bin/zsh --emulate sh +o ignore_braces +o sh_glob -o bash_rematch +o bsd_echo -c` (macOS's `/bin/sh` is bash 3.2, which can't parse an apostrophe in a heredoc inside `"$( )"`, the usual commit message shape). That mode reads no rc files and keeps POSIX word splitting, unmatched globs left as is, `{1..3}`, `[[ … =~ (…) ]]` with `BASH_REMATCH`, arrays, `$'…'`, `&>` and echo expanding `\t`. Bash-only builtins and variables (`shopt`, `BASH_VERSION`, `${!prefix*}`, `read -p`) are not there.
|
|
21
|
-
- Task metadata and output are persisted under `tmp/tasks/`: each task's `tmp/tasks/<id>/task.json` is a `TaskRecord` (`lib/samagotchi/tools/task_record.rb`, a value object: `.from_file` reads it, `#to_file` is the JSON object written, an update is a `#with`). Its keys keep their order; `stderr_path` and `handed_over_by` (a handed-over execute)
|
|
21
|
+
- Task metadata and output are persisted under `tmp/tasks/`: each task's `tmp/tasks/<id>/task.json` is a `TaskRecord` (`lib/samagotchi/tools/task_record.rb`, a value object: `.from_file` reads it, `#to_file` is the JSON object written, an update is a `#with`). Its keys keep their order; `stderr_path` and `handed_over_by` (a handed-over execute), `stop_requested_by` (a stop under way or done) and `leftovers` (`stopped` or `detached`: what the shell left holding the log, below) are left out until set. `bundles/slow-commands` reads these files on its own, so the shape is a contract.
|
|
22
22
|
- A task record keeps its process's pid and start time (`pid_started`). Before `task_stop` signals, the pid must still lead its own process group and must not have started at another time; otherwise the pid was reused by another process, nothing is signalled and the task ends as failed. A start time that can't be read at that moment (a failed `ps`) falls back to the group check, as does a record without `pid_started` (from an older chi). `task_get`, `task_list`, `task_wait`'s polls and the running-task lists (a cancelled turn's note, a worker's restart hold, the finish wake's watch) make the same check, so a task whose pid was reused reads as exited (failed) at once, not as running until a `task_stop`; on macOS that is one `ps` per running task per check (~5 ms).
|
|
23
|
-
- A stop (`task_stop`, the user's Stop of an `execute`, the execute limit in kill mode) TERMs the task's process group, then KILLs it after a grace. The groups its processes started are stopped too: a GNU `timeout N cmd` (without `--foreground`) moves itself and its command to a group of its own. `ProcessGroup.stop` finds them with one `ps -A -o pid=,ppid=,pgid=` (~40 ms on macOS) before the TERM and again before the KILL, walking down from the group's members. A process whose parent already exited (reparented to init, e.g. a setsid'd `cmd &`, or a backgrounded `timeout N cmd &` after its shell exited) is not found
|
|
23
|
+
- A stop (`task_stop`, the user's Stop of an `execute`, the execute limit in kill mode) TERMs the task's process group, then KILLs it after a grace. The groups its processes started are stopped too: a GNU `timeout N cmd` (without `--foreground`) moves itself and its command to a group of its own. `ProcessGroup.stop` finds them with one `ps -A -o pid=,ppid=,pgid=` (~40 ms on macOS) before the TERM and again before the KILL, walking down from the group's members. A process whose parent already exited (reparented to init, e.g. a setsid'd `cmd &`, or a backgrounded `timeout N cmd &` after its shell exited) is not found by that walk; one still in the task's group is stopped by the leftover rule below, so only one outside the group runs on: a setsid'd `cmd &`, or a backgrounded `timeout N cmd &` (GNU `timeout` moves to a group of its own). Holding the task's log, it is reported detached.
|
|
24
24
|
- Task listing is workspace-scoped (current project only).
|
|
25
|
-
- `execute` runs its command with stdout and stderr in two logs under `$XDG_STATE_HOME/samagotchi/execute/<id>/` (always an absolute path: a relative `XDG_STATE_HOME` is taken from the directory chi started in; outside the workspace: `git status` and `rm -rf tmp` never see them), stdin `/dev/null` and the same `exit_code` wrapper as a task. Its own copies of the logs hold a shared `flock` across the spawn: while a fresh exclusive `flock` fails, some process the command started still has them open. When the shell exits, a background child still holding them (`server &`) gets 1.5 s, then its group is stopped; one holding none (`nohup server >log 2>&1 &`) is left alone. A holder that left the group (setsid) is out of the stop's reach: it runs on, the result ends with the "left running" hint, and its dir stays for it to write to (the sweep removes it once no one holds the logs). Otherwise a finished command's dir is removed. Known gap on Linux: a command that writes through `/dev/stdout` or `/dev/stderr` (`echo b >/dev/stdout`) reopens the log file itself with `O_TRUNC`, so the output before it is lost (macOS dups the descriptor; the fix would be a relay pipe). The check needs the state dir on a local file system: over NFS, `flock` is emulated with `fcntl` locks, which children don't inherit.
|
|
25
|
+
- `execute` runs its command with stdout and stderr in two logs under `$XDG_STATE_HOME/samagotchi/execute/<id>/` (always an absolute path: a relative `XDG_STATE_HOME` is taken from the directory chi started in; outside the workspace: `git status` and `rm -rf tmp` never see them), stdin `/dev/null` and the same `exit_code` wrapper as a task. Its own copies of the logs hold a shared `flock` across the spawn: while a fresh exclusive `flock` fails, some process the command started still has them open. When the shell exits, a background child still holding them (`server &`) gets 1.5 s, then its group is stopped (the result's hint says to start a long job with `task_create` in the foreground, no `&`: a `cmd &` left behind there is stopped too); one holding none (`nohup server >log 2>&1 &`) is left alone. A holder that left the group (setsid) is out of the stop's reach: it runs on, the result ends with the "left running" hint, and its dir stays for it to write to (the sweep removes it once no one holds the logs). Otherwise a finished command's dir is removed. Known gap on Linux: a command that writes through `/dev/stdout` or `/dev/stderr` (`echo b >/dev/stdout`) reopens the log file itself with `O_TRUNC`, so the output before it is lost (macOS dups the descriptor; the fix would be a relay pipe). The check needs the state dir on a local file system: over NFS, `flock` is emulated with `fcntl` locks, which children don't inherit.
|
|
26
26
|
- The exit code: the command runs after an EXIT trap that writes the shell's status to the `exit_code` file (`TaskRuntime.wrapped_shell_command`, shared with `task_create`), so `exit N`, a `set -e` failure and a trailing `\` or `|` in the command all record what the shell exited with. The trap runs wherever the shell is when it exits (a `task_create` `cwd`, or a `cd` in the command), so `task_create`'s `exit_code_path` is absolute; its `output_path` stays relative (`tmp/tasks/<id>/output.log`, opened by chi in the worker's cwd before the spawn). A command that sets its own EXIT trap replaces it, and a shell killed by a signal skips it (zsh's sh mode, on TERM, INT and KILL): `execute` still reports the shell's status, and a `task_create` task or a handed-over execute gets its code from chi's waiter while the chi that started it runs (`TaskRuntime.record_exit_status`): the exit status, or `128 + the signal` (TERM → 143), with no new `stop_reason`. A record a refresh already finished without a code in between (`failed`, `process_ended_without_exit_code` or the not-chi's-process reason) is corrected, its `finished_at` kept; a stopped task (its stop flag on disk) is never touched. `process_ended_without_exit_code` is left only when the shell wrote nothing and the chi that started it was gone too.
|
|
27
|
+
- `task_create` applies `execute`'s leftover rule (`Tools::Leftovers`, one implementation: `held?`, the grace, the group stop, the hint wording): `create_task` holds `output.log` with a shared `flock` across the spawn, and a handed-over execute's two logs are already held. When the task's shell exits and a process it started still holds the log (`yes >/dev/null &` with no `wait`), the task stays `running` (so the finish wake's watch and `task_wait` keep waiting) while the waiter of the chi that started it (`TaskRuntime.record_exit_status`) gives it 1.5 s (`LEFTOVER_GRACE_SEC`), then stops the group (TERM, 1 s, KILL; `Leftovers.stop_group`, only while the group still has members: a pgid isn't reused while it has any) and finishes the record in one write: the shell's status and exit code (the leftovers don't make it a failure) and `leftovers: "stopped"`. A holder outside the group with the group empty (a setsid'd `cmd &`, or a backgrounded `timeout N cmd &`: GNU `timeout` without `--foreground` moves itself and its command to a group of its own) is signalled nothing: `leftovers: "detached"`, left running, and the hint says so (`task_stop` can't reach it: kill it if it shouldn't run). A process holding no log (`nohup cmd >f 2>&1 &`) is left alone. `task_get`, `task_wait` (so the finish note too) and `task_list` add the hint line (`Leftovers.task_hint`), ``(a background process kept the task's log open and was stopped; to keep one running, run it in the foreground or end the command with `wait`)`` (or `was left running`), built from the same `Leftovers.hint` as execute's. One settler per task: while that waiter thread lives (`TaskRuntime.waiter_for`, in memory, this process only), a refresh here only reads a held record. With no waiter here (the chi that started it is gone, a worker that exited mid-grace, or another process reading), the next refresh that finds the shell dead and the log held settles it itself: a second look after 0.05 s (two `held?` probes at once read each other as holders), then the stop with a 0.5 s TERM grace and 0.5 s KILL wait (only of a group that still had members at the first look; one gone by the stop with nothing holding the log records no `leftovers`), so that read blocks up to ~1 s plus a `ps`. With no later reader of that cwd's tasks the leftovers run on; records already finished (an older chi's) are never revisited, and an older chi's record (its log never `flock`'d) reads as not held and settles as before. A `task_stop` during the grace stops the group (`Leftovers.stop_group`) and the record ends `stopped` (its stop flag wins over the waiter's write; in one process the two writes share a lock). Cost: one non-blocking `flock` try per log at shell exit (~0.2 ms), the grace only when something holds the log; a refresh of a running record whose shell is dead adds one `flock` try, and one `ps` only when the log is held.
|
|
27
28
|
- A stop of an `execute` (the user's Stop, the limit in kill mode) is done once the shell is reaped and nothing holds the logs: a child that ignores TERM after its shell died gets the KILL.
|
|
28
29
|
- A command still running at `execute.timeout_sec` is handed over as a task (`execute.on_timeout: task`, the default; `kill` stops it instead, and the `!cmd` bang always kills): the result starts `Still running at the 120s limit: moved to a background task, not killed.`, then `task_id: …` and the tails of both logs so far. A command is also handed over early when a person's message waits for the turn's next step (the `message_waiting:` probe, the same `Engine#input_waiting?` as `task_wait`'s): after `Execute::EARLY_HAND_OVER_FLOOR_SEC` (3 s: a short command ends first and its result is the better answer), in the next 0.2 s slice. The first line then reads `Still running at the 4s mark: a message from the user is waiting, so the command moved to a background task, not killed.` (the seconds it had run), and the line after `task_id:` starts `Read the message first.`; the rest is the same hand-over, and the task stays watched. Never in `kill` mode (`execute.on_timeout: kill`, a participant's pair turn, the `!cmd` bang): there the probe is not even read and the command runs to its limit and is killed. A command that can't be adopted at that moment (a record that can't be written) isn't killed early: it runs on to its limit. Everything that matches the first line builds on `Execute::HANDED_OVER` (`Still running at the`) and `Execute::HANDED_OVER_AFTER` (`120s limit:` or `4s mark:`): `TaskRuntime.handed_over_pattern`, `ToolActivity::HANDED_OVER_START`, `TaskWatch` (`limit_sec` for the limit's form, `early_sec` for the mark's, which the finish note words as `handed over by execute after 4s: a message from the user was waiting`) and the web's `task_stop.js`; the slow-commands bundle reads only the limit's form, which is the only one that is a timeout. A timeout during the 1.5 s background grace is a kill (the shell is gone, nothing to hand over). If the record can't be written, the command is killed. `TaskRuntime.adopt` writes a record for the process execute already started, with `handed_over_by: "execute"`. Its logs stay where execute wrote them, so the record's paths are absolute: `output_path` (stdout), `stderr_path` (stderr, a log of its own) and `exit_code_path` (a `task_create` record's `exit_code_path` is absolute too; its `output_path` is relative). `started_at` (and `created_at`) is the spawn time, not the hand-over's; `pid_started` is read at the hand-over, while execute's detach waiter is still running. From there it is an ordinary task: `task_wait`, `task_get`, `task_list` and `task_stop` treat it as any other. Its dir gets a `task` back-pointer file holding the record's absolute path. Once per process, the first `execute` sweeps `…/execute/`: a dir whose logs no process holds is removed when it has no back-pointer and is a day old (chi died mid-command), when its record is gone, or when it is 14 days old. The records live in each project's `tmp/tasks`, which the state dir can't list: hence the back-pointer.
|
|
29
30
|
- `task_wait` and `task_get` show `stderr_path` when the record has one; `task_wait`'s output tail is followed by a `stderr_tail:` of at most 10 lines when that log isn't empty. A `task_create` task has one log (stdout and stderr together) and no `stderr_path`. A `task_wait` result longer than `max_tool_output_chars` keeps its header and the tail's end, with a gap line naming `output_path`, where the whole log already is (and `stderr_path`, when the record has one) (`ToolOutputCut`'s `:head_tail_ref`; nothing is copied; see [Tool output guardrails](tool-output-limits.md#the-runners-cut-max_tool_output_chars)).
|
data/docs/internals/bridge.md
CHANGED
|
@@ -157,7 +157,7 @@ no line for (an older worker's, one from before drawings, a dropped one) gets on
|
|
|
157
157
|
is memoized per range (`Synth.memoized`), so a show after a turn end makes no old turn again. What each step did
|
|
158
158
|
as message parts (`MessageParts`, `parts: true`) is the participant review's only (`ParticipantReview`, frozen on
|
|
159
159
|
its message model).
|
|
160
|
-
- **Compat.** An older worker writes nothing, a continue (a note, no turns)
|
|
160
|
+
- **Compat.** An older worker writes nothing, a continue (a note, no turns) copies no drawings, and
|
|
161
161
|
an older chi's fork or one-shot wrote none: their turns are made from their messages. A `/btw keep` child forked
|
|
162
162
|
before its first turn (saved without its system head) draws its turns made from its messages, without CardStore
|
|
163
163
|
rows, until that turn puts the head back and its carried lines hold (`Synth::LOSSES` `fork_before_first_turn`;
|
|
@@ -444,8 +444,11 @@ The Bridge exposes:
|
|
|
444
444
|
(memory only) holds for that relay (`child_id`, `child_question_id`, `state`, `answer`, `by`);
|
|
445
445
|
`404` for an unknown id. A POST with a body because routes match exact paths.
|
|
446
446
|
- `POST /session/:id/command` — a session command (`/model`, `/models`, `!rollback`, `!cmd`,
|
|
447
|
-
`/continue`) for the worker loop; `202` with a `command_id` its
|
|
448
|
-
the line isn't one.
|
|
447
|
+
`/continue`) for the worker loop (`{line, client_id, card?, deadline?}`); `202` with a `command_id` its
|
|
448
|
+
`:command_ran` names, `400` when the line isn't one. `client_id` is required: without one (or a blank one) `400
|
|
449
|
+
missing_client_id` (`Bridge::UNNAMED_COMMAND`); from a sender that may not send commands (`CommandIntake.allowed?`:
|
|
450
|
+
only the owner's senders, `web:`, `tui:`, `cli:send`, and chi answer's `cli:answer`) `403 command_not_permitted`, its
|
|
451
|
+
detail `CommandIntake::COMMAND_REFUSED` (`CommandIntake::REFUSED` for a `!` line), nothing queued. A `:command_ran`'s `output` is the command's, up to `Worker::COMMAND_OUTPUT_LIMIT` (64 KiB of chars; past it
|
|
449
452
|
the text ends with a `[cut: N of M chars: …]` line, which the UIs print as they print the rest). It carries `thinking`, `reasoning_history` and `llm_context`
|
|
450
453
|
(the summaries the next turn runs under) when the command changed them or the model, and
|
|
451
454
|
`confirm: {line, text}` when a `/thinking` or `/reasoning-history` change from a `web:` or `tui:`
|
|
@@ -615,6 +618,29 @@ the Live's client or nil; `WorkerLink.await` polls for a new worker's Live (an `
|
|
|
615
618
|
successor from the old worker); chi web's `App#worker_link` / `#await_worker_link` wrap them. The Bridge writes
|
|
616
619
|
`pid` and `protocol` with its port and removes its sidecar on stop only when the file still carries its epoch.
|
|
617
620
|
|
|
621
|
+
The sidecar's `features` array is the worker's capability handshake: clients check a name rather than infer
|
|
622
|
+
compatibility from its version. `Bridge::FEATURES` advertises:
|
|
623
|
+
|
|
624
|
+
| Feature | What a client gains |
|
|
625
|
+
|---|---|
|
|
626
|
+
| `restart` | `POST /session/:id/exit` can hand the session to a worker running the newest chi (`chi sessions restart`). |
|
|
627
|
+
| `task_stop` | The web can stop a running background task with `POST /session/:id/tasks/stop`. |
|
|
628
|
+
| `reparent` | A continued chain can move a live delegate worker with its parent. |
|
|
629
|
+
| `delivery` | The worker understands all delivery modes, including queueing a turn until the current turn ends. |
|
|
630
|
+
| `turn_ids` | A client can wait for a particular enqueued turn across running, continued and stopped turns. |
|
|
631
|
+
| `verify` | The worker accepts and validates Verify anchors on turns. |
|
|
632
|
+
| `revise` | The worker accepts and validates Revise anchors on turns. |
|
|
633
|
+
| `unqueue` | A client can take back a queued turn before it starts (`POST /session/:id/turn/dequeue`). |
|
|
634
|
+
| `review_turns` | An older chi web checks this before sending legacy participant turns; it is not a read-only mode on current workers. |
|
|
635
|
+
| `pair_turns` | The worker runs participant turns under the owner's guardrails, so chi web may invite participants. |
|
|
636
|
+
| `turn_drawings` | chi web can render completed turns from their saved drawings instead of reconstructing them. |
|
|
637
|
+
| `activity` | `GET /activity` tells `chi schedule tick` what the live worker is doing. |
|
|
638
|
+
| `objectives_track` | chi web can show the worker's progress tracking for active objectives. |
|
|
639
|
+
| `participant_steer` | A participant's message during their own turn can go in at its next step. |
|
|
640
|
+
| `cancel_turn_id` | `POST /session/:id/cancel` can stop only the named turn. |
|
|
641
|
+
| `participant_revise` | chi web can pass a participant's Revise draft for worker-side validation. |
|
|
642
|
+
| `participant_client_id` | chi web can identify a participant as `participant:<id>` instead of using the legacy `review:<id>`. |
|
|
643
|
+
|
|
618
644
|
`chi web`'s `GET /api/sessions/:id/stream` proxies this bridge
|
|
619
645
|
(503 `not_live` for no worker, a leaving or stuck worker, or an unreachable Bridge; 502 `worker_newer` for skew and
|
|
620
646
|
`bridge_error` / `bridge_secret` for a refused Bridge; 200 only after the Bridge answers; full history of any session
|
data/docs/internals/engine.md
CHANGED
|
@@ -84,7 +84,7 @@ hook's model switch names the new model and `incoming` the old one. Building one
|
|
|
84
84
|
| Stage | Built with | Called with | Called | State |
|
|
85
85
|
|---|---|---|---|---|
|
|
86
86
|
| `TurnStages::ToolkitSuggestion` (ToolkitSuggest's ask; configuration.md (Toolkits), guardrails.md (System 1)) | side judgments, host registry, toolkit binding, tools | `start(turn, recorder:)`; `settle`, `abandon(turn, why)`, `finish` (the turn); `warm!(session)` | `start` before `refresh_profile!`; `settle` after `apply_staged_tools!` (on mode: waits up to System 1's timeout or a Stop, which wins over an answer already in; a pick ≥ threshold → `ToolkitBinding#suggest`); `abandon` at STOP CHECK A and in the ensure, then `finish`; `warm!` / `stop_warmup` (Worker start, `shutdown`) | the turn's `ToolkitSuggest::Pending` (turn thread only; another turn's is never touched; dropped at `finish`), the warm-up thread |
|
|
87
|
-
| `TurnStages::ContextJudge` ([attached-context.md](attached-context.md), [context.md](../context.md) "The judge") | side judgments, host registry, `TurnState`, `show_card:`, `current_session:` | `start(turn, recorder:)`; `late_candidates(session, messages:, recorder:, state_dir:)`; `show_cards_after_turn` | `start` after `settle`, before `apply_toolkit!` (owner turns only); `late_candidates` from `judge_late_candidates` (which returns on no session
|
|
87
|
+
| `TurnStages::ContextJudge` ([attached-context.md](attached-context.md), [context.md](../context.md) "The judge") | side judgments, host registry, `TurnState`, `show_card:`, `current_session:` | `start(turn, recorder:)`; `late_candidates(session, messages:, recorder:, state_dir:)`; `show_cards_after_turn` | `start` after `settle`, before `apply_toolkit!` (owner turns only); `late_candidates` from `judge_late_candidates` (which returns on no session first, before reading anything else); `show_cards_after_turn` after `release_turn` | the cards an answer brought while a turn ran, under their mutex |
|
|
88
88
|
| `TurnStages::Objectives` ([objectives.md](objectives.md)) | side judgments, host registry | `incoming(turn, recorder:)`, `outgoing(turn, result, recorder:)`, `note(session, note, recorder:, state_dir:)`, `announce(session, state_dir:, running:)` → the event or nil, `propose(proposal)`, `finally(turn)` → the cards, `track(turn, engine:)` → the tracker's thread or nil, `cancel_track` | `cancel_track` first thing in `begin_turn` (any turn, a wake's too); `incoming` after the judge's `start` (owner and human prompts only); `announce` from `announce_objectives` (inside `end_turn`'s step, and between turns from any thread); `outgoing` in `complete_turn` before `:after_turn`, `track` right after it (`Engine#track_objectives_after`); `note` in `add_context_note`; `propose`; `finally` from `show_objective_proposals` in the ensure | the turn's proposals under their mutex (drained at `finally`), the last view announced (touched only under the event lock), the tracker's automatic read's cancel under its own mutex; the `ObjectivesAudit` is built per call |
|
|
89
89
|
| `TurnStages::Warmup` (PromptWarmup) | `PromptWarmup`, kernel, `TurnState`, model settings, reminder queue, `system_prompt` | `after(turn, result, next_turn_waiting:)` | after `complete_turn` (reads `turn.context.settings`) | none (PromptWarmup keeps its pin and thread) |
|
|
90
90
|
| `TurnStages::VerifyAnchors` | nothing | `verified(session, anchor, state_dir:)`; `stamp_opening`, `record_verdict` | `verified` in `begin_turn` (before any `TurnContext`); `stamp_opening`, `record_verdict` inside `end_turn`'s step | none |
|
|
@@ -533,23 +533,35 @@ Where a participant's author (`"p:<id>"`; `Steer.participant_author?`) goes (the
|
|
|
533
533
|
grouped by sender and author so a participant's lines never share the owner's message (`Steer::Line#author`).
|
|
534
534
|
Assistant and tool messages carry none: `Steer.author_at(messages, index)` resolves by position. `ChatLoop#plain`
|
|
535
535
|
keeps the keys (`Steer::AUTHOR_KEYS`).
|
|
536
|
-
- **The wire**: such a message goes out under
|
|
536
|
+
- **The wire**: such a message goes out under its participant header (`Steer.wire_text`: the pair one, or the review one for an older chi's; prompt-caching.md).
|
|
537
537
|
Saved raw.
|
|
538
538
|
- **`Session#last_turn.author`** and the analytics record's `author` (`SessionMetrics`); a Continue keeps the offer
|
|
539
539
|
turn's author (`ContinueOffer#run_continue_turn`).
|
|
540
540
|
- **Never a command**: a participant's `/word` or `!line` is refused (`Bridge#handle_post_turn` 403,
|
|
541
541
|
`WorkerInbound#queue_as_command` drops it). The same two intakes ask `CommandIntake.allowed?` for every other
|
|
542
|
-
sender: only
|
|
543
|
-
|
|
542
|
+
sender: only the owner's (`ClientId.owner?`) and `cli:answer`'s line is a command; from a delegate, a schedule, a
|
|
543
|
+
plugin, a wake or a sender that names none a `/word` line is a prompt and a `!` line is refused (the Bridge's 403
|
|
544
544
|
`command_not_permitted`; an input file's or a first prompt's is queued and `Worker#run_command_line` answers it with
|
|
545
545
|
the error `command_ran`). A session's first prompt carries its sender too: `WorkerInbound#initial_origin` reads
|
|
546
|
-
`Session#first_turn_client_id` (a delegate child without it: `ClientId.delegate` of its parent)
|
|
547
|
-
for `#initial_command?`
|
|
546
|
+
`Session#first_turn_client_id` (a delegate child without it: `ClientId.delegate` of its parent), else the owner's
|
|
547
|
+
`ClientId::FIRST_PROMPT` (`spawn:first`: a person's session saves none), and `first_turn_id`, for `#initial_command?`
|
|
548
|
+
and `Worker#run_initial_prompt`.
|
|
549
|
+
- **Who sent it**: `client_id.rb`'s `ClientId::ROWS`, one `ClientId::Sender` row per id chi makes (the whole id, or a
|
|
550
|
+
prefix ending in `:`; the longest wins): `human`, `owner`, `interactive`, `wake`, `origin`, the merged line's `source`
|
|
551
|
+
and the UIs' `label`. `ClientId.human?`, `.owner?`, `.interactive?`, `.wake_kind`, `.origin`,
|
|
552
|
+
`Steer.source_for_client` and the TUI's labels read it; `turn_events.js CLIENT_LABELS` keeps the same labels
|
|
553
|
+
(`spec/shared/labels_matrix.json` has a case per row). No client id is `ClientId::NONE`: a human's (a delegate
|
|
554
|
+
child's report, the metrics) but **never the owner's**: no session command, no un-archive. Every sender names itself:
|
|
555
|
+
the Bridge's `POST /command` answers 400 `missing_client_id` (`Bridge::UNNAMED_COMMAND`) without one, and a person's
|
|
556
|
+
card answer, which names none (a TUI's, the web's), is stamped `ClientId::CARD_ANSWER` by `ContinueOffer#answered`
|
|
557
|
+
so their Continue / Stop un-archives and resets the wakes (`Worker#user_input`). An id chi doesn't know is
|
|
558
|
+
`ClientId::UNKNOWN`: automatic.
|
|
548
559
|
- **Delivery**: a participant's input always waits for a turn of its own (`SessionInbox.waits_for_turn_end?`), so
|
|
549
560
|
the drain never merges it; their turns count against chi web's `pending_limit` (429 `too_many_turns`).
|
|
550
|
-
`Worker#run_prompt` checks their link and cap (`participant_refusal`) before the turn and after it.
|
|
551
|
-
- **The gate**: `GuardrailWiring#participant_boundary` picks `Guardrails::PairBoundary`
|
|
552
|
-
`Guardrails::
|
|
561
|
+
`Worker#run_prompt` checks their link (`ParticipantTurnMode`: an older chi's read-only one is `outdated`) and cap (`participant_refusal`) before the turn and after it.
|
|
562
|
+
- **The gate**: `GuardrailWiring#participant_boundary` picks `Guardrails::PairBoundary` for a pair turn, else
|
|
563
|
+
`Guardrails::ParticipantRefusal` (every call denied), by `TurnContext#participant_mode` (guardrails.md). Both are
|
|
564
|
+
no-ops for the owner.
|
|
553
565
|
The declared tools stay the session's (no rebuild per author).
|
|
554
566
|
- **Hooks and plugins**: `Engine#turn_author` (the published `TurnContext#author`, so any thread reads it from the
|
|
555
567
|
turn's first moment) is the hook runtime's (`author:` on every event of such a turn) and `ctx.turn_author`.
|
|
@@ -133,8 +133,7 @@ Bridge's `TurnAccumulator#current_messages`) leaves tool calls out. A move shows
|
|
|
133
133
|
- **Declared**: on `full` (`all_core`) and on the coordinator kit (its bundle adds it); named in the not-loaded line
|
|
134
134
|
elsewhere, and so counted in `find_tools`' chi line, and among the deferred tools on a host that loads tools.
|
|
135
135
|
- **Cost**: one extra generation when the move is the step's only call, none when it comes in a batch with another call.
|
|
136
|
-
- **Guardrails**: no rule names it, so it passes with no ask, in `strict` too. `
|
|
137
|
-
outside its kit. `PairBoundary` denies it as owner-voiced: a move stays in the owner's history and reads as the
|
|
136
|
+
- **Guardrails**: no rule names it, so it passes with no ask, in `strict` too. `PairBoundary` denies it as owner-voiced: a move stays in the owner's history and reads as the
|
|
138
137
|
session's own.
|
|
139
138
|
- **The row**: `recording a move` in the TUI's line with `id=`, `state=` (blocked or done only, before `note=` so a cut
|
|
140
139
|
can't drop it: `ToolActivity#objectives_state_param`), `note=`, `evidence=`; the web's row is `objectives O2 note · evidence`
|
|
@@ -239,8 +238,7 @@ command), which absorbs the file. It no longer waits for the fallback tick.
|
|
|
239
238
|
after the carry note and any moved context's note, so the list reads as the latest word. It is not in
|
|
240
239
|
`SessionChain.note_text` (capped; the last answer gets what the recap leaves). It reads the previous link fresh,
|
|
241
240
|
with its unabsorbed newest file. A failure is only logged (`continue_objectives_failed`), because it runs inside the
|
|
242
|
-
continue's rollback.
|
|
243
|
-
differ. The previous link's other waiting notes move after it (`NoteMove.move`, the step after: moved first, the
|
|
241
|
+
continue's rollback. The previous link's other waiting notes move after it (`NoteMove.move`, the step after: moved first, the
|
|
244
242
|
carry would miss a pending edit, and the stale list would be the batch's newest); its objectives notes never move,
|
|
245
243
|
and the new link's worker never adopts one from it (`NoteMove.adoption`), so a list from the archived link can't
|
|
246
244
|
overwrite the carried one.
|
|
@@ -373,7 +371,7 @@ not a canceled or exhausted one), on the turn's thread after `end_turn` and befo
|
|
|
373
371
|
`ObjectivesTrack.after_turn?` decides, in this order: the setting (`objectives.tracker`, default `off`), then the list (an
|
|
374
372
|
active item; `pending_payload` is a file read), then the turn: not a `--non-interactive` run (`Engine#interface ==
|
|
375
373
|
:non_interactive`: its origin can't tell, `ClientId.human?(nil)` is true), the owner's (`OwnerPrompt.turn?`: not a
|
|
376
|
-
participant's
|
|
374
|
+
participant's; a person's prompt or a wake), and the newest turn of the stored conversation (after
|
|
377
375
|
its last `Steer.turn_prompt?` entry) has at least one run that is work (`Objectives::Backing.work?`: an edit or write that
|
|
378
376
|
succeeded, an execute that finished ok, the page's no-move rule) and no objectives call that recorded a move. The stored
|
|
379
377
|
conversation is copied on the turn's thread; the request goes on a thread of its own kind (`SideJudgments#start`), so the
|