Skip to content

Commit 73de089

Browse files
committed
feat: add Stop Monitoring to trajectory page, full agent monitoring loop in SKILL.md
1 parent fb56a51 commit 73de089

File tree

2 files changed

+59
-22
lines changed

2 files changed

+59
-22
lines changed

packages/web/src/pages/TrajectoryPage.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,15 @@ function TrajectoryPageInner() {
10281028
setSubmitting(false)
10291029
}
10301030

1031+
const stopMonitoring = async () => {
1032+
await fetch(`/api/sessions/${id}/page-status`, {
1033+
method: 'POST',
1034+
headers: { 'Content-Type': 'application/json' },
1035+
body: JSON.stringify({ state: 'hidden', stopMonitoring: true, reason: 'user_stopped' }),
1036+
})
1037+
navigate('/')
1038+
}
1039+
10311040
// ─── Render states ──────────────────────────────────────────────────────────
10321041

10331042
if (fetchError) return (
@@ -1073,7 +1082,7 @@ function TrajectoryPageInner() {
10731082

10741083
return (
10751084
<div className="min-h-screen bg-gray-50 dark:bg-zinc-950">
1076-
<div className="max-w-4xl mx-auto py-10 px-4">
1085+
<div className="max-w-full mx-auto py-10 px-4">
10771086

10781087
{/* Header */}
10791088
<div className="mb-6">
@@ -1170,6 +1179,13 @@ function TrajectoryPageInner() {
11701179
>
11711180
Reject
11721181
</button>
1182+
<button
1183+
onClick={stopMonitoring}
1184+
disabled={submitting}
1185+
className={`px-5 text-sm text-zinc-400 dark:text-zinc-500 border border-zinc-200 dark:border-zinc-700 rounded-lg hover:bg-zinc-50 dark:hover:bg-zinc-900 transition-colors ${submitting ? 'opacity-50 cursor-not-allowed' : ''}`}
1186+
>
1187+
Stop Monitoring
1188+
</button>
11731189
</div>
11741190

11751191
</div>

skills/clickui-trajectory/SKILL.md

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,20 @@ Submit a multi-step agent execution trajectory to AgentClick for human review. T
9595
| `pending` | Step not yet executed |
9696
| `skipped` | Step was skipped |
9797

98-
## Submitting a Trajectory
98+
## Step 1: Health check
9999

100100
```bash
101101
if curl -s --max-time 1 http://localhost:38173/api/health > /dev/null 2>&1; then
102102
AGENTCLICK_BASE="http://localhost:38173"
103103
else
104104
AGENTCLICK_BASE="http://host.docker.internal:38173"
105105
fi
106+
```
107+
108+
## Step 2: Create the session
106109

107-
curl -X POST "$AGENTCLICK_BASE/api/review" \
110+
```bash
111+
RESPONSE=$(curl -s -X POST "$AGENTCLICK_BASE/api/review" \
108112
-H 'Content-Type: application/json' \
109113
-d '{
110114
"type": "trajectory_review",
@@ -116,36 +120,36 @@ curl -X POST "$AGENTCLICK_BASE/api/review" \
116120
{ "id": "s2", "type": "error", "label": "Parse failed", "status": "failure", "error": { "message": "Invalid JSON" } }
117121
]
118122
}
119-
}'
123+
}')
124+
SESSION_ID=$(echo "$RESPONSE" | grep -o '"sessionId":"[^"]*"' | cut -d'"' -f4)
120125
```
121126

122-
On submission, AgentClick opens the trajectory review page.
127+
## Step 3: Monitor the session
123128

124-
## Polling for Result
125-
126-
After submitting, poll for the human's response using environment detection:
129+
After creating the session, stay attached and respond to user actions.
127130

128131
```bash
129-
# Detect environment: GOG_ACCOUNT is set in Docker (docker-compose.yml), absent elsewhere
132+
# Detect environment: GOG_ACCOUNT is set in Docker, absent elsewhere
130133
if [ -n "$GOG_ACCOUNT" ]; then
131-
# Docker: use short-poll (one curl per exec, you are the loop controller)
132134
curl -s "$AGENTCLICK_BASE/api/sessions/${SESSION_ID}"
133135
else
134-
# Non-Docker: use blocking /wait
135136
curl -s --max-time 310 "$AGENTCLICK_BASE/api/sessions/${SESSION_ID}/wait"
136137
fi
137138
```
138139

139-
- In Docker (`GOG_ACCOUNT` set): run ONE curl per exec call, check result in your context, then poll again. Do NOT use a bash while loop. You are the loop controller.
140-
- In non-Docker: the `/wait` call blocks until state changes, then process the result.
140+
After each poll result:
141+
- If `pageStatus.stopMonitoring` is `true`**stop immediately** (user clicked Stop Monitoring)
142+
- If `status` is `"completed"` → read result and stop
143+
- If `status` is `"rewriting"` → handle the retry request (see Step 4), then poll again
144+
- Otherwise → wait 1 second, then poll again
141145

142-
## Result Schema
146+
## Step 4: Handle retry requests
143147

144-
The human's response is returned via `/api/sessions/:id` (poll) or `/api/sessions/:id/wait` (non-Docker blocking):
148+
When `/wait` returns `status: "rewriting"`, the user clicked "Request Retry". The result contains:
145149

146150
```json
147151
{
148-
"approved": true,
152+
"approved": false,
149153
"revisions": [
150154
{
151155
"stepId": "s3",
@@ -160,13 +164,30 @@ The human's response is returned via `/api/sessions/:id` (poll) or `/api/session
160164
}
161165
```
162166

163-
## Rewrite Cycle
167+
Agent must:
168+
1. Read `revisions` — for each, apply corrections to the affected steps
169+
2. Read `globalNote` — treat as an overarching instruction
170+
3. Read `resumeFromStep` — re-execute from that step if instructed
171+
4. PUT the updated trajectory payload back so the page reflects the new steps:
172+
173+
```bash
174+
curl -s -X PUT "$AGENTCLICK_BASE/api/sessions/${SESSION_ID}/payload" \
175+
-H 'Content-Type: application/json' \
176+
-d '{"payload": {"title": "...", "steps": [...updated steps...]}}'
177+
```
164178

165-
1. Human reviews trajectory and clicks "Request Retry"
166-
2. Agent's poll (or `/wait` in non-Docker) resolves with `status: "rewriting"`
167-
3. Agent applies corrections, re-executes from `resumeFromStep`
168-
4. Agent PUTs updated payload: `PUT /api/sessions/:id/payload`
169-
5. Human reviews again (status resets to `pending`)
179+
5. Poll again — the page will show the updated trajectory for the next review round.
180+
181+
## Result Schema (on completion)
182+
183+
```json
184+
{
185+
"approved": true,
186+
"revisions": [...],
187+
"globalNote": "...",
188+
"resumeFromStep": "s3"
189+
}
190+
```
170191

171192
## Learning
172193

0 commit comments

Comments
 (0)