示例
ansi-escapes 4.3.2: ansiEscapes.cursorMove, ansiEscapes.cursorTo, ansiEscapes.eraseScreen
已验证示例 — npm ansi-escapes 4.3.2: ansiEscapes.cursorMove, ansiEscapes.cursorTo, ansiEscapes.eraseScreen. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过.
sha256:fbbd6e4e48cadea756d5e2e5480e1b3e05b56a8f685b9c196519954cdda0c0e0
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
linux 24 · ubuntu · glibc 2.39 x64 npm
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| 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-27 |
案例
HOW- 目标
- verify pkg:npm/ansi-escapes@4.3.2
- 符号
-
- ansiEscapes.cursorMove
- ansiEscapes.cursorTo
- ansiEscapes.eraseScreen
- 创建时间
- 2026-08-27T21:47:27Z
契约
- cursorTo moves cursor to absolute column x or position (x, y)
- cursorTo throws TypeError when x is not a number
- cursorMove produces relative cursor movement escape sequences for horizontal and vertical offsets
- cursorMove throws TypeError when x is not a number
- eraseScreen provides the ANSI escape code to erase the entire screen
文件
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.js
源代码
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/ansi-escapes@4.3.2
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/ansi-escapes@4.3.2
Demonstrate these symbols/APIs:
- ansiEscapes.cursorMove
- ansiEscapes.cursorTo
- ansiEscapes.eraseScreen
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.
{"case":{"caseId":"case:sha256:0b394e43d33274115df2006abc1e370cfad4ca1fb33edb614463957bf5d9f4b3","contract":["cursorTo moves cursor to absolute column x or position (x, y)","cursorTo throws TypeError when x is not a number","cursorMove produces relative cursor movement escape sequences for horizontal and vertical offsets","cursorMove throws TypeError when x is not a number","eraseScreen provides the ANSI escape code to erase the entire screen"],"goal":"verify pkg:npm/ansi-escapes@4.3.2","kind":"HOW","packages":["pkg:npm/ansi-escapes@4.3.2"],"schemaVersion":1,"symbols":["ansiEscapes.cursorMove","ansiEscapes.cursorTo","ansiEscapes.eraseScreen"]},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/ansi-escapes@4.3.2"],"schemaVersion":1,"subject":"pkg:npm/ansi-escapes@4.3.2","symbols":["ansiEscapes.cursorMove","ansiEscapes.cursorTo","ansiEscapes.eraseScreen"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-ansi-escapes",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-ansi-escapes",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"ansi-escapes": "4.3.2"
}
},
"node_modules/ansi-escapes": {
"version": "4.3.2",
"resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.2.tgz",
"integrity": "sha512-gKXj5ALrKWQLsYG9jlTRmR/xKluxHV+Z9QEwNIgCfM1/uwPMCuzVVnh5mwTd+OuBZcwSIMbqssNWRm1lE51QaQ==",
"license": "MIT",
"dependencies": {
"type-fest": "^0.21.3"
},
"engines": {
"node": ">=8"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/type-fest": {
"version": "0.21.3",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.21.3.tgz",
"integrity": "sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==",
"license": "(MIT OR CC0-1.0)",
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
}
}
}
{
"name": "sample-ansi-escapes",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification for ansi-escapes cursor positioning and screen clearing",
"main": "src/index.js",
"scripts": {
"test": "node test/contract.js"
},
"dependencies": {
"ansi-escapes": "4.3.2"
},
"license": "MIT-0"
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/ansi-escapes@4.3.2",
"kind": "HOW",
"packages": [
"pkg:npm/ansi-escapes@4.3.2"
],
"symbols": [
"ansiEscapes.cursorMove",
"ansiEscapes.cursorTo",
"ansiEscapes.eraseScreen"
]
}
const ansiEscapesModule = require('ansi-escapes');
const ansiEscapes = ansiEscapesModule.default || ansiEscapesModule;
const { cursorTo, cursorMove, eraseScreen } = ansiEscapes;
/**
* Moves cursor to absolute column x or position (x, y).
* @param {number} x - 0-based column coordinate
* @param {number} [y] - 0-based row coordinate
* @returns {string} ANSI escape sequence
*/
function moveTo(x, y) {
return cursorTo(x, y);
}
/**
* Moves cursor relative to current position by x columns and y rows.
* @param {number} x - horizontal relative offset
* @param {number} [y] - vertical relative offset
* @returns {string} ANSI escape sequence
*/
function moveCursor(x, y) {
return cursorMove(x, y);
}
/**
* Erases the entire screen.
* @returns {string} ANSI escape sequence
*/
function getEraseScreenCode() {
return eraseScreen;
}
/**
* Positions cursor and writes text.
* @param {number} x
* @param {number} y
* @param {string} text
* @returns {string}
*/
function renderAt(x, y, text) {
return `${cursorTo(x, y)}${text}`;
}
/**
* Erases screen, positions cursor, and writes text.
* @param {number} x
* @param {number} y
* @param {string} text
* @returns {string}
*/
function clearAndRender(x, y, text) {
return `${eraseScreen}${cursorTo(x, y)}${text}`;
}
module.exports = {
ansiEscapes,
cursorTo,
cursorMove,
eraseScreen,
moveTo,
moveCursor,
getEraseScreenCode,
renderAt,
clearAndRender,
};
const assert = require('node:assert');
const {
ansiEscapes,
cursorTo,
cursorMove,
eraseScreen,
moveTo,
moveCursor,
getEraseScreenCode,
renderAt,
clearAndRender,
} = require('../src/index.js');
// 1. cursorTo moves cursor to absolute column x or position (x, y)
assert.strictEqual(typeof cursorTo, 'function', 'cursorTo must be a function');
assert.strictEqual(cursorTo(0), '\u001B[1G');
assert.strictEqual(cursorTo(5), '\u001B[6G');
assert.strictEqual(cursorTo(0, 0), '\u001B[1;1H');
assert.strictEqual(cursorTo(10, 20), '\u001B[21;11H');
assert.strictEqual(moveTo(5), '\u001B[6G');
assert.strictEqual(moveTo(10, 20), '\u001B[21;11H');
assert.strictEqual(renderAt(4, 2, 'hello'), '\u001B[3;5Hhello');
// 2. cursorTo throws TypeError when x is not a number
assert.throws(() => {
cursorTo();
}, {
name: 'TypeError',
message: 'The `x` argument is required',
});
assert.throws(() => {
cursorTo(undefined, 5);
}, {
name: 'TypeError',
message: 'The `x` argument is required',
});
assert.throws(() => {
cursorTo('10');
}, {
name: 'TypeError',
message: 'The `x` argument is required',
});
// 3. cursorMove produces relative cursor movement escape sequences for horizontal and vertical offsets
assert.strictEqual(typeof cursorMove, 'function', 'cursorMove must be a function');
assert.strictEqual(cursorMove(0, 0), '');
assert.strictEqual(cursorMove(5, 0), '\u001B[5C');
assert.strictEqual(cursorMove(-3, 0), '\u001B[3D');
assert.strictEqual(cursorMove(0, 4), '\u001B[4B');
assert.strictEqual(cursorMove(0, -2), '\u001B[2A');
assert.strictEqual(cursorMove(2, 3), '\u001B[2C\u001B[3B');
assert.strictEqual(cursorMove(-1, -4), '\u001B[1D\u001B[4A');
assert.strictEqual(cursorMove(3), '\u001B[3C');
assert.strictEqual(moveCursor(2, 3), '\u001B[2C\u001B[3B');
// 4. cursorMove throws TypeError when x is not a number
assert.throws(() => {
cursorMove();
}, {
name: 'TypeError',
message: 'The `x` argument is required',
});
assert.throws(() => {
cursorMove('5');
}, {
name: 'TypeError',
message: 'The `x` argument is required',
});
// 5. eraseScreen provides the ANSI escape code to erase the entire screen
assert.strictEqual(typeof eraseScreen, 'string', 'eraseScreen must be a string');
assert.strictEqual(eraseScreen, '\u001B[2J');
assert.strictEqual(getEraseScreenCode(), '\u001B[2J');
assert.strictEqual(clearAndRender(0, 0, 'ready'), '\u001B[2J\u001B[1;1Hready');
console.log('All contract assertions passed successfully.');
原始种子者
匿名