Skip to content

Open-source SEO, GEO, and marketing skills for AI agents.

feat(goals): confirming the plan in chat starts the loop — drop the START button

Yuting Zhong69c0ceccbb2e
diff --git a/notfair/CLAUDE.md b/notfair/CLAUDE.md
index 0e4646d7..dea790a7 100644
--- a/notfair/CLAUDE.md
+++ b/notfair/CLAUDE.md
@@ -6,7 +6,8 @@ Project conventions and notes for AI assistants working on NotFair.
A local, single-user, goal-driven agent runner. The user states a goal; NotFair
provisions an anonymous agent for it (agent = goal, 1:1), the agent defines a
-platform-verifiable metric + target in chat, the user clicks START, and a
+platform-verifiable metric + target in chat, the user confirms the plan (which
+starts the loop on the spot), and a
heartbeat loop ("checks") measures the metric and lets the agent act — with
observation windows, a spend envelope, and per-goal memory as the controls.
No approvals, no tasks, no orchestration layer: goals are the only unit.
@@ -29,7 +30,7 @@ This repo carries no migrations or legacy/compat code. Verification is:
assignment points the suite at the developer's live `~/.notfair`.
3. `pnpm build` — must be clean.
4. Live smoke: `pnpm dev` (port 3326), then walk the affected flow in the
- browser (goal index → goal page → chat / START / checks).
+ browser (goal index → goal page → chat / confirm / checks).
Prompt-affecting changes (`src/server/goals/identity.ts`, tick briefs in
`src/server/goals/tick.ts`, tool descriptions in
diff --git a/notfair/src/app/(app)/[project]/goals/[agent]/page.tsx b/notfair/src/app/(app)/[project]/goals/[agent]/page.tsx
index 8dc949b2..3a3b96d2 100644
--- a/notfair/src/app/(app)/[project]/goals/[agent]/page.tsx
+++ b/notfair/src/app/(app)/[project]/goals/[agent]/page.tsx
@@ -35,7 +35,6 @@ import { cadenceLabel } from "@/lib/goal-cadence";
import { cn } from "@/lib/utils";
import { LiveTranscript } from "@/components/live-transcript";
import { GoalControls } from "@/components/goal-controls";
-import { GoalStartButton } from "@/components/goal-start-button";
import { GoalAutoRefresh } from "@/components/goal-auto-refresh";
import { GoalProgressChart } from "@/components/goal-progress-chart";
import { GoalMetricCard, type MetricVariant } from "@/components/goal-metric-card";
@@ -78,7 +77,7 @@ function fmtClock(iso: string): string {
const STATUS_CHIP: Record<Goal["status"], string> = {
intake: "setting up",
- proposed: "ready to start",
+ proposed: "confirm the plan",
active: "running",
paused: "paused",
achieved: "achieved",
@@ -168,12 +167,11 @@ export default async function GoalPage({
return (
<div className="flex min-h-0 flex-1 flex-col">
- {/* Every pre-terminal state before START changes server-side via
- agent tool calls: intake verifies the metric (→ proposed), and a
- proposed goal's target lands via propose_target — which is what
- makes the START button appear. Without polling `proposed`, the
- user is told "press START" but the button never renders until a
- manual reload. */}
+ {/* Every pre-terminal state changes server-side via agent tool
+ calls: intake verifies the metric (→ proposed), and the user's
+ confirmation in chat lands via propose_target (→ active, first
+ check running). Without polling, the rail keeps showing the
+ previous stage until a manual reload. */}
{(goal.status === "intake" ||
goal.status === "proposed" ||
goal.status === "active") && <GoalAutoRefresh intervalMs={8000} />}
@@ -378,40 +376,20 @@ function GoalDashboard({
{goal.status === "proposed" && (
<RailCard>
- {goal.target_value !== null ? (
- <>
- <p className="m-0 mb-3 text-[12.5px] leading-relaxed">
- Baseline <b className="tabular-nums">{formatMetric(goal.baseline_value)}</b>,
- verified against{" "}
- <span className="font-mono text-[11px]">{goal.metric_source_key}</span>{" "}
- <MetricMethodDialog
- name={goal.metric_name ?? "Metric"}
- sourceKey={goal.metric_source_key}
- sourceTool={goal.metric_source_tool}
- argsJson={goal.metric_source_args_json}
- direction={goal.metric_direction}
- />
- . The plan is agreed — the loop starts when you press START,
- and the first check runs immediately.
- </p>
- <dl className="mb-3 grid grid-cols-2 gap-2 text-[12px]">
- <RailStat k="Target" v={`${formatMetric(goal.target_value)}${goal.mode === "maintain" ? " (hold)" : ""}`} />
- <RailStat k="Heartbeat" v={cadenceLabel(goal.cadence_cron)} />
- <RailStat k="Deadline" v={goal.deadline ? fmtDate(goal.deadline) : "none"} />
- <RailStat
- k="Spend cap"
- v={goal.spend_envelope_usd !== null ? `$${goal.spend_envelope_usd}` : "none"}
- />
- </dl>
- <GoalStartButton goalId={goal.id} />
- </>
- ) : (
- <p className="m-0 text-[12.5px] leading-relaxed">
- Metric verified — baseline{" "}
- <b className="tabular-nums">{formatMetric(goal.baseline_value)}</b>. Agree the
- target in chat and the START button appears here.
- </p>
- )}
+ <p className="m-0 text-[12.5px] leading-relaxed">
+ Baseline <b className="tabular-nums">{formatMetric(goal.baseline_value)}</b>,
+ verified against{" "}
+ <span className="font-mono text-[11px]">{goal.metric_source_key}</span>{" "}
+ <MetricMethodDialog
+ name={goal.metric_name ?? "Metric"}
+ sourceKey={goal.metric_source_key}
+ sourceTool={goal.metric_source_tool}
+ argsJson={goal.metric_source_args_json}
+ direction={goal.metric_direction}
+ />
+ . Agree the target in chat — the moment you confirm, the loop
+ starts and the first check runs.
+ </p>
</RailCard>
)}
@@ -563,12 +541,3 @@ function SupportMetricItem({ metric }: { metric: GoalSupportMetric }) {
</div>
);
}
-
-function RailStat({ k, v }: { k: string; v: string }) {
- return (
- <div>
- <dt className="text-[hsl(var(--notfair-ink-4))]">{k}</dt>
- <dd className="m-0 font-medium tabular-nums">{v}</dd>
- </div>
- );
-}
diff --git a/notfair/src/app/(app)/[project]/page.tsx b/notfair/src/app/(app)/[project]/page.tsx
index a6610b76..9c6864cf 100644
--- a/notfair/src/app/(app)/[project]/page.tsx
+++ b/notfair/src/app/(app)/[project]/page.tsx
@@ -95,7 +95,7 @@ export default async function ProjectGoalsPage({
<div className="ns-page-head-stack">
<h1 className="ns-page-title">{project.display_name}</h1>
<p className="ns-page-sub">
- State a goal. It gets measured, you press START, the loop runs.
+ State a goal. It gets measured, you confirm the plan, the loop runs.
</p>
</div>
</header>
diff --git a/notfair/src/components/goal-start-button.tsx b/notfair/src/components/goal-start-button.tsx
deleted file mode 100644
index 45da95b2..00000000
--- a/notfair/src/components/goal-start-button.tsx
+++ /dev/null
@@ -1,37 +0,0 @@
-"use client";
-
-import { useRouter } from "next/navigation";
-import { useTransition } from "react";
-import { toast } from "sonner";
-import { Play } from "lucide-react";
-import { startGoalLoopAction } from "@/server/actions/goals";
-import { Button } from "@/components/ui/button";
-
-/**
- * The consent moment: the loop does not start until the user clicks this.
- * The click also fires the first tick immediately, so the reward for
- * consenting is watching the agent work right now.
- */
-export function GoalStartButton({ goalId }: { goalId: string }) {
- const router = useRouter();
- const [pending, startTransition] = useTransition();
-
- function start() {
- startTransition(async () => {
- const r = await startGoalLoopAction(goalId);
- if (!r.ok) {
- toast.error(r.error ?? "Could not start the loop.");
- return;
- }
- toast.success("Loop started — the first tick is running now.");
- router.refresh();
- });
- }
-
- return (
- <Button onClick={start} disabled={pending} size="lg" className="gap-2">
- <Play className="size-4" />
- {pending ? "Starting…" : "START the loop"}
- </Button>
- );
-}
diff --git a/notfair/src/components/goal-suggestions.tsx b/notfair/src/components/goal-suggestions.tsx
index 113099e0..31d34919 100644
--- a/notfair/src/components/goal-suggestions.tsx
+++ b/notfair/src/components/goal-suggestions.tsx
@@ -16,7 +16,8 @@ import { Button } from "@/components/ui/button";
/**
* Suggested-goal cards minted from a mechanical audit of a connected ads
* account. Accepting one runs the normal statement-first flow: a goal
- * agent spins up, verifies the metric, and nothing spends until START.
+ * agent spins up, verifies the metric, and nothing spends until the user
+ * confirms the plan.
*/
export function GoalSuggestionCard({
suggestion,
@@ -75,7 +76,7 @@ export function GoalSuggestionCard({
</p>
<div className="mt-1 flex items-center justify-between gap-3">
<p className="m-0 text-[11.5px] text-[hsl(var(--notfair-ink-4))]">
- An agent verifies the numbers first — nothing runs until you press START.
+ An agent verifies the numbers first — nothing runs until you confirm the plan in chat.
</p>
<Button size="sm" onClick={accept} disabled={pending}>
{pending ? "Creating…" : "Create this goal"}
diff --git a/notfair/src/components/goals-board.tsx b/notfair/src/components/goals-board.tsx
index f21fa7b8..6d9d2fd7 100644
--- a/notfair/src/components/goals-board.tsx
+++ b/notfair/src/components/goals-board.tsx
@@ -42,7 +42,7 @@ type GroupKey = "setup" | "running" | "paused" | "achieved" | "failed" | "closed
/**
* Board columns. Intake and proposed share a column — both are "the goal
* isn't running yet"; the card chip tells them apart (and flags the one
- * that's waiting on the user's START). The three terminal states each get
+ * waiting on the user's confirm in chat). The three terminal states each get
* their own column so an achieved goal reads as a win, not just "gone".
*/
const GROUPS: Array<{
@@ -192,7 +192,7 @@ function GoalCard({ goal }: { goal: BoardGoal }) {
</div>
{goal.status === "proposed" && (
- <span className="ns-tag-accent mt-1.5 inline-block">ready to start</span>
+ <span className="ns-tag-accent mt-1.5 inline-block">confirm the plan in chat</span>
)}
{goal.status === "intake" && (
<span className="ns-tag mt-1.5 inline-block">defining metric</span>
diff --git a/notfair/src/components/new-goal-form.tsx b/notfair/src/components/new-goal-form.tsx
index 626e3fce..5161aea7 100644
--- a/notfair/src/components/new-goal-form.tsx
+++ b/notfair/src/components/new-goal-form.tsx
@@ -121,7 +121,7 @@ export function NewGoalForm({
<div className="flex items-center justify-between gap-3">
<p className="m-0 text-[12px] text-[hsl(var(--notfair-ink-4))]">
An agent takes it from here: it turns this into a measured metric,
- shows you the baseline, and nothing runs until you press START.
+ shows you the baseline, and nothing runs until you confirm the plan.
</p>
<Button onClick={submit} disabled={pending || !statement.trim()}>
{pending ? "Creating…" : "Create goal"}
diff --git a/notfair/src/components/onboarding-flow.tsx b/notfair/src/components/onboarding-flow.tsx
index 612c1b37..360cdfa5 100644
--- a/notfair/src/components/onboarding-flow.tsx
+++ b/notfair/src/components/onboarding-flow.tsx
@@ -625,7 +625,7 @@ function FirstGoalStep({
<h1 className="ns-hero-title">Create your first goal.</h1>
<p className="ns-hero-sub">
Pick a focus, state the ambition. An agent measures it, shows you
- the baseline, and waits for your START.
+ the baseline, and waits for your go-ahead.
</p>
</header>
diff --git a/notfair/src/server/actions/goals.ts b/notfair/src/server/actions/goals.ts
index edb20f83..58dea7cc 100644
--- a/notfair/src/server/actions/goals.ts
+++ b/notfair/src/server/actions/goals.ts
@@ -12,7 +12,6 @@ import {
reviewGoalAction,
setGoalPinned,
setGoalStatus,
- startGoalLoop,
USER_ACTION_PREFIX,
} from "@/server/db/goals";
import { cascadeDeleteAgentArtifacts } from "@/server/agents/cascade-delete";
@@ -108,29 +107,6 @@ export async function createGoalAgentAction(input: {
};
}
-/**
- * The user's START click — the platform-enforced consent that begins the
- * loop. Fires the first tick immediately so the user watches it work
- * rather than waiting for tomorrow's heartbeat.
- */
-export async function startGoalLoopAction(goal_id: string): Promise<GoalActionResult> {
- const goal = getGoal(goal_id);
- if (!goal) return { ok: false, error: "Goal not found." };
- if (goal.status !== "proposed" || goal.target_value === null) {
- return {
- ok: false,
- error: "The goal isn't ready to start — agree a target with the agent in chat first.",
- };
- }
- const started = startGoalLoop(goal_id);
- if (!started) return { ok: false, error: "Could not start the loop." };
- void runGoalTick(started, "manual").catch((err) =>
- console.error("[goal-tick] first tick failed:", err),
- );
- revalidatePath("/", "layout");
- return { ok: true, goal_id: started.id };
-}
-
export async function pauseGoalAction(goal_id: string): Promise<GoalActionResult> {
const goal = setGoalStatus(goal_id, "paused", "paused by user");
if (!goal) return { ok: false, error: "Goal not found." };
diff --git a/notfair/src/server/actions/suggestions.ts b/notfair/src/server/actions/suggestions.ts
index f4eff70b..a8edfa7a 100644
--- a/notfair/src/server/actions/suggestions.ts
+++ b/notfair/src/server/actions/suggestions.ts
@@ -15,7 +15,7 @@ import { createGoalAgentAction, type GoalActionResult } from "@/server/actions/g
/**
* Accept a suggestion: mint the goal from its statement (the normal
* statement-first flow — the agent still verifies the metric and the
- * user still presses START) and retire the card.
+ * user still confirms the plan in chat) and retire the card.
*/
export async function acceptSuggestionAction(id: string): Promise<GoalActionResult> {
const suggestion = getSuggestion(id);
diff --git a/notfair/src/server/db/goals.ts b/notfair/src/server/db/goals.ts
index c3e338cd..a65af111 100644
--- a/notfair/src/server/db/goals.ts
+++ b/notfair/src/server/db/goals.ts
@@ -318,22 +318,24 @@ export type ProposeTargetInput = {
};
/**
- * Agent proposal: record the suggested target/cadence/envelope on a
- * `proposed` goal. Does NOT start the loop — that consent belongs to the
- * user, who clicks "Start the loop" (startGoalLoop) on the Goal tab.
+ * The user's confirmation, recorded from chat: target/cadence/envelope
+ * land on the `proposed` goal and the loop goes live in the same step —
+ * proposed → active with the first heartbeat scheduled. The caller fires
+ * an immediate first tick.
*/
export function proposeTarget(id: string, input: ProposeTargetInput): Goal | null {
const goal = getGoal(id);
if (!goal || goal.status !== "proposed") return null;
const cadence = input.cadence_cron ?? goal.cadence_cron;
- if (!computeNextTick(cadence)) {
+ const nextTick = computeNextTick(cadence);
+ if (!nextTick) {
throw new Error(`Invalid cadence cron expression: '${cadence}'`);
}
getDb()
.prepare(
`UPDATE goals
SET target_value = ?, mode = ?, deadline = ?, spend_envelope_usd = ?,
- cadence_cron = ?, updated_at = ?
+ cadence_cron = ?, status = 'active', next_tick_at = ?, updated_at = ?
WHERE id = ? AND status = 'proposed'`,
)
.run(
@@ -342,30 +344,13 @@ export function proposeTarget(id: string, input: ProposeTargetInput): Goal | nul
input.deadline ?? goal.deadline,
input.spend_envelope_usd ?? goal.spend_envelope_usd,
cadence,
+ nextTick,
now(),
id,
);
return getGoal(id);
}
-/**
- * The user's click: proposed (with a target on record) → active. Computes
- * the first heartbeat; the caller fires an immediate first tick.
- */
-export function startGoalLoop(id: string): Goal | null {
- const goal = getGoal(id);
- if (!goal || goal.status !== "proposed" || goal.target_value === null) return null;
- const nextTick = computeNextTick(goal.cadence_cron);
- if (!nextTick) throw new Error(`Invalid cadence cron expression: '${goal.cadence_cron}'`);
- getDb()
- .prepare(
- `UPDATE goals SET status = 'active', next_tick_at = ?, updated_at = ?
- WHERE id = ? AND status = 'proposed'`,
- )
- .run(nextTick, now(), id);
- return getGoal(id);
-}
-
export type AmendGoalInput = {
target_value?: number;
deadline?: string | null;
diff --git a/notfair/src/server/goals/handlers.ts b/notfair/src/server/goals/handlers.ts
index b6561bbd..6164a96d 100644
--- a/notfair/src/server/goals/handlers.ts
+++ b/notfair/src/server/goals/handlers.ts
@@ -445,10 +445,10 @@ export type ProposeTargetToolInput = {
};
/**
- * Record the target/cadence/envelope the user agreed to in chat. Does NOT
- * start the loop — the user clicks "Start the loop" on the Goal tab.
- * That click is the platform-enforced consent moment: an agent cannot
- * start spending cycles (or money) on its own say-so.
+ * Record the target/cadence/envelope the user agreed to in chat — and
+ * start the loop. The user's confirmation in chat IS the consent moment:
+ * the goal goes active and the first tick fires immediately, so the
+ * agent must only call this after the user has explicitly agreed.
*/
export function handleProposeTarget(
input: ProposeTargetToolInput,
@@ -479,6 +479,14 @@ export function handleProposeTarget(
}
if (!updated) return { ok: false, error: "Goal left 'proposed' while recording the target." };
void syncIdentity(updated);
+ // The loop is live — fire the first tick now so the user watches the
+ // agent work immediately instead of waiting for the next heartbeat.
+ // Dynamic import: tick.ts pulls in the adapter runtime, which the
+ // handler module must not load eagerly.
+ const started = updated;
+ void import("./tick")
+ .then(({ runGoalTick }) => runGoalTick(started, "manual"))
+ .catch((err) => console.error("[goal-handlers] first tick failed:", err));
return { ok: true, data: { goal_id: updated.id, status: updated.status } };
}
diff --git a/notfair/src/server/goals/identity.ts b/notfair/src/server/goals/identity.ts
index f2b3fd52..4d6aa7ca 100644
--- a/notfair/src/server/goals/identity.ts
+++ b/notfair/src/server/goals/identity.ts
@@ -93,9 +93,9 @@ is a short conversation that ends with a measurable goal:
+ cadence + spend envelope, and ask. Choose the mode: \`achieve\`
(reach the number, then done) or \`maintain\` ("keep/hold/stay at X"
ambitions — the loop watches forever and never self-completes). When
- the user agrees, record it with \`propose_target\` and tell them to
- hit START on your Goal tab — the platform requires their click; you
- cannot start the loop.
+ the user EXPLICITLY confirms, record it with \`propose_target\` —
+ that starts the loop on the spot (the first check fires
+ immediately), so never call it on an assumed or implied yes.
If neither a connected source nor a \`local\` shell command can
measure the ambition, say so plainly and name what to connect (the
diff --git a/notfair/src/server/goals/intake.ts b/notfair/src/server/goals/intake.ts
index 86dd9e25..53c3652a 100644
--- a/notfair/src/server/goals/intake.ts
+++ b/notfair/src/server/goals/intake.ts
@@ -36,8 +36,8 @@ greet: acknowledge the ambition in one sentence, ask only what's truly
blocking (if anything), then explore the data, author + TEST the metric
query, verify it via propose_goal_metric, and report the measured
baseline with a suggested target, cadence, and spend envelope. End by
-asking the user to confirm (they'll press START on your Goal tab after
-you record their agreement via propose_target).`;
+asking the user to confirm — the moment they do, record it via
+propose_target, which starts the loop and fires the first check.`;
}
/** Fire-and-forget from goal creation. The goal screen's embedded chat
diff --git a/notfair/src/server/mcp-server/tools.ts b/notfair/src/server/mcp-server/tools.ts
index 73ca8f26..88797fdb 100644
--- a/notfair/src/server/mcp-server/tools.ts
+++ b/notfair/src/server/mcp-server/tools.ts
@@ -26,7 +26,8 @@ import {
* its IDENTITY.md — we never derive identity from the bearer.
*
* The surface is deliberately small: the goal lifecycle
- * (define → propose metric → propose target → user clicks START), the loop's bookkeeping
+ * (define → propose metric → propose target on the user's confirm, which
+ * starts the loop), the loop's bookkeeping
* (actions, reviews, learnings, status), the shared workspace context,
* and auxiliary scheduling. There is no task board, no approvals, no
* delegation — one agent, one goal, one loop.
@@ -156,7 +157,7 @@ async function handleProposeGoalMetricTool(input: unknown): Promise<ToolResult>
const r = await handleProposeGoalMetric(rest, { project_slug, agent_id });
if (!r.ok) return { ok: false, error: r.error };
return txt(
- `Metric verified server-side. Baseline measured: ${r.data.baseline_value}. Report this to the user, suggest a target + cadence + spend envelope, and record it with propose_target once they agree. They start the loop with the START button on your Goal tab.`,
+ `Metric verified server-side. Baseline measured: ${r.data.baseline_value}. Report this to the user, suggest a target + cadence + spend envelope, and record it with propose_target once they agree — recording it starts the loop immediately.`,
);
}
@@ -280,7 +281,7 @@ async function handleProposeTargetTool(input: unknown): Promise<ToolResult> {
const r = handleProposeTarget(rest, { project_slug, agent_id });
if (!r.ok) return { ok: false, error: r.error };
return txt(
- "Target recorded. Tell the user everything is set and point them at the START button on your Goal tab — the loop begins the moment they click it (the first tick runs immediately). You cannot start it yourself.",
+ "Target recorded — the loop is LIVE and the first check is running now. Tell the user the plan is locked in and they can watch the first check on their Goal tab.",
);
}
@@ -578,7 +579,7 @@ export const TOOLS: ToolDefinition[] = [
{
name: "propose_target",
description:
- "Intake step 3: record the target/cadence/spend envelope the user agreed to in chat. This does NOT start the loop — the user clicks START on your Goal tab (platform-enforced consent), which also fires the first tick immediately. Rejects targets on the wrong side of the baseline.",
+ "Intake step 3: record the target/cadence/spend envelope the user agreed to in chat. Recording it STARTS the loop — the goal goes active and the first check fires immediately, so call this ONLY after the user has explicitly confirmed the plan. Rejects targets on the wrong side of the baseline.",
inputSchema: proposeTargetInput,
handler: handleProposeTargetTool,
},