CodeSampleX

Sample

chalk 4.1.2

Verified sample for npm chalk 4.1.2. The contract ran on node 22 · linux alpine/x64 · docker and passed: chalk styles terminal text with foreground colors…

sha256:af420db0115b2b548c363f73f273b92231b8be663d8fd051f3515d934e0af195

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Verification-run environments

Environment Contract Stages Run
node 22 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-19

Case

HOW
Goal
verify pkg:npm/chalk@4.1.2
Packages
Environment
node 22.23.2
Created
2026-08-19T18:31:31Z

Contract

  1. chalk styles terminal text with foreground colors, background colors, and text modifiers
  2. chalk supports style chaining and truecolor models including RGB and Hex
  3. chalk Instance level configuration allows controlling ANSI color support and disabling styles deterministically

Files

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.js

Download the source artifact (tar.gz)

Source

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify pkg:npm/chalk@4.1.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/chalk@4.1.2
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:40ee748ff7076525c89f4c453b8ddb99f18432b01ec562101d280e615754f97c","constraints":{"executionContext":"node"},"contract":["chalk styles terminal text with foreground colors, background colors, and text modifiers","chalk supports style chaining and truecolor models including RGB and Hex","chalk Instance level configuration allows controlling ANSI color support and disabling styles deterministically"],"goal":"verify pkg:npm/chalk@4.1.2","kind":"HOW","packages":["pkg:npm/chalk@4.1.2"],"schemaVersion":1},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/chalk@4.1.2"],"schemaVersion":1,"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "chalk-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "chalk-sample",
      "version": "1.0.0",
      "dependencies": {
        "chalk": "4.1.2"
      }
    },
    "node_modules/ansi-styles": {
      "version": "4.3.0",
      "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
      "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
      "license": "MIT",
      "dependencies": {
        "color-convert": "^2.0.1"
      },
      "engines": {
        "node": ">=8"
      },
      "funding": {
        "url": "https://github.com/chalk/ansi-styles?sponsor=1"
      }
    },
    "node_modules/chalk": {
      "version": "4.1.2",
      "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
      "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
      "license": "MIT",
      "dependencies": {
        "ansi-styles": "^4.1.0",
        "supports-color": "^7.1.0"
      },
      "engines": {
        "node": ">=10"
      },
      "funding": {
        "url": "https://github.com/chalk/chalk?sponsor=1"
      }
    },
    "node_modules/color-convert": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
      "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
      "license": "MIT",
      "dependencies": {
        "color-name": "~1.1.4"
      },
      "engines": {
        "node": ">=7.0.0"
      }
    },
    "node_modules/color-name": {
      "version": "1.1.4",
      "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
      "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
      "license": "MIT"
    },
    "node_modules/has-flag": {
      "version": "4.0.0",
      "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
      "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
      "license": "MIT",
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/supports-color": {
      "version": "7.2.0",
      "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
      "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
      "license": "MIT",
      "dependencies": {
        "has-flag": "^4.0.0"
      },
      "engines": {
        "node": ">=8"
      }
    }
  }
}
package.json
{
  "name": "chalk-sample",
  "version": "1.0.0",
  "dependencies": {
    "chalk": "4.1.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/chalk@4.1.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/chalk@4.1.2"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const chalk = require('chalk');

/**
 * Creates a configured Chalk instance with explicit color level support.
 *
 * @param {number} [level=3] - Color level (0: disabled, 1: 16 colors, 2: 256 colors, 3: 16M truecolor).
 * @returns {import('chalk').Chalk}
 */
function createFormatter(level = 3) {
  return new chalk.Instance({ level });
}

/**
 * Formats text with standard foreground color and optional bold modifier.
 *
 * @param {import('chalk').Chalk} instance
 * @param {string} text
 * @param {'blue'|'green'|'red'|'yellow'} color
 * @param {boolean} [bold=false]
 * @returns {string}
 */
function formatColor(instance, text, color, bold = false) {
  let fn = instance[color];
  if (bold) {
    fn = fn.bold;
  }
  return fn(text);
}

/**
 * Formats text with background color.
 *
 * @param {import('chalk').Chalk} instance
 * @param {string} text
 * @param {'bgBlue'|'bgGreen'|'bgRed'|'bgYellow'} bgColor
 * @returns {string}
 */
function formatBackground(instance, text, bgColor) {
  return instance[bgColor](text);
}

/**
 * Formats text using custom RGB truecolor.
 *
 * @param {import('chalk').Chalk} instance
 * @param {string} text
 * @param {number} r
 * @param {number} g
 * @param {number} b
 * @returns {string}
 */
function formatRgb(instance, text, r, g, b) {
  return instance.rgb(r, g, b)(text);
}

/**
 * Formats text using custom Hex color.
 *
 * @param {import('chalk').Chalk} instance
 * @param {string} text
 * @param {string} hexCode
 * @returns {string}
 */
function formatHex(instance, text, hexCode) {
  return instance.hex(hexCode)(text);
}

/**
 * Formats text with chained styling.
 *
 * @param {import('chalk').Chalk} instance
 * @param {string} text
 * @returns {string}
 */
function formatChainedHighlight(instance, text) {
  return instance.bold.underline.red(text);
}

module.exports = {
  createFormatter,
  formatColor,
  formatBackground,
  formatRgb,
  formatHex,
  formatChainedHighlight,
  chalk,
};
test/contract.js
const assert = require('node:assert/strict');
const {
  createFormatter,
  formatColor,
  formatBackground,
  formatRgb,
  formatHex,
  formatChainedHighlight,
} = require('../src/index.js');

// Contract 1: chalk styles terminal text with foreground colors, background colors, and text modifiers
{
  const formatter = createFormatter(3);

  const blueText = formatColor(formatter, 'blue test', 'blue');
  assert.strictEqual(blueText, '\u001b[34mblue test\u001b[39m', 'Should wrap string in ANSI blue foreground escape codes');

  const boldGreenText = formatColor(formatter, 'green bold test', 'green', true);
  assert.strictEqual(boldGreenText, '\u001b[32m\u001b[1mgreen bold test\u001b[22m\u001b[39m', 'Should apply bold modifier and green foreground codes');

  const bgRedText = formatBackground(formatter, 'bg test', 'bgRed');
  assert.strictEqual(bgRedText, '\u001b[41mbg test\u001b[49m', 'Should wrap string in ANSI bgRed background escape codes');
}

// Contract 2: chalk supports style chaining and truecolor models including RGB and Hex
{
  const formatter = createFormatter(3);

  const rgbText = formatRgb(formatter, 'rgb test', 255, 128, 0);
  assert.strictEqual(rgbText, '\u001b[38;2;255;128;0mrgb test\u001b[39m', 'Should format text with 24-bit truecolor RGB escape sequence');

  const hexText = formatHex(formatter, 'hex test', '#DEADED');
  assert.strictEqual(hexText, '\u001b[38;2;222;173;237mhex test\u001b[39m', 'Should convert hex code to 24-bit RGB ANSI escape sequence');

  const chainedText = formatChainedHighlight(formatter, 'highlight');
  assert.strictEqual(chainedText, '\u001b[1m\u001b[4m\u001b[31mhighlight\u001b[39m\u001b[24m\u001b[22m', 'Should compose bold, underline, and red styling');
}

// Contract 3: chalk Instance level configuration allows controlling ANSI color support and disabling styles deterministically
{
  const disabledFormatter = createFormatter(0);
  assert.strictEqual(disabledFormatter.level, 0, 'Instance color level should be 0');

  const plainBlue = formatColor(disabledFormatter, 'plain text', 'blue');
  assert.strictEqual(plainBlue, 'plain text', 'Level 0 formatter should return unmodified plain text for color styles');

  const plainChained = formatChainedHighlight(disabledFormatter, 'plain text');
  assert.strictEqual(plainChained, 'plain text', 'Level 0 formatter should return unmodified plain text for chained styles');

  const level1Formatter = createFormatter(1);
  assert.strictEqual(level1Formatter.level, 1, 'Instance color level should be 1');
  const level1Blue = formatColor(level1Formatter, 'basic blue', 'blue');
  assert.strictEqual(level1Blue, '\u001b[34mbasic blue\u001b[39m', 'Level 1 basic color returns standard ANSI code');
}

console.log('All pkg:npm/chalk@4.1.2 contracts passed successfully.');

Origin Seeder

anonymous