CodeSampleX

Пример

sisteransi 1.0.5: beep, cursor, erase

Проверенный пример — npm sisteransi 1.0.5: beep, cursor, erase. Контракт выполнен на node 22 · linux alpine/x64 · docker и пройден.

sha256:5fae8172b0b60e66c27b81b20dd8bf4036edddbf57001e792a27cb3fc8a7d66f

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
2
Ключи подписи, собравшие его
1
Заявленная среда node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Среды запусков проверки

Окружение Контракт Этапы Запуск
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-23
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-07

Кейс

HOW
Цель
verify pkg:npm/sisteransi@1.0.5
Пакеты
Символы
  • sisteransi.beep
  • sisteransi.cursor
  • sisteransi.erase
  • sisteransi.scroll
Окружение
node 22.23.2
Создан
2026-08-23T17:06:55Z

Контракт

  1. beep returns ANSI audio bell escape code
  2. cursor.to and cursor.move produce absolute and relative cursor positioning escape sequences
  3. cursor directional methods generate up, down, forward, backward, nextLine, and prevLine ANSI sequences
  4. cursor.hide, cursor.show, cursor.save, and cursor.restore produce cursor visibility and position save/restore escape sequences
  5. scroll.up and scroll.down generate terminal buffer scroll escape sequences
  6. erase.screen, erase.line, erase.lineEnd, erase.lineStart, and erase.lines generate display and line clearing ANSI sequences

Файлы

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

Скачать артефакт с исходным кодом (tar.gz)

Исходный код

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/sisteransi@1.0.5
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/sisteransi@1.0.5
Demonstrate these symbols/APIs:
  - sisteransi.beep
  - sisteransi.cursor
  - sisteransi.erase
  - sisteransi.scroll
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:2153332118adeef97613ce84b909edd29b36dfe62f66e21a99b4c23bef9444c1","constraints":{"executionContext":"node"},"contract":["beep returns ANSI audio bell escape code","cursor.to and cursor.move produce absolute and relative cursor positioning escape sequences","cursor directional methods generate up, down, forward, backward, nextLine, and prevLine ANSI sequences","cursor.hide, cursor.show, cursor.save, and cursor.restore produce cursor visibility and position save/restore escape sequences","scroll.up and scroll.down generate terminal buffer scroll escape sequences","erase.screen, erase.line, erase.lineEnd, erase.lineStart, and erase.lines generate display and line clearing ANSI sequences"],"goal":"verify pkg:npm/sisteransi@1.0.5","kind":"HOW","packages":["pkg:npm/sisteransi@1.0.5"],"schemaVersion":1,"symbols":["sisteransi.beep","sisteransi.cursor","sisteransi.erase","sisteransi.scroll"]},"contractCommand":["node","test/contract.cjs"],"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/sisteransi@1.0.5"],"schemaVersion":1,"subject":"pkg:npm/sisteransi@1.0.5","symbols":["sisteransi.beep","sisteransi.cursor","sisteransi.erase","sisteransi.scroll"],"verifierAdapter":"node-typescript@1"}
index.cjs
'use strict';

const ansi = require('sisteransi');

/**
 * Demonstrates ANSI cursor navigation, screen/line erasing, scrolling, and bell signals using sisteransi.
 */
function getCursorPosition(x, y) {
  return ansi.cursor.to(x, y);
}

function moveCursor(x, y) {
  return ansi.cursor.move(x, y);
}

function clearLines(count) {
  return ansi.erase.lines(count);
}

function scrollBuffer(direction, count = 1) {
  if (direction === 'up') {
    return ansi.scroll.up(count);
  } else if (direction === 'down') {
    return ansi.scroll.down(count);
  }
  throw new Error('Invalid scroll direction');
}

function getBeep() {
  return ansi.beep;
}

module.exports = {
  ansi,
  getCursorPosition,
  moveCursor,
  clearLines,
  scrollBuffer,
  getBeep,
};
package-lock.json
{
  "name": "sample-sisteransi",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-sisteransi",
      "version": "1.0.0",
      "dependencies": {
        "sisteransi": "1.0.5"
      }
    },
    "node_modules/sisteransi": {
      "version": "1.0.5",
      "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz",
      "integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-sisteransi",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of sisteransi",
  "dependencies": {
    "sisteransi": "1.0.5"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/sisteransi@1.0.5",
  "kind": "HOW",
  "packages": [
    "pkg:npm/sisteransi@1.0.5"
  ],
  "symbols": [
    "sisteransi.beep",
    "sisteransi.cursor",
    "sisteransi.erase",
    "sisteransi.scroll"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.cjs
'use strict';

const assert = require('node:assert/strict');
const ansi = require('sisteransi');
const {
  getCursorPosition,
  moveCursor,
  clearLines,
  scrollBuffer,
  getBeep,
} = require('../index.cjs');

// 1. sisteransi exports
assert.equal(typeof ansi, 'object', 'sisteransi must export an object');
assert.equal(typeof ansi.cursor, 'object', 'cursor must be an object');
assert.equal(typeof ansi.scroll, 'object', 'scroll must be an object');
assert.equal(typeof ansi.erase, 'object', 'erase must be an object');
assert.equal(typeof ansi.beep, 'string', 'beep must be a string');

// 2. Beep escape character
assert.equal(ansi.beep, '\u0007', 'beep matches ASCII BEL code');
assert.equal(getBeep(), '\u0007', 'getBeep returns ASCII BEL code');

// 3. Cursor positioning and movement
assert.equal(ansi.cursor.to(2), '\x1b[3G', 'cursor.to single coordinate (x)');
assert.equal(ansi.cursor.to(2, 1), '\x1b[2;3H', 'cursor.to x and y coordinates');
assert.equal(getCursorPosition(2, 1), '\x1b[2;3H', 'getCursorPosition helper');
assert.equal(ansi.cursor.move(2, -3), '\x1b[2C\x1b[3A', 'cursor.move forward and up');
assert.equal(ansi.cursor.move(-1, 4), '\x1b[1D\x1b[4B', 'cursor.move backward and down');
assert.equal(moveCursor(2, -3), '\x1b[2C\x1b[3A', 'moveCursor helper');

assert.equal(ansi.cursor.up(2), '\x1b[2A', 'cursor.up with count');
assert.equal(ansi.cursor.up(), '\x1b[1A', 'cursor.up default count');
assert.equal(ansi.cursor.down(3), '\x1b[3B', 'cursor.down with count');
assert.equal(ansi.cursor.forward(4), '\x1b[4C', 'cursor.forward with count');
assert.equal(ansi.cursor.backward(1), '\x1b[1D', 'cursor.backward with count');
assert.equal(ansi.cursor.nextLine(2), '\x1b[E\x1b[E', 'cursor.nextLine with count');
assert.equal(ansi.cursor.prevLine(1), '\x1b[F', 'cursor.prevLine with count');
assert.equal(ansi.cursor.left, '\x1b[G', 'cursor.left');
assert.equal(ansi.cursor.hide, '\x1b[?25l', 'cursor.hide');
assert.equal(ansi.cursor.show, '\x1b[?25h', 'cursor.show');
assert.equal(ansi.cursor.save, '\x1b7', 'cursor.save');
assert.equal(ansi.cursor.restore, '\x1b8', 'cursor.restore');

// 4. Scroll operations
assert.equal(ansi.scroll.up(), '\x1b[S', 'scroll.up default count');
assert.equal(ansi.scroll.up(2), '\x1b[S\x1b[S', 'scroll.up with count');
assert.equal(ansi.scroll.down(2), '\x1b[T\x1b[T', 'scroll.down with count');
assert.equal(scrollBuffer('up', 2), '\x1b[S\x1b[S', 'scrollBuffer helper up');
assert.equal(scrollBuffer('down', 1), '\x1b[T', 'scrollBuffer helper down');
assert.throws(() => scrollBuffer('left'), /Invalid scroll direction/);

// 5. Erase operations
assert.equal(ansi.erase.screen, '\x1b[2J', 'erase.screen');
assert.equal(ansi.erase.up(2), '\x1b[1J\x1b[1J', 'erase.up with count');
assert.equal(ansi.erase.down(1), '\x1b[J', 'erase.down with count');
assert.equal(ansi.erase.line, '\x1b[2K', 'erase.line');
assert.equal(ansi.erase.lineEnd, '\x1b[K', 'erase.lineEnd');
assert.equal(ansi.erase.lineStart, '\x1b[1K', 'erase.lineStart');
assert.equal(ansi.erase.lines(0), '', 'erase.lines 0');
assert.equal(ansi.erase.lines(2), '\x1b[2K\x1b[1A\x1b[2K\x1b[G', 'erase.lines 2');
assert.equal(clearLines(2), '\x1b[2K\x1b[1A\x1b[2K\x1b[G', 'clearLines helper');

console.log('Contract test passed.');

Исходный сидер

аноним