harness_code
Call before coding or reviewing code to receive an engineering scaffold that identifies failure patterns, provides correct-pattern examples, and verifies correctness.
Instructions
Call BEFORE generating, refactoring, reviewing, or debugging code. Trigger queries include: "write a function/script/class for X", "review this code/diff/PR", "refactor this", "debug this error", "is this implementation correct", "what's wrong with this code", "improve this code", "translate from X to Y language", "what would happen if I did X to this code", or any prompt that includes a code block the user wants you to act on. Also call when planning architectural changes, picking algorithms or data structures, or evaluating dependency upgrades. The tool returns an engineering scaffold (failure pattern, procedure, correct-pattern example, verification step) that you absorb internally before responding. It catches common LLM coding failure modes (hallucinated APIs, lost edge cases, premature algorithm commitment, silent contract violations, refactors that change behavior) that produce code which looks plausible but breaks under real conditions. DO NOT call for: pure code reading with no action requested, simple syntax questions, file system operations, running existing tests, or confirming an existing pattern is fine. When in doubt on non-trivial code work: call it. Pass a specific 1-2 sentence framing of WHAT you are coding or reviewing. Absorb the scaffold internally; do NOT echo bracket labels or harness vocabulary in your reply.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | 1-2 sentence framing of the task you need the harness for. Be specific about WHAT you are trying to do, not what tool you want. Good: 'diagnose why a microservice returns 503s under load'. Bad: 'help me think'. |
Implementation Reference
- src/index.ts:55-77 (handler)The registration loop that registers all harness tools including 'harness_code' via server.tool(). The handler calls callHarness(query, harness.mode) with mode='code'.
for (const harness of HARNESSES) { server.tool( harness.name, harness.description, querySchema, async ({ query }: { query: string }) => { try { const injection = await callHarness(query, harness.mode); return { content: [{ type: "text" as const, text: injection }], }; } catch (err) { const message = err instanceof Error ? err.message : String(err); return { content: [ { type: "text" as const, text: `Ejentum harness error: ${message}` }, ], isError: true, }; } }, ); } - src/index.ts:41-48 (schema)Zod query schema used by all harness tools including 'harness_code'. Requires a non-empty string query describing what the user is doing.
const querySchema = { query: z .string() .min(1, "query must be a non-empty string") .describe( "1-2 sentence framing of the task you need the harness for. Be specific about WHAT you are trying to do, not what tool you want. Good: 'diagnose why a microservice returns 503s under load'. Bad: 'help me think'.", ), }; - src/index.ts:21-26 (registration)Tool definition entry for 'harness_code' with name, mode='code', and description. Part of the HARNESSES array used in the registration loop.
{ name: "harness_code", mode: "code", description: "Call BEFORE generating, refactoring, reviewing, or debugging code. Trigger queries include: \"write a function/script/class for X\", \"review this code/diff/PR\", \"refactor this\", \"debug this error\", \"is this implementation correct\", \"what's wrong with this code\", \"improve this code\", \"translate from X to Y language\", \"what would happen if I did X to this code\", or any prompt that includes a code block the user wants you to act on. Also call when planning architectural changes, picking algorithms or data structures, or evaluating dependency upgrades. The tool returns an engineering scaffold (failure pattern, procedure, correct-pattern example, verification step) that you absorb internally before responding. It catches common LLM coding failure modes (hallucinated APIs, lost edge cases, premature algorithm commitment, silent contract violations, refactors that change behavior) that produce code which looks plausible but breaks under real conditions. DO NOT call for: pure code reading with no action requested, simple syntax questions, file system operations, running existing tests, or confirming an existing pattern is fine. When in doubt on non-trivial code work: call it. Pass a specific 1-2 sentence framing of WHAT you are coding or reviewing. Absorb the scaffold internally; do NOT echo bracket labels or harness vocabulary in your reply.", }, - src/client.ts:25-109 (helper)The callHarness function that makes the HTTP POST to the Ejentum API with the query and mode ('code' for harness_code). Handles auth, network errors, response parsing, and field extraction using bracket notation.
export async function callHarness( query: string, mode: HarnessMode, ): Promise<string> { const apiKey = process.env.EJENTUM_API_KEY; if (!apiKey || apiKey.trim().length === 0) { throw new Error( "EJENTUM_API_KEY is not set. Set it in your MCP client config (env block) and restart the client.", ); } const apiUrl = process.env.EJENTUM_API_URL || DEFAULT_API_URL; let response: Response; try { response = await fetch(apiUrl, { method: "POST", headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json", }, body: JSON.stringify({ query, mode }), }); } catch (err) { const detail = err instanceof Error ? err.message : String(err); throw new Error(`Network error calling Ejentum API at ${apiUrl}: ${detail}`); } if (!response.ok) { const body = await response.text().catch(() => ""); if (response.status === 401) { throw new LogicAPIError( 401, body, "Unauthorized (401): check your EJENTUM_API_KEY value. Get one at https://ejentum.com/dashboard.", ); } if (response.status === 403) { throw new LogicAPIError( 403, body, "Forbidden (403): your API key does not have access to this mode. Multi modes require the Haki tier.", ); } if (response.status === 429) { throw new LogicAPIError( 429, body, "Rate limit exceeded (429): you have hit your tier's request limit. See https://ejentum.com/pricing.", ); } throw new LogicAPIError( response.status, body, `Ejentum API returned ${response.status}: ${body.slice(0, 200)}`, ); } let parsed: unknown; try { parsed = await response.json(); } catch { throw new Error("Ejentum API returned invalid JSON"); } if (!Array.isArray(parsed) || parsed.length === 0) { throw new Error( `Ejentum API returned unexpected shape (expected non-empty array): ${JSON.stringify(parsed).slice(0, 200)}`, ); } const item = parsed[0] as LogicAPIResponseItem; // Bracket access is required because the `anti-deception` field name contains a hyphen. // Dot access (item.anti-deception) would parse as `item.anti - deception` and silently break. const injection = item[mode]; if (typeof injection !== "string" || injection.length === 0) { throw new Error( `Ejentum API response missing or empty "${mode}" field. Got: ${JSON.stringify(item).slice(0, 200)}`, ); } return injection; } - src/client.ts:8-8 (helper)Type definition for HarnessMode, used to type the mode parameter for harness_code ('code').
export type HarnessMode = "reasoning" | "code" | "anti-deception" | "memory";