Repository navigation
feat(bin): add slack-captain process-event-source adapter - #4
Merged
Merged
Conversation
Register a bounded long-poll of a configured Slack channel as a process-event source, so a message the captain posts there reaches firstmate as an ordinary check wake. The source is never terminal, so a quiet channel exits nonzero with no output and the runner's reconcile re-arms it without publishing an empty wake. The poll child never advances the stored read position; that happens only after the result is durably captured, so a crash cannot skip messages, and a result that does not continue the stored position is refused loudly rather than rebased. The bot token is read from the home's .env inside the poll child and handed to curl on stdin, so it never reaches argv, a registration record, a captured result, or a diagnostic. Channel and identities are configuration, and any author other than the configured captain is marked untrusted in the result and distinguished by classify.
…rface jq failures
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.
Intent
Build the slack-captain process-event-source adapter for firstmate, so messages the captain posts in the Slack #captain channel wake the primary firstmate. This changes firstmate's SHARED TRACKED material, so the firstmate-coding-guidelines skill applies throughout: one-owner rule (every contract stated in full exactly once, other mentions are one-line cross-references), the knowledge-placement decision tree, shellcheck clean via bin/fm-lint.sh, the bin script header owns exact mechanics rather than prose elsewhere, and one full sentence per line in tracked Markdown.
Deliverables, all in this one PR:
Explicit constraints the captain set, which a reviewer reading only the diff would not know:
Deliberate design decisions I made while implementing, which differ from that prototype on purpose:
Verification performed beyond the unit tests: the full path was exercised against the real Slack API read-only in a throwaway home, proving arm, runner start, real conversations.history call, 0600 capture, wake publication, classify reporting messages with the configured captain trusted, handle advancing the cursor and recording the acknowledgement, and the source remaining armed afterwards.
What Changed
bin/fm-procevent-slack-captain.sh, a process-event-source adapter that polls the Slack #captain channel and wakes the primary firstmate: arm registers the source and spawns a bounded poll child with cursor-file continuity (cursor advances only in handle/autohandle after the runner captures the result; cursor breaks fail loudly), classify distinguishes messages / untrusted-messages / empty / api-error / unknown and is never terminal, and the token is read from.envviafmx_env_getand passed to curl on stdin so it never appears in argv or logs. Messages from anyone other than the configuredallowed_userare marked untrusted, and message text is treated purely as data.tests/fm-procevent-slack-captain.test.shwith a fake-curl PATH shim (no network in CI), covering new-message capture with cursor advance, bot-post filtering, non-allowed-user untrusted marking, cursor-break loud failure, and token-absent refusal.FM_SLACK_CAPTAIN_MAX_PAGEStuning variable indocs/configuration.md, and a one-line arming entry in the process-event-sources SKILL.md.Risk Assessment
✅ Low: All three authorized round-1 fixes are correctly implemented with behavioral regression tests, the pagination invariant and security constraints (token on stdin only, bounded runtime) are preserved, and the only residuals are a one-line doc omission and a deliberate bounded-refusal trade-off.
Testing
Ran the adapter's colocated behavior suite (16/16 pass, network replaced by a PATH curl shim) covering capture with cursor advance, bot filtering, untrusted marking, cursor-break loud refusal, token-absent refusal, pagination, api-error handling, and a runner round-trip; then performed a manual end-to-end demonstration through the generic runner and recorded a transcript showing arm, capture with 0600 perms, wake publication, classify, token confinement to stdin, handle advancing the cursor, and the source remaining armed. No screenshot applies — this is a CLI/daemon change with no rendered surface; the CLI transcript is the end-user surface.
Evidence: End-to-end CLI transcript: arm → runner capture → classify → handle
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-procevent-slack-captain.sh:273- cmd_poll issues a single conversations.history call with limit=$PAGE_LIMIT (default 200) and ignores has_more. Slack returns newest-first, so a burst of more than PAGE_LIMIT messages past the cursor drops the oldest ones while to_ts commits the newest timestamp; handle then advances the cursor past the never-captured messages — silent loss within retention, contradicting the intent's cursor-continuity/no-loss-within-retention requirement. Fix at the poll boundary: detect has_more (or count == PAGE_LIMIT) and paginate to exhaustion, or cap to_ts at the oldest fetched message so the next poll captures the remainder.bin/fm-procevent-slack-captain.sh:392- An api-error result can never be acknowledged through the adapter: apply_result dies for any class other than messages/untrusted-messages, yet the new SKILL.md line names the adapter's handle as "the required handling command". An api-error wake therefore re-announces indefinitely unless firstmate bypasses the adapter with raw fm-procevent.sh handled. Either let handle acknowledge api-error (the cursor advance is already a no-op since from_ts == to_ts) or document the intended retirement path in the header/SKILL — this challenges a deliberate design choice, so asking the author.bin/fm-procevent-slack-captain.sh:290- When the ok:true jq extraction pipeline fails (e.g., a malformed message ts breaks tonumber),|| : > "$payload"treats the page as empty and the bounded loop silently retries until no-traffic exit. No cursor advance occurs so nothing is lost, but a persistently malformed page degrades into quiet no-result cycles with no diagnostic; a one-line stderr note or die on repeated jq failure would surface it.🔧 Fix: paginate poll windows, acknowledge api-error, surface jq failures
2 infos still open:
docs/configuration.md:503- docs/configuration.md's Slack captain section enumerates the tuning variables FM_SLACK_CAPTAIN_MAX_LOOPS, INTERVAL, MAX_TIME, and PAGE_LIMIT, but omits FM_SLACK_CAPTAIN_MAX_PAGES introduced by the pagination fix (referenced in the adapter header). Add it to the list to keep the enumeration complete.bin/fm-procevent-slack-captain.sh:317- When a window past the cursor exceeds FM_SLACK_CAPTAIN_MAX_PAGES (default 25 pages, ~5000 messages), every poll dies loudly and the source re-arms into the same refusal until an operator intervenes. No message is lost and the intent forbids an unbounded fetch, so this is a deliberate bounded-runtime trade-off, not a defect.✅ **Test** - passed
✅ No issues found.
bash tests/fm-procevent-slack-captain.test.sh (16/16 pass, fake curl PATH shim, no network)manual e2e: arm → fm-procevent.sh start → captured 0600 result → classify=messages → wake-queue entry → handle advances cursor → source still armedtoken confinement check: token absent from curl argv and captured result, present once on curl stdin via --config -docs presence check: SKILL.md arming line and docs/configuration.md config/slack-captain sectiongit status clean after cleanup of temp home and shim✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.