Phase 1 — dedup + hardening (~9 items): - Remove duplicate *skill-registry* defvar from core-skills - Merge *backend-registry* into *probabilistic-backends*, delete backend-register - Remove inject-stimulus alias, standardize on stimulus-inject - Add pre-eval sandbox (skill-source-scan) blocks restricted symbols before eval - Remove dead plist-get function; remove duplicate json-alist-to-plist export - Fix read-framed-message whitespace DoS (4096-iteration max) - Add *read-eval* nil to dispatcher-approvals-process read-from-string (RCE) - Add test-op to ASDF; update .asd version 0.4.3→0.7.2 Phase 2 — prose + contracts + reorder: - Split ROADMAP: 2623→1089 lines (TODO only), CHANGELOG: 260→1528 lines (full DONE history, 14 versions reverse chron) - Add Contracts + Overview to 6 channel files + embedding-native + programming-standards + symbolic-scope - Reorder 28 .org files: Contract → Test Suite → Implementation (TDD order) - Add 7-phase inline prose to think() in core-reason - Expand USER_MANUAL: 183→461 lines (10 new sections) Phase 3 — decomposition + export organization: - Decompose think() into think-assemble-prompt, think-call-llm, think-parse-response orchestrator - Organize 188 exports into 16 grouped sections by module Phase 4 — budget enforcement + error protocol: - Per-session budget enforcement (SESSION_BUDGET_USD env var, budget-exhausted-p, guard in think-call-llm) - Error condition hierarchy (6 conditions: pipeline-error, llm-error, gate-error, budget-error, protocol-error) - Restarts in loop-process: skip-signal, use-fallback, abort-pipeline
87 lines
3.8 KiB
Org Mode
87 lines
3.8 KiB
Org Mode
#+TITLE: Channel Slack (channel-slack.org)
|
|
#+AUTHOR: Agent
|
|
#+FILETAGS: :channel:slack:
|
|
#+PROPERTY: header-args:lisp :tangle ../lisp/channel-slack.lisp
|
|
|
|
* Channel Slack
|
|
|
|
Extracted from gateway-messaging in v0.5.0. Isolated platform — Slack-specific poll and send logic.
|
|
|
|
* Overview
|
|
|
|
The Slack channel provides bidirectional communication via the Slack Web API
|
|
(chat.postMessage for outbound, conversations.history for inbound polling).
|
|
Messages from Slack channels are injected into the cognitive pipeline as
|
|
~:user-input~ signals with ~:source :slack~. Outbound messages route through
|
|
the actuator registry when the pipeline targets ~:slack~.
|
|
|
|
The channel uses two functions: ~slack-poll~ (inbound sensor) and ~slack-send~
|
|
(outbound actuator). Both retrieve the bot token from the credentials vault.
|
|
HITL commands are intercepted before injection so approval flows work identically
|
|
across all channels.
|
|
|
|
** Contract
|
|
|
|
1. (slack-get-token): returns the Slack bot token from the vault
|
|
(via ~vault-get-secret :slack~), or nil if not configured.
|
|
2. (slack-poll): polls configured channels via conversations.history,
|
|
injects each non-bot message as a ~:user-input~ stimulus with
|
|
~:source :slack~. Handles API errors gracefully. HITL commands are
|
|
intercepted before injection.
|
|
3. (slack-send action context): sends a message via chat.postMessage.
|
|
Extracts ~:channel-id~ and ~:text~ from the action plist. Uses Bearer
|
|
token authentication. Logs send failures without crashing the pipeline.
|
|
|
|
* Implementation
|
|
|
|
#+begin_src lisp
|
|
(in-package :passepartout)
|
|
(defun slack-get-token ()
|
|
(vault-get-secret :slack))
|
|
|
|
(defun slack-send (action context)
|
|
"Sends a message via Slack Web API."
|
|
(declare (ignore context))
|
|
(let* ((payload (getf action :payload))
|
|
(meta (getf action :meta))
|
|
(channel (or (getf meta :channel-id) (getf payload :chat-id)))
|
|
(text (or (getf payload :text) (getf action :text)))
|
|
(token (slack-get-token)))
|
|
(when (and token channel text)
|
|
(handler-case
|
|
(dex:post "https://slack.com/api/chat.postMessage"
|
|
:headers `(("Authorization" . ,(format nil "Bearer ~a" token))
|
|
("Content-Type" . "application/json; charset=utf-8"))
|
|
:content (cl-json:encode-json-to-string
|
|
`((channel . ,channel) (text . ,text))))
|
|
(error (c) (log-message "SLACK ERROR: ~a" c))))))
|
|
|
|
(defun slack-poll ()
|
|
"Polls Slack for new messages via conversations.history."
|
|
(let* ((token (slack-get-token)))
|
|
(when token
|
|
(dolist (channel '("general")) ;; configured channel IDs
|
|
(handler-case
|
|
(let* ((url (format nil "https://slack.com/api/conversations.history?channel=~a&limit=5" channel))
|
|
(response (dex:get url :headers
|
|
`(("Authorization" . ,(format nil "Bearer ~a" token))))))
|
|
(let* ((json (ignore-errors (cl-json:decode-json-from-string response)))
|
|
(ok (cdr (assoc :ok json)))
|
|
(messages (cdr (assoc :messages json))))
|
|
(when (and ok messages (listp messages))
|
|
(dolist (msg messages)
|
|
(let* ((text (cdr (assoc :text msg)))
|
|
(user (cdr (assoc :user msg)))
|
|
(ts (cdr (assoc :ts msg))))
|
|
(when (and text user (not (string= user "USLACKBOT")))
|
|
(unless (ignore-errors (hitl-handle-message text :slack))
|
|
(stimulus-inject
|
|
(list :type :EVENT
|
|
:meta (list :source :slack :chat-id channel)
|
|
:payload (list :sensor :user-input :text text))))))))))
|
|
(error (c) (log-message "SLACK POLL ERROR: ~a" c)))))))
|
|
#+end_src
|
|
|
|
|
|
#+end_src
|