UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

3 lines (2 loc) • 4.72 kB
import { createRequire as __piCreateRequire } from "node:module"; const require = __piCreateRequire(import.meta.url); { const __piWorkerThreads = require("node:worker_threads"); if (typeof __piWorkerThreads.markAsUncloneable !== "function") { __piWorkerThreads.markAsUncloneable = () => {}; } } import{realmRegistry}from"./chunk-XDEZA6U6.js";var SLOT_KEY_NAME="@code-yeongyu/senpi/config-reference-redaction/v1",MIN_REDACTED_LENGTH=4,MAX_REMEMBERED_LENGTH=65536,ConfigReferenceRedactionSlotError=class extends Error{constructor(cause){super(`The process-wide redaction registry ${SLOT_KEY_NAME} was not installed by senpi or is incompatible; restart the process.`,cause===void 0?void 0:{cause}),this.name="ConfigReferenceRedactionSlotError",this.code="SENPI_REDACTION_SLOT_INCOMPATIBLE"}};function createRegistry(){let values=new Set;return Object.freeze({version:1,add(value){typeof value!="string"||value.length<MIN_REDACTED_LENGTH||value.length>MAX_REMEMBERED_LENGTH||values.add(value)},get size(){return values.size},values:()=>[...values]})}function isFrozenV1Registry(value){return typeof value=="object"&&value!==null&&Object.isFrozen(value)&&Reflect.get(value,"version")===1&&typeof Reflect.get(value,"add")=="function"&&typeof Reflect.get(value,"values")=="function"&&typeof Reflect.get(value,"size")=="number"}var registry=realmRegistry(SLOT_KEY_NAME,createRegistry,isFrozenV1Registry,cause=>new ConfigReferenceRedactionSlotError(cause)),redactionForms=[],formsSize=0;function rememberResolvedReferenceValue(value){registry.add(value)}function encodings(value){let form=new URLSearchParams([["",value]]).toString().slice(1);return[value,JSON.stringify(value).slice(1,-1),encodeURIComponent(value),encodeURI(value),form]}function forms(){let size=registry.size;return size!==formsSize&&(redactionForms=[...new Set(registry.values().flatMap(encodings))].filter(form=>form.length>=MIN_REDACTED_LENGTH).sort((left,right)=>right.length-left.length),formsSize=size),redactionForms}function redactResolvedReferenceValues(text,replacement="<redacted>"){let redacted=text;for(let form of forms())redacted.includes(form)&&(redacted=redacted.split(form).join(replacement));return redacted}var PROTOCOL_TYPES=new Set(["text","image","audio","resource","resource_link","object","array","string","number","integer","boolean","null"]),SCHEMA_FORMATS=new Set(["date-time","date","time","duration","email","idn-email","hostname","idn-hostname","ipv4","ipv6","uri","uri-reference","iri","iri-reference","uri-template","uuid","json-pointer","relative-json-pointer","regex","byte","binary","password"]),MEDIA_TYPES=new Set(["text/plain","text/markdown","text/html","text/css","text/csv","text/javascript","text/xml","text/x-python","text/x-typescript","application/json","application/xml","application/yaml","application/javascript","application/typescript","application/pdf","application/zip","application/gzip","application/octet-stream","application/x-ndjson","image/png","image/jpeg","image/gif","image/webp","image/svg+xml","image/bmp","image/avif","image/heic","image/tiff","audio/wav","audio/mpeg","audio/mp3","audio/ogg","audio/webm","audio/flac","audio/aac","video/mp4","video/webm"]),SCHEMA_URLS=new Set(["http://json-schema.org/draft-04/schema#","http://json-schema.org/draft-06/schema#","http://json-schema.org/draft-07/schema#","http://json-schema.org/schema#","https://json-schema.org/draft/2019-09/schema","https://json-schema.org/draft/2020-12/schema"]),PROTOCOL_VALUES={type:PROTOCOL_TYPES,mimeType:MEDIA_TYPES,format:SCHEMA_FORMATS,jsonrpc:new Set(["2.0"]),role:new Set(["user","assistant"]),$schema:SCHEMA_URLS};function isProtocolValue(key,value){return Object.hasOwn(PROTOCOL_VALUES,key)&&PROTOCOL_VALUES[key]?.has(value)===!0}function redactResolvedReferenceData(value){if(registry.size===0)return value;let copies=new WeakMap,pending=[],copy=input=>{let source=typeof input=="object"&&input!==null&&typeof Reflect.get(input,"toJSON")=="function"?Reflect.get(input,"toJSON").call(input):input;if(typeof source=="string")return redactResolvedReferenceValues(source);if(typeof source!="object"||source===null)return source;let existing=copies.get(source);if(existing!==void 0)return existing;let target=Array.isArray(source)?new Array(source.length):{};return copies.set(source,target),pending.push({source,target}),target},result=copy(value);for(let{source,target}of pending)for(let key of Object.keys(source)){let child=Reflect.get(source,key);Object.defineProperty(target,key,{value:typeof child=="string"&&isProtocolValue(key,child)?child:copy(child),enumerable:!0,writable:!0,configurable:!0})}return result}export{rememberResolvedReferenceValue,redactResolvedReferenceValues,redactResolvedReferenceData};