dunsocial 0.11.0 → 0.12.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/README.md +1 -1
- package/dist/index.js +63 -63
- package/package.json +2 -10
package/README.md
CHANGED
|
@@ -178,7 +178,7 @@ Tips:
|
|
|
178
178
|
- Help for any command: `dun posts --help` / `dun reddit --help`
|
|
179
179
|
- Structured output for scripts: add `--json`
|
|
180
180
|
- Platform-specific options (Reddit, etc.): `--meta '{…}'`
|
|
181
|
-
- Prefer ChatGPT or Claude **in the browser**? Use [MCP](https://
|
|
181
|
+
- Prefer ChatGPT or Claude **in the browser**? Use [MCP](https://www.dunsocial.com/mcp) instead of the CLI (`com.dunsocial/dunsocial` on the official registry, or `https://api.dunsocial.com/api/mcp`)
|
|
182
182
|
- Personalization is workspace-wide AI voice (Settings → Personalization). Updating it needs a token with the `workspace:write` scope
|
|
183
183
|
|
|
184
184
|
---
|
package/dist/index.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{readFileSync as
|
|
3
|
-
`,"utf8");try{await
|
|
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
|
-
`);return}process.stderr.write(`[debug] ${
|
|
17
|
-
`)}function
|
|
18
|
-
${
|
|
2
|
+
import{readFileSync as Me}from"node:fs";import{mkdir as qe,readFile as je,writeFile as We,chmod as Ve,unlink as Ge}from"node:fs/promises";import{dirname as Be,join as V}from"node:path";import{homedir as Ke}from"node:os";var a={OK:0,USAGE:1,AUTH:2,FORBIDDEN:3,VALIDATION:4,NOT_FOUND:5,RATE_LIMITED:6,NETWORK:7};class d extends Error{code;details;constructor(e,n=a.USAGE,t){super(e);this.name="CliError",this.code=n,this.details=t}}function te(e){if(e===401)return a.AUTH;if(e===403)return a.FORBIDDEN;if(e===404)return a.NOT_FOUND;if(e===429)return a.RATE_LIMITED;if(e>=400&&e<500)return a.VALIDATION;return a.NETWORK}var Fe="https://api.dunsocial.com",ne="0.12.0";function He(){if(!ne.includes("@@"))return ne;try{let e=JSON.parse(Me(V(import.meta.dir,"..","package.json"),"utf8"));if(typeof e.version==="string"&&e.version.length>0)return e.version}catch{}return"0.0.0"}var N=He();function _(){if(process.env.DUN_CONFIG)return process.env.DUN_CONFIG;let e=process.env.XDG_CONFIG_HOME,n=e?e:V(Ke(),".config");return V(n,"dunsocial","config.json")}function L(){return _()}async function G(){let e=_();try{let n=await je(e,"utf8");return JSON.parse(n)}catch(n){if(n.code==="ENOENT")return{};throw new d(`Failed to read config at ${e}: ${n.message}`,a.USAGE)}}async function D(e){let n=_();await qe(Be(n),{recursive:!0});let t={...e,updatedAt:new Date().toISOString()};await We(n,`${JSON.stringify(t,null,2)}
|
|
3
|
+
`,"utf8");try{await Ve(n,384)}catch{}}async function re(){let e=_();try{await Ge(e)}catch(n){if(n.code!=="ENOENT")throw new d(`Failed to clear config: ${n.message}`,a.USAGE)}}async function ie(e){let n=await G(),t=(e.apiUrl||process.env.DUN_API_URL||n.apiUrl||Fe).replace(/\/$/,""),s=e.token||process.env.DUN_TOKEN||n.token,c=e.workspace||process.env.DUN_WORKSPACE_ID||n.defaultWorkspaceId||void 0,r=process.env.DUN_JSON==="0",o=!process.stdout.isTTY,i=r?!1:e.json===!0||process.env.DUN_JSON==="1"||process.env.CI==="true"||process.env.CI==="1"||o;return{apiUrl:t,token:s,workspaceId:c,json:i,debug:e.debug===!0||process.env.DUN_DEBUG==="1",quiet:e.quiet===!0,yes:e.yes===!0||process.env.CI==="true"||process.env.CI==="1",config:n}}function I(e){if(!e.token)throw new d("Not authenticated. Run `dun auth login` (or `dun auth login --token <token>` / set DUN_TOKEN).",a.AUTH);return e.token}function A(e){if(!e.workspaceId)throw new d("No workspace selected. Run `dun workspace use <id|slug>` or pass --workspace / DUN_WORKSPACE_ID.",a.VALIDATION);return e.workspaceId}function oe(e){let n={},t=[],s=0,c=!0;while(s<e.length){let u=e[s];if(c&&u==="--"){c=!1,s+=1;continue}if(c&&u.startsWith("--")){let p=u.indexOf("=");if(p!==-1){n[u.slice(2,p)]=u.slice(p+1),s+=1;continue}let w=u.slice(2),g=e[s+1];if(g!==void 0&&!g.startsWith("-"))n[w]=g,s+=2;else n[w]=!0,s+=1;continue}if(c&&u.startsWith("-")&&u.length>1&&u!=="-"){let p=u.slice(1);if(p.length>1&&!p.includes("=")){for(let k of p)n[k]=!0;s+=1;continue}let w=p,g=e[s+1];if(g!==void 0&&!g.startsWith("-"))n[w]=g,s+=2;else n[w]=!0,s+=1;continue}t.push(u),s+=1}let r=t[0],o,i,l=1;if(r==="memory"&&(t[1]==="collections"||t[1]==="collection"))i="collections",o=t[2],l=o?3:2;else o=t[1],l=o?2:1;return{group:r,action:o,nest:i,flags:n,positionals:t.slice(l)}}function f(e,...n){for(let t of n){let s=e[t];if(typeof s==="string"&&s.length>0)return s}return}function h(e,...n){for(let t of n){let s=e[t];if(s===!0)return!0;if(typeof s==="string"){let c=s.toLowerCase();if(c==="1"||c==="true"||c==="yes")return!0}}return!1}function E(e,...n){let t=f(e,...n);if(t===void 0)return;let s=Number(t);if(!Number.isFinite(s))throw Error(`Invalid number for --${n[0]}: ${t}`);return s}function C(e,...n){let t=f(e,...n);if(t===void 0)return;return t.split(",").map((s)=>s.trim()).filter(Boolean)}function B(e){return h(e,"help","h")}function K(e){return h(e,"version","v","V")}function m(e,n){if(n.quiet&&!n.json)return;if(n.json||!process.stdout.isTTY){process.stdout.write(`${JSON.stringify({ok:!0,data:e},null,2)}
|
|
4
|
+
`);return}if(e===void 0||e===null){process.stdout.write(`ok
|
|
5
|
+
`);return}if(typeof e==="string"){process.stdout.write(`${e}
|
|
6
|
+
`);return}process.stdout.write(`${Ye(e,n.emptyMessage)}
|
|
7
|
+
`)}function ae(e,n){let{message:t,code:s,details:c}=Je(e);if(n.json||!process.stdout.isTTY)process.stdout.write(`${JSON.stringify({ok:!1,error:{code:ze(s),message:t,details:c??null}},null,2)}
|
|
8
|
+
`);else if(process.stderr.write(`error: ${t}
|
|
9
|
+
`),c!==void 0&&process.env.DUN_DEBUG==="1")process.stderr.write(`${JSON.stringify(c,null,2)}
|
|
10
|
+
`);return s}function ze(e){switch(e){case a.AUTH:return"auth";case a.FORBIDDEN:return"forbidden";case a.VALIDATION:return"validation";case a.NOT_FOUND:return"not_found";case a.RATE_LIMITED:return"rate_limited";case a.NETWORK:return"network";default:return"usage"}}function Je(e){if(e instanceof d)return{message:e.message,code:e.code,details:e.details};if(e instanceof Error)return{message:e.message,code:a.USAGE};return{message:String(e),code:a.USAGE}}function Ye(e,n){if(Array.isArray(e)){if(e.length===0)return n??"(empty)";if(e.every((t)=>t&&typeof t==="object"))return se(e,n);return e.map((t)=>`- ${F(t)}`).join(`
|
|
11
|
+
`)}if(e&&typeof e==="object"){let t=e;if(Array.isArray(t.items)){if(t.items.length===0&&n)return n;let s=typeof t.total==="number"?`total=${t.total} showing=${t.items.length}`:void 0,c=se(t.items,n);return s?`${s}
|
|
12
|
+
${c}`:c}return Object.entries(t).map(([s,c])=>`${s}: ${F(c)}`).join(`
|
|
13
|
+
`)}return String(e)}function se(e,n){if(e.length===0)return n??"(empty)";let t=["id","name","slug","status","providerName","username","displayName","role","scheduledAt","content","text","originalFilename","score","collectionId"],s=new Set;for(let u of e)for(let p of Object.keys(u))s.add(p);let c=[...t.filter((u)=>s.has(u)),...[...s].filter((u)=>!t.includes(u)).slice(0,6)].slice(0,8),r=e.map((u)=>c.map((p)=>Xe(F(u[p]),p==="content"||p==="text"?48:28))),o=c.map((u,p)=>Math.max(u.length,...r.map((w)=>w[p]?.length??0))),i=c.map((u,p)=>u.padEnd(o[p])).join(" "),l=r.map((u)=>u.map((p,w)=>p.padEnd(o[w])).join(" ")).join(`
|
|
14
|
+
`);return`${i}
|
|
15
|
+
${l}`}function F(e){if(e===null||e===void 0)return"";if(typeof e==="string")return e.replace(/\s+/g," ").trim();if(typeof e==="number"||typeof e==="boolean")return String(e);if(e instanceof Date)return e.toISOString();if(typeof e==="object"){let n=e;if(typeof n.id==="string"&&typeof n.name==="string")return`${n.name} (${n.id})`;if(typeof n.status==="string")return n.status;return JSON.stringify(e)}return String(e)}function Xe(e,n){if(e.length<=n)return e;return`${e.slice(0,Math.max(0,n-1))}...`}function R(e,n,t){if(!e)return;if(t!==void 0){process.stderr.write(`[debug] ${n} ${JSON.stringify(t)}
|
|
16
|
+
`);return}process.stderr.write(`[debug] ${n}
|
|
17
|
+
`)}function S(e,n){let t=`${e} ${n}`,s="-".repeat(Math.max(12,t.length+4));return`${t}
|
|
18
|
+
${s}`}var H=`dun - schedule & publish social posts
|
|
19
19
|
|
|
20
20
|
Usage:
|
|
21
21
|
dun <command> [flags]
|
|
22
22
|
|
|
23
|
-
${
|
|
23
|
+
${S("\uD83D\uDD10","Auth")}
|
|
24
24
|
dun auth login # device-code browser flow
|
|
25
25
|
dun auth login --token <token> # CI / headless
|
|
26
26
|
dun auth login --no-browser
|
|
@@ -28,20 +28,20 @@ ${F("\uD83D\uDD10","Auth")}
|
|
|
28
28
|
dun auth whoami
|
|
29
29
|
dun auth status
|
|
30
30
|
|
|
31
|
-
${
|
|
31
|
+
${S("\uD83D\uDCC1","Workspaces")}
|
|
32
32
|
dun workspace list
|
|
33
33
|
dun workspace use <id|slug>
|
|
34
34
|
dun workspace current
|
|
35
35
|
|
|
36
|
-
${
|
|
36
|
+
${S("\uD83D\uDD17","Accounts")}
|
|
37
37
|
dun accounts list [--platform x|reddit|...]
|
|
38
38
|
|
|
39
|
-
${
|
|
39
|
+
${S("\uD83D\uDFE0","Reddit")}
|
|
40
40
|
dun reddit flairs <subreddit> # template id + text + textEditable
|
|
41
41
|
dun reddit requirements <subreddit> # live post rules (flair required, ...)
|
|
42
42
|
# alias: dun accounts reddit flairs <subreddit>
|
|
43
43
|
|
|
44
|
-
${
|
|
44
|
+
${S("\uD83D\uDCDD","Posts")}
|
|
45
45
|
dun posts list [--status scheduled|published|failed|draft|cancelled]
|
|
46
46
|
dun posts get <id>
|
|
47
47
|
dun posts validate --accounts <id> [--media id] --meta '{...}'
|
|
@@ -62,20 +62,20 @@ ${F("\uD83D\uDCDD","Posts")}
|
|
|
62
62
|
# Company Pages stay images-only. Do not mix video + images on LinkedIn.
|
|
63
63
|
# publish queues async work; without --wait, status scheduled means queued
|
|
64
64
|
|
|
65
|
-
${
|
|
65
|
+
${S("\uD83D\uDCC4","Drafts")}
|
|
66
66
|
dun drafts list
|
|
67
67
|
dun drafts get <id>
|
|
68
68
|
dun drafts create --text "..." [--platforms x,linkedin] [--accounts id,id]
|
|
69
69
|
dun drafts update <id> --text "..."
|
|
70
70
|
dun drafts delete <id> [--yes]
|
|
71
71
|
|
|
72
|
-
${
|
|
72
|
+
${S("\uD83D\uDDBC️","Media")}
|
|
73
73
|
dun media list
|
|
74
74
|
dun media get <id>
|
|
75
75
|
dun media upload <file> [--alt "..."] # local preflight: images <=8MB, video <=256MB
|
|
76
76
|
dun media delete <id> [--yes]
|
|
77
77
|
|
|
78
|
-
${
|
|
78
|
+
${S("\uD83E\uDDE0","Memory")}
|
|
79
79
|
dun memory collections list
|
|
80
80
|
dun memory collections create --name "..." [--color blue] [--private]
|
|
81
81
|
dun memory collections get <id>
|
|
@@ -86,7 +86,7 @@ ${F("\uD83E\uDDE0","Memory")}
|
|
|
86
86
|
dun memory search --prompt "..." --collections <id,id> [--top-k 5]
|
|
87
87
|
dun memory delete <id> --collection <id> [--yes]
|
|
88
88
|
|
|
89
|
-
${
|
|
89
|
+
${S("\uD83C\uDF99️","Personalization")}
|
|
90
90
|
# workspace AI voice
|
|
91
91
|
dun personalization get
|
|
92
92
|
dun personalization set --description "..."
|
|
@@ -94,21 +94,21 @@ ${F("\uD83C\uDF99️","Personalization")}
|
|
|
94
94
|
dun personalization set --clear
|
|
95
95
|
# requires PAT scope workspace:write for set (owner/admin)
|
|
96
96
|
|
|
97
|
-
${
|
|
97
|
+
${S("\uD83E\uDDE9","Agent skills")}
|
|
98
98
|
dun skill install <agent|all>
|
|
99
99
|
dun skill list
|
|
100
100
|
dun skill path
|
|
101
101
|
# agents: claude codex cursor pi opencode agents copilot windsurf
|
|
102
102
|
# goose gemini amp grok continue antigravity
|
|
103
103
|
|
|
104
|
-
${
|
|
104
|
+
${S("⬆️","Update")}
|
|
105
105
|
dun update # upgrade to latest from npm
|
|
106
106
|
dun update --check # report only
|
|
107
107
|
dun update --force # reinstall latest even if current
|
|
108
108
|
# aliases: upgrade, self-update
|
|
109
109
|
# detects npm / bun / pnpm / yarn; prints command for npx
|
|
110
110
|
|
|
111
|
-
${
|
|
111
|
+
${S("⚙️","Global flags")}
|
|
112
112
|
--json Machine-readable output (default when non-TTY / CI)
|
|
113
113
|
--workspace <id> Override workspace for this command
|
|
114
114
|
--api-url <url> Override API base (default https://api.dunsocial.com)
|
|
@@ -119,14 +119,14 @@ ${F("⚙️","Global flags")}
|
|
|
119
119
|
--help, -h Show help
|
|
120
120
|
--version, -v Show version
|
|
121
121
|
|
|
122
|
-
${
|
|
122
|
+
${S("\uD83C\uDF31","Env")}
|
|
123
123
|
DUN_TOKEN DUN_WORKSPACE_ID DUN_API_URL DUN_CONFIG DUN_JSON=1 DUN_DEBUG=1
|
|
124
124
|
|
|
125
|
-
${
|
|
125
|
+
${S("\uD83D\uDEAA","Exit codes")}
|
|
126
126
|
0 ok | 1 usage | 2 auth | 3 forbidden | 4 validation | 5 not found | 6 rate limit | 7 network
|
|
127
127
|
|
|
128
128
|
Docs: https://dunsocial.com/docs/cli
|
|
129
|
-
`;function
|
|
129
|
+
`;function z(e){return{auth:`dun auth
|
|
130
130
|
|
|
131
131
|
login [--token] Device-code browser login (default) or --token for CI
|
|
132
132
|
logout Clear local config
|
|
@@ -218,43 +218,43 @@ dun skill path`,update:`dun update
|
|
|
218
218
|
--force Reinstall latest even if versions match
|
|
219
219
|
|
|
220
220
|
Aliases: dun upgrade, dun self-update
|
|
221
|
-
`,upgrade:"Alias of update","self-update":"Alias of update"}[
|
|
222
|
-
`),
|
|
223
|
-
`).map((
|
|
224
|
-
CLI v${
|
|
225
|
-
`)}import{spawn as
|
|
226
|
-
Next: dun workspace list && dun workspace use <id|slug>`}async function
|
|
227
|
-
${
|
|
221
|
+
`,upgrade:"Alias of update","self-update":"Alias of update"}[e]??H}var Ze=["DunSocial","---------"].join(`
|
|
222
|
+
`),ce="DunSocial";var Xt=de(Ze),Zt=de(ce);function de(e){return Math.max(...e.split(`
|
|
223
|
+
`).map((n)=>n.length))}function U(e=process.stderr){if(!e.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 le(){return`DunSocial CLI v${N}`}function ue(){return`${ce}
|
|
224
|
+
CLI v${N}`}var Qe="https://dunsocial.com/docs/cli";function et(e){if(!e.token)return"signed_out";if(!e.workspaceId)return"needs_workspace";return"ready"}function pe(e){let n=et(e),t=[`DunSocial CLI v${N}`,""];if(n==="signed_out")t.push("Not signed in.",""," Next: dun auth login");else if(n==="needs_workspace")t.push("Signed in — pick a workspace.",""," Next: dun workspace list"," dun workspace use <slug>");else{let s=e.config.defaultWorkspaceSlug||e.config.defaultWorkspaceName||e.workspaceId||"workspace";t.push(`Ready | workspace: ${s}`,""," Tip: dun accounts list"," dun posts list")}return t.push(""," dun --help all commands",` Docs ${Qe}`,""),t.join(`
|
|
225
|
+
`)}import{spawn as tt}from"node:child_process";class me{ctx;constructor(e){this.ctx=e}async request(e){let n=e.method??"GET",t=new URL(e.path.startsWith("http")?e.path:`${this.ctx.apiUrl}${e.path}`);if(e.query)for(let[l,u]of Object.entries(e.query)){if(u===void 0||u===null||u==="")continue;t.searchParams.set(l,String(u))}let s={Accept:"application/json","User-Agent":`dunsocial-cli/${N}`,...e.headers??{}};if(e.auth!==!1)s.Authorization=`Bearer ${I(this.ctx)}`;if(e.workspace)s["X-Workspace-Id"]=A(this.ctx);let c;if(e.body!==void 0)s["Content-Type"]="application/json",c=JSON.stringify(e.body);R(this.ctx.debug,`${n} ${t.toString()}`);let r;try{r=await fetch(t,{method:n,headers:s,body:c})}catch(l){throw new d(`Network error: ${l.message}`,a.NETWORK,{cause:String(l)})}let o=await r.text(),i=null;if(o)try{i=JSON.parse(o)}catch{i=null}if(R(this.ctx.debug,`<- ${r.status}`,{ok:r.ok,bodyPreview:o.slice(0,300)}),!r.ok){let l=i?.error||i?.message||(o?o.slice(0,300):`HTTP ${r.status}`);throw new d(l,te(r.status),{status:r.status,body:i??o})}if(i&&typeof i==="object"&&"success"in i){if(i.success===!1)throw new d(i.error||i.message||"Request failed",a.VALIDATION,i);return i.data}return i??void 0}get(e,n){return this.request({...n,method:"GET",path:e})}post(e,n,t){return this.request({...t,method:"POST",path:e,body:n})}patch(e,n,t){return this.request({...t,method:"PATCH",path:e,body:n})}delete(e,n,t){return this.request({...t,method:"DELETE",path:e,body:n})}}function y(e){return new me(e)}async function fe(e,n,t,s){switch(n){case"login":return nt(e,t);case"logout":return ot(e);case"whoami":return st(e);case"status":return at(e);default:throw new d(`Unknown auth command "${n??""}". Try: login, logout, whoami, status`,a.USAGE)}}async function nt(e,n){let t=f(n,"token")||process.env.DUN_TOKEN;if(t)return rt(e,t);return it(e,n)}function P(e){if(e)return"Logged in.";return`Logged in.
|
|
226
|
+
Next: dun workspace list && dun workspace use <id|slug>`}async function rt(e,n){let t={...e,token:n},c=await y(t).get("/api/user/profile");if(await D({...e.config,apiUrl:e.apiUrl,token:n,defaultWorkspaceId:e.config.defaultWorkspaceId,defaultWorkspaceSlug:e.config.defaultWorkspaceSlug,defaultWorkspaceName:e.config.defaultWorkspaceName}),!e.json&&U(process.stdout)){m(P(Boolean(e.config.defaultWorkspaceId)),e);return}m({user:{id:c.id,name:c.name,email:c.email},configPath:L(),method:"token",message:P(Boolean(e.config.defaultWorkspaceId))},e)}async function it(e,n){let t=y({...e,token:void 0}),s=await t.post("/api/cli/auth/start",{clientName:"dun-cli"},{auth:!1}),c=!h(n,"no-browser");if(!e.json){if(U(process.stderr))process.stderr.write(`
|
|
227
|
+
${ue()}
|
|
228
228
|
|
|
229
229
|
`);else process.stderr.write(`
|
|
230
230
|
DunSocial CLI login
|
|
231
231
|
`),process.stderr.write(`───────────────────
|
|
232
232
|
`);process.stderr.write(`In your browser, open:
|
|
233
|
-
${
|
|
233
|
+
${s.verificationUrlComplete}
|
|
234
234
|
|
|
235
|
-
`),process.stderr.write(`Or go to ${
|
|
236
|
-
`),process.stderr.write(` ${
|
|
235
|
+
`),process.stderr.write(`Or go to ${s.verificationUrl} and enter code:
|
|
236
|
+
`),process.stderr.write(` ${s.userCode}
|
|
237
237
|
|
|
238
238
|
`),process.stderr.write(`Waiting for approval...
|
|
239
|
-
`)}else process.stderr.write(JSON.stringify({ok:!0,phase:"waiting",userCode:
|
|
240
|
-
`);if(n&&process.stdout.isTTY)try{await nd(D.verificationUrlComplete)}catch{}let $=Math.max(3,D.interval||5)*1000,U=Date.now()+(D.expiresIn||900)*1000;while(Date.now()<U){await Od($);let w=await d.post("/api/cli/auth/poll",{deviceCode:D.deviceCode},{auth:!1});if(w.status==="pending")continue;if(w.status==="expired")throw new e("Login expired. Run dun auth login again.",O.AUTH);if(w.status==="denied")throw new e("Login was denied in the browser.",O.AUTH);if(w.status==="approved"){let y=w.token,z={...u,token:y},q=R(z),V=await q.get("/api/user/profile"),k={...u.config,apiUrl:u.apiUrl,token:y,defaultWorkspaceId:w.workspaceId||u.config.defaultWorkspaceId,defaultWorkspaceSlug:u.config.defaultWorkspaceSlug,defaultWorkspaceName:u.config.defaultWorkspaceName};if(w.workspaceId)try{let j=(await q.get("/api/workspaces")).find((Lu)=>Lu.id===w.workspaceId);if(j)k.defaultWorkspaceId=j.id,k.defaultWorkspaceSlug=j.slug,k.defaultWorkspaceName=j.name}catch{}await P(k);let J=Boolean(k.defaultWorkspaceId);if(!u.json&&A(process.stdout)){X(L(J),u);return}X({user:{id:V.id,name:V.name,email:V.email},workspaceId:k.defaultWorkspaceId??null,configPath:M(),method:"device",message:L(J)},u);return}}throw new e("Login timed out. Run dun auth login again.",O.AUTH)}async function wd(u){if(await mu(),!u.json&&A(process.stdout)){X("Logged out. Config cleared.",u);return}X({message:"Logged out. Config cleared.",configPath:M()},u)}async function Ud(u){G(u);let d=await R(u).get("/api/user/profile");X({id:d.id,name:d.name,email:d.email,image:d.image??null,apiUrl:u.apiUrl,workspaceId:u.workspaceId??null},u)}async function Dd(u){let m=Boolean(u.token),d=null,D=null;if(m)try{d=await R(u).get("/api/user/profile")}catch(n){D=n instanceof Error?n.message:String(n)}X({authenticated:Boolean(d),tokenPresent:m,apiUrl:u.apiUrl,workspaceId:u.workspaceId??null,workspaceSlug:u.config.defaultWorkspaceSlug??null,workspaceName:u.config.defaultWorkspaceName??null,configPath:M(),user:d?{id:d.id,name:d.name,email:d.email}:null,error:D},u)}function Od(u){return new Promise((m)=>setTimeout(m,u))}async function nd(u){let m=process.platform,d=m==="darwin"?["open",u]:m==="win32"?["cmd","/c","start","",u]:["xdg-open",u];await new Promise((D,n)=>{let $=ud(d[0],d.slice(1),{stdio:"ignore",windowsHide:!0});$.on("error",n),$.on("close",()=>D())})}async function Zu(u,m,d,D){G(u);let n=R(u);switch(m){case"list":case"ls":{let $=await n.get("/api/workspaces");X($.map((U)=>({id:U.id,name:U.name,slug:U.slug,role:U.role,timezone:U.timezone,plan:U.subscription?.planName??null,status:U.subscription?.status??null})),{...u,emptyMessage:"No workspaces yet."});return}case"use":{let $=D[0];if(!$)throw new e("Usage: dun workspace use <id|slug>",O.USAGE);let w=(await n.get("/api/workspaces")).find((y)=>y.id===$||y.slug===$);if(!w)throw new e(`Workspace not found: ${$}. Run dun workspace list`,O.NOT_FOUND);await P({...u.config,apiUrl:u.apiUrl,token:u.token,defaultWorkspaceId:w.id,defaultWorkspaceSlug:w.slug,defaultWorkspaceName:w.name}),X({id:w.id,name:w.name,slug:w.slug,role:w.role,message:`Default workspace set to ${w.name}`},u);return}case"current":{if(!u.workspaceId&&!u.config.defaultWorkspaceId)throw new e("No workspace selected. Run dun workspace use <id|slug>",O.VALIDATION);let $=u.workspaceId||u.config.defaultWorkspaceId;try{let w=(await n.get("/api/workspaces")).find((y)=>y.id===$||y.slug===$);if(w){X({id:w.id,name:w.name,slug:w.slug,role:w.role,timezone:w.timezone},u);return}}catch{}X({id:$,name:u.config.defaultWorkspaceName??null,slug:u.config.defaultWorkspaceSlug??null},u);return}default:throw new e(`Unknown workspace command "${m??""}". Try: list, use, current`,O.USAGE)}}async function ku(u,m,d,D){G(u),b(u);let n=R(u);switch(m){case void 0:case"list":case"ls":{let $=await n.get("/api/social-accounts",{workspace:!0}),U=Z(d,"platform","p")?.toLowerCase(),w=U?$.filter((y)=>{let z=(y.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"],tiktok:["tiktok"]}[U]??[U]).some((k)=>z.includes(k))}):$;X(w.map((y)=>({id:y.id,providerName:y.providerName,username:y.username??null,displayName:y.displayName??null,isConnected:y.isConnected,expiresAt:y.expiresAt??null})),{...u,emptyMessage:U?`No ${U} accounts connected. Connect one in the DunSocial dashboard.`:"No accounts connected. Connect one in the DunSocial dashboard."});return}default:throw new e(`Unknown accounts command "${m}". Try: list (or: dun accounts reddit flairs <subreddit>)`,O.USAGE)}}import{readFileSync as zd}from"node:fs";var ed=/^(\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 s(u,m=new Date){let d=u.trim();if(!d)throw new e("Empty time value",O.VALIDATION);let D=d.match(ed);if(D){let U=Number(D[1]),w=D[2].toLowerCase(),y=yd(w)*U;return new Date(m.getTime()+y)}let n=d.match(/^in\s+(.+)$/i);if(n)return s(n[1],m);let $=new Date(d);if(Number.isNaN($.getTime()))throw new e(`Invalid time "${u}". Use ISO-8601 (2026-06-01T09:00:00Z) or relative (2h, 30m, 1d).`,O.VALIDATION);return $}function yd(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 e(`Unknown time unit: ${u}`,O.VALIDATION)}}function v(u){if(u.at&&u.in)throw new e("Pass only one of --at or --in",O.VALIDATION);if(u.at)return s(u.at).toISOString();if(u.in)return s(u.in).toISOString();throw new e("Schedule time required. Pass --at <iso> or --in <duration> (e.g. 2h).",O.VALIDATION)}function Qu(u){if(!u)return[];return u.split(",").map((m)=>m.trim()).filter(Boolean)}function Vu(u,m){let d=Z(u,"text","content","c","t");if(d)return d;let D=m?.reddit;if(D&&typeof D==="object"&&!Array.isArray(D)&&typeof D.title==="string"&&D.title.trim())return D.title.trim();throw new e("Missing --text",O.VALIDATION)}function h(u){let m=I(u,"accounts","account","a")??Qu(Z(u,"accounts","account","a"));if(!m||m.length===0)throw new e("Missing --accounts <id,id>",O.VALIDATION);return m}function S(u){return I(u,"media","media-urls")??Qu(Z(u,"media","media-urls"))}function B(u){let m=Z(u,"meta","metadata","meta-json");if(!m)return;try{let d=JSON.parse(m);if(!d||typeof d!=="object"||Array.isArray(d))throw Error("metadata must be a JSON object");return d}catch(d){throw new e(`Invalid --meta JSON: ${d.message}`,O.VALIDATION)}}var qd=new Set(["published","failed","cancelled"]);async function Xd(u){await new Promise((m)=>setTimeout(m,u))}async function Zd(u,m,d,D){let n=Date.now()+D*1000,$=new Map,U=1500;while($.size<d.length){if(Date.now()>n){let z=d.filter((q)=>!$.has(q.id)).map((q)=>q.id);throw new e(`Timed out waiting for publish after ${D}s. Still pending: ${z.join(", ")}. Poll with: dun posts get <id> --json`,O.NETWORK,{pending:z})}for(let z of d){if($.has(z.id))continue;let q=await u.get(`/api/posts/${z.id}`,{workspace:!0});if(H(m.debug,`wait status ${z.id}=${q.status}`),qd.has(q.status))$.set(z.id,q)}if($.size>=d.length)break;await Xd(U),U=Math.min(U*1.4,8000)}let w=d.map((z)=>$.get(z.id)),y=w.filter((z)=>z.status==="failed");if(y.length>0){let z=y.map((q)=>`${q.id}: ${q.error||"publish failed"}`).join("; ");throw new e(`Publish failed — ${z}`,O.VALIDATION,{posts:w})}return w}async function kd(u,m){let d=[],D=m.meta?.reddit??null;if(!D||typeof D!=="object")throw new e("Reddit accounts require --meta with a reddit object, e.g. "+`--meta '{"reddit":{"subreddit":"…","kind":"self","title":"…","flairId":"…"}}'`,O.VALIDATION);let n=(D.subreddit??"").trim().replace(/^\/?r\//i,""),$=(D.title??"").trim(),U=(D.kind??"").trim(),w=(D.flairId??"").trim(),y=(D.flairText??"").trim();if(!n)throw new e("metadata.reddit.subreddit is required",O.VALIDATION);if(!$)throw new e("metadata.reddit.title is required",O.VALIDATION);if($.length>300)throw new e(`Reddit title exceeds 300 characters: ${$.length}/300`,O.VALIDATION);if(!["self","link","image","video"].includes(U))throw new e("metadata.reddit.kind must be one of: self, link, image, video",O.VALIDATION);if(d.push(`kind=${U}`),d.push(`titleLength=${$.length}`),y&&!w)throw new e(`Can't set flairText without flairId for r/${n}. Run: dun reddit flairs ${n} --json`,O.VALIDATION);if(U==="link"){if(!D.url?.trim())throw new e("Reddit link posts require metadata.reddit.url",O.VALIDATION);try{new URL(D.url)}catch{throw new e("metadata.reddit.url is invalid",O.VALIDATION)}if(m.media.length>0)throw new e("Reddit link posts do not accept --media",O.VALIDATION)}else if(U==="image"||U==="video"){if(m.media.length!==1)throw new e(`Reddit ${U} posts require exactly one --media asset id`,O.VALIDATION)}else if(m.media.length>0)throw new e("Reddit self posts do not accept --media. Use kind image or video.",O.VALIDATION);let z=await u.get("/api/social-accounts/reddit/post-requirements",{workspace:!0,query:{subreddit:n}});if(d.push("fetched post-requirements"),z?.is_flair_required&&!w)throw new e(`r/${n} requires post flair. Discover ids with: dun reddit flairs ${n} --json`,O.VALIDATION);let q=z?.title_text_max_length??300;if($.length>q)throw new e(`Reddit title too long for r/${n}: ${$.length}/${q}`,O.VALIDATION);if(z?.title_text_min_length&&$.length<z.title_text_min_length)throw new e(`Reddit title must be at least ${z.title_text_min_length} characters`,O.VALIDATION);if(w){let V=await u.get("/api/social-accounts/reddit/flair-options",{workspace:!0,query:{subreddit:n}});d.push(`fetched ${V.choices?.length??0} flairs`);let k=(V.choices??[]).find((J)=>J.id===w);if(!k)throw new e(`Unknown flairId "${w}" for r/${n}. Run: dun reddit flairs ${n} --json`,O.VALIDATION);if(k.textEditable===!1&&y&&y!==k.text)throw new e(`Customization not allowed for this flair template. Use flairId "${k.id}" alone`+(k.text?` (template text: "${k.text}")`:""),O.VALIDATION);d.push(`flairId=${k.id}`)}return{ok:!0,checks:d,reddit:{subreddit:n,kind:U,title:$,flairId:w||null,accounts:m.accounts,media:m.media,textPreview:m.text?.slice(0,120)??null,requirements:{is_flair_required:z?.is_flair_required??!1,title_text_max_length:q}}}}async function Ju(u,m,d,D){G(u),b(u);let n=R(u);switch(m){case"list":case"ls":{let $=await n.get("/api/posts",{workspace:!0,query:{status:Z(d,"status","s"),socialAccountId:Z(d,"account","social-account"),groupId:Z(d,"group"),limit:T(d,"limit")??50,offset:T(d,"offset")??0}});X($,{...u,emptyMessage:"No posts yet. Schedule one with dun posts schedule."});return}case"get":{let $=D[0];if(!$)throw new e("Usage: dun posts get <id>",O.USAGE);let U=await n.get(`/api/posts/${$}`,{workspace:!0});X(U,u);return}case"validate":{let $=h(d),U=S(d),w=B(d)??{},y=Z(d,"text","content","c","t"),z=Boolean(w.reddit),q=z;if(!z){let k=await n.get("/api/social-accounts",{workspace:!0});q=$.some((J)=>{return(k.find((j)=>j.id===J)?.providerName||"").toLowerCase().includes("reddit")})}if(!q){X({ok:!0,checks:["no reddit-specific rules for selected accounts"],accounts:$,media:U},u);return}let V=await kd(n,{accounts:$,text:y,media:U,meta:w});X(V,u);return}case"schedule":{let $=B(d)??{},U=Vu(d,$),w=h(d),y=v({at:Z(d,"at"),in:Z(d,"in")}),z=await n.post("/api/posts/schedule",{content:U,socialAccountIds:w,scheduledAt:y,mediaUrls:S(d),metadata:$},{workspace:!0});X(z,u);return}case"publish":case"publish-now":{let $=B(d)??{},U=Vu(d,$),w=h(d),y=await n.post("/api/posts/publish-now",{content:U,socialAccountIds:w,mediaUrls:S(d),metadata:$,naturalPosting:Q(d,"natural","natural-posting")},{workspace:!0});if(!Q(d,"wait")){X(y,u);return}let q=Array.isArray(y)?y:[];if(q.length===0||!q.every((J)=>typeof J?.id==="string"))throw new e("publish --wait expected an array of created posts with ids",O.NETWORK,{data:y});let V=T(d,"wait-timeout","timeout")??120,k=await Zd(n,u,q,V);X({queued:q,posts:k,status:k.every((J)=>J.status==="published")?"published":k[0]?.status},u);return}case"reschedule":{let $=D[0];if(!$)throw new e("Usage: dun posts reschedule <id> --at|--in",O.USAGE);let w={scheduledAt:v({at:Z(d,"at"),in:Z(d,"in")})},y=Z(d,"text","content","c","t");if(y)w.content=y;let z=S(d);if(z.length)w.mediaUrls=z;let q=B(d);if(q)w.metadata=q;if(!w.content){let k=await n.get(`/api/posts/${$}`,{workspace:!0});if(w.content=k.content,!w.metadata&&k.metadata)w.metadata=k.metadata;if(!w.mediaUrls&&k.mediaUrls)w.mediaUrls=k.mediaUrls}let V=await n.post(`/api/posts/${$}/reschedule`,w,{workspace:!0});X(V,u);return}case"cancel":{let $=D[0];if(!$)throw new e("Usage: dun posts cancel <id>",O.USAGE);let U=await n.post(`/api/posts/${$}/cancel`,void 0,{workspace:!0});X(U??{id:$,status:"cancelled"},u);return}case"delete":case"rm":{let $=D[0];if(!$)throw new e("Usage: dun posts delete <id> [--yes]",O.USAGE);if(!u.yes&&!Q(d,"yes","y"))throw new e("Refusing to delete without --yes (or CI/yes mode)",O.VALIDATION);let U=await n.delete(`/api/posts/${$}`,void 0,{workspace:!0});X(U??{id:$,deleted:!0},u);return}case"x-cap":case"xcap":{let $=await n.get("/api/posts/x-cap-usage",{workspace:!0});X($,u);return}case"schedule-thread":case"publish-thread":case"publish-thread-now":{let $=Z(d,"file","f"),U=Z(d,"account","accounts","a")??h(d)[0];if(!U)throw new e("Missing --account <xAccountId>",O.VALIDATION);let w;if($){let z;try{z=zd($,"utf8")}catch(V){throw new e(`Could not read file: ${V.message}`,O.VALIDATION)}let q=JSON.parse(z);if(Array.isArray(q))w=q;else if(q&&typeof q==="object"&&Array.isArray(q.tweets))w=q.tweets;else throw new e("Thread file must be an array of tweets or { tweets: [] }",O.VALIDATION)}else{let z=Z(d,"text","content");if(!z)throw new e('Provide --file thread.json (array of {content}) or --text "tweet1||tweet2"',O.VALIDATION);w=z.split("||").map((q)=>({content:q.trim()})).filter((q)=>q.content)}if(w.length<2)throw new e("Threads require at least 2 tweets",O.VALIDATION);if(m==="schedule-thread"){let z=v({at:Z(d,"at"),in:Z(d,"in")}),q=await n.post("/api/posts/schedule-thread",{socialAccountId:U,tweets:w,scheduledAt:z,metadata:B(d)??{}},{workspace:!0});X(q,u);return}let y=await n.post("/api/posts/publish-thread-now",{socialAccountId:U,tweets:w,metadata:B(d)??{}},{workspace:!0});X(y,u);return}default:throw new e(`Unknown posts command "${m??""}". Try: list, get, validate, schedule, publish, reschedule, cancel, delete, x-cap, schedule-thread, publish-thread`,O.USAGE)}}async function Ru(u,m,d,D){G(u),b(u);let n=R(u);switch(m){case"list":case"ls":{let $=await n.get("/api/drafts",{workspace:!0,query:{limit:T(d,"limit")??50,offset:T(d,"offset")??0}});X($,{...u,emptyMessage:'No drafts yet. Create one with dun drafts create --text "..."'});return}case"get":{let $=D[0];if(!$)throw new e("Usage: dun drafts get <id>",O.USAGE);let U=await n.get(`/api/drafts/${$}`,{workspace:!0});X(U,u);return}case"create":{let $=Z(d,"text","content","c","t");if(!$)throw new e("Missing --text",O.VALIDATION);let U=await n.post("/api/drafts",{content:$,name:Z(d,"name","n"),socialAccountIds:I(d,"accounts","account","a")??[],selectedPlatforms:I(d,"platforms","platform","p")??[],mediaUrls:I(d,"media")??[]},{workspace:!0});X(U,u);return}case"update":{let $=D[0];if(!$)throw new e("Usage: dun drafts update <id> --text ...",O.USAGE);let U={id:$},w=Z(d,"text","content","c","t");if(w)U.content=w;let y=Z(d,"name","n");if(y!==void 0)U.name=y;let z=I(d,"accounts","account","a");if(z)U.socialAccountIds=z;let q=I(d,"platforms","platform","p");if(q)U.selectedPlatforms=q;let V=I(d,"media");if(V)U.mediaUrls=V;let k=await n.patch(`/api/drafts/${$}`,U,{workspace:!0});X(k,u);return}case"delete":case"rm":{let $=D[0];if(!$)throw new e("Usage: dun drafts delete <id> [--yes]",O.USAGE);if(!u.yes&&!Q(d,"yes","y"))throw new e("Refusing to delete without --yes",O.VALIDATION);let U=await n.delete(`/api/drafts/${$}`,void 0,{workspace:!0});X(U??{id:$,deleted:!0},u);return}default:throw new e(`Unknown drafts command "${m??""}". Try: list, get, create, update, delete`,O.USAGE)}}import{readFileSync as Vd,existsSync as Qd,statSync as Jd}from"node:fs";import{basename as Rd}from"node:path";var Gu=["image/jpeg","image/png","image/gif","image/webp"],Yu=["video/mp4","video/quicktime","video/webm"];function bu(u){if(u<1024)return`${u}B`;if(u<1048576)return`${(u/1024).toFixed(1)}KB`;return`${(u/1048576).toFixed(1)}MB`}function Fu(u){let{mimeType:m,fileSize:d}=u,D=Gu.includes(m),n=Yu.includes(m);if(!D&&!n)return{ok:!1,message:`Unsupported MIME type "${m}". Allowed images: ${Gu.join(", ")}; videos: ${Yu.join(", ")}`};if(n&&d>268435456)return{ok:!1,message:`Video files must be less than 256MB (got ${bu(d)}). Compress first, e.g.:
|
|
241
|
-
ffmpeg -i input.mp4 -vf scale=-2:1080 -c:v libx264 -crf 23 -c:a aac output.mp4`};if(
|
|
242
|
-
Example: dun reddit flairs tamilyapping --json`,
|
|
243
|
-
`),
|
|
244
|
-
|
|
245
|
-
${
|
|
246
|
-
`;else
|
|
247
|
-
`;return await
|
|
248
|
-
Try: dun skill list`,
|
|
239
|
+
`)}else process.stderr.write(JSON.stringify({ok:!0,phase:"waiting",userCode:s.userCode,verificationUrlComplete:s.verificationUrlComplete})+`
|
|
240
|
+
`);if(c&&process.stdout.isTTY)try{await dt(s.verificationUrlComplete)}catch{}let r=Math.max(3,s.interval||5)*1000,o=Date.now()+(s.expiresIn||900)*1000;while(Date.now()<o){await ct(r);let i=await t.post("/api/cli/auth/poll",{deviceCode:s.deviceCode},{auth:!1});if(i.status==="pending")continue;if(i.status==="expired")throw new d("Login expired. Run dun auth login again.",a.AUTH);if(i.status==="denied")throw new d("Login was denied in the browser.",a.AUTH);if(i.status==="approved"){let l=i.token,u={...e,token:l},p=y(u),w=await p.get("/api/user/profile"),g={...e.config,apiUrl:e.apiUrl,token:l,defaultWorkspaceId:i.workspaceId||e.config.defaultWorkspaceId,defaultWorkspaceSlug:e.config.defaultWorkspaceSlug,defaultWorkspaceName:e.config.defaultWorkspaceName};if(i.workspaceId)try{let v=(await p.get("/api/workspaces")).find((Pe)=>Pe.id===i.workspaceId);if(v)g.defaultWorkspaceId=v.id,g.defaultWorkspaceSlug=v.slug,g.defaultWorkspaceName=v.name}catch{}await D(g);let k=Boolean(g.defaultWorkspaceId);if(!e.json&&U(process.stdout)){m(P(k),e);return}m({user:{id:w.id,name:w.name,email:w.email},workspaceId:g.defaultWorkspaceId??null,configPath:L(),method:"device",message:P(k)},e);return}}throw new d("Login timed out. Run dun auth login again.",a.AUTH)}async function ot(e){if(await re(),!e.json&&U(process.stdout)){m("Logged out. Config cleared.",e);return}m({message:"Logged out. Config cleared.",configPath:L()},e)}async function st(e){I(e);let t=await y(e).get("/api/user/profile");m({id:t.id,name:t.name,email:t.email,image:t.image??null,apiUrl:e.apiUrl,workspaceId:e.workspaceId??null},e)}async function at(e){let n=Boolean(e.token),t=null,s=null;if(n)try{t=await y(e).get("/api/user/profile")}catch(c){s=c instanceof Error?c.message:String(c)}m({authenticated:Boolean(t),tokenPresent:n,apiUrl:e.apiUrl,workspaceId:e.workspaceId??null,workspaceSlug:e.config.defaultWorkspaceSlug??null,workspaceName:e.config.defaultWorkspaceName??null,configPath:L(),user:t?{id:t.id,name:t.name,email:t.email}:null,error:s},e)}function ct(e){return new Promise((n)=>setTimeout(n,e))}async function dt(e){let n=process.platform,t=n==="darwin"?["open",e]:n==="win32"?["cmd","/c","start","",e]:["xdg-open",e];await new Promise((s,c)=>{let r=tt(t[0],t.slice(1),{stdio:"ignore",windowsHide:!0});r.on("error",c),r.on("close",()=>s())})}async function ge(e,n,t,s){I(e);let c=y(e);switch(n){case"list":case"ls":{let r=await c.get("/api/workspaces");m(r.map((o)=>({id:o.id,name:o.name,slug:o.slug,role:o.role,timezone:o.timezone,plan:o.subscription?.planName??null,status:o.subscription?.status??null})),{...e,emptyMessage:"No workspaces yet."});return}case"use":{let r=s[0];if(!r)throw new d("Usage: dun workspace use <id|slug>",a.USAGE);let i=(await c.get("/api/workspaces")).find((l)=>l.id===r||l.slug===r);if(!i)throw new d(`Workspace not found: ${r}. Run dun workspace list`,a.NOT_FOUND);await D({...e.config,apiUrl:e.apiUrl,token:e.token,defaultWorkspaceId:i.id,defaultWorkspaceSlug:i.slug,defaultWorkspaceName:i.name}),m({id:i.id,name:i.name,slug:i.slug,role:i.role,message:`Default workspace set to ${i.name}`},e);return}case"current":{if(!e.workspaceId&&!e.config.defaultWorkspaceId)throw new d("No workspace selected. Run dun workspace use <id|slug>",a.VALIDATION);let r=e.workspaceId||e.config.defaultWorkspaceId;try{let i=(await c.get("/api/workspaces")).find((l)=>l.id===r||l.slug===r);if(i){m({id:i.id,name:i.name,slug:i.slug,role:i.role,timezone:i.timezone},e);return}}catch{}m({id:r,name:e.config.defaultWorkspaceName??null,slug:e.config.defaultWorkspaceSlug??null},e);return}default:throw new d(`Unknown workspace command "${n??""}". Try: list, use, current`,a.USAGE)}}async function we(e,n,t,s){I(e),A(e);let c=y(e);switch(n){case void 0:case"list":case"ls":{let r=await c.get("/api/social-accounts",{workspace:!0}),o=f(t,"platform","p")?.toLowerCase(),i=o?r.filter((l)=>{let u=(l.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"],tiktok:["tiktok"]}[o]??[o]).some((g)=>u.includes(g))}):r;m(i.map((l)=>({id:l.id,providerName:l.providerName,username:l.username??null,displayName:l.displayName??null,isConnected:l.isConnected,expiresAt:l.expiresAt??null})),{...e,emptyMessage:o?`No ${o} accounts connected. Connect one in the DunSocial dashboard.`:"No accounts connected. Connect one in the DunSocial dashboard."});return}default:throw new d(`Unknown accounts command "${n}". Try: list (or: dun accounts reddit flairs <subreddit>)`,a.USAGE)}}import{readFileSync as pt}from"node:fs";var lt=/^(\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 J(e,n=new Date){let t=e.trim();if(!t)throw new d("Empty time value",a.VALIDATION);let s=t.match(lt);if(s){let o=Number(s[1]),i=s[2].toLowerCase(),l=ut(i)*o;return new Date(n.getTime()+l)}let c=t.match(/^in\s+(.+)$/i);if(c)return J(c[1],n);let r=new Date(t);if(Number.isNaN(r.getTime()))throw new d(`Invalid time "${e}". Use ISO-8601 (2026-06-01T09:00:00Z) or relative (2h, 30m, 1d).`,a.VALIDATION);return r}function ut(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 d(`Unknown time unit: ${e}`,a.VALIDATION)}}function M(e){if(e.at&&e.in)throw new d("Pass only one of --at or --in",a.VALIDATION);if(e.at)return J(e.at).toISOString();if(e.in)return J(e.in).toISOString();throw new d("Schedule time required. Pass --at <iso> or --in <duration> (e.g. 2h).",a.VALIDATION)}function ke(e){if(!e)return[];return e.split(",").map((n)=>n.trim()).filter(Boolean)}function he(e,n){let t=f(e,"text","content","c","t");if(t)return t;let s=n?.reddit;if(s&&typeof s==="object"&&!Array.isArray(s)&&typeof s.title==="string"&&s.title.trim())return s.title.trim();throw new d("Missing --text",a.VALIDATION)}function q(e){let n=C(e,"accounts","account","a")??ke(f(e,"accounts","account","a"));if(!n||n.length===0)throw new d("Missing --accounts <id,id>",a.VALIDATION);return n}function j(e){return C(e,"media","media-urls")??ke(f(e,"media","media-urls"))}function O(e){let n=f(e,"meta","metadata","meta-json");if(!n)return;try{let t=JSON.parse(n);if(!t||typeof t!=="object"||Array.isArray(t))throw Error("metadata must be a JSON object");return t}catch(t){throw new d(`Invalid --meta JSON: ${t.message}`,a.VALIDATION)}}var mt=new Set(["published","failed","cancelled"]);async function ft(e){await new Promise((n)=>setTimeout(n,e))}async function gt(e,n,t,s){let c=Date.now()+s*1000,r=new Map,o=1500;while(r.size<t.length){if(Date.now()>c){let u=t.filter((p)=>!r.has(p.id)).map((p)=>p.id);throw new d(`Timed out waiting for publish after ${s}s. Still pending: ${u.join(", ")}. Poll with: dun posts get <id> --json`,a.NETWORK,{pending:u})}for(let u of t){if(r.has(u.id))continue;let p=await e.get(`/api/posts/${u.id}`,{workspace:!0});if(R(n.debug,`wait status ${u.id}=${p.status}`),mt.has(p.status))r.set(u.id,p)}if(r.size>=t.length)break;await ft(o),o=Math.min(o*1.4,8000)}let i=t.map((u)=>r.get(u.id)),l=i.filter((u)=>u.status==="failed");if(l.length>0){let u=l.map((p)=>`${p.id}: ${p.error||"publish failed"}`).join("; ");throw new d(`Publish failed — ${u}`,a.VALIDATION,{posts:i})}return i}async function wt(e,n){let t=[],s=n.meta?.reddit??null;if(!s||typeof s!=="object")throw new d("Reddit accounts require --meta with a reddit object, e.g. "+`--meta '{"reddit":{"subreddit":"…","kind":"self","title":"…","flairId":"…"}}'`,a.VALIDATION);let c=(s.subreddit??"").trim().replace(/^\/?r\//i,""),r=(s.title??"").trim(),o=(s.kind??"").trim(),i=(s.flairId??"").trim(),l=(s.flairText??"").trim();if(!c)throw new d("metadata.reddit.subreddit is required",a.VALIDATION);if(!r)throw new d("metadata.reddit.title is required",a.VALIDATION);if(r.length>300)throw new d(`Reddit title exceeds 300 characters: ${r.length}/300`,a.VALIDATION);if(!["self","link","image","video"].includes(o))throw new d("metadata.reddit.kind must be one of: self, link, image, video",a.VALIDATION);if(t.push(`kind=${o}`),t.push(`titleLength=${r.length}`),l&&!i)throw new d(`Can't set flairText without flairId for r/${c}. Run: dun reddit flairs ${c} --json`,a.VALIDATION);if(o==="link"){if(!s.url?.trim())throw new d("Reddit link posts require metadata.reddit.url",a.VALIDATION);try{new URL(s.url)}catch{throw new d("metadata.reddit.url is invalid",a.VALIDATION)}if(n.media.length>0)throw new d("Reddit link posts do not accept --media",a.VALIDATION)}else if(o==="image"||o==="video"){if(n.media.length!==1)throw new d(`Reddit ${o} posts require exactly one --media asset id`,a.VALIDATION)}else if(n.media.length>0)throw new d("Reddit self posts do not accept --media. Use kind image or video.",a.VALIDATION);let u=await e.get("/api/social-accounts/reddit/post-requirements",{workspace:!0,query:{subreddit:c}});if(t.push("fetched post-requirements"),u?.is_flair_required&&!i)throw new d(`r/${c} requires post flair. Discover ids with: dun reddit flairs ${c} --json`,a.VALIDATION);let p=u?.title_text_max_length??300;if(r.length>p)throw new d(`Reddit title too long for r/${c}: ${r.length}/${p}`,a.VALIDATION);if(u?.title_text_min_length&&r.length<u.title_text_min_length)throw new d(`Reddit title must be at least ${u.title_text_min_length} characters`,a.VALIDATION);if(i){let w=await e.get("/api/social-accounts/reddit/flair-options",{workspace:!0,query:{subreddit:c}});t.push(`fetched ${w.choices?.length??0} flairs`);let g=(w.choices??[]).find((k)=>k.id===i);if(!g)throw new d(`Unknown flairId "${i}" for r/${c}. Run: dun reddit flairs ${c} --json`,a.VALIDATION);if(g.textEditable===!1&&l&&l!==g.text)throw new d(`Customization not allowed for this flair template. Use flairId "${g.id}" alone`+(g.text?` (template text: "${g.text}")`:""),a.VALIDATION);t.push(`flairId=${g.id}`)}return{ok:!0,checks:t,reddit:{subreddit:c,kind:o,title:r,flairId:i||null,accounts:n.accounts,media:n.media,textPreview:n.text?.slice(0,120)??null,requirements:{is_flair_required:u?.is_flair_required??!1,title_text_max_length:p}}}}async function ye(e,n,t,s){I(e),A(e);let c=y(e);switch(n){case"list":case"ls":{let r=await c.get("/api/posts",{workspace:!0,query:{status:f(t,"status","s"),socialAccountId:f(t,"account","social-account"),groupId:f(t,"group"),limit:E(t,"limit")??50,offset:E(t,"offset")??0}});m(r,{...e,emptyMessage:"No posts yet. Schedule one with dun posts schedule."});return}case"get":{let r=s[0];if(!r)throw new d("Usage: dun posts get <id>",a.USAGE);let o=await c.get(`/api/posts/${r}`,{workspace:!0});m(o,e);return}case"validate":{let r=q(t),o=j(t),i=O(t)??{},l=f(t,"text","content","c","t"),u=Boolean(i.reddit),p=u;if(!u){let g=await c.get("/api/social-accounts",{workspace:!0});p=r.some((k)=>(g.find((v)=>v.id===k)?.providerName||"").toLowerCase().includes("reddit"))}if(!p){m({ok:!0,checks:["no reddit-specific rules for selected accounts"],accounts:r,media:o},e);return}let w=await wt(c,{accounts:r,text:l,media:o,meta:i});m(w,e);return}case"schedule":{let r=O(t)??{},o=he(t,r),i=q(t),l=M({at:f(t,"at"),in:f(t,"in")}),u=await c.post("/api/posts/schedule",{content:o,socialAccountIds:i,scheduledAt:l,mediaUrls:j(t),metadata:r},{workspace:!0});m(u,e);return}case"publish":case"publish-now":{let r=O(t)??{},o=he(t,r),i=q(t),l=await c.post("/api/posts/publish-now",{content:o,socialAccountIds:i,mediaUrls:j(t),metadata:r,naturalPosting:h(t,"natural","natural-posting")},{workspace:!0});if(!h(t,"wait")){m(l,e);return}let p=Array.isArray(l)?l:[];if(p.length===0||!p.every((k)=>typeof k?.id==="string"))throw new d("publish --wait expected an array of created posts with ids",a.NETWORK,{data:l});let w=E(t,"wait-timeout","timeout")??120,g=await gt(c,e,p,w);m({queued:p,posts:g,status:g.every((k)=>k.status==="published")?"published":g[0]?.status},e);return}case"reschedule":{let r=s[0];if(!r)throw new d("Usage: dun posts reschedule <id> --at|--in",a.USAGE);let i={scheduledAt:M({at:f(t,"at"),in:f(t,"in")})},l=f(t,"text","content","c","t");if(l)i.content=l;let u=j(t);if(u.length)i.mediaUrls=u;let p=O(t);if(p)i.metadata=p;if(!i.content){let g=await c.get(`/api/posts/${r}`,{workspace:!0});if(i.content=g.content,!i.metadata&&g.metadata)i.metadata=g.metadata;if(!i.mediaUrls&&g.mediaUrls)i.mediaUrls=g.mediaUrls}let w=await c.post(`/api/posts/${r}/reschedule`,i,{workspace:!0});m(w,e);return}case"cancel":{let r=s[0];if(!r)throw new d("Usage: dun posts cancel <id>",a.USAGE);let o=await c.post(`/api/posts/${r}/cancel`,void 0,{workspace:!0});m(o??{id:r,status:"cancelled"},e);return}case"delete":case"rm":{let r=s[0];if(!r)throw new d("Usage: dun posts delete <id> [--yes]",a.USAGE);if(!e.yes&&!h(t,"yes","y"))throw new d("Refusing to delete without --yes (or CI/yes mode)",a.VALIDATION);let o=await c.delete(`/api/posts/${r}`,void 0,{workspace:!0});m(o??{id:r,deleted:!0},e);return}case"x-cap":case"xcap":{let r=await c.get("/api/posts/x-cap-usage",{workspace:!0});m(r,e);return}case"schedule-thread":case"publish-thread":case"publish-thread-now":{let r=f(t,"file","f"),o=f(t,"account","accounts","a")??q(t)[0];if(!o)throw new d("Missing --account <xAccountId>",a.VALIDATION);let i;if(r){let u;try{u=pt(r,"utf8")}catch(w){throw new d(`Could not read file: ${w.message}`,a.VALIDATION)}let p=JSON.parse(u);if(Array.isArray(p))i=p;else if(p&&typeof p==="object"&&Array.isArray(p.tweets))i=p.tweets;else throw new d("Thread file must be an array of tweets or { tweets: [] }",a.VALIDATION)}else{let u=f(t,"text","content");if(!u)throw new d('Provide --file thread.json (array of {content}) or --text "tweet1||tweet2"',a.VALIDATION);i=u.split("||").map((p)=>({content:p.trim()})).filter((p)=>p.content)}if(i.length<2)throw new d("Threads require at least 2 tweets",a.VALIDATION);if(n==="schedule-thread"){let u=M({at:f(t,"at"),in:f(t,"in")}),p=await c.post("/api/posts/schedule-thread",{socialAccountId:o,tweets:i,scheduledAt:u,metadata:O(t)??{}},{workspace:!0});m(p,e);return}let l=await c.post("/api/posts/publish-thread-now",{socialAccountId:o,tweets:i,metadata:O(t)??{}},{workspace:!0});m(l,e);return}default:throw new d(`Unknown posts command "${n??""}". Try: list, get, validate, schedule, publish, reschedule, cancel, delete, x-cap, schedule-thread, publish-thread`,a.USAGE)}}async function Ie(e,n,t,s){I(e),A(e);let c=y(e);switch(n){case"list":case"ls":{let r=await c.get("/api/drafts",{workspace:!0,query:{limit:E(t,"limit")??50,offset:E(t,"offset")??0}});m(r,{...e,emptyMessage:'No drafts yet. Create one with dun drafts create --text "..."'});return}case"get":{let r=s[0];if(!r)throw new d("Usage: dun drafts get <id>",a.USAGE);let o=await c.get(`/api/drafts/${r}`,{workspace:!0});m(o,e);return}case"create":{let r=f(t,"text","content","c","t");if(!r)throw new d("Missing --text",a.VALIDATION);let o=await c.post("/api/drafts",{content:r,name:f(t,"name","n"),socialAccountIds:C(t,"accounts","account","a")??[],selectedPlatforms:C(t,"platforms","platform","p")??[],mediaUrls:C(t,"media")??[]},{workspace:!0});m(o,e);return}case"update":{let r=s[0];if(!r)throw new d("Usage: dun drafts update <id> --text ...",a.USAGE);let o={id:r},i=f(t,"text","content","c","t");if(i)o.content=i;let l=f(t,"name","n");if(l!==void 0)o.name=l;let u=C(t,"accounts","account","a");if(u)o.socialAccountIds=u;let p=C(t,"platforms","platform","p");if(p)o.selectedPlatforms=p;let w=C(t,"media");if(w)o.mediaUrls=w;let g=await c.patch(`/api/drafts/${r}`,o,{workspace:!0});m(g,e);return}case"delete":case"rm":{let r=s[0];if(!r)throw new d("Usage: dun drafts delete <id> [--yes]",a.USAGE);if(!e.yes&&!h(t,"yes","y"))throw new d("Refusing to delete without --yes",a.VALIDATION);let o=await c.delete(`/api/drafts/${r}`,void 0,{workspace:!0});m(o??{id:r,deleted:!0},e);return}default:throw new d(`Unknown drafts command "${n??""}". Try: list, get, create, update, delete`,a.USAGE)}}import{readFileSync as ht,existsSync as kt,statSync as yt}from"node:fs";import{basename as It}from"node:path";var be=["image/jpeg","image/png","image/gif","image/webp"],Ae=["video/mp4","video/quicktime","video/webm"];function Se(e){if(e<1024)return`${e}B`;if(e<1048576)return`${(e/1024).toFixed(1)}KB`;return`${(e/1048576).toFixed(1)}MB`}function Te(e){let{mimeType:n,fileSize:t}=e,s=be.includes(n),c=Ae.includes(n);if(!s&&!c)return{ok:!1,message:`Unsupported MIME type "${n}". Allowed images: ${be.join(", ")}; videos: ${Ae.join(", ")}`};if(c&&t>268435456)return{ok:!1,message:`Video files must be less than 256MB (got ${Se(t)}). Compress first, e.g.:
|
|
241
|
+
ffmpeg -i input.mp4 -vf scale=-2:1080 -c:v libx264 -crf 23 -c:a aac output.mp4`};if(s&&t>8388608)return{ok:!1,message:`Image files must be less than 8MB (got ${Se(t)}).`};return{ok:!0}}function bt(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 Ne(e,n,t,s){I(e),A(e);let c=y(e);switch(n){case"list":case"ls":{let r=await c.get("/api/media",{workspace:!0,query:{limit:E(t,"limit")??50,offset:E(t,"offset")??0}});m(r,{...e,emptyMessage:"No media yet. Upload with dun media upload <file>."});return}case"get":{let r=s[0];if(!r)throw new d("Usage: dun media get <id>",a.USAGE);let o=await c.get(`/api/media/${r}`,{workspace:!0});m(o,e);return}case"upload":{let r=s[0]||f(t,"file","f");if(!r)throw new d('Usage: dun media upload <file> [--alt "..."]',a.USAGE);if(!kt(r))throw new d(`File not found: ${r}`,a.VALIDATION);let o=It(r),i=yt(r).size,l=f(t,"mime","type","content-type")||bt(o),u=f(t,"alt","alt-text"),p=Te({mimeType:l,fileSize:i});if(!p.ok)throw new d(p.message,a.VALIDATION);let w=await c.post("/api/media/upload-url",{filename:o,mimeType:l,fileSize:i},{workspace:!0});R(e.debug,`PUT ${w.uploadUrl}`,{storageKey:w.storageKey,fileSize:i});let g=ht(r),k;try{k=await fetch(w.uploadUrl,{method:"PUT",headers:{"Content-Type":l,"Content-Length":String(i)},body:g})}catch(v){throw new d(`Upload PUT failed: ${v.message}`,a.NETWORK)}if(!k.ok){let v=await k.text().catch(()=>"");throw new d(`Upload PUT failed with HTTP ${k.status}${v?`: ${v.slice(0,200)}`:""}`,a.NETWORK)}let x=await c.post("/api/media/complete",{storageKey:w.storageKey,originalFilename:o,mimeType:l,fileSize:i,altText:u},{workspace:!0});m(x,e);return}case"delete":case"rm":{let r=s[0];if(!r)throw new d("Usage: dun media delete <id> [--yes]",a.USAGE);if(!e.yes&&!h(t,"yes","y"))throw new d("Refusing to delete without --yes",a.VALIDATION);let o=await c.delete(`/api/media/${r}`,void 0,{workspace:!0});m(o??{id:r,deleted:!0},e);return}default:throw new d(`Unknown media command "${n??""}". Try: list, get, upload, delete`,a.USAGE)}}async function Ee(e,n,t,s){I(e),A(e);let c=y(e),r=n[0];if(r==="collections"||r==="collection"){let o=n[1]||"list";switch(o){case"list":case"ls":{let i=await c.get("/api/memory/collections",{workspace:!0});m(i,{...e,emptyMessage:'No memory collections yet. Create one with dun memory collections create --name "..."'});return}case"create":{let i=f(t,"name","n");if(!i)throw new d("Missing --name",a.VALIDATION);let l=await c.post("/api/memory/collections",{name:i,color:f(t,"color")??"blue",isPrivate:h(t,"private")},{workspace:!0});m(l,e);return}case"get":{let i=n[2]||s[0];if(!i)throw new d("Usage: dun memory collections get <id>",a.USAGE);let l=await c.get(`/api/memory/collections/${i}`,{workspace:!0});m(l,e);return}case"update":{let i=n[2]||s[0];if(!i)throw new d("Usage: dun memory collections update <id> [--name] [--color] [--private|--public]",a.USAGE);let l=f(t,"name","n"),u=f(t,"color"),p=h(t,"private"),w=h(t,"public");if(p&&w)throw new d("Use either --private or --public, not both",a.VALIDATION);let g={};if(l)g.name=l;if(u)g.color=u;if(p)g.isPrivate=!0;if(w)g.isPrivate=!1;if(Object.keys(g).length===0)throw new d("Provide at least one of --name, --color, --private, or --public",a.VALIDATION);let k=await c.patch(`/api/memory/collections/${i}`,g,{workspace:!0});m(k,e);return}case"delete":case"rm":{let i=n[2]||s[0];if(!i)throw new d("Usage: dun memory collections delete <id> [--yes]",a.USAGE);if(!e.yes&&!h(t,"yes","y"))throw new d("Refusing to delete without --yes",a.VALIDATION);let l=await c.delete(`/api/memory/collections/${i}`,void 0,{workspace:!0});m(l??{id:i,deleted:!0},e);return}default:throw new d(`Unknown memory collections command "${o}". Try: list, create, get, update, delete`,a.USAGE)}}switch(r){case"list":case"ls":{let o=f(t,"collection","collection-id","c");if(!o)throw new d("Missing --collection <id>",a.VALIDATION);let i=await c.get("/api/memory",{workspace:!0,query:{collectionId:o,limit:E(t,"limit")??100}});m(i,{...e,emptyMessage:"No memories in this collection."});return}case"save":case"add":{let o=f(t,"collection","collection-id","c"),i=f(t,"text","t");if(!o)throw new d("Missing --collection <id>",a.VALIDATION);if(!i)throw new d("Missing --text",a.VALIDATION);let l=await c.post("/api/memory",{collectionId:o,text:i},{workspace:!0});m(l,e);return}case"search":{let o=f(t,"prompt","q","query","text"),i=C(t,"collections","collection","collection-ids","c")??[];if(!o)throw new d("Missing --prompt",a.VALIDATION);if(i.length===0)throw new d("Missing --collections <id,id>",a.VALIDATION);let l=await c.post("/api/memory/search",{prompt:o,collectionIds:i,topK:E(t,"top-k","topk","k")??5},{workspace:!0});m(l,e);return}case"delete":case"rm":{let o=n[1]||s[0],i=f(t,"collection","collection-id","c");if(!o)throw new d("Usage: dun memory delete <id> --collection <id>",a.USAGE);if(!i)throw new d("Missing --collection <id>",a.VALIDATION);if(!e.yes&&!h(t,"yes","y"))throw new d("Refusing to delete without --yes",a.VALIDATION);let l=await c.delete(`/api/memory/${o}`,{collectionId:i,memoryId:o},{workspace:!0});m(l??{id:o,deleted:!0},e);return}default:throw new d(`Unknown memory command "${r??""}". Try: collections, list, save, search, delete`,a.USAGE)}}import{readFileSync as At}from"node:fs";async function Ce(e,n,t,s){I(e);let c=A(e),r=y(e),o=`/api/workspaces/${c}/ai-voice-settings`;switch(n){case"get":case"show":case void 0:{let i=await r.get(o,{workspace:!0});m(i??{personalization:null,hint:'No personalization set. Use dun personalization set --description "..."'},e);return}case"set":case"update":{let i=h(t,"clear"),l=f(t,"description","d"),u=f(t,"file","f");if([i,Boolean(l),Boolean(u)].filter(Boolean).length!==1)throw new d("Use exactly one of --description, --file, or --clear",a.VALIDATION);let w;if(i)w=null;else if(u){let k;try{k=At(u,"utf8").trim()}catch(x){throw new d(`Could not read file: ${x.message}`,a.VALIDATION)}if(!k)throw new d("File is empty",a.VALIDATION);w={description:k}}else{let k=l.trim();if(!k)throw new d("--description cannot be empty",a.VALIDATION);w={description:k}}let g=await r.patch(o,w,{workspace:!0});m(g,e);return}default:throw new d(`Unknown personalization command "${n}". Try: get, set`,a.USAGE)}}function ve(e){return e.trim().replace(/^\/?r\//i,"").replace(/^@/,"")}async function Y(e,n,t,s){I(e),A(e);let c=y(e);switch(n){case"flairs":case"flair":case"flair-options":{let r=s[0]||f(t,"subreddit","sub","r");if(!r)throw new d(`Usage: dun reddit flairs <subreddit>
|
|
242
|
+
Example: dun reddit flairs tamilyapping --json`,a.USAGE);let o=ve(r),l=((await c.get("/api/social-accounts/reddit/flair-options",{workspace:!0,query:{subreddit:o}})).choices??[]).map((u)=>({id:u.id,text:u.text,textEditable:u.textEditable!==!1}));m({subreddit:o,choices:l},{...e,emptyMessage:`No flairs returned for r/${o}. The subreddit may not use post flair.`});return}case"requirements":case"post-requirements":{let r=s[0]||f(t,"subreddit","sub","r");if(!r)throw new d("Usage: dun reddit requirements <subreddit>",a.USAGE);let o=ve(r),i=await c.get("/api/social-accounts/reddit/post-requirements",{workspace:!0,query:{subreddit:o}});m({subreddit:o,requirements:i},e);return}default:throw new d(`Unknown reddit command "${n??""}". Try: flairs, requirements`,a.USAGE)}}import{existsSync as St}from"node:fs";import{mkdir as Oe,writeFile as $e,readFile as xe}from"node:fs/promises";import{dirname as Q,join as b}from"node:path";import{homedir as ee}from"node:os";import{fileURLToPath as Tt}from"node:url";var W=[{id:"claude",label:"Claude Code",aliases:["claude-code"],dest:(e)=>b(e,".claude","skills","dunsocial","SKILL.md")},{id:"codex",label:"Codex",dest:(e)=>b(e,".codex","skills","dunsocial","SKILL.md"),afterInstall:async(e)=>({agentsPath:await vt(e)})},{id:"cursor",label:"Cursor",dest:(e)=>b(e,".cursor","skills","dunsocial","SKILL.md")},{id:"pi",label:"Pi",dest:(e)=>b(e,".pi","agent","skills","dunsocial","SKILL.md")},{id:"opencode",label:"OpenCode",dest:(e)=>b(e,".config","opencode","skills","dunsocial","SKILL.md")},{id:"agents",label:"Universal (.agents)",aliases:["universal"],dest:(e)=>b(e,".agents","skills","dunsocial","SKILL.md")},{id:"copilot",label:"GitHub Copilot",aliases:["github-copilot","github"],dest:(e)=>b(e,".copilot","skills","dunsocial","SKILL.md")},{id:"windsurf",label:"Windsurf",dest:(e)=>b(e,".codeium","windsurf","skills","dunsocial","SKILL.md")},{id:"goose",label:"Goose",dest:(e)=>b(e,".config","goose","skills","dunsocial","SKILL.md")},{id:"gemini",label:"Gemini CLI",aliases:["gemini-cli"],dest:(e)=>b(e,".gemini","skills","dunsocial","SKILL.md")},{id:"amp",label:"Amp",dest:(e)=>b(e,".config","agents","skills","dunsocial","SKILL.md")},{id:"grok",label:"Grok Build",dest:(e)=>b(e,".grok","skills","dunsocial","SKILL.md")},{id:"continue",label:"Continue",dest:(e)=>b(e,".continue","skills","dunsocial","SKILL.md")},{id:"antigravity",label:"Antigravity",dest:(e)=>b(e,".gemini","antigravity","skills","dunsocial","SKILL.md")}],X=new Map;for(let e of W){X.set(e.id,e);for(let n of e.aliases??[])X.set(n,e)}var Ue=`Usage: dun skill install <${W.map((e)=>e.id).join("|")}|all>`;function Z(){let e=Q(Tt(import.meta.url)),n=b("skills","dunsocial","SKILL.md"),t=[b(e,"..",n),b(e,"..","..",n)];return t.find(St)??t[0]}function Nt(){let e=ee();return W.map((n)=>({id:n.id,label:n.label,path:n.dest(e),aliases:n.aliases??[]}))}async function Et(){try{return await xe(Z(),"utf8")}catch{throw new d(`Bundled skill not found at ${Z()}. Reinstall dunsocial.`,a.USAGE)}}async function Ct(e,n){await Oe(Q(e),{recursive:!0}),await $e(e,n,"utf8")}async function vt(e){let n=b(ee(),".codex","AGENTS.md");await Oe(Q(n),{recursive:!0});let t="";try{t=await xe(n,"utf8")}catch{t=""}let s=["<!-- BEGIN DUNSOCIAL CLI SKILL -->","## DunSocial CLI","","Use the `dun` CLI for DunSocial scheduling from the shell. Prefer `--json` output.",`Skill details: ${e}`,"","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(`
|
|
243
|
+
`),c="<!-- BEGIN DUNSOCIAL CLI SKILL -->",r="<!-- END DUNSOCIAL CLI SKILL -->",o,i=t.indexOf(c),l=t.indexOf(r);if(i!==-1&&l!==-1&&l>i)o=t.slice(0,i)+s+t.slice(l+r.length);else if(t.trim())o=`${t.trimEnd()}
|
|
244
|
+
|
|
245
|
+
${s}
|
|
246
|
+
`;else o=`${s}
|
|
247
|
+
`;return await $e(n,o,"utf8"),n}async function Re(e,n){let t=e.dest(ee());await Ct(t,n);let s=e.afterInstall?await e.afterInstall(t):{};return{target:e.id,path:t,message:`Installed DunSocial skill for ${e.label}. Restart or open a new session if needed.`,...s}}async function Le(e,n,t,s){switch(n){case"path":{m({path:Z()},e);return}case"list":{m({targets:Nt(),hint:"Install with: dun skill install <target|all>"},e);return}case"install":{let c=(s[0]||"").toLowerCase();if(!c)throw new d(Ue,a.USAGE);let r=await Et();if(c==="all"){let l=[];for(let u of W){let p=await Re(u,r);l.push({target:p.target,path:p.path})}m({target:"all",count:l.length,installed:l,message:`Installed DunSocial skill for ${l.length} agents.`},e);return}let o=X.get(c);if(!o)throw new d(`Unknown agent "${c}". ${Ue}
|
|
248
|
+
Try: dun skill list`,a.USAGE);let i=await Re(o,r);m(i,e);return}default:throw new d(`Unknown skill command "${n??""}". Try: install, list, path`,a.USAGE)}}import{spawn as Ut}from"node:child_process";import{realpathSync as Rt}from"node:fs";var T="dunsocial",Ot=`https://registry.npmjs.org/${T}/latest`;function $t(e=process.argv[1]??""){let n=e.replaceAll("\\","/");try{n=Rt(e).replaceAll("\\","/")}catch{}if(n.includes("/.npm/_npx")||n.includes("/npm/_npx")||n.includes("/_npx/"))return{packageManager:"npx",manual:`npm install -g ${T}@latest`};if(n.includes("/.pnpm/")||n.includes("/pnpm/"))return{packageManager:"pnpm",command:"pnpm",args:["add","-g",`${T}@latest`],manual:`pnpm add -g ${T}@latest`};if(n.includes("/.yarn/")||n.includes("/yarn/global"))return{packageManager:"yarn",command:"yarn",args:["global","add",`${T}@latest`],manual:`yarn global add ${T}@latest`};if(n.includes("/.bun/")||n.includes("/bun/install/global"))return{packageManager:"bun",command:"bun",args:["add","-g",`${T}@latest`],manual:`bun add -g ${T}@latest`};if(n.includes(`/node_modules/${T}/`))return{packageManager:"npm",command:"npm",args:["install","-g",`${T}@latest`],manual:`npm install -g ${T}@latest`};return{packageManager:"unknown",manual:`npm install -g ${T}@latest`}}function xt(e,n){let t=e.replace(/^v/,"").split(".").map((r)=>Number.parseInt(r,10)||0),s=n.replace(/^v/,"").split(".").map((r)=>Number.parseInt(r,10)||0),c=Math.max(t.length,s.length);for(let r=0;r<c;r++){let o=t[r]??0,i=s[r]??0;if(o>i)return 1;if(o<i)return-1}return 0}async function Lt(e=fetch){let n=await e(Ot,{headers:{Accept:"application/json"}});if(!n.ok)throw new d(`Could not check npm for updates (HTTP ${n.status}). Try: npm install -g ${T}@latest`,a.NETWORK);let t=await n.json();if(!t.version)throw new d("npm registry response missing version",a.NETWORK);return t.version}function Dt(e,n){return new Promise((t,s)=>{let c=Ut(e,n,{stdio:"inherit",env:process.env,windowsHide:!0,shell:process.platform==="win32"});c.on("error",(r)=>{s(new d(`Failed to run ${e}: ${r.message}. Try manually: ${e} ${n.join(" ")}`,a.NETWORK))}),c.on("close",(r)=>t(r??1))})}async function De(e,n,t){let s=h(t,"check"),c=h(t,"force"),r=N,o=$t(),i;try{i=await Lt()}catch(w){if(w instanceof d)throw w;throw new d(`Could not check npm for updates: ${w.message}`,a.NETWORK)}let l=xt(i,r)>0,u={current:r,latest:i,upToDate:!l,packageManager:o.packageManager,command:o.manual};if(!l&&!c){m(e.json?u:`Already on the latest version (${r}).`,e);return}if(s){m(e.json?{...u,updateAvailable:l}:`Update available: ${r} → ${i}
|
|
249
249
|
Run: dun update
|
|
250
|
-
Or: ${
|
|
251
|
-
Cannot auto-update this install (${
|
|
252
|
-
Run: ${
|
|
253
|
-
`);let
|
|
254
|
-
|
|
255
|
-
`);process.stdout.write(`${
|
|
256
|
-
`)}async function
|
|
257
|
-
`)}async function
|
|
258
|
-
`),
|
|
259
|
-
`);else
|
|
260
|
-
`),
|
|
250
|
+
Or: ${o.manual}`,e);return}if(!o.command||!o.args){m(e.json?{...u,applied:!1,hint:o.manual}:`Update available: ${r} → ${i}
|
|
251
|
+
Cannot auto-update this install (${o.packageManager}).
|
|
252
|
+
Run: ${o.manual}`,e);return}if(!e.json&&!e.quiet)process.stderr.write(`Updating ${T}: ${r} → ${i} via ${o.packageManager}...
|
|
253
|
+
`);let p=await Dt(o.command,o.args);if(p!==0)throw new d(`Update command failed (exit ${p}). Try: ${o.manual}`,a.NETWORK);m(e.json?{...u,applied:!0}:`Updated via ${o.packageManager}. Run dun --version to confirm.`,e)}function _e(){if(U(process.stdout))process.stdout.write(`${le()}
|
|
254
|
+
|
|
255
|
+
`);process.stdout.write(`${H}
|
|
256
|
+
`)}async function _t(){let e=await G(),n=process.env.DUN_TOKEN||e.token,t=process.env.DUN_WORKSPACE_ID||e.defaultWorkspaceId;process.stdout.write(`${pe({token:n,workspaceId:t,config:e})}
|
|
257
|
+
`)}async function Pt(e){let n=oe(e),{group:t,action:s,nest:c,flags:r,positionals:o}=n;if(K(r)&&!t)return process.stdout.write(`${N}
|
|
258
|
+
`),a.OK;if(t==="help"||!t&&B(r)){let l=t==="help"?s||o[0]:void 0;if(l)process.stdout.write(`${z(l)}
|
|
259
|
+
`);else _e();return a.OK}if(!t){if(U(process.stdout))await _t();else _e();return a.OK}if(B(r))return process.stdout.write(`${z(t)}
|
|
260
|
+
`),a.OK;let i=await ie({apiUrl:f(r,"api-url","apiUrl"),token:f(r,"token"),workspace:f(r,"workspace","w"),json:h(r,"json","j")?!0:void 0,debug:h(r,"debug"),quiet:h(r,"quiet","q"),yes:h(r,"yes","y")});if(K(r))return m({version:N},i),a.OK;try{switch(t){case"auth":await fe(i,s,r,o);break;case"workspace":case"workspaces":await ge(i,s,r,o);break;case"account":case"accounts":if(s==="reddit"){await Y(i,o[0],r,o.slice(1));break}await we(i,s??"list",r,o);break;case"reddit":await Y(i,s,r,o);break;case"post":case"posts":await ye(i,s,r,o);break;case"draft":case"drafts":await Ie(i,s,r,o);break;case"media":await Ne(i,s,r,o);break;case"memory":{let l=c?[c,s].filter(Boolean):s?[s]:[];await Ee(i,l,r,o);break}case"personalization":case"voice":await Ce(i,s,r,o);break;case"skill":case"skills":await Le(i,s,r,o);break;case"update":case"upgrade":case"self-update":await De(i,s,r);break;case"version":m({version:N},i);break;default:throw new d(`Unknown command "${t}". Run dun --help`,a.USAGE)}return a.OK}catch(l){return ae(l,i)}}var Mt=await Pt(process.argv.slice(2));process.exit(Mt);
|
package/package.json
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dunsocial",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.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",
|
|
7
|
-
"
|
|
8
|
-
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/thisuxhq/dunpostsapp.git",
|
|
10
|
-
"directory": "apps/cli"
|
|
11
|
-
},
|
|
12
|
-
"bugs": {
|
|
13
|
-
"url": "https://github.com/thisuxhq/dunpostsapp/issues"
|
|
14
|
-
},
|
|
15
|
-
"homepage": "https://dunsocial.com",
|
|
7
|
+
"homepage": "https://www.dunsocial.com/cli",
|
|
16
8
|
"keywords": [
|
|
17
9
|
"dunsocial",
|
|
18
10
|
"cli",
|