create-posthuman 0.1.1 → 0.1.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-posthuman",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "A starter folder for your own AI agent: your brand's voice, ideas, media and recipes on your computer, posted through Posthuman.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -16,7 +16,8 @@ schedules and posts what you and the user agree on.
16
16
  account's notes that isn't in `brand/voice.md` yet: add it there. Refresh `brand/accounts.md` from each
17
17
  account's `setup` (one `## <account>` heading each, then `- account_id:`, `- who reads it:`, `- sounds:`,
18
18
  `- what goes here:`, `- how often:`, `- never:` with `; ` between, `- like this:`; or `- not yet`; and
19
- `- posts so far:` with the account's `past_posts` number, 0 when the briefing shows none). Studio's
19
+ `- posts so far:` with the account's `past_posts` number, 0 when the briefing shows none; and `- longest post:`
20
+ with its `max_characters` when the briefing gives one, like an X account with Premium that takes long posts). Studio's
20
21
  **Accounts → Refresh** does the same. Then **About you**: Posthuman's `about_you` is the short profile the
21
22
  user's phone and other chats read; `brand/about.md` is the detail. Fill empty sections here from it, and when this
22
23
  folder knows more (what it is, who it's for, Topics, Goals, Links), send it with `set_about` in the user's own
@@ -3,3 +3,4 @@
3
3
  node_modules/
4
4
  library/**/*.part
5
5
  .studio
6
+ library/.thumbs/
@@ -12,8 +12,9 @@
12
12
  // - never: hashtags; naming my day job, Acme
13
13
  // - like this: Day 3 of building after the kids go to bed…
14
14
  // - posts so far: 46 (how many past posts Posthuman has for it; 0 = a brand-new account, see introFor)
15
+ // - longest post: 25000 (only when this account takes more than its platform usually does: X with Premium)
15
16
 
16
- const KEYS = { account_id: "account_id", "posts so far": "posts", "who reads it": "who_reads_it", sounds: "sounds", "what goes here": "what_goes_here", "how often": "how_often", never: "never", "like this": "like_this" };
17
+ const KEYS = { account_id: "account_id", "posts so far": "posts", "longest post": "max", "who reads it": "who_reads_it", sounds: "sounds", "what goes here": "what_goes_here", "how often": "how_often", never: "never", "like this": "like_this" };
17
18
 
18
19
  export function parseAccounts(text = "") {
19
20
  const out = [];
@@ -35,6 +36,7 @@ export function parseAccounts(text = "") {
35
36
  if (!k) continue;
36
37
  if (k === "account_id") cur.account_id = Number(kv[2]) || null;
37
38
  else if (k === "posts") cur.posts = /^\d+$/.test(kv[2].trim()) ? Number(kv[2]) : null;
39
+ else if (k === "max") cur.max = Number(kv[2].replace(/[,_\s]/g, "")) || null;
38
40
  else if (/^not yet/i.test(kv[2])) continue;
39
41
  else {
40
42
  cur.setup ??= {};
@@ -53,6 +55,7 @@ export function writeAccounts(accounts, { url = "", now = new Date() } = {}) {
53
55
  `## ${line(a.account)}`,
54
56
  a.account_id ? `- account_id: ${a.account_id}` : "",
55
57
  Number.isInteger(a.past_posts ?? a.posts) ? `- posts so far: ${a.past_posts ?? a.posts}` : "",
58
+ Number(a.max_characters ?? a.max) > 0 ? `- longest post: ${Number(a.max_characters ?? a.max)}` : "",
56
59
  ...(s
57
60
  ? [
58
61
  s.who_reads_it && `- who reads it: ${line(s.who_reads_it)}`,
@@ -60,7 +60,8 @@ export function checkPost(file, { root = ROOT } = {}) {
60
60
  }
61
61
  for (const acct of listOf(p.front.accounts)) {
62
62
  const w = wordsFor(p, acct);
63
- for (const f of [...lengthCheck(acct, w, { media }), ...fitCheck(setupFor(acct, accts)?.setup, w)]) out.push({ where: acct, tell: f.issue, found: [], fix: f.fix });
63
+ const known = setupFor(acct, accts);
64
+ for (const f of [...lengthCheck(acct, w, { media, max: known?.max }), ...fitCheck(known?.setup, w)]) out.push({ where: acct, tell: f.issue, found: [], fix: f.fix });
64
65
  }
65
66
  return out;
66
67
  }
@@ -4,6 +4,8 @@
4
4
  //
5
5
  // Thread platforms (X, Bluesky, Mastodon, Threads) post each --- part under the one before, so each part has to fit.
6
6
  // Everywhere else the parts go out as one post, so the whole thing has to fit.
7
+ // Some accounts take more than their platform usually does (X with Premium: 25,000). Posthuman's briefing says so
8
+ // (max_characters), brand/accounts.md keeps it as "- longest post:", and the callers pass it here as { max }.
7
9
 
8
10
  export const PLATFORMS = [
9
11
  { id: "x", re: /^x\b|^twitter\b/i, name: "X", limit: 280, thread: true, count: "x" },
@@ -55,10 +57,10 @@ export function lengthOn(platform, text) {
55
57
  const split = (t) => String(t ?? "").split(/\n-{3}[ \t]*(?:\n|$)/).map((s) => s.trim()).filter(Boolean);
56
58
 
57
59
  /** [{ part, length, limit }] for one account's words: each part on a thread platform, the whole post elsewhere. */
58
- export function lengthsFor(account, words, { media = 0 } = {}) {
60
+ export function lengthsFor(account, words, { media = 0, max = 0 } = {}) {
59
61
  const p = platformOf(account);
60
62
  if (!p) return [];
61
- const limit = media && p.withMedia ? p.withMedia : p.limit;
63
+ const limit = Number(max) > 0 ? Number(max) : media && p.withMedia ? p.withMedia : p.limit;
62
64
  const parts = split(words);
63
65
  if (p.thread) return parts.map((t, i) => ({ part: parts.length > 1 ? i + 1 : 0, length: lengthOn(p, t), limit }));
64
66
  return [{ part: 0, length: lengthOn(p, parts.join("\n\n")), limit }];
@@ -51,7 +51,7 @@ export const accountsView = () => {
51
51
  export function refreshAccounts() {
52
52
  const prompt =
53
53
  "Call the posthuman briefing tool. Reply with ONLY a JSON array, nothing else: one object per account in the briefing, " +
54
- '{"account_id": its account_id, "account": its account name exactly as the briefing says it, "setup": its setup object exactly as given, or the string "not yet", "past_posts": its past_posts number, or 0 when the briefing shows none}. ' +
54
+ '{"account_id": its account_id, "account": its account name exactly as the briefing says it, "setup": its setup object exactly as given, or the string "not yet", "past_posts": its past_posts number, or 0 when the briefing shows none, "max_characters": its max_characters number only when the briefing gives one (an X account with Premium), else leave it out}. ' +
55
55
  "If Posthuman isn't connected, reply with exactly: NOT CONNECTED";
56
56
  return runAgent("accounts", prompt, [...mcpConfig(), "--allowedTools", ...POSTHUMAN_READ, "--disallowedTools", "Bash", "Edit", "Write"], {
57
57
  onDone(job) {
@@ -180,6 +180,18 @@ main { padding: 26px 28px 80px; min-width: 0; }
180
180
  .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
181
181
  .grid .tile { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--card); cursor: pointer; }
182
182
  .grid .tile img, .grid .tile video { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
183
+ .lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-top: 14px; }
184
+ .lib-card { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: var(--card); display: grid; grid-template-rows: auto 1fr; }
185
+ .lib-media { position: relative; display: block; background: #111; aspect-ratio: 4 / 5; }
186
+ .lib-media img, .lib-media video { width: 100%; height: 100%; object-fit: contain; display: block; }
187
+ .lib-media.audio { display: grid; place-items: center; font-size: 40px; background: var(--paper); color: var(--soft); }
188
+ .lib-badge { position: absolute; left: 8px; bottom: 8px; background: rgb(0 0 0 / .65); color: #fff; font-size: 11px; font-weight: 700; border-radius: 999px; padding: 2px 8px; }
189
+ .lib-body { padding: 10px 12px 12px; display: grid; gap: 6px; align-content: start; }
190
+ .lib-alt { margin: 0; font-size: 13px; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
191
+ .lib-alt.none { color: var(--soft); font-style: italic; }
192
+ .lib-meta { margin: 0; font-size: 11px; color: var(--soft); }
193
+ .lib-meta b { color: var(--ink); font-weight: 600; }
194
+ .lib-body button { justify-self: start; }
183
195
  .grid .tile .cap { font-size: 11px; padding: 4px 6px; color: var(--soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
184
196
  .grid .tile.audio { display: grid; place-items: center; aspect-ratio: 1; font-size: 26px; }
185
197
 
@@ -518,7 +530,7 @@ function drawCounts() {
518
530
  $("#counts-line").innerHTML = accts.map((a) => {
519
531
  const pf = platformOf(a);
520
532
  if (lengthsFor) {
521
- const l = lengthsFor(a, resolved(a), { media: open.media.length });
533
+ const l = lengthsFor(a, resolved(a), { media: open.media.length, max: setupFor ? setupFor(a, S.accounts?.accounts || [])?.max : 0 });
522
534
  if (l.length) {
523
535
  const worst = l.reduce((m, x) => (x.length - x.limit > m.length - m.limit ? x : m));
524
536
  return `<span class="count ${worst.length > worst.limit ? "over" : ""}" title="${esc(a)}${worst.part ? `: part ${worst.part}` : ""}">${esc(pf.name)} ${worst.length}/${worst.limit}</span>`;
@@ -1131,18 +1143,41 @@ function drawMake() {
1131
1143
  // ---------- Library ----------
1132
1144
 
1133
1145
  function drawLibrary() {
1134
- $("#v-library").innerHTML = head("Library", "Everything made or dropped in, newest first. Click one to describe it: the description becomes its alt text.") + `
1146
+ $("#v-library").innerHTML = head("Library", "Everything made or dropped in, newest first. Point at a clip to play it, click it to open full size. The description becomes its alt text.") + `
1135
1147
  <div class="drop" id="libDrop">Drop pictures, clips or audio here</div>
1136
- <div class="grid" style="margin-top:14px;grid-template-columns:repeat(auto-fill,minmax(150px,1fr))">${S.library.map(tile).join("")}</div>${S.library.length ? "" : `<p class="small muted">Nothing yet.</p>`}`;
1148
+ <div class="lib-grid">${S.library.map(libCard).join("")}</div>${S.library.length ? "" : `<p class="small muted">Nothing yet.</p>`}`;
1137
1149
  dropZone($("#libDrop"), () => drawLibrary());
1138
- $("#v-library").querySelectorAll(".tile").forEach((t) => (t.onclick = async () => {
1139
- const x = S.library.find((y) => y.file === t.dataset.file);
1150
+ // A clip shows its still (library/.thumbs), plays muted while the pointer is on it, and says how long it is.
1151
+ $("#v-library").querySelectorAll(".lib-media video").forEach((v) => {
1152
+ v.parentElement.onmouseenter = () => v.play().catch(() => {});
1153
+ v.parentElement.onmouseleave = () => { v.pause(); };
1154
+ });
1155
+ $("#v-library").querySelectorAll("[data-describe]").forEach((t) => (t.onclick = async () => {
1156
+ const x = S.library.find((y) => y.file === t.dataset.describe);
1140
1157
  const alt = prompt(`Describe ${x.file} in one sentence (alt text):`, x.alt || "");
1141
1158
  if (alt === null) return;
1142
1159
  await api("PUT", "/api/alt", { file: x.file, alt }); x.alt = alt; drawLibrary(); toast("Description saved");
1143
1160
  }));
1144
1161
  }
1145
1162
 
1163
+ /** One thing in the library: the picture or clip (opens full size), what it is, which posts use it. */
1164
+ function libCard(x) {
1165
+ const src = media(x.file);
1166
+ const mb = x.size ? `${(x.size / 1048576).toFixed(x.size < 10485760 ? 1 : 0)} MB` : "";
1167
+ const shown = x.type === "video"
1168
+ ? `<video src="${src}" ${x.poster ? `poster="${media(x.poster)}" preload="none"` : `preload="metadata"`} muted playsinline loop></video><span class="lib-badge">▶ ${x.duration ? `${Math.floor(x.duration / 60)}:${String(Math.round(x.duration % 60)).padStart(2, "0")}` : "video"}</span>`
1169
+ : x.type === "audio" ? "♪" : `<img src="${src}" alt="${esc(x.alt)}" loading="lazy">`;
1170
+ const used = (x.used_in || []).length ? `In <b>${x.used_in.map(esc).join("</b>, <b>")}</b>` : "Not in a post yet";
1171
+ return `<div class="lib-card">
1172
+ <a class="lib-media ${x.type === "audio" ? "audio" : ""}" href="${src}" target="_blank" rel="noopener" title="Open ${esc(x.file)} full size">${shown}</a>
1173
+ <div class="lib-body">
1174
+ <p class="lib-alt ${x.alt ? "" : "none"}" title="${esc(x.alt)}">${x.alt ? esc(x.alt) : "No description yet"}</p>
1175
+ <p class="lib-meta">${used}<br>${esc(x.file)}${mb ? ` · ${mb}` : ""}</p>
1176
+ <button class="ghost small" data-describe="${esc(x.file)}">${x.alt ? "Change description" : "Describe it"}</button>
1177
+ </div>
1178
+ </div>`;
1179
+ }
1180
+
1146
1181
  function dropZone(el, done) {
1147
1182
  el.ondragover = (e) => { e.preventDefault(); el.classList.add("over"); };
1148
1183
  el.ondragleave = () => el.classList.remove("over");
@@ -115,7 +115,7 @@ function postView(file) {
115
115
  // Each account's hard no's (brand/accounts.md).
116
116
  fits: list(p.front.accounts).map((acct) => ({ account: acct, issues: fitCheck(setupFor(acct, ACCTS())?.setup, wordsFor(p, acct)) })).filter((f) => f.issues.length),
117
117
  // Too long for its platform (each part of a thread on X, Bluesky, Mastodon, Threads).
118
- long: list(p.front.accounts).map((acct) => ({ account: acct, issues: lengthCheck(acct, wordsFor(p, acct), { media: list(p.front.media).length }) })).filter((f) => f.issues.length),
118
+ long: list(p.front.accounts).map((acct) => ({ account: acct, issues: lengthCheck(acct, wordsFor(p, acct), { media: list(p.front.media).length, max: setupFor(acct, ACCTS())?.max }) })).filter((f) => f.issues.length),
119
119
  first_draft: p.other.find((s) => s.title === "First draft")?.text ?? null,
120
120
  rewrite_asked: p.other.find((s) => s.title === "Rewrite asked")?.text ?? null,
121
121
  other: p.other.filter((s) => !["Notes", "First draft", "Rewrite asked"].includes(s.title)),
@@ -183,16 +183,36 @@ function libraryRows() {
183
183
  }
184
184
  return rows;
185
185
  }
186
+ // A still and the length of each clip, made once with ffmpeg and kept in library/.thumbs/ (a clip's first frame is
187
+ // often blank, and a page of 20 MB videos shouldn't have to load to show what they are). No ffmpeg: no still.
188
+ const THUMBS = path.join(LIB, ".thumbs");
189
+ function clipFacts(rel, full) {
190
+ const base = path.join(THUMBS, rel.replace(/[\\/]/g, "__"));
191
+ const jpg = `${base}.jpg`, facts = `${base}.json`;
192
+ const fresh = (f) => fs.existsSync(f) && fs.statSync(f).mtimeMs >= fs.statSync(full).mtimeMs;
193
+ if (!fresh(facts)) {
194
+ fs.mkdirSync(THUMBS, { recursive: true });
195
+ const probe = spawnSync("ffprobe", ["-v", "error", "-show_entries", "format=duration", "-of", "default=nw=1:nk=1", full], { encoding: "utf8" });
196
+ if (probe.error) return {};
197
+ const duration = Number(probe.stdout.trim()) || 0;
198
+ spawnSync("ffmpeg", ["-v", "error", "-y", "-ss", String(Math.min(1, duration / 2)), "-i", full, "-frames:v", "1", "-vf", "scale=480:-2", jpg]);
199
+ fs.writeFileSync(facts, JSON.stringify({ duration }));
200
+ }
201
+ const { duration = 0 } = JSON.parse(fs.readFileSync(facts, "utf8"));
202
+ return { duration, poster: fs.existsSync(jpg) ? path.relative(LIB, jpg).split(path.sep).join("/") : "" };
203
+ }
186
204
  function libraryView() {
187
205
  const rows = libraryRows();
188
206
  const files = [];
189
207
  const walk = (d) => {
190
208
  for (const e of fs.existsSync(d) ? fs.readdirSync(d, { withFileTypes: true }) : []) {
191
209
  const f = path.join(d, e.name);
210
+ if (e.name.startsWith(".")) continue; // .thumbs and other hidden things aren't library items
192
211
  if (e.isDirectory()) walk(f);
193
212
  else if (/\.(jpe?g|png|webp|gif|mp4|mov|mp3|wav|m4a)$/i.test(e.name)) {
194
213
  const rel = path.relative(LIB, f).split(path.sep).join("/");
195
- files.push({ file: rel, type: typeOf(f).split("/")[0], alt: rows.get(rel)?.alt ?? "", made_with: rows.get(rel)?.made_with ?? "", size: fs.statSync(f).size, mtime: fs.statSync(f).mtimeMs });
214
+ const type = typeOf(f).split("/")[0];
215
+ files.push({ file: rel, type, ...(type === "video" ? clipFacts(rel, f) : {}), alt: rows.get(rel)?.alt ?? "", made_with: rows.get(rel)?.made_with ?? "", used_in: (rows.get(rel)?.used_in ?? "").split(/,\s*/).map((s) => s.replace(/\.md$/, "").trim()).filter(Boolean), size: fs.statSync(f).size, mtime: fs.statSync(f).mtimeMs });
196
216
  }
197
217
  }
198
218
  };
@@ -264,7 +284,7 @@ function rewritePrompt(slug, note, humanize) {
264
284
  const voice = readIf(brandFile(brand, "voice.md", ROOT));
265
285
  const setups = p.accounts.map((a) => ({ a, s: setupFor(a, ACCTS())?.setup })).filter((x) => x.s);
266
286
  // the tightest limit among its accounts (each part of a thread on X, Bluesky, Mastodon, Threads)
267
- const limits = p.accounts.map((a) => lengthsFor(a, "x")[0]?.limit).filter(Boolean);
287
+ const limits = p.accounts.map((a) => lengthsFor(a, "x", { max: setupFor(a, ACCTS())?.max })[0]?.limit).filter(Boolean);
268
288
  return [
269
289
  "Rewrite one social post. Reply with ONLY the new words of the post: no preamble, no quotes, no explanation.",
270
290
  `If it's a thread, keep a line holding only --- between the parts.${limits.length ? ` Each part must fit ${Math.min(...limits)} characters.` : ""}`,
@@ -334,7 +354,17 @@ const server = http.createServer(async (req, res) => {
334
354
  if (u.searchParams.get("t") !== TOKEN) return send(res, 403, { error: "token" });
335
355
  const f = inLib(decodeURIComponent(u.pathname.slice(9)));
336
356
  if (!f) return send(res, 404, { error: "no such file" });
337
- res.writeHead(200, { "Content-Type": typeOf(f), "Cache-Control": "no-store", "X-Content-Type-Options": "nosniff" });
357
+ // Ranges, so a clip can start playing (and skip ahead) before the whole file has come
358
+ const size = fs.statSync(f).size;
359
+ const range = /^bytes=(\d*)-(\d*)$/.exec(String(req.headers.range || ""));
360
+ if (range && size) {
361
+ const start = range[1] ? Number(range[1]) : Math.max(0, size - Number(range[2]));
362
+ const end = range[1] && range[2] ? Math.min(Number(range[2]), size - 1) : size - 1;
363
+ if (start > end || start >= size) { res.writeHead(416, { "Content-Range": `bytes */${size}` }); return res.end(); }
364
+ res.writeHead(206, { "Content-Type": typeOf(f), "Content-Range": `bytes ${start}-${end}/${size}`, "Content-Length": end - start + 1, "Accept-Ranges": "bytes", "Cache-Control": "no-store", "X-Content-Type-Options": "nosniff" });
365
+ return fs.createReadStream(f, { start, end }).pipe(res);
366
+ }
367
+ res.writeHead(200, { "Content-Type": typeOf(f), "Content-Length": size, "Accept-Ranges": "bytes", "Cache-Control": "no-store", "X-Content-Type-Options": "nosniff" });
338
368
  return fs.createReadStream(f).pipe(res);
339
369
  }
340
370
  // A file from one of your own folders (brand/sources.md), for Your stuff. Only those folders, only media.