yaml-flow 8.4.0 → 8.4.1

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.
@@ -1,8 +1,8 @@
1
- import'child_process';import*as d from'fs';import {existsSync}from'fs';import*as _ from'os';import*as y from'path';import {dirname,resolve}from'path';import'net';import {fileURLToPath}from'url';import {randomUUID}from'crypto';import {createRequire}from'module';import'proper-lockfile';import'ajv-formats';function R(...e){return y.join(...e)}function w(...e){return y.resolve(...e)}y.join(_.tmpdir(),".board-live-cards-git-bash-cache.json");var j=dirname(fileURLToPath(import.meta.url)),X=createRequire(import.meta.url);function Z(){let e=resolve(j,"./jsonata-sync.cjs");return existsSync(e)?e:resolve(j,"../../card-compute/jsonata-sync.cjs")}X(Z());createRequire(import.meta.url);function rt(e,n){if(process.platform!=="win32"){d.renameSync(e,n);return}let o=[10,20,40,80,160];for(let a=0;a<=o.length;a++)try{d.renameSync(e,n);return}catch(s){let u=s.code;if((u==="EPERM"||u==="EBUSY")&&a<o.length){Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,o[a]);continue}throw s}}function $(e){function n(a){return y.join(e,...a.split("/"))+".json"}function o(a,s,u,i){if(d.existsSync(a))for(let t of d.readdirSync(a,{withFileTypes:true})){let r=s?`${s}/${t.name}`:t.name;if(t.isDirectory()){o(y.join(a,t.name),r,u,i);continue}if(!t.isFile()||!t.name.endsWith(".json"))continue;let c=r.replace(/\.json$/,"");(!u||c.startsWith(u))&&i.push(c);}}return {read(a){let s=n(a);if(!d.existsSync(s))return null;try{return JSON.parse(d.readFileSync(s,"utf-8"))}catch{return null}},write(a,s){let u=n(a),i=`${u}.${process.pid}.${randomUUID()}.tmp`;d.mkdirSync(y.dirname(u),{recursive:true}),d.writeFileSync(i,JSON.stringify(s,null,2),"utf-8"),rt(i,u);},delete(a){let s=n(a);try{d.existsSync(s)&&d.unlinkSync(s);}catch{}},listKeys(a){let s=[];return o(e,"",a,s),s.sort()}}}function N(e){function n(){if(!d.existsSync(e))return [];let o=d.readFileSync(e,"utf-8").trim();return o?o.split(`
2
- `).filter(Boolean).map(a=>JSON.parse(a)):[]}return {append(o){let a={id:randomUUID(),payload:o};return d.mkdirSync(y.dirname(e),{recursive:true}),d.appendFileSync(e,JSON.stringify(a)+`
3
- `,"utf-8"),a},readAll(){return n()},readAfter(o){let a=n();if(!o)return {entries:a,newCursor:a.length>0?a[a.length-1].id:null};let s=a.findIndex(i=>i.id===o),u=s===-1?a:a.slice(s+1);return {entries:u,newCursor:u.length>0?u[u.length-1].id:o}},clear(){d.existsSync(e)&&d.truncateSync(e,0);}}}var ot=createRequire(import.meta.url);ot("./jsonata-sync.cjs");function B(e){return String(e).replace(/[^a-zA-Z0-9_-]/g,"_")}function D(e){let n=e.payload??{};return {id:e.id,role:typeof n.role=="string"?n.role:"system",text:typeof n.text=="string"?n.text:"",files:Array.isArray(n.files)?n.files:[],updated_at:typeof n.updated_at=="string"?n.updated_at:""}}function E(e,n){let o=s=>`chats/${B(s)}/processing`,a=s=>`chats/${B(s)}/config`;return {append(s,u,i,t=[]){return e(s).append({role:u,text:i,files:t,updated_at:new Date().toISOString()}).id},readAll(s){return e(s).readAll().map(D)},readAfter(s,u){let i=e(s).readAfter(u);return {records:i.entries.map(D),cursor:i.newCursor}},clear(s){e(s).clear?.();},setProcessing(s,u){u?n.write(o(s),true):n.delete(o(s));},isProcessing(s){return n.read(o(s))===true},getConfig(s){return n.read(a(s))??{}},setConfig(s,u){let i=n.read(a(s))??{};n.write(a(s),{...i,...u});}}}var lt=createRequire(import.meta.url);lt("./jsonata-sync.cjs");function A(e,n={}){let o=n.chatsSubdir??"chats",a=n.kvSubdir??".kv",u=$(R(e,...a?[a,"chat"]:["chat"]));return E(i=>{let r=`${String(i).replace(/[^a-zA-Z0-9_-]/g,"_")}.jsonl`,c=o?R(e,o,r):R(e,r);return N(c)},u)}function T(e){function n(t){return {status:"success",data:t}}function o(t){return {status:"fail",error:t}}function a(t){return {status:"error",error:t instanceof Error?t.message:String(t)}}function s(t,r="command envelope"){let c=typeof t.cardId=="string"?t.cardId:void 0;if(!t.command)return o(`chat-store: ${r} missing "command"`);if(!c)return o(`chat-store: ${r} missing "cardId"`);if(t.command==="append")return i.append({params:{cardId:c},body:{role:t.role,text:t.text,files:t.files}});if(t.command==="read-all")return i.readAll({params:{cardId:c}});if(t.command==="read-after")return i.readAfter({params:{cardId:c},body:{cursor:t.cursor??null}});if(t.command==="clear")return i.clear({params:{cardId:c}});if(t.command==="set-processing")return i.setProcessing({params:{cardId:c},body:{active:t.active}});if(t.command==="is-processing")return i.isProcessing({params:{cardId:c}});if(t.command==="get-config")return i.getConfig({params:{cardId:c}});if(t.command==="set-config"){let{command:l,cardId:p,...g}=t;return i.setConfig({params:{cardId:c},body:g})}return o(`chat-store: unknown command "${String(t.command)}"`)}function u(t){if(!Array.isArray(t.commands)||t.commands.length===0)return o('chat-store: command envelope must include a non-empty "commands" array');let r=[];for(let c=0;c<t.commands.length;c+=1){let l=t.commands[c];if(!l||typeof l!="object"||Array.isArray(l))return o(`chat-store: command envelope entry ${c} must be an object`);let p={cardId:t.cardId,...l},g=s(p,`command envelope entry ${c}`);if(g.status!=="success")return g;r.push({index:c,command:String(p.command),data:g.data});}return n({results:r})}let i={append(t){try{let r=t.params?.cardId;if(!r)return o("append requires params.cardId");let c=t.body??{},l=typeof c.role=="string"?c.role:"",p=typeof c.text=="string"?c.text:"",g=Array.isArray(c.files)?c.files:[];if(!l)return o("append requires body.role");let b=e.append(r,l,p,g);return n({id:b})}catch(r){return a(r)}},readAll(t){try{let r=t.params?.cardId;return r?n({records:e.readAll(r)}):o("readAll requires params.cardId")}catch(r){return a(r)}},readAfter(t){try{let r=t.params?.cardId;if(!r)return o("readAfter requires params.cardId");let l=(t.body??{}).cursor??null;return n(e.readAfter(r,l))}catch(r){return a(r)}},clear(t){try{let r=t.params?.cardId;return r?(e.clear(r),n({ok:!0})):o("clear requires params.cardId")}catch(r){return a(r)}},setProcessing(t){try{let r=t.params?.cardId;if(!r)return o("setProcessing requires params.cardId");let c=t.body??{};return typeof c.active!="boolean"?o("setProcessing requires body.active (boolean)"):(e.setProcessing(r,c.active),n({ok:!0}))}catch(r){return a(r)}},isProcessing(t){try{let r=t.params?.cardId;return r?n({active:e.isProcessing(r)}):o("isProcessing requires params.cardId")}catch(r){return a(r)}},getConfig(t){try{let r=t.params?.cardId;return r?n({config:e.getConfig(r)}):o("getConfig requires params.cardId")}catch(r){return a(r)}},setConfig(t){try{let r=t.params?.cardId;if(!r)return o("setConfig requires params.cardId");let c=t.body??{};return e.setConfig(r,c),n({ok:!0})}catch(r){return a(r)}},run:s,runBatch:u};return i}function f(e,n,o){let a=e.indexOf(n),s=a!==-1?e[a+1]:void 0;if(!s)throw new Error(`Missing ${n}
4
- Usage: ${o}`);return s}function C(e,n){let o=e.indexOf(n);return o!==-1?e[o+1]:void 0}async function V(){let e=[];for await(let n of process.stdin)e.push(Buffer.isBuffer(n)?n:Buffer.from(n));return Buffer.concat(e).toString("utf-8")}var I=["chat-store \u2014 chat history and state operations for a board card",""," chat-store append --board-dir <dir> --card-id <id> --role <role> --text <text> [--files-json <json>]"," Append a message. Prints { id } on success.",""," chat-store read-all --board-dir <dir> --card-id <id>"," Print all messages as a JSON array.",""," chat-store read-after --board-dir <dir> --card-id <id> [--cursor <cursor>]"," Print messages after cursor as { records, cursor }.",""," chat-store clear --board-dir <dir> --card-id <id>"," Remove all messages for the card.",""," chat-store set-processing --board-dir <dir> --card-id <id> --active <true|false>"," Set or clear the processing flag.",""," chat-store is-processing --board-dir <dir> --card-id <id>"," Print { active: true|false }.",""," chat-store get-config --board-dir <dir> --card-id <id>"," Print the chat config object.",""," chat-store set-config --board-dir <dir> --card-id <id> [--system-prompt <text>]"," Patch the chat config. Extra fields can be piped as JSON to stdin.",""," Alternatively, pipe a JSON object to stdin:",' { "command": "<cmd>", "boardDir": "<dir>", "cardId": "<id>", ... }'," Or pipe a command envelope with defaults plus sequential commands:",' { "boardDir": "<dir>", "cardId": "<id>", "commands": [{ "command": "append", ... }, { "command": "set-processing", ... }] }'].join(`
5
- `);async function kt(e){if(e.length===0||e[0]==="--stdin"){let i=await V();if(!i.trim()){console.error(I);return}let t;try{t=JSON.parse(i);}catch{console.error("chat-store: stdin is not valid JSON"),process.exit(1);}let r=t.boardDir;r||(console.error('chat-store: stdin envelope missing "boardDir"'),process.exit(1));let c=t.chatsSubdir,l=t.kvSubdir,p={};c!==void 0&&(p.chatsSubdir=c),l!==void 0&&(p.kvSubdir=l);let g=T(A(r,p));if(Array.isArray(t.commands)){let K=g.runBatch(Ct(t));m(K);return}let b=g.run(Rt(t));m(b);return}let n=e[0],o=e.slice(1);if(!n||n==="help"||n==="--help"||n==="-h"){console.error(I);return}let a=f(o,"--board-dir",`chat-store ${n} --board-dir <dir> --card-id <id>`),s=C(o,"--card-id"),u=T(A(a));if(n==="append"){let i=f(o,"--role","chat-store append --board-dir <dir> --card-id <id> --role <role> --text <text>"),t=f(o,"--text","chat-store append --board-dir <dir> --card-id <id> --role <role> --text <text>"),r=C(o,"--files-json"),c=r?JSON.parse(r):[],l=s??f(o,"--card-id","chat-store append --board-dir <dir> --card-id <id> --role <role> --text <text>"),p=u.append({params:{cardId:l},body:{role:i,text:t,files:c}});m(p);return}if(n==="read-all"){let i=s??f(o,"--card-id","chat-store read-all --board-dir <dir> --card-id <id>"),t=u.readAll({params:{cardId:i}});m(t);return}if(n==="read-after"){let i=s??f(o,"--card-id","chat-store read-after --board-dir <dir> --card-id <id>"),t=C(o,"--cursor")??null,r=u.readAfter({params:{cardId:i},body:{cursor:t}});m(r);return}if(n==="clear"){let i=s??f(o,"--card-id","chat-store clear --board-dir <dir> --card-id <id>"),t=u.clear({params:{cardId:i}});m(t);return}if(n==="set-processing"){let i=s??f(o,"--card-id","chat-store set-processing --board-dir <dir> --card-id <id> --active <true|false>"),t=f(o,"--active","chat-store set-processing --board-dir <dir> --card-id <id> --active <true|false>");t!=="true"&&t!=="false"&&(console.error('chat-store set-processing: --active must be "true" or "false"'),process.exit(1));let r=u.setProcessing({params:{cardId:i},body:{active:t==="true"}});m(r);return}if(n==="is-processing"){let i=s??f(o,"--card-id","chat-store is-processing --board-dir <dir> --card-id <id>"),t=u.isProcessing({params:{cardId:i}});m(t);return}if(n==="get-config"){let i=s??f(o,"--card-id","chat-store get-config --board-dir <dir> --card-id <id>"),t=u.getConfig({params:{cardId:i}});m(t);return}if(n==="set-config"){let i=s??f(o,"--card-id","chat-store set-config --board-dir <dir> --card-id <id>"),t=C(o,"--system-prompt"),r={};if(t!==void 0&&(r.systemPrompt=t),!process.stdin.isTTY){let l=await V();if(l.trim())try{Object.assign(r,JSON.parse(l));}catch{}}let c=u.setConfig({params:{cardId:i},body:r});m(c);return}console.error(`chat-store: unknown command "${n}"
6
- ${I}`),process.exit(1);}function Rt(e){let{boardDir:n,commands:o,...a}=e;return a}function Ct(e){let{boardDir:n,commands:o,cardId:a}=e;return {cardId:typeof a=="string"?a:void 0,commands:Array.isArray(o)?o.map(s=>{if(!s||typeof s!="object"||Array.isArray(s))return s;let{boardDir:u,commands:i,...t}=s;return t}):[]}}function m(e){e.status!=="success"&&(console.error(`chat-store: ${e.status}: ${e.error}`),process.exit(1)),e.data!==void 0&&process.stdout.write(JSON.stringify(e.data,null,2)+`
7
- `);}var bt=process.argv[1]&&w(process.argv[1])===w(new URL(import.meta.url).pathname.replace(/^\/([A-Z]:)/,"$1"));bt&&kt(process.argv.slice(2)).catch(e=>{console.error("chat-store:",e instanceof Error?e.message:String(e)),process.exit(1);});export{kt as cli};//# sourceMappingURL=chat-store-cli.js.map
1
+ import'child_process';import*as d from'fs';import {existsSync}from'fs';import*as _ from'os';import*as y from'path';import {dirname,resolve}from'path';import'net';import {fileURLToPath}from'url';import {randomUUID}from'crypto';import {createRequire}from'module';import'proper-lockfile';import'ajv-formats';function R(...e){return y.join(...e)}function w(...e){return y.resolve(...e)}y.join(_.tmpdir(),".board-live-cards-git-bash-cache.json");var j=dirname(fileURLToPath(import.meta.url)),X=createRequire(import.meta.url);function Z(){let e=resolve(j,"./jsonata-sync.cjs");return existsSync(e)?e:resolve(j,"../../card-compute/jsonata-sync.cjs")}X(Z());createRequire(import.meta.url);function rt(e,n){if(process.platform!=="win32"){d.renameSync(e,n);return}let r=[10,20,40,80,160];for(let a=0;a<=r.length;a++)try{d.renameSync(e,n);return}catch(o){let u=o.code;if((u==="EPERM"||u==="EBUSY")&&a<r.length){Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,r[a]);continue}throw o}}function P(e){function n(a){return y.join(e,...a.split("/"))+".json"}function r(a,o,u,i){if(d.existsSync(a))for(let t of d.readdirSync(a,{withFileTypes:true})){let s=o?`${o}/${t.name}`:t.name;if(t.isDirectory()){r(y.join(a,t.name),s,u,i);continue}if(!t.isFile()||!t.name.endsWith(".json"))continue;let c=s.replace(/\.json$/,"");(!u||c.startsWith(u))&&i.push(c);}}return {read(a){let o=n(a);if(!d.existsSync(o))return null;try{return JSON.parse(d.readFileSync(o,"utf-8"))}catch{return null}},write(a,o){let u=n(a),i=`${u}.${process.pid}.${randomUUID()}.tmp`;d.mkdirSync(y.dirname(u),{recursive:true}),d.writeFileSync(i,JSON.stringify(o,null,2),"utf-8"),rt(i,u);},delete(a){let o=n(a);try{d.existsSync(o)&&d.unlinkSync(o);}catch{}},listKeys(a){let o=[];return r(e,"",a,o),o.sort()}}}function N(e){function n(){if(!d.existsSync(e))return [];let r=d.readFileSync(e,"utf-8").trim();return r?r.split(`
2
+ `).filter(Boolean).map(a=>JSON.parse(a)):[]}return {append(r){let a={id:randomUUID(),payload:r};return d.mkdirSync(y.dirname(e),{recursive:true}),d.appendFileSync(e,JSON.stringify(a)+`
3
+ `,"utf-8"),a},readAll(){return n()},readAfter(r){let a=n();if(!r)return {entries:a,newCursor:a.length>0?a[a.length-1].id:null};let o=a.findIndex(i=>i.id===r),u=o===-1?a:a.slice(o+1);return {entries:u,newCursor:u.length>0?u[u.length-1].id:r}},clear(){d.existsSync(e)&&d.truncateSync(e,0);}}}var ot=createRequire(import.meta.url);ot("./jsonata-sync.cjs");function B(e){return String(e).replace(/[^a-zA-Z0-9_-]/g,"_")}function D(e){let n=e.payload??{};return {id:e.id,role:typeof n.role=="string"?n.role:"system",text:typeof n.text=="string"?n.text:"",files:Array.isArray(n.files)?n.files:[],updated_at:typeof n.updated_at=="string"?n.updated_at:""}}function E(e,n){let r=o=>`chats/${B(o)}/processing`,a=o=>`chats/${B(o)}/config`;return {append(o,u,i,t=[]){return e(o).append({role:u,text:i,files:t,updated_at:new Date().toISOString()}).id},readAll(o){return e(o).readAll().map(D)},readAfter(o,u){let i=e(o).readAfter(u);return {records:i.entries.map(D),cursor:i.newCursor}},clear(o){e(o).clear?.();},setProcessing(o,u){u?n.write(r(o),true):n.delete(r(o));},isProcessing(o){return n.read(r(o))===true},getConfig(o){return n.read(a(o))??{}},setConfig(o,u){let i=n.read(a(o))??{};n.write(a(o),{...i,...u});}}}var lt=createRequire(import.meta.url);lt("./jsonata-sync.cjs");function kt(e,n){if(!e||!n)return false;let r=String(e).replace(/[\\/]+$/,"").split(/[\\/]+/).filter(Boolean);return r.length>0&&r[r.length-1]===n}function A(e,n={}){let r=n.chatsSubdir??"chats",a=n.kvSubdir??".kv",o=a?[a,"chat"]:["chat"],u=r&&!kt(e,r)?R(e,r):e,i=P(R(e,...o));return E(t=>{let c=`${String(t).replace(/[^a-zA-Z0-9_-]/g,"_")}.jsonl`,l=R(u,c);return N(l)},i)}function T(e){function n(t){return {status:"success",data:t}}function r(t){return {status:"fail",error:t}}function a(t){return {status:"error",error:t instanceof Error?t.message:String(t)}}function o(t,s="command envelope"){let c=typeof t.cardId=="string"?t.cardId:void 0;if(!t.command)return r(`chat-store: ${s} missing "command"`);if(!c)return r(`chat-store: ${s} missing "cardId"`);if(t.command==="append")return i.append({params:{cardId:c},body:{role:t.role,text:t.text,files:t.files}});if(t.command==="read-all")return i.readAll({params:{cardId:c}});if(t.command==="read-after")return i.readAfter({params:{cardId:c},body:{cursor:t.cursor??null}});if(t.command==="clear")return i.clear({params:{cardId:c}});if(t.command==="set-processing")return i.setProcessing({params:{cardId:c},body:{active:t.active}});if(t.command==="is-processing")return i.isProcessing({params:{cardId:c}});if(t.command==="get-config")return i.getConfig({params:{cardId:c}});if(t.command==="set-config"){let{command:l,cardId:p,...g}=t;return i.setConfig({params:{cardId:c},body:g})}return r(`chat-store: unknown command "${String(t.command)}"`)}function u(t){if(!Array.isArray(t.commands)||t.commands.length===0)return r('chat-store: command envelope must include a non-empty "commands" array');let s=[];for(let c=0;c<t.commands.length;c+=1){let l=t.commands[c];if(!l||typeof l!="object"||Array.isArray(l))return r(`chat-store: command envelope entry ${c} must be an object`);let p={cardId:t.cardId,...l},g=o(p,`command envelope entry ${c}`);if(g.status!=="success")return g;s.push({index:c,command:String(p.command),data:g.data});}return n({results:s})}let i={append(t){try{let s=t.params?.cardId;if(!s)return r("append requires params.cardId");let c=t.body??{},l=typeof c.role=="string"?c.role:"",p=typeof c.text=="string"?c.text:"",g=Array.isArray(c.files)?c.files:[];if(!l)return r("append requires body.role");let b=e.append(s,l,p,g);return n({id:b})}catch(s){return a(s)}},readAll(t){try{let s=t.params?.cardId;return s?n({records:e.readAll(s)}):r("readAll requires params.cardId")}catch(s){return a(s)}},readAfter(t){try{let s=t.params?.cardId;if(!s)return r("readAfter requires params.cardId");let l=(t.body??{}).cursor??null;return n(e.readAfter(s,l))}catch(s){return a(s)}},clear(t){try{let s=t.params?.cardId;return s?(e.clear(s),n({ok:!0})):r("clear requires params.cardId")}catch(s){return a(s)}},setProcessing(t){try{let s=t.params?.cardId;if(!s)return r("setProcessing requires params.cardId");let c=t.body??{};return typeof c.active!="boolean"?r("setProcessing requires body.active (boolean)"):(e.setProcessing(s,c.active),n({ok:!0}))}catch(s){return a(s)}},isProcessing(t){try{let s=t.params?.cardId;return s?n({active:e.isProcessing(s)}):r("isProcessing requires params.cardId")}catch(s){return a(s)}},getConfig(t){try{let s=t.params?.cardId;return s?n({config:e.getConfig(s)}):r("getConfig requires params.cardId")}catch(s){return a(s)}},setConfig(t){try{let s=t.params?.cardId;if(!s)return r("setConfig requires params.cardId");let c=t.body??{};return e.setConfig(s,c),n({ok:!0})}catch(s){return a(s)}},run:o,runBatch:u};return i}function f(e,n,r){let a=e.indexOf(n),o=a!==-1?e[a+1]:void 0;if(!o)throw new Error(`Missing ${n}
4
+ Usage: ${r}`);return o}function C(e,n){let r=e.indexOf(n);return r!==-1?e[r+1]:void 0}async function V(){let e=[];for await(let n of process.stdin)e.push(Buffer.isBuffer(n)?n:Buffer.from(n));return Buffer.concat(e).toString("utf-8")}var I=["chat-store \u2014 chat history and state operations for a board card",""," chat-store append --board-dir <dir> --card-id <id> --role <role> --text <text> [--files-json <json>]"," Append a message. Prints { id } on success.",""," chat-store read-all --board-dir <dir> --card-id <id>"," Print all messages as a JSON array.",""," chat-store read-after --board-dir <dir> --card-id <id> [--cursor <cursor>]"," Print messages after cursor as { records, cursor }.",""," chat-store clear --board-dir <dir> --card-id <id>"," Remove all messages for the card.",""," chat-store set-processing --board-dir <dir> --card-id <id> --active <true|false>"," Set or clear the processing flag.",""," chat-store is-processing --board-dir <dir> --card-id <id>"," Print { active: true|false }.",""," chat-store get-config --board-dir <dir> --card-id <id>"," Print the chat config object.",""," chat-store set-config --board-dir <dir> --card-id <id> [--system-prompt <text>]"," Patch the chat config. Extra fields can be piped as JSON to stdin.",""," Alternatively, pipe a JSON object to stdin:",' { "command": "<cmd>", "boardDir": "<dir>", "cardId": "<id>", ... }'," Or pipe a command envelope with defaults plus sequential commands:",' { "boardDir": "<dir>", "cardId": "<id>", "commands": [{ "command": "append", ... }, { "command": "set-processing", ... }] }'].join(`
5
+ `);async function Rt(e){if(e.length===0||e[0]==="--stdin"){let i=await V();if(!i.trim()){console.error(I);return}let t;try{t=JSON.parse(i);}catch{console.error("chat-store: stdin is not valid JSON"),process.exit(1);}let s=t.boardDir;s||(console.error('chat-store: stdin envelope missing "boardDir"'),process.exit(1));let c=t.chatsSubdir,l=t.kvSubdir,p={};c!==void 0&&(p.chatsSubdir=c),l!==void 0&&(p.kvSubdir=l);let g=T(A(s,p));if(Array.isArray(t.commands)){let K=g.runBatch(bt(t));m(K);return}let b=g.run(Ct(t));m(b);return}let n=e[0],r=e.slice(1);if(!n||n==="help"||n==="--help"||n==="-h"){console.error(I);return}let a=f(r,"--board-dir",`chat-store ${n} --board-dir <dir> --card-id <id>`),o=C(r,"--card-id"),u=T(A(a));if(n==="append"){let i=f(r,"--role","chat-store append --board-dir <dir> --card-id <id> --role <role> --text <text>"),t=f(r,"--text","chat-store append --board-dir <dir> --card-id <id> --role <role> --text <text>"),s=C(r,"--files-json"),c=s?JSON.parse(s):[],l=o??f(r,"--card-id","chat-store append --board-dir <dir> --card-id <id> --role <role> --text <text>"),p=u.append({params:{cardId:l},body:{role:i,text:t,files:c}});m(p);return}if(n==="read-all"){let i=o??f(r,"--card-id","chat-store read-all --board-dir <dir> --card-id <id>"),t=u.readAll({params:{cardId:i}});m(t);return}if(n==="read-after"){let i=o??f(r,"--card-id","chat-store read-after --board-dir <dir> --card-id <id>"),t=C(r,"--cursor")??null,s=u.readAfter({params:{cardId:i},body:{cursor:t}});m(s);return}if(n==="clear"){let i=o??f(r,"--card-id","chat-store clear --board-dir <dir> --card-id <id>"),t=u.clear({params:{cardId:i}});m(t);return}if(n==="set-processing"){let i=o??f(r,"--card-id","chat-store set-processing --board-dir <dir> --card-id <id> --active <true|false>"),t=f(r,"--active","chat-store set-processing --board-dir <dir> --card-id <id> --active <true|false>");t!=="true"&&t!=="false"&&(console.error('chat-store set-processing: --active must be "true" or "false"'),process.exit(1));let s=u.setProcessing({params:{cardId:i},body:{active:t==="true"}});m(s);return}if(n==="is-processing"){let i=o??f(r,"--card-id","chat-store is-processing --board-dir <dir> --card-id <id>"),t=u.isProcessing({params:{cardId:i}});m(t);return}if(n==="get-config"){let i=o??f(r,"--card-id","chat-store get-config --board-dir <dir> --card-id <id>"),t=u.getConfig({params:{cardId:i}});m(t);return}if(n==="set-config"){let i=o??f(r,"--card-id","chat-store set-config --board-dir <dir> --card-id <id>"),t=C(r,"--system-prompt"),s={};if(t!==void 0&&(s.systemPrompt=t),!process.stdin.isTTY){let l=await V();if(l.trim())try{Object.assign(s,JSON.parse(l));}catch{}}let c=u.setConfig({params:{cardId:i},body:s});m(c);return}console.error(`chat-store: unknown command "${n}"
6
+ ${I}`),process.exit(1);}function Ct(e){let{boardDir:n,commands:r,...a}=e;return a}function bt(e){let{boardDir:n,commands:r,cardId:a}=e;return {cardId:typeof a=="string"?a:void 0,commands:Array.isArray(r)?r.map(o=>{if(!o||typeof o!="object"||Array.isArray(o))return o;let{boardDir:u,commands:i,...t}=o;return t}):[]}}function m(e){e.status!=="success"&&(console.error(`chat-store: ${e.status}: ${e.error}`),process.exit(1)),e.data!==void 0&&process.stdout.write(JSON.stringify(e.data,null,2)+`
7
+ `);}var wt=process.argv[1]&&w(process.argv[1])===w(new URL(import.meta.url).pathname.replace(/^\/([A-Z]:)/,"$1"));wt&&Rt(process.argv.slice(2)).catch(e=>{console.error("chat-store:",e instanceof Error?e.message:String(e)),process.exit(1);});export{Rt as cli};//# sourceMappingURL=chat-store-cli.js.map
8
8
  //# sourceMappingURL=chat-store-cli.js.map