trustycsv 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +21 -0
- package/README.md +138 -2
- package/THIRD-PARTY-LICENSES.txt +421 -0
- package/bin/chunks/cli-BUck2dri.js +538 -0
- package/bin/chunks/excel-pdfNVgvx.js +142 -0
- package/bin/chunks/mcp-BtQ-Hy3_.js +5 -0
- package/bin/chunks/zip--IbYBxOO.js +1 -0
- package/bin/trustycsv.js +2 -0
- package/package.json +35 -4
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{S as e,_ as t,a as n,b as r,c as i,d as a,f as o,g as s,h as c,i as l,l as u,m as d,o as f,p,r as m,s as h,t as g,u as _,v,x as y,y as b}from"./cli-BUck2dri.js";import x from"node:fs";import S from"node:fs/promises";import C from"node:path";import w from"node:os";import T from"node:readline";var E=[`2025-11-25`,`2025-06-18`,`2025-03-26`,`2024-11-05`],D=`Trusty CSV's engine for CSV files (and TSV, Excel, OpenDocument and JSON files), run on this computer: nothing is uploaded.
|
|
2
|
+
Look at a file with inspect_file before changing it. check_quality runs Trusty CSV's Quality Check: what is surely wrong in a file, in the order to fix it. fix_problems fixes kinds of those problems. apply_recipe does steps of the Trusty CSV app's recipes (sorting, cleaning cells, splitting and joining columns, reshaping…): read recipe_reference for how to write them, and use dry_run first to see what each step would do. convert_file writes a file in another format. compare_files says what changed between two versions of a file, cell by cell.
|
|
3
|
+
The tools that write never write over a file unless "overwrite" is true. They keep a file's encoding, delimiter and line breaks, and change nothing but what a step changes. Give paths in full.`,O={sheet:{type:`string`,description:`The sheet of a workbook (.xlsx, .xls, .ods). The first, if not given.`},zip_entry:{type:`string`,description:`The file inside a .zip that holds several.`},input_encoding:{type:`string`,enum:[`utf-8`,`windows-1252`,`utf-16le`,`utf-16be`],description:`How the file is encoded. Detected if not given.`},input_delimiter:{type:`string`,description:`The file's delimiter: "," ";" "tab" "|"… Detected if not given.`},header:{type:`boolean`,description:`Whether the first row names the columns. Detected if not given.`}},k={output:{type:`string`,description:`The file to write the result to.`},overwrite:{type:`boolean`,default:!1,description:`Write over the output file if it exists (it may be the file itself, if it is a CSV, TSV or text file kept in its format).`},format:{type:`string`,enum:Object.keys(s),description:`The format to write. Default: the output's extension, or the file's own format.`},delimiter:{type:`string`,description:`The delimiter of a CSV written. Default: the file's own.`},encoding:{type:`string`,enum:[`utf-8`,`windows-1252`,`utf-16le`,`utf-16be`],description:`The encoding of a CSV written. Default: the file's own.`},bom:{type:`boolean`,description:`A byte order mark at the start of a CSV written (Excel needs it to read UTF-8). Default: as the file had.`},line_breaks:{type:`string`,enum:[`crlf`,`lf`],description:`The line breaks of a CSV written. Default: the file's own.`},quote_all:{type:`boolean`,default:!1,description:`Quotes around every value of a CSV written.`}},A={type:`string`,description:`The file: a full path.`},j={type:`boolean`,default:!1,description:`Write nothing: say what each step would do, and show the first rows of the result.`},M={type:`integer`,minimum:0,maximum:50,default:5,description:`How many of the result's first rows to show.`},N=(e,t)=>({type:`object`,properties:e,required:t,additionalProperties:!1}),P={readOnlyHint:!0,openWorldHint:!1},F={readOnlyHint:!1,destructiveHint:!0,idempotentHint:!0,openWorldHint:!1},I=[{name:`inspect_file`,title:`Inspect a CSV file`,description:`How a CSV, TSV, Excel, OpenDocument or JSON file is written (encoding, delimiter, header row, line breaks, lines above the table) and what it holds: its rows, each column's name and type (numbers with their decimal separator, dates with their day/month order, times, email addresses, text), how many values of each column are empty, missing (NA, null…) and different, and its first rows. Read-only.`,inputSchema:N({path:A,sample_rows:{type:`integer`,minimum:0,maximum:50,default:5,description:`How many of the first rows to show.`},...O},[`path`]),annotations:P,run:async e=>{let{state:t,from:n}=await R(e.path,e);return i(t,n,{sampleRows:e.sample_rows??5,cut:200})}},{name:`check_quality`,title:`Check a CSV file's quality`,description:`Trusty CSV's Quality Check: only what is surely wrong in a file (rows with too few or too many values, rows cut by a line break, empty and repeated rows and columns, unnamed or repeated column names, broken encodings, invisible characters, spaces at the edges, numbers, dates, yes/no values and countries written in several ways in one column, codes that lost their leading zeros, impossible dates, incomplete emails, spreadsheet errors and rounded numbers, repeated keys…), in the order to fix it, with the first places of each kind: the line in the file, the column and the value. Each kind says whether fix_problems can fix it. Read-only.`,inputSchema:N({path:A,max_places:{type:`integer`,minimum:0,maximum:200,default:5,description:`How many places of each kind to list.`},kinds:{type:`array`,items:{type:`string`,enum:c},description:`Only these kinds of problem.`},...O},[`path`]),annotations:P,run:async e=>{let{state:t,from:r}=await R(e.path,e);return n(t,r,{max:e.max_places??5,kinds:e.kinds??null})}},{name:`fix_problems`,title:`Fix problems of a CSV file`,description:`Fixes every problem of some kinds that check_quality finds, as the buttons of Trusty CSV's Quality Check do, in the order to fix them, then checks the result again and says what is left. Kinds with a fix: ${_.join(`, `)}; "all": every one of those that the file has. With dry_run, writes nothing.`,inputSchema:N({path:A,kinds:{type:`array`,items:{type:`string`,enum:[`all`,..._]},minItems:1,description:`The kinds to fix, or ["all"].`},...k,dry_run:j,preview_rows:M,...O},[`path`,`kinds`]),annotations:F,run:async e=>{let t=e.kinds.includes(`all`);return B(e,(r,i)=>{let a=n(r,i,{max:0}).problems.map(e=>e.kind).filter(n=>_.includes(n)&&(t||e.kinds.includes(n)));return a.length?o(a):[]},{recheck:!0})}},{name:`apply_recipe`,title:`Apply a recipe to a CSV file`,description:`Does a recipe's steps on a file, as Trusty CSV's Apply Recipe does: cell operations (trim, change case, remove accents, fill empty cells, replace or merge values…), reformatting numbers and dates, sorting, removing duplicate or empty rows, filtering rows, inserting, deleting, moving, renaming, splitting, joining and merging columns, columns to rows and back, summarizing by group, find and replace (regular expressions too), and the Quality Check's fixes. Each step names its columns by their header names; a step whose columns aren't in the file is skipped, and says so. The steps are given in "steps" (read recipe_reference for their format first) or in a recipe file exported by the app ("recipe_path"). Use dry_run to see what each step would do before writing.`,inputSchema:N({path:A,steps:{type:`array`,items:{type:`object`},description:`The steps, in order (see recipe_reference).`},recipe_path:{type:`string`,description:`A recipe file exported by Trusty CSV (name.recipe.json), instead of "steps".`},...k,dry_run:j,preview_rows:M,...O},[`path`]),annotations:F,run:async t=>{if(t.steps==null==(t.recipe_path==null))throw new e(`Give it "steps" or "recipe_path".`);let n=t.steps;if(t.recipe_path!=null)try{n=JSON.parse(await S.readFile(L(t.recipe_path),`utf8`))}catch(n){throw new e(n.code?`Could not read ${t.recipe_path}: ${m(n)}`:`${t.recipe_path} isn’t JSON: ${n.message}`)}let{steps:r}=p(n);return B(t,()=>r)}},{name:`convert_file`,title:`Convert a CSV file to another format`,description:`Writes a file in another format: ${Object.keys(s).join(`, `)}; or as CSV with another delimiter, encoding or line breaks. CSV keeps the text exactly as it is unless the delimiter changes or quote_all is given. JSON writes numbers as numbers in columns of numbers; SQL is a CREATE TABLE and INSERT statements (SQLite, PostgreSQL). Reads workbooks and JSON too.`,inputSchema:N({path:A,...k,...O},[`path`,`output`]),annotations:F,run:e=>B(e,()=>[])},{name:`compare_files`,title:`Compare two versions of a CSV file`,description:`What changed between two versions of a table, as Trusty CSV's Compare With: columns added, removed or renamed (matched by name), rows changed, added and removed, and each cell that changed, before and after. Rows are matched by their content, or by a key column ("key": an id) wherever they are; when the rows seem to be in another order, it suggests a key. Read-only.`,inputSchema:N({before:{type:`string`,description:`The version before: a full path.`},after:{type:`string`,description:`The version after: a full path.`},key:{type:`string`,description:`A column that identifies each row (by its name in "after").`},max_rows:{type:`integer`,minimum:0,maximum:500,default:20,description:`How many changed, added and removed rows to list, of each.`},...O},[`before`,`after`]),annotations:P,run:async e=>{let t=await R(e.before,e),n=await R(e.after,e);return f(t.state,n.state,{key:e.key??null,max:e.max_rows??20,beforeName:e.before,afterName:e.after})}},{name:`recipe_reference`,title:`How to write a Trusty CSV recipe`,description:`The format of a recipe's steps for apply_recipe: every kind of step, its fields and an example. Read it before writing steps.`,inputSchema:N({},[]),annotations:P,run:()=>a}],L=e=>C.resolve(String(e).replace(/^~(?=$|[\\/])/,w.homedir()));async function R(t,n){let r=L(t),i;try{i=new Uint8Array(await S.readFile(r))}catch(t){throw new e(`Could not read ${r}: ${m(t)}`)}return b(i,C.basename(r),{sheet:n.sheet,entry:n.zip_entry,encoding:n.input_encoding,delimiter:n.input_delimiter,header:n.header})}var z=e=>e.length>200?e.slice(0,199)+`…`:e;async function B(i,a,{recheck:o=!1}={}){if(!i.dry_run&&!i.output)throw new e(`Give it an "output" file, or "dry_run": true.`);let{state:s,from:c}=await R(i.path,i),u=i.output?L(i.output):null,d=r({type:i.format,delimiter:i.delimiter,encoding:i.encoding,bom:i.bom,eol:i.line_breaks,quoteAll:i.quote_all},s,c,u),f=u&&u.toLowerCase()===L(i.path).toLowerCase();if(u&&!i.dry_run){if(f){if(!i.overwrite)throw new e(`The output is the file itself: "overwrite": true writes over it.`);t(u,c,s,d)}else if(!i.overwrite&&x.existsSync(u))throw new e(`${u} exists already: "overwrite": true writes over it.`)}let p=a(s,c),g=p.length?h(s,p):{after:s,changed:!1,results:[]},_={file:L(i.path),output:null,format:d.type,changed:g.changed,steps:g.results,notes:[...c.notes]};if(o&&(_.left=n(g.after,c,{max:0}).problems.map(e=>({kind:e.kind,count:e.count,fixable:!!e.fix}))),u&&!i.dry_run&&(!f||g.changed)){let{bytes:t,notes:n}=await y(g.after,c,d);_.notes.push(...n);try{await l(u,[t])}catch(t){throw new e(`Could not write ${u}: ${m(t)}`)}_.output=u}else f&&!g.changed&&_.notes.push(`Nothing changed: the file wasn’t written.`);let b=i.preview_rows??5;return b&&(g.changed||i.dry_run)&&(_.firstRows=v(g.after,b+1).map(e=>e.map(z))),i.dry_run&&(_.dryRun=`Nothing was written.`),_}function V(t,n){let{properties:r,required:i}=t.inputSchema,a=[];for(let e of i)n[e]??a.push(`"${e}" is required.`);for(let[e,i]of Object.entries(n)){let n=r[e];if(!n){a.push(`there is no argument "${e}". The arguments: ${Object.keys(r).join(`, `)}.`);continue}if(i==null)continue;let o=Array.isArray(i)?`array`:Number.isInteger(i)?`integer`:typeof i;if(n.type!==o&&(n.type!==`number`||o!==`integer`))a.push(`"${e}" must be ${n.type===`integer`?`a whole number`:`a ${n.type}`}.`);else if(n.enum&&!n.enum.includes(i))a.push(`"${e}" must be one of: ${n.enum.join(`, `)}.`);else if(n.type===`integer`&&(n.minimum!=null&&i<n.minimum||n.maximum!=null&&i>n.maximum))a.push(`"${e}" must be from ${n.minimum} to ${n.maximum}.`);else if(n.type===`array`&&n.items?.enum){let r=i.filter(e=>!n.items.enum.includes(e));r.length&&a.push(`"${e}": ${r.map(e=>JSON.stringify(e)).join(`, `)} ${r.length===1?`isn’t one`:`aren’t`} of: ${n.items.enum.join(`, `)}.${e===`kinds`&&t.name===`fix_problems`?` (${r.filter(e=>c.includes(e)).map(e=>`${e}: ${d(e)}`).join(`; `)})`:``}`.replace(` ()`,``))}}if(a.length)throw new e(a.join(`
|
|
4
|
+
`))}async function H(t,n){let r=I.find(e=>e.name===t);try{V(r,n??{});let e=await r.run(n??{});return{content:[{type:`text`,text:typeof e==`string`?e:u(e)}]}}catch(t){return t instanceof e||console.error(t),{content:[{type:`text`,text:t instanceof e?t.message:`It failed: ${t.message}`}],isError:!0}}}var U=(e,t,n)=>({jsonrpc:`2.0`,id:e,error:{code:t,message:n}}),W=(e,t)=>({jsonrpc:`2.0`,id:e,result:t});async function G(e){if(!e||typeof e!=`object`||e.jsonrpc!==`2.0`)return U(null,-32600,`Invalid Request`);let{id:t,method:n,params:r}=e;if(typeof n!=`string`||t==null)return null;switch(n){case`initialize`:{let e=r?.protocolVersion;return W(t,{protocolVersion:E.includes(e)?e:E[0],capabilities:{tools:{listChanged:!1}},serverInfo:{name:`trustycsv`,title:`Trusty CSV`,version:g},instructions:D})}case`ping`:return W(t,{});case`tools/list`:return W(t,{tools:I.map(({run:e,...t})=>t)});case`tools/call`:return I.some(e=>e.name===r?.name)?r.arguments!=null&&(typeof r.arguments!=`object`||Array.isArray(r.arguments))?U(t,-32602,`The arguments must be an object.`):W(t,await H(r.name,r.arguments)):U(t,-32602,`Unknown tool: ${r?.name}`);default:return U(t,-32601,`Method not found: ${n}`)}}async function K(e){let t;try{t=JSON.parse(e)}catch{return U(null,-32700,`Parse error`)}if(Array.isArray(t)){if(!t.length)return U(null,-32600,`Invalid Request`);let e=[];for(let n of t){let t=await G(n);t&&e.push(t)}return e.length?e:null}return G(t)}async function q({input:e=process.stdin,output:t=process.stdout}={}){console.log=console.info=console.debug=console.warn=console.error;let n=T.createInterface({input:e,crlfDelay:1/0});for await(let e of n){if(!e.trim())continue;let n=await K(e);n&&t.write(JSON.stringify(n)+`
|
|
5
|
+
`)}}export{q as serve};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=101010256,t=33639248,n=67324752;function r(r){let i=new DataView(r.buffer,r.byteOffset,r.byteLength),a=-1;for(let t=r.length-22;t>=Math.max(0,r.length-22-65535);t--)if(i.getUint32(t,!0)===e){a=t;break}if(a<0)throw Error(`This file is not a zip archive.`);let o=i.getUint16(a+10,!0),s=i.getUint32(a+16,!0);if(o===65535||s===4294967295)throw Error(`This archive is too big to read.`);let c=new TextDecoder,l=new Map;for(let e=0;e<o;e++){if(s+46>r.length||i.getUint32(s,!0)!==t)throw Error(`This zip archive is damaged.`);let e=i.getUint16(s+28,!0),n=c.decode(r.subarray(s+46,s+46+e));l.set(n,{method:i.getUint16(s+10,!0),locked:(i.getUint16(s+8,!0)&1)==1,size:i.getUint32(s+20,!0),full:i.getUint32(s+24,!0),local:i.getUint32(s+42,!0)}),s+=46+e+i.getUint16(s+30,!0)+i.getUint16(s+32,!0)}let u=new Map;for(let e of l.keys()){u.set(e.toLowerCase(),e);try{u.set(decodeURIComponent(e).toLowerCase(),e)}catch{}}let d=e=>l.has(e)?e:u.get(e.toLowerCase())||null;return{names:[...l.keys()],find:d,size:e=>l.get(d(e))?.full??0,async read(e){let t=l.get(d(e));if(!t)throw Error(`${e} is not in the archive.`);if(t.locked)throw Error(`This archive has a password, which can’t be given here. Extract its files first.`);if(i.getUint32(t.local,!0)!==n)throw Error(`This zip archive is damaged.`);let a=t.local+30+i.getUint16(t.local+26,!0)+i.getUint16(t.local+28,!0),o=r.subarray(a,a+t.size);if(t.method===0)return o;if(t.method!==8)throw Error(`This zip archive uses a compression that can’t be read.`);let s=new Blob([o]).stream().pipeThrough(new DecompressionStream(`deflate-raw`));return new Uint8Array(await new Response(s).arrayBuffer())}}}var i=null;function a(e){if(!i){i=new Uint32Array(256);for(let e=0;e<256;e++){let t=e;for(let e=0;e<8;e++)t=t&1?3988292384^t>>>1:t>>>1;i[e]=t>>>0}}let t=4294967295;for(let n=0;n<e.length;n++)t=i[(t^e[n])&255]^t>>>8;return(t^4294967295)>>>0}function o(r,i){let o=new DataView(r.buffer,r.byteOffset,r.byteLength),s=-1;for(let t=r.length-22;t>=Math.max(0,r.length-22-65535);t--)if(o.getUint32(t,!0)===e){s=t;break}if(s<0)return r;let c=o.getUint16(s+10,!0),l=o.getUint32(s+16,!0);if(c===65535||l===4294967295)return r;let u=new TextEncoder,d=new TextDecoder,f=[];for(let e=0;e<c;e++){if(o.getUint32(l,!0)!==t)return r;let e=o.getUint16(l+28,!0),i=o.getUint16(l+30,!0),a=o.getUint16(l+32,!0),s=o.getUint32(l+42,!0);if(o.getUint16(l+8,!0)&8||o.getUint32(s,!0)!==n)return r;let c=s+30+o.getUint16(s+26,!0)+o.getUint16(s+28,!0)+o.getUint32(l+20,!0);f.push({name:d.decode(r.subarray(l+46,l+46+e)),central:r.subarray(l,l+46+e+i+a),local:r.subarray(s,c)}),l+=46+e+i+a}let p=u.encode(`mimetype`),m=u.encode(i),h=a(m),g=new Uint8Array(30+p.length+m.length),_=new DataView(g.buffer);_.setUint32(0,n,!0),_.setUint16(4,10,!0),_.setUint32(14,h,!0),_.setUint32(18,m.length,!0),_.setUint32(22,m.length,!0),_.setUint16(26,p.length,!0),g.set(p,30),g.set(m,30+p.length);let v=new Uint8Array(46+p.length),y=new DataView(v.buffer);y.setUint32(0,t,!0),y.setUint16(4,20,!0),y.setUint16(6,10,!0),y.setUint32(16,h,!0),y.setUint32(20,m.length,!0),y.setUint32(24,m.length,!0),y.setUint16(28,p.length,!0),v.set(p,46);let b=f.filter(e=>e.name!==`mimetype`),x=[g],S=[v],C=g.length;for(let e of b){let t=e.central.slice();new DataView(t.buffer).setUint32(42,C,!0),x.push(e.local),S.push(t),C+=e.local.length}let w=S.reduce((e,t)=>e+t.length,0),T=new Uint8Array(22),E=new DataView(T.buffer);E.setUint32(0,e,!0),E.setUint16(8,S.length,!0),E.setUint16(10,S.length,!0),E.setUint32(12,w,!0),E.setUint32(16,C,!0);let D=new Uint8Array(C+w+22),O=0;for(let e of[...x,...S,T])D.set(e,O),O+=e.length;return D}export{r as n,o as t};
|
package/bin/trustycsv.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trustycsv",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Check, clean, convert and compare CSV files from the command line, and an MCP server that lets AI assistants do it: the engine of the Trusty CSV editor, run on your computer.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"csv",
|
|
7
|
+
"tsv",
|
|
8
|
+
"csv-lint",
|
|
9
|
+
"csv-validator",
|
|
10
|
+
"data-cleaning",
|
|
11
|
+
"data-quality",
|
|
12
|
+
"data-preparation",
|
|
13
|
+
"excel",
|
|
14
|
+
"json",
|
|
15
|
+
"diff",
|
|
16
|
+
"cli",
|
|
17
|
+
"mcp",
|
|
18
|
+
"mcp-server",
|
|
19
|
+
"model-context-protocol"
|
|
20
|
+
],
|
|
21
|
+
"homepage": "https://trustycsv.com",
|
|
22
|
+
"author": "Calmly Studio (https://calmly.studio)",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"type": "module",
|
|
25
|
+
"bin": {
|
|
26
|
+
"trustycsv": "bin/trustycsv.js"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"bin/",
|
|
30
|
+
"README.md",
|
|
31
|
+
"LICENSE.txt",
|
|
32
|
+
"THIRD-PARTY-LICENSES.txt"
|
|
33
|
+
],
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=22"
|
|
36
|
+
}
|
|
37
|
+
}
|