Repository navigation
Triggers: the definition (the rule, the notice, the mark), in proto, spec and fixtures - #341
Closed
kombuchapunk wants to merge 17 commits into
Closed
kombuchapunk wants to merge 17 commits into
kombuchapunk wants to merge 17 commits into
Conversation
RFC 0004 §6. A run the daemon starts or resumes for a trigger rule needs a
mark a receiver can show ("started by trigger card-todo"). It cannot be
`launched_by`: that names a session, and a rule is none.
- `Session.triggered_by` (tier 0, beside `launched_by` and `delegated_by`):
the rule's name, `^[a-z0-9][a-z0-9_-]{0,39}$`. That pattern is now the one
every place that names a rule uses (`RULE_NAME_RE` in core).
- The hook reads it from `SESSIONPIPE_TRIGGERED_BY` as it reads the other
lineage variables, drops a value that does not fit, leaves a subagent to
its parent, and the worker takes the job's value, never its own.
- The variable joins `LINEAGE_ENV`, so every place that resets the lineage
(jobEnv, claudeEnv, the Agent SDK host) resets it too. The tests that hold
a daemon's stale lineage away from its children now carry it.
- Lineage, never authority: nothing reads it to allow anything.
Fixture: conformance/harness/claude-code/session-start-triggered-by.json,
the recorded SessionStart payload of the launched_by fixture with the
variable swapped (the harness passes it unread, so the payload is the same).
Spec: PROTOCOL.md §3, PRIVACY.md tier 0 and the note on names.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
RFC 0004 §3 and §8. A receiver picks WHEN one of the person's rules runs by
sending a notice; the machine alone decides whether anything runs. This is the
definition only: nothing reads a notice yet.
- `ControlNotice` (control-notice.json), strict: id, topic, event, subject,
and optional state, for and by, all short typed tokens, with at and
expires_at. No session, words, folder, level or tool. What a schema cannot
say (at most a day of life, not from the future, 1 KiB) is in its comment
and in the reader.
- `ControlPoll.notices`, at most 50, beside `messages`; a daemon that
predates it reads `messages` only.
- `ControlHello.triggers`: on, and the topics of this machine's rules whose
source is that receiver. Never a filter, words, target or level.
- `POST {control}/notices/ack` (control-notice-ack.json): id, outcome, at,
`session` only with `ran`, a refusal code only with `refused`.
Two outcomes beyond the RFC's list: `taken` (not final), because a run that
waits for a held session would otherwise be redelivered on every poll and
turn the long-poll into a busy loop, and `failed`, for a run whose harness
would not start. The refusal codes are one closed enum, with `harness`,
`start_limit` and `missed` beside the RFC's.
- `ControlInfo.notices`: a receiver says it sends notices, so `trigger add`
can tell the person when one does not. It works as `files` does.
- Core: `parseNotice(raw, now)` checks a notice against the generated
schema and then the times and size, and says whether its id can be read
(acked `bad_notice`) or not (nothing to ack); `noticesIn` takes 50 a poll;
`noticeAck` can only build an ack that says what it may.
Vector: conformance/control-vectors/171-kind-trigger.json, a trigger.add
whose signatures all hold, refused unknown_kind (the RFC said 180; the
generator numbers vectors in order and nothing holds 171 to 179).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
RFC 0004 §2, and RFC 0001 §8, which names config.proto as where a machine's own files are defined. The rule never travels, but the CLI, the daemon and later the command table must read one definition of it. - config.proto: TriggerRule (strict) with a source that is either a receiver and topic (and event) or a clock, `when` lists, a subject pattern, a target that is either `start <harness>` or `continue <harness>:<id>`, folder, level, MCP tools (the receivers' session_tools pattern), a per-day cap and the words; TriggersFile; and the --json answers of `trigger list` and `trigger test`. - tools/doors: typesFile can write a module of its own that imports the types it names from another file (config.ts imports three from v1.ts), and the machine-local schemas go to packages/core/gen/config-schemas.ts, never under schemas/v1. v1.ts and every published schema are unchanged. - Core, pure and fully tested: the file checked against the generated schema and then for what a schema can't say (notice rules at edits at most, clock rules with nothing to filter or fill, folders, unique names, the clock); the rule in plain words; the hello's topics; matching a notice; the level; the framed words, where a test with hostile tokens that pass the wire patterns shows none leaves its backticks. - The subject pattern language: a subset of regular expressions with the meaning a RegExp gives it (held to RegExp in a test), anchored, no groups, alternation or lazy quantifiers, counts up to 40, and matched by stepping through the subject once per piece, so it cannot backtrack. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
RFC 0004 as normative text, in the document's voice, with the principle
each rule keeps quoted from §1: the rule made only at the machine, the
notice, topics in the hello, acks, asleep, the clock, the run (the checks
in order, the narrower level, the caps shared with ask, a window-held
session waits, permissions), the words and the subject pattern, the mark,
off, and what a receiver does. The RFC's §1 table is there with the real
fixture paths. HTTP.md §1 gains `control.notices`, §3 the notices in a
poll answer and `POST {control}/notices/ack`; CONTROL.md §2, §5 and §11
point at §14.
Decisions the RFC left open, written down here:
- One notice runs at most one rule: the first in the file's order that
takes it, so an ack has one outcome.
- A paused rule is not a candidate (`no_match`), and its topic leaves the
hello.
- A broken notice whose id can be read is acked `refused` `bad_notice`;
one whose id cannot be read has nothing to ack and is dropped each time.
- Triggers off is checked before the notice's shape, and a rules file that
doesn't fit is read as off, never in part.
- `taken` pauses re-delivery until the notice expires.
- Every command that changes rules refuses inside a session (the guard
`ask on` uses), and the three that widen need an interactive `yes` with
no flag to skip it.
- The cooldown is for notice rules; a clock rule is held by its cap.
Fixtures: conformance/triggers/, thirteen scenario files and two for the
reader alone (rules files, subject patterns). Every part the pure functions
decide is held now by packages/core/test/trigger-fixtures.test.ts; the
rest (dedup, counts, the allowlist, a held session, the caps, the clock,
turning off) waits for the engine, which runs the same files.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
…ider
Review fixes to the definition (points 1, 3, 4a, 8 and part of 9).
- Words and folders may hold no character that does not show. config.proto's
patterns refuse every control character (C0 with carriage return, DEL, C1;
a folder also tab and line feed), which every reader's pattern engine can
say; checkTriggers refuses the rest by Unicode's categories (format: bidi,
zero-width, tag characters; line and paragraph separators; private use;
unassigned; surrogates). `visible` writes such characters out, and
describeRule, a refusal that quotes a value, and a pattern's refusal all
use it.
- triggerLevel takes the rule: a notice rule is narrowed to edits by the
function itself, not only by the file check. Its facts are an object,
`{recorded?, offered?}`: with the harness's offered levels it gives the
widest no wider, or null (refused `harness`). triggerRun and testAnswer
follow. describeRule says what Codex's levels mean.
- A rule's folder may not be the home folder, nor hold or lie inside
sessionpipe's config or state folders: checkTriggers and readTriggers take
the places (triggerPlaces reads this machine's), folderProblem says why.
- One definition: NOTICES_PER_POLL, SUBJECT_PATTERN_MAX and the clock's
shape are read from the generated schemas; SUBJECT_CHAR, SUBJECT_MAX and
RULE_NAME_RE stay constants (RULE_NAME_RE because the worker must not
bundle the schemas), each held equal to the definition by a test, as is
the daemon's session_tools pattern.
- A compiled subject pattern refuses input longer than a subject, so `^a*$`
never means something else than its RegExp.
- `missed` leaves the wire enum: it is a TriggerResult of a clock rule's
history. TriggerWhen's comment says what an absent list means and that a
filter is no secret; `by` says it trusts the receiver's word.
- conformance/triggers/rules-file.json gains a case for each class of
hidden character in words and folder, and for each forbidden folder.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
… promise Review fixes to CONTROL.md §14 and its fixtures (points 2, 4b, 4c, 5, 6, 7, and the rest of 9). - When a run counts: the moment it is taken or begins. A count is given back when it ends without running (held, start_limit, off, expiry), and the folder, harness and session are checked again when a waiting run is let go. Waiting runs are kept in the daemon's state and outlive a restart. - The machine's pause after no_session lives in the daemon's state, never in triggers.json; the hello's topics and `trigger list` show it, `trigger resume` clears it. The CLI writes triggers.json beside and renames it. - §14.1 names the guard's variables exactly (and which three `ask on` checks), says the terminal test and the guard are no proof a person is there, that anything running as the person can edit their files, and that this is control.json's limit too. Receivers are named by URL host, lowercased, default port dropped; `add` refuses a name two pairings share; bracketed IPv6 is not supported. - §14.4: one rule for a seen id (`duplicate`, which never replaces an ack a receiver has; acks are kept until accepted), and a plain list of what a receiver learns from acks: a filter is a limit, not a secret. - §14.2: patterns are ECMA-262 (`$` is the very end), the 1 KiB is measured re-serialised without whitespace, a member named twice reads as the last. A machine never checks a whole poll answer against control-poll.json. - §14.7: the first rule that fits takes the notice and a refusal does not fall through; a notice rule is edits at most however the file says more; the harness's own levels narrow the run; and what an edits run can leave for later runs (.claude/settings.json, .git/hooks). - Fixtures: notice-bad-shape.json (too big, a day's life or none, ahead of the clock, null, mistyped, `__proto__`, trailing line breaks, no milliseconds); run-waits gains counting at taken, the count given back and the recheck on release; run-level-capped a Codex start at edits. One expectation was wrong and the model below found it: 52 notices on a 2-at-once machine run 2, wait 3 (counted) and refuse the rest for the cap. - trigger-fixtures.test.ts now runs every step through a small model of §14.7 and checks every expectation (acks in order, runs, history, pauses, cancelled, hello at once, unacked, message acks). The reviewer's five mutations and three more are all caught. README says what only a daemon can show. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
…, and the sentence stands alone
Second review fixes (points 1 to 7).
- triggerLevel returns null for a rule's level that is none of the four
and for a recorded level it does not know (none recorded and `inherit`
keep their meaning); levelRefusal says why: triggers_off (the file can't
fit), no_session (a session it can't continue as it was), or harness.
A level it was not given can no longer come out.
- The folder's floor: not home nor above it; not sessionpipe's config or
state folders, inside or holding them; not a harness's own folder (read
from the adapters' config files), inside or holding one; not a dot-folder
in home; on macOS not ~/Library. Without regard to case on darwin and
win32. TriggerPlaces carries the harness folders and the platform;
realFolderProblem compares real paths (realpathSync.native).
- Hidden text also covers Default_Ignorable_Code_Point, U+2800, U+FFFC,
every space but U+0020, and more than four combining marks in a row; a
refusal names the character, its escape and its place. visible() escapes
them and doubles a backslash wherever it could start an escape.
- describeRule returns { lines }: a sentence that holds no free text, then
the folder and the words on their own marked lines. Words that try to
finish the sentence stay on their lines.
- The fixture model follows §14.7 for ticks (re-check, start-cap wait),
keeps a sliding hour, cancels only runs still running, sends a hello only
when a receiver's `triggers` changes, settles deadlines first, compares
acks by id, and models `resume` and the pause's end. New cases for each;
the three surviving clock mutations and nine more are caught.
- Spec: the cooldown with no state, what counts against the start caps
(exactly an ask's), every give-back, a lent count refusing for good, the
deadline, ack order, the hello rule, the pause's end, the tick order, the
folder's floor and real paths, the hidden-character list, the sentence's
shape, and the step-0 note claiming only what was measured.
- config.proto's level comments name every input and that no run exists
when nothing fits; `reserved 10` where `missed` was.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
PR #340 landed the step-0 recording (conformance/control-claude-folder-rules.json); the note in CONTROL.md §14.7 now names it and the versions it was recorded on, so it claims exactly what that file shows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
… Windows' own folders
Third review fixes (points 1 to 8).
- describeRule(rule, { width }) cuts a long line of the folder or the words
itself (80 columns by default, never under 40, Infinity for a pipe), every
further piece behind `┆`, between characters as a person sees them, wide
characters and pictographs counted two columns (core's own columnsOf: the
CLI's `cols` counts code points, which wide padding would get past).
- The folder's floor on Windows: %APPDATA% and %LOCALAPPDATA% (is, holds or
inside), a drive's root, and segments compared without the trailing dots
and spaces Windows ignores. TriggerPlaces gains `system`; triggerPlaces
reads the two variables on win32. Every platform compares names in NFC.
- A continued run waiting for a headless slot is taken, and at its deadline
refused start_limit with its count given back.
- One run of a rule at a time: the next waits behind the last, in the
order taken, and at its deadline is refused with the new code `busy`.
- no_session's two meanings are said; the machine's pause has a reason
(TriggerPause: gone, unknown_level) that `trigger list --json` carries.
- triggerLevel and levelRefusal check the mode as an own key (`__proto__`
and unknown modes give no level, triggers_off).
- hiddenIn's `at` counts characters as shown (grapheme clusters; a hidden
mark or joiner is in the character it follows), with `codePoint` beside
it. Fixtures: a waiting tick reaching six hours, a clock rule continuing
a held session, busy for a notice rule and a clock rule, headless slots.
The model refuses a hello to an unpaired receiver; §14.1 says each
process checks the places with its own environment and both must pass.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
…, not a pattern Code scanning flagged `/[. ]+$/` on a rule's folder: on a long run of dots and spaces that does not reach the end of the segment it tries again from each of them. A folder is at most a few hundred characters, so the cost was small, but a loop has none and says the same. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
…notice's history `sessionpipe trigger list --json` and `trigger test --json` print config.proto's TriggerList and TriggerTestAnswer. tools/doors now generates their schemas beside the rules file's (CONFIG_SCHEMAS: `trigger-list`, `trigger-test`), so the CLI checks what it prints against the definition and no longer against a copy put together by hand, which disagreed with the proto (a missed tick made `list --json` throw). The scenario files under conformance/triggers stated the history of clock rules only. Every run and refusal of a rule that took the cause goes to its history (§14.10), a notice's with its subject and state: the model in trigger-fixtures.test.ts now keeps those lines, and the files carry them (written from the model with SESSIONPIPE_WRITE_TRIGGER_HISTORY=1, then read in the diff). An engine that runs the files compares them too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
… is its own describeRule cut the folder and the words to the terminal's width and left the sentence whole, so each CLI folded it its own way. It cuts the sentence too now, at spaces, every line at the left edge and never behind a mark: every machine prints a rule the same, and a CLI prints the lines as they come. hiddenProblem said "a space pasted from a web page" of every hidden character. It says what to do by the kind of character: a space other than U+0020, an emoji's joiner or variation selector (a red heart carries one, the common honest case), marks stacked on one character, or text copied from a chat or a page. CONTROL.md §14: a rule that continues a session runs in that session's folder, so its folder is the session's recorded folder, written by `add` and checked (floor and allowlist) on the folder the run really uses; a clock rule's first tick is the first after the daemon has seen the rule (a rule records no time it was made); and the local socket may lift a pause the machine made itself without a terminal test, which §14.1's limits paragraph now says. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
…drops waits as no_match - The scenario model's sessions may say their folder; run-session-folder.json runs a rule whose session's folder is its own and refuses folder for one whose session's folder is no longer the rule's. - §14.7: a rule paused, removed or changed under the same name drops its waiting runs with their counts given back, a notice among them acked no_match, never triggers_off. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
TriggerLine in config.proto (the line, and the words it splits into) is what `sessionpipe trigger line <name> --json` prints; its schema is generated with the others. §14.1 names the command, the fixed flag order and the quoting rule, since a program reads the line back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
…l counts them, a sentence never cut inside a token - hiddenIn says why a character was refused (hidden, or a mark past the fourth); the stacked-marks hint is for that only. The emoji hint is for an emoji's own selector, joiner and flag tags; any other variation selector gets its own hint. - columnsOf counts a spacing mark one column and Unicode 16's new wide characters two. - describeRule cuts the sentence at spaces only: a token wider than the width starts its own line and goes on behind the mark. Asked for under 40 columns, it says the description is too narrow to confirm. - A hello's topics are sorted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
…ve their fixtures - A rule paused, removed or changed (in what decides a run) drops the runs taken for it that have not begun: the count back, a notice told no_match, a history line `dropped` (a new TriggerResult) while the rule is in the file. The count rule, the no_match row and the §14.12 model say so; run-waits.json has the cases. - trigger-line.json fixes `trigger line`: the flag order, the defaults written, lists joined by a comma, POSIX quoting that zsh reads too (a value starting with = is quoted), a value starting with - written --flag=<value>, a line feed kept inside its quotes. Core's triggerLine and shellWord make it; TriggerLine has real limits. - Step 12: a continued session's folder, compared as real paths, known, the rule's and allowed. Every scenario session says its folder; Codex cases say Codex takes no edits. - The clock counts from when the daemon first saw a rule, kept across restarts; an interval's first tick is one interval later (a case). - Topics are sorted; reordering rules sends no hello (a case). - The output messages are strict; TriggerList says why a rules file can't be read (`problem`). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
kombuchapunk
force-pushed
the
triggers/definition
branch
2 times, most recently
from
November 25, 2026 22:29
7bb2012 to
a9bbc42
Compare
…d fixtures Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
kombuchapunk
force-pushed
the
triggers/definition
branch
from
November 25, 2026 22:36
a9bbc42 to
c488b97
Compare
Collaborator
Author
|
Superseded by #380 (rebased onto |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Draft. It will not merge before 2026-12-02, when the seven days of the spec proposal (#339) end. It is open now so the proposal has exact text to read and so the whole CI matrix runs on it. Design: RFC 0004 (
docs/rfcs/0004-triggers.md).Nothing here runs anything yet: this is the definition that the commands, the clock and the daemon's handling of notices are being built on.
What it defines
On the wire (
control.proto,events.proto,http.proto; schemas and types regenerated, additive,buf breakingclean):ControlNotice, strict:id,topic,event,subject, optionalstate,for,by,at,expires_at. Any other member, or a broken one, drops it.ControlPoll.notices(at most 50),ControlHello.triggers(on,topics), the ackPOST {control}/notices/ackwith a closed outcome (ran,taken,no_match,duplicate,expired,refused,failed) and a closed refusal code.Session.triggered_by: the rule's name. Lineage, never authority.ControlInfo.notices: a receiver says it sends notices.On the machine only (a new
config.proto, never published underschemas/v1):TriggerRule,TriggersFile, and the messagestrigger listandtrigger testprint as--json.Spec: CONTROL.md §14 "Triggers" (each rule tied to the principle of §1 it keeps and to a fixture), HTTP.md §3.
Pure functions in core (
packages/core/src/triggers/): read and check a notice against the generated schema; read and check a rules file; say a rule in plain words; match; the level a run gets; compose the framed words.Fixtures:
conformance/triggers/*.json(scenarios an engine runs, checked here by a small model of §14.7) and the vector171-kind-trigger.json(a correctly signedtrigger.addcommand isunknown_kind: no command makes a rule).Decisions beyond the RFC, each in the spec
busyat its deadline.edits), the session's recorded level and what the harness takes. A level the machine does not know gives no run. So a rule that asks foreditsedits only on a machine whose mode isauto.addand at every run. A floor, not a guarantee.What the spec says it cannot promise
control.jsontoday.claude -pwas not measured (its allow rules do not count: control: a safe run says why a folder's own allow rule did nothing #340).Checked
npm run test:coverage: 4,587 tests pass, coverage 100 %. Schemas in sync, biome and typecheck clean,buf breakingagainst main clean, 321 conformance fixtures, fixture scan clean, build, site.Not checked
path.win32on macOS.🤖 Generated with Claude Code