Skip to content

drafael/coding-harness / skills/typesafe-ai

typesafe-ai

Verified

Build AI-powered software with TypeSafe: small units of AI intelligence you can use like programming primitives. Its System One models, including Jev, turn natural language and application state into typed judgments and probabilities that code can combine. Use when a feature needs programmable common sense, when brainstorming what AI could make possible in an app, or when an LLM prompt-and-parse step could become a structured decision. Applications include routing, ranking, extraction, verification, and interactive experiences; these are starting points, not the limits. Read live docs and cookbooks to find useful patterns and discover new combinations.

FileKindSize
LICENSEother1.0 KB
README.mdmarkdown2.5 KB
SKILL.mdskill md10.9 KB
scripts/evaluate.mjsexecutablescript3.4 KB
scripts/evaluate.test.mjsscript6.1 KB

scripts/evaluate.test.mjs

View on GitHub
import assert from "node:assert/strict";
import { spawn } from "node:child_process";
import { mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { dirname, join } from "node:path";
import test from "node:test";
import { fileURLToPath } from "node:url";

const SCRIPT_PATH = join(dirname(fileURLToPath(import.meta.url)), "evaluate.mjs");

function environment(apiKey) {
  const env = { ...process.env };
  if (apiKey === undefined) {
    delete env.TYPESAFE_API_KEY;
  } else {
    env.TYPESAFE_API_KEY = apiKey;
  }
  return env;
}

function runCli(options) {
  const { args = [], input, preload } = options;
  const apiKey = Object.hasOwn(options, "apiKey") ? options.apiKey : "test-key";
  const nodeArgs = [];
  if (preload) {
    nodeArgs.push("--import", preload);
  }
  nodeArgs.push(SCRIPT_PATH, ...args);

  return new Promise((resolve, reject) => {
    const child = spawn(process.execPath, nodeArgs, {
      env: environment(apiKey),
      stdio: ["pipe", "pipe", "pipe"],
    });
    let stdout = "";
    let stderr = "";

    child.stdout.setEncoding("utf8");
    child.stderr.setEncoding("utf8");
    child.stdout.on("data", (chunk) => {
      stdout += chunk;
    });
    child.stderr.on("data", (chunk) => {
      stderr += chunk;
    });
    child.stdin.on("error", (error) => {
      if (error.code !== "EPIPE") {
        reject(error);
      }
    });
    child.on("error", reject);
    child.on("close", (code, signal) => {
      resolve({ code, signal, stdout, stderr });
    });

    child.stdin.end(input);
  });
}

async function createSandbox(t) {
  const directory = await mkdtemp(join(tmpdir(), "typesafe-ai-test-"));
  t.after(() => rm(directory, { recursive: true, force: true }));
  return directory;
}

async function writeSuccessPreload(directory) {
  const path = join(directory, "success-fetch.mjs");
  await writeFile(
    path,
    `globalThis.fetch = async (url, options) => new Response(JSON.stringify({
  url,
  method: options.method,
  authorization: options.headers.Authorization,
  request: JSON.parse(options.body),
}), { status: 200, headers: { "Content-Type": "application/json" } });\n`,
  );
  return path;
}

const validRequest = {
  state: "hello",
  questions: {
    greeting: {
      type: "noul",
      instructions: "Is this a greeting?",
    },
  },
};

test("evaluate reads a request file and writes the successful response only to stdout", async (t) => {
  const directory = await createSandbox(t);
  const preload = await writeSuccessPreload(directory);
  const requestPath = join(directory, "request.json");
  await writeFile(requestPath, JSON.stringify(validRequest));

  const result = await runCli({ args: [requestPath], preload });

  assert.equal(result.code, 0);
  assert.equal(result.signal, null);
  assert.equal(result.stderr, "");
  const response = JSON.parse(result.stdout);
  assert.equal(response.url, "https://api.typesafe.ai/v1/systemone");
  assert.equal(response.method, "POST");
  assert.equal(response.authorization, "Bearer test-key");
  assert.equal(response.request.model, "jev-latest");
  assert.deepEqual(response.request.state, validRequest.state);
});

test("evaluate reads a piped request from stdin", async (t) => {
  const directory = await createSandbox(t);
  const preload = await writeSuccessPreload(directory);

  const result = await runCli({ input: JSON.stringify(validRequest), preload });

  assert.equal(result.code, 0);
  assert.equal(result.stderr, "");
  assert.equal(JSON.parse(result.stdout).request.questions.greeting.type, "noul");
});

test("evaluate prints help to stdout without requiring an API key", async () => {
  const result = await runCli({ args: ["--help"], apiKey: undefined });

  assert.equal(result.code, 0);
  assert.match(result.stdout, /^Usage:/);
  assert.equal(result.stderr, "");
});

test("evaluate rejects a missing API key without writing to stdout", async () => {
  const result = await runCli({ input: JSON.stringify(validRequest), apiKey: undefined });

  assert.equal(result.code, 1);
  assert.equal(result.stdout, "");
  assert.match(result.stderr, /TYPESAFE_API_KEY is not set/);
});

test("evaluate rejects malformed JSON without writing to stdout", async () => {
  const result = await runCli({ input: "{bad json" });

  assert.equal(result.code, 1);
  assert.equal(result.stdout, "");
  assert.match(result.stderr, /Request is not valid JSON/);
});

test("evaluate rejects an empty questions object", async () => {
  const result = await runCli({
    input: JSON.stringify({ state: "hello", questions: {} }),
  });

  assert.equal(result.code, 1);
  assert.equal(result.stdout, "");
  assert.match(result.stderr, /non-empty "questions" object/);
});

test("evaluate omits API error bodies that may contain submitted state", async (t) => {
  const directory = await createSandbox(t);
  const preload = join(directory, "error-fetch.mjs");
  await writeFile(
    preload,
    `globalThis.fetch = async () => new Response(JSON.stringify({
  detail: "Rejected state: PRIVATE_STATE",
  state: "PRIVATE_STATE",
}), { status: 422, headers: { "Content-Type": "application/json" } });\n`,
  );

  const result = await runCli({
    input: JSON.stringify({ ...validRequest, state: "PRIVATE_STATE" }),
    preload,
  });

  assert.equal(result.code, 1);
  assert.equal(result.stdout, "");
  assert.match(result.stderr, /HTTP 422/);
  assert.match(result.stderr, /Response body omitted/);
  assert.doesNotMatch(result.stderr, /PRIVATE_STATE|Rejected state/);
});

test("evaluate reports a bounded request timeout", async (t) => {
  const directory = await createSandbox(t);
  const preload = join(directory, "timeout-fetch.mjs");
  await writeFile(
    preload,
    `AbortSignal.timeout = () => AbortSignal.abort(new DOMException("Synthetic timeout", "TimeoutError"));
globalThis.fetch = async (_url, options) => {
  if (!options.signal?.aborted) {
    throw new Error("Expected an aborted timeout signal");
  }
  throw options.signal.reason;
};\n`,
  );

  const result = await runCli({ input: JSON.stringify(validRequest), preload });

  assert.equal(result.code, 1);
  assert.equal(result.stdout, "");
  assert.match(result.stderr, /timed out after 10000 ms/);
});
rea-changelog-updatemorluto/reaPrepare or rewrite REA release changelogs and GitHub release notes from pinned Git history, with verified contributor thanks and Release Please synchronization.Stars: 467kUpdated Claude CodeCodexVerifiedInstall
academy-guideanthropics/skillsStop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials, and use cases from Claude Academy (academy.claude.com), Anthropic's learning hub. Trigger on: "how do I", "how can I", "getting started with", "what can Claude do", "teach me", "learn to use"; questions about artifacts, projects, skills, plugins, connectors, MCP; requests about rolling Claude out to a team, class, or organization; and any ask for training materials, onboarding content, or learning resources. Use it when the user is learning how to use a feature or product — not when they are mid-task and just want the task done. This skill composes with other skills: after consulting product documentation to answer how a Claude feature works, also check here for a matching course or tutorial — a docs-grounded answer and an Academy recommendation belong together. Only recommend on a strong match; never invent Academy content.Stars: 196kUpdated Claude CodeCodexVerifiedInstall
claude-apianthropics/skillsReference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER — read BEFORE opening the target file; don't skip because it "looks like a one-liner" — whenever: the prompt names Claude/Anthropic in any form (Claude, Anthropic, Fable, Opus, Sonnet, Haiku, `anthropic`, `@anthropic-ai`, `claude-*`, `us.anthropic.*`, `[1m]`); the user asks about an LLM (pricing/model choice/limits/caching) — never answer from memory; OR the task is LLM-shaped with provider unstated (agent/MCP/tool-definition/multi-agent/RAG/LLM-judge/computer-use; generate/summarize/extract/classify/rewrite/converse over NL; debugging refusals/cutoffs/streaming/tool-calls/tokens). SKIP only when another provider is being worked on (overrides all triggers): OpenAI/GPT/Gemini/Llama/Mistral/Cohere/Ollama named in the query; OR `grep -rE 'openai|langchain_openai|google.generativeai|genai|mistralai|cohere|ollama'` over the project hits (run this grep FIRST if no provider named — don't Read the file).Stars: 196kUpdated Claude CodeCodexUnverifiedInstall
doc-coauthoringanthropics/skillsGuide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision docs, or similar structured content. This workflow helps users efficiently transfer context, refine content through iteration, and verify the doc works for readers. Trigger when user mentions writing docs, creating proposals, drafting specs, or similar documentation tasks.Stars: 196kUpdated Claude CodeCodexVerifiedInstall