dunsocial 0.8.1 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -2
- package/dist/index.js +131 -159
- package/package.json +1 -1
- package/scripts/postinstall.js +18 -43
- package/skills/dunsocial/SKILL.md +68 -2
package/README.md
CHANGED
|
@@ -6,9 +6,17 @@ Post and schedule to your social accounts from the terminal.
|
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install -g dunsocial
|
|
9
|
+
# or: bun add -g dunsocial / pnpm add -g dunsocial
|
|
9
10
|
```
|
|
10
11
|
|
|
11
|
-
Then use the `dun` command (Node.js 20+).
|
|
12
|
+
Then use the `dun` command (Node.js 20+ — Bun not required at runtime).
|
|
13
|
+
|
|
14
|
+
Upgrade later:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
dun update
|
|
18
|
+
# or: dun update --check
|
|
19
|
+
```
|
|
12
20
|
|
|
13
21
|
---
|
|
14
22
|
|
|
@@ -52,6 +60,59 @@ dun posts publish \
|
|
|
52
60
|
--accounts ACCOUNT_ID
|
|
53
61
|
```
|
|
54
62
|
|
|
63
|
+
`publish` queues the post (`status: scheduled`). To wait until it finishes:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
dun posts publish \
|
|
67
|
+
--text "Hello from DunSocial" \
|
|
68
|
+
--accounts ACCOUNT_ID \
|
|
69
|
+
--wait
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Reddit
|
|
75
|
+
|
|
76
|
+
Reddit needs platform options via `--meta`. Many subreddits also require a flair **template id**.
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
# 1. Upload media first (videos must be under 256MB)
|
|
80
|
+
dun media upload ./demo.mp4 --json
|
|
81
|
+
|
|
82
|
+
# 2. List flairs for the subreddit (use id, not just the label text)
|
|
83
|
+
dun reddit flairs tamilyapping --json
|
|
84
|
+
|
|
85
|
+
# 3. Optional dry-run against subreddit rules
|
|
86
|
+
dun posts validate \
|
|
87
|
+
--accounts REDDIT_ACCOUNT_ID \
|
|
88
|
+
--media ASSET_ID \
|
|
89
|
+
--meta '{"reddit":{"subreddit":"tamilyapping","kind":"video","title":"Your title","flairId":"FLAIR_ID"}}' \
|
|
90
|
+
--json
|
|
91
|
+
|
|
92
|
+
# 4. Publish and wait for the real permalink
|
|
93
|
+
dun posts publish \
|
|
94
|
+
--accounts REDDIT_ACCOUNT_ID \
|
|
95
|
+
--media ASSET_ID \
|
|
96
|
+
--meta '{"reddit":{"subreddit":"tamilyapping","kind":"video","title":"Your title","flairId":"FLAIR_ID"}}' \
|
|
97
|
+
--wait \
|
|
98
|
+
--json
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
`--meta.reddit` fields:
|
|
102
|
+
|
|
103
|
+
| Field | Required | Notes |
|
|
104
|
+
|-------|----------|--------|
|
|
105
|
+
| `subreddit` | yes | without `r/` |
|
|
106
|
+
| `kind` | yes | `self`, `link`, `image`, or `video` |
|
|
107
|
+
| `title` | yes | |
|
|
108
|
+
| `flairId` | when the sub requires flair | from `dun reddit flairs` |
|
|
109
|
+
| `url` | for `link` | |
|
|
110
|
+
| `flairText` | no | only if that flair's `textEditable` is true |
|
|
111
|
+
|
|
112
|
+
Prefer `flairId` alone. Sending `flairText` without `flairId` always fails.
|
|
113
|
+
|
|
114
|
+
Also useful: `dun reddit requirements <subreddit> --json`.
|
|
115
|
+
|
|
55
116
|
---
|
|
56
117
|
|
|
57
118
|
## Automated posting (CI)
|
|
@@ -81,6 +142,8 @@ dun --help
|
|
|
81
142
|
dun auth status
|
|
82
143
|
dun posts list
|
|
83
144
|
dun media upload ./photo.png
|
|
145
|
+
dun reddit flairs some-subreddit
|
|
146
|
+
dun posts validate --accounts ACCOUNT_ID --meta '{"reddit":{…}}'
|
|
84
147
|
dun drafts create --text "Idea for later"
|
|
85
148
|
dun personalization get
|
|
86
149
|
dun personalization set --description "Concise, direct, no fluff."
|
|
@@ -88,8 +151,9 @@ dun personalization set --description "Concise, direct, no fluff."
|
|
|
88
151
|
|
|
89
152
|
Tips:
|
|
90
153
|
|
|
91
|
-
- Help for any command: `dun posts --help`
|
|
154
|
+
- Help for any command: `dun posts --help` / `dun reddit --help`
|
|
92
155
|
- Structured output for scripts: add `--json`
|
|
156
|
+
- Platform-specific options (Reddit, etc.): `--meta '{…}'`
|
|
93
157
|
- Prefer ChatGPT or Claude **in the browser**? Use [MCP](https://docs.dunsocial.com/mcp) instead of the CLI
|
|
94
158
|
- Personalization is workspace-wide AI voice (Settings → Personalization). Updating it needs a token with the `workspace:write` scope
|
|
95
159
|
|
package/dist/index.js
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
${
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{readFileSync as eu}from"node:fs";import{mkdir as hu,readFile as Su,writeFile as pu,chmod as fu,unlink as Eu}from"node:fs/promises";import{dirname as iu,join as f}from"node:path";import{homedir as Cu}from"node:os";var O={OK:0,USAGE:1,AUTH:2,FORBIDDEN:3,VALIDATION:4,NOT_FOUND:5,RATE_LIMITED:6,NETWORK:7};class y extends Error{code;details;constructor(u,$=O.USAGE,w){super(u);this.name="CliError",this.code=$,this.details=w}}function uu(u){if(u===401)return O.AUTH;if(u===403)return O.FORBIDDEN;if(u===404)return O.NOT_FOUND;if(u===429)return O.RATE_LIMITED;if(u>=400&&u<500)return O.VALIDATION;return O.NETWORK}var ou="https://api.dunsocial.com",wu="0.9.1";function gu(){if(!wu.includes("@@"))return wu;try{let u=JSON.parse(eu(f(import.meta.dir,"..","package.json"),"utf8"));if(typeof u.version==="string"&&u.version.length>0)return u.version}catch{}return"0.0.0"}var B=gu();function v(){if(process.env.DUN_CONFIG)return process.env.DUN_CONFIG;let u=process.env.XDG_CONFIG_HOME,$=u?u:f(Cu(),".config");return f($,"dunsocial","config.json")}function j(){return v()}async function E(){let u=v();try{let $=await Su(u,"utf8");return JSON.parse($)}catch($){if($.code==="ENOENT")return{};throw new y(`Failed to read config at ${u}: ${$.message}`,O.USAGE)}}async function L(u){let $=v();await hu(iu($),{recursive:!0});let w={...u,updatedAt:new Date().toISOString()};await pu($,`${JSON.stringify(w,null,2)}
|
|
3
|
+
`,"utf8");try{await fu($,384)}catch{}}async function $u(){let u=v();try{await Eu(u)}catch($){if($.code!=="ENOENT")throw new y(`Failed to clear config: ${$.message}`,O.USAGE)}}async function Uu(u){let $=await E(),w=(u.apiUrl||process.env.DUN_API_URL||$.apiUrl||ou).replace(/\/$/,""),D=u.token||process.env.DUN_TOKEN||$.token,z=u.workspace||process.env.DUN_WORKSPACE_ID||$.defaultWorkspaceId||void 0,U=process.env.DUN_JSON==="0",m=!process.stdout.isTTY,d=U?!1:u.json===!0||process.env.DUN_JSON==="1"||process.env.CI==="true"||process.env.CI==="1"||m;return{apiUrl:w,token:D,workspaceId:z,json:d,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:$}}function F(u){if(!u.token)throw new y("Not authenticated. Run `dun auth login` (or `dun auth login --token <token>` / set DUN_TOKEN).",O.AUTH);return u.token}function W(u){if(!u.workspaceId)throw new y("No workspace selected. Run `dun workspace use <id|slug>` or pass --workspace / DUN_WORKSPACE_ID.",O.VALIDATION);return u.workspaceId}function du(u){let $={},w=[],D=0,z=!0;while(D<u.length){let X=u[D];if(z&&X==="--"){z=!1,D+=1;continue}if(z&&X.startsWith("--")){let Z=X.indexOf("=");if(Z!==-1){$[X.slice(2,Z)]=X.slice(Z+1),D+=1;continue}let J=X.slice(2),G=u[D+1];if(G!==void 0&&!G.startsWith("-"))$[J]=G,D+=2;else $[J]=!0,D+=1;continue}if(z&&X.startsWith("-")&&X.length>1&&X!=="-"){let Z=X.slice(1);if(Z.length>1&&!Z.includes("=")){for(let k of Z)$[k]=!0;D+=1;continue}let J=Z,G=u[D+1];if(G!==void 0&&!G.startsWith("-"))$[J]=G,D+=2;else $[J]=!0,D+=1;continue}w.push(X),D+=1}let U=w[0],m,d,q=1;if(U==="memory"&&(w[1]==="collections"||w[1]==="collection"))d="collections",m=w[2],q=m?3:2;else m=w[1],q=m?2:1;return{group:U,action:m,nest:d,flags:$,positionals:w.slice(q)}}function Q(u,...$){for(let w of $){let D=u[w];if(typeof D==="string"&&D.length>0)return D}return}function R(u,...$){for(let w of $){let D=u[w];if(D===!0)return!0;if(typeof D==="string"){let z=D.toLowerCase();if(z==="1"||z==="true"||z==="yes")return!0}}return!1}function H(u,...$){let w=Q(u,...$);if(w===void 0)return;let D=Number(w);if(!Number.isFinite(D))throw Error(`Invalid number for --${$[0]}: ${w}`);return D}function A(u,...$){let w=Q(u,...$);if(w===void 0)return;return w.split(",").map((D)=>D.trim()).filter(Boolean)}function i(u){return R(u,"help","h")}function C(u){return R(u,"version","v","V")}function V(u,$){if($.quiet&&!$.json)return;if($.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(`${su(u,$.emptyMessage)}
|
|
7
|
+
`)}function Du(u,$){let{message:w,code:D,details:z}=cu(u);if($.json||!process.stdout.isTTY)process.stdout.write(`${JSON.stringify({ok:!1,error:{code:ru(D),message:w,details:z??null}},null,2)}
|
|
8
|
+
`);else if(process.stderr.write(`error: ${w}
|
|
9
|
+
`),z!==void 0&&process.env.DUN_DEBUG==="1")process.stderr.write(`${JSON.stringify(z,null,2)}
|
|
10
|
+
`);return D}function ru(u){switch(u){case O.AUTH:return"auth";case O.FORBIDDEN:return"forbidden";case O.VALIDATION:return"validation";case O.NOT_FOUND:return"not_found";case O.RATE_LIMITED:return"rate_limited";case O.NETWORK:return"network";default:return"usage"}}function cu(u){if(u instanceof y)return{message:u.message,code:u.code,details:u.details};if(u instanceof Error)return{message:u.message,code:O.USAGE};return{message:String(u),code:O.USAGE}}function su(u,$){if(Array.isArray(u)){if(u.length===0)return $??"(empty)";if(u.every((w)=>w&&typeof w==="object"))return mu(u,$);return u.map((w)=>`- ${o(w)}`).join(`
|
|
11
|
+
`)}if(u&&typeof u==="object"){let w=u;if(Array.isArray(w.items)){if(w.items.length===0&&$)return $;let D=typeof w.total==="number"?`total=${w.total} showing=${w.items.length}`:void 0,z=mu(w.items,$);return D?`${D}
|
|
12
|
+
${z}`:z}return Object.entries(w).map(([D,z])=>`${D}: ${o(z)}`).join(`
|
|
13
|
+
`)}return String(u)}function mu(u,$){if(u.length===0)return $??"(empty)";let w=["id","name","slug","status","providerName","username","displayName","role","scheduledAt","content","text","originalFilename","score","collectionId"],D=new Set;for(let X of u)for(let Z of Object.keys(X))D.add(Z);let z=[...w.filter((X)=>D.has(X)),...[...D].filter((X)=>!w.includes(X)).slice(0,6)].slice(0,8),U=u.map((X)=>z.map((Z)=>xu(o(X[Z]),Z==="content"||Z==="text"?48:28))),m=z.map((X,Z)=>Math.max(X.length,...U.map((J)=>J[Z]?.length??0))),d=z.map((X,Z)=>X.padEnd(m[Z])).join(" "),q=U.map((X)=>X.map((Z,J)=>Z.padEnd(m[J])).join(" ")).join(`
|
|
14
|
+
`);return`${d}
|
|
15
|
+
${q}`}function o(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 $=u;if(typeof $.id==="string"&&typeof $.name==="string")return`${$.name} (${$.id})`;if(typeof $.status==="string")return $.status;return JSON.stringify(u)}return String(u)}function xu(u,$){if(u.length<=$)return u;return`${u.slice(0,Math.max(0,$-1))}...`}function M(u,$,w){if(!u)return;if(w!==void 0){process.stderr.write(`[debug] ${$} ${JSON.stringify(w)}
|
|
16
|
+
`);return}process.stderr.write(`[debug] ${$}
|
|
17
|
+
`)}function K(u,$){let w=`${u} ${$}`,D="-".repeat(Math.max(12,w.length+4));return`${w}
|
|
18
|
+
${D}`}var g=`dun - schedule & publish social posts
|
|
16
19
|
|
|
17
20
|
Usage:
|
|
18
21
|
dun <command> [flags]
|
|
19
22
|
|
|
20
|
-
Auth
|
|
23
|
+
${K("\uD83D\uDD10","Auth")}
|
|
21
24
|
dun auth login # device-code browser flow
|
|
22
25
|
dun auth login --token <token> # CI / headless
|
|
23
26
|
dun auth login --no-browser
|
|
@@ -25,38 +28,49 @@ Auth:
|
|
|
25
28
|
dun auth whoami
|
|
26
29
|
dun auth status
|
|
27
30
|
|
|
28
|
-
Workspaces
|
|
31
|
+
${K("\uD83D\uDCC1","Workspaces")}
|
|
29
32
|
dun workspace list
|
|
30
33
|
dun workspace use <id|slug>
|
|
31
34
|
dun workspace current
|
|
32
35
|
|
|
33
|
-
Accounts
|
|
34
|
-
dun accounts list [--platform x]
|
|
36
|
+
${K("\uD83D\uDD17","Accounts")}
|
|
37
|
+
dun accounts list [--platform x|reddit|...]
|
|
35
38
|
|
|
36
|
-
|
|
39
|
+
${K("\uD83D\uDFE0","Reddit")}
|
|
40
|
+
dun reddit flairs <subreddit> # template id + text + textEditable
|
|
41
|
+
dun reddit requirements <subreddit> # live post rules (flair required, ...)
|
|
42
|
+
# alias: dun accounts reddit flairs <subreddit>
|
|
43
|
+
|
|
44
|
+
${K("\uD83D\uDCDD","Posts")}
|
|
37
45
|
dun posts list [--status scheduled|published|failed|draft|cancelled]
|
|
38
46
|
dun posts get <id>
|
|
39
|
-
dun posts
|
|
40
|
-
dun posts
|
|
47
|
+
dun posts validate --accounts <id> [--media id] --meta '{...}'
|
|
48
|
+
dun posts schedule --text "..." --accounts <id,id> (--at ISO | --in 2h) [--media id,id] [--meta '{...}']
|
|
49
|
+
dun posts publish --text "..." --accounts <id,id> [--media id,id] [--meta '{...}'] [--natural] [--wait]
|
|
41
50
|
dun posts reschedule <id> --at ISO|--in 2h [--text "..."]
|
|
42
51
|
dun posts cancel <id>
|
|
43
52
|
dun posts delete <id> [--yes]
|
|
44
53
|
dun posts x-cap
|
|
45
54
|
|
|
46
|
-
|
|
55
|
+
# Reddit --meta example (video):
|
|
56
|
+
# --meta '{"reddit":{"subreddit":"tamilyapping","kind":"video","title":"...","flairId":"..."}}'
|
|
57
|
+
# kinds: self | link | image | video
|
|
58
|
+
# publish queues async work; without --wait, status scheduled means queued
|
|
59
|
+
|
|
60
|
+
${K("\uD83D\uDCC4","Drafts")}
|
|
47
61
|
dun drafts list
|
|
48
62
|
dun drafts get <id>
|
|
49
63
|
dun drafts create --text "..." [--platforms x,linkedin] [--accounts id,id]
|
|
50
64
|
dun drafts update <id> --text "..."
|
|
51
65
|
dun drafts delete <id> [--yes]
|
|
52
66
|
|
|
53
|
-
Media
|
|
67
|
+
${K("\uD83D\uDDBC️","Media")}
|
|
54
68
|
dun media list
|
|
55
69
|
dun media get <id>
|
|
56
|
-
dun media upload <file> [--alt "..."]
|
|
70
|
+
dun media upload <file> [--alt "..."] # local preflight: images <=8MB, video <=256MB
|
|
57
71
|
dun media delete <id> [--yes]
|
|
58
72
|
|
|
59
|
-
Memory
|
|
73
|
+
${K("\uD83E\uDDE0","Memory")}
|
|
60
74
|
dun memory collections list
|
|
61
75
|
dun memory collections create --name "..." [--color blue] [--private]
|
|
62
76
|
dun memory list --collection <id>
|
|
@@ -64,21 +78,29 @@ Memory:
|
|
|
64
78
|
dun memory search --prompt "..." --collections <id,id> [--top-k 5]
|
|
65
79
|
dun memory delete <id> --collection <id> [--yes]
|
|
66
80
|
|
|
67
|
-
Personalization
|
|
81
|
+
${K("\uD83C\uDF99️","Personalization")}
|
|
82
|
+
# workspace AI voice
|
|
68
83
|
dun personalization get
|
|
69
84
|
dun personalization set --description "..."
|
|
70
85
|
dun personalization set --file voice.md
|
|
71
86
|
dun personalization set --clear
|
|
72
87
|
# requires PAT scope workspace:write for set (owner/admin)
|
|
73
88
|
|
|
74
|
-
Agent skills
|
|
89
|
+
${K("\uD83E\uDDE9","Agent skills")}
|
|
75
90
|
dun skill install <agent|all>
|
|
76
91
|
dun skill list
|
|
77
92
|
dun skill path
|
|
78
93
|
# agents: claude codex cursor pi opencode agents copilot windsurf
|
|
79
94
|
# goose gemini amp grok continue antigravity
|
|
80
95
|
|
|
81
|
-
|
|
96
|
+
${K("⬆️","Update")}
|
|
97
|
+
dun update # upgrade to latest from npm
|
|
98
|
+
dun update --check # report only
|
|
99
|
+
dun update --force # reinstall latest even if current
|
|
100
|
+
# aliases: upgrade, self-update
|
|
101
|
+
# detects npm / bun / pnpm / yarn; prints command for npx
|
|
102
|
+
|
|
103
|
+
${K("⚙️","Global flags")}
|
|
82
104
|
--json Machine-readable output (default when non-TTY / CI)
|
|
83
105
|
--workspace <id> Override workspace for this command
|
|
84
106
|
--api-url <url> Override API base (default https://api.dunsocial.com)
|
|
@@ -89,14 +111,14 @@ Global flags:
|
|
|
89
111
|
--help, -h Show help
|
|
90
112
|
--version, -v Show version
|
|
91
113
|
|
|
92
|
-
Env
|
|
114
|
+
${K("\uD83C\uDF31","Env")}
|
|
93
115
|
DUN_TOKEN DUN_WORKSPACE_ID DUN_API_URL DUN_CONFIG DUN_JSON=1 DUN_DEBUG=1
|
|
94
116
|
|
|
95
|
-
Exit codes
|
|
117
|
+
${K("\uD83D\uDEAA","Exit codes")}
|
|
96
118
|
0 ok | 1 usage | 2 auth | 3 forbidden | 4 validation | 5 not found | 6 rate limit | 7 network
|
|
97
119
|
|
|
98
120
|
Docs: https://dunsocial.com/docs/cli
|
|
99
|
-
`;function
|
|
121
|
+
`;function r(u){return{auth:`dun auth
|
|
100
122
|
|
|
101
123
|
login [--token] Device-code browser login (default) or --token for CI
|
|
102
124
|
logout Clear local config
|
|
@@ -107,17 +129,53 @@ Docs: https://dunsocial.com/docs/cli
|
|
|
107
129
|
list List workspaces you belong to
|
|
108
130
|
use <id|slug> Set default workspace
|
|
109
131
|
current Show default workspace
|
|
110
|
-
`,workspaces:"Alias of workspace",accounts
|
|
132
|
+
`,workspaces:"Alias of workspace",accounts:`dun accounts list [--platform <name>]
|
|
133
|
+
dun accounts reddit flairs <subreddit> # alias of dun reddit flairs
|
|
134
|
+
`,reddit:`dun reddit
|
|
135
|
+
|
|
136
|
+
flairs <subreddit> List flair template ids for the connected Reddit account
|
|
137
|
+
requirements <subreddit> Live post requirements (flair required, title limits, ...)
|
|
138
|
+
|
|
139
|
+
Output fields for flairs: id (flair_template_id), text, textEditable
|
|
140
|
+
|
|
141
|
+
Example:
|
|
142
|
+
dun reddit flairs tamilyapping --json
|
|
143
|
+
`,posts:`dun posts
|
|
111
144
|
|
|
112
145
|
list [--status] [--account] [--limit] [--offset]
|
|
113
146
|
get <id>
|
|
114
|
-
|
|
115
|
-
|
|
147
|
+
validate --accounts [--text] [--media] --meta Dry-run Reddit/media rules before enqueue
|
|
148
|
+
schedule --text --accounts (--at|--in) [--media] [--meta]
|
|
149
|
+
publish --text --accounts [--media] [--meta] [--natural] [--wait] [--wait-timeout 120]
|
|
116
150
|
reschedule <id> (--at|--in) [--text]
|
|
117
151
|
cancel <id>
|
|
118
152
|
delete <id> [--yes]
|
|
119
153
|
x-cap
|
|
120
|
-
|
|
154
|
+
|
|
155
|
+
Platform metadata (--meta / --metadata / --meta-json):
|
|
156
|
+
Reddit (required when publishing to a Reddit account):
|
|
157
|
+
{"reddit":{"subreddit":"NAME","kind":"self|link|image|video","title":"...","flairId":"..."}}
|
|
158
|
+
Optional reddit fields: body, url (link), flairText (only if textEditable), posterMediaAssetId, nsfw, spoiler
|
|
159
|
+
|
|
160
|
+
Reddit happy path:
|
|
161
|
+
1. dun media upload ./video.mp4 --json # rejects >256MB locally
|
|
162
|
+
2. dun reddit flairs SUB --json # pick flairId
|
|
163
|
+
3. dun posts validate --accounts ID --media ASSET --meta '...' --json
|
|
164
|
+
4. dun posts publish --accounts ID --media ASSET --meta '...' --wait --json
|
|
165
|
+
|
|
166
|
+
Notes:
|
|
167
|
+
- publish without --wait returns status scheduled (queued). Poll get or use --wait.
|
|
168
|
+
- Prefer flairId alone. flairText without flairId always fails.
|
|
169
|
+
`,drafts:"dun drafts list|get|create|update|delete",media:`dun media
|
|
170
|
+
|
|
171
|
+
list|get|upload|delete
|
|
172
|
+
upload <file> [--alt] [--mime]
|
|
173
|
+
|
|
174
|
+
Local preflight before upload-url:
|
|
175
|
+
images <= 8MB (jpeg/png/gif/webp)
|
|
176
|
+
video <= 256MB (mp4/mov/webm)
|
|
177
|
+
Oversized video error includes an ffmpeg compress one-liner.
|
|
178
|
+
`,memory:`dun memory collections list|create
|
|
121
179
|
dun memory list|save|search|delete`,personalization:`dun personalization
|
|
122
180
|
|
|
123
181
|
get Show workspace AI voice profile
|
|
@@ -129,136 +187,50 @@ Workspace-scoped (not per-user). set requires owner/admin + PAT scope workspace:
|
|
|
129
187
|
Alias: dun voice ...
|
|
130
188
|
`,voice:"Alias of personalization",skill:`dun skill install <claude|codex|cursor|pi|opencode|agents|copilot|windsurf|goose|gemini|amp|grok|continue|antigravity|all>
|
|
131
189
|
dun skill list
|
|
132
|
-
dun skill path
|
|
133
|
-
|
|
134
|
-
Usage:
|
|
135
|
-
dun <command> [flags]
|
|
136
|
-
|
|
137
|
-
Auth:
|
|
138
|
-
dun auth login # device-code browser flow
|
|
139
|
-
dun auth login --token <token> # CI / headless
|
|
140
|
-
dun auth login --no-browser
|
|
141
|
-
dun auth logout
|
|
142
|
-
dun auth whoami
|
|
143
|
-
dun auth status
|
|
144
|
-
|
|
145
|
-
Workspaces:
|
|
146
|
-
dun workspace list
|
|
147
|
-
dun workspace use <id|slug>
|
|
148
|
-
dun workspace current
|
|
149
|
-
|
|
150
|
-
Accounts:
|
|
151
|
-
dun accounts list [--platform x]
|
|
152
|
-
|
|
153
|
-
Posts:
|
|
154
|
-
dun posts list [--status scheduled|published|failed|draft|cancelled]
|
|
155
|
-
dun posts get <id>
|
|
156
|
-
dun posts schedule --text "..." --accounts <id,id> (--at ISO | --in 2h) [--media id,id]
|
|
157
|
-
dun posts publish --text "..." --accounts <id,id> [--media id,id] [--natural]
|
|
158
|
-
dun posts reschedule <id> --at ISO|--in 2h [--text "..."]
|
|
159
|
-
dun posts cancel <id>
|
|
160
|
-
dun posts delete <id> [--yes]
|
|
161
|
-
dun posts x-cap
|
|
162
|
-
|
|
163
|
-
Drafts:
|
|
164
|
-
dun drafts list
|
|
165
|
-
dun drafts get <id>
|
|
166
|
-
dun drafts create --text "..." [--platforms x,linkedin] [--accounts id,id]
|
|
167
|
-
dun drafts update <id> --text "..."
|
|
168
|
-
dun drafts delete <id> [--yes]
|
|
169
|
-
|
|
170
|
-
Media:
|
|
171
|
-
dun media list
|
|
172
|
-
dun media get <id>
|
|
173
|
-
dun media upload <file> [--alt "..."]
|
|
174
|
-
dun media delete <id> [--yes]
|
|
175
|
-
|
|
176
|
-
Memory:
|
|
177
|
-
dun memory collections list
|
|
178
|
-
dun memory collections create --name "..." [--color blue] [--private]
|
|
179
|
-
dun memory list --collection <id>
|
|
180
|
-
dun memory save --collection <id> --text "..."
|
|
181
|
-
dun memory search --prompt "..." --collections <id,id> [--top-k 5]
|
|
182
|
-
dun memory delete <id> --collection <id> [--yes]
|
|
183
|
-
|
|
184
|
-
Personalization (workspace AI voice):
|
|
185
|
-
dun personalization get
|
|
186
|
-
dun personalization set --description "..."
|
|
187
|
-
dun personalization set --file voice.md
|
|
188
|
-
dun personalization set --clear
|
|
189
|
-
# requires PAT scope workspace:write for set (owner/admin)
|
|
190
|
-
|
|
191
|
-
Agent skills:
|
|
192
|
-
dun skill install <agent|all>
|
|
193
|
-
dun skill list
|
|
194
|
-
dun skill path
|
|
195
|
-
# agents: claude codex cursor pi opencode agents copilot windsurf
|
|
196
|
-
# goose gemini amp grok continue antigravity
|
|
197
|
-
|
|
198
|
-
Global flags:
|
|
199
|
-
--json Machine-readable output (default when non-TTY / CI)
|
|
200
|
-
--workspace <id> Override workspace for this command
|
|
201
|
-
--api-url <url> Override API base (default https://api.dunsocial.com)
|
|
202
|
-
--token <token> Override bearer token for this command
|
|
203
|
-
--debug Log HTTP method/path/status to stderr
|
|
204
|
-
--quiet Suppress human success output
|
|
205
|
-
--yes Skip destructive confirmations
|
|
206
|
-
--help, -h Show help
|
|
207
|
-
--version, -v Show version
|
|
190
|
+
dun skill path`,update:`dun update
|
|
208
191
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
Exit codes:
|
|
213
|
-
0 ok | 1 usage | 2 auth | 3 forbidden | 4 validation | 5 not found | 6 rate limit | 7 network
|
|
192
|
+
(no args) Check npm and upgrade via detected package manager
|
|
193
|
+
--check Report current vs latest only
|
|
194
|
+
--force Reinstall latest even if versions match
|
|
214
195
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
`)
|
|
219
|
-
`),
|
|
220
|
-
`).
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
${A}
|
|
224
|
-
|
|
225
|
-
`)}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)}
|
|
226
|
-
`);return}if(U===void 0||U===null){process.stdout.write(`ok
|
|
227
|
-
`);return}if(typeof U==="string"){process.stdout.write(`${U}
|
|
228
|
-
`);return}process.stdout.write(`${A0(U,D.emptyMessage)}
|
|
229
|
-
`)}function A0(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(`
|
|
230
|
-
`)}if(U&&typeof U==="object"){let O=U;if(Array.isArray(O.items)){if(O.items.length===0&&D)return D;let A=typeof O.total==="number"?`total=${O.total} showing=${O.items.length}`:void 0,G=TU(O.items,D);return A?`${A}
|
|
231
|
-
${G}`:G}return Object.entries(O).map(([A,G])=>`${A}: ${r(G)}`).join(`
|
|
232
|
-
`)}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"],A=new Set;for(let Z of U)for(let J of Object.keys(Z))A.add(J);let G=[...O.filter((Z)=>A.has(Z)),...[...A].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))),V=G.map((Z,J)=>Math.max(Z.length,...$.map((q)=>q[J]?.length??0))),K=G.map((Z,J)=>Z.padEnd(V[J])).join(" "),X=$.map((Z)=>Z.map((J,q)=>J.padEnd(V[q])).join(" ")).join(`
|
|
233
|
-
`);return`${K}
|
|
234
|
-
${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 S(U,D,O){if(!U)return;if(O!==void 0){process.stderr.write(`[debug] ${D} ${JSON.stringify(O)}
|
|
235
|
-
`);return}process.stderr.write(`[debug] ${D}
|
|
236
|
-
`)}class NU{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 A={Accept:"application/json","User-Agent":`dunsocial-cli/${M}`,...U.headers??{}};if(U.auth!==!1)A.Authorization=`Bearer ${N(this.ctx)}`;if(U.workspace)A["X-Workspace-Id"]=P(this.ctx);let G;if(U.body!==void 0)A["Content-Type"]="application/json",G=JSON.stringify(U.body);S(this.ctx.debug,`${D} ${O.toString()}`);let $;try{$=await fetch(O,{method:D,headers:A,body:G})}catch(X){throw new Q(`Network error: ${X.message}`,z.NETWORK,{cause:String(X)})}let V=await $.text(),K=null;if(V)try{K=JSON.parse(V)}catch{K=null}if(S(this.ctx.debug,`<- ${$.status}`,{ok:$.ok,bodyPreview:V.slice(0,300)}),!$.ok){let X=K?.error||K?.message||(V?V.slice(0,300):`HTTP ${$.status}`);throw new Q(X,$U($.status),{status:$.status,body:K??V})}if(K&&typeof K==="object"&&"success"in K){if(K.success===!1)throw new Q(K.error||K.message||"Request failed",z.VALIDATION,K);return K.data}return K??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 NU(U)}function w(U,...D){for(let O of D){let A=U[O];if(typeof A==="string"&&A.length>0)return A}return}function u(U,...D){for(let O of D){let A=U[O];if(A===!0)return!0;if(typeof A==="string"){let G=A.toLowerCase();if(G==="1"||G==="true"||G==="yes")return!0}}return!1}function F(U,...D){let O=w(U,...D);if(O===void 0)return;let A=Number(O);if(!Number.isFinite(A))throw Error(`Invalid number for --${D[0]}: ${O}`);return A}function _(U,...D){let O=w(U,...D);if(O===void 0)return;return O.split(",").map((A)=>A.trim()).filter(Boolean)}var V0=["█▀▀▄ █ █ █▀▀▄ █▀▀▀ █▀▀█ █▀▀▀ ▀█▀ █▀▀█ █","█ █ █ █ █ █ ▀▀▀█ █ █ █ █ █▀▀█ █","▀▀▀▀ ▀▀▀▀ ▀ ▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀ ▀ ▀ ▀▀▀"].join(`
|
|
237
|
-
`),WU=["█▀▀▄ █ █ █▀▀▄","█ █ █ █ █ █","▀▀▀▀ ▀▀▀▀ ▀ ▀",""," DunSocial"].join(`
|
|
238
|
-
`);var VO=PU(V0),GO=PU(WU);function PU(U){return Math.max(...U.split(`
|
|
239
|
-
`).map((D)=>D.length))}function d(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 uU(){return WU}async function HU(U,D,O,A){switch(D){case"login":return G0(U,O);case"logout":return X0(U);case"whoami":return Z0(U);case"status":return J0(U);default:throw new Q(`Unknown auth command "${D??""}". Try: login, logout, whoami, status`,z.USAGE)}}async function G0(U,D){let O=w(D,"token")||process.env.DUN_TOKEN;if(O)return z0(U,O);return Q0(U,D)}function E(U){if(U)return"Logged in.";return`Logged in.
|
|
240
|
-
Next: dun workspace list && dun workspace use <id|slug>`}async function z0(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&&d(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 Q0(U,D){let O=T({...U,token:void 0}),A=await O.post("/api/cli/auth/start",{clientName:"dun-cli"},{auth:!1}),G=!u(D,"no-browser");if(!U.json){if(d(process.stderr))process.stderr.write(`
|
|
241
|
-
${uU()}
|
|
196
|
+
Aliases: dun upgrade, dun self-update
|
|
197
|
+
`,upgrade:"Alias of update","self-update":"Alias of update"}[u]??g}var lu=["DunSocial","---------"].join(`
|
|
198
|
+
`),Ou="DunSocial";var xw=zu(lu),lw=zu(Ou);function zu(u){return Math.max(...u.split(`
|
|
199
|
+
`).map(($)=>$.length))}function I(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 yu(){return`DunSocial CLI v${B}`}function qu(){return`${Ou}
|
|
200
|
+
CLI v${B}`}var au="https://dunsocial.com/docs/cli";function tu(u){if(!u.token)return"signed_out";if(!u.workspaceId)return"needs_workspace";return"ready"}function Xu(u){let $=tu(u),w=[`DunSocial CLI v${B}`,""];if($==="signed_out")w.push("Not signed in.",""," Next: dun auth login");else if($==="needs_workspace")w.push("Signed in — pick a workspace.",""," Next: dun workspace list"," dun workspace use <slug>");else{let D=u.config.defaultWorkspaceSlug||u.config.defaultWorkspaceName||u.workspaceId||"workspace";w.push(`Ready | workspace: ${D}`,""," Tip: dun accounts list"," dun posts list")}return w.push(""," dun --help all commands",` Docs ${au}`,""),w.join(`
|
|
201
|
+
`)}import{spawn as uw}from"node:child_process";class Zu{ctx;constructor(u){this.ctx=u}async request(u){let $=u.method??"GET",w=new URL(u.path.startsWith("http")?u.path:`${this.ctx.apiUrl}${u.path}`);if(u.query)for(let[q,X]of Object.entries(u.query)){if(X===void 0||X===null||X==="")continue;w.searchParams.set(q,String(X))}let D={Accept:"application/json","User-Agent":`dunsocial-cli/${B}`,...u.headers??{}};if(u.auth!==!1)D.Authorization=`Bearer ${F(this.ctx)}`;if(u.workspace)D["X-Workspace-Id"]=W(this.ctx);let z;if(u.body!==void 0)D["Content-Type"]="application/json",z=JSON.stringify(u.body);M(this.ctx.debug,`${$} ${w.toString()}`);let U;try{U=await fetch(w,{method:$,headers:D,body:z})}catch(q){throw new y(`Network error: ${q.message}`,O.NETWORK,{cause:String(q)})}let m=await U.text(),d=null;if(m)try{d=JSON.parse(m)}catch{d=null}if(M(this.ctx.debug,`<- ${U.status}`,{ok:U.ok,bodyPreview:m.slice(0,300)}),!U.ok){let q=d?.error||d?.message||(m?m.slice(0,300):`HTTP ${U.status}`);throw new y(q,uu(U.status),{status:U.status,body:d??m})}if(d&&typeof d==="object"&&"success"in d){if(d.success===!1)throw new y(d.error||d.message||"Request failed",O.VALIDATION,d);return d.data}return d??void 0}get(u,$){return this.request({...$,method:"GET",path:u})}post(u,$,w){return this.request({...w,method:"POST",path:u,body:$})}patch(u,$,w){return this.request({...w,method:"PATCH",path:u,body:$})}delete(u,$,w){return this.request({...w,method:"DELETE",path:u,body:$})}}function Y(u){return new Zu(u)}async function Vu(u,$,w,D){switch($){case"login":return ww(u,w);case"logout":return dw(u);case"whoami":return mw(u);case"status":return Dw(u);default:throw new y(`Unknown auth command "${$??""}". Try: login, logout, whoami, status`,O.USAGE)}}async function ww(u,$){let w=Q($,"token")||process.env.DUN_TOKEN;if(w)return $w(u,w);return Uw(u,$)}function n(u){if(u)return"Logged in.";return`Logged in.
|
|
202
|
+
Next: dun workspace list && dun workspace use <id|slug>`}async function $w(u,$){let w={...u,token:$},z=await Y(w).get("/api/user/profile");if(await L({...u.config,apiUrl:u.apiUrl,token:$,defaultWorkspaceId:u.config.defaultWorkspaceId,defaultWorkspaceSlug:u.config.defaultWorkspaceSlug,defaultWorkspaceName:u.config.defaultWorkspaceName}),!u.json&&I(process.stdout)){V(n(Boolean(u.config.defaultWorkspaceId)),u);return}V({user:{id:z.id,name:z.name,email:z.email},configPath:j(),method:"token",message:n(Boolean(u.config.defaultWorkspaceId))},u)}async function Uw(u,$){let w=Y({...u,token:void 0}),D=await w.post("/api/cli/auth/start",{clientName:"dun-cli"},{auth:!1}),z=!R($,"no-browser");if(!u.json){if(I(process.stderr))process.stderr.write(`
|
|
203
|
+
${qu()}
|
|
242
204
|
|
|
243
205
|
`);else process.stderr.write(`
|
|
244
206
|
DunSocial CLI login
|
|
245
207
|
`),process.stderr.write(`───────────────────
|
|
246
208
|
`);process.stderr.write(`In your browser, open:
|
|
247
|
-
${
|
|
209
|
+
${D.verificationUrlComplete}
|
|
248
210
|
|
|
249
|
-
`),process.stderr.write(`Or go to ${
|
|
250
|
-
`),process.stderr.write(` ${
|
|
211
|
+
`),process.stderr.write(`Or go to ${D.verificationUrl} and enter code:
|
|
212
|
+
`),process.stderr.write(` ${D.userCode}
|
|
251
213
|
|
|
252
214
|
`),process.stderr.write(`Waiting for approval...
|
|
253
|
-
`)}else process.stderr.write(JSON.stringify({ok:!0,phase:"waiting",userCode:
|
|
254
|
-
`);if(G&&process.stdout.isTTY)try{await w0(A.verificationUrlComplete)}catch{}let $=Math.max(3,A.interval||5)*1000,V=Date.now()+(A.expiresIn||900)*1000;while(Date.now()<V){await R0($);let K=await O.post("/api/cli/auth/poll",{deviceCode:A.deviceCode},{auth:!1});if(K.status==="pending")continue;if(K.status==="expired")throw new Q("Login expired. Run dun auth login again.",z.AUTH);if(K.status==="denied")throw new Q("Login was denied in the browser.",z.AUTH);if(K.status==="approved"){let X=K.token,Z={...U,token:X},J=T(Z),q=await J.get("/api/user/profile"),Y={...U.config,apiUrl:U.apiUrl,token:X,defaultWorkspaceId:K.workspaceId||U.config.defaultWorkspaceId,defaultWorkspaceSlug:U.config.defaultWorkspaceSlug,defaultWorkspaceName:U.config.defaultWorkspaceName};if(K.workspaceId)try{let L=(await J.get("/api/workspaces")).find((k)=>k.id===K.workspaceId);if(L)Y.defaultWorkspaceId=L.id,Y.defaultWorkspaceSlug=L.slug,Y.defaultWorkspaceName=L.name}catch{}await b(Y);let H=Boolean(Y.defaultWorkspaceId);if(!U.json&&d(process.stdout)){R(E(H),U);return}R({user:{id:q.id,name:q.name,email:q.email},workspaceId:Y.defaultWorkspaceId??null,configPath:j(),method:"device",message:E(H)},U);return}}throw new Q("Login timed out. Run dun auth login again.",z.AUTH)}async function X0(U){if(await ZU(),!U.json&&d(process.stdout)){R("Logged out. Config cleared.",U);return}R({message:"Logged out. Config cleared.",configPath:j()},U)}async function Z0(U){N(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 J0(U){let D=Boolean(U.token),O=null,A=null;if(D)try{O=await T(U).get("/api/user/profile")}catch(G){A=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:A},U)}function R0(U){return new Promise((D)=>setTimeout(D,U))}async function w0(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 FU(U,D,O,A){N(U);let G=T(U);switch(D){case"list":case"ls":{let $=await G.get("/api/workspaces");R($.map((V)=>({id:V.id,name:V.name,slug:V.slug,role:V.role,timezone:V.timezone,plan:V.subscription?.planName??null,status:V.subscription?.status??null})),{...U,emptyMessage:"No workspaces yet."});return}case"use":{let $=A[0];if(!$)throw new Q("Usage: dun workspace use <id|slug>",z.USAGE);let K=(await G.get("/api/workspaces")).find((X)=>X.id===$||X.slug===$);if(!K)throw new Q(`Workspace not found: ${$}. Run dun workspace list`,z.NOT_FOUND);await b({...U.config,apiUrl:U.apiUrl,token:U.token,defaultWorkspaceId:K.id,defaultWorkspaceSlug:K.slug,defaultWorkspaceName:K.name}),R({id:K.id,name:K.name,slug:K.slug,role:K.role,message:`Default workspace set to ${K.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 K=(await G.get("/api/workspaces")).find((X)=>X.id===$||X.slug===$);if(K){R({id:K.id,name:K.name,slug:K.slug,role:K.role,timezone:K.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,A){N(U),P(U);let G=T(U);switch(D){case void 0:case"list":case"ls":{let $=await G.get("/api/social-accounts",{workspace:!0}),V=w(O,"platform","p")?.toLowerCase(),K=V?$.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"],tiktok:["tiktok"]}[V]??[V]).some((Y)=>Z.includes(Y))}):$;R(K.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:V?`No ${V} 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 A=O.match(Y0);if(A){let V=Number(A[1]),K=A[2].toLowerCase(),X=q0(K)*V;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 yU(U){if(!U)return[];return U.split(",").map((D)=>D.trim()).filter(Boolean)}function IU(U){let D=w(U,"text","content","c","t");if(!D)throw new Q("Missing --text",z.VALIDATION);return D}function s(U){let D=_(U,"accounts","account","a")??yU(w(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,"media","media-urls")??yU(w(U,"media","media-urls"))}function h(U){let D=w(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,A){N(U),P(U);let G=T(U);switch(D){case"list":case"ls":{let $=await G.get("/api/posts",{workspace:!0,query:{status:w(O,"status","s"),socialAccountId:w(O,"account","social-account"),groupId:w(O,"group"),limit:F(O,"limit")??50,offset:F(O,"offset")??0}});R($,{...U,emptyMessage:"No posts yet. Schedule one with dun posts schedule."});return}case"get":{let $=A[0];if(!$)throw new Q("Usage: dun posts get <id>",z.USAGE);let V=await G.get(`/api/posts/${$}`,{workspace:!0});R(V,U);return}case"schedule":{let $=IU(O),V=s(O),K=C({at:w(O,"at"),in:w(O,"in")}),X=await G.post("/api/posts/schedule",{content:$,socialAccountIds:V,scheduledAt:K,mediaUrls:t(O),metadata:h(O)??{}},{workspace:!0});R(X,U);return}case"publish":case"publish-now":{let $=IU(O),V=s(O),K=await G.post("/api/posts/publish-now",{content:$,socialAccountIds:V,mediaUrls:t(O),metadata:h(O)??{},naturalPosting:u(O,"natural","natural-posting")},{workspace:!0});R(K,U);return}case"reschedule":{let $=A[0];if(!$)throw new Q("Usage: dun posts reschedule <id> --at|--in",z.USAGE);let K={scheduledAt:C({at:w(O,"at"),in:w(O,"in")})},X=w(O,"text","content","c","t");if(X)K.content=X;let Z=t(O);if(Z.length)K.mediaUrls=Z;let J=h(O);if(J)K.metadata=J;if(!K.content){let Y=await G.get(`/api/posts/${$}`,{workspace:!0});if(K.content=Y.content,!K.metadata&&Y.metadata)K.metadata=Y.metadata;if(!K.mediaUrls&&Y.mediaUrls)K.mediaUrls=Y.mediaUrls}let q=await G.post(`/api/posts/${$}/reschedule`,K,{workspace:!0});R(q,U);return}case"cancel":{let $=A[0];if(!$)throw new Q("Usage: dun posts cancel <id>",z.USAGE);let V=await G.post(`/api/posts/${$}/cancel`,void 0,{workspace:!0});R(V??{id:$,status:"cancelled"},U);return}case"delete":case"rm":{let $=A[0];if(!$)throw new Q("Usage: dun posts delete <id> [--yes]",z.USAGE);if(!U.yes&&!u(O,"yes","y"))throw new Q("Refusing to delete without --yes (or CI/yes mode)",z.VALIDATION);let V=await G.delete(`/api/posts/${$}`,void 0,{workspace:!0});R(V??{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 $=w(O,"file","f"),V=w(O,"account","accounts","a")??s(O)[0];if(!V)throw new Q("Missing --account <xAccountId>",z.VALIDATION);let K;if($){let Z=await Bun.file($).text(),J=JSON.parse(Z);if(Array.isArray(J))K=J;else if(J&&typeof J==="object"&&Array.isArray(J.tweets))K=J.tweets;else throw new Q("Thread file must be an array of tweets or { tweets: [] }",z.VALIDATION)}else{let Z=w(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);K=Z.split("||").map((J)=>({content:J.trim()})).filter((J)=>J.content)}if(K.length<2)throw new Q("Threads require at least 2 tweets",z.VALIDATION);if(D==="schedule-thread"){let Z=C({at:w(O,"at"),in:w(O,"in")}),J=await G.post("/api/posts/schedule-thread",{socialAccountId:V,tweets:K,scheduledAt:Z,metadata:h(O)??{}},{workspace:!0});R(J,U);return}let X=await G.post("/api/posts/publish-thread-now",{socialAccountId:V,tweets:K,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,A){N(U),P(U);let G=T(U);switch(D){case"list":case"ls":{let $=await G.get("/api/drafts",{workspace:!0,query:{limit:F(O,"limit")??50,offset:F(O,"offset")??0}});R($,{...U,emptyMessage:'No drafts yet. Create one with dun drafts create --text "..."'});return}case"get":{let $=A[0];if(!$)throw new Q("Usage: dun drafts get <id>",z.USAGE);let V=await G.get(`/api/drafts/${$}`,{workspace:!0});R(V,U);return}case"create":{let $=w(O,"text","content","c","t");if(!$)throw new Q("Missing --text",z.VALIDATION);let V=await G.post("/api/drafts",{content:$,name:w(O,"name","n"),socialAccountIds:_(O,"accounts","account","a")??[],selectedPlatforms:_(O,"platforms","platform","p")??[],mediaUrls:_(O,"media")??[]},{workspace:!0});R(V,U);return}case"update":{let $=A[0];if(!$)throw new Q("Usage: dun drafts update <id> --text ...",z.USAGE);let V={id:$},K=w(O,"text","content","c","t");if(K)V.content=K;let X=w(O,"name","n");if(X!==void 0)V.name=X;let Z=_(O,"accounts","account","a");if(Z)V.socialAccountIds=Z;let J=_(O,"platforms","platform","p");if(J)V.selectedPlatforms=J;let q=_(O,"media");if(q)V.mediaUrls=q;let Y=await G.patch(`/api/drafts/${$}`,V,{workspace:!0});R(Y,U);return}case"delete":case"rm":{let $=A[0];if(!$)throw new Q("Usage: dun drafts delete <id> [--yes]",z.USAGE);if(!U.yes&&!u(O,"yes","y"))throw new Q("Refusing to delete without --yes",z.VALIDATION);let V=await G.delete(`/api/drafts/${$}`,void 0,{workspace:!0});R(V??{id:$,deleted:!0},U);return}default:throw new Q(`Unknown drafts command "${D??""}". Try: list, get, create, update, delete`,z.USAGE)}}import{basename as T0}from"node:path";function N0(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,A){N(U),P(U);let G=T(U);switch(D){case"list":case"ls":{let $=await G.get("/api/media",{workspace:!0,query:{limit:F(O,"limit")??50,offset:F(O,"offset")??0}});R($,{...U,emptyMessage:"No media yet. Upload with dun media upload <file>."});return}case"get":{let $=A[0];if(!$)throw new Q("Usage: dun media get <id>",z.USAGE);let V=await G.get(`/api/media/${$}`,{workspace:!0});R(V,U);return}case"upload":{let $=A[0]||w(O,"file","f");if(!$)throw new Q('Usage: dun media upload <file> [--alt "..."]',z.USAGE);let V=Bun.file($);if(!await V.exists())throw new Q(`File not found: ${$}`,z.VALIDATION);let X=T0($),Z=w(O,"mime","type","content-type")||V.type||N0(X),J=V.size,q=w(O,"alt","alt-text"),Y=await G.post("/api/media/upload-url",{filename:X,mimeType:Z,fileSize:J},{workspace:!0});S(U.debug,`PUT ${Y.uploadUrl}`,{storageKey:Y.storageKey,fileSize:J});let H=await V.arrayBuffer(),y;try{y=await fetch(Y.uploadUrl,{method:"PUT",headers:{"Content-Type":Z,"Content-Length":String(J)},body:H})}catch(k){throw new Q(`Upload PUT failed: ${k.message}`,z.NETWORK)}if(!y.ok){let k=await y.text().catch(()=>"");throw new Q(`Upload PUT failed with HTTP ${y.status}${k?`: ${k.slice(0,200)}`:""}`,z.NETWORK)}let L=await G.post("/api/media/complete",{storageKey:Y.storageKey,originalFilename:X,mimeType:Z,fileSize:J,altText:q},{workspace:!0});R(L,U);return}case"delete":case"rm":{let $=A[0];if(!$)throw new Q("Usage: dun media delete <id> [--yes]",z.USAGE);if(!U.yes&&!u(O,"yes","y"))throw new Q("Refusing to delete without --yes",z.VALIDATION);let V=await G.delete(`/api/media/${$}`,void 0,{workspace:!0});R(V??{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,A){N(U),P(U);let G=T(U),$=D[0];if($==="collections"||$==="collection"){let V=D[1]||"list";switch(V){case"list":case"ls":{let K=await G.get("/api/memory/collections",{workspace:!0});R(K,{...U,emptyMessage:'No memory collections yet. Create one with dun memory collections create --name "..."'});return}case"create":{let K=w(O,"name","n");if(!K)throw new Q("Missing --name",z.VALIDATION);let X=await G.post("/api/memory/collections",{name:K,color:w(O,"color")??"blue",isPrivate:u(O,"private")},{workspace:!0});R(X,U);return}case"get":{let K=D[2]||A[0];if(!K)throw new Q("Usage: dun memory collections get <id>",z.USAGE);let X=await G.get(`/api/memory/collections/${K}`,{workspace:!0});R(X,U);return}default:throw new Q(`Unknown memory collections command "${V}". Try: list, create, get`,z.USAGE)}}switch($){case"list":case"ls":{let V=w(O,"collection","collection-id","c");if(!V)throw new Q("Missing --collection <id>",z.VALIDATION);let K=await G.get("/api/memory",{workspace:!0,query:{collectionId:V,limit:F(O,"limit")??100}});R(K,{...U,emptyMessage:"No memories in this collection."});return}case"save":case"add":{let V=w(O,"collection","collection-id","c"),K=w(O,"text","t");if(!V)throw new Q("Missing --collection <id>",z.VALIDATION);if(!K)throw new Q("Missing --text",z.VALIDATION);let X=await G.post("/api/memory",{collectionId:V,text:K},{workspace:!0});R(X,U);return}case"search":{let V=w(O,"prompt","q","query","text"),K=_(O,"collections","collection","collection-ids","c")??[];if(!V)throw new Q("Missing --prompt",z.VALIDATION);if(K.length===0)throw new Q("Missing --collections <id,id>",z.VALIDATION);let X=await G.post("/api/memory/search",{prompt:V,collectionIds:K,topK:F(O,"top-k","topk","k")??5},{workspace:!0});R(X,U);return}case"delete":case"rm":{let V=D[1]||A[0],K=w(O,"collection","collection-id","c");if(!V)throw new Q("Usage: dun memory delete <id> --collection <id>",z.USAGE);if(!K)throw new Q("Missing --collection <id>",z.VALIDATION);if(!U.yes&&!u(O,"yes","y"))throw new Q("Refusing to delete without --yes",z.VALIDATION);let X=await G.delete(`/api/memory/${V}`,{collectionId:K,memoryId:V},{workspace:!0});R(X??{id:V,deleted:!0},U);return}default:throw new Q(`Unknown memory command "${$??""}". Try: collections, list, save, search, delete`,z.USAGE)}}import{readFileSync as W0}from"node:fs";async function jU(U,D,O,A){N(U);let G=P(U),$=T(U),V=`/api/workspaces/${G}/ai-voice-settings`;switch(D){case"get":case"show":case void 0:{let K=await $.get(V,{workspace:!0});R(K??{personalization:null,hint:'No personalization set. Use dun personalization set --description "..."'},U);return}case"set":case"update":{let K=u(O,"clear"),X=w(O,"description","d"),Z=w(O,"file","f");if([K,Boolean(X),Boolean(Z)].filter(Boolean).length!==1)throw new Q("Use exactly one of --description, --file, or --clear",z.VALIDATION);let q;if(K)q=null;else if(Z){let H;try{H=W0(Z,"utf8").trim()}catch(y){throw new Q(`Could not read file: ${y.message}`,z.VALIDATION)}if(!H)throw new Q("File is empty",z.VALIDATION);q={description:H}}else{let H=X.trim();if(!H)throw new Q("--description cannot be empty",z.VALIDATION);q={description:H}}let Y=await $.patch(V,q,{workspace:!0});R(Y,U);return}default:throw new Q(`Unknown personalization command "${D}". Try: get, set`,z.USAGE)}}import{existsSync as P0}from"node:fs";import{mkdir as dU,writeFile as hU,readFile as vU}from"node:fs/promises";import{dirname as OU,join as W}from"node:path";import{homedir as DU}from"node:os";import{fileURLToPath as u0}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 I0(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 bU=`Usage: dun skill install <${p.map((U)=>U.id).join("|")}|all>`;function UU(){let U=OU(u0(import.meta.url)),D=W("skills","dunsocial","SKILL.md"),O=[W(U,"..",D),W(U,"..","..",D)];return O.find(P0)??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 vU(UU(),"utf8")}catch{throw new Q(`Bundled skill not found at ${UU()}. Reinstall dunsocial.`,z.USAGE)}}async function _0(U,D){await dU(OU(U),{recursive:!0}),await hU(U,D,"utf8")}async function I0(U){let D=W(DU(),".codex","AGENTS.md");await dU(OU(D),{recursive:!0});let O="";try{O=await vU(D,"utf8")}catch{O=""}let A=["<!-- 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(`
|
|
255
|
-
`),
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
`),
|
|
263
|
-
|
|
264
|
-
|
|
215
|
+
`)}else process.stderr.write(JSON.stringify({ok:!0,phase:"waiting",userCode:D.userCode,verificationUrlComplete:D.verificationUrlComplete})+`
|
|
216
|
+
`);if(z&&process.stdout.isTTY)try{await zw(D.verificationUrlComplete)}catch{}let U=Math.max(3,D.interval||5)*1000,m=Date.now()+(D.expiresIn||900)*1000;while(Date.now()<m){await Ow(U);let d=await w.post("/api/cli/auth/poll",{deviceCode:D.deviceCode},{auth:!1});if(d.status==="pending")continue;if(d.status==="expired")throw new y("Login expired. Run dun auth login again.",O.AUTH);if(d.status==="denied")throw new y("Login was denied in the browser.",O.AUTH);if(d.status==="approved"){let q=d.token,X={...u,token:q},Z=Y(X),J=await Z.get("/api/user/profile"),G={...u.config,apiUrl:u.apiUrl,token:q,defaultWorkspaceId:d.workspaceId||u.config.defaultWorkspaceId,defaultWorkspaceSlug:u.config.defaultWorkspaceSlug,defaultWorkspaceName:u.config.defaultWorkspaceName};if(d.workspaceId)try{let N=(await Z.get("/api/workspaces")).find((nu)=>nu.id===d.workspaceId);if(N)G.defaultWorkspaceId=N.id,G.defaultWorkspaceSlug=N.slug,G.defaultWorkspaceName=N.name}catch{}await L(G);let k=Boolean(G.defaultWorkspaceId);if(!u.json&&I(process.stdout)){V(n(k),u);return}V({user:{id:J.id,name:J.name,email:J.email},workspaceId:G.defaultWorkspaceId??null,configPath:j(),method:"device",message:n(k)},u);return}}throw new y("Login timed out. Run dun auth login again.",O.AUTH)}async function dw(u){if(await $u(),!u.json&&I(process.stdout)){V("Logged out. Config cleared.",u);return}V({message:"Logged out. Config cleared.",configPath:j()},u)}async function mw(u){F(u);let w=await Y(u).get("/api/user/profile");V({id:w.id,name:w.name,email:w.email,image:w.image??null,apiUrl:u.apiUrl,workspaceId:u.workspaceId??null},u)}async function Dw(u){let $=Boolean(u.token),w=null,D=null;if($)try{w=await Y(u).get("/api/user/profile")}catch(z){D=z instanceof Error?z.message:String(z)}V({authenticated:Boolean(w),tokenPresent:$,apiUrl:u.apiUrl,workspaceId:u.workspaceId??null,workspaceSlug:u.config.defaultWorkspaceSlug??null,workspaceName:u.config.defaultWorkspaceName??null,configPath:j(),user:w?{id:w.id,name:w.name,email:w.email}:null,error:D},u)}function Ow(u){return new Promise(($)=>setTimeout($,u))}async function zw(u){let $=process.platform,w=$==="darwin"?["open",u]:$==="win32"?["cmd","/c","start","",u]:["xdg-open",u];await new Promise((D,z)=>{let U=uw(w[0],w.slice(1),{stdio:"ignore",windowsHide:!0});U.on("error",z),U.on("close",()=>D())})}async function Qu(u,$,w,D){F(u);let z=Y(u);switch($){case"list":case"ls":{let U=await z.get("/api/workspaces");V(U.map((m)=>({id:m.id,name:m.name,slug:m.slug,role:m.role,timezone:m.timezone,plan:m.subscription?.planName??null,status:m.subscription?.status??null})),{...u,emptyMessage:"No workspaces yet."});return}case"use":{let U=D[0];if(!U)throw new y("Usage: dun workspace use <id|slug>",O.USAGE);let d=(await z.get("/api/workspaces")).find((q)=>q.id===U||q.slug===U);if(!d)throw new y(`Workspace not found: ${U}. Run dun workspace list`,O.NOT_FOUND);await L({...u.config,apiUrl:u.apiUrl,token:u.token,defaultWorkspaceId:d.id,defaultWorkspaceSlug:d.slug,defaultWorkspaceName:d.name}),V({id:d.id,name:d.name,slug:d.slug,role:d.role,message:`Default workspace set to ${d.name}`},u);return}case"current":{if(!u.workspaceId&&!u.config.defaultWorkspaceId)throw new y("No workspace selected. Run dun workspace use <id|slug>",O.VALIDATION);let U=u.workspaceId||u.config.defaultWorkspaceId;try{let d=(await z.get("/api/workspaces")).find((q)=>q.id===U||q.slug===U);if(d){V({id:d.id,name:d.name,slug:d.slug,role:d.role,timezone:d.timezone},u);return}}catch{}V({id:U,name:u.config.defaultWorkspaceName??null,slug:u.config.defaultWorkspaceSlug??null},u);return}default:throw new y(`Unknown workspace command "${$??""}". Try: list, use, current`,O.USAGE)}}async function Ju(u,$,w,D){F(u),W(u);let z=Y(u);switch($){case void 0:case"list":case"ls":{let U=await z.get("/api/social-accounts",{workspace:!0}),m=Q(w,"platform","p")?.toLowerCase(),d=m?U.filter((q)=>{let X=(q.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"]}[m]??[m]).some((G)=>X.includes(G))}):U;V(d.map((q)=>({id:q.id,providerName:q.providerName,username:q.username??null,displayName:q.displayName??null,isConnected:q.isConnected,expiresAt:q.expiresAt??null})),{...u,emptyMessage:m?`No ${m} accounts connected. Connect one in the DunSocial dashboard.`:"No accounts connected. Connect one in the DunSocial dashboard."});return}default:throw new y(`Unknown accounts command "${$}". Try: list (or: dun accounts reddit flairs <subreddit>)`,O.USAGE)}}import{readFileSync as Xw}from"node:fs";var yw=/^(\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(u,$=new Date){let w=u.trim();if(!w)throw new y("Empty time value",O.VALIDATION);let D=w.match(yw);if(D){let m=Number(D[1]),d=D[2].toLowerCase(),q=qw(d)*m;return new Date($.getTime()+q)}let z=w.match(/^in\s+(.+)$/i);if(z)return c(z[1],$);let U=new Date(w);if(Number.isNaN(U.getTime()))throw new y(`Invalid time "${u}". Use ISO-8601 (2026-06-01T09:00:00Z) or relative (2h, 30m, 1d).`,O.VALIDATION);return U}function qw(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 y(`Unknown time unit: ${u}`,O.VALIDATION)}}function e(u){if(u.at&&u.in)throw new y("Pass only one of --at or --in",O.VALIDATION);if(u.at)return c(u.at).toISOString();if(u.in)return c(u.in).toISOString();throw new y("Schedule time required. Pass --at <iso> or --in <duration> (e.g. 2h).",O.VALIDATION)}function Ru(u){if(!u)return[];return u.split(",").map(($)=>$.trim()).filter(Boolean)}function Gu(u,$){let w=Q(u,"text","content","c","t");if(w)return w;let D=$?.reddit;if(D&&typeof D==="object"&&!Array.isArray(D)&&typeof D.title==="string"&&D.title.trim())return D.title.trim();throw new y("Missing --text",O.VALIDATION)}function h(u){let $=A(u,"accounts","account","a")??Ru(Q(u,"accounts","account","a"));if(!$||$.length===0)throw new y("Missing --accounts <id,id>",O.VALIDATION);return $}function S(u){return A(u,"media","media-urls")??Ru(Q(u,"media","media-urls"))}function P(u){let $=Q(u,"meta","metadata","meta-json");if(!$)return;try{let w=JSON.parse($);if(!w||typeof w!=="object"||Array.isArray(w))throw Error("metadata must be a JSON object");return w}catch(w){throw new y(`Invalid --meta JSON: ${w.message}`,O.VALIDATION)}}var Zw=new Set(["published","failed","cancelled"]);async function Vw(u){await new Promise(($)=>setTimeout($,u))}async function Qw(u,$,w,D){let z=Date.now()+D*1000,U=new Map,m=1500;while(U.size<w.length){if(Date.now()>z){let X=w.filter((Z)=>!U.has(Z.id)).map((Z)=>Z.id);throw new y(`Timed out waiting for publish after ${D}s. Still pending: ${X.join(", ")}. Poll with: dun posts get <id> --json`,O.NETWORK,{pending:X})}for(let X of w){if(U.has(X.id))continue;let Z=await u.get(`/api/posts/${X.id}`,{workspace:!0});if(M($.debug,`wait status ${X.id}=${Z.status}`),Zw.has(Z.status))U.set(X.id,Z)}if(U.size>=w.length)break;await Vw(m),m=Math.min(m*1.4,8000)}let d=w.map((X)=>U.get(X.id)),q=d.filter((X)=>X.status==="failed");if(q.length>0){let X=q.map((Z)=>`${Z.id}: ${Z.error||"publish failed"}`).join("; ");throw new y(`Publish failed — ${X}`,O.VALIDATION,{posts:d})}return d}async function Jw(u,$){let w=[],D=$.meta?.reddit??null;if(!D||typeof D!=="object")throw new y("Reddit accounts require --meta with a reddit object, e.g. "+`--meta '{"reddit":{"subreddit":"…","kind":"self","title":"…","flairId":"…"}}'`,O.VALIDATION);let z=(D.subreddit??"").trim().replace(/^\/?r\//i,""),U=(D.title??"").trim(),m=(D.kind??"").trim(),d=(D.flairId??"").trim(),q=(D.flairText??"").trim();if(!z)throw new y("metadata.reddit.subreddit is required",O.VALIDATION);if(!U)throw new y("metadata.reddit.title is required",O.VALIDATION);if(U.length>300)throw new y(`Reddit title exceeds 300 characters: ${U.length}/300`,O.VALIDATION);if(!["self","link","image","video"].includes(m))throw new y("metadata.reddit.kind must be one of: self, link, image, video",O.VALIDATION);if(w.push(`kind=${m}`),w.push(`titleLength=${U.length}`),q&&!d)throw new y(`Can't set flairText without flairId for r/${z}. Run: dun reddit flairs ${z} --json`,O.VALIDATION);if(m==="link"){if(!D.url?.trim())throw new y("Reddit link posts require metadata.reddit.url",O.VALIDATION);try{new URL(D.url)}catch{throw new y("metadata.reddit.url is invalid",O.VALIDATION)}if($.media.length>0)throw new y("Reddit link posts do not accept --media",O.VALIDATION)}else if(m==="image"||m==="video"){if($.media.length!==1)throw new y(`Reddit ${m} posts require exactly one --media asset id`,O.VALIDATION)}else if($.media.length>0)throw new y("Reddit self posts do not accept --media. Use kind image or video.",O.VALIDATION);let X=await u.get("/api/social-accounts/reddit/post-requirements",{workspace:!0,query:{subreddit:z}});if(w.push("fetched post-requirements"),X?.is_flair_required&&!d)throw new y(`r/${z} requires post flair. Discover ids with: dun reddit flairs ${z} --json`,O.VALIDATION);let Z=X?.title_text_max_length??300;if(U.length>Z)throw new y(`Reddit title too long for r/${z}: ${U.length}/${Z}`,O.VALIDATION);if(X?.title_text_min_length&&U.length<X.title_text_min_length)throw new y(`Reddit title must be at least ${X.title_text_min_length} characters`,O.VALIDATION);if(d){let J=await u.get("/api/social-accounts/reddit/flair-options",{workspace:!0,query:{subreddit:z}});w.push(`fetched ${J.choices?.length??0} flairs`);let G=(J.choices??[]).find((k)=>k.id===d);if(!G)throw new y(`Unknown flairId "${d}" for r/${z}. Run: dun reddit flairs ${z} --json`,O.VALIDATION);if(G.textEditable===!1&&q&&q!==G.text)throw new y(`Customization not allowed for this flair template. Use flairId "${G.id}" alone`+(G.text?` (template text: "${G.text}")`:""),O.VALIDATION);w.push(`flairId=${G.id}`)}return{ok:!0,checks:w,reddit:{subreddit:z,kind:m,title:U,flairId:d||null,accounts:$.accounts,media:$.media,textPreview:$.text?.slice(0,120)??null,requirements:{is_flair_required:X?.is_flair_required??!1,title_text_max_length:Z}}}}async function ku(u,$,w,D){F(u),W(u);let z=Y(u);switch($){case"list":case"ls":{let U=await z.get("/api/posts",{workspace:!0,query:{status:Q(w,"status","s"),socialAccountId:Q(w,"account","social-account"),groupId:Q(w,"group"),limit:H(w,"limit")??50,offset:H(w,"offset")??0}});V(U,{...u,emptyMessage:"No posts yet. Schedule one with dun posts schedule."});return}case"get":{let U=D[0];if(!U)throw new y("Usage: dun posts get <id>",O.USAGE);let m=await z.get(`/api/posts/${U}`,{workspace:!0});V(m,u);return}case"validate":{let U=h(w),m=S(w),d=P(w)??{},q=Q(w,"text","content","c","t"),X=Boolean(d.reddit),Z=X;if(!X){let G=await z.get("/api/social-accounts",{workspace:!0});Z=U.some((k)=>{return(G.find((N)=>N.id===k)?.providerName||"").toLowerCase().includes("reddit")})}if(!Z){V({ok:!0,checks:["no reddit-specific rules for selected accounts"],accounts:U,media:m},u);return}let J=await Jw(z,{accounts:U,text:q,media:m,meta:d});V(J,u);return}case"schedule":{let U=P(w)??{},m=Gu(w,U),d=h(w),q=e({at:Q(w,"at"),in:Q(w,"in")}),X=await z.post("/api/posts/schedule",{content:m,socialAccountIds:d,scheduledAt:q,mediaUrls:S(w),metadata:U},{workspace:!0});V(X,u);return}case"publish":case"publish-now":{let U=P(w)??{},m=Gu(w,U),d=h(w),q=await z.post("/api/posts/publish-now",{content:m,socialAccountIds:d,mediaUrls:S(w),metadata:U,naturalPosting:R(w,"natural","natural-posting")},{workspace:!0});if(!R(w,"wait")){V(q,u);return}let Z=Array.isArray(q)?q:[];if(Z.length===0||!Z.every((k)=>typeof k?.id==="string"))throw new y("publish --wait expected an array of created posts with ids",O.NETWORK,{data:q});let J=H(w,"wait-timeout","timeout")??120,G=await Qw(z,u,Z,J);V({queued:Z,posts:G,status:G.every((k)=>k.status==="published")?"published":G[0]?.status},u);return}case"reschedule":{let U=D[0];if(!U)throw new y("Usage: dun posts reschedule <id> --at|--in",O.USAGE);let d={scheduledAt:e({at:Q(w,"at"),in:Q(w,"in")})},q=Q(w,"text","content","c","t");if(q)d.content=q;let X=S(w);if(X.length)d.mediaUrls=X;let Z=P(w);if(Z)d.metadata=Z;if(!d.content){let G=await z.get(`/api/posts/${U}`,{workspace:!0});if(d.content=G.content,!d.metadata&&G.metadata)d.metadata=G.metadata;if(!d.mediaUrls&&G.mediaUrls)d.mediaUrls=G.mediaUrls}let J=await z.post(`/api/posts/${U}/reschedule`,d,{workspace:!0});V(J,u);return}case"cancel":{let U=D[0];if(!U)throw new y("Usage: dun posts cancel <id>",O.USAGE);let m=await z.post(`/api/posts/${U}/cancel`,void 0,{workspace:!0});V(m??{id:U,status:"cancelled"},u);return}case"delete":case"rm":{let U=D[0];if(!U)throw new y("Usage: dun posts delete <id> [--yes]",O.USAGE);if(!u.yes&&!R(w,"yes","y"))throw new y("Refusing to delete without --yes (or CI/yes mode)",O.VALIDATION);let m=await z.delete(`/api/posts/${U}`,void 0,{workspace:!0});V(m??{id:U,deleted:!0},u);return}case"x-cap":case"xcap":{let U=await z.get("/api/posts/x-cap-usage",{workspace:!0});V(U,u);return}case"schedule-thread":case"publish-thread":case"publish-thread-now":{let U=Q(w,"file","f"),m=Q(w,"account","accounts","a")??h(w)[0];if(!m)throw new y("Missing --account <xAccountId>",O.VALIDATION);let d;if(U){let X;try{X=Xw(U,"utf8")}catch(J){throw new y(`Could not read file: ${J.message}`,O.VALIDATION)}let Z=JSON.parse(X);if(Array.isArray(Z))d=Z;else if(Z&&typeof Z==="object"&&Array.isArray(Z.tweets))d=Z.tweets;else throw new y("Thread file must be an array of tweets or { tweets: [] }",O.VALIDATION)}else{let X=Q(w,"text","content");if(!X)throw new y("Provide --file thread.json (array of {content}) or informal --text with || separators is not enough alone for threads - use --file",O.VALIDATION);d=X.split("||").map((Z)=>({content:Z.trim()})).filter((Z)=>Z.content)}if(d.length<2)throw new y("Threads require at least 2 tweets",O.VALIDATION);if($==="schedule-thread"){let X=e({at:Q(w,"at"),in:Q(w,"in")}),Z=await z.post("/api/posts/schedule-thread",{socialAccountId:m,tweets:d,scheduledAt:X,metadata:P(w)??{}},{workspace:!0});V(Z,u);return}let q=await z.post("/api/posts/publish-thread-now",{socialAccountId:m,tweets:d,metadata:P(w)??{}},{workspace:!0});V(q,u);return}default:throw new y(`Unknown posts command "${$??""}". Try: list, get, validate, schedule, publish, reschedule, cancel, delete, x-cap, schedule-thread, publish-thread`,O.USAGE)}}async function Yu(u,$,w,D){F(u),W(u);let z=Y(u);switch($){case"list":case"ls":{let U=await z.get("/api/drafts",{workspace:!0,query:{limit:H(w,"limit")??50,offset:H(w,"offset")??0}});V(U,{...u,emptyMessage:'No drafts yet. Create one with dun drafts create --text "..."'});return}case"get":{let U=D[0];if(!U)throw new y("Usage: dun drafts get <id>",O.USAGE);let m=await z.get(`/api/drafts/${U}`,{workspace:!0});V(m,u);return}case"create":{let U=Q(w,"text","content","c","t");if(!U)throw new y("Missing --text",O.VALIDATION);let m=await z.post("/api/drafts",{content:U,name:Q(w,"name","n"),socialAccountIds:A(w,"accounts","account","a")??[],selectedPlatforms:A(w,"platforms","platform","p")??[],mediaUrls:A(w,"media")??[]},{workspace:!0});V(m,u);return}case"update":{let U=D[0];if(!U)throw new y("Usage: dun drafts update <id> --text ...",O.USAGE);let m={id:U},d=Q(w,"text","content","c","t");if(d)m.content=d;let q=Q(w,"name","n");if(q!==void 0)m.name=q;let X=A(w,"accounts","account","a");if(X)m.socialAccountIds=X;let Z=A(w,"platforms","platform","p");if(Z)m.selectedPlatforms=Z;let J=A(w,"media");if(J)m.mediaUrls=J;let G=await z.patch(`/api/drafts/${U}`,m,{workspace:!0});V(G,u);return}case"delete":case"rm":{let U=D[0];if(!U)throw new y("Usage: dun drafts delete <id> [--yes]",O.USAGE);if(!u.yes&&!R(w,"yes","y"))throw new y("Refusing to delete without --yes",O.VALIDATION);let m=await z.delete(`/api/drafts/${U}`,void 0,{workspace:!0});V(m??{id:U,deleted:!0},u);return}default:throw new y(`Unknown drafts command "${$??""}". Try: list, get, create, update, delete`,O.USAGE)}}import{readFileSync as Gw,existsSync as Rw,statSync as kw}from"node:fs";import{basename as Yw}from"node:path";var Fu=["image/jpeg","image/png","image/gif","image/webp"],bu=["video/mp4","video/quicktime","video/webm"];function Wu(u){if(u<1024)return`${u}B`;if(u<1048576)return`${(u/1024).toFixed(1)}KB`;return`${(u/1048576).toFixed(1)}MB`}function Ku(u){let{mimeType:$,fileSize:w}=u,D=Fu.includes($),z=bu.includes($);if(!D&&!z)return{ok:!1,message:`Unsupported MIME type "${$}". Allowed images: ${Fu.join(", ")}; videos: ${bu.join(", ")}`};if(z&&w>268435456)return{ok:!1,message:`Video files must be less than 256MB (got ${Wu(w)}). Compress first, e.g.:
|
|
217
|
+
ffmpeg -i input.mp4 -vf scale=-2:1080 -c:v libx264 -crf 23 -c:a aac output.mp4`};if(D&&w>8388608)return{ok:!1,message:`Image files must be less than 8MB (got ${Wu(w)}).`};return{ok:!0}}function Fw(u){let $=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"}[$]??"application/octet-stream"}async function Tu(u,$,w,D){F(u),W(u);let z=Y(u);switch($){case"list":case"ls":{let U=await z.get("/api/media",{workspace:!0,query:{limit:H(w,"limit")??50,offset:H(w,"offset")??0}});V(U,{...u,emptyMessage:"No media yet. Upload with dun media upload <file>."});return}case"get":{let U=D[0];if(!U)throw new y("Usage: dun media get <id>",O.USAGE);let m=await z.get(`/api/media/${U}`,{workspace:!0});V(m,u);return}case"upload":{let U=D[0]||Q(w,"file","f");if(!U)throw new y('Usage: dun media upload <file> [--alt "..."]',O.USAGE);if(!Rw(U))throw new y(`File not found: ${U}`,O.VALIDATION);let m=Yw(U),d=kw(U).size,q=Q(w,"mime","type","content-type")||Fw(m),X=Q(w,"alt","alt-text"),Z=Ku({mimeType:q,fileSize:d});if(!Z.ok)throw new y(Z.message,O.VALIDATION);let J=await z.post("/api/media/upload-url",{filename:m,mimeType:q,fileSize:d},{workspace:!0});M(u.debug,`PUT ${J.uploadUrl}`,{storageKey:J.storageKey,fileSize:d});let G=Gw(U),k;try{k=await fetch(J.uploadUrl,{method:"PUT",headers:{"Content-Type":q,"Content-Length":String(d)},body:G})}catch(N){throw new y(`Upload PUT failed: ${N.message}`,O.NETWORK)}if(!k.ok){let N=await k.text().catch(()=>"");throw new y(`Upload PUT failed with HTTP ${k.status}${N?`: ${N.slice(0,200)}`:""}`,O.NETWORK)}let _=await z.post("/api/media/complete",{storageKey:J.storageKey,originalFilename:m,mimeType:q,fileSize:d,altText:X},{workspace:!0});V(_,u);return}case"delete":case"rm":{let U=D[0];if(!U)throw new y("Usage: dun media delete <id> [--yes]",O.USAGE);if(!u.yes&&!R(w,"yes","y"))throw new y("Refusing to delete without --yes",O.VALIDATION);let m=await z.delete(`/api/media/${U}`,void 0,{workspace:!0});V(m??{id:U,deleted:!0},u);return}default:throw new y(`Unknown media command "${$??""}". Try: list, get, upload, delete`,O.USAGE)}}async function Bu(u,$,w,D){F(u),W(u);let z=Y(u),U=$[0];if(U==="collections"||U==="collection"){let m=$[1]||"list";switch(m){case"list":case"ls":{let d=await z.get("/api/memory/collections",{workspace:!0});V(d,{...u,emptyMessage:'No memory collections yet. Create one with dun memory collections create --name "..."'});return}case"create":{let d=Q(w,"name","n");if(!d)throw new y("Missing --name",O.VALIDATION);let q=await z.post("/api/memory/collections",{name:d,color:Q(w,"color")??"blue",isPrivate:R(w,"private")},{workspace:!0});V(q,u);return}case"get":{let d=$[2]||D[0];if(!d)throw new y("Usage: dun memory collections get <id>",O.USAGE);let q=await z.get(`/api/memory/collections/${d}`,{workspace:!0});V(q,u);return}default:throw new y(`Unknown memory collections command "${m}". Try: list, create, get`,O.USAGE)}}switch(U){case"list":case"ls":{let m=Q(w,"collection","collection-id","c");if(!m)throw new y("Missing --collection <id>",O.VALIDATION);let d=await z.get("/api/memory",{workspace:!0,query:{collectionId:m,limit:H(w,"limit")??100}});V(d,{...u,emptyMessage:"No memories in this collection."});return}case"save":case"add":{let m=Q(w,"collection","collection-id","c"),d=Q(w,"text","t");if(!m)throw new y("Missing --collection <id>",O.VALIDATION);if(!d)throw new y("Missing --text",O.VALIDATION);let q=await z.post("/api/memory",{collectionId:m,text:d},{workspace:!0});V(q,u);return}case"search":{let m=Q(w,"prompt","q","query","text"),d=A(w,"collections","collection","collection-ids","c")??[];if(!m)throw new y("Missing --prompt",O.VALIDATION);if(d.length===0)throw new y("Missing --collections <id,id>",O.VALIDATION);let q=await z.post("/api/memory/search",{prompt:m,collectionIds:d,topK:H(w,"top-k","topk","k")??5},{workspace:!0});V(q,u);return}case"delete":case"rm":{let m=$[1]||D[0],d=Q(w,"collection","collection-id","c");if(!m)throw new y("Usage: dun memory delete <id> --collection <id>",O.USAGE);if(!d)throw new y("Missing --collection <id>",O.VALIDATION);if(!u.yes&&!R(w,"yes","y"))throw new y("Refusing to delete without --yes",O.VALIDATION);let q=await z.delete(`/api/memory/${m}`,{collectionId:d,memoryId:m},{workspace:!0});V(q??{id:m,deleted:!0},u);return}default:throw new y(`Unknown memory command "${U??""}". Try: collections, list, save, search, delete`,O.USAGE)}}import{readFileSync as bw}from"node:fs";async function Hu(u,$,w,D){F(u);let z=W(u),U=Y(u),m=`/api/workspaces/${z}/ai-voice-settings`;switch($){case"get":case"show":case void 0:{let d=await U.get(m,{workspace:!0});V(d??{personalization:null,hint:'No personalization set. Use dun personalization set --description "..."'},u);return}case"set":case"update":{let d=R(w,"clear"),q=Q(w,"description","d"),X=Q(w,"file","f");if([d,Boolean(q),Boolean(X)].filter(Boolean).length!==1)throw new y("Use exactly one of --description, --file, or --clear",O.VALIDATION);let J;if(d)J=null;else if(X){let k;try{k=bw(X,"utf8").trim()}catch(_){throw new y(`Could not read file: ${_.message}`,O.VALIDATION)}if(!k)throw new y("File is empty",O.VALIDATION);J={description:k}}else{let k=q.trim();if(!k)throw new y("--description cannot be empty",O.VALIDATION);J={description:k}}let G=await U.patch(m,J,{workspace:!0});V(G,u);return}default:throw new y(`Unknown personalization command "${$}". Try: get, set`,O.USAGE)}}function Au(u){return u.trim().replace(/^\/?r\//i,"").replace(/^@/,"")}async function s(u,$,w,D){F(u),W(u);let z=Y(u);switch($){case"flairs":case"flair":case"flair-options":{let U=D[0]||Q(w,"subreddit","sub","r");if(!U)throw new y(`Usage: dun reddit flairs <subreddit>
|
|
218
|
+
Example: dun reddit flairs tamilyapping --json`,O.USAGE);let m=Au(U),q=((await z.get("/api/social-accounts/reddit/flair-options",{workspace:!0,query:{subreddit:m}})).choices??[]).map((X)=>({id:X.id,text:X.text,textEditable:X.textEditable!==!1}));V({subreddit:m,choices:q},{...u,emptyMessage:`No flairs returned for r/${m}. The subreddit may not use post flair.`});return}case"requirements":case"post-requirements":{let U=D[0]||Q(w,"subreddit","sub","r");if(!U)throw new y("Usage: dun reddit requirements <subreddit>",O.USAGE);let m=Au(U),d=await z.get("/api/social-accounts/reddit/post-requirements",{workspace:!0,query:{subreddit:m}});V({subreddit:m,requirements:d},u);return}default:throw new y(`Unknown reddit command "${$??""}". Try: flairs, requirements`,O.USAGE)}}import{existsSync as Ww}from"node:fs";import{mkdir as Mu,writeFile as Pu,readFile as _u}from"node:fs/promises";import{dirname as a,join as b}from"node:path";import{homedir as t}from"node:os";import{fileURLToPath as Kw}from"node:url";var p=[{id:"claude",label:"Claude Code",aliases:["claude-code"],dest:(u)=>b(u,".claude","skills","dunsocial","SKILL.md")},{id:"codex",label:"Codex",dest:(u)=>b(u,".codex","skills","dunsocial","SKILL.md"),afterInstall:async(u)=>{return{agentsPath:await Aw(u)}}},{id:"cursor",label:"Cursor",dest:(u)=>b(u,".cursor","skills","dunsocial","SKILL.md")},{id:"pi",label:"Pi",dest:(u)=>b(u,".pi","agent","skills","dunsocial","SKILL.md")},{id:"opencode",label:"OpenCode",dest:(u)=>b(u,".config","opencode","skills","dunsocial","SKILL.md")},{id:"agents",label:"Universal (.agents)",aliases:["universal"],dest:(u)=>b(u,".agents","skills","dunsocial","SKILL.md")},{id:"copilot",label:"GitHub Copilot",aliases:["github-copilot","github"],dest:(u)=>b(u,".copilot","skills","dunsocial","SKILL.md")},{id:"windsurf",label:"Windsurf",dest:(u)=>b(u,".codeium","windsurf","skills","dunsocial","SKILL.md")},{id:"goose",label:"Goose",dest:(u)=>b(u,".config","goose","skills","dunsocial","SKILL.md")},{id:"gemini",label:"Gemini CLI",aliases:["gemini-cli"],dest:(u)=>b(u,".gemini","skills","dunsocial","SKILL.md")},{id:"amp",label:"Amp",dest:(u)=>b(u,".config","agents","skills","dunsocial","SKILL.md")},{id:"grok",label:"Grok Build",dest:(u)=>b(u,".grok","skills","dunsocial","SKILL.md")},{id:"continue",label:"Continue",dest:(u)=>b(u,".continue","skills","dunsocial","SKILL.md")},{id:"antigravity",label:"Antigravity",dest:(u)=>b(u,".gemini","antigravity","skills","dunsocial","SKILL.md")}],x=new Map;for(let u of p){x.set(u.id,u);for(let $ of u.aliases??[])x.set($,u)}var Nu=`Usage: dun skill install <${p.map((u)=>u.id).join("|")}|all>`;function l(){let u=a(Kw(import.meta.url)),$=b("skills","dunsocial","SKILL.md"),w=[b(u,"..",$),b(u,"..","..",$)];return w.find(Ww)??w[0]}function Tw(){let u=t();return p.map(($)=>({id:$.id,label:$.label,path:$.dest(u),aliases:$.aliases??[]}))}async function Bw(){try{return await _u(l(),"utf8")}catch{throw new y(`Bundled skill not found at ${l()}. Reinstall dunsocial.`,O.USAGE)}}async function Hw(u,$){await Mu(a(u),{recursive:!0}),await Pu(u,$,"utf8")}async function Aw(u){let $=b(t(),".codex","AGENTS.md");await Mu(a($),{recursive:!0});let w="";try{w=await _u($,"utf8")}catch{w=""}let D=["<!-- 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(`
|
|
219
|
+
`),z="<!-- BEGIN DUNSOCIAL CLI SKILL -->",U="<!-- END DUNSOCIAL CLI SKILL -->",m,d=w.indexOf(z),q=w.indexOf(U);if(d!==-1&&q!==-1&&q>d)m=w.slice(0,d)+D+w.slice(q+U.length);else if(w.trim())m=`${w.trimEnd()}
|
|
220
|
+
|
|
221
|
+
${D}
|
|
222
|
+
`;else m=`${D}
|
|
223
|
+
`;return await Pu($,m,"utf8"),$}async function Iu(u,$){let w=u.dest(t());await Hw(w,$);let D=u.afterInstall?await u.afterInstall(w):{};return{target:u.id,path:w,message:`Installed DunSocial skill for ${u.label}. Restart or open a new session if needed.`,...D}}async function ju(u,$,w,D){switch($){case"path":{V({path:l()},u);return}case"list":{V({targets:Tw(),hint:"Install with: dun skill install <target|all>"},u);return}case"install":{let z=(D[0]||"").toLowerCase();if(!z)throw new y(Nu,O.USAGE);let U=await Bw();if(z==="all"){let q=[];for(let X of p){let Z=await Iu(X,U);q.push({target:Z.target,path:Z.path})}V({target:"all",count:q.length,installed:q,message:`Installed DunSocial skill for ${q.length} agents.`},u);return}let m=x.get(z);if(!m)throw new y(`Unknown agent "${z}". ${Nu}
|
|
224
|
+
Try: dun skill list`,O.USAGE);let d=await Iu(m,U);V(d,u);return}default:throw new y(`Unknown skill command "${$??""}". Try: install, list, path`,O.USAGE)}}import{spawn as Nw}from"node:child_process";import{realpathSync as Iw}from"node:fs";var T="dunsocial",Mw=`https://registry.npmjs.org/${T}/latest`;function Pw(u=process.argv[1]??""){let $=u.replaceAll("\\","/");try{$=Iw(u).replaceAll("\\","/")}catch{}if($.includes("/.npm/_npx")||$.includes("/npm/_npx")||$.includes("/_npx/"))return{packageManager:"npx",manual:`npm install -g ${T}@latest`};if($.includes("/.pnpm/")||$.includes("/pnpm/"))return{packageManager:"pnpm",command:"pnpm",args:["add","-g",`${T}@latest`],manual:`pnpm add -g ${T}@latest`};if($.includes("/.yarn/")||$.includes("/yarn/global"))return{packageManager:"yarn",command:"yarn",args:["global","add",`${T}@latest`],manual:`yarn global add ${T}@latest`};if($.includes("/.bun/")||$.includes("/bun/install/global"))return{packageManager:"bun",command:"bun",args:["add","-g",`${T}@latest`],manual:`bun add -g ${T}@latest`};if($.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 _w(u,$){let w=u.replace(/^v/,"").split(".").map((U)=>Number.parseInt(U,10)||0),D=$.replace(/^v/,"").split(".").map((U)=>Number.parseInt(U,10)||0),z=Math.max(w.length,D.length);for(let U=0;U<z;U++){let m=w[U]??0,d=D[U]??0;if(m>d)return 1;if(m<d)return-1}return 0}async function jw(u=fetch){let $=await u(Mw,{headers:{Accept:"application/json"}});if(!$.ok)throw new y(`Could not check npm for updates (HTTP ${$.status}). Try: npm install -g ${T}@latest`,O.NETWORK);let w=await $.json();if(!w.version)throw new y("npm registry response missing version",O.NETWORK);return w.version}function Lw(u,$){return new Promise((w,D)=>{let z=Nw(u,$,{stdio:"inherit",env:process.env,windowsHide:!0,shell:process.platform==="win32"});z.on("error",(U)=>{D(new y(`Failed to run ${u}: ${U.message}. Try manually: ${u} ${$.join(" ")}`,O.NETWORK))}),z.on("close",(U)=>w(U??1))})}async function Lu(u,$,w){let D=R(w,"check"),z=R(w,"force"),U=B,m=Pw(),d;try{d=await jw()}catch(J){if(J instanceof y)throw J;throw new y(`Could not check npm for updates: ${J.message}`,O.NETWORK)}let q=_w(d,U)>0,X={current:U,latest:d,upToDate:!q,packageManager:m.packageManager,command:m.manual};if(!q&&!z){V(u.json?X:`Already on the latest version (${U}).`,u);return}if(D){V(u.json?{...X,updateAvailable:q}:`Update available: ${U} → ${d}
|
|
225
|
+
Run: dun update
|
|
226
|
+
Or: ${m.manual}`,u);return}if(!m.command||!m.args){V(u.json?{...X,applied:!1,hint:m.manual}:`Update available: ${U} → ${d}
|
|
227
|
+
Cannot auto-update this install (${m.packageManager}).
|
|
228
|
+
Run: ${m.manual}`,u);return}if(!u.json&&!u.quiet)process.stderr.write(`Updating ${T}: ${U} → ${d} via ${m.packageManager}...
|
|
229
|
+
`);let Z=await Lw(m.command,m.args);if(Z!==0)throw new y(`Update command failed (exit ${Z}). Try: ${m.manual}`,O.NETWORK);V(u.json?{...X,applied:!0}:`Updated via ${m.packageManager}. Run dun --version to confirm.`,u)}function vu(){if(I(process.stdout))process.stdout.write(`${yu()}
|
|
230
|
+
|
|
231
|
+
`);process.stdout.write(`${g}
|
|
232
|
+
`)}async function vw(){let u=await E(),$=process.env.DUN_TOKEN||u.token,w=process.env.DUN_WORKSPACE_ID||u.defaultWorkspaceId;process.stdout.write(`${Xu({token:$,workspaceId:w,config:u})}
|
|
233
|
+
`)}async function nw(u){let $=du(u),{group:w,action:D,nest:z,flags:U,positionals:m}=$;if(C(U)&&!w)return process.stdout.write(`${B}
|
|
234
|
+
`),O.OK;if(w==="help"||!w&&i(U)){let q=w==="help"?D||m[0]:void 0;if(q)process.stdout.write(`${r(q)}
|
|
235
|
+
`);else vu();return O.OK}if(!w){if(I(process.stdout))await vw();else vu();return O.OK}if(i(U))return process.stdout.write(`${r(w)}
|
|
236
|
+
`),O.OK;let d=await Uu({apiUrl:Q(U,"api-url","apiUrl"),token:Q(U,"token"),workspace:Q(U,"workspace","w"),json:R(U,"json","j")?!0:void 0,debug:R(U,"debug"),quiet:R(U,"quiet","q"),yes:R(U,"yes","y")});if(C(U))return V({version:B},d),O.OK;try{switch(w){case"auth":await Vu(d,D,U,m);break;case"workspace":case"workspaces":await Qu(d,D,U,m);break;case"account":case"accounts":if(D==="reddit"){await s(d,m[0],U,m.slice(1));break}await Ju(d,D??"list",U,m);break;case"reddit":await s(d,D,U,m);break;case"post":case"posts":await ku(d,D,U,m);break;case"draft":case"drafts":await Yu(d,D,U,m);break;case"media":await Tu(d,D,U,m);break;case"memory":{let q=z?[z,D].filter(Boolean):D?[D]:[];await Bu(d,q,U,m);break}case"personalization":case"voice":await Hu(d,D,U,m);break;case"skill":case"skills":await ju(d,D,U,m);break;case"update":case"upgrade":case"self-update":await Lu(d,D,U);break;case"version":V({version:B},d);break;default:throw new y(`Unknown command "${w}". Run dun --help`,O.USAGE)}return O.OK}catch(q){return Du(q,d)}}var ew=await nw(process.argv.slice(2));process.exit(ew);
|
package/package.json
CHANGED
package/scripts/postinstall.js
CHANGED
|
@@ -1,30 +1,27 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Quiet install tip — silent in CI / non-TTY / agent / local deps.
|
|
4
|
+
* Max 2 lines; onboarding lives on bare `dun`, not here.
|
|
5
5
|
*/
|
|
6
6
|
'use strict';
|
|
7
7
|
|
|
8
|
+
import { readFileSync } from 'node:fs';
|
|
8
9
|
import path from 'node:path';
|
|
9
|
-
import { pathToFileURL } from 'node:url';
|
|
10
|
-
|
|
11
|
-
const BANNER_FULL = [
|
|
12
|
-
'█▀▀▄ █ █ █▀▀▄ █▀▀▀ █▀▀█ █▀▀▀ ▀█▀ █▀▀█ █',
|
|
13
|
-
'█ █ █ █ █ █ ▀▀▀█ █ █ █ █ █▀▀█ █',
|
|
14
|
-
'▀▀▀▀ ▀▀▀▀ ▀ ▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀ ▀ ▀ ▀▀▀'
|
|
15
|
-
].join('\n');
|
|
16
|
-
|
|
17
|
-
const BANNER_MINI = [
|
|
18
|
-
'█▀▀▄ █ █ █▀▀▄',
|
|
19
|
-
'█ █ █ █ █ █',
|
|
20
|
-
'▀▀▀▀ ▀▀▀▀ ▀ ▀',
|
|
21
|
-
'',
|
|
22
|
-
' DunSocial'
|
|
23
|
-
].join('\n');
|
|
10
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
24
11
|
|
|
25
12
|
/** Keep in sync with apps/cli/src/commands/help.ts Docs line. */
|
|
26
13
|
export const DOCS_URL = 'https://dunsocial.com/docs/cli';
|
|
27
14
|
|
|
15
|
+
function packageVersion() {
|
|
16
|
+
try {
|
|
17
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
18
|
+
const pkg = JSON.parse(readFileSync(path.join(here, '..', 'package.json'), 'utf8'));
|
|
19
|
+
return typeof pkg.version === 'string' ? pkg.version : '0.0.0';
|
|
20
|
+
} catch {
|
|
21
|
+
return '0.0.0';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
28
25
|
function isCi() {
|
|
29
26
|
const env = process.env;
|
|
30
27
|
return (
|
|
@@ -38,29 +35,11 @@ function isCi() {
|
|
|
38
35
|
);
|
|
39
36
|
}
|
|
40
37
|
|
|
41
|
-
function maxWidth(art) {
|
|
42
|
-
return Math.max(...art.split('\n').map((line) => line.length));
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function renderBanner(columns) {
|
|
46
|
-
const cols = columns > 0 ? columns : 80;
|
|
47
|
-
if (cols >= maxWidth(BANNER_FULL)) return BANNER_FULL;
|
|
48
|
-
if (cols >= maxWidth(BANNER_MINI)) return BANNER_MINI;
|
|
49
|
-
return 'DunSocial';
|
|
50
|
-
}
|
|
51
|
-
|
|
52
38
|
/** Human tip lines after a global install (exported for tests). */
|
|
53
|
-
export function gettingStartedTip() {
|
|
39
|
+
export function gettingStartedTip(version = packageVersion()) {
|
|
54
40
|
return [
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
' dun workspace list',
|
|
58
|
-
' dun workspace use <slug>',
|
|
59
|
-
' dun accounts list',
|
|
60
|
-
' dun posts publish --text "Hello from DunSocial" --accounts ACCOUNT_ID',
|
|
61
|
-
'',
|
|
62
|
-
' dun --help',
|
|
63
|
-
` Docs: ${DOCS_URL}`,
|
|
41
|
+
`dunsocial ${version} installed`,
|
|
42
|
+
`Run \`dun\` to get started | docs: ${DOCS_URL}`,
|
|
64
43
|
''
|
|
65
44
|
].join('\n');
|
|
66
45
|
}
|
|
@@ -73,11 +52,7 @@ function main() {
|
|
|
73
52
|
process.env.npm_config_global === 'true' || process.env.DUN_POSTINSTALL_FORCE === '1';
|
|
74
53
|
if (!globalInstall) return;
|
|
75
54
|
|
|
76
|
-
|
|
77
|
-
const banner = renderBanner(columns);
|
|
78
|
-
|
|
79
|
-
process.stderr.write(`\n${banner}\n\n`);
|
|
80
|
-
process.stderr.write(`${gettingStartedTip()}\n`);
|
|
55
|
+
process.stderr.write(`\n${gettingStartedTip()}\n`);
|
|
81
56
|
}
|
|
82
57
|
|
|
83
58
|
try {
|
|
@@ -69,6 +69,13 @@ Absolute time: `--at 2026-06-01T09:00:00Z`.
|
|
|
69
69
|
dun posts publish --text "Hello from dun" --accounts acc_x --json
|
|
70
70
|
```
|
|
71
71
|
|
|
72
|
+
`publish` **queues** work (`status: scheduled`). For a terminal outcome use `--wait`:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
dun posts publish --text "Hello" --accounts acc_x --wait --json
|
|
76
|
+
# optional: --wait-timeout 180
|
|
77
|
+
```
|
|
78
|
+
|
|
72
79
|
## Upload media then post
|
|
73
80
|
|
|
74
81
|
```bash
|
|
@@ -76,6 +83,63 @@ dun media upload ./shot.png --alt "Product screenshot" --json
|
|
|
76
83
|
dun posts schedule --text "…" --accounts acc_x --media <assetId> --in 30m --json
|
|
77
84
|
```
|
|
78
85
|
|
|
86
|
+
Local preflight rejects images > 8MB and video > 256MB **before** upload-url. Compress video first if needed:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
ffmpeg -i input.mp4 -vf scale=-2:1080 -c:v libx264 -crf 23 -c:a aac output.mp4
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Reddit (special)
|
|
93
|
+
|
|
94
|
+
Reddit needs platform metadata under `--meta`. Discover flairs first — many subs require a **template id**, not free text.
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
dun accounts list --platform reddit --json
|
|
98
|
+
dun reddit flairs tamilyapping --json
|
|
99
|
+
# -> { id, text, textEditable }
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Required `metadata.reddit` fields:
|
|
103
|
+
|
|
104
|
+
| Field | Notes |
|
|
105
|
+
|-------|--------|
|
|
106
|
+
| `subreddit` | without `r/` |
|
|
107
|
+
| `kind` | `self` \| `link` \| `image` \| `video` |
|
|
108
|
+
| `title` | max 300 (sub may be stricter) |
|
|
109
|
+
| `flairId` | template id from `dun reddit flairs` when flair is required |
|
|
110
|
+
|
|
111
|
+
Optional: `body` (self), `url` (link), `flairText` (**only** when `textEditable` is true), `posterMediaAssetId`, `nsfw`, `spoiler`.
|
|
112
|
+
|
|
113
|
+
**Do not** send `flairText` without `flairId`. For non-editable templates, send **`flairId` alone**.
|
|
114
|
+
|
|
115
|
+
### Worked Reddit video example
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
dun media upload ./demo.mp4 --json
|
|
119
|
+
# assetId from response
|
|
120
|
+
|
|
121
|
+
dun reddit flairs tamilyapping --json
|
|
122
|
+
# pick flairId
|
|
123
|
+
|
|
124
|
+
dun posts validate \
|
|
125
|
+
--accounts <redditAccountId> \
|
|
126
|
+
--media <assetId> \
|
|
127
|
+
--meta '{"reddit":{"subreddit":"tamilyapping","kind":"video","title":"Approved title","flairId":"<id>"}}' \
|
|
128
|
+
--json
|
|
129
|
+
|
|
130
|
+
dun posts publish \
|
|
131
|
+
--accounts <redditAccountId> \
|
|
132
|
+
--media <assetId> \
|
|
133
|
+
--meta '{"reddit":{"subreddit":"tamilyapping","kind":"video","title":"Approved title","flairId":"<id>"}}' \
|
|
134
|
+
--wait \
|
|
135
|
+
--json
|
|
136
|
+
# (--text optional for Reddit when metadata.reddit.title is set)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
`--wait` polls until `published` or `failed` and returns `publishedPostUrl` (post permalink, not the subreddit root).
|
|
140
|
+
|
|
141
|
+
Also: `dun reddit requirements <subreddit> --json` for live rules (`is_flair_required`, title limits).
|
|
142
|
+
|
|
79
143
|
## Drafts / memory / threads
|
|
80
144
|
|
|
81
145
|
```bash
|
|
@@ -84,7 +148,7 @@ dun memory collections list --json
|
|
|
84
148
|
dun memory save --collection <id> --text "…" --json
|
|
85
149
|
dun memory search --prompt "…" --collections <id> --json
|
|
86
150
|
|
|
87
|
-
# thread.json: [ {"content":"1"},
|
|
151
|
+
# thread.json: [ {"content":"1"},{"content":"2"} ]
|
|
88
152
|
dun posts schedule-thread --account acc_x --file ./thread.json --in 2h --json
|
|
89
153
|
```
|
|
90
154
|
|
|
@@ -132,7 +196,8 @@ Failure JSON:
|
|
|
132
196
|
- Need workspace: `workspace use` or `--workspace` / `DUN_WORKSPACE_ID`
|
|
133
197
|
- `--accounts` = DunSocial social account **ids**, not handles
|
|
134
198
|
- Upload local files with `media upload` before attaching
|
|
135
|
-
-
|
|
199
|
+
- Reddit (and some other platforms) need `--meta '{"reddit":{…}}'`
|
|
200
|
+
- `posts get` / list never include OAuth secrets — safe to log
|
|
136
201
|
- MCP OAuth and CLI tokens are different systems
|
|
137
202
|
|
|
138
203
|
## Help
|
|
@@ -140,4 +205,5 @@ Failure JSON:
|
|
|
140
205
|
```bash
|
|
141
206
|
dun --help
|
|
142
207
|
dun posts --help
|
|
208
|
+
dun reddit --help
|
|
143
209
|
```
|