Repository navigation
Approval demo #718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
khaliqgant
wants to merge
19
commits into
main
Choose a base branch
from
demo/nabis-flow/uc1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,879
−7
Open
Approval demo #718
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
6404734
Add local Nabis UC1 Slack approval demo
khaliqgant fb79d8f
Reconnect the UC1 journal before processing Slack approval
khaliqgant 0d3a3bc
Validate UC1 coder output and verify approval across daemon restart
khaliqgant 27c9fc5
Keep UC1 model invocation read-only and paginate journal reads
khaliqgant 31e0ab6
Capture UC1 approval and helper replay regression receipts
khaliqgant 70f329d
Surface daemon attach warnings in the UC1 bridge
khaliqgant b93e121
Pin UC1 to the supported Codex model pair
khaliqgant 5008a07
Ignore empty PATH entries in the UC1 bridge
khaliqgant ee42845
Refuse a shim-only PATH in the UC1 verifier
khaliqgant f3b5edb
Run Nabis UC1 from a scoped Slack mention
khaliqgant 95abfe8
Expose Nabis UC1 runs through the Flows CLI
khaliqgant 5cc9be2
Retain UC1 Slack callbacks for safe retry
khaliqgant 407f80f
Support native hosted Slack intake for Nabis UC1
khaliqgant bd08c23
Trigger hosted Nabis UC1 from a Slack app mention
khaliqgant 96ce4a2
Correct the UC1 Slack mention instructions
khaliqgant b1f0375
Wait for the hosted UC1 Slack mirror on cold start
khaliqgant 7ffa843
Post the hosted UC1 run link before the first agent step
khaliqgant 854c854
Address UC1 Slack listener and run link review
khaliqgant 12cf8a4
Normalize the hosted UC1 dashboard link like the SDK
khaliqgant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,201 @@ | ||
| # Nabis UC1 — pickup routing demo | ||
|
|
||
| A Slack message starts a run for a fictional pickup-routing change. A planner | ||
| generates a task graph at runtime. Coders run in dependency order and produce a | ||
| JSON rule table. The demo asks the coders to omit the held-pickup rule on the | ||
| first pass. A reviewer rejects that omission, a repair agent adds the rule, and | ||
| a second review and deterministic routing checks must both pass. | ||
|
|
||
| The thread shows the lead's assignments, the first coder build, the reviewer's | ||
| send-back, the repair, the approval pause, and the lead's summary. Flows | ||
| posts the approval prompt in the originating thread and parks on | ||
| `f.human`. A verified reply from the designated user must match the | ||
| workspace, channel, thread, and open wait. The local bridge also checks the run reference. Approval records | ||
| the repaired table as a simulated shipment in the local journal. Decline | ||
| closes the run without a shipment record. Both paths reply in the same thread | ||
| with **Done**, **Next**, and **Blocked**. | ||
|
|
||
| ## Build from the checkout | ||
|
|
||
| Use Node 22.18 or later, Bun, npm, and Rust. From the repository root: | ||
|
|
||
| ```sh | ||
| (cd packages/surface && bun install --frozen-lockfile --ignore-scripts && bun run build) | ||
| npm ci --prefix packages/sdk --ignore-scripts | ||
| npm install ./packages/surface --prefix packages/sdk --no-save --ignore-scripts | ||
| npm run build --prefix packages/sdk | ||
| mkdir -p node_modules/@relayflows | ||
| ln -sfn ../../packages/sdk/node_modules/@relayflows/surface node_modules/@relayflows/surface | ||
| (cd kernel && cargo build --locked -p relayflowd) | ||
| export RELAYFLOWD_BIN="$PWD/kernel/target/debug/relayflowd" | ||
| ``` | ||
|
|
||
| If the daemon was built under a separate Cargo target directory, set | ||
| `RELAYFLOWD_BIN` to that binary instead. | ||
|
|
||
| ## Reproduce the recorded run | ||
|
|
||
| ```sh | ||
| RELAYFLOWS_SLACK_MOCK=1 node packages/sdk/dist/cli.js check --json examples/nabis-uc1/uc1.flow.ts | ||
| npm run typecheck:examples --prefix packages/surface | ||
| node examples/nabis-uc1/verify.mjs | ||
| node examples/nabis-uc1/verify.mjs --real-agent | ||
| node --test examples/nabis-uc1/*.test.mjs | ||
| ``` | ||
|
|
||
| The first verification uses mock Codex and mock Slack. It checks approval, | ||
| decline, duplicate delivery, competing decisions, wrong workspace or channel, | ||
| wrong approver or thread, stale approval, and bot replies. The second runs | ||
| signed-in Codex with `gpt-5.6-sol` and keeps Slack mocked. Both modes start | ||
| the real local daemon and exercise `flows run`, `flows answer`, and | ||
| `flows resume` with Cloud reporting and Observer disabled. They check the | ||
| journal before and after approval and print redacted JSON receipts for the | ||
| six threaded replies and the approval. The shim runs Codex in a separate, | ||
| read-only working directory with shell, delegated agents, apps, plugins, hooks, | ||
| and web search disabled. See the recorded | ||
| [mock-agent run](verification/mock-agent-mock-slack.json) and | ||
| [real-agent run](verification/real-agent-mock-slack.json) for the original | ||
| two-reply demonstration. | ||
|
|
||
| The real-agent verifier passed on Node 26.8.1 with `gpt-5.6-sol`. To send the | ||
| two mock Slack callbacks individually, use the team and channel from the | ||
| fixture, approver `UAPPROVER1`, and a fresh state directory. | ||
|
|
||
| ```sh | ||
| export UC1_SLACK_MODE=mock | ||
| export UC1_SLACK_TEAM=TUC1DEMO UC1_SLACK_CHANNEL=CUC1DEMO UC1_SLACK_APPROVER=UAPPROVER1 | ||
| export UC1_STATE_DIR="$(mktemp -d)" | ||
| node examples/nabis-uc1/slack-event.mjs examples/nabis-uc1/fixtures/mention.json | ||
| cp examples/nabis-uc1/fixtures/approve.json "$UC1_STATE_DIR/approve.json" | ||
| node examples/nabis-uc1/slack-event.mjs "$UC1_STATE_DIR/approve.json" | ||
| ``` | ||
|
|
||
| The mock-agent verification passed on Node 22.23.3. It also resumed approval | ||
| successfully after stopping the local daemon while the run was parked. | ||
| The [SDK regression receipt](verification/helper-resume-regression.txt) | ||
| shows the failure without the helper replay fix and the pass with it restored. | ||
|
|
||
| ## Hosted Slack recording | ||
|
|
||
| This path uses the Cloud workspace's existing Slack connection. The hosted | ||
| runner supplies the Relayfile mount for `f.slack.reply`. Connect the | ||
| `AgentWorkforce/flows` repository and Codex/OpenAI account in the same Cloud | ||
| workspace, and sign in to the Flows CLI. The Slack approver handle for this | ||
| demo is `khaliq`. | ||
|
|
||
| After deployment is authorized, deploy the self-contained source: | ||
|
|
||
| ```sh | ||
| node packages/sdk/dist/cli.js deploy examples/nabis-uc1/uc1.flow.ts \ | ||
| --repo AgentWorkforce/flows \ | ||
| --on 'slack:channel=C0B9Z4CLG1J,mentioned=true,contains=[UC1 SYNTHETIC] nabis-uc1' \ | ||
| --approver khaliq --agents codex --name nabis-uc1 --no-connect | ||
| ``` | ||
|
|
||
| In **#watchdog-test** (`C0B9Z4CLG1J`), select **Agent Relay** from Slack's mention | ||
| picker, then append ` [UC1 SYNTHETIC] nabis-uc1` immediately after the | ||
| mention. Send `@Agent Relay [UC1 SYNTHETIC] nabis-uc1` as a new top-level message. | ||
| Cloud filters the channel, the mention and the command. UC1 checks the exact | ||
| message text and the sender in the mounted Slack record before starting any | ||
| agents or replies. On a cold start, UC1 waits up to 60 seconds for the | ||
| trigger's record to appear in the mirror. The first threaded reply links to | ||
| the live run in Flows Cloud, followed by the role updates. Cloud posts the | ||
| `f.human` question in the same thread. | ||
| The designated operator replies `yes` or `no` to resume. Inspect the linked | ||
| run in the Cloud dashboard. Cloud may add its own acknowledgement and | ||
| terminal receipt alongside the demo's role updates. | ||
|
|
||
| The hosted test exercises the input and mounted-record checks and approval | ||
| branches using local fixtures. | ||
|
|
||
| ## Local recording from a real Slack mention | ||
|
|
||
| ### One-time setup | ||
|
|
||
| 1. Build the checkout, sign in to the real Codex CLI on `PATH`, and set | ||
| `RELAYFLOWD_BIN` if using a separate native build. Sign in with | ||
| `agent-relay cloud login` for the Cloud dashboard. For the Observer link, | ||
| use the approved active Agent Relay workspace or configure | ||
| `RELAYCAST_WORKSPACE_KEY` in the local environment. Keep | ||
| `FLOWS_NO_OBSERVER` unset for the recording. | ||
| 2. In the approved Slack workspace, enable Socket Mode on the demo app. | ||
| Load its app-level `xapp-` token with `connections:write` into | ||
| `UC1_SLACK_APP_TOKEN` in the operator's shell. Subscribe the bot to | ||
| `app_mention` and `message.channels` with `app_mentions:read` and | ||
| `channels:history`. Install the app and invite it to **#watchdog-test** | ||
| (`C0B9Z4CLG1J`). | ||
| [Socket Mode setup](https://docs.slack.dev/apis/events-api/using-socket-mode/) | ||
| 3. Use an existing approved Relayfile writeback connection with access to the | ||
| same channel and `chat:write` for its Slack bot. Point | ||
| `RELAYFILE_MOUNT_PATH` at the root containing `slack/`. Keep that mount | ||
| running with writeback enabled while recording. The listener uses the app | ||
| token for ingress and Relayfile for replies. It has no `SLACK_BOT_TOKEN` | ||
| setting. | ||
| 4. Set `UC1_SLACK_TEAM` to the approved Slack workspace ID, | ||
| `UC1_SLACK_BOT_USER` to the demo app's bot user ID (the ID inside the | ||
| mention), and `UC1_SLACK_APPROVER` to the human Slack user ID who posts | ||
| both the trigger and the decision. Set `UC1_STATE_DIR` to a fresh private | ||
| directory, for example with `export UC1_STATE_DIR="$(mktemp -d)"`. Keep | ||
| that path for the whole recording. | ||
|
|
||
| ### Run the recording | ||
|
|
||
| From the built repository root, launch the listener and leave its terminal open: | ||
|
|
||
| ```sh | ||
| node examples/nabis-uc1/slack-listen.mjs | ||
| ``` | ||
|
|
||
| The listener hands verified callbacks to `slack-event.mjs`. The bridge invokes | ||
| the Flows CLI built by this checkout: | ||
|
|
||
| ```text | ||
| flows run --local-agent --cloud-mirror --json --data-dir <journal> <flow> --input <scoped-flow-input-json> | ||
| flows answer --json --data-dir <journal> <run-id> <wait-id> <yes-or-no> --by slack:@<user-id> --note <event-receipt> | ||
| flows resume --local-agent --cloud-mirror --json --data-dir <journal> <run-id> | ||
| ``` | ||
|
|
||
| 1. Wait for the listening message. As the designated human, select the actual | ||
| app in Slack's mention picker and post `@YourSlackApp nabis-uc1` as a new | ||
| message in **#watchdog-test**. Socket Mode delivers the authenticated | ||
| callback to the listener, which filters it and passes it to | ||
| `slack-event.mjs`. The bridge starts the real Codex flow and all | ||
| writebacks go to the originating thread. | ||
| 2. Leave the approval pause visible for the recording. When ready, reply | ||
| `approve UC1-…` or `decline UC1-…` as the designated human in that | ||
| thread, using the reference from the prompt. The listener forwards the | ||
| scoped `message` event to the bridge, which checks the journaled gate. | ||
| 3. Inspect the lead's **Done / Next / Blocked** reply. Save the terminal's | ||
| `runId` and `humanWait.waitId` if you need the local receipts. Stop the | ||
| listener with Ctrl-C after the summary. | ||
|
|
||
| The listener saves accepted callbacks under `UC1_STATE_DIR/inbox` before | ||
| acknowledging them to Slack. If a flow command fails twice, correct the issue | ||
| and start the listener again with the same state directory. It replays the | ||
| original callback, including an approval that reached the journal but whose | ||
| resume failed. | ||
|
|
||
| ### Follow the run | ||
|
|
||
| The terminal prints `Observer: https://agentrelay.com/observer?key=ot_live_<redacted>` | ||
| when the run's Observer link is ready. Open it locally to see the live step | ||
| progress and approval pause. Keep the keyed link out of Relay messages, | ||
| Slack replies, and recordings. | ||
|
|
||
| The terminal also prints `Dashboard: <cloud-base>/dashboard/workflow/<cloud-run-id>/runner` | ||
| after Cloud registers the run. Open the dashboard to follow the run graph, | ||
| agent handoffs, step transcripts, Slack effects, and approval outcome. The | ||
| Cloud dashboard links the parked attempt to the resumed attempt. The local | ||
| journal retains the same run ID throughout, including the approval and the | ||
| final summary. | ||
|
|
||
| ```sh | ||
| node packages/sdk/dist/cli.js status --json --data-dir "$UC1_STATE_DIR/journal" '<run-id>' | ||
| ``` | ||
|
|
||
| The live procedure runs real Codex agents for a fictional routing task and | ||
| records only a simulated shipment. Delivery through the approved Slack | ||
| connection remains unverified. For a separate authenticated event source, | ||
| the one-shot bridge accepts a private verified callback file or `-` for | ||
| stdin. Set `UC1_SLACK_MODE=live` and `UC1_SLACK_CHANNEL` explicitly for that | ||
| path. The Socket Mode listener sets them for you. | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| #!/bin/sh | ||
| # This demo needs JSON results. Give every model turn a fresh, read-only process | ||
| # with shell, delegated agents, apps, plugins, hooks and web search disabled. | ||
| # The bridge puts this directory first on PATH for the pinned Codex role. | ||
| shim_dir="${0%/*}" | ||
| case "${PATH:-}" in | ||
| "$shim_dir") | ||
| printf '%s\n' 'UC1 requires a Codex executable on PATH outside the shim.' >&2 | ||
| exit 127 | ||
| ;; | ||
| "$shim_dir:"*) | ||
| PATH="${PATH#*:}" | ||
| export PATH | ||
| ;; | ||
| esac | ||
|
|
||
| refuse() { | ||
| printf '%s\n' 'UC1 accepts only fresh Codex turns and model probes.' >&2 | ||
| exit 2 | ||
| } | ||
|
|
||
| if [ "${1:-}" = 'exec' ]; then | ||
| shift | ||
| case "${1:-}" in | ||
| --skip-git-repo-check) | ||
| [ "${2:-}" = '--dangerously-bypass-approvals-and-sandbox' ] || refuse | ||
| shift 2 | ||
| ;; | ||
| --ephemeral) | ||
| [ "${2:-}" = '--sandbox' ] && [ "${3:-}" = 'read-only' ] && [ "${4:-}" = '--skip-git-repo-check' ] || refuse | ||
| shift 4 | ||
| ;; | ||
| *) refuse ;; | ||
| esac | ||
| for option do | ||
| case "$option" in | ||
| --) break ;; | ||
| --dangerously-bypass-approvals-and-sandbox|--sandbox|--sandbox=*|--full-auto) refuse ;; | ||
| esac | ||
| done | ||
| exec codex -a never exec --ignore-user-config --disable shell_tool --disable unified_exec \ | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
|
||
| --disable multi_agent --disable apps --disable plugins --disable hooks -c web_search=disabled \ | ||
| --skip-git-repo-check --sandbox read-only --ephemeral "$@" | ||
| fi | ||
| exec codex "$@" | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| // The hosted deployment uploads only uc1.flow.ts. Keep the bridge's imports | ||
| // here while sharing the same contract with the self-contained flow source. | ||
| export { | ||
| approvalAttribution, approvalQuestion, approverIdentity, CHANNEL_ID, EVENT_ID, | ||
| MOCK_PROMPT_TS, orderedTasks, record, REQUEST_ID, routes, SLACK_TS, TEAM_ID, USER_ID, | ||
| type RunInput, | ||
| } from './uc1.flow.ts'; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "type": "event_callback", | ||
| "team_id": "TUC1DEMO", | ||
| "event_id": "EvMockApprove1", | ||
| "event": { | ||
| "type": "message", | ||
| "channel": "CUC1DEMO", | ||
| "user": "UAPPROVER1", | ||
| "thread_ts": "1780000000.000001", | ||
| "ts": "1780000001.000001", | ||
| "text": "approve UC1-3f9d57368e0adee4" | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| #!/usr/bin/env node | ||
| // MOCK Codex CLI. The demo still uses the real Flows agent worker and journal. | ||
| const argv = process.argv.slice(2); | ||
| if (argv[0] === '--version') { | ||
| console.log('codex-cli 0.154.0'); | ||
| } else if (argv[0] === 'login') { | ||
| console.log('Logged in using ChatGPT'); | ||
| } else { | ||
| const options = argv.slice(0, argv.indexOf('--')); | ||
| if (!options.includes('read-only') || options.includes('--dangerously-bypass-approvals-and-sandbox')) { | ||
| throw new Error('UC1 agent invocation did not enforce read-only mode.'); | ||
| } | ||
| const task = argv.at(-1); | ||
| if (task.includes('RELAYFLOWS_MODEL_READY')) { | ||
| console.log('RELAYFLOWS_MODEL_READY'); | ||
| } else { | ||
| const contract = { ready: 'pickup-queue', held: 'manual-review', canceled: 'archive' }; | ||
| let result; | ||
| if (task.startsWith('UC1 planner.')) { | ||
| result = { tasks: [ | ||
| { id: 'exceptions', statuses: ['held', 'canceled'], dependsOn: ['baseline'] }, | ||
| { id: 'baseline', statuses: ['ready'], dependsOn: [] }, | ||
| ] }; | ||
| } else if (task.startsWith('UC1 coder.')) { | ||
| const [, json] = /task (\{.*?\}) as a JSON routing table/u.exec(task); | ||
| const { statuses } = JSON.parse(json); | ||
| result = { rules: Object.fromEntries(statuses.filter(status => status !== 'held') | ||
| .map(status => [status, contract[status]])) }; | ||
| } else if (task.startsWith('UC1 first review.')) { | ||
| result = { verdict: 'reject', finding: 'missing-held-route' }; | ||
| } else if (task.startsWith('UC1 repair.')) { | ||
| result = { rules: contract }; | ||
| } else if (task.startsWith('UC1 repaired review.')) { | ||
| result = { verdict: 'approve' }; | ||
| } else { | ||
| throw new Error('Unexpected mock agent task.'); | ||
| } | ||
| console.log(JSON.stringify({ | ||
| type: 'item.completed', item: { id: 'fixture-response', type: 'agent_message', text: JSON.stringify(result) }, | ||
| })); | ||
| console.log(JSON.stringify({ | ||
| type: 'turn.completed', usage: { input_tokens: 10, cached_input_tokens: 0, output_tokens: 10 }, | ||
| })); | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "type": "event_callback", | ||
| "team_id": "TUC1DEMO", | ||
| "event_id": "EvMockMention1", | ||
| "event": { | ||
| "type": "app_mention", | ||
| "channel": "CUC1DEMO", | ||
| "user": "UFIXTURE1", | ||
| "ts": "1780000000.000001", | ||
| "text": "<@UBOTDEMO> nabis-uc1" | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "cli": "codex", | ||
| "models": ["gpt-5.6-sol"] | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.