dunsocial 0.3.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +142 -47
- package/package.json +4 -2
- package/scripts/postinstall.js +69 -0
package/dist/index.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
import{mkdir as
|
|
4
|
-
`);return}if(
|
|
5
|
-
`);return}if(typeof
|
|
6
|
-
`);return}process.stdout.write(`${
|
|
7
|
-
`)}function
|
|
8
|
-
`);else if(process.stderr.write(`error: ${
|
|
9
|
-
`),
|
|
10
|
-
`);return
|
|
11
|
-
`)}if(
|
|
12
|
-
${
|
|
13
|
-
`)}return String(
|
|
14
|
-
`);return`${
|
|
15
|
-
${
|
|
16
|
-
`,"utf8");try{await We(n,384)}catch{}}async function oe(){let e=E();try{await Me(e)}catch(n){if(n.code!=="ENOENT")throw new w(`Failed to clear config: ${n.message}`,o.USAGE)}}function R(e){if(!e.token)throw new w("Not authenticated. Run `dun auth login --token <token>` or set DUN_TOKEN.",o.AUTH);return e.token}function k(e){if(!e.workspaceId)throw new w("No workspace selected. Run `dun workspace use <id|slug>` or pass --workspace / DUN_WORKSPACE_ID.",o.VALIDATION);return e.workspaceId}var Z=`dun — DunSocial agent-first CLI v${X}
|
|
3
|
+
import{mkdir as L0,readFile as EU,writeFile as k0,chmod as M0,unlink as j0}from"node:fs/promises";import{dirname as d0,join as KU}from"node:path";import{homedir as CU}from"node:os";var z={OK:0,USAGE:1,AUTH:2,FORBIDDEN:3,VALIDATION:4,NOT_FOUND:5,RATE_LIMITED:6,NETWORK:7};class Q extends Error{code;details;constructor(U,D=z.USAGE,O){super(U);this.name="CliError",this.code=D,this.details=O}}function $U(U){if(U===401)return z.AUTH;if(U===403)return z.FORBIDDEN;if(U===404)return z.NOT_FOUND;if(U===429)return z.RATE_LIMITED;if(U>=400&&U<500)return z.VALIDATION;return z.NETWORK}var pU="https://api.dunsocial.com",v="0.4.0";function nU(){if(process.env.DUN_CONFIG)return process.env.DUN_CONFIG;let U=process.env.XDG_CONFIG_HOME,D=U?U:KU(CU(),".config");return KU(D,"dunsocial","config.json")}async function fU(){let U=nU();try{let D=await EU(U,"utf8");return JSON.parse(D)}catch(D){if(D.code==="ENOENT")return{};throw new Q(`Failed to read config at ${U}: ${D.message}`,z.USAGE)}}async function VU(U){let D=await fU(),O=(U.apiUrl||process.env.DUN_API_URL||D.apiUrl||pU).replace(/\/$/,""),K=U.token||process.env.DUN_TOKEN||D.token,G=U.workspace||process.env.DUN_WORKSPACE_ID||D.defaultWorkspaceId||void 0,$=process.env.DUN_JSON==="0",A=!process.stdout.isTTY,V=$?!1:U.json===!0||process.env.DUN_JSON==="1"||process.env.CI==="true"||process.env.CI==="1"||A;return{apiUrl:O,token:K,workspaceId:G,json:V,debug:U.debug===!0||process.env.DUN_DEBUG==="1",quiet:U.quiet===!0,yes:U.yes===!0||process.env.CI==="true"||process.env.CI==="1",config:D}}function AU(U){let D={},O=[],K=0,G=!0;while(K<U.length){let Z=U[K];if(G&&Z==="--"){G=!1,K+=1;continue}if(G&&Z.startsWith("--")){let J=Z.indexOf("=");if(J!==-1){D[Z.slice(2,J)]=Z.slice(J+1),K+=1;continue}let N=Z.slice(2),q=U[K+1];if(q!==void 0&&!q.startsWith("-"))D[N]=q,K+=2;else D[N]=!0,K+=1;continue}if(G&&Z.startsWith("-")&&Z.length>1&&Z!=="-"){let J=Z.slice(1);if(J.length>1&&!J.includes("=")){for(let I of J)D[I]=!0;K+=1;continue}let N=J,q=U[K+1];if(q!==void 0&&!q.startsWith("-"))D[N]=q,K+=2;else D[N]=!0,K+=1;continue}O.push(Z),K+=1}let $=O[0],A,V,X=1;if($==="memory"&&(O[1]==="collections"||O[1]==="collection"))V="collections",A=O[2],X=A?3:2;else A=O[1],X=A?2:1;return{group:$,action:A,nest:V,flags:D,positionals:O.slice(X)}}function m(U,...D){for(let O of D){let K=U[O];if(typeof K==="string"&&K.length>0)return K}return}function y(U,...D){for(let O of D){let K=U[O];if(K===!0)return!0;if(typeof K==="string"){let G=K.toLowerCase();if(G==="1"||G==="true"||G==="yes")return!0}}return!1}function n(U){return y(U,"help","h")}function f(U){return y(U,"version","v","V")}function x(U,D){if(D.quiet&&!D.json)return;if(D.json||!process.stdout.isTTY){process.stdout.write(`${JSON.stringify({ok:!0,data:U},null,2)}
|
|
4
|
+
`);return}if(U===void 0||U===null){process.stdout.write(`ok
|
|
5
|
+
`);return}if(typeof U==="string"){process.stdout.write(`${U}
|
|
6
|
+
`);return}process.stdout.write(`${cU(U,D.emptyMessage)}
|
|
7
|
+
`)}function zU(U,D){let{message:O,code:K,details:G}=xU(U);if(D.json||!process.stdout.isTTY)process.stdout.write(`${JSON.stringify({ok:!1,error:{code:iU(K),message:O,details:G??null}},null,2)}
|
|
8
|
+
`);else if(process.stderr.write(`error: ${O}
|
|
9
|
+
`),G!==void 0&&process.env.DUN_DEBUG==="1")process.stderr.write(`${JSON.stringify(G,null,2)}
|
|
10
|
+
`);return K}function iU(U){switch(U){case z.AUTH:return"auth";case z.FORBIDDEN:return"forbidden";case z.VALIDATION:return"validation";case z.NOT_FOUND:return"not_found";case z.RATE_LIMITED:return"rate_limited";case z.NETWORK:return"network";default:return"usage"}}function xU(U){if(U instanceof Q)return{message:U.message,code:U.code,details:U.details};if(U instanceof Error)return{message:U.message,code:z.USAGE};return{message:String(U),code:z.USAGE}}function cU(U,D){if(Array.isArray(U)){if(U.length===0)return D??"(empty)";if(U.every((O)=>O&&typeof O==="object"))return GU(U,D);return U.map((O)=>`- ${i(O)}`).join(`
|
|
11
|
+
`)}if(U&&typeof U==="object"){let O=U;if(Array.isArray(O.items)){if(O.items.length===0&&D)return D;let K=typeof O.total==="number"?`total=${O.total} showing=${O.items.length}`:void 0,G=GU(O.items,D);return K?`${K}
|
|
12
|
+
${G}`:G}return Object.entries(O).map(([K,G])=>`${K}: ${i(G)}`).join(`
|
|
13
|
+
`)}return String(U)}function GU(U,D){if(U.length===0)return D??"(empty)";let O=["id","name","slug","status","providerName","username","displayName","role","scheduledAt","content","text","originalFilename","score","collectionId"],K=new Set;for(let Z of U)for(let J of Object.keys(Z))K.add(J);let G=[...O.filter((Z)=>K.has(Z)),...[...K].filter((Z)=>!O.includes(Z)).slice(0,6)].slice(0,8),$=U.map((Z)=>G.map((J)=>gU(i(Z[J]),J==="content"||J==="text"?48:28))),A=G.map((Z,J)=>Math.max(Z.length,...$.map((N)=>N[J]?.length??0))),V=G.map((Z,J)=>Z.padEnd(A[J])).join(" "),X=$.map((Z)=>Z.map((J,N)=>J.padEnd(A[N])).join(" ")).join(`
|
|
14
|
+
`);return`${V}
|
|
15
|
+
${X}`}function i(U){if(U===null||U===void 0)return"";if(typeof U==="string")return U.replace(/\s+/g," ").trim();if(typeof U==="number"||typeof U==="boolean")return String(U);if(U instanceof Date)return U.toISOString();if(typeof U==="object"){let D=U;if(typeof D.id==="string"&&typeof D.name==="string")return`${D.name} (${D.id})`;if(typeof D.status==="string")return D.status;return JSON.stringify(U)}return String(U)}function gU(U,D){if(U.length<=D)return U;return`${U.slice(0,Math.max(0,D-1))}…`}var _={OK:0,USAGE:1,AUTH:2,FORBIDDEN:3,VALIDATION:4,NOT_FOUND:5,RATE_LIMITED:6,NETWORK:7};class c extends Error{code;details;constructor(U,D=_.USAGE,O){super(U);this.name="CliError",this.code=D,this.details=O}}var QU=`dun — schedule & publish social posts
|
|
17
16
|
|
|
18
17
|
Usage:
|
|
19
18
|
dun <command> [flags]
|
|
@@ -66,9 +65,11 @@ Memory:
|
|
|
66
65
|
dun memory delete <id> --collection <id> [--yes]
|
|
67
66
|
|
|
68
67
|
Agent skills:
|
|
69
|
-
dun skill install
|
|
70
|
-
dun skill
|
|
68
|
+
dun skill install <agent|all>
|
|
69
|
+
dun skill list
|
|
71
70
|
dun skill path
|
|
71
|
+
# agents: claude codex cursor pi opencode agents copilot windsurf
|
|
72
|
+
# goose gemini amp grok continue antigravity
|
|
72
73
|
|
|
73
74
|
Global flags:
|
|
74
75
|
--json Machine-readable output (default when non-TTY / CI)
|
|
@@ -87,8 +88,8 @@ Env:
|
|
|
87
88
|
Exit codes:
|
|
88
89
|
0 ok · 1 usage · 2 auth · 3 forbidden · 4 validation · 5 not found · 6 rate limit · 7 network
|
|
89
90
|
|
|
90
|
-
Docs: https://dunsocial.com
|
|
91
|
-
`;function
|
|
91
|
+
Docs: https://dunsocial.com
|
|
92
|
+
`;function g(U){return{auth:`dun auth
|
|
92
93
|
|
|
93
94
|
login [--token] Device-code browser login (default) or --token for CI
|
|
94
95
|
logout Clear local config
|
|
@@ -110,37 +111,131 @@ Docs: https://dunsocial.com · MCP remains the remote-host path; CLI is local/CI
|
|
|
110
111
|
delete <id> [--yes]
|
|
111
112
|
x-cap
|
|
112
113
|
`,drafts:"dun drafts list|get|create|update|delete",media:"dun media list|get|upload|delete",memory:`dun memory collections list|create
|
|
113
|
-
dun memory list|save|search|delete`,skill:`dun skill install claude|codex
|
|
114
|
-
dun skill
|
|
115
|
-
`
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
114
|
+
dun memory list|save|search|delete`,skill:`dun skill install <claude|codex|cursor|pi|opencode|agents|copilot|windsurf|goose|gemini|amp|grok|continue|antigravity|all>
|
|
115
|
+
dun skill list
|
|
116
|
+
dun skill path`}[U]??`dun — schedule & publish social posts
|
|
117
|
+
|
|
118
|
+
Usage:
|
|
119
|
+
dun <command> [flags]
|
|
120
|
+
|
|
121
|
+
Auth:
|
|
122
|
+
dun auth login # device-code browser flow
|
|
123
|
+
dun auth login --token <token> # CI / headless
|
|
124
|
+
dun auth login --no-browser
|
|
125
|
+
dun auth logout
|
|
126
|
+
dun auth whoami
|
|
127
|
+
dun auth status
|
|
128
|
+
|
|
129
|
+
Workspaces:
|
|
130
|
+
dun workspace list
|
|
131
|
+
dun workspace use <id|slug>
|
|
132
|
+
dun workspace current
|
|
133
|
+
|
|
134
|
+
Accounts:
|
|
135
|
+
dun accounts list [--platform x]
|
|
136
|
+
|
|
137
|
+
Posts:
|
|
138
|
+
dun posts list [--status scheduled|published|failed|draft|cancelled]
|
|
139
|
+
dun posts get <id>
|
|
140
|
+
dun posts schedule --text "..." --accounts <id,id> (--at ISO | --in 2h) [--media id,id]
|
|
141
|
+
dun posts publish --text "..." --accounts <id,id> [--media id,id] [--natural]
|
|
142
|
+
dun posts reschedule <id> --at ISO|--in 2h [--text "..."]
|
|
143
|
+
dun posts cancel <id>
|
|
144
|
+
dun posts delete <id> [--yes]
|
|
145
|
+
dun posts x-cap
|
|
146
|
+
|
|
147
|
+
Drafts:
|
|
148
|
+
dun drafts list
|
|
149
|
+
dun drafts get <id>
|
|
150
|
+
dun drafts create --text "..." [--platforms x,linkedin] [--accounts id,id]
|
|
151
|
+
dun drafts update <id> --text "..."
|
|
152
|
+
dun drafts delete <id> [--yes]
|
|
153
|
+
|
|
154
|
+
Media:
|
|
155
|
+
dun media list
|
|
156
|
+
dun media get <id>
|
|
157
|
+
dun media upload <file> [--alt "..."]
|
|
158
|
+
dun media delete <id> [--yes]
|
|
159
|
+
|
|
160
|
+
Memory:
|
|
161
|
+
dun memory collections list
|
|
162
|
+
dun memory collections create --name "..." [--color blue] [--private]
|
|
163
|
+
dun memory list --collection <id>
|
|
164
|
+
dun memory save --collection <id> --text "..."
|
|
165
|
+
dun memory search --prompt "..." --collections <id,id> [--top-k 5]
|
|
166
|
+
dun memory delete <id> --collection <id> [--yes]
|
|
167
|
+
|
|
168
|
+
Agent skills:
|
|
169
|
+
dun skill install <agent|all>
|
|
170
|
+
dun skill list
|
|
171
|
+
dun skill path
|
|
172
|
+
# agents: claude codex cursor pi opencode agents copilot windsurf
|
|
173
|
+
# goose gemini amp grok continue antigravity
|
|
174
|
+
|
|
175
|
+
Global flags:
|
|
176
|
+
--json Machine-readable output (default when non-TTY / CI)
|
|
177
|
+
--workspace <id> Override workspace for this command
|
|
178
|
+
--api-url <url> Override API base (default https://api.dunsocial.com)
|
|
179
|
+
--token <token> Override bearer token for this command
|
|
180
|
+
--debug Log HTTP method/path/status to stderr
|
|
181
|
+
--quiet Suppress human success output
|
|
182
|
+
--yes Skip destructive confirmations
|
|
183
|
+
--help, -h Show help
|
|
184
|
+
--version, -v Show version
|
|
185
|
+
|
|
186
|
+
Env:
|
|
187
|
+
DUN_TOKEN DUN_WORKSPACE_ID DUN_API_URL DUN_CONFIG DUN_JSON=1 DUN_DEBUG=1
|
|
188
|
+
|
|
189
|
+
Exit codes:
|
|
190
|
+
0 ok · 1 usage · 2 auth · 3 forbidden · 4 validation · 5 not found · 6 rate limit · 7 network
|
|
191
|
+
|
|
192
|
+
Docs: https://dunsocial.com
|
|
193
|
+
`}import{mkdir as oU,readFile as i0,writeFile as eU,chmod as rU,unlink as lU}from"node:fs/promises";import{dirname as sU,join as XU}from"node:path";import{homedir as tU}from"node:os";var M="0.4.0";function o(){if(process.env.DUN_CONFIG)return process.env.DUN_CONFIG;let U=process.env.XDG_CONFIG_HOME,D=U?U:XU(tU(),".config");return XU(D,"dunsocial","config.json")}function j(){return o()}async function b(U){let D=o();await oU(sU(D),{recursive:!0});let O={...U,updatedAt:new Date().toISOString()};await eU(D,`${JSON.stringify(O,null,2)}
|
|
194
|
+
`,"utf8");try{await rU(D,384)}catch{}}async function ZU(){let U=o();try{await lU(U)}catch(D){if(D.code!=="ENOENT")throw new Q(`Failed to clear config: ${D.message}`,z.USAGE)}}function w(U){if(!U.token)throw new Q("Not authenticated. Run `dun auth login` (or `dun auth login --token <token>` / set DUN_TOKEN).",z.AUTH);return U.token}function H(U){if(!U.workspaceId)throw new Q("No workspace selected. Run `dun workspace use <id|slug>` or pass --workspace / DUN_WORKSPACE_ID.",z.VALIDATION);return U.workspaceId}var JU=[" ___ ___ _ _ "," | \\ _ _ _ _ / __| ___ __(_)__ _| |"," | |) | || | ' \\__ \\/ _ \\/ _| / _` | |"," |___/ \\_,_|_||_|___/\\___/\\__|_\\__,_|_|"].join(`
|
|
195
|
+
`),RU=[" _ "," __| |_ _ _ _ "," / _` | || | ' \\ "," \\__,_|\\_,_|_||_|",""," DunSocial"].join(`
|
|
196
|
+
`),aU="DunSocial",U0=YU(JU),O0=YU(RU);function YU(U){return Math.max(...U.split(`
|
|
197
|
+
`).map((D)=>D.length))}function e(U=process.stderr){if(!U.isTTY)return!1;if(process.env.CI==="true"||process.env.CI==="1")return!1;if(process.env.GITHUB_ACTIONS||process.env.TF_BUILD||process.env.GITLAB_CI)return!1;if(process.env.DUN_JSON==="1")return!1;return!0}function qU(U=process.stdout.columns??80){let D=U>0?U:80;if(D>=U0)return JU;if(D>=O0)return RU;return aU}function D0(U=process.stdout.columns??80){return`${qU(U)}
|
|
198
|
+
|
|
199
|
+
Schedule & publish from the terminal · v${M}`}function NU(U=process.stderr,D={}){if(!e(U))return;let O=D.columns??U.columns??process.stdout.columns??80,K=D.tagline?D0(O):qU(O);U.write(`
|
|
200
|
+
${K}
|
|
201
|
+
|
|
202
|
+
`)}function R(U,D){if(D.quiet&&!D.json)return;if(D.json||!process.stdout.isTTY){process.stdout.write(`${JSON.stringify({ok:!0,data:U},null,2)}
|
|
203
|
+
`);return}if(U===void 0||U===null){process.stdout.write(`ok
|
|
204
|
+
`);return}if(typeof U==="string"){process.stdout.write(`${U}
|
|
205
|
+
`);return}process.stdout.write(`${$0(U,D.emptyMessage)}
|
|
206
|
+
`)}function $0(U,D){if(Array.isArray(U)){if(U.length===0)return D??"(empty)";if(U.every((O)=>O&&typeof O==="object"))return TU(U,D);return U.map((O)=>`- ${r(O)}`).join(`
|
|
207
|
+
`)}if(U&&typeof U==="object"){let O=U;if(Array.isArray(O.items)){if(O.items.length===0&&D)return D;let K=typeof O.total==="number"?`total=${O.total} showing=${O.items.length}`:void 0,G=TU(O.items,D);return K?`${K}
|
|
208
|
+
${G}`:G}return Object.entries(O).map(([K,G])=>`${K}: ${r(G)}`).join(`
|
|
209
|
+
`)}return String(U)}function TU(U,D){if(U.length===0)return D??"(empty)";let O=["id","name","slug","status","providerName","username","displayName","role","scheduledAt","content","text","originalFilename","score","collectionId"],K=new Set;for(let Z of U)for(let J of Object.keys(Z))K.add(J);let G=[...O.filter((Z)=>K.has(Z)),...[...K].filter((Z)=>!O.includes(Z)).slice(0,6)].slice(0,8),$=U.map((Z)=>G.map((J)=>K0(r(Z[J]),J==="content"||J==="text"?48:28))),A=G.map((Z,J)=>Math.max(Z.length,...$.map((N)=>N[J]?.length??0))),V=G.map((Z,J)=>Z.padEnd(A[J])).join(" "),X=$.map((Z)=>Z.map((J,N)=>J.padEnd(A[N])).join(" ")).join(`
|
|
210
|
+
`);return`${V}
|
|
211
|
+
${X}`}function r(U){if(U===null||U===void 0)return"";if(typeof U==="string")return U.replace(/\s+/g," ").trim();if(typeof U==="number"||typeof U==="boolean")return String(U);if(U instanceof Date)return U.toISOString();if(typeof U==="object"){let D=U;if(typeof D.id==="string"&&typeof D.name==="string")return`${D.name} (${D.id})`;if(typeof D.status==="string")return D.status;return JSON.stringify(U)}return String(U)}function K0(U,D){if(U.length<=D)return U;return`${U.slice(0,Math.max(0,D-1))}…`}function d(U,D,O){if(!U)return;if(O!==void 0){process.stderr.write(`[debug] ${D} ${JSON.stringify(O)}
|
|
212
|
+
`);return}process.stderr.write(`[debug] ${D}
|
|
213
|
+
`)}class WU{ctx;constructor(U){this.ctx=U}async request(U){let D=U.method??"GET",O=new URL(U.path.startsWith("http")?U.path:`${this.ctx.apiUrl}${U.path}`);if(U.query)for(let[X,Z]of Object.entries(U.query)){if(Z===void 0||Z===null||Z==="")continue;O.searchParams.set(X,String(Z))}let K={Accept:"application/json","User-Agent":`dunsocial-cli/${M}`,...U.headers??{}};if(U.auth!==!1)K.Authorization=`Bearer ${w(this.ctx)}`;if(U.workspace)K["X-Workspace-Id"]=H(this.ctx);let G;if(U.body!==void 0)K["Content-Type"]="application/json",G=JSON.stringify(U.body);d(this.ctx.debug,`${D} ${O.toString()}`);let $;try{$=await fetch(O,{method:D,headers:K,body:G})}catch(X){throw new Q(`Network error: ${X.message}`,z.NETWORK,{cause:String(X)})}let A=await $.text(),V=null;if(A)try{V=JSON.parse(A)}catch{V=null}if(d(this.ctx.debug,`← ${$.status}`,{ok:$.ok,bodyPreview:A.slice(0,300)}),!$.ok){let X=V?.error||V?.message||(A?A.slice(0,300):`HTTP ${$.status}`);throw new Q(X,$U($.status),{status:$.status,body:V??A})}if(V&&typeof V==="object"&&"success"in V){if(V.success===!1)throw new Q(V.error||V.message||"Request failed",z.VALIDATION,V);return V.data}return V??void 0}get(U,D){return this.request({...D,method:"GET",path:U})}post(U,D,O){return this.request({...O,method:"POST",path:U,body:D})}patch(U,D,O){return this.request({...O,method:"PATCH",path:U,body:D})}delete(U,D,O){return this.request({...O,method:"DELETE",path:U,body:D})}}function T(U){return new WU(U)}function Y(U,...D){for(let O of D){let K=U[O];if(typeof K==="string"&&K.length>0)return K}return}function F(U,...D){for(let O of D){let K=U[O];if(K===!0)return!0;if(typeof K==="string"){let G=K.toLowerCase();if(G==="1"||G==="true"||G==="yes")return!0}}return!1}function P(U,...D){let O=Y(U,...D);if(O===void 0)return;let K=Number(O);if(!Number.isFinite(K))throw Error(`Invalid number for --${D[0]}: ${O}`);return K}function u(U,...D){let O=Y(U,...D);if(O===void 0)return;return O.split(",").map((K)=>K.trim()).filter(Boolean)}var V0=[" ___ ___ _ _ "," | \\ _ _ _ _ / __| ___ __(_)__ _| |"," | |) | || | ' \\__ \\/ _ \\/ _| / _` | |"," |___/ \\_,_|_||_|___/\\___/\\__|_\\__,_|_|"].join(`
|
|
214
|
+
`),wU=[" _ "," __| |_ _ _ _ "," / _` | || | ' \\ "," \\__,_|\\_,_|_||_|",""," DunSocial"].join(`
|
|
215
|
+
`);var KO=HU(V0),VO=HU(wU);function HU(U){return Math.max(...U.split(`
|
|
216
|
+
`).map((D)=>D.length))}function S(U=process.stderr){if(!U.isTTY)return!1;if(process.env.CI==="true"||process.env.CI==="1")return!1;if(process.env.GITHUB_ACTIONS||process.env.TF_BUILD||process.env.GITLAB_CI)return!1;if(process.env.DUN_JSON==="1")return!1;return!0}function FU(){return wU}async function PU(U,D,O,K){switch(D){case"login":return A0(U,O);case"logout":return Q0(U);case"whoami":return X0(U);case"status":return Z0(U);default:throw new Q(`Unknown auth command "${D??""}". Try: login, logout, whoami, status`,z.USAGE)}}async function A0(U,D){let O=Y(D,"token")||process.env.DUN_TOKEN;if(O)return G0(U,O);return z0(U,D)}function E(U){if(U)return"Logged in.";return`Logged in.
|
|
217
|
+
Next: dun workspace list && dun workspace use <id|slug>`}async function G0(U,D){let O={...U,token:D},G=await T(O).get("/api/user/profile");if(await b({...U.config,apiUrl:U.apiUrl,token:D,defaultWorkspaceId:U.config.defaultWorkspaceId,defaultWorkspaceSlug:U.config.defaultWorkspaceSlug,defaultWorkspaceName:U.config.defaultWorkspaceName}),!U.json&&S(process.stdout)){R(E(Boolean(U.config.defaultWorkspaceId)),U);return}R({user:{id:G.id,name:G.name,email:G.email},configPath:j(),method:"token",message:E(Boolean(U.config.defaultWorkspaceId))},U)}async function z0(U,D){let O=T({...U,token:void 0}),K=await O.post("/api/cli/auth/start",{clientName:"dun-cli"},{auth:!1}),G=!F(D,"no-browser");if(!U.json){if(S(process.stderr))process.stderr.write(`
|
|
218
|
+
${FU()}
|
|
219
|
+
|
|
220
|
+
`);else process.stderr.write(`
|
|
126
221
|
DunSocial CLI login
|
|
127
222
|
`),process.stderr.write(`───────────────────
|
|
128
|
-
`)
|
|
129
|
-
${
|
|
223
|
+
`);process.stderr.write(`In your browser, open:
|
|
224
|
+
${K.verificationUrlComplete}
|
|
130
225
|
|
|
131
|
-
`),process.stderr.write(`Or go to ${
|
|
132
|
-
`),process.stderr.write(` ${
|
|
226
|
+
`),process.stderr.write(`Or go to ${K.verificationUrl} and enter code:
|
|
227
|
+
`),process.stderr.write(` ${K.userCode}
|
|
133
228
|
|
|
134
229
|
`),process.stderr.write(`Waiting for approval…
|
|
135
|
-
`)
|
|
136
|
-
`);if(y&&process.stdout.isTTY)try{await fe(t.verificationUrlComplete)}catch{}let d=Math.max(3,t.interval||5)*1000,i=Date.now()+(t.expiresIn||900)*1000;while(Date.now()<i){await Ee(d);let r=await u.post("/api/cli/auth/poll",{deviceCode:t.deviceCode},{auth:!1});if(r.status==="pending")continue;if(r.status==="expired")throw new w("Login expired. Run dun auth login again.",o.AUTH);if(r.status==="denied")throw new w("Login was denied in the browser.",o.AUTH);if(r.status==="approved"){let m=r.token,O={...e,token:m},A=D(O),T=await A.get("/api/user/profile"),U={...e.config,apiUrl:e.apiUrl,token:m,defaultWorkspaceId:r.workspaceId||e.config.defaultWorkspaceId,defaultWorkspaceSlug:e.config.defaultWorkspaceSlug,defaultWorkspaceName:e.config.defaultWorkspaceName};if(r.workspaceId)try{let b=(await A.get("/api/workspaces")).find((_)=>_.id===r.workspaceId);if(b)U.defaultWorkspaceId=b.id,U.defaultWorkspaceSlug=b.slug,U.defaultWorkspaceName=b.name}catch{}await H(U),N({user:{id:T.id,name:T.name,email:T.email},workspaceId:U.defaultWorkspaceId??null,configPath:J(),method:"device",message:U.defaultWorkspaceId?"Logged in.":"Logged in. Next: dun workspace list && dun workspace use <id|slug>"},e);return}}throw new w("Login timed out. Run dun auth login again.",o.AUTH)}async function Pe(e){await oe(),N({message:"Logged out. Config cleared.",configPath:J()},e)}async function se(e){R(e);let u=await D(e).get("/api/user/profile");N({id:u.id,name:u.name,email:u.email,image:u.image??null,apiUrl:e.apiUrl,workspaceId:e.workspaceId??null},e)}async function Se(e){let n=Boolean(e.token),u=null,t=null;if(n)try{u=await D(e).get("/api/user/profile")}catch(y){t=y instanceof Error?y.message:String(y)}N({authenticated:Boolean(u),tokenPresent:n,apiUrl:e.apiUrl,workspaceId:e.workspaceId??null,workspaceSlug:e.config.defaultWorkspaceSlug??null,workspaceName:e.config.defaultWorkspaceName??null,configPath:J(),user:u?{id:u.id,name:u.name,email:u.email}:null,error:t},e)}function Ee(e){return new Promise((n)=>setTimeout(n,e))}async function fe(e){let n=process.platform,u=n==="darwin"?["open",e]:n==="win32"?["cmd","/c","start","",e]:["xdg-open",e];await Bun.spawn(u,{stdout:"ignore",stderr:"ignore"}).exited}async function Ne(e,n,u,t){R(e);let y=D(e);switch(n){case"list":case"ls":{let d=await y.get("/api/workspaces");N(d.map((i)=>({id:i.id,name:i.name,slug:i.slug,role:i.role,timezone:i.timezone,plan:i.subscription?.planName??null,status:i.subscription?.status??null})),e);return}case"use":{let d=t[0];if(!d)throw new w("Usage: dun workspace use <id|slug>",o.USAGE);let r=(await y.get("/api/workspaces")).find((m)=>m.id===d||m.slug===d);if(!r)throw new w(`Workspace not found: ${d}. Run dun workspace list`,o.NOT_FOUND);await H({...e.config,apiUrl:e.apiUrl,token:e.token,defaultWorkspaceId:r.id,defaultWorkspaceSlug:r.slug,defaultWorkspaceName:r.name}),N({id:r.id,name:r.name,slug:r.slug,role:r.role,message:`Default workspace set to ${r.name}`},e);return}case"current":{if(!e.workspaceId&&!e.config.defaultWorkspaceId)throw new w("No workspace selected. Run dun workspace use <id|slug>",o.VALIDATION);let d=e.workspaceId||e.config.defaultWorkspaceId;try{let r=(await y.get("/api/workspaces")).find((m)=>m.id===d||m.slug===d);if(r){N({id:r.id,name:r.name,slug:r.slug,role:r.role,timezone:r.timezone},e);return}}catch{}N({id:d,name:e.config.defaultWorkspaceName??null,slug:e.config.defaultWorkspaceSlug??null},e);return}default:throw new w(`Unknown workspace command "${n??""}". Try: list, use, current`,o.USAGE)}}async function Ae(e,n,u,t){R(e),k(e);let y=D(e);switch(n){case void 0:case"list":case"ls":{let d=await y.get("/api/social-accounts",{workspace:!0}),i=$(u,"platform","p")?.toLowerCase(),r=i?d.filter((m)=>{let O=(m.providerName||"").toLowerCase();return({x:["x","twitter"],twitter:["x","twitter"],linkedin:["linkedin"],"linkedin-business":["linkedin business","linkedin-business","linkedin_business"],bluesky:["bluesky"],threads:["threads"],reddit:["reddit"],pinterest:["pinterest"],instagram:["instagram"],youtube:["youtube"]}[i]??[i]).some((U)=>O.includes(U))}):d;N(r.map((m)=>({id:m.id,providerName:m.providerName,username:m.username??null,displayName:m.displayName??null,isConnected:m.isConnected,expiresAt:m.expiresAt??null})),e);return}default:throw new w(`Unknown accounts command "${n}". Try: list`,o.USAGE)}}var ve=/^(\d+)\s*(s|sec|secs|second|seconds|m|min|mins|minute|minutes|h|hr|hrs|hour|hours|d|day|days|w|week|weeks)$/i;function C(e,n=new Date){let u=e.trim();if(!u)throw new w("Empty time value",o.VALIDATION);let t=u.match(ve);if(t){let i=Number(t[1]),r=t[2].toLowerCase(),m=Ce(r)*i;return new Date(n.getTime()+m)}let y=u.match(/^in\s+(.+)$/i);if(y)return C(y[1],n);let d=new Date(u);if(Number.isNaN(d.getTime()))throw new w(`Invalid time "${e}". Use ISO-8601 (2026-06-01T09:00:00Z) or relative (2h, 30m, 1d).`,o.VALIDATION);return d}function Ce(e){switch(e){case"s":case"sec":case"secs":case"second":case"seconds":return 1000;case"m":case"min":case"mins":case"minute":case"minutes":return 60000;case"h":case"hr":case"hrs":case"hour":case"hours":return 3600000;case"d":case"day":case"days":return 86400000;case"w":case"week":case"weeks":return 604800000;default:throw new w(`Unknown time unit: ${e}`,o.VALIDATION)}}function B(e){if(e.at&&e.in)throw new w("Pass only one of --at or --in",o.VALIDATION);if(e.at)return C(e.at).toISOString();if(e.in)return C(e.in).toISOString();throw new w("Schedule time required. Pass --at <iso> or --in <duration> (e.g. 2h).",o.VALIDATION)}function Ue(e){if(!e)return[];return e.split(",").map((n)=>n.trim()).filter(Boolean)}function $e(e){let n=$(e,"text","content","c","t");if(!n)throw new w("Missing --text",o.VALIDATION);return n}function c(e){let n=p(e,"accounts","account","a")??Ue($(e,"accounts","account","a"));if(!n||n.length===0)throw new w("Missing --accounts <id,id>",o.VALIDATION);return n}function l(e){return p(e,"media","media-urls")??Ue($(e,"media","media-urls"))}function z(e){let n=$(e,"meta","metadata","meta-json");if(!n)return;try{let u=JSON.parse(n);if(!u||typeof u!=="object"||Array.isArray(u))throw Error("metadata must be a JSON object");return u}catch(u){throw new w(`Invalid --meta JSON: ${u.message}`,o.VALIDATION)}}async function Te(e,n,u,t){R(e),k(e);let y=D(e);switch(n){case"list":case"ls":{let d=await y.get("/api/posts",{workspace:!0,query:{status:$(u,"status","s"),socialAccountId:$(u,"account","social-account"),groupId:$(u,"group"),limit:I(u,"limit")??50,offset:I(u,"offset")??0}});N(d,e);return}case"get":{let d=t[0];if(!d)throw new w("Usage: dun posts get <id>",o.USAGE);let i=await y.get(`/api/posts/${d}`,{workspace:!0});N(i,e);return}case"schedule":{let d=$e(u),i=c(u),r=B({at:$(u,"at"),in:$(u,"in")}),m=await y.post("/api/posts/schedule",{content:d,socialAccountIds:i,scheduledAt:r,mediaUrls:l(u),metadata:z(u)??{}},{workspace:!0});N(m,e);return}case"publish":case"publish-now":{let d=$e(u),i=c(u),r=await y.post("/api/posts/publish-now",{content:d,socialAccountIds:i,mediaUrls:l(u),metadata:z(u)??{},naturalPosting:j(u,"natural","natural-posting")},{workspace:!0});N(r,e);return}case"reschedule":{let d=t[0];if(!d)throw new w("Usage: dun posts reschedule <id> --at|--in",o.USAGE);let r={scheduledAt:B({at:$(u,"at"),in:$(u,"in")})},m=$(u,"text","content","c","t");if(m)r.content=m;let O=l(u);if(O.length)r.mediaUrls=O;let A=z(u);if(A)r.metadata=A;if(!r.content){let U=await y.get(`/api/posts/${d}`,{workspace:!0});if(r.content=U.content,!r.metadata&&U.metadata)r.metadata=U.metadata;if(!r.mediaUrls&&U.mediaUrls)r.mediaUrls=U.mediaUrls}let T=await y.post(`/api/posts/${d}/reschedule`,r,{workspace:!0});N(T,e);return}case"cancel":{let d=t[0];if(!d)throw new w("Usage: dun posts cancel <id>",o.USAGE);let i=await y.post(`/api/posts/${d}/cancel`,void 0,{workspace:!0});N(i??{id:d,status:"cancelled"},e);return}case"delete":case"rm":{let d=t[0];if(!d)throw new w("Usage: dun posts delete <id> [--yes]",o.USAGE);if(!e.yes&&!j(u,"yes","y"))throw new w("Refusing to delete without --yes (or CI/yes mode)",o.VALIDATION);let i=await y.delete(`/api/posts/${d}`,void 0,{workspace:!0});N(i??{id:d,deleted:!0},e);return}case"x-cap":case"xcap":{let d=await y.get("/api/posts/x-cap-usage",{workspace:!0});N(d,e);return}case"schedule-thread":case"publish-thread":case"publish-thread-now":{let d=$(u,"file","f"),i=$(u,"account","accounts","a")??c(u)[0];if(!i)throw new w("Missing --account <xAccountId>",o.VALIDATION);let r;if(d){let O=await Bun.file(d).text(),A=JSON.parse(O);if(Array.isArray(A))r=A;else if(A&&typeof A==="object"&&Array.isArray(A.tweets))r=A.tweets;else throw new w("Thread file must be an array of tweets or { tweets: [] }",o.VALIDATION)}else{let O=$(u,"text","content");if(!O)throw new w("Provide --file thread.json (array of {content}) or informal --text with || separators is not enough alone for threads — use --file",o.VALIDATION);r=O.split("||").map((A)=>({content:A.trim()})).filter((A)=>A.content)}if(r.length<2)throw new w("Threads require at least 2 tweets",o.VALIDATION);if(n==="schedule-thread"){let O=B({at:$(u,"at"),in:$(u,"in")}),A=await y.post("/api/posts/schedule-thread",{socialAccountId:i,tweets:r,scheduledAt:O,metadata:z(u)??{}},{workspace:!0});N(A,e);return}let m=await y.post("/api/posts/publish-thread-now",{socialAccountId:i,tweets:r,metadata:z(u)??{}},{workspace:!0});N(m,e);return}default:throw new w(`Unknown posts command "${n??""}". Try: list, get, schedule, publish, reschedule, cancel, delete, x-cap, schedule-thread, publish-thread`,o.USAGE)}}async function De(e,n,u,t){R(e),k(e);let y=D(e);switch(n){case"list":case"ls":{let d=await y.get("/api/drafts",{workspace:!0,query:{limit:I(u,"limit")??50,offset:I(u,"offset")??0}});N(d,e);return}case"get":{let d=t[0];if(!d)throw new w("Usage: dun drafts get <id>",o.USAGE);let i=await y.get(`/api/drafts/${d}`,{workspace:!0});N(i,e);return}case"create":{let d=$(u,"text","content","c","t");if(!d)throw new w("Missing --text",o.VALIDATION);let i=await y.post("/api/drafts",{content:d,name:$(u,"name","n"),socialAccountIds:p(u,"accounts","account","a")??[],selectedPlatforms:p(u,"platforms","platform","p")??[],mediaUrls:p(u,"media")??[]},{workspace:!0});N(i,e);return}case"update":{let d=t[0];if(!d)throw new w("Usage: dun drafts update <id> --text ...",o.USAGE);let i={id:d},r=$(u,"text","content","c","t");if(r)i.content=r;let m=$(u,"name","n");if(m!==void 0)i.name=m;let O=p(u,"accounts","account","a");if(O)i.socialAccountIds=O;let A=p(u,"platforms","platform","p");if(A)i.selectedPlatforms=A;let T=p(u,"media");if(T)i.mediaUrls=T;let U=await y.patch(`/api/drafts/${d}`,i,{workspace:!0});N(U,e);return}case"delete":case"rm":{let d=t[0];if(!d)throw new w("Usage: dun drafts delete <id> [--yes]",o.USAGE);if(!e.yes&&!j(u,"yes","y"))throw new w("Refusing to delete without --yes",o.VALIDATION);let i=await y.delete(`/api/drafts/${d}`,void 0,{workspace:!0});N(i??{id:d,deleted:!0},e);return}default:throw new w(`Unknown drafts command "${n??""}". Try: list, get, create, update, delete`,o.USAGE)}}import{basename as ce}from"node:path";function le(e){let n=e.split(".").pop()?.toLowerCase()??"";return{jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp",mp4:"video/mp4",mov:"video/quicktime",webm:"video/webm"}[n]??"application/octet-stream"}async function Re(e,n,u,t){R(e),k(e);let y=D(e);switch(n){case"list":case"ls":{let d=await y.get("/api/media",{workspace:!0,query:{limit:I(u,"limit")??50,offset:I(u,"offset")??0}});N(d,e);return}case"get":{let d=t[0];if(!d)throw new w("Usage: dun media get <id>",o.USAGE);let i=await y.get(`/api/media/${d}`,{workspace:!0});N(i,e);return}case"upload":{let d=t[0]||$(u,"file","f");if(!d)throw new w('Usage: dun media upload <file> [--alt "..."]',o.USAGE);let i=Bun.file(d);if(!await i.exists())throw new w(`File not found: ${d}`,o.VALIDATION);let m=ce(d),O=$(u,"mime","type","content-type")||i.type||le(m),A=i.size,T=$(u,"alt","alt-text"),U=await y.post("/api/media/upload-url",{filename:m,mimeType:O,fileSize:A},{workspace:!0});Y(e.debug,`PUT ${U.uploadUrl}`,{storageKey:U.storageKey,fileSize:A});let V=await i.arrayBuffer(),b;try{b=await fetch(U.uploadUrl,{method:"PUT",headers:{"Content-Type":O,"Content-Length":String(A)},body:V})}catch(W){throw new w(`Upload PUT failed: ${W.message}`,o.NETWORK)}if(!b.ok){let W=await b.text().catch(()=>"");throw new w(`Upload PUT failed with HTTP ${b.status}${W?`: ${W.slice(0,200)}`:""}`,o.NETWORK)}let _=await y.post("/api/media/complete",{storageKey:U.storageKey,originalFilename:m,mimeType:O,fileSize:A,altText:T},{workspace:!0});N(_,e);return}case"delete":case"rm":{let d=t[0];if(!d)throw new w("Usage: dun media delete <id> [--yes]",o.USAGE);if(!e.yes&&!j(u,"yes","y"))throw new w("Refusing to delete without --yes",o.VALIDATION);let i=await y.delete(`/api/media/${d}`,void 0,{workspace:!0});N(i??{id:d,deleted:!0},e);return}default:throw new w(`Unknown media command "${n??""}". Try: list, get, upload, delete`,o.USAGE)}}async function be(e,n,u,t){R(e),k(e);let y=D(e),d=n[0];if(d==="collections"||d==="collection"){let i=n[1]||"list";switch(i){case"list":case"ls":{let r=await y.get("/api/memory/collections",{workspace:!0});N(r,e);return}case"create":{let r=$(u,"name","n");if(!r)throw new w("Missing --name",o.VALIDATION);let m=await y.post("/api/memory/collections",{name:r,color:$(u,"color")??"blue",isPrivate:j(u,"private")},{workspace:!0});N(m,e);return}case"get":{let r=n[2]||t[0];if(!r)throw new w("Usage: dun memory collections get <id>",o.USAGE);let m=await y.get(`/api/memory/collections/${r}`,{workspace:!0});N(m,e);return}default:throw new w(`Unknown memory collections command "${i}". Try: list, create, get`,o.USAGE)}}switch(d){case"list":case"ls":{let i=$(u,"collection","collection-id","c");if(!i)throw new w("Missing --collection <id>",o.VALIDATION);let r=await y.get("/api/memory",{workspace:!0,query:{collectionId:i,limit:I(u,"limit")??100}});N(r,e);return}case"save":case"add":{let i=$(u,"collection","collection-id","c"),r=$(u,"text","t");if(!i)throw new w("Missing --collection <id>",o.VALIDATION);if(!r)throw new w("Missing --text",o.VALIDATION);let m=await y.post("/api/memory",{collectionId:i,text:r},{workspace:!0});N(m,e);return}case"search":{let i=$(u,"prompt","q","query","text"),r=p(u,"collections","collection","collection-ids","c")??[];if(!i)throw new w("Missing --prompt",o.VALIDATION);if(r.length===0)throw new w("Missing --collections <id,id>",o.VALIDATION);let m=await y.post("/api/memory/search",{prompt:i,collectionIds:r,topK:I(u,"top-k","topk","k")??5},{workspace:!0});N(m,e);return}case"delete":case"rm":{let i=n[1]||t[0],r=$(u,"collection","collection-id","c");if(!i)throw new w("Usage: dun memory delete <id> --collection <id>",o.USAGE);if(!r)throw new w("Missing --collection <id>",o.VALIDATION);if(!e.yes&&!j(u,"yes","y"))throw new w("Refusing to delete without --yes",o.VALIDATION);let m=await y.delete(`/api/memory/${i}`,{collectionId:r,memoryId:i},{workspace:!0});N(m??{id:i,deleted:!0},e);return}default:throw new w(`Unknown memory command "${d??""}". Try: collections, list, save, search, delete`,o.USAGE)}}import{existsSync as ge}from"node:fs";import{mkdir as g,writeFile as x,readFile as ke}from"node:fs/promises";import{dirname as F,join as L}from"node:path";import{homedir as a}from"node:os";import{fileURLToPath as xe}from"node:url";function ee(){let e=F(xe(import.meta.url)),n=L("skills","dunsocial","SKILL.md"),u=[L(e,"..",n),L(e,"..","..",n)];return u.find(ge)??u[0]}async function ae(){try{return await ke(ee(),"utf8")}catch{throw new w(`Bundled skill not found at ${ee()}. Reinstall dunsocial.`,o.USAGE)}}async function je(e,n,u,t){switch(n){case"path":{N({path:ee()},e);return}case"install":{let y=(t[0]||"").toLowerCase();if(!y||y!=="claude"&&y!=="codex")throw new w("Usage: dun skill install claude|codex",o.USAGE);let d=await ae();if(y==="claude"){let _=L(a(),".claude","skills","dunsocial","SKILL.md");await g(F(_),{recursive:!0}),await x(_,d,"utf8"),N({target:"claude",path:_,message:"Installed DunSocial skill for Claude Code. Restart or open a new session if needed."},e);return}let i=L(a(),".codex","skills","dunsocial","SKILL.md");await g(F(i),{recursive:!0}),await x(i,d,"utf8");let r=L(a(),".codex","AGENTS.md");await g(F(r),{recursive:!0});let m="";try{m=await ke(r,"utf8")}catch{m=""}let O=["<!-- BEGIN DUNSOCIAL CLI SKILL -->","## DunSocial CLI","","Use the `dun` CLI for DunSocial scheduling from the shell. Prefer `--json` output.",`Skill details: ${i}`,"","Common flow:","1. `dun auth status --json`","2. `dun workspace list --json` / `dun workspace use <id>`","3. `dun accounts list --json`",'4. `dun posts schedule --text "..." --accounts <id> --in 1h --json`',"<!-- END DUNSOCIAL CLI SKILL -->"].join(`
|
|
137
|
-
`),
|
|
138
|
-
|
|
139
|
-
${
|
|
140
|
-
`;else
|
|
141
|
-
`;await
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
`),
|
|
145
|
-
`),
|
|
146
|
-
`),
|
|
230
|
+
`)}else process.stderr.write(JSON.stringify({ok:!0,phase:"waiting",userCode:K.userCode,verificationUrlComplete:K.verificationUrlComplete})+`
|
|
231
|
+
`);if(G&&process.stdout.isTTY)try{await R0(K.verificationUrlComplete)}catch{}let $=Math.max(3,K.interval||5)*1000,A=Date.now()+(K.expiresIn||900)*1000;while(Date.now()<A){await J0($);let V=await O.post("/api/cli/auth/poll",{deviceCode:K.deviceCode},{auth:!1});if(V.status==="pending")continue;if(V.status==="expired")throw new Q("Login expired. Run dun auth login again.",z.AUTH);if(V.status==="denied")throw new Q("Login was denied in the browser.",z.AUTH);if(V.status==="approved"){let X=V.token,Z={...U,token:X},J=T(Z),N=await J.get("/api/user/profile"),q={...U.config,apiUrl:U.apiUrl,token:X,defaultWorkspaceId:V.workspaceId||U.config.defaultWorkspaceId,defaultWorkspaceSlug:U.config.defaultWorkspaceSlug,defaultWorkspaceName:U.config.defaultWorkspaceName};if(V.workspaceId)try{let B=(await J.get("/api/workspaces")).find((L)=>L.id===V.workspaceId);if(B)q.defaultWorkspaceId=B.id,q.defaultWorkspaceSlug=B.slug,q.defaultWorkspaceName=B.name}catch{}await b(q);let I=Boolean(q.defaultWorkspaceId);if(!U.json&&S(process.stdout)){R(E(I),U);return}R({user:{id:N.id,name:N.name,email:N.email},workspaceId:q.defaultWorkspaceId??null,configPath:j(),method:"device",message:E(I)},U);return}}throw new Q("Login timed out. Run dun auth login again.",z.AUTH)}async function Q0(U){if(await ZU(),!U.json&&S(process.stdout)){R("Logged out. Config cleared.",U);return}R({message:"Logged out. Config cleared.",configPath:j()},U)}async function X0(U){w(U);let O=await T(U).get("/api/user/profile");R({id:O.id,name:O.name,email:O.email,image:O.image??null,apiUrl:U.apiUrl,workspaceId:U.workspaceId??null},U)}async function Z0(U){let D=Boolean(U.token),O=null,K=null;if(D)try{O=await T(U).get("/api/user/profile")}catch(G){K=G instanceof Error?G.message:String(G)}R({authenticated:Boolean(O),tokenPresent:D,apiUrl:U.apiUrl,workspaceId:U.workspaceId??null,workspaceSlug:U.config.defaultWorkspaceSlug??null,workspaceName:U.config.defaultWorkspaceName??null,configPath:j(),user:O?{id:O.id,name:O.name,email:O.email}:null,error:K},U)}function J0(U){return new Promise((D)=>setTimeout(D,U))}async function R0(U){let D=process.platform,O=D==="darwin"?["open",U]:D==="win32"?["cmd","/c","start","",U]:["xdg-open",U];await Bun.spawn(O,{stdout:"ignore",stderr:"ignore"}).exited}async function uU(U,D,O,K){w(U);let G=T(U);switch(D){case"list":case"ls":{let $=await G.get("/api/workspaces");R($.map((A)=>({id:A.id,name:A.name,slug:A.slug,role:A.role,timezone:A.timezone,plan:A.subscription?.planName??null,status:A.subscription?.status??null})),{...U,emptyMessage:"No workspaces yet."});return}case"use":{let $=K[0];if(!$)throw new Q("Usage: dun workspace use <id|slug>",z.USAGE);let V=(await G.get("/api/workspaces")).find((X)=>X.id===$||X.slug===$);if(!V)throw new Q(`Workspace not found: ${$}. Run dun workspace list`,z.NOT_FOUND);await b({...U.config,apiUrl:U.apiUrl,token:U.token,defaultWorkspaceId:V.id,defaultWorkspaceSlug:V.slug,defaultWorkspaceName:V.name}),R({id:V.id,name:V.name,slug:V.slug,role:V.role,message:`Default workspace set to ${V.name}`},U);return}case"current":{if(!U.workspaceId&&!U.config.defaultWorkspaceId)throw new Q("No workspace selected. Run dun workspace use <id|slug>",z.VALIDATION);let $=U.workspaceId||U.config.defaultWorkspaceId;try{let V=(await G.get("/api/workspaces")).find((X)=>X.id===$||X.slug===$);if(V){R({id:V.id,name:V.name,slug:V.slug,role:V.role,timezone:V.timezone},U);return}}catch{}R({id:$,name:U.config.defaultWorkspaceName??null,slug:U.config.defaultWorkspaceSlug??null},U);return}default:throw new Q(`Unknown workspace command "${D??""}". Try: list, use, current`,z.USAGE)}}async function _U(U,D,O,K){w(U),H(U);let G=T(U);switch(D){case void 0:case"list":case"ls":{let $=await G.get("/api/social-accounts",{workspace:!0}),A=Y(O,"platform","p")?.toLowerCase(),V=A?$.filter((X)=>{let Z=(X.providerName||"").toLowerCase();return({x:["x","twitter"],twitter:["x","twitter"],linkedin:["linkedin"],"linkedin-business":["linkedin business","linkedin-business","linkedin_business"],bluesky:["bluesky"],threads:["threads"],reddit:["reddit"],pinterest:["pinterest"],instagram:["instagram"],youtube:["youtube"]}[A]??[A]).some((q)=>Z.includes(q))}):$;R(V.map((X)=>({id:X.id,providerName:X.providerName,username:X.username??null,displayName:X.displayName??null,isConnected:X.isConnected,expiresAt:X.expiresAt??null})),{...U,emptyMessage:A?`No ${A} accounts connected. Connect one in the DunSocial dashboard.`:"No accounts connected. Connect one in the DunSocial dashboard."});return}default:throw new Q(`Unknown accounts command "${D}". Try: list`,z.USAGE)}}var Y0=/^(\d+)\s*(s|sec|secs|second|seconds|m|min|mins|minute|minutes|h|hr|hrs|hour|hours|d|day|days|w|week|weeks)$/i;function l(U,D=new Date){let O=U.trim();if(!O)throw new Q("Empty time value",z.VALIDATION);let K=O.match(Y0);if(K){let A=Number(K[1]),V=K[2].toLowerCase(),X=q0(V)*A;return new Date(D.getTime()+X)}let G=O.match(/^in\s+(.+)$/i);if(G)return l(G[1],D);let $=new Date(O);if(Number.isNaN($.getTime()))throw new Q(`Invalid time "${U}". Use ISO-8601 (2026-06-01T09:00:00Z) or relative (2h, 30m, 1d).`,z.VALIDATION);return $}function q0(U){switch(U){case"s":case"sec":case"secs":case"second":case"seconds":return 1000;case"m":case"min":case"mins":case"minute":case"minutes":return 60000;case"h":case"hr":case"hrs":case"hour":case"hours":return 3600000;case"d":case"day":case"days":return 86400000;case"w":case"week":case"weeks":return 604800000;default:throw new Q(`Unknown time unit: ${U}`,z.VALIDATION)}}function C(U){if(U.at&&U.in)throw new Q("Pass only one of --at or --in",z.VALIDATION);if(U.at)return l(U.at).toISOString();if(U.in)return l(U.in).toISOString();throw new Q("Schedule time required. Pass --at <iso> or --in <duration> (e.g. 2h).",z.VALIDATION)}function IU(U){if(!U)return[];return U.split(",").map((D)=>D.trim()).filter(Boolean)}function yU(U){let D=Y(U,"text","content","c","t");if(!D)throw new Q("Missing --text",z.VALIDATION);return D}function s(U){let D=u(U,"accounts","account","a")??IU(Y(U,"accounts","account","a"));if(!D||D.length===0)throw new Q("Missing --accounts <id,id>",z.VALIDATION);return D}function t(U){return u(U,"media","media-urls")??IU(Y(U,"media","media-urls"))}function h(U){let D=Y(U,"meta","metadata","meta-json");if(!D)return;try{let O=JSON.parse(D);if(!O||typeof O!=="object"||Array.isArray(O))throw Error("metadata must be a JSON object");return O}catch(O){throw new Q(`Invalid --meta JSON: ${O.message}`,z.VALIDATION)}}async function BU(U,D,O,K){w(U),H(U);let G=T(U);switch(D){case"list":case"ls":{let $=await G.get("/api/posts",{workspace:!0,query:{status:Y(O,"status","s"),socialAccountId:Y(O,"account","social-account"),groupId:Y(O,"group"),limit:P(O,"limit")??50,offset:P(O,"offset")??0}});R($,{...U,emptyMessage:"No posts yet. Schedule one with dun posts schedule."});return}case"get":{let $=K[0];if(!$)throw new Q("Usage: dun posts get <id>",z.USAGE);let A=await G.get(`/api/posts/${$}`,{workspace:!0});R(A,U);return}case"schedule":{let $=yU(O),A=s(O),V=C({at:Y(O,"at"),in:Y(O,"in")}),X=await G.post("/api/posts/schedule",{content:$,socialAccountIds:A,scheduledAt:V,mediaUrls:t(O),metadata:h(O)??{}},{workspace:!0});R(X,U);return}case"publish":case"publish-now":{let $=yU(O),A=s(O),V=await G.post("/api/posts/publish-now",{content:$,socialAccountIds:A,mediaUrls:t(O),metadata:h(O)??{},naturalPosting:F(O,"natural","natural-posting")},{workspace:!0});R(V,U);return}case"reschedule":{let $=K[0];if(!$)throw new Q("Usage: dun posts reschedule <id> --at|--in",z.USAGE);let V={scheduledAt:C({at:Y(O,"at"),in:Y(O,"in")})},X=Y(O,"text","content","c","t");if(X)V.content=X;let Z=t(O);if(Z.length)V.mediaUrls=Z;let J=h(O);if(J)V.metadata=J;if(!V.content){let q=await G.get(`/api/posts/${$}`,{workspace:!0});if(V.content=q.content,!V.metadata&&q.metadata)V.metadata=q.metadata;if(!V.mediaUrls&&q.mediaUrls)V.mediaUrls=q.mediaUrls}let N=await G.post(`/api/posts/${$}/reschedule`,V,{workspace:!0});R(N,U);return}case"cancel":{let $=K[0];if(!$)throw new Q("Usage: dun posts cancel <id>",z.USAGE);let A=await G.post(`/api/posts/${$}/cancel`,void 0,{workspace:!0});R(A??{id:$,status:"cancelled"},U);return}case"delete":case"rm":{let $=K[0];if(!$)throw new Q("Usage: dun posts delete <id> [--yes]",z.USAGE);if(!U.yes&&!F(O,"yes","y"))throw new Q("Refusing to delete without --yes (or CI/yes mode)",z.VALIDATION);let A=await G.delete(`/api/posts/${$}`,void 0,{workspace:!0});R(A??{id:$,deleted:!0},U);return}case"x-cap":case"xcap":{let $=await G.get("/api/posts/x-cap-usage",{workspace:!0});R($,U);return}case"schedule-thread":case"publish-thread":case"publish-thread-now":{let $=Y(O,"file","f"),A=Y(O,"account","accounts","a")??s(O)[0];if(!A)throw new Q("Missing --account <xAccountId>",z.VALIDATION);let V;if($){let Z=await Bun.file($).text(),J=JSON.parse(Z);if(Array.isArray(J))V=J;else if(J&&typeof J==="object"&&Array.isArray(J.tweets))V=J.tweets;else throw new Q("Thread file must be an array of tweets or { tweets: [] }",z.VALIDATION)}else{let Z=Y(O,"text","content");if(!Z)throw new Q("Provide --file thread.json (array of {content}) or informal --text with || separators is not enough alone for threads — use --file",z.VALIDATION);V=Z.split("||").map((J)=>({content:J.trim()})).filter((J)=>J.content)}if(V.length<2)throw new Q("Threads require at least 2 tweets",z.VALIDATION);if(D==="schedule-thread"){let Z=C({at:Y(O,"at"),in:Y(O,"in")}),J=await G.post("/api/posts/schedule-thread",{socialAccountId:A,tweets:V,scheduledAt:Z,metadata:h(O)??{}},{workspace:!0});R(J,U);return}let X=await G.post("/api/posts/publish-thread-now",{socialAccountId:A,tweets:V,metadata:h(O)??{}},{workspace:!0});R(X,U);return}default:throw new Q(`Unknown posts command "${D??""}". Try: list, get, schedule, publish, reschedule, cancel, delete, x-cap, schedule-thread, publish-thread`,z.USAGE)}}async function LU(U,D,O,K){w(U),H(U);let G=T(U);switch(D){case"list":case"ls":{let $=await G.get("/api/drafts",{workspace:!0,query:{limit:P(O,"limit")??50,offset:P(O,"offset")??0}});R($,{...U,emptyMessage:'No drafts yet. Create one with dun drafts create --text "..."'});return}case"get":{let $=K[0];if(!$)throw new Q("Usage: dun drafts get <id>",z.USAGE);let A=await G.get(`/api/drafts/${$}`,{workspace:!0});R(A,U);return}case"create":{let $=Y(O,"text","content","c","t");if(!$)throw new Q("Missing --text",z.VALIDATION);let A=await G.post("/api/drafts",{content:$,name:Y(O,"name","n"),socialAccountIds:u(O,"accounts","account","a")??[],selectedPlatforms:u(O,"platforms","platform","p")??[],mediaUrls:u(O,"media")??[]},{workspace:!0});R(A,U);return}case"update":{let $=K[0];if(!$)throw new Q("Usage: dun drafts update <id> --text ...",z.USAGE);let A={id:$},V=Y(O,"text","content","c","t");if(V)A.content=V;let X=Y(O,"name","n");if(X!==void 0)A.name=X;let Z=u(O,"accounts","account","a");if(Z)A.socialAccountIds=Z;let J=u(O,"platforms","platform","p");if(J)A.selectedPlatforms=J;let N=u(O,"media");if(N)A.mediaUrls=N;let q=await G.patch(`/api/drafts/${$}`,A,{workspace:!0});R(q,U);return}case"delete":case"rm":{let $=K[0];if(!$)throw new Q("Usage: dun drafts delete <id> [--yes]",z.USAGE);if(!U.yes&&!F(O,"yes","y"))throw new Q("Refusing to delete without --yes",z.VALIDATION);let A=await G.delete(`/api/drafts/${$}`,void 0,{workspace:!0});R(A??{id:$,deleted:!0},U);return}default:throw new Q(`Unknown drafts command "${D??""}". Try: list, get, create, update, delete`,z.USAGE)}}import{basename as N0}from"node:path";function T0(U){let D=U.split(".").pop()?.toLowerCase()??"";return{jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp",mp4:"video/mp4",mov:"video/quicktime",webm:"video/webm"}[D]??"application/octet-stream"}async function kU(U,D,O,K){w(U),H(U);let G=T(U);switch(D){case"list":case"ls":{let $=await G.get("/api/media",{workspace:!0,query:{limit:P(O,"limit")??50,offset:P(O,"offset")??0}});R($,{...U,emptyMessage:"No media yet. Upload with dun media upload <file>."});return}case"get":{let $=K[0];if(!$)throw new Q("Usage: dun media get <id>",z.USAGE);let A=await G.get(`/api/media/${$}`,{workspace:!0});R(A,U);return}case"upload":{let $=K[0]||Y(O,"file","f");if(!$)throw new Q('Usage: dun media upload <file> [--alt "..."]',z.USAGE);let A=Bun.file($);if(!await A.exists())throw new Q(`File not found: ${$}`,z.VALIDATION);let X=N0($),Z=Y(O,"mime","type","content-type")||A.type||T0(X),J=A.size,N=Y(O,"alt","alt-text"),q=await G.post("/api/media/upload-url",{filename:X,mimeType:Z,fileSize:J},{workspace:!0});d(U.debug,`PUT ${q.uploadUrl}`,{storageKey:q.storageKey,fileSize:J});let I=await A.arrayBuffer(),k;try{k=await fetch(q.uploadUrl,{method:"PUT",headers:{"Content-Type":Z,"Content-Length":String(J)},body:I})}catch(L){throw new Q(`Upload PUT failed: ${L.message}`,z.NETWORK)}if(!k.ok){let L=await k.text().catch(()=>"");throw new Q(`Upload PUT failed with HTTP ${k.status}${L?`: ${L.slice(0,200)}`:""}`,z.NETWORK)}let B=await G.post("/api/media/complete",{storageKey:q.storageKey,originalFilename:X,mimeType:Z,fileSize:J,altText:N},{workspace:!0});R(B,U);return}case"delete":case"rm":{let $=K[0];if(!$)throw new Q("Usage: dun media delete <id> [--yes]",z.USAGE);if(!U.yes&&!F(O,"yes","y"))throw new Q("Refusing to delete without --yes",z.VALIDATION);let A=await G.delete(`/api/media/${$}`,void 0,{workspace:!0});R(A??{id:$,deleted:!0},U);return}default:throw new Q(`Unknown media command "${D??""}". Try: list, get, upload, delete`,z.USAGE)}}async function MU(U,D,O,K){w(U),H(U);let G=T(U),$=D[0];if($==="collections"||$==="collection"){let A=D[1]||"list";switch(A){case"list":case"ls":{let V=await G.get("/api/memory/collections",{workspace:!0});R(V,{...U,emptyMessage:'No memory collections yet. Create one with dun memory collections create --name "..."'});return}case"create":{let V=Y(O,"name","n");if(!V)throw new Q("Missing --name",z.VALIDATION);let X=await G.post("/api/memory/collections",{name:V,color:Y(O,"color")??"blue",isPrivate:F(O,"private")},{workspace:!0});R(X,U);return}case"get":{let V=D[2]||K[0];if(!V)throw new Q("Usage: dun memory collections get <id>",z.USAGE);let X=await G.get(`/api/memory/collections/${V}`,{workspace:!0});R(X,U);return}default:throw new Q(`Unknown memory collections command "${A}". Try: list, create, get`,z.USAGE)}}switch($){case"list":case"ls":{let A=Y(O,"collection","collection-id","c");if(!A)throw new Q("Missing --collection <id>",z.VALIDATION);let V=await G.get("/api/memory",{workspace:!0,query:{collectionId:A,limit:P(O,"limit")??100}});R(V,{...U,emptyMessage:"No memories in this collection."});return}case"save":case"add":{let A=Y(O,"collection","collection-id","c"),V=Y(O,"text","t");if(!A)throw new Q("Missing --collection <id>",z.VALIDATION);if(!V)throw new Q("Missing --text",z.VALIDATION);let X=await G.post("/api/memory",{collectionId:A,text:V},{workspace:!0});R(X,U);return}case"search":{let A=Y(O,"prompt","q","query","text"),V=u(O,"collections","collection","collection-ids","c")??[];if(!A)throw new Q("Missing --prompt",z.VALIDATION);if(V.length===0)throw new Q("Missing --collections <id,id>",z.VALIDATION);let X=await G.post("/api/memory/search",{prompt:A,collectionIds:V,topK:P(O,"top-k","topk","k")??5},{workspace:!0});R(X,U);return}case"delete":case"rm":{let A=D[1]||K[0],V=Y(O,"collection","collection-id","c");if(!A)throw new Q("Usage: dun memory delete <id> --collection <id>",z.USAGE);if(!V)throw new Q("Missing --collection <id>",z.VALIDATION);if(!U.yes&&!F(O,"yes","y"))throw new Q("Refusing to delete without --yes",z.VALIDATION);let X=await G.delete(`/api/memory/${A}`,{collectionId:V,memoryId:A},{workspace:!0});R(X??{id:A,deleted:!0},U);return}default:throw new Q(`Unknown memory command "${$??""}". Try: collections, list, save, search, delete`,z.USAGE)}}import{existsSync as W0}from"node:fs";import{mkdir as dU,writeFile as SU,readFile as hU}from"node:fs/promises";import{dirname as OU,join as W}from"node:path";import{homedir as DU}from"node:os";import{fileURLToPath as w0}from"node:url";var p=[{id:"claude",label:"Claude Code",aliases:["claude-code"],dest:(U)=>W(U,".claude","skills","dunsocial","SKILL.md")},{id:"codex",label:"Codex",dest:(U)=>W(U,".codex","skills","dunsocial","SKILL.md"),afterInstall:async(U)=>{return{agentsPath:await u0(U)}}},{id:"cursor",label:"Cursor",dest:(U)=>W(U,".cursor","skills","dunsocial","SKILL.md")},{id:"pi",label:"Pi",dest:(U)=>W(U,".pi","agent","skills","dunsocial","SKILL.md")},{id:"opencode",label:"OpenCode",dest:(U)=>W(U,".config","opencode","skills","dunsocial","SKILL.md")},{id:"agents",label:"Universal (.agents)",aliases:["universal"],dest:(U)=>W(U,".agents","skills","dunsocial","SKILL.md")},{id:"copilot",label:"GitHub Copilot",aliases:["github-copilot","github"],dest:(U)=>W(U,".copilot","skills","dunsocial","SKILL.md")},{id:"windsurf",label:"Windsurf",dest:(U)=>W(U,".codeium","windsurf","skills","dunsocial","SKILL.md")},{id:"goose",label:"Goose",dest:(U)=>W(U,".config","goose","skills","dunsocial","SKILL.md")},{id:"gemini",label:"Gemini CLI",aliases:["gemini-cli"],dest:(U)=>W(U,".gemini","skills","dunsocial","SKILL.md")},{id:"amp",label:"Amp",dest:(U)=>W(U,".config","agents","skills","dunsocial","SKILL.md")},{id:"grok",label:"Grok Build",dest:(U)=>W(U,".grok","skills","dunsocial","SKILL.md")},{id:"continue",label:"Continue",dest:(U)=>W(U,".continue","skills","dunsocial","SKILL.md")},{id:"antigravity",label:"Antigravity",dest:(U)=>W(U,".gemini","antigravity","skills","dunsocial","SKILL.md")}],a=new Map;for(let U of p){a.set(U.id,U);for(let D of U.aliases??[])a.set(D,U)}var jU=`Usage: dun skill install <${p.map((U)=>U.id).join("|")}|all>`;function UU(){let U=OU(w0(import.meta.url)),D=W("skills","dunsocial","SKILL.md"),O=[W(U,"..",D),W(U,"..","..",D)];return O.find(W0)??O[0]}function H0(){let U=DU();return p.map((D)=>({id:D.id,label:D.label,path:D.dest(U),aliases:D.aliases??[]}))}async function F0(){try{return await hU(UU(),"utf8")}catch{throw new Q(`Bundled skill not found at ${UU()}. Reinstall dunsocial.`,z.USAGE)}}async function P0(U,D){await dU(OU(U),{recursive:!0}),await SU(U,D,"utf8")}async function u0(U){let D=W(DU(),".codex","AGENTS.md");await dU(OU(D),{recursive:!0});let O="";try{O=await hU(D,"utf8")}catch{O=""}let K=["<!-- BEGIN DUNSOCIAL CLI SKILL -->","## DunSocial CLI","","Use the `dun` CLI for DunSocial scheduling from the shell. Prefer `--json` output.",`Skill details: ${U}`,"","Common flow:","1. `dun auth status --json`","2. `dun workspace list --json` / `dun workspace use <id>`","3. `dun accounts list --json`",'4. `dun posts schedule --text "..." --accounts <id> --in 1h --json`',"<!-- END DUNSOCIAL CLI SKILL -->"].join(`
|
|
232
|
+
`),G="<!-- BEGIN DUNSOCIAL CLI SKILL -->",$="<!-- END DUNSOCIAL CLI SKILL -->",A,V=O.indexOf(G),X=O.indexOf($);if(V!==-1&&X!==-1&&X>V)A=O.slice(0,V)+K+O.slice(X+$.length);else if(O.trim())A=`${O.trimEnd()}
|
|
233
|
+
|
|
234
|
+
${K}
|
|
235
|
+
`;else A=`${K}
|
|
236
|
+
`;return await SU(D,A,"utf8"),D}async function bU(U,D){let O=U.dest(DU());await P0(O,D);let K=U.afterInstall?await U.afterInstall(O):{};return{target:U.id,path:O,message:`Installed DunSocial skill for ${U.label}. Restart or open a new session if needed.`,...K}}async function vU(U,D,O,K){switch(D){case"path":{R({path:UU()},U);return}case"list":{R({targets:H0(),hint:"Install with: dun skill install <target|all>"},U);return}case"install":{let G=(K[0]||"").toLowerCase();if(!G)throw new Q(jU,z.USAGE);let $=await F0();if(G==="all"){let X=[];for(let Z of p){let J=await bU(Z,$);X.push({target:J.target,path:J.path})}R({target:"all",count:X.length,installed:X,message:`Installed DunSocial skill for ${X.length} agents.`},U);return}let A=a.get(G);if(!A)throw new Q(`Unknown agent "${G}". ${jU}
|
|
237
|
+
Try: dun skill list`,z.USAGE);let V=await bU(A,$);R(V,U);return}default:throw new Q(`Unknown skill command "${D??""}". Try: install, list, path`,z.USAGE)}}function mU(){if(e(process.stdout))NU(process.stdout,{tagline:!0});process.stdout.write(`${QU}
|
|
238
|
+
`)}async function _0(U){let D=AU(U),{group:O,action:K,nest:G,flags:$,positionals:A}=D;if(f($)&&!O)return process.stdout.write(`${v}
|
|
239
|
+
`),_.OK;if(O==="help"||!O&&n($)){let X=O==="help"?K||A[0]:void 0;if(X)process.stdout.write(`${g(X)}
|
|
240
|
+
`);else mU();return _.OK}if(!O)return mU(),_.OK;if(n($))return process.stdout.write(`${g(O)}
|
|
241
|
+
`),_.OK;let V=await VU({apiUrl:m($,"api-url","apiUrl"),token:m($,"token"),workspace:m($,"workspace","w"),json:y($,"json","j")?!0:void 0,debug:y($,"debug"),quiet:y($,"quiet","q"),yes:y($,"yes","y")});if(f($))return x({version:v},V),_.OK;try{switch(O){case"auth":await PU(V,K,$,A);break;case"workspace":case"workspaces":await uU(V,K,$,A);break;case"account":case"accounts":await _U(V,K??"list",$,A);break;case"post":case"posts":await BU(V,K,$,A);break;case"draft":case"drafts":await LU(V,K,$,A);break;case"media":await kU(V,K,$,A);break;case"memory":{let X=G?[G,K].filter(Boolean):K?[K]:[];await MU(V,X,$,A);break}case"skill":case"skills":await vU(V,K,$,A);break;case"version":x({version:v},V);break;default:throw new c(`Unknown command "${O}". Run dun --help`,_.USAGE)}return _.OK}catch(X){return zU(X,V)}}var y0=await _0(process.argv.slice(2));process.exit(y0);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dunsocial",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "DunSocial agent-first CLI — schedule and publish social posts from the terminal, CI, and coding agents",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"files": [
|
|
29
29
|
"dist",
|
|
30
30
|
"skills",
|
|
31
|
+
"scripts/postinstall.js",
|
|
31
32
|
"README.md",
|
|
32
33
|
"LICENSE"
|
|
33
34
|
],
|
|
@@ -45,7 +46,8 @@
|
|
|
45
46
|
"type-check": "tsc --noEmit",
|
|
46
47
|
"test": "bun test",
|
|
47
48
|
"release-check": "bun run scripts/release-check.ts",
|
|
48
|
-
"prepack": "bun run build && bun run release-check"
|
|
49
|
+
"prepack": "bun run build && bun run release-check",
|
|
50
|
+
"postinstall": "node ./scripts/postinstall.js"
|
|
49
51
|
},
|
|
50
52
|
"devDependencies": {
|
|
51
53
|
"@types/bun": "latest",
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Gated install tip — silent in CI / non-TTY / agent installs.
|
|
4
|
+
* Keep in sync with apps/cli/src/brand.ts FIGlet Small art.
|
|
5
|
+
*/
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
const BANNER_FULL = [
|
|
9
|
+
' ___ ___ _ _ ',
|
|
10
|
+
" | \\ _ _ _ _ / __| ___ __(_)__ _| |",
|
|
11
|
+
" | |) | || | ' \\__ \\/ _ \\/ _| / _` | |",
|
|
12
|
+
' |___/ \\_,_|_||_|___/\\___/\\__|_\\__,_|_|'
|
|
13
|
+
].join('\n');
|
|
14
|
+
|
|
15
|
+
const BANNER_MINI = [
|
|
16
|
+
' _ ',
|
|
17
|
+
' __| |_ _ _ _ ',
|
|
18
|
+
" / _` | || | ' \\ ",
|
|
19
|
+
' \\__,_|\\_,_|_||_|',
|
|
20
|
+
'',
|
|
21
|
+
' DunSocial'
|
|
22
|
+
].join('\n');
|
|
23
|
+
|
|
24
|
+
function isCi() {
|
|
25
|
+
const env = process.env;
|
|
26
|
+
return (
|
|
27
|
+
env.CI === 'true' ||
|
|
28
|
+
env.CI === '1' ||
|
|
29
|
+
Boolean(env.GITHUB_ACTIONS) ||
|
|
30
|
+
Boolean(env.TF_BUILD) ||
|
|
31
|
+
Boolean(env.GITLAB_CI) ||
|
|
32
|
+
Boolean(env.CIRCLECI) ||
|
|
33
|
+
Boolean(env.BUILDKITE)
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function maxWidth(art) {
|
|
38
|
+
return Math.max(...art.split('\n').map((line) => line.length));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function renderBanner(columns) {
|
|
42
|
+
const cols = columns > 0 ? columns : 80;
|
|
43
|
+
if (cols >= maxWidth(BANNER_FULL)) return BANNER_FULL;
|
|
44
|
+
if (cols >= maxWidth(BANNER_MINI)) return BANNER_MINI;
|
|
45
|
+
return 'DunSocial';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function main() {
|
|
49
|
+
if (!process.stderr.isTTY || isCi()) return;
|
|
50
|
+
|
|
51
|
+
// Quiet for monorepo / local deps; greet on `npm install -g dunsocial`
|
|
52
|
+
const globalInstall =
|
|
53
|
+
process.env.npm_config_global === 'true' || process.env.DUN_POSTINSTALL_FORCE === '1';
|
|
54
|
+
if (!globalInstall) return;
|
|
55
|
+
|
|
56
|
+
const columns = process.stderr.columns || process.stdout.columns || 80;
|
|
57
|
+
const banner = renderBanner(columns);
|
|
58
|
+
|
|
59
|
+
process.stderr.write(`\n${banner}\n\n`);
|
|
60
|
+
process.stderr.write(' dun auth login\n');
|
|
61
|
+
process.stderr.write(' dun --help\n');
|
|
62
|
+
process.stderr.write(' Docs: https://dunsocial.com\n\n');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
main();
|
|
67
|
+
} catch {
|
|
68
|
+
// never fail install
|
|
69
|
+
}
|