Skip to content

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

refactor(agents): single-source the agent context — no more duplicated text

Yuting Zhong1730cc7c67af
diff --git a/notfair/src/server/actions/context.ts b/notfair/src/server/actions/context.ts
index cd012613..ac53acb3 100644
--- a/notfair/src/server/actions/context.ts
+++ b/notfair/src/server/actions/context.ts
@@ -131,14 +131,6 @@ export async function getGoalContextAction(input: {
);
}
}
- const skill = await readWorkspaceFile(agent_id, "SKILL.md");
- if (skill) {
- chunks.push(
- chunk("skill", "Goal-loop skill (SKILL.md)", "instructions", skill,
- "Loaded on demand — enters context when the agent reads it during a session."),
- );
- }
-
// ── MCP tool definitions ──────────────────────────────────────
const goalTools = toolsChunk("notfair-goals", "Goal tools (notfair-goals)", await internalToolsList("goals"));
if (goalTools) chunks.push(goalTools);
diff --git a/notfair/src/server/adapters/claude-code-local/provision.ts b/notfair/src/server/adapters/claude-code-local/provision.ts
index db6b766e..3b1a6d3a 100644
--- a/notfair/src/server/adapters/claude-code-local/provision.ts
+++ b/notfair/src/server/adapters/claude-code-local/provision.ts
@@ -1,4 +1,4 @@
-import { mkdir, writeFile } from "node:fs/promises";
+import { mkdir, rm, writeFile } from "node:fs/promises";
import { join } from "node:path";
import type { AgentProvisionSpec } from "../types";
@@ -7,25 +7,33 @@ import type { AgentProvisionSpec } from "../types";
*
* Layout under `<workspaceDir>/`:
* IDENTITY.md — system prompt (NotFair's source of truth)
- * CLAUDE.md — same content (Claude Code auto-loads CLAUDE.md from cwd)
- * SKILL.md — shared goal-loop skill text (sidecar for humans)
+ * CLAUDE.md — a one-paragraph pointer, NOT a mirror. NotFair passes
+ * IDENTITY.md via --append-system-prompt on every turn;
+ * mirroring the full identity here would load the same
+ * ~18KB into context TWICE (system prompt + auto-load).
* PROJECT.md — project brief if available (sidecar for humans)
*
+ * The skill text lives INSIDE the identity — never as a SKILL.md sidecar.
* No subprocess calls. Claude Code discovers the workspace lazily on first
* invocation; there's no "register agent" step.
*/
+const CLAUDE_MD_POINTER = `# NotFair agent workspace
+
+This agent's full instructions live in IDENTITY.md — NotFair injects them
+as the system prompt on every turn, so they are not mirrored here. If you
+are a human (or a manually launched session) exploring this workspace,
+read IDENTITY.md.
+`;
+
export async function provisionClaudeCodeAgent(spec: AgentProvisionSpec): Promise<void> {
await mkdir(spec.workspaceDir, { recursive: true });
await Promise.all([
writeFile(join(spec.workspaceDir, "IDENTITY.md"), spec.identityMd, "utf8"),
- // Mirror to CLAUDE.md so the harness auto-loads it without us passing
- // --append-system-prompt — useful when users open the workspace directly.
- writeFile(join(spec.workspaceDir, "CLAUDE.md"), spec.identityMd, "utf8"),
- spec.skillMd
- ? writeFile(join(spec.workspaceDir, "SKILL.md"), spec.skillMd, "utf8")
- : Promise.resolve(),
+ writeFile(join(spec.workspaceDir, "CLAUDE.md"), CLAUDE_MD_POINTER, "utf8"),
spec.projectMd
? writeFile(join(spec.workspaceDir, "PROJECT.md"), spec.projectMd, "utf8")
: Promise.resolve(),
+ // Remove the sidecar older provisions wrote.
+ rm(join(spec.workspaceDir, "SKILL.md"), { force: true }),
]);
}
diff --git a/notfair/src/server/adapters/codex-local/provision.ts b/notfair/src/server/adapters/codex-local/provision.ts
index d62c2d9d..b46322b7 100644
--- a/notfair/src/server/adapters/codex-local/provision.ts
+++ b/notfair/src/server/adapters/codex-local/provision.ts
@@ -1,4 +1,4 @@
-import { mkdir, writeFile } from "node:fs/promises";
+import { mkdir, rm, writeFile } from "node:fs/promises";
import { join } from "node:path";
import type { AgentProvisionSpec } from "../types";
@@ -8,19 +8,21 @@ import type { AgentProvisionSpec } from "../types";
* Layout under `<workspaceDir>/`:
* IDENTITY.md — NotFair source of truth (also written so humans see it)
* AGENTS.md — same content; codex auto-loads AGENTS.md from cwd
- * SKILL.md — the goal-loop skill text
* PROJECT.md — project brief if available
+ *
+ * The skill text lives INSIDE the identity — never as a SKILL.md sidecar,
+ * which would be the same content twice (once auto-loaded, once whenever
+ * the agent reads the file).
*/
export async function provisionCodexAgent(spec: AgentProvisionSpec): Promise<void> {
await mkdir(spec.workspaceDir, { recursive: true });
await Promise.all([
writeFile(join(spec.workspaceDir, "IDENTITY.md"), spec.identityMd, "utf8"),
writeFile(join(spec.workspaceDir, "AGENTS.md"), spec.identityMd, "utf8"),
- spec.skillMd
- ? writeFile(join(spec.workspaceDir, "SKILL.md"), spec.skillMd, "utf8")
- : Promise.resolve(),
spec.projectMd
? writeFile(join(spec.workspaceDir, "PROJECT.md"), spec.projectMd, "utf8")
: Promise.resolve(),
+ // Remove the sidecar older provisions wrote.
+ rm(join(spec.workspaceDir, "SKILL.md"), { force: true }),
]);
}
diff --git a/notfair/src/server/adapters/types.ts b/notfair/src/server/adapters/types.ts
index 875b6d28..ba48c003 100644
--- a/notfair/src/server/adapters/types.ts
+++ b/notfair/src/server/adapters/types.ts
@@ -40,8 +40,6 @@ export interface AgentProvisionSpec {
workspaceDir: string;
/** The fully-rendered IDENTITY.md the agent should run with. */
identityMd: string;
- /** The shared SKILL.md (goals MCP usage etc.). Optional sidecar copy. */
- skillMd?: string;
/** PROJECT.md context, if a project brief exists yet. */
projectMd?: string;
}
diff --git a/notfair/src/server/agents/provisioning.ts b/notfair/src/server/agents/provisioning.ts
index 0b32e793..7ef4c232 100644
--- a/notfair/src/server/agents/provisioning.ts
+++ b/notfair/src/server/agents/provisioning.ts
@@ -19,7 +19,6 @@ export interface ProvisionInput {
displayName: string;
templateKey: string;
identityMd: string;
- skillMd?: string;
projectMd?: string;
harnessAdapter: HarnessAdapterId;
}
@@ -33,7 +32,6 @@ export async function provisionAgent(input: ProvisionInput): Promise<void> {
templateKey: input.templateKey,
workspaceDir: workspaceDirFor(input.agentId),
identityMd: input.identityMd,
- skillMd: input.skillMd,
projectMd: input.projectMd,
};
await adapter.provisionAgent(spec);
diff --git a/notfair/src/server/goals/identity.ts b/notfair/src/server/goals/identity.ts
index ff3280be..be8d8fe4 100644
--- a/notfair/src/server/goals/identity.ts
+++ b/notfair/src/server/goals/identity.ts
@@ -49,38 +49,10 @@ State lives in tool calls, never in prose. Every tool requires
\`project_slug\`, \`agent_id\`, and usually \`goal_id\` — take them from
"Your runtime identity" above. Never guess.
-- \`get_goal\` — full goal state incl. the shared context, your logged
- spend total, and resources gated by OTHER agents. Call FIRST whenever
- you've lost context.
-- \`define_goal\` — intake: record the ambition + a compact
- \`short_label\` ("Wasted X spend → $0") — the label is how the user
- identifies this goal everywhere in the UI, so make it specific.
-- \`propose_goal_metric\` — intake: submit the metric you authored AND
- tested; the platform re-runs it server-side and records the baseline.
-- \`backfill_metric_history\` — intake: submit a date-segmented version
- of the metric (per-day values, ~30 days) so the progress chart has
- history from day one.
-- \`propose_target\` — intake: record the target/cadence/envelope the
- user agreed to. The USER starts the loop with the START button on
- your Goal tab — you cannot start it, and the first tick fires the
- moment they click.
-- \`amend_goal\` — adjust a live goal when the user asks: new target,
- deadline, envelope, or cadence. Echo the change back after.
-- \`log_goal_action\` — record a move BEFORE you execute it: kind
- (mutation / research / decision), description, resources_touched,
- expected_effect, review_after_hours (required for mutations), and
- spend_usd when the move commits incremental spend.
-- \`review_goal_action\` — score an action whose review date arrived:
- what actually happened vs. expected_effect.
-- \`register_pull_request\` — record a PR you opened against the
- workspace's codebase (see "Changing the code" below). The platform
- syncs its GitHub state into every tick brief and shows it to the user
- for review.
-- \`log_learning\` / \`search_learnings\` — your durable memory.
-- \`update_goal_status\` — declare achieved / failed, or pause. Requires
- a reason grounded in the measured metric.
-- \`set_shared_context\` — rewrite the shared workspace brief (all
- agents see it).
+Each \`notfair-goals\` tool carries its full contract in its own
+description — read those rather than re-deriving parameters. The
+sections below tell you WHEN to call what; the descriptions tell you
+HOW. Re-anchor with \`get_goal\` whenever you've lost context.
### Intake: define the goal in conversation
@@ -101,13 +73,22 @@ is a short conversation that ends with a measurable goal:
2. **Author the metric.** Explore the connected data sources, write ONE
tool call (usually \`runScript\`) that returns a single number — bare
number or \`{value: <number>}\`, trailing window (e.g. last 30 days)
- so every tick measures the same shape. TEST it yourself.
+ so every tick measures the same shape. When no connected MCP can
+ measure the ambition (GitHub state, a local database, an external
+ endpoint), use the \`local\` source instead: key \`local\`, tool
+ \`shell\`, args \`{"command": "<sh command>"}\` — the platform runs
+ the command on this machine and reads the number from stdout. Use
+ absolute paths. Either way, TEST it yourself first.
3. **Verify.** \`propose_goal_metric\`. If the platform can't reproduce
a number, fix the query and propose again. Then give the user's chart
its history: write the DATE-SEGMENTED version of the same query
(per-day values, ~30 days), test it, and submit it via
\`backfill_metric_history\`. Skip only if the source truly can't
- segment by date.
+ segment by date. If the ambition has a natural leading indicator
+ (submissions while merges are the target, impressions while clicks
+ are), add it via \`add_supporting_metric\` — the platform measures it
+ on every check and shows it to the user, but the goal is judged on
+ the primary metric only.
4. **Agree the target.** Report the measured baseline, suggest a target
+ cadence + spend envelope, and ask. Choose the mode: \`achieve\`
(reach the number, then done) or \`maintain\` ("keep/hold/stay at X"
@@ -116,9 +97,9 @@ is a short conversation that ends with a measurable goal:
hit START on your Goal tab — the platform requires their click; you
cannot start the loop.
-If NO connected source can measure the ambition, say so plainly and
-name what to connect (the Connections page). Do not invent a proxy
-metric without flagging it.
+If neither a connected source nor a \`local\` shell command can
+measure the ambition, say so plainly and name what to connect (the
+Connections page). Do not invent a proxy metric without flagging it.
### The tick protocol
@@ -210,10 +191,6 @@ ticks must know goes into \`log_learning\`.
${BROWSER_SKILL}`;
-export function getGoalSkill(): string {
- return GOAL_SKILL;
-}
-
/**
* Render IDENTITY.md for a goal agent. Pure — provisioning writes it via
* the harness adapter (mirrored to CLAUDE.md / AGENTS.md per adapter).
diff --git a/notfair/src/server/goals/provision.ts b/notfair/src/server/goals/provision.ts
index ce0b9ca1..73150479 100644
--- a/notfair/src/server/goals/provision.ts
+++ b/notfair/src/server/goals/provision.ts
@@ -11,7 +11,7 @@ import {
} from "@/server/mcp-server/registration";
import { listProjectMcpTokens } from "@/server/mcp/tokens";
import { goalLabel } from "@/lib/goal-label";
-import { getGoalSkill, renderGoalIdentity } from "./identity";
+import { renderGoalIdentity } from "./identity";
/**
* Provisioning for goal agents. An agent is a consequence of a goal
@@ -59,7 +59,6 @@ export async function provisionGoalAgent(input: {
displayName: label,
templateKey: GOAL_TEMPLATE_KEY,
identityMd,
- skillMd: getGoalSkill(),
projectMd: brief ?? undefined,
harnessAdapter,
});
@@ -138,7 +137,6 @@ export async function syncGoalIdentity(goal: Goal): Promise<void> {
displayName: label,
templateKey: GOAL_TEMPLATE_KEY,
identityMd: renderGoalIdentity({ goal, brief, project }),
- skillMd: getGoalSkill(),
projectMd: brief ?? undefined,
harnessAdapter: project.harness_adapter ?? DEFAULT_HARNESS_ADAPTER,
});
diff --git a/notfair/src/server/skills/browser-skill.ts b/notfair/src/server/skills/browser-skill.ts
index c4b6a720..b4d4967b 100644
--- a/notfair/src/server/skills/browser-skill.ts
+++ b/notfair/src/server/skills/browser-skill.ts
@@ -83,20 +83,8 @@ Do not try to bypass interstitials by reloading or clicking around. The
user signed into this profile manually; if Google or Meta wants a
re-verification now, only the user can give it.
-### Tool inventory (full list in tool descriptions)
-
-- \`browser_status\` — is the workspace browser running, where the
- profile lives. Cheap; safe to call first.
-- \`browser_tabs\` — list every tab with handle, URL, title.
-- \`browser_open\` — open / reuse a tab. ALWAYS pass \`label\`.
-- \`browser_close\` — close a tab by handle.
-- \`browser_navigate\` — point an existing tab at a new URL.
-- \`browser_snapshot\` — get refs + text. Snapshot before every action.
-- \`browser_click\` — click ref. Supports right/middle/double + modifiers.
-- \`browser_type\` — type into ref. \`submit: true\` presses Enter after.
-- \`browser_press\` — single key / chord (Tab, Escape, Control+a, ...).
-- \`browser_scroll\` — viewport scroll up/down/left/right.
-- \`browser_back\` — history back.
+The full \`browser_*\` tool list with parameters arrives with the tool
+definitions themselves — don't re-learn it here, read the descriptions.
You CANNOT stop the workspace browser. Browser lifecycle belongs to the
user (Settings → Workspace browser → Stop). This is deliberate: every
@@ -104,8 +92,3 @@ agent in this workspace shares one Chrome, so stopping it would interrupt
your teammates mid-task.
`;
-
-/** Back-compat alias used by tests. */
-export function getBrowserSkill(): string {
- return BROWSER_SKILL;
-}