dockito 0.0.1-beta.2 → 0.0.1-beta.3
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/README.md +4 -4
- package/dockito.js +55 -85
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,13 +11,13 @@ npx dockito@beta publish plan.md -m "Sent to the client"
|
|
|
11
11
|
| Command | Does |
|
|
12
12
|
|---|---|
|
|
13
13
|
| `login` | Sign in through the browser and choose what this login may do in each workspace |
|
|
14
|
-
| `sync
|
|
15
|
-
| `publish <file...>` | Publish
|
|
14
|
+
| `sync <folder> --to <project>` | Mirror a folder into a project: subfolders become folders, only changed files are sent, a plan first |
|
|
15
|
+
| `publish <file...>` | Publish a file; one with the same name in that place updates its doc |
|
|
16
16
|
| `tree`, `mkdir` | Every workspace, project and folder you can use; make new ones |
|
|
17
17
|
| `ls`, `open`, `get` | List, open and download docs |
|
|
18
18
|
| `history`, `restore`, `save` | A doc's History |
|
|
19
|
-
| `whoami`, `
|
|
19
|
+
| `whoami`, `logout` | Your login and workspaces |
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
The CLI keeps nothing but your login: where docs go is passed with `--to` each time. Run `dockito --help` for everything, and `dockito agent` for what an AI agent needs to know. `--json` gives machine-readable output for agents, and `DOCKITO_TOKEN` uses a token from Account → Tokens instead of a login.
|
|
22
22
|
|
|
23
23
|
This is a beta: commands may still change.
|
package/dockito.js
CHANGED
|
@@ -1,100 +1,70 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
`),
|
|
5
|
-
`);
|
|
6
|
-
`)
|
|
7
|
-
|
|
8
|
-
`),
|
|
9
|
-
`)
|
|
10
|
-
`)}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
`,"\r"
|
|
18
|
-
`
|
|
19
|
-
`)return`\r
|
|
20
|
-
`;return"\r"}else if(t===`
|
|
21
|
-
`)return`
|
|
22
|
-
`}return e&&e.eol||`
|
|
23
|
-
`}function Ie(e,n){return`\r
|
|
24
|
-
`.indexOf(e.charAt(n))!==-1}var _e;(function(e){e.DEFAULT={allowTrailingComma:!1}})(_e||(_e={}));function fn(e,n=[],r=_e.DEFAULT){let t=null,s=[],o=[];function c(l){if(Array.isArray(s))s.push(l);else if(t!==null)s[t]=l}return _t(e,{onObjectBegin:()=>{let l={};c(l),o.push(s),s=l,t=null},onObjectProperty:(l)=>{t=l},onObjectEnd:()=>{s=o.pop()},onArrayBegin:()=>{let l=[];c(l),o.push(s),s=l,t=null},onArrayEnd:()=>{s=o.pop()},onLiteralValue:c,onError:(l,f,u)=>{n.push({error:l,offset:f,length:u})}},r),s[0]}function It(e,n=[],r=_e.DEFAULT){let t={type:"array",offset:-1,length:-1,children:[],parent:void 0};function s(l){if(t.type==="property")t.length=l-t.offset,t=t.parent}function o(l){return t.children.push(l),l}_t(e,{onObjectBegin:(l)=>{t=o({type:"object",offset:l,length:-1,parent:t,children:[]})},onObjectProperty:(l,f,u)=>{t=o({type:"property",offset:f,length:-1,parent:t,children:[]}),t.children.push({type:"string",value:l,offset:f,length:u,parent:t})},onObjectEnd:(l,f)=>{s(l+f),t.length=l+f-t.offset,t=t.parent,s(l+f)},onArrayBegin:(l,f)=>{t=o({type:"array",offset:l,length:-1,parent:t,children:[]})},onArrayEnd:(l,f)=>{t.length=l+f-t.offset,t=t.parent,s(l+f)},onLiteralValue:(l,f,u)=>{o({type:lr(l),offset:f,length:u,parent:t,value:l}),s(f+u)},onSeparator:(l,f,u)=>{if(t.type==="property"){if(l===":")t.colonOffset=f;else if(l===",")s(f)}},onError:(l,f,u)=>{n.push({error:l,offset:f,length:u})}},r);let i=t.children[0];if(i)delete i.parent;return i}function nt(e,n){if(!e)return;let r=e;for(let t of n)if(typeof t==="string"){if(r.type!=="object"||!Array.isArray(r.children))return;let s=!1;for(let o of r.children)if(Array.isArray(o.children)&&o.children[0].value===t&&o.children.length===2){r=o.children[1],s=!0;break}if(!s)return}else{let s=t;if(r.type!=="array"||s<0||!Array.isArray(r.children)||s>=r.children.length)return;r=r.children[s]}return r}function _t(e,n,r=_e.DEFAULT){let t=Ee(e,!1),s=[],o=0;function c(S){return S?()=>o===0&&S(t.getTokenOffset(),t.getTokenLength(),t.getTokenStartLine(),t.getTokenStartCharacter()):()=>!0}function i(S){return S?(F)=>o===0&&S(F,t.getTokenOffset(),t.getTokenLength(),t.getTokenStartLine(),t.getTokenStartCharacter()):()=>!0}function l(S){return S?(F)=>o===0&&S(F,t.getTokenOffset(),t.getTokenLength(),t.getTokenStartLine(),t.getTokenStartCharacter(),()=>s.slice()):()=>!0}function f(S){return S?()=>{if(o>0)o++;else if(S(t.getTokenOffset(),t.getTokenLength(),t.getTokenStartLine(),t.getTokenStartCharacter(),()=>s.slice())===!1)o=1}:()=>!0}function u(S){return S?()=>{if(o>0)o--;if(o===0)S(t.getTokenOffset(),t.getTokenLength(),t.getTokenStartLine(),t.getTokenStartCharacter())}:()=>!0}let p=f(n.onObjectBegin),g=l(n.onObjectProperty),v=u(n.onObjectEnd),A=f(n.onArrayBegin),j=u(n.onArrayEnd),T=l(n.onLiteralValue),P=i(n.onSeparator),L=c(n.onComment),m=i(n.onError),E=r&&r.disallowComments,b=r&&r.allowTrailingComma;function y(){while(!0){let S=t.scan();switch(t.getTokenError()){case 4:d(14);break;case 5:d(15);break;case 3:d(13);break;case 1:if(!E)d(11);break;case 2:d(12);break;case 6:d(16);break}switch(S){case 12:case 13:if(E)d(10);else L();break;case 16:d(1);break;case 15:case 14:break;default:return S}}}function d(S,F=[],Ae=[]){if(m(S),F.length+Ae.length>0){let me=t.getToken();while(me!==17){if(F.indexOf(me)!==-1){y();break}else if(Ae.indexOf(me)!==-1)break;me=y()}}}function H(S){let F=t.getTokenValue();if(S)T(F);else g(F),s.push(F);return y(),!0}function se(){switch(t.getToken()){case 11:let S=t.getTokenValue(),F=Number(S);if(isNaN(F))d(2),F=0;T(F);break;case 7:T(null);break;case 8:T(!0);break;case 9:T(!1);break;default:return!1}return y(),!0}function Y(){if(t.getToken()!==10)return d(3,[],[2,5]),!1;if(H(!1),t.getToken()===6){if(P(":"),y(),!ge())d(4,[],[2,5])}else d(5,[],[2,5]);return s.pop(),!0}function Je(){p(),y();let S=!1;while(t.getToken()!==2&&t.getToken()!==17){if(t.getToken()===5){if(!S)d(4,[],[]);if(P(","),y(),t.getToken()===2&&b)break}else if(S)d(6,[],[]);if(!Y())d(4,[],[2,5]);S=!0}if(v(),t.getToken()!==2)d(7,[2],[]);else y();return!0}function ee(){A(),y();let S=!0,F=!1;while(t.getToken()!==4&&t.getToken()!==17){if(t.getToken()===5){if(!F)d(4,[],[]);if(P(","),y(),t.getToken()===4&&b)break}else if(F)d(6,[],[]);if(S)s.push(0),S=!1;else s[s.length-1]++;if(!ge())d(4,[],[4,5]);F=!0}if(j(),!S)s.pop();if(t.getToken()!==4)d(8,[4],[]);else y();return!0}function ge(){switch(t.getToken()){case 3:return ee();case 1:return Je();case 10:return H(!0);default:return se()}}if(y(),t.getToken()===17){if(r.allowEmptyContent)return!0;return d(4,[],[]),!1}if(!ge())return d(4,[],[]),!1;if(t.getToken()!==17)d(9,[],[]);return!0}function lr(e){switch(typeof e){case"boolean":return"boolean";case"number":return"number";case"string":return"string";case"object":{if(!e)return"null";else if(Array.isArray(e))return"array";return"object"}default:return"null"}}function dn(e,n,r,t){let s=n.slice(),c=It(e,[]),i=void 0,l=void 0;while(s.length>0)if(l=s.pop(),i=nt(c,s),i===void 0&&r!==void 0)if(typeof l==="string")r={[l]:r};else r=[r];else break;if(!i){if(r===void 0)throw Error("Can not delete in empty document");return ae(e,{offset:c?c.offset:0,length:c?c.length:0,content:JSON.stringify(r)},t)}else if(i.type==="object"&&typeof l==="string"&&Array.isArray(i.children)){let f=nt(i,[l]);if(f!==void 0)if(r===void 0){if(!f.parent)throw Error("Malformed AST");let u=i.children.indexOf(f.parent),p,g=f.parent.offset+f.parent.length;if(u>0){let v=i.children[u-1];p=v.offset+v.length}else if(p=i.offset+1,i.children.length>1)g=i.children[1].offset;return ae(e,{offset:p,length:g-p,content:""},t)}else return ae(e,{offset:f.offset,length:f.length,content:JSON.stringify(r)},t);else{if(r===void 0)return[];let u=`${JSON.stringify(l)}: ${JSON.stringify(r)}`,p=t.getInsertionIndex?t.getInsertionIndex(i.children.map((v)=>v.children[0].value)):i.children.length,g;if(p>0){let v=i.children[p-1];g={offset:v.offset+v.length,length:0,content:","+u}}else if(i.children.length===0)g={offset:i.offset+1,length:0,content:u};else g={offset:i.offset+1,length:0,content:u+","};return ae(e,g,t)}}else if(i.type==="array"&&typeof l==="number"&&Array.isArray(i.children)){let f=l;if(f===-1){let u=`${JSON.stringify(r)}`,p;if(i.children.length===0)p={offset:i.offset+1,length:0,content:u};else{let g=i.children[i.children.length-1];p={offset:g.offset+g.length,length:0,content:","+u}}return ae(e,p,t)}else if(r===void 0&&i.children.length>=0){let u=l,p=i.children[u],g;if(i.children.length===1)g={offset:i.offset+1,length:i.length-2,content:""};else if(i.children.length-1===u){let v=i.children[u-1],A=v.offset+v.length,j=i.offset+i.length;g={offset:A,length:j-2-A,content:""}}else g={offset:p.offset,length:i.children[u+1].offset-p.offset,content:""};return ae(e,g,t)}else if(r!==void 0){let u,p=`${JSON.stringify(r)}`;if(!t.isArrayInsertion&&i.children.length>l){let g=i.children[l];u={offset:g.offset,length:g.length,content:p}}else if(i.children.length===0||l===0)u={offset:i.offset+1,length:0,content:i.children.length===0?p:p+","};else{let g=l>i.children.length?i.children.length:l,v=i.children[g-1];u={offset:v.offset+v.length,length:0,content:","+p}}return ae(e,u,t)}else throw Error(`Can not ${r===void 0?"remove":t.isArrayInsertion?"insert":"modify"} Array index ${f} as length is not sufficient`)}else throw Error(`Can not add ${typeof l!=="number"?"index":"property"} to parent of type ${i.type}`)}function ae(e,n,r){if(!r.formattingOptions)return[n];let t=rt(e,n),s=n.offset,o=n.offset+n.content.length;if(n.length===0||n.content.length===0){while(s>0&&!Ie(t,s-1))s--;while(o<t.length&&!Ie(t,o))o++}let c=Et(t,{offset:s,length:o-s},{...r.formattingOptions,keepLines:!1});for(let l=c.length-1;l>=0;l--){let f=c[l];t=rt(t,f),s=Math.min(s,f.offset),o=Math.max(o,f.offset+f.length),o+=f.content.length-f.length}let i=e.length-(t.length-o)-s;return[{offset:s,length:i,content:t.substring(s,o)}]}function rt(e,n){return e.substring(0,n.offset)+n.content+e.substring(n.offset+n.length)}var pn;(function(e){e[e.None=0]="None",e[e.UnexpectedEndOfComment=1]="UnexpectedEndOfComment",e[e.UnexpectedEndOfString=2]="UnexpectedEndOfString",e[e.UnexpectedEndOfNumber=3]="UnexpectedEndOfNumber",e[e.InvalidUnicode=4]="InvalidUnicode",e[e.InvalidEscapeCharacter=5]="InvalidEscapeCharacter",e[e.InvalidCharacter=6]="InvalidCharacter"})(pn||(pn={}));var gn;(function(e){e[e.OpenBraceToken=1]="OpenBraceToken",e[e.CloseBraceToken=2]="CloseBraceToken",e[e.OpenBracketToken=3]="OpenBracketToken",e[e.CloseBracketToken=4]="CloseBracketToken",e[e.CommaToken=5]="CommaToken",e[e.ColonToken=6]="ColonToken",e[e.NullKeyword=7]="NullKeyword",e[e.TrueKeyword=8]="TrueKeyword",e[e.FalseKeyword=9]="FalseKeyword",e[e.StringLiteral=10]="StringLiteral",e[e.NumericLiteral=11]="NumericLiteral",e[e.LineCommentTrivia=12]="LineCommentTrivia",e[e.BlockCommentTrivia=13]="BlockCommentTrivia",e[e.LineBreakTrivia=14]="LineBreakTrivia",e[e.Trivia=15]="Trivia",e[e.Unknown=16]="Unknown",e[e.EOF=17]="EOF"})(gn||(gn={}));var ot=fn;var mn;(function(e){e[e.InvalidSymbol=1]="InvalidSymbol",e[e.InvalidNumberFormat=2]="InvalidNumberFormat",e[e.PropertyNameExpected=3]="PropertyNameExpected",e[e.ValueExpected=4]="ValueExpected",e[e.ColonExpected=5]="ColonExpected",e[e.CommaExpected=6]="CommaExpected",e[e.CloseBraceExpected=7]="CloseBraceExpected",e[e.CloseBracketExpected=8]="CloseBracketExpected",e[e.EndOfFileExpected=9]="EndOfFileExpected",e[e.InvalidCommentToken=10]="InvalidCommentToken",e[e.UnexpectedEndOfComment=11]="UnexpectedEndOfComment",e[e.UnexpectedEndOfString=12]="UnexpectedEndOfString",e[e.UnexpectedEndOfNumber=13]="UnexpectedEndOfNumber",e[e.InvalidUnicode=14]="InvalidUnicode",e[e.InvalidEscapeCharacter=15]="InvalidEscapeCharacter",e[e.InvalidCharacter=16]="InvalidCharacter"})(mn||(mn={}));function st(e,n,r,t){return dn(e,n,r,t)}function it(e,n){let r=n.slice(0).sort((s,o)=>{let c=s.offset-o.offset;if(c===0)return s.length-o.length;return c}),t=e.length;for(let s=r.length-1;s>=0;s--){let o=r[s];if(o.offset+o.length<=t)e=rt(e,o);else throw Error("Overlapping edit");t=o.offset}return e}var ue="dockito.jsonc";function Rt(e=process.cwd()){for(let n=bn(e);;n=hn(n)){let r=yn(n,ue);if(fr(r)){let t=[],s=ot(wn(r,"utf8"),t,{allowTrailingComma:!0});if(t.length||!s||typeof s!=="object")throw Error(`${r} isn't valid JSONC.`);return{file:r,dir:n,config:s}}if(hn(n)===n)return null}}var gr=(e,n)=>dr(e.dir,bn(n)).split(pr).join("/");function oe(e,n,r){let t=wn(e.file,"utf8"),s=st(t,n,r,{formattingOptions:{insertSpaces:!0,tabSize:2}});kn(e.file,it(t,s));let o=e.config;for(let c of n.slice(0,-1))o=o[c]??={};o[n[n.length-1]]=r}var Dt=(e,n,r)=>oe(e,["docs",gr(e,n)],r);function $n(e,n){let r=["{"," // Where Dockito docs from this repo go. No secrets in this file."," // Run `dockito agent` to learn the CLI, `dockito tree` to see places.",` "workspace": ${JSON.stringify(n.workspace)},`,n.project?` "project": ${JSON.stringify(n.project)},`:' // "project": "my-project",',n.folder?` "folder": ${JSON.stringify(n.folder)},`:' // "folder": "Folder/Subfolder",',n.dir?` // \`dockito sync\` mirrors this folder into the project, subfolders as folders.
|
|
25
|
-
"dir": ${JSON.stringify(n.dir)},`:' // "dir": "docs",'," // Local files and the docs they publish to. Filled in by Dockito.",' "docs": {}',"}",""],t=yn(e,ue);return kn(t,r.join(`
|
|
26
|
-
`)),t}var Re=2,br=4,De=(e)=>e<1048576?`${e?Math.max(1,Math.round(e/1024)):0} KB`:`${(e/1048576).toFixed(1)} MB`,Ut=[],lt=(e)=>{let n=/\.[^./]+$/.exec(e.toLowerCase())?.[0]??"";return Ut.find((r)=>r.extensions.includes(n))?.id??null},$r=(e)=>Fe(e).replace(/\.[^.]+$/,"").trim(),jr=(e)=>mr("sha256").update(e).digest("hex"),Pe=(e)=>e.split(yr).join("/");class de extends Error{code;data;constructor(e,n,r={}){super(n);this.code=e;this.data=r}}function at(e,n){let r=hr("git",e,{cwd:n,encoding:"utf8",maxBuffer:67108864});return r.error||r.status!==0?null:r.stdout}var Tr=(e=process.cwd())=>at(["rev-parse","--show-toplevel"],e)?.trim()||null;function vr(e){let n=at(["ls-files","-z","--cached","--others","--exclude-standard","--","."],e);return(n!==null?n.split("\x00").filter(Boolean):function t(s){return kr(B(e,s),{withFileTypes:!0}).flatMap((o)=>o.name.startsWith(".")||o.name==="node_modules"?[]:o.isDirectory()?t(B(s,o.name)):[Pe(B(s,o.name))])}("")).filter((t)=>lt(t)&&fe(B(e,t))&&vn(B(e,t)).isFile()).sort()}function xr(e,n){let r=[...e.matchAll(/\b(?:src|href)=["']([^"'#?]+)/gi)].map((t)=>t[1]);return[...new Set(r.filter((t)=>!/^([a-z]+:|\/\/|\/)/i.test(t)&&!lt(t)&&fe(B(n,t))))]}var ct=(e)=>e.level===null||e.level==="publish"||e.level==="everything",Or=(e,n)=>e.projects.find((r)=>r.slug===n)??e.projects.find((r)=>r.name.toLowerCase()===n.toLowerCase())??null,Ft=(e)=>e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"");function Bt(e,n,r){let t=e.filter(ct),s=(i,l,f="")=>`dockito sync ${n==="."?"":n+" "}-w ${i} --to ${l}${f}`,o=t.flatMap((i)=>[...i.projects.map((l)=>({workspace:i.slug,project:l.slug,name:l.name,docs:l.docs,command:s(i.slug,l.slug)})),{workspace:i.slug,project:null,name:"a new project",docs:0,command:s(i.slug,"<name>"," --create")}]),c=Math.max(...o.map((i)=>i.command.length));throw new de("needs_place",[`${r} Ask the user which project it goes to, then run one of:`,...o.map((i)=>` ${i.command.padEnd(c)} ${D(i.project?`${i.name} · ${i.docs} doc${i.docs===1?"":"s"}`:i.name)}`),D("Subfolders become folders. `dockito tree` shows every place.")].join(`
|
|
27
|
-
`),{choices:o})}async function ut(e,n,r){let{c:t,url:s}=e,o=xt()&&!r.json,c=Rt(),i=c?.dir??Tr()??process.cwd(),l=n?Pe(Pt(i,jn(n)))||".":c?.config.dir;if(l?.startsWith(".."))X(`${n} is outside ${c?ue:"this repo"} at ${i}.`);if(n&&c?.config.dir&&l!==c.config.dir)X(`This repo syncs ${c.config.dir} (${ue}). Change "dir" there to sync another folder.`);let f=!c?.config.dir||!c.config.project,{kinds:u,workspaces:p}=await t.tree();if(Ut=u,!p.some(ct))X("This login can't publish anywhere. Run `dockito login --update`.");let g=r.workspace??c?.config.workspace??At(s).workspace,v=g?p.find((a)=>a.slug===g):void 0;if(g&&!v)X(`This login can't reach workspace "${g}". \`dockito tree\` lists the ones it can.`);let A=r.to??(c?.config.project?[c.config.project,c.config.folder].filter(Boolean).join("/"):void 0);if(!l){let a=fe(B(i,"docs"))?"docs":Pe(Pt(i,process.cwd()))||".";if(o)l=Pe(Pt(i,jn(i,await Ze("Folder to sync",a))))||".";else if(!A)Bt(p,a,`Nothing says where ${a==="."?"this folder":a+"/"} goes yet.`);else l=a}if(!fe(B(i,l))||!vn(B(i,l)).isDirectory())X(`${l} isn't a folder.`);if(!v){let a=p.filter(ct);if(a.length===1)v=a[0];else if(o)v=a[await Ot("Workspace",a.map((k)=>({label:k.name,hint:k.slug})))];else Bt(p,l,"Pick a workspace and project.")}if(!ct(v))X(`This login has View access in ${v.slug}; syncing needs Publish. Run \`dockito login --update\`.`);let j=v,T,P;if(A){if([T,...P]=A.split("/").filter(Boolean),!T)X("--to takes a project, or project/folder.")}else if(o){let a=Fe(i),k=[...j.projects.map((I)=>({label:I.name,hint:`${I.slug} · ${I.docs} doc${I.docs===1?"":"s"}`})),{label:"New project",hint:""}],h=j.projects.findIndex((I)=>I.slug===Ft(a)),w=await Ot("Project",k,h>=0?h:k.length-1);T=w<j.projects.length?j.projects[w].slug:await Ze("Project name",a),P=[]}else return Bt(p,l,`Nothing says where ${l==="."?"this folder":l+"/"} goes yet.`);let L=Or(j,T),m=!L;if(m&&!r.create&&!(o&&!A))throw new de("no_project",`No project "${T}" in ${j.slug}. Projects: ${j.projects.map((a)=>a.slug).join(", ")||"none"}.
|
|
28
|
-
To make it, run again with --create.`,{workspace:j.slug,projects:j.projects.map((a)=>a.slug)});if(P.length>Re)X(`Folders go at most ${Re} deep inside a project.`);let E=B(i,l),b=vr(E);if(!b.length)X(`No ${Ut.flatMap((a)=>a.extensions).join(", ")} files in ${l}.`);let y=Object.entries(c?.config.map??{}).map(([a,k])=>({from:a.replace(/\/\*\*$/,""),to:k.split("/").filter(Boolean)})),d=Re-P.length,H=b.map((a)=>{let k=a.split("/").slice(0,-1),h=y.filter((w)=>a.startsWith(w.from+"/")).sort((w,I)=>I.from.length-w.from.length)[0];return{f:a,folder:h?h.to:k}}),se=null,Y=H.filter((a)=>a.folder.length>d);if(Y.length){let a={};for(let w of Y){let I=w.folder.slice(0,d);a[[...I,w.folder[d]].join("/")+"/**"]=I.join("/")}let k=Object.entries(a).map(([w,I])=>` "${w}": "${I||"(the project's top)"}"`);if(!(r.fold||o&&(Le(`${Y.length} file${Y.length===1?" is":"s are"} more than ${Re} folders deep. Dockito would put them here:
|
|
29
|
-
${k.join(`
|
|
30
|
-
`)}`),await Ce("Fold them like that?"))))throw new de("too_deep",`${Y.length} file${Y.length===1?" is":"s are"} more than ${Re} folders deep inside the project. Run again with --fold to put them here (kept in ${ue} as "map"):
|
|
31
|
-
${k.join(`
|
|
32
|
-
`)}`,{map:a});for(let w of Y)w.folder=w.folder.slice(0,d);se=a}let Je=m?[]:await t.places(j.id),ee=new Map,ge=new Map;if(L){let a=new Map(L.folders.map((h)=>[h.id,h])),k=(h)=>{let w=a.get(h);return[...w.parentId?k(w.parentId):[],w.name]};for(let h of L.folders){let w=k(h.id);ee.set(w.join("/").toLowerCase(),h.id),ge.set(h.id,w.join("/"))}}let S=(a)=>a.projectId!==L?.id?a.projectId?"another project":"Docs":a.folderId?ge.get(a.folderId)??"a folder":"the project's top",F=At(s),Ae=at(["rev-parse","HEAD"],i)?.trim()??null,me=new Set((at(["status","--porcelain","-z","--",l],i)??"").split("\x00").map((a)=>a.slice(3)).filter(Boolean)),yt=new Set,ie=[];for(let{f:a,folder:k}of H){let h=[...P,...k],w=Pe(B(l,a)),I=B(E,a),te=new Uint8Array(Tn(I)),ne=lt(a),G={path:w,name:Fe(a),folder:h,kind:ne,bytes:te,hash:jr(te),action:"new",doc:null,base:null,stays:null,assets:[]};if(ne==="html")G.assets=xr(new TextDecoder().decode(te),B(E,a,".."));let Yn=h.length?ee.get(h.join("/").toLowerCase())??"missing":null,Ke=c?.config.docs?.[w],ce=Ke?Je.find((q)=>q.slug===Ke):void 0;if(Ke&&!ce)try{let q=await t.doc(Ke);G.doc={id:q.doc.id,slug:q.doc.slug},G.stays=`${q.workspace.slug}${q.project?"/"+q.project.slug:""}`}catch(q){if(!(q instanceof Se)||q.code!=="not_found"&&q.code!=="deleted")throw q}if(ce){if(G.doc={id:ce.id,slug:ce.slug},ce.projectId!==L?.id||(ce.folderId??null)!==Yn)G.stays=S(ce)}if(G.doc)yt.add(G.doc.id),G.base=F.entries?.[G.doc.id]??null,G.action=F.hashes?.[G.doc.id]===G.hash?"same":"update";ie.push(G)}for(let a of ie){if(a.doc||!L)continue;let k=a.folder.length?ee.get(a.folder.join("/").toLowerCase()):null;if(k===void 0)continue;let h=Je.find((w)=>!yt.has(w.id)&&w.projectId===L.id&&(w.folderId??null)===k&&w.kind===a.kind&&w.title===$r(a.name));if(h)yt.add(h.id),a.doc={id:h.id,slug:h.slug},a.action="link"}let Ge=l==="."?"":l+"/",Yt=Object.entries(c?.config.docs??{}).filter(([a])=>a.startsWith(Ge)&<(a)&&!fe(B(i,a))),Q=[],Xt=new Set;for(let a of ie)for(let k=1;k<=a.folder.length;k++){let h=a.folder.slice(0,k),w=h.join("/").toLowerCase();if(!ee.has(w)&&!Xt.has(w))Xt.add(w),Q.push(h)}Q.sort((a,k)=>a.length-k.length);let Qt=ie.filter((a)=>a.bytes.length>j.maxFile);if(Qt.length)X(`Over the ${De(j.maxFile)} limit per file in ${j.slug}:
|
|
33
|
-
${Qt.map((a)=>` ${a.path} ${De(a.bytes.length)}`).join(`
|
|
34
|
-
`)}`);let zn=`${j.slug}/${L?.slug??Ft(T)}${P.length?"/"+P.join("/"):""}`,V=ie.filter((a)=>a.action!=="same"),bt=ie.length-V.length,Hn=m||Q.length>0||ie.some((a)=>a.action==="link");if(!r.json){if(R(`${re(l==="."?"./":l+"/")} → ${re(zn)}`),m)R(` ${U("+ project")} ${T}`);for(let h of Q)R(` ${U("+ folder ")} ${h.join("/")}`);let a=V.length>15;if(a)for(let[h,w]of[["new",U("+ new ")],["link",le("= link ")]]){let I=new Map;for(let te of V.filter((ne)=>ne.action===h))I.set(te.folder.join("/"),[...I.get(te.folder.join("/"))??[],te.name]);for(let[te,ne]of I)R(` ${w} ${ne.length} in ${te||"the project's top"}: ${D(ne.slice(0,4).join(", ")+(ne.length>4?`, ${ne.length-4} more`:""))}`)}if(a&&V.some((h)=>h.action==="link"))R(D(" = link: a doc with the same name is already there; the file updates it"));for(let h of V){let w=h.path.slice(Ge.length),I=h.folder.join("/")!==[...P,...w.split("/").slice(0,-1)].join("/")?D(` → ${h.folder.join("/")||"the project's top"}`):"";if(h.action==="new")!a&&R(` ${U("+ new ")} ${w}${I}`);else if(h.action==="link")!a&&R(` ${le("= link ")} ${w} ${D(`updates the doc already there, ${t.linkOf(h.doc.slug)}`)}`);else R(` ${Qe("~ update ")} ${w}${h.stays?D(` (stays in ${h.stays}; moving comes later)`):""}`)}if(bt)R(D(` ${bt} unchanged`));if(V.length)R(D(` ${V.length} file${V.length===1?"":"s"} to send, ${De(V.reduce((h,w)=>h+w.bytes.length,0))}`));for(let[h,w]of Yt)R(` ${Xe("- gone ")} ${h.slice(Ge.length)} ${D(`file deleted; its doc stays, ${t.linkOf(w)}`)}`);let k=V.filter((h)=>h.assets.length);if(k.length)R(Qe(` ! ${k.length===1?k[0].path.slice(Ge.length):`${k.length} HTML files`} load${k.length===1?"s":""} ${[...new Set(k.flatMap((h)=>h.assets))].join(", ")} from next to ${k.length===1?"it":"them"}; only HTML files are published`))}let ze={workspace:j.slug,project:L?.slug??Ft(T),dir:l,create:{project:m?T:null,folders:Q.map((a)=>a.join("/"))},docs:V.map((a)=>({file:a.path,action:a.action,folder:a.folder.join("/")||null,link:a.doc?t.linkOf(a.doc.slug):null,stays:a.stays})),unchanged:bt,gone:Yt.map(([a,k])=>({file:a,link:t.linkOf(k)}))};if(!V.length&&!m&&!Q.length){if(r.json)R(JSON.stringify({...ze,applied:!0},null,2));else R(`${U("✓")} Up to date`);return Zt()}if(r["dry-run"]){if(r.json)R(JSON.stringify({...ze,applied:!1},null,2));return}if((Hn||f)&&!r.yes){if(!o){let a=["dockito sync",n?l:"",r.workspace?`-w ${j.slug}`:"",r.to?`--to ${r.to}`:"",r.create?"--create":"",r.fold?"--fold":"","--yes"].filter(Boolean).join(" ");if(r.json)return R(JSON.stringify({...ze,applied:!1,next:a},null,2));throw new de("confirm",`
|
|
35
|
-
Nothing changed yet. Show the user this plan, then run: ${a}`,{next:a})}if(!await Ce("Apply?"))return Le(D("Nothing changed."))}Zt();function Zt(){if(!c){if($n(i,{workspace:j.slug,dir:l}),c=Rt(i),!r.json)Le(D(`Wrote ${ue}`))}if(c.config.workspace!==j.slug)oe(c,["workspace"],j.slug);if(c.config.dir!==l)oe(c,["dir"],l);if(!c.config.project&&L)oe(c,["project"],L.slug);if(!c.config.folder&&P.length)oe(c,["folder"],P.join("/"));if(se){for(let[a,k]of Object.entries(se))if(c.config.map?.[a]===void 0)oe(c,["map",a],k)}}if(m){let a=await t.createProject(j.id,T);if(L={id:a.id,slug:a.slug,name:T,docs:0,folders:[]},oe(c,["project"],a.slug),!r.json)R(`${U("✓")} Project ${T}`)}for(let a of Q){let k=a.length>1?ee.get(a.slice(0,-1).join("/").toLowerCase()):null,h=await t.createFolder(L.id,a[a.length-1],k);ee.set(a.join("/").toLowerCase(),h.id)}if(Q.length&&!r.json)R(`${U("✓")} ${Q.length} folder${Q.length===1?"":"s"}`);let he=[],He=null,$t=[...V],qe=!r.json&&xt(),qn=V.reduce((a,k)=>a+k.bytes.length,0),Ct=0,en=()=>qe&&process.stdout.write(`\r\x1B[2K${D(`Sending ${he.length} of ${V.length} · ${De(Ct)} of ${De(qn)}`)}`);en();async function Kn(a){let k=Ae&&!me.has(a.path)?Ae:null;for(;;)try{if(a.doc){let I=await t.update(a.doc.id,a.name,a.bytes,{commit:k,base:a.action==="link"?null:a.base});if(Lt(s,I.id,I.version,a.hash),a.action==="link")Dt(c,B(i,a.path),I.slug);return{file:a.path,action:a.action,link:t.linkOf(I.slug)}}let h=a.folder.length?ee.get(a.folder.join("/").toLowerCase()):null,w=await t.create(j.id,a.name,a.bytes,{project:L.id,folder:h});return Lt(s,w.id,w.version,a.hash),Dt(c,B(i,a.path),w.slug),{file:a.path,action:"new",link:t.linkOf(w.slug)}}catch(h){if(h instanceof Se&&h.code==="rate_limited"){if(!He){if(!r.json)Le(D("Upload limit reached; carrying on in a minute…"));He=new Promise((w)=>setTimeout(w,30000)).then(()=>void(He=null))}await He;continue}return{file:a.path,action:a.action,error:h instanceof Se?on(h,s):String(h)}}}if(await Promise.all(Array.from({length:Math.min(br,$t.length)},async()=>{for(let a=$t.shift();a;a=$t.shift()){let k=await Kn(a);if(he.push(k),Ct+=a.bytes.length,qe)process.stdout.write("\r\x1B[2K");if(k.error&&!r.json)R(`${Xe("✗")} ${k.file} ${Xe(k.error)}`);else if(!r.json&&!qe)R(`${U("✓")} ${k.file} ${D(k.link)}`);en()}})),qe)process.stdout.write("\r\x1B[2K");let jt=he.filter((a)=>a.error),tn=`${s}/${j.slug}/project/${L.slug}`;if(r.json)R(JSON.stringify({...ze,project:L.slug,applied:!0,link:tn,results:he},null,2));else R(`
|
|
36
|
-
${jt.length?Qe(`${he.length-jt.length} of ${he.length} sent`):U("✓ Synced")} ${D(tn)}`);if(jt.length)process.exitCode=1;if(f&&o)await Lr(i)}var Ar="\n## Dockito\n\nDocs here publish to Dockito (see `dockito.jsonc`). After changing them, run `dockito sync` (or `npx dockito@beta sync`).\nRun `dockito agent` first to learn the CLI; never guess where a doc goes.\n";async function Lr(e){let n=["AGENTS.md","CLAUDE.md"].map((r)=>B(e,r)).find(fe)??B(e,"AGENTS.md");if(fe(n)&&/dockito/i.test(Tn(n,"utf8")))return;if(!await Ce(`Add a Dockito note to ${Fe(n)} so AI agents know how to publish?`))return;wr(n,Ar),R(`${U("✓")} ${Fe(n)}`)}var Sr=!process.env.NO_COLOR&&process.stdout.isTTY,je=(e)=>(n)=>Sr?`\x1B[${e}m${n}\x1B[0m`:n,x=je("2"),pe=je("1"),M=je("32"),Be=je("31"),ft=je("33"),us=je("36"),O=(e="")=>process.stdout.write(e+`
|
|
37
|
-
`),W=(e="")=>process.stderr.write(e+`
|
|
38
|
-
`);class dt extends Error{}var N=(e)=>{throw new dt(e)},$e={view:"View",publish:"Publish",everything:"Everything"};function pt(e){let n=Math.round((Date.now()-new Date(e).getTime())/1000);if(n<60)return"just now";let r=Math.round(n/60);if(r<60)return`${r} min ago`;let t=Math.round(r/60);if(t<24)return`${t} h ago`;let s=Math.round(t/24);if(s<30)return s===1?"yesterday":`${s} days ago`;return new Date(e).toLocaleDateString(void 0,{day:"numeric",month:"short",year:"numeric"})}function Te(e){let n=(t)=>t.replace(/\x1b\[[0-9;]*m/g,""),r=e[0]?.map((t,s)=>Math.max(...e.map((o)=>n(o[s]??"").length)))??[];for(let t of e)O(t.map((s,o)=>o===t.length-1?s:s+" ".repeat(r[o]-n(s).length)).join(" ").trimEnd())}function Mt(e,n){switch(e.code){case"offline":return`Couldn't reach Dockito at ${n}.`;case"invalid_token":return"Your login has ended or was signed out. Run `dockito login`.";case"token_level":return`This needs ${$e[e.detail.needs]??e.detail.needs} access; this login has ${$e[e.detail.has]??e.detail.has}. Run \`dockito login --update\`.`;case"not_for_tokens":return"That can only be done in the browser.";case"not_found":return"Not found, or this login has no access to it. `dockito whoami` lists what it can reach.";case"deleted":return"That doc was deleted.";case"conflict":return"Someone published a newer version since yours. Get it with `dockito get`, or publish anyway with --force.";case"rate_limited":return"Too many requests. Try again in a minute.";case"too_large":return`The file is too large (limit ${Math.round(Number(e.detail.limit??0)/1048576)} MB).`;case"out_of_space":return"The workspace is out of storage.";case"unsupported":return"Dockito takes .md and .html files.";case"other_kind":return"That doc is a different kind of file (Markdown and HTML can't replace each other).";case"empty":return"The file is empty.";case"not_text":return"The file isn't text.";case"too_deep":return"Folders go at most 2 deep inside a project.";case"invalid_name":return"Names need 1 to 80 characters.";case"folder_gone":return"That project or folder no longer exists.";default:return`Dockito said: ${e.code}`}}import{existsSync as ps,mkdirSync as Nr,readFileSync as Er,writeFileSync as Ir}from"node:fs";import{homedir as _r}from"node:os";import{join as gt}from"node:path";var Rr="https://dockito-app.dockito.workers.dev";function xn(){if(process.env.DOCKITO_CONFIG_DIR)return process.env.DOCKITO_CONFIG_DIR;if(process.platform==="win32"&&process.env.APPDATA)return gt(process.env.APPDATA,"dockito");return gt(process.env.XDG_CONFIG_HOME||gt(_r(),".config"),"dockito")}var On=()=>gt(xn(),"state.json");function An(){try{return JSON.parse(Er(On(),"utf8"))}catch{return{}}}function Z(e){return An().sites?.[e]??{}}function mt(e,n){let r=An();r.sites??={};let t=r.sites[e]??={};n(t),Nr(xn(),{recursive:!0,mode:448}),Ir(On(),JSON.stringify(r,null,2)+`
|
|
39
|
-
`)}var Ln=()=>(process.env.DOCKITO_URL||Rr).replace(/\/+$/,""),Sn=(e)=>new URL(e).host;var Nn=(e,n,r,t)=>mt(e,(s)=>{if((s.entries??={})[n]=r,t)(s.hashes??={})[n]=t});import{spawnSync as Dr}from"node:child_process";import{chmodSync as Pr,existsSync as Vt,mkdirSync as Fr,readFileSync as Br,rmSync as En,writeFileSync as Ur}from"node:fs";import{dirname as Mr,join as Vr}from"node:path";var ve="dockito";function xe(e,n,r){try{let t=Dr(e,n,{input:r,encoding:"utf8",stdio:["pipe","pipe","pipe"]});return t.error?null:t}catch{return null}}var Ue=(e)=>Vr(tt(),"tokens",`${e.replace(/[^a-z0-9.-]/gi,"_")}`);function Wr(e,n){if(process.platform==="darwin"){let r=xe("security",["-i"],`add-generic-password -U -s ${ve} -a ${e} -l Dockito -w ${n}
|
|
40
|
-
`);return!!r&&r.status===0&&!/error/i.test(r.stderr??"")}if(process.platform==="linux"){let r=xe("secret-tool",["store","--label=Dockito","service",ve,"account",e],n);return!!r&&r.status===0}return!1}function Jr(e){let n=process.platform==="darwin"?xe("security",["find-generic-password","-s",ve,"-a",e,"-w"]):process.platform==="linux"?xe("secret-tool",["lookup","service",ve,"account",e]):null;return(n?.status===0?n.stdout.trim():"")||null}function Gr(e){if(process.platform==="darwin")xe("security",["delete-generic-password","-s",ve,"-a",e]);else if(process.platform==="linux")xe("secret-tool",["clear","service",ve,"account",e])}function In(e,n){if(Wr(e,n)){if(Vt(Ue(e)))En(Ue(e));return"keychain"}let r=Ue(e);return Fr(Mr(r),{recursive:!0,mode:448}),Ur(r,n,{mode:384}),Pr(r,384),"file"}function ht(e){if(process.env.DOCKITO_TOKEN)return process.env.DOCKITO_TOKEN.trim();let n=Jr(e);if(n)return n;let r=Ue(e);return Vt(r)?Br(r,"utf8").trim()||null:null}function _n(e){Gr(e);let n=Ue(e);if(Vt(n))En(n)}import{existsSync as zr,readFileSync as Dn,writeFileSync as Pn}from"node:fs";import{dirname as Rn,join as Fn,relative as Hr,resolve as Bn,sep as qr}from"node:path";var Me="dockito.jsonc";function C(e=process.cwd()){for(let n=Bn(e);;n=Rn(n)){let r=Fn(n,Me);if(zr(r)){let t=[],s=ot(Dn(r,"utf8"),t,{allowTrailingComma:!0});if(t.length||!s||typeof s!=="object")throw Error(`${r} isn't valid JSONC.`);return{file:r,dir:n,config:s}}if(Rn(n)===n)return null}}var wt=(e,n)=>Hr(e.dir,Bn(n)).split(qr).join("/");function Kr(e,n,r){let t=Dn(e.file,"utf8"),s=st(t,n,r,{formattingOptions:{insertSpaces:!0,tabSize:2}});Pn(e.file,it(t,s));let o=e.config;for(let c of n.slice(0,-1))o=o[c]??={};o[n[n.length-1]]=r}var Un=(e,n,r)=>Kr(e,["docs",wt(e,n)],r);function Mn(e,n){let r=["{"," // Where Dockito docs from this repo go. No secrets in this file."," // Run `dockito agent` to learn the CLI, `dockito tree` to see places.",` "workspace": ${JSON.stringify(n.workspace)},`,n.project?` "project": ${JSON.stringify(n.project)},`:' // "project": "my-project",',n.folder?` "folder": ${JSON.stringify(n.folder)},`:' // "folder": "Folder/Subfolder",',n.dir?` // \`dockito sync\` mirrors this folder into the project, subfolders as folders.
|
|
41
|
-
"dir": ${JSON.stringify(n.dir)},`:' // "dir": "docs",'," // Local files and the docs they publish to. Filled in by Dockito.",' "docs": {}',"}",""],t=Fn(e,Me);return Pn(t,r.join(`
|
|
42
|
-
`)),t}var zt="0.0.1-beta.2",_=Ln(),We=Sn(_),Ht=`dockito-cli/${zt} (${process.platform})`;function J(){let e=ht(We);if(!e)N("Not logged in. Run `dockito login`.");return Ye({url:_,token:e,source:"cli",userAgent:Ht})}function Jn(e){let[n,r]=process.platform==="darwin"?["open",[e]]:process.platform==="win32"?["cmd",["/c","start","",e]]:["xdg-open",[e]];try{let t=Yr(n,r,{stdio:"ignore",detached:!0});return t.on("error",()=>{}),t.unref(),!0}catch{return!1}}var ro=()=>!process.env.SSH_CONNECTION&&!process.env.CI&&(process.platform!=="linux"||!!process.env.DISPLAY||!!process.env.WAYLAND_DISPLAY),oo=(e)=>new Promise((n)=>setTimeout(n,e)),so=()=>eo().replace(/\.local$/,"").slice(0,60)||"Unknown device";function qt(e,n,r){let t=n??r?.config.workspace??Z(_).workspace;if(t){let o=e.workspaces.find((c)=>c.slug===t);if(!o)N(`This login can't reach workspace "${t}". \`dockito whoami\` lists the ones it can.`);return o}if(e.workspaces.length===1)return e.workspaces[0];let s=e.workspaces.find((o)=>o.kind==="personal"&&o.role==="owner");if(s)return s;return N(`Pick a workspace with --workspace, or set one with \`dockito switch\`: ${e.workspaces.map((o)=>o.slug).join(", ")}`)}async function Kt(e,n,r){if(!r)return{project:null,folder:null,label:""};let[t,...s]=r.split("/").filter(Boolean),o=await e.projects(n),c=o.find((f)=>f.slug===t)??o.find((f)=>f.name.toLowerCase()===t.toLowerCase());if(!c)return N(`No project "${t}". Projects: ${o.map((f)=>f.slug).join(", ")||"none"}`);let i=null,l=null;for(let f of s){let u=c.folders.find((p)=>p.parentId===i&&p.name.toLowerCase()===f.toLowerCase());if(!u)return N(`No folder "${f}" in ${c.slug}${i?" at that level":""}.`);l=i=u.id}return{project:c.id,folder:l,label:[c.slug,...s].join("/")}}var io=/^[a-z0-9]{12}$/;function Oe(e,n){let t=(/^https?:\/\//.test(e)?new URL(e).pathname.split("/").filter(Boolean).pop()??"":e).replace(/\.(md|html)$/,"");if(io.test(t)&&/\d/.test(t))return t;if(Jt(e)){let s=(n&&n.config.docs?.[wt(n,e)])??Z(_).files?.[Ve(e)];if(s)return s;N(`${e} hasn't been published yet. Run \`dockito publish ${e}\`.`)}return N(`"${e}" isn't a doc link, code or published file.`)}function Wt(e,n,r){if(e&&Ve(n).startsWith(e.dir))Un(e,n,r);else mt(_,(t)=>(t.files??={})[Ve(n)]=r)}var kt=(e,n,r)=>Nn(_,e,n,r&&Xr("sha256").update(r).digest("hex"));function co(e){let n=to(Ve(e)),r=Vn("git",["rev-parse","HEAD"],{cwd:n,encoding:"utf8"});if(r.error||r.status!==0)return null;let t=Vn("git",["status","--porcelain","--",Gt(e)],{cwd:n,encoding:"utf8"});if(t.status!==0||t.stdout.trim())return null;return r.stdout.trim()}async function lo(e){let n=ht(We);if(e.update&&!n)N("Not logged in. Run `dockito login` first.");if(process.env.DOCKITO_TOKEN)W(ft("DOCKITO_TOKEN is set, so commands will keep using it instead of this login."));let r=Ye({url:_,token:e.update?n:null,userAgent:Ht}),t=await r.startLogin("Dockito CLI",so()),s=!e["no-browser"]&&ro()&&Jn(t.verification_uri_complete);O(s?`Opening ${t.verification_uri_complete}`:`Open ${pe(t.verification_uri)}`),O(`Code: ${pe(t.user_code)}`),W(x("Waiting for approval\u2026"));let o=t.interval*1000,c=Date.now()+t.expires_in*1000;while(Date.now()<c){await oo(o);try{let i=await r.pollLogin(t.device_code);if(!i)continue;let l=In(We,i.token);O(`${M("\u2713")} Logged in as ${i.user.name}${i.user.username?x(` (${i.user.username})`):""}`);for(let f of i.workspaces)O(` ${f.name} ${x(`${f.slug} \xB7 ${$e[f.level]}`)}`);if(l==="file")W(ft("No keychain found, so the token is in a file only you can read, in ~/.config/dockito."));return}catch(i){if(i instanceof K&&i.code==="access_denied")N("Denied in the browser.");if(i instanceof K&&i.code==="expired_token")N("The code expired. Run `dockito login` again.");if(i instanceof K&&i.code==="offline"){o=Math.min(o*2,30000);continue}throw i}}N("The code expired. Run `dockito login` again.")}async function ao(){let e=ht(We);if(!e)return O("Not logged in.");if(process.env.DOCKITO_TOKEN)N("DOCKITO_TOKEN is set; unset it or revoke that token in Account \u2192 Tokens.");try{await Ye({url:_,token:e,userAgent:Ht}).logout()}catch(n){if(!(n instanceof K)||n.code!=="invalid_token"&&n.code!=="not_found")throw n}_n(We),O(`${M("\u2713")} Logged out`)}async function uo(e){let n=await J().whoami();if(e.json)return O(JSON.stringify(n,null,2));let r=Z(_).workspace;if(O(`${n.user.name} ${x(`${n.user.username} \xB7 ${n.user.email}`)}`),n.token)O(x(`${n.token.name} \xB7 ${n.token.source==="cli"?"ends after 90 days without use":`expires ${new Date(n.token.expiresAt).toLocaleDateString()}`}`));if(O(),Te(n.workspaces.map((t)=>[t.slug===r?M("\u25CF"):" ",t.slug,t.name,x(t.level?$e[t.level]:t.role)])),_!=="https://dockito-app.dockito.workers.dev")W(x(`
|
|
43
|
-
${_}`))}async function fo(e){let n=await J().whoami();if(!e){let t=Z(_).workspace;return Te(n.workspaces.map((s)=>[s.slug===t?M("\u25CF"):" ",s.slug,s.name]))}let r=n.workspaces.find((t)=>t.slug===e);if(!r)N(`This login can't reach "${e}": ${n.workspaces.map((t)=>t.slug).join(", ")}`);mt(_,(t)=>t.workspace=r.slug),O(`${M("\u2713")} Commands now use ${r.name} ${x(r.slug)}`)}async function po(e){if(Jt(Me))N(`${Me} is already here.`);let n=J(),r=await n.whoami(),t=qt(r,e.workspace,null),[s,...o]=(e.to??"").split("/").filter(Boolean);if(s)await Kt(n,t.id,e.to);let c=Mn(process.cwd(),{workspace:t.slug,project:s,folder:o.join("/")||void 0});O(`${M("\u2713")} Wrote ${Gt(c)} ${x(`\u2192 ${[t.slug,s,...o].filter(Boolean).join("/")}`)}`)}async function go(e,n){if(!e.length)N("Name a file: `dockito publish notes.md`");if(n.doc&&e.length>1)N("--doc takes one file.");for(let i of e)if(!Jt(i)||!Zr(i).isFile())N(`${i} isn't a file.`);let r=J(),t=C(),s=null,o=[],c="";for(let i of e){let l=new Uint8Array(Qr(i)),f=Gt(i),u=n.new?null:n.doc?Oe(n.doc,t):(t&&t.config.docs?.[wt(t,i)])??Z(_).files?.[Ve(i)]??null,p=co(i);if(u){let T;try{T=await r.doc(u)}catch(m){if(m instanceof K&&(m.code==="deleted"||m.code==="not_found"))N(`${i} was published to ${r.linkOf(u)}, which ${m.code==="deleted"?"was deleted":"this login can't reach"}. Publish it as a new doc with --new.`);throw m}let P=n.force?null:Z(_).entries?.[T.doc.id]??null,L=await r.update(T.doc.id,f,l,{note:n.message,commit:p,base:P});if(kt(L.id,L.version,l),n.doc)Wt(t,i,L.slug);if(o.push({file:i,...L,link:r.linkOf(L.slug)}),!n.json)O(L.unchanged?`${x("=")} ${i} ${x("unchanged")} ${r.linkOf(L.slug)}`:`${M("\u2713")} ${i} \u2192 ${r.linkOf(L.slug)}${n.message?x(` \xB7 saved: ${n.message}`):""}`);continue}s??=await r.whoami();let g=qt(s,n.workspace,t),v=n.to??(t&&g.slug===t.config.workspace&&t.config.project?[t.config.project,t.config.folder].filter(Boolean).join("/"):void 0),A=await Kt(r,g.id,v),j=await r.create(g.id,f,l,{project:A.project,folder:A.folder});if(n.message)await r.save(j.id,j.version,n.message);if(kt(j.id,j.version,l),Wt(t,i,j.slug),o.push({file:i,...j,link:r.linkOf(j.slug),new:!0}),!n.json)O(`${M("\u2713")} ${i} \u2192 ${r.linkOf(j.slug)} ${x(`new in ${[g.slug,A.label||"Docs"].join("/")}`)}${n.message?x(` \xB7 saved: ${n.message}`):""}`);if(!v)c=t?.config.dir?"`dockito sync` puts files from "+t.config.dir+"/ in their folders.":"In the workspace's Docs. To put docs in a project: --to <project>; `dockito tree` lists them."}if(c&&!n.json)W(x(c));if(n.json)O(JSON.stringify(o,null,2))}async function mo(e,n){let r=J(),t=await r.whoami(),s=qt(t,n.workspace,C()),o=await Kt(r,s.id,e),[c,i]=await Promise.all([r.docs(s.id,{project:o.project,folder:o.folder}),e?Promise.resolve([]):r.projects(s.id)]),l=e?(await r.projects(s.id)).find((u)=>u.id===o.project)?.folders.filter((u)=>u.parentId===o.folder)??[]:[];if(n.json)return O(JSON.stringify({workspace:s.slug,place:o.label||null,projects:i,folders:l,docs:c},null,2));let f=[];for(let u of i)f.push([pe(`${u.slug}/`),u.name,x(`${u.docs} doc${u.docs===1?"":"s"}`),""]);for(let u of l)f.push([pe(`${u.name}/`),"",x(`${u.docs} doc${u.docs===1?"":"s"}`),""]);for(let u of c)f.push([u.slug,u.title+x(u.kind==="html"?" .html":" .md"),x(pt(u.updatedAt)),x(u.updatedByName??"")]);if(!f.length)return W(x(`Nothing in ${[s.slug,o.label].filter(Boolean).join("/")} yet.`));Te(f)}async function ho(e){if(!e)N("Name a doc: `dockito open <link, code or file>`");let n=`${_}/${Oe(e,C())}`;if(!Jn(n))O(n)}async function wo(e,n){if(!e)N("Name a doc: `dockito get <link, code or file> [-o file]`");let r=J(),t=C(),s=await r.doc(Oe(e,t)),o=n.entry?Number(n.entry):null;if(n.entry&&(!Number.isInteger(o)||o<1))N("--entry takes an entry number from `dockito history`.");let{bytes:c,entry:i}=await r.content(s.doc.id,o);if(!o)kt(s.doc.id,i,c);if(!n.output)return void process.stdout.write(c);if(Cr(n.output,c),!o)Wt(t,n.output,s.doc.slug);W(`${M("\u2713")} ${n.output} ${x(`\u2190 ${r.linkOf(s.doc.slug)}${o?` entry ${o}`:""}`)}`)}async function ko(e,n){if(!e)N("Name a doc: `dockito history <link, code or file>`");let r=await J().doc(Oe(e,C()));if(n.json)return O(JSON.stringify(r.versions,null,2));O(`${pe(r.doc.title)} ${x(`${_}/${r.doc.slug}`)}`),Te(r.versions.map((t,s)=>[String(t.number),s===0?M("current"):x(pt(t.createdAt)),s===0?x(pt(t.createdAt)):"",t.byName??"",x(t.source),t.savedAt?`${ft("saved")}${t.note?` ${t.note}`:""}`:"",t.gitCommit?x(t.gitCommit.slice(0,7)):""]))}async function yo(e,n){let r=Number(n);if(!e||!Number.isInteger(r)||r<1)N("`dockito restore <doc> <entry>`; entries are in `dockito history`.");let t=J(),s=await t.doc(Oe(e,C())),o=Z(_).entries?.[s.doc.id]??s.versions[0]?.number??null,c=await t.restore(s.doc.id,r,o);kt(c.id,c.version),O(`${M("\u2713")} Restored entry ${r} as entry ${c.version} ${x(t.linkOf(c.slug))}`)}async function bo(e,n,r){if(!e)N('`dockito save <doc> [entry] -m "note"`');let t=J(),s=await t.doc(Oe(e,C())),o=n?Number(n):s.versions[0]?.number;if(!Number.isInteger(o)||o<1)N("Entries are in `dockito history`.");await t.save(s.doc.id,o,r.message??null),O(`${M("\u2713")} Saved entry ${o}${r.message?x(` \xB7 ${r.message}`):""}`)}async function $o(e){let n=await J().tree();if(e.json)return O(JSON.stringify(n,null,2));let r=n.workspaces,t=Z(_).workspace;for(let s of r){let o=(i)=>x(`${i} doc${i===1?"":"s"}`);O(`${s.slug===t?M("\u25CF"):" "} ${pe(s.slug)} ${s.name} ${x(`\xB7 ${s.level?$e[s.level]:s.role}`)}`);let c=[[x("Docs"),"",o(s.docs)]];for(let i of s.projects){c.push([i.slug,i.name,o(i.docs)]);let l=(f,u)=>{for(let p of i.folders.filter((g)=>g.parentId===f))c.push([`${u}/${p.name}`,"",o(p.docs)]),l(p.id,`${u}/${p.name}`)};l(null,i.slug)}Te(c.map((i)=>[" ",...i])),O()}W(x("Publish into a place: dockito publish <file> -w <workspace> --to <project/folder>"))}async function jo(e,n){let[r,...t]=(e??"").split("/").filter(Boolean);if(!r)N("`dockito mkdir <project>[/folder[/subfolder]]`");if(t.length>2)N("Folders go at most 2 deep inside a project.");let s=J(),{workspaces:o}=await s.tree(),c=n.workspace??C()?.config.workspace??Z(_).workspace,i=c?o.find((g)=>g.slug===c):o.length===1?o[0]:o.find((g)=>g.kind==="personal"&&g.role==="owner")??null;if(!i)return N(c?`This login can't reach workspace "${c}".`:`Pick a workspace with -w: ${o.map((g)=>g.slug).join(", ")}`);let l=i.projects.find((g)=>g.slug===r)??i.projects.find((g)=>g.name.toLowerCase()===r.toLowerCase()),f=l?.id;if(!f){let g=await s.createProject(i.id,r);f=g.id,O(`${M("\u2713")} Project ${r} ${x(`${i.slug}/${g.slug}`)}`)}let u=null,p=!l;for(let g of t){let v=l?.folders.find((A)=>A.parentId===u&&A.name.toLowerCase()===g.toLowerCase());if(v){u=v.id;continue}u=(await s.createFolder(f,g,u)).id,l=void 0,p=!0,O(`${M("\u2713")} Folder ${g}`)}if(!p)W(x("Already there."))}var Gn=`Dockito hosts Markdown and HTML docs at a short link, with History.
|
|
2
|
+
import{spawn as Bt,spawnSync as ct}from"node:child_process";import{createHash as Ht}from"node:crypto";import{existsSync as Jt,readFileSync as at,statSync as Gt,writeFileSync as zt}from"node:fs";import{hostname as qt}from"node:os";import{basename as Ce,dirname as Vt,resolve as Yt}from"node:path";import{parseArgs as Xt}from"node:util";var v=class extends Error{constructor(t,o,s={}){super(t);this.code=t;this.status=o;this.detail=s}code;status;detail};function pe(e){let n=e.url.replace(/\/+$/,"");async function t(r,c,a={}){let f=new URL(`${n}/api${c}`);for(let[x,$]of Object.entries(a.query??{}))$!=null&&$!==""&&f.searchParams.set(x,String($));let h={},g=a.token===void 0?e.token:a.token;g&&(h.authorization=`Bearer ${g}`),e.userAgent&&(h["user-agent"]=e.userAgent);let d;a.json!==void 0?(h["content-type"]="application/json",d=JSON.stringify(a.json)):a.body&&(h["content-type"]="application/octet-stream",d=a.body);let y;try{y=await fetch(f,{method:r,headers:h,body:d})}catch{throw new v("offline",0)}return y}async function o(r){let c=await r.json().catch(()=>({}));if(!r.ok){let{error:a,...f}=c;throw new v(typeof a=="string"?a:`http_${r.status}`,r.status,f)}return c}let s=encodeURIComponent;return{url:n,linkOf:r=>`${n}/${r}`,startLogin:async(r,c)=>o(await t("POST","/device/code",{json:{client:r,device:c}})),pollLogin:async r=>{let c=await t("POST","/device/token",{json:{device_code:r},token:null}),a=await c.json().catch(()=>({}));if(c.ok)return a;if(a.error==="authorization_pending"||a.error==="slow_down")return null;throw new v(a.error??`http_${c.status}`,c.status)},logout:async()=>o(await t("DELETE","/tokens/current")),whoami:async()=>o(await t("GET","/whoami")),tree:async()=>o(await t("GET","/tree")),projects:async r=>(await o(await t("GET",`/workspaces/${s(r)}/projects`))).projects,docs:async(r,c={})=>(await o(await t("GET",`/workspaces/${s(r)}/docs`,{query:c}))).docs,files:async(r,c)=>(await o(await t("GET",`/workspaces/${s(r)}/files`,{query:{project:c}}))).docs,createProject:async(r,c)=>o(await t("POST",`/workspaces/${s(r)}/projects`,{json:{name:c}})),createFolder:async(r,c,a)=>o(await t("POST",`/projects/${s(r)}/folders`,{json:{name:c,parentId:a}})),recent:async r=>(await o(await t("GET",`/workspaces/${s(r)}/docs/recent`))).docs,doc:async r=>o(await t("GET",`/docs/by-code/${s(r)}`)),content:async(r,c)=>{let a=await t("GET",`/docs/${s(r)}/content`,{query:{v:c}});return a.ok||await o(a),{bytes:new Uint8Array(await a.arrayBuffer()),entry:Number(a.headers.get("x-doc-version"))}},create:async(r,c,a,f={})=>o(await t("POST",`/workspaces/${s(r)}/docs`,{query:{name:c,...f,source:e.source},body:a})),update:async(r,c,a,f={})=>o(await t("POST",`/docs/${s(r)}/versions`,{query:{name:c,note:f.note,commit:f.commit,base:f.base,source:e.source},body:a})),restore:async(r,c,a)=>o(await t("POST",`/docs/${s(r)}/history/${c}/restore`,{query:{base:a}})),save:async(r,c,a)=>o(await t("PUT",`/docs/${s(r)}/history/${c}/saved`,{json:{note:a}})),rename:async(r,c)=>o(await t("PATCH",`/docs/${s(r)}`,{json:{title:c}}))}}import{emitKeypressEvents as wt}from"node:readline";import{createInterface as yt}from"node:readline/promises";var ht=!process.env.NO_COLOR&&process.stdout.isTTY,W=e=>n=>ht?`\x1B[${e}m${n}\x1B[0m`:n,p=W("2"),T=W("1"),k=W("32"),A=W("31"),E=W("33"),De=W("36"),u=(e="")=>process.stdout.write(e+`
|
|
3
|
+
`),b=(e="")=>process.stderr.write(e+`
|
|
4
|
+
`),K=class extends Error{},w=e=>{throw new K(e)},U={view:"View",publish:"Publish",everything:"Everything"};function fe(e){let n=Math.round((Date.now()-new Date(e).getTime())/1e3);if(n<60)return"just now";let t=Math.round(n/60);if(t<60)return`${t} min ago`;let o=Math.round(t/60);if(o<24)return`${o} h ago`;let s=Math.round(o/24);return s<30?s===1?"yesterday":`${s} days ago`:new Date(e).toLocaleDateString(void 0,{day:"numeric",month:"short",year:"numeric"})}function Q(e){let n=o=>o.replace(/\x1b\[[0-9;]*m/g,""),t=e[0]?.map((o,s)=>Math.max(...e.map(r=>n(r[s]??"").length)))??[];for(let o of e)u(o.map((s,r)=>r===o.length-1?s:s+" ".repeat(t[r]-n(s).length)).join(" ").trimEnd())}function Z(e,n){switch(e.code){case"offline":return`Couldn't reach Dockito at ${n}.`;case"invalid_token":return"Your login has ended or was signed out. Run `dockito login`.";case"token_level":return`This needs ${U[e.detail.needs]??e.detail.needs} access; this login has ${U[e.detail.has]??e.detail.has}. Run \`dockito login --update\`.`;case"not_for_tokens":return"That can only be done in the browser.";case"not_found":return"Not found, or this login has no access to it. `dockito whoami` lists what it can reach.";case"deleted":return"That doc was deleted.";case"conflict":return"Someone published a newer version since yours. Get it with `dockito get`, or publish anyway with --force.";case"rate_limited":return"Too many requests. Try again in a minute.";case"too_large":return`The file is too large (limit ${Math.round(Number(e.detail.limit??0)/1048576)} MB).`;case"out_of_space":return"The workspace is out of storage.";case"unsupported":return"Dockito takes .md and .html files.";case"other_kind":return"That doc is a different kind of file (Markdown and HTML can't replace each other).";case"empty":return"The file is empty.";case"not_text":return"The file isn't text.";case"too_deep":return"Folders go at most 2 deep inside a project.";case"invalid_name":return"Names need 1 to 80 characters.";case"folder_gone":return"That project or folder no longer exists.";default:return`Dockito said: ${e.code}`}}var Ne=()=>!!process.stdin.isTTY&&!!process.stdout.isTTY&&!process.env.CI,B=e=>process.stdout.write(e);function Ve(e,n,t=0){return new Promise((o,s)=>{let r=t,c=h=>{h||B(`\x1B[${n.length}A`);for(let[g,d]of n.entries())B(`\x1B[2K${g===r?De("\u276F "+d.label):" "+d.label}${d.hint?p(" "+d.hint):""}
|
|
5
|
+
`)};B(`${k("?")} ${T(e)} ${p("(\u2191\u2193, Enter)")}
|
|
6
|
+
\x1B[?25l`),c(!0),wt(process.stdin),process.stdin.setRawMode(!0),process.stdin.resume();let a=()=>{process.stdin.off("keypress",f),process.stdin.setRawMode(!1),process.stdin.pause(),B("\x1B[?25h")},f=(h,g)=>{if(g.ctrl&&g.name==="c")return a(),B(`
|
|
7
|
+
`),s(new ee);if(g.name==="up"||g.name==="k")r=(r-1+n.length)%n.length;else if(g.name==="down"||g.name==="j")r=(r+1)%n.length;else return g.name==="return"?(a(),B(`\x1B[${n.length+1}A\x1B[0J${k("?")} ${T(e)} ${De(n[r].label)}
|
|
8
|
+
`),o(r)):void 0;c(!1)};process.stdin.on("keypress",f)})}async function ge(e,n=""){let t=yt({input:process.stdin,output:process.stdout});try{return(await t.question(`${k("?")} ${T(e)}${n?p(` (${n})`):""} `)).trim()||n}finally{t.close()}}async function Se(e,n=!0){let t=(await ge(`${e} ${p(n?"[Y/n]":"[y/N]")}`)).toLowerCase();return t?t.startsWith("y"):n}var ee=class extends Error{};import{homedir as kt}from"node:os";import{join as _e}from"node:path";var $t="https://dockito-app.dockito.workers.dev";function Ye(){return process.env.DOCKITO_CONFIG_DIR?process.env.DOCKITO_CONFIG_DIR:process.platform==="win32"&&process.env.APPDATA?_e(process.env.APPDATA,"dockito"):_e(process.env.XDG_CONFIG_HOME||_e(kt(),".config"),"dockito")}var Xe=()=>(process.env.DOCKITO_URL||$t).replace(/\/+$/,""),Qe=e=>new URL(e).host;import{spawnSync as bt}from"node:child_process";import{chmodSync as jt,existsSync as Pe,mkdirSync as vt,readFileSync as xt,rmSync as Ze,writeFileSync as Tt}from"node:fs";import{dirname as Ot,join as Dt}from"node:path";var H="dockito";function J(e,n,t){try{let o=bt(e,n,{input:t,encoding:"utf8",stdio:["pipe","pipe","pipe"]});return o.error?null:o}catch{return null}}var te=e=>Dt(Ye(),"tokens",`${e.replace(/[^a-z0-9.-]/gi,"_")}`);function Nt(e,n){if(process.platform==="darwin"){let t=J("security",["-i"],`add-generic-password -U -s ${H} -a ${e} -l Dockito -w ${n}
|
|
9
|
+
`);return!!t&&t.status===0&&!/error/i.test(t.stderr??"")}if(process.platform==="linux"){let t=J("secret-tool",["store","--label=Dockito","service",H,"account",e],n);return!!t&&t.status===0}return!1}function St(e){let n=process.platform==="darwin"?J("security",["find-generic-password","-s",H,"-a",e,"-w"]):process.platform==="linux"?J("secret-tool",["lookup","service",H,"account",e]):null;return(n?.status===0?n.stdout.trim():"")||null}function _t(e){process.platform==="darwin"?J("security",["delete-generic-password","-s",H,"-a",e]):process.platform==="linux"&&J("secret-tool",["clear","service",H,"account",e])}function et(e,n){if(Nt(e,n))return Pe(te(e))&&Ze(te(e)),"keychain";let t=te(e);return vt(Ot(t),{recursive:!0,mode:448}),Tt(t,n,{mode:384}),jt(t,384),"file"}function me(e){if(process.env.DOCKITO_TOKEN)return process.env.DOCKITO_TOKEN.trim();let n=St(e);if(n)return n;let t=te(e);return Pe(t)&&xt(t,"utf8").trim()||null}function tt(e){_t(e);let n=te(e);Pe(n)&&Ze(n)}var D=class extends Error{constructor(t,o,s={}){super(o);this.code=t;this.data=s}code;data},L=e=>e.level===null||e.level==="publish"||e.level==="everything";function he(e,n){let t=e.workspaces;if(n)return t.find(s=>s.slug===n)??w(`This login can't reach workspace "${n}". \`dockito tree\` lists the ones it can.`);let o=t.length===1?t[0]:t.find(s=>s.kind==="personal"&&s.role==="owner");if(o)return o;throw new D("needs_workspace",`Pick a workspace with -w: ${t.map(s=>s.slug).join(", ")}`,{workspaces:t.map(s=>s.slug)})}var G=(e,n)=>e.projects.find(t=>t.slug===n)??e.projects.find(t=>t.name.toLowerCase()===n.toLowerCase())??null;function ne(e){let n=new Map((e?.folders??[]).map(s=>[s.id,s])),t=s=>{let r=n.get(s);return[...r.parentId?t(r.parentId):[],r.name]},o=new Map((e?.folders??[]).map(s=>[t(s.id).join("/").toLowerCase(),s.id]));return{idOf:s=>s.length?o.get(s.join("/").toLowerCase()):null,pathOf:s=>s&&n.has(s)?t(s):[],add:(s,r)=>{o.set(s.join("/").toLowerCase(),r)}}}function Ae(e,n){if(!n)return{project:null,folder:null,label:`${e.slug} Docs`};let[t,...o]=n.split("/").filter(Boolean),s=G(e,t);if(!s)return w(`No project "${t}" in ${e.slug}. \`dockito tree\` lists them; \`dockito mkdir ${n}\` makes it.`);let r=ne(s).idOf(o);return r===void 0?w(`No folder "${o.join("/")}" in ${s.slug}. \`dockito mkdir ${s.slug}/${o.join("/")}\` makes it.`):{project:s.id,folder:r,label:[e.slug,s.slug,...o].join("/")}}var Pt=e=>e.fileName??`${e.title}.${e.kind}`,we=(e,n,t)=>e.filter(o=>(o.folderId??null)===n&&Pt(o).toLowerCase()===t.toLowerCase());import{createHash as At}from"node:crypto";import{spawnSync as Et}from"node:child_process";import{existsSync as re,readFileSync as Ct,readdirSync as It,statSync as rt}from"node:fs";import{basename as nt,join as C,relative as Lt,resolve as Ee,sep as Ft}from"node:path";var ye=2,Rt=4,oe=e=>e<1024*1024?`${e?Math.max(1,Math.round(e/1024)):0} KB`:`${(e/1048576).toFixed(1)} MB`,Mt=e=>At("sha256").update(e).digest("hex"),st=e=>e.split(Ft).join("/"),z=(e,n)=>`${e} ${n}${e===1?"":"s"}`,Kt=(e,n)=>{let t=/\.[^./]+$/.exec(n.toLowerCase())?.[0]??"";return e.find(o=>o.extensions.includes(t))?.id??null};function ke(e,n){let t=Et("git",e,{cwd:n,encoding:"utf8",maxBuffer:67108864});return t.error||t.status!==0?null:t.stdout}function Ut(e,n){let t=ke(["ls-files","-z","--cached","--others","--exclude-standard","--","."],e);return(t!==null?t.split("\0").filter(Boolean):(function s(r){return It(C(e,r),{withFileTypes:!0}).flatMap(c=>c.name.startsWith(".")||c.name==="node_modules"?[]:c.isDirectory()?s(C(r,c.name)):[st(C(r,c.name))])})("")).filter(s=>n(s)&&re(C(e,s))&&rt(C(e,s)).isFile()).sort()}function Wt(e,n,t){let o=[...e.matchAll(/\b(?:src|href)=["']([^"'#?]+)/gi)].map(s=>s[1]);return[...new Set(o.filter(s=>!/^([a-z]+:|\/\/|\/)/i.test(s)&&!t(s)&&re(C(n,s))))]}function ot(e,n){let t=(r,c,a="")=>`dockito sync ${n} -w ${r} --to ${c}${a}`,o=e.workspaces.filter(L).flatMap(r=>[...r.projects.map(c=>({workspace:r.slug,project:c.slug,name:c.name,docs:c.docs,command:t(r.slug,c.slug)})),{workspace:r.slug,project:null,name:"a new project",docs:0,command:t(r.slug,"<name>"," --create")}]),s=Math.max(...o.map(r=>r.command.length));throw new D("needs_place",[`Which project should ${n==="."?"this folder":n+"/"} go to? Ask the user, then run one of:`,...o.map(r=>` ${r.command.padEnd(s)} ${p(r.project?`${r.name} \xB7 ${z(r.docs,"doc")}`:r.name)}`),p("Subfolders become folders. `dockito tree` shows every place.")].join(`
|
|
10
|
+
`),{choices:o})}async function it(e,n,t){let o=Ne()&&!t.json,s=await e.tree(),r=i=>!!Kt(s.kinds,i);s.workspaces.some(L)||w("This login can't publish anywhere. Run `dockito login --update`.");let c=n;c||(o||ot(s,re("docs")?"docs":"."),c=await ge("Folder to sync",re("docs")?"docs":"."));let a=Ee(c);(!re(a)||!rt(a).isDirectory())&&w(`${c} isn't a folder.`);let f=st(Lt(process.cwd(),a))||".",h;t.workspace&&(h=s.workspaces.find(i=>i.slug===t.workspace)??w(`This login can't reach workspace "${t.workspace}".`));let g=t.to;if(!g){o||ot(s,f);let i=(h?[h]:s.workspaces.filter(L)).flatMap(m=>[...m.projects.map(j=>({w:m,p:j.slug,label:j.name,hint:`${m.slug} \xB7 ${z(j.docs,"doc")}`})),{w:m,p:null,label:"New project",hint:m.slug}]),l=i[await Ve("Project",i)];h=l.w,g=l.p??await ge("Project name",nt(a===process.cwd()?a:Ee(a,".."))),t.create||=!l.p}if(!h){let i=s.workspaces.filter(m=>L(m)&&G(m,g.split("/")[0])),l=s.workspaces.find(m=>m.kind==="personal"&&m.role==="owner");if(h=i.length===1?i[0]:s.workspaces.length===1?s.workspaces[0]:!i.length&&l?l:void 0,!h)throw new D("needs_workspace",`Which workspace? Run again with -w: ${(i.length?i:s.workspaces).map(m=>m.slug).join(", ")}`)}let d=h;L(d)||w(`This login has View access in ${d.slug}; syncing needs Publish. Run \`dockito login --update\`.`);let[y,...x]=g.split("/").filter(Boolean);y||w("--to takes a project, or project/folder."),x.length>ye&&w(`Folders go at most ${ye} deep inside a project.`);let $=G(d,y);if(!$&&!t.create)throw new D("no_project",`No project "${y}" in ${d.slug}. Projects: ${d.projects.map(i=>i.slug).join(", ")||"none"}.
|
|
11
|
+
To make it, run again with --create.`,{workspace:d.slug,projects:d.projects.map(i=>i.slug)});let ie=Ut(a,r);ie.length||w(`No ${s.kinds.flatMap(i=>i.extensions).join(", ")} files in ${f}.`);let ce=ye-x.length,V=ie.filter(i=>i.split("/").length-1>ce);if(V.length&&!t.fold){let i=m=>m.split("/").slice(0,ce).join("/")||"the project's top",l=`${z(V.length,"file")} ${V.length===1?"is":"are"} more than ${ye} folders deep inside the project. With --fold they go in ${[...new Set(V.map(i))].join(", ")}; where two would share a name, the folders left out go in front (plans/archive/grok/README.md \u2192 grok-README.md).`;if(!o)throw new D("too_deep",`${l}
|
|
12
|
+
Ask the user, then run again with --fold.`,{files:V});if(b(l),!await Se("Fold them like that?"))return b(p("Nothing changed."));t.fold=!0}let Fe=i=>{let l=i.split("/");return{folder:[...x,...l.slice(0,-1).slice(0,ce)],dropped:l.slice(0,-1).slice(ce),file:l[l.length-1]}},$e=new Map;for(let i of ie){let l=Fe(i),m=[...l.folder,l.file].join("/").toLowerCase();$e.set(m,($e.get(m)??0)+1)}let Re=$?await e.files(d.id,$.id):[],Y=ne($),F=ie.map(i=>{let{folder:l,dropped:m,file:j}=Fe(i),I=m.length&&$e.get([...l,j].join("/").toLowerCase())>1?[...m,j].join("-"):j,N=new Uint8Array(Ct(C(a,i))),M={rel:i,name:I,folder:l,bytes:N,hash:Mt(N),action:"new",doc:null,others:[],assets:[]};/\.html?$/i.test(i)&&(M.assets=Wt(new TextDecoder().decode(N),C(a,i,".."),r));let qe=Y.idOf(l);if(qe===void 0)return M;let X=we(Re,qe,I);return X.length>1?{...M,action:"ambiguous",others:X}:X.length?{...M,doc:X[0],action:X[0].sha256===M.hash?"same":"update"}:M}),Me=F.filter(i=>i.bytes.length>d.maxFile);Me.length&&w(`Over the ${oe(d.maxFile)} limit per file in ${d.slug}:
|
|
13
|
+
${Me.map(i=>` ${i.rel} ${oe(i.bytes.length)}`).join(`
|
|
14
|
+
`)}`);let be=new Map;for(let i of F){let l=[...i.folder,i.name].join("/").toLowerCase();be.set(l,[...be.get(l)??[],i.rel])}let Ke=[...be.values()].filter(i=>i.length>1);Ke.length&&w(`These files would be the same doc; rename one of each:
|
|
15
|
+
${Ke.map(i=>" "+i.join(" and ")).join(`
|
|
16
|
+
`)}`);let P=[],Ue=new Set;for(let i of F)for(let l=1;l<=i.folder.length;l++){let m=i.folder.slice(0,l),j=m.join("/").toLowerCase();Y.idOf(m)===void 0&&!Ue.has(j)&&(Ue.add(j),P.push(m))}P.sort((i,l)=>i.length-l.length);let O=F.filter(i=>i.action==="new"||i.action==="update"),We=F.filter(i=>i.action==="ambiguous"),je=F.filter(i=>i.action==="same").length,pt=new Set(F.flatMap(i=>i.doc?[i.doc.id]:i.others.map(l=>l.id))),ve=Re.filter(i=>!pt.has(i.id)).length,Be=`${d.slug}/${$?.slug??y}${x.length?"/"+x.join("/"):""}`,ae={workspace:d.slug,to:Be,create:{project:$?null:y,folders:P.map(i=>i.join("/"))},docs:O.map(i=>({file:i.rel,action:i.action,folder:i.folder.join("/")||null,name:i.name,link:i.doc?e.linkOf(i.doc.slug):null})),unchanged:je,ambiguous:We.map(i=>({file:i.rel,docs:i.others.map(l=>e.linkOf(l.slug))})),notHere:ve};if(!t.json){u(`${T(f==="."?"./":f+"/")} \u2192 ${T(Be)}`),$||u(` ${k("+ project")} ${y}`);for(let l of P)u(` ${k("+ folder ")} ${l.join("/")}`);if(O.length>15)for(let[l,m]of[["new",k("+ new ")],["update",E("~ update ")]]){let j=new Map;for(let I of O.filter(N=>N.action===l))j.set(I.folder.join("/"),[...j.get(I.folder.join("/"))??[],I.name]);for(let[I,N]of j)u(` ${m} ${N.length} in ${I||"the project's top"}: ${p(N.slice(0,4).join(", ")+(N.length>4?`, ${N.length-4} more`:""))}`)}else for(let l of O){let m=l.name!==nt(l.rel)?p(` \u2192 ${[...l.folder,l.name].join("/")}`):"";u(` ${l.action==="new"?k("+ new "):E("~ update ")} ${l.rel}${m}`)}je&&u(p(` ${je} unchanged`));for(let l of We)u(` ${A("? skip ")} ${l.rel} ${p(`${l.others.length} docs there have this name: ${l.others.map(m=>e.linkOf(m.slug)).join(", ")}`)}`);ve&&u(p(` ${z(ve,"doc")} in the project with no file here, left as they are`)),O.length&&u(p(` ${z(O.length,"file")} to send, ${oe(O.reduce((l,m)=>l+m.bytes.length,0))}`));let i=O.filter(l=>l.assets.length);i.length&&u(E(` ! ${i.length===1?i[0].rel:`${i.length} HTML files`} load ${[...new Set(i.flatMap(l=>l.assets))].join(", ")} from next to ${i.length===1?"it":"them"}; only HTML files are published`))}if(!O.length&&$&&!P.length){t.json?u(JSON.stringify({...ae,applied:!0},null,2)):u(`${k("\u2713")} Up to date`);return}if(t["dry-run"]){t.json&&u(JSON.stringify({...ae,applied:!1},null,2));return}if((!$||P.length)&&!t.yes){let i=["dockito sync",f,`-w ${d.slug}`,`--to ${g}`,t.create&&!$?"--create":"",t.fold?"--fold":"","--yes"].filter(Boolean).join(" ");if(!o){if(t.json)return u(JSON.stringify({...ae,applied:!1,next:i},null,2));throw new D("confirm",`
|
|
17
|
+
Nothing changed yet. Show the user this plan, then run: ${i}`,{next:i})}if(!await Se("Apply?"))return b(p("Nothing changed."))}if(!$){let i=await e.createProject(d.id,y);$={id:i.id,slug:i.slug,name:y,docs:0,folders:[]},t.json||u(`${k("\u2713")} Project ${y}`)}let xe=$;for(let i of P){let l=await e.createFolder(xe.id,i[i.length-1],i.length>1?Y.idOf(i.slice(0,-1)):null);Y.add(i,l.id)}P.length&&!t.json&&u(`${k("\u2713")} ${z(P.length,"folder")}`);let le=ke(["rev-parse","--show-toplevel"],a)?.trim()??null,He=le?ke(["rev-parse","HEAD"],le)?.trim()??null:null,ft=new Set(le?(ke(["status","--porcelain","-z","--","."],a)??"").split("\0").filter(Boolean).map(i=>Ee(le,i.slice(3))):[]),R=[],de=null,Te=[...O],ue=!t.json&&Ne(),gt=O.reduce((i,l)=>i+l.bytes.length,0),Je=0,Ge=()=>ue&&process.stdout.write(`\r\x1B[2K${p(`Sending ${R.length} of ${O.length} \xB7 ${oe(Je)} of ${oe(gt)}`)}`);async function mt(i){let l=He&&!ft.has(C(a,i.rel))?He:null;for(;;)try{let m=i.doc?await e.update(i.doc.id,i.name,i.bytes,{commit:l}):await e.create(d.id,i.name,i.bytes,{project:xe.id,folder:Y.idOf(i.folder)??null});return{file:i.rel,action:i.action,link:e.linkOf(m.slug)}}catch(m){if(m instanceof v&&m.code==="rate_limited"){de||(t.json||b(p("\rUpload limit reached; carrying on in a minute\u2026")),de=new Promise(j=>setTimeout(j,3e4)).then(()=>{de=null})),await de;continue}return{file:i.rel,action:i.action,error:m instanceof v?Z(m,e.url):String(m)}}}Ge(),await Promise.all(Array.from({length:Math.min(Rt,Te.length)},async()=>{for(let i=Te.shift();i;i=Te.shift()){let l=await mt(i);R.push(l),Je+=i.bytes.length,ue&&process.stdout.write("\r\x1B[2K"),l.error&&!t.json?u(`${A("\u2717")} ${l.file} ${A(l.error)}`):!t.json&&!ue&&u(`${k("\u2713")} ${l.file} ${p(l.link)}`),Ge()}})),ue&&process.stdout.write("\r\x1B[2K");let Oe=R.filter(i=>i.error),ze=`${e.url}/${d.slug}/project/${xe.slug}`;t.json?u(JSON.stringify({...ae,applied:!0,link:ze,results:R},null,2)):u(`${Oe.length?E(`${R.length-Oe.length} of ${R.length} sent`):k("\u2713 Synced")} ${p(ze)}`),Oe.length&&(process.exitCode=1)}var Ie="0.0.1-beta.3",S=Xe(),se=Qe(S),Le=`dockito-cli/${Ie} (${process.platform})`;function _(){let e=me(se);return e||w("Not logged in. Run `dockito login`."),pe({url:S,token:e,source:"cli",userAgent:Le})}function dt(e){let[n,t]=process.platform==="darwin"?["open",[e]]:process.platform==="win32"?["cmd",["/c","start","",e]]:["xdg-open",[e]];try{let o=Bt(n,t,{stdio:"ignore",detached:!0});return o.on("error",()=>{}),o.unref(),!0}catch{return!1}}var Qt=()=>!process.env.SSH_CONNECTION&&!process.env.CI&&(process.platform!=="linux"||!!process.env.DISPLAY||!!process.env.WAYLAND_DISPLAY),Zt=e=>new Promise(n=>setTimeout(n,e)),en=()=>qt().replace(/\.local$/,"").slice(0,60)||"Unknown device",tn=/^[a-z0-9]{12}$/;function q(e){let t=(/^https?:\/\//.test(e)?new URL(e).pathname.split("/").filter(Boolean).pop()??"":e).replace(/\.[a-z]+$/,"");return tn.test(t)&&/\d/.test(t)?t:w(`"${e}" isn't a doc link or code. \`dockito ls\` lists docs with their codes.`)}function lt(e){let n=Vt(Yt(e)),t=ct("git",["rev-parse","HEAD"],{cwd:n,encoding:"utf8"});if(t.error||t.status!==0)return null;let o=ct("git",["status","--porcelain","--",Ce(e)],{cwd:n,encoding:"utf8"});return o.status!==0||o.stdout.trim()?null:t.stdout.trim()}var nn=e=>Ht("sha256").update(e).digest("hex");async function on(e){let n=me(se);e.update&&!n&&w("Not logged in. Run `dockito login` first."),process.env.DOCKITO_TOKEN&&b(E("DOCKITO_TOKEN is set, so commands will keep using it instead of this login."));let t=pe({url:S,token:e.update?n:null,userAgent:Le}),o=await t.startLogin("Dockito CLI",en()),s=!e["no-browser"]&&Qt()&&dt(o.verification_uri_complete);u(s?`Opening ${o.verification_uri_complete}`:`Open ${T(o.verification_uri)}`),u(`Code: ${T(o.user_code)}`),b(p("Waiting for approval\u2026"));let r=o.interval*1e3,c=Date.now()+o.expires_in*1e3;for(;Date.now()<c;){await Zt(r);try{let a=await t.pollLogin(o.device_code);if(!a)continue;let f=et(se,a.token);u(`${k("\u2713")} Logged in as ${a.user.name}${a.user.username?p(` (${a.user.username})`):""}`);for(let h of a.workspaces)u(` ${h.name} ${p(`${h.slug} \xB7 ${U[h.level]}`)}`);f==="file"&&b(E("No keychain found, so the token is in a file only you can read, in ~/.config/dockito."));return}catch(a){if(a instanceof v&&a.code==="access_denied"&&w("Denied in the browser."),a instanceof v&&a.code==="expired_token"&&w("The code expired. Run `dockito login` again."),a instanceof v&&a.code==="offline"){r=Math.min(r*2,3e4);continue}throw a}}w("The code expired. Run `dockito login` again.")}async function rn(){let e=me(se);if(!e)return u("Not logged in.");process.env.DOCKITO_TOKEN&&w("DOCKITO_TOKEN is set; unset it or revoke that token in Account \u2192 Tokens.");try{await pe({url:S,token:e,userAgent:Le}).logout()}catch(n){if(!(n instanceof v)||n.code!=="invalid_token"&&n.code!=="not_found")throw n}tt(se),u(`${k("\u2713")} Logged out`)}async function sn(e){let n=await _().whoami();if(e.json)return u(JSON.stringify(n,null,2));u(`${n.user.name} ${p(`${n.user.username} \xB7 ${n.user.email}`)}`),n.token&&u(p(`${n.token.name} \xB7 ${n.token.source==="cli"?"ends after 90 days without use":`expires ${new Date(n.token.expiresAt).toLocaleDateString()}`}`)),u(),Q(n.workspaces.map(t=>[t.slug,t.name,p(t.level?U[t.level]:t.role)])),S!=="https://dockito-app.dockito.workers.dev"&&b(p(`
|
|
18
|
+
${S}`))}async function cn(e,n){e.length||w("Name a file: `dockito publish notes.md --to <project/folder>`"),n.doc&&e.length>1&&w("--doc takes one file.");for(let f of e)(!Jt(f)||!Gt(f).isFile())&&w(`${f} isn't a file.`);let t=_(),o=[];if(n.doc){let f=await t.doc(q(n.doc)),h=new Uint8Array(at(e[0])),g=await t.update(f.doc.id,Ce(e[0]),h,{note:n.message,commit:lt(e[0])});return n.json?u(JSON.stringify([{file:e[0],...g,link:t.linkOf(g.slug)}],null,2)):u(g.unchanged?`${p("=")} ${e[0]} ${p("unchanged")} ${t.linkOf(g.slug)}`:`${k("\u2713")} ${e[0]} \u2192 ${t.linkOf(g.slug)}`)}let s=await t.tree(),r=he(s,n.workspace);L(r)||w(`This login has View access in ${r.slug}. Run \`dockito login --update\`.`);let c=Ae(r,n.to),a=await t.files(r.id,c.project);for(let f of e){let h=new Uint8Array(at(f)),g=Ce(f),d=n.new?[]:we(a,c.folder,g);d.length>1&&w(`${d.length} docs in ${c.label} are named ${g}: ${d.map($=>t.linkOf($.slug)).join(", ")}. Pick one with --doc, or publish a new one with --new.`);let y=d[0];if(y&&y.sha256===nn(h)&&!n.message){o.push({file:f,id:y.id,slug:y.slug,version:y.version,unchanged:!0,link:t.linkOf(y.slug)}),n.json||u(`${p("=")} ${f} ${p("unchanged")} ${t.linkOf(y.slug)}`);continue}let x=y?await t.update(y.id,g,h,{note:n.message,commit:lt(f)}):await t.create(r.id,g,h,{project:c.project,folder:c.folder});!y&&n.message&&await t.save(x.id,x.version,n.message),o.push({file:f,...x,link:t.linkOf(x.slug),new:!y}),n.json||u(`${k("\u2713")} ${f} \u2192 ${t.linkOf(x.slug)} ${p(y?x.unchanged?"unchanged":"updated":`new in ${c.label}`)}${n.message?p(` \xB7 saved: ${n.message}`):""}`)}n.json?u(JSON.stringify(o,null,2)):!n.to&&o.some(f=>f.new)&&b(p("In the workspace's Docs. To put docs in a project: --to <project/folder>; `dockito tree` lists them."))}async function an(e){let n=await _().tree();if(e.json)return u(JSON.stringify(n,null,2));let t=o=>p(`${o} doc${o===1?"":"s"}`);for(let o of n.workspaces){u(`${T(o.slug)} ${o.name} ${p(`\xB7 ${o.level?U[o.level]:o.role}`)}`);let s=[[p("Docs"),"",t(o.docs)]];for(let r of o.projects){s.push([r.slug,r.name,t(r.docs)]);let c=(a,f)=>{for(let h of r.folders.filter(g=>g.parentId===a))s.push([`${f}/${h.name}`,"",t(h.docs)]),c(h.id,`${f}/${h.name}`)};c(null,r.slug)}Q(s.map(r=>[" ",...r])),u()}b(p("Publish into a place: dockito publish <file> -w <workspace> --to <project/folder>"))}async function ln(e,n){let t=_(),o=await t.tree(),s=he(o,n.workspace),r=Ae(s,e),c=await t.docs(s.id,{project:r.project,folder:r.folder}),a=r.project?s.projects.find(d=>d.id===r.project):null,f=e?[]:s.projects,h=a?a.folders.filter(d=>d.parentId===r.folder):[];if(n.json)return u(JSON.stringify({workspace:s.slug,place:e??null,projects:f,folders:h,docs:c},null,2));let g=[];for(let d of f)g.push([T(`${d.slug}/`),d.name,p(`${d.docs} doc${d.docs===1?"":"s"}`),""]);for(let d of h)g.push([T(`${d.name}/`),"",p(`${d.docs} doc${d.docs===1?"":"s"}`),""]);for(let d of c)g.push([d.slug,d.title+p(d.kind==="html"?" .html":" .md"),p(fe(d.updatedAt)),p(d.updatedByName??"")]);if(!g.length)return b(p(`Nothing in ${r.label} yet.`));Q(g)}async function dn(e,n){let[t,...o]=(e??"").split("/").filter(Boolean);t||w("`dockito mkdir <project>[/folder[/subfolder]]`"),o.length>2&&w("Folders go at most 2 deep inside a project.");let s=_(),r=he(await s.tree(),n.workspace),c=G(r,t),a=c?.id??(await s.createProject(r.id,t)).id,f=!c;c||u(`${k("\u2713")} Project ${t}`);let h=ne(c),g=null;for(let d=0;d<o.length;d++){let y=h.idOf(o.slice(0,d+1));if(y){g=y;continue}g=(await s.createFolder(a,o[d],g)).id,h.add(o.slice(0,d+1),g),f=!0,u(`${k("\u2713")} Folder ${o.slice(0,d+1).join("/")}`)}f||b(p("Already there."))}async function un(e){e||w("Name a doc: `dockito open <link or code>`");let n=`${S}/${q(e)}`;dt(n)||u(n)}async function pn(e,n){e||w("Name a doc: `dockito get <link or code> [-o file]`");let t=_(),o=await t.doc(q(e)),s=n.entry?Number(n.entry):null;n.entry&&(!Number.isInteger(s)||s<1)&&w("--entry takes an entry number from `dockito history`.");let{bytes:r}=await t.content(o.doc.id,s);if(!n.output)return void process.stdout.write(r);zt(n.output,r),b(`${k("\u2713")} ${n.output} ${p(`\u2190 ${t.linkOf(o.doc.slug)}${s?` entry ${s}`:""}`)}`)}async function fn(e,n){e||w("Name a doc: `dockito history <link or code>`");let t=await _().doc(q(e));if(n.json)return u(JSON.stringify(t.versions,null,2));u(`${T(t.doc.title)} ${p(`${S}/${t.doc.slug}`)}`),Q(t.versions.map((o,s)=>[String(o.number),s===0?k("current"):p(fe(o.createdAt)),s===0?p(fe(o.createdAt)):"",o.byName??"",p(o.source),o.savedAt?`${E("saved")}${o.note?` ${o.note}`:""}`:"",o.gitCommit?p(o.gitCommit.slice(0,7)):""]))}async function gn(e,n){let t=Number(n);(!e||!Number.isInteger(t)||t<1)&&w("`dockito restore <doc> <entry>`; entries are in `dockito history`.");let o=_(),s=await o.doc(q(e)),r=await o.restore(s.doc.id,t,s.versions[0]?.number??null);u(`${k("\u2713")} Restored entry ${t} as entry ${r.version} ${p(o.linkOf(r.slug))}`)}async function mn(e,n,t){e||w('`dockito save <doc> [entry] -m "note"`');let o=_(),s=await o.doc(q(e)),r=n?Number(n):s.versions[0]?.number;(!Number.isInteger(r)||r<1)&&w("Entries are in `dockito history`."),await o.save(s.doc.id,r,t.message??null),u(`${k("\u2713")} Saved entry ${r}${t.message?p(` \xB7 ${t.message}`):""}`)}var ut=`Dockito hosts Markdown and HTML docs at a short link, with History.
|
|
44
19
|
|
|
45
20
|
workspace a person's or a team's space; its slug is in every link
|
|
46
21
|
project docs grouped in a workspace, with folders up to 2 deep
|
|
47
|
-
Docs a workspace's docs outside any project
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
updates the same doc and keeps its link
|
|
22
|
+
Docs a workspace's docs outside any project
|
|
23
|
+
doc one file. Publishing a file with the same name to the same
|
|
24
|
+
place updates that doc and keeps its link
|
|
51
25
|
History every publish is an entry; -m keeps one as a saved point
|
|
52
26
|
access a login has View, Publish or Everything per workspace
|
|
53
27
|
|
|
54
28
|
For AI agents:
|
|
55
|
-
- Run \`dockito tree\` to see
|
|
56
|
-
|
|
57
|
-
-
|
|
58
|
-
|
|
59
|
-
-
|
|
60
|
-
|
|
29
|
+
- The CLI remembers nothing between runs. Run \`dockito tree\` to see
|
|
30
|
+
where docs can go and \`dockito ls <place>\` for what's there.
|
|
31
|
+
- Never guess a place: ask the user, then pass it with --to every time.
|
|
32
|
+
Keep it in your own notes if the user wants it remembered.
|
|
33
|
+
- A folder of docs: \`dockito sync <folder> --to <project>\`. It shows a
|
|
34
|
+
plan; show it to the user before running with --yes.
|
|
35
|
+
- Use --json. On failure, read "error" and the commands it suggests.`,hn=`Dockito CLI ${Ie}
|
|
61
36
|
|
|
62
|
-
${
|
|
37
|
+
${ut}
|
|
63
38
|
|
|
64
39
|
Usage: dockito <command>
|
|
65
40
|
|
|
66
|
-
sync
|
|
67
|
-
|
|
68
|
-
--
|
|
69
|
-
--
|
|
70
|
-
--
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
--
|
|
75
|
-
--doc <doc>
|
|
76
|
-
--new
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
save <doc> [entry] -m ... Keep an entry as a saved point
|
|
41
|
+
sync <folder> --to <project> Mirror a folder into a project: subfolders become
|
|
42
|
+
folders, only changed files are sent, plan first
|
|
43
|
+
--create Make the project if it doesn't exist
|
|
44
|
+
--fold Put folders deeper than 2 into the deepest allowed
|
|
45
|
+
--yes Apply without asking; --dry-run shows the plan only
|
|
46
|
+
publish <file...> Publish files; a file with the same name in that
|
|
47
|
+
place updates its doc
|
|
48
|
+
--to <project/folder> Where (default: the workspace's Docs)
|
|
49
|
+
-m, --message <note> Keep this entry as a saved point
|
|
50
|
+
--doc <doc> Update this doc instead
|
|
51
|
+
--new Publish as a new doc even if the name is there
|
|
52
|
+
tree Every workspace, project and folder you can use
|
|
53
|
+
ls [project/folder] What's in a place
|
|
54
|
+
mkdir <project/folder> Make a project or folders
|
|
55
|
+
open <doc> Open in the browser
|
|
56
|
+
get <doc> [-o file] Download (--entry <n> for a History entry)
|
|
57
|
+
history <doc> History entries
|
|
58
|
+
restore <doc> <entry> Make a History entry current again
|
|
59
|
+
save <doc> [entry] -m ... Keep an entry as a saved point
|
|
86
60
|
|
|
87
|
-
login [--update]
|
|
88
|
-
logout
|
|
89
|
-
whoami
|
|
90
|
-
|
|
91
|
-
init [--to project/folder] Write a dockito.jsonc here
|
|
92
|
-
agent What an AI agent needs to know, on its own
|
|
61
|
+
login [--update] Sign in through the browser (--update changes access)
|
|
62
|
+
logout Sign out this machine
|
|
63
|
+
whoami Who you are and what this login can reach
|
|
64
|
+
agent What an AI agent needs to know, on its own
|
|
93
65
|
|
|
94
|
-
<doc> is a link
|
|
95
|
-
-w, --workspace <slug>
|
|
96
|
-
--json
|
|
66
|
+
<doc> is a link or a code.
|
|
67
|
+
-w, --workspace <slug> Another workspace (default: your personal one)
|
|
68
|
+
--json Machine-readable output
|
|
97
69
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
Environment: DOCKITO_TOKEN (use this token), DOCKITO_URL (another Dockito)`;async function To(){let{values:e,positionals:n}=no({allowPositionals:!0,options:{message:{type:"string",short:"m"},to:{type:"string"},doc:{type:"string"},new:{type:"boolean"},force:{type:"boolean"},workspace:{type:"string",short:"w"},output:{type:"string",short:"o"},entry:{type:"string"},json:{type:"boolean"},update:{type:"boolean"},yes:{type:"boolean",short:"y"},"dry-run":{type:"boolean"},create:{type:"boolean"},fold:{type:"boolean"},"no-browser":{type:"boolean"},help:{type:"boolean",short:"h"},version:{type:"boolean",short:"v"}}}),[r,...t]=n;if(e.version)return O(zt);if(e.help||r==="help")return O(Wn);if(!r)return C()?.config.dir||Tt()?ut({c:J(),url:_},void 0,e):O(Wn);switch(r){case"login":return lo(e);case"logout":return ao();case"whoami":return uo(e);case"switch":return fo(t[0]);case"init":return e.to||e.workspace||!Tt()?po(e):ut({c:J(),url:_},void 0,e);case"sync":return ut({c:J(),url:_},t[0],e);case"publish":return go(t,e);case"tree":return $o(e);case"ls":return mo(t[0],e);case"mkdir":return jo(t[0],e);case"open":return ho(t[0]);case"get":return wo(t[0],e);case"history":return ko(t[0],e);case"restore":return yo(t[0],t[1]);case"save":return bo(t[0],t[1],e);case"agent":return O(Gn);default:N(`Unknown command "${r}". Run \`dockito --help\`.`)}}To().then(()=>process.exit(process.exitCode??0),(e)=>{let n=process.argv.includes("--json");if(e instanceof de){if(n)O(JSON.stringify({error:e.code,message:e.message.replace(/\x1b\[[0-9;]*m/g,""),...e.data},null,2));else W(e.message);process.exit(2)}if(e instanceof vt)process.exit(130);if(n&&e instanceof K)O(JSON.stringify({error:e.code,message:Mt(e,_),...e.detail},null,2));else if(e instanceof dt)n?O(JSON.stringify({error:"failed",message:e.message},null,2)):W(Be(e.message));else if(e instanceof K)W(Be(Mt(e,_)));else if(e instanceof TypeError&&/parseArgs|option|positional/i.test(String(e.message)))W(Be(`${e.message}. Run \`dockito --help\`.`));else W(Be(String(e?.stack??e)));process.exit(1)});
|
|
70
|
+
Environment: DOCKITO_TOKEN (use this token), DOCKITO_URL (another Dockito)`;async function wn(){let{values:e,positionals:n}=Xt({allowPositionals:!0,options:{message:{type:"string",short:"m"},to:{type:"string"},doc:{type:"string"},new:{type:"boolean"},workspace:{type:"string",short:"w"},output:{type:"string",short:"o"},entry:{type:"string"},json:{type:"boolean"},update:{type:"boolean"},yes:{type:"boolean",short:"y"},"dry-run":{type:"boolean"},create:{type:"boolean"},fold:{type:"boolean"},"no-browser":{type:"boolean"},help:{type:"boolean",short:"h"},version:{type:"boolean",short:"v"}}}),[t,...o]=n;if(e.version)return u(Ie);if(e.help||!t||t==="help")return u(hn);switch(t){case"login":return on(e);case"logout":return rn();case"whoami":return sn(e);case"sync":return it(_(),o[0],e);case"publish":return cn(o,e);case"tree":return an(e);case"ls":return ln(o[0],e);case"mkdir":return dn(o[0],e);case"open":return un(o[0]);case"get":return pn(o[0],e);case"history":return fn(o[0],e);case"restore":return gn(o[0],o[1]);case"save":return mn(o[0],o[1],e);case"agent":return u(ut);default:w(`Unknown command "${t}". Run \`dockito --help\`.`)}}wn().then(()=>process.exit(process.exitCode??0),e=>{let n=process.argv.includes("--json");e instanceof D&&(n?u(JSON.stringify({error:e.code,message:e.message.replace(/\x1b\[[0-9;]*m/g,""),...e.data},null,2)):b(e.message),process.exit(2)),e instanceof ee&&process.exit(130),n&&e instanceof v?u(JSON.stringify({error:e.code,message:Z(e,S),...e.detail},null,2)):n&&e instanceof K?u(JSON.stringify({error:"failed",message:e.message},null,2)):e instanceof K?b(A(e.message)):e instanceof v?b(A(Z(e,S))):e instanceof TypeError&&/parseArgs|option|positional/i.test(String(e.message))?b(A(`${e.message}. Run \`dockito --help\`.`)):b(A(String(e?.stack??e))),process.exit(1)});
|
package/package.json
CHANGED