Skip to content

feat(triggers): definition, local CLI commands, clock, and daemon engine (RFC 0004) - #380

Merged
kombuchapunk merged 32 commits into
mainfrom
triggers/local-rebased
Dec 4, 2026
Merged

kombuchapunk merged 32 commits into
mainfrom
triggers/local-rebased

Conversation

@kombuchapunk

Copy link
Copy Markdown
Collaborator

Summary

Rebases #345 (triggers/local, carrying #341 triggers/definition + 12 local commits) cleanly onto main (9708098) after the 7-day lazy-consensus window for #339 elapsed on 2026-12-02 with no objections, fixes all Windows & coverage CI failures, and addresses all multi-model QA findings (Fable 5.2 xhigh + Gemini 4 Neon).

Supersedes #341
Supersedes #345
Refs #339

Rebase & Integration Highlights

  • Proto & doors: moved ControlHello.triggers to field 18 (skills holds 17), merged config.proto cleanly with main's local config/update messages, added LocalTriggerRequest (LocalRequest.trigger = 12) in local.proto for main's socket door, and added CLI-only trigger_service.proto (including rpc Line) wired into tools/doors -> shared/doors.json. buf breaking vs origin/main and buf lint pass.
  • Daemon & lineage: preserved main's childEnv (reply_to local lineage fix) and skills in daemon.ts, propagated triggered_by lineage cleanly inside if (!session.parent_id) in run.ts, and removed the unreachable entered ? ran : null branch in daemon.ts.
  • Windows & lockfile fixes:
    • Added cross-platform ruleFolder() (packages/core/src/triggers/rules.ts) and hardened folderKey() (packages/cli/src/control/triggers.ts) so rule folders normalize to ~/~/... with / and case-fold cleanly on win32 and darwin.
    • Fixed non-dangling symlink lockfile recovery (lstatSync(aside).isFile()) and made offline trigger resume acquire triggers-state.lock before modifying triggers-state.json.
    • Updated lock/path tests for Windows (process.pid instead of PID 1, realpathSync.native for 8.3 temp paths).

Verification

  • Audited by Fable 5.2 (xhigh) and Gemini 4 Neon against built dist.
  • npm run lint (0 errors), npm run typecheck, npm run build, npm run schemas -- --check (31 files), buf breaking, npm run conformance (367 fixtures), npm run fixture-scan (421 files), and full monorepo npm run test:coverage (5,344 tests, 100% Stmts / Branch / Funcs / Lines).

Note: Slice 4 (daemon receiver notice polling/dedup/ack + hello.triggers + receiver notices state machine) follows immediately in the next PR before any public release.

kombuchapunk and others added 30 commits December 4, 2026 08:21
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>
…d fixtures

Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
`<config>/triggers.json` (CONTROL.md §14.1) gets its home beside
control.json: read whole or not at all through core's readTriggers (not
there is none, a file that does not fit is refused with every problem,
and both are triggers off), and written whole through the same private
writer control.json uses, after checkTriggers says it would read back. A
file that would not is never written.

The writer now sets 0600 on the temporary file before it renames it into
place, so a temporary file left behind by a crash can never carry another
mode onto the real one.

The daemon's own record of the rules' runs gets its path beside its other
state (triggers-state.json): the daemon writes it, the CLI only reads it.
A pause the machine makes itself (a rule whose session is gone, §14.7 step
11) is kept there, so the rules file stays exactly what the person
confirmed at the terminal.

`harnessSession` is the guard every command that changes a rule uses: the
variables `ask on` checks (Claude Code's and Codex's session ids, the
daemon's job mark) and Claude Code's own CLAUDECODE. It stops an honest
session doing it by accident; it is no proof that a person typed it.

`allowedIn` is the daemon's folder rule (real paths, whole segments, `~`
read under this user's home), moved where the CLI can ask it too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
The daemon runs the person's rules (CONTROL.md §14). One module,
control/triggers.ts, as injectable as the daemon's other parts: one entry,
fire(rule, cause), where the cause is a clock tick now and a notice a rule
took later, with §14.7's checks that are not about the wire in order (on,
paused, the cooldown for notices, the cap, the folder, the harness, the
session to continue). A run counts from the moment it is taken and gives
its count back if it ends without running. Then the run, or a wait: for
room under the machine's caps on starts (shared with receivers' starts and
asks), or for a window to let go of the session a rule continues. Waiting
runs are kept in the daemon's own record and wait again after a restart;
at their deadline (a notice's expiry, six hours for a tick) they end with
their refusal. A rule whose session is gone is paused in that record, never
in the rules file, and `trigger resume` lets go of it over the local socket.

The clock (control/clock.ts) works each tick out afresh from `every` in
the machine's local time, so nothing drifts; a tick missed while asleep
runs once on waking under six hours late, else a `missed` line; the last
tick is recorded before the run, so a restart never runs it twice. A time
the night skips runs as the clock jumps past it; a repeated one runs once.

The seam with ask. runTrigger begins a run down the paths onAsk takes:
startSession for a start, the session's line and prompt() for a session
continued, with an AckSink of the daemon's own. What differs, and nothing
else: the level is triggerRun's (the rule's narrowed by its source, the
machine's mode and the session's own level, then fitted to the levels the
harness takes here, the hello's start.<harness>.permissions) where an ask is safe at most; the rule's MCP
tools are allowed (read through sessionToolsFrom, as a receiver's are);
the words come framed by the rule; the environment carries
SESSIONPIPE_TRIGGERED_BY and no ask lineage; and only a turn the daemon runs
itself is taken (`ownTurns`: resume, or an Agent SDK session opened no
wider than the run), never a waiter, a Stop, an inbox, a channel, a fork
or Codex's queue. The level still goes through startChoice, so it is never
above the machine's mode, and neither an ask nor a receiver can name that
sink. ACP agents are not run by rules yet: they take no level here and
would run at the machine's mode.

One run of a rule at a time: a rule's next run waits while its last one
is still going, and at its deadline is refused `busy` (the code the
definition's next round adds), its count given back. A run handed to the
daemon that waits for the machine's headless slot has not begun: it is
taken, and at its deadline stopped and refused start_limit. The machine's
own pause says why (the session is gone, or its recorded level is one this
machine doesn't know, which `trigger resume` cannot clear).

The folder is checked at every run with the definition's
realFolderProblem (real paths, the floor's places as the daemon's own
environment names them) as well as the allowlist.

`triggers off` drops every waiting run and stops running triggered turns
the way a cancel stops a turn the machine runs. Nothing on this path
answers a permission prompt (a test sends one into a triggered run).

All fourteen scenario files under conformance/triggers run against the
engine, from the files themselves, every expectation of every step. Steps
1 to 6 of §14.7 (the id, the switch, the shape, the expiry, the dedup, the
match) are the notices step's: the test does them as that step will, and
calls fire(). The files state the history of clock rules only, and one
expectation disagrees with the spec (a machine's pause and the hello at
once): the spec's word is followed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
…test

The person's rules at this computer's terminal (CONTROL.md §14.1), in
today's hand-written pattern (RFC 0001's step 3 is not built), with
--json on list, status and test printing config.proto's TriggerList and
TriggerTestAnswer, checked before they are printed.

Who may run what: add, resume and triggers on widen what this computer
does by itself, so each needs an interactive terminal, shows what will run
and takes a typed yes, with no flag to skip it. Every command that changes
a rule refuses inside a harness session (the guard `ask on` uses, and
CLAUDECODE). pause, remove and triggers off only narrow, and need no
terminal, as `ask off` needs none. list, status and test run anywhere.
Both guards keep an honest session from doing this by accident; neither is
proof that a person typed it, and no text here claims more.

add checks what a run would and says what to do when it refuses: the
folder (the definition's floor, then the allowlist, then the floor again
by the folder's real path, so a link into sessionpipe's own folders is
caught), the agent runnable headlessly here (an ACP agent not yet: it
takes no level here), the receiver paired by its host, never two pairings
of one name and never a bracketed IPv6 host, the session to continue. It
warns when the receiver's well-known file doesn't say it sends notices,
and when the words name {state}, {for} or {by} that the rule doesn't
require. It says what it writes when --level or --cap is not given.

The level a rule really runs at here is said in add, resume, triggers on,
list and test, from the definition's triggerLevel with the levels each
harness takes here (the background service's own word, else Codex's and
Antigravity's by the mode), and why when it is narrower than the rule
asks: the machine's mode, the source's ceiling, or an agent with no such
level. What the level means for that agent is said too (Codex's safe is
its workspace sandbox, which writes files in the folder).

What a person reads is what runs: every rule, folder and word shown goes
through core's visible(), its escapes marked, and the person's words are
never coloured as commands. list shows each rule in a line with its runs
today, paused by the person or by this computer (and how to resume), and
its latest five history lines in this computer's time; a rules file that
can't be read is said, never written over.

`ask off` keeps the background service while triggers are on.
sessionpipe-core/schema exports CONFIG_SCHEMAS for the CLI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
One row in "This computer", in the commands' own style, and only once
there is a rules file, so a computer with none reads exactly as before
(every existing snapshot is unchanged): `triggers  on · 2 rules, 1
paused` (status: `triggers on (2 rules, 1 paused)`), `off · … ·
\`sessionpipe triggers on\` turns them on`, or, for a file that can't be
read, a warning with what to do. Paused counts the person's pauses and
this computer's own (the daemon's record). doctor --json gains
`triggers: {on, readable, rules, paused}` the same way.

With triggers on the background service is needed, as it is for a
receiver, the pool or asking, so doctor says when it isn't running.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
CONFIG_SCHEMAS and the checker are exported from sessionpipe-core
itself, so the CLI's build reaches them as it reaches everything else
of core (the schema subpath has no build of its own).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
…record stops the service

- A continue run that waits in its session's line is a waiting run:
  taken, counted, ended by its deadline, dropped by triggers off with
  its count given back (a stopped flag checked when its turn comes).
- A rule's turn never goes into a session something else holds (the
  look and prompt() both say held); a session a rule opened through
  the Agent SDK takes no other turn and is closed when the rule's turn
  ends. begin() comes before the send.
- A continued session's own folder is the run's: refused folder unless
  it is the rule's, allowed and over the floor.
- triggers-state.json is read deeply (trigger-state.ts): what does not
  fit is dropped and logged; counts, deadlines and clocks clamped; a
  waiting run of the wrong cause dropped; a 4 MiB cap, and 2 MiB on
  triggers.json. Every engine entry point in the daemon is guarded.
- Names from files key null-prototype maps; a waiting run carries its
  rule's fingerprint and is dropped, acked no_match, when the rule
  under that name changed; the record is written only when it changed.
- The daemon's tests drive a real permission prompt and a real ask
  from the triggered run's environment, and wait on the engine's own
  clock rather than the wall clock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
…en over a change

- add resolves the session's folder, shows it on the folder line and
  writes it; another --folder is refused with what to do.
- add, resume and triggers on read the file again after yes: changed
  meanwhile, nothing is written and the person is told to run it again.
- triggers on runs the terminal check first, even when already on.
- --json is checked against the generated TriggerList and
  TriggerTestAnswer schemas; the hand-built copy is gone. A history
  line with a code this version doesn't know is said as such.
- A receiver's error text is never printed (a fixed sentence instead),
  and every value shown from a file goes through visible().
- A clock rule added while the service isn't running says when its
  first tick is. control off keeps the service while triggers are on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
…ncy throws wedges the engine

- Waiting runs read from the record are checked against the rules: a
  tick that is no tick of its rule's clock, one there twice, or more for
  a rule and day than its cap (the oldest kept) are dropped and logged.
- retry() lets go of its flag in finally; a look that throws leaves its
  run waiting in its place. Every call out of the engine (the look at a
  session, the folder, the harnesses, the run, an ack, the hello, a
  history line, a cancel) is guarded: a fire that throws says the run
  could not begin, and the next tick runs.
- A run handed over whose turn has not begun (a session's line, the
  headless slot) goes back to the waiting runs when the daemon stops,
  its count held; its count is saved when it is queued.
- A rule paused, removed or changed drops its waiting and queued runs,
  a notice among them told no_match; off stays triggers_off.
- The fingerprint is of what a run does, in one spelling: key order,
  defaults and the pause change nothing.
- Every waiting run the record or the rules drop goes through one place
  that tells its notice: no_match, expired, or refused cap.
- The engine's scenario runner gives a session its folder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
… writers take a lock

- `sessionpipe trigger line <name>` prints the one `trigger add` line,
  alone on stdout: flags in a fixed order, a value bare only when it
  holds nothing but A-Za-z0-9_./:@=+-, else in POSIX single quotes.
  `--json` prints TriggerLine. Read-only: no terminal, no yes. Tested by
  a POSIX word-splitter feeding the line back to add, for every rule in
  the scenario files and a set of hostile ones.
- Every command that writes the rules holds triggers.json.lock around
  its last read and its write; another command meanwhile is refused,
  and a lock older than 30 s is broken and said.
- A rule name nobody has says the nearest ones.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
… the rules, and no stored day is trusted

- RunEvents.ready(): the daemon asks the moment a handed-over run would
  begin. Its rule must be there, unpaused and the same (fingerprint),
  and the folder, harness, session and level as they are now; else it
  is dropped as no_match with its count back and a `dropped` line. A
  queued run of a rule changed under the same name is dropped at load.
- Agent SDK: a start waiting for the headless slot stays a run in hand
  until it has the slot, so off and its deadline stop it (the claude -p
  path already did). Every queued-to-began path checked: claude -p
  start, SDK start, a continue through the session's line, Codex via
  ownRun; ACP is never a trigger's.
- suspend() makes the engine inert: no tick, retry, load, fire, lift or
  save after it, every callback a no-op.
- The engine is made only once the daemon holds the record's claim
  (triggers-state.lock, lockfile.ts: O_EXCL, an owner token, a dead
  owner's claim broken by rename); one that steps aside never reads,
  runs or writes the record.
- On load, each waiting run's day is its cause's own (a tick's due, a
  notice's at) in this zone; the cap counts what ran today and what
  waits; ticks not of the clock or six hours old, notices expired or
  not taken by their rule, are dropped through the one ack place.
  Record copies are dropped as read, told nothing.
- Acks go only to notices this machine received, one final each. A
  tick whose record can't be saved does not run. retry() puts back
  whatever it had not looked at when something throws. Hello topics
  compare as a sorted set.
- A rule paused or changed writes `dropped` for its waiting runs; the
  scenario runner compares history in order within a rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
… knows its owner

- `trigger line` is written as its bytes at a terminal of any width
  (cli.ts treats it as output for a program) and made by core's
  triggerLine: a value starting with = is quoted, one starting with -
  is written --flag=<value>, which add now takes for every option.
- It runs add's checks (buildRule, shared with add): a rule add would
  refuse here is refused with why; a rule spelled otherwise than add
  writes it is printed as add writes it, with a note on stderr.
- The rules' lock is lockfile.ts: an owner token, released only by its
  holder, a dead owner's lock or a link or one from the future broken
  at once by rename, a folder there said with what to do.
- list says a dropped run; list --json carries why the rules file
  can't be read (`problem`). A terminal too narrow for a rule's lines
  shows nothing to confirm and says to widen it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
…n floor, ready refusals, queued crash safety)

Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
…hold on Windows

- trigger add wrote a folder under home with the system's separator, so on
  Windows the rules file, the confirmation, the control folders add hint and
  trigger line said ~\work\acme. CONTROL.md §14.1 names ~/…, and trigger line
  is read back on other computers: core's ruleFolder writes ~ or ~/… with /
  between segments on every system; a folder outside home stays as it is.
- trigger line no longer notes a spelling difference on Windows for a rule
  written ~/…, since add now writes it that way too.
- The lock tests named pid 1 as a running owner; Windows has no pid 1, so the
  lock read as one whose command had ended. They name this process instead.
- allowedIn returns the real path (realpathSync.native), which on Windows is
  the long name of an 8.3 temp folder: the test's folder is read the same way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
kombuchapunk and others added 2 commits December 4, 2026 08:42
…d after the rebase

- local.proto validates every socket line (main's socket door), so a trigger
  op other than resume, or a name outside the rule pattern, is no request and
  the connection closes unanswered; the daemon no longer checks the action.
- setup.test bundles the CLI with @sessionpipe/core/schema aliased again: main's
  socket door and MCP handlers import it.
- An Agent SDK resume is let go of the moment it has the slot, so no stop can
  find it afterwards; the flag that said whether it had entered is gone, as
  its true side could never be reached (CI's uncovered branch).
- The engine's catch around a clock rule's tick is covered by a unit test (a
  rule whose every no reader let through) rather than by the daemon test's
  timing, which Ubuntu on Node 22 missed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
…laim, one folder spelling, link locks)

- trigger_service.proto has rpc Line (`trigger line <name> [--json]`), so the
  command has its usage line and the generated trigger parent names it.
- trigger resume with no daemon answering writes the record only under the
  daemon's claim (triggers-state.lock): a busy daemon holding it is refused
  with what to do, never written over; a rule no longer in the record, or no
  longer paused there, is left alone.
- ruleFolder compares resolved paths (a trailing separator dropped, a root's
  kept, C:/x read as C:\x) and, on win32 and darwin, without regard to case.
- The fingerprint's folder key expands ~ with expandFolder and resolves in the
  platform's syntax, in one form and case on win32 and darwin, so ~/work/acme
  and C:\Users\Alice\work\acme are one rule's folder on Windows too.
- A lock judged not a file (a link, dangling or not) is checked with lstat
  after it is renamed aside, never read through its link and put back.
- A live owner's lock with a future time stays unbroken, as round 4 decided;
  the header now says so (it still listed a future time as stale).
- Unused DescFile import gone; LocalTriggerRequest's shape pinned in the
  socket door test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
@kombuchapunk
kombuchapunk merged commit e393d2f into main Dec 4, 2026
18 checks passed
@kombuchapunk
kombuchapunk deleted the triggers/local-rebased branch December 4, 2026 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant