@privateclaw/privateclaw 0.1.25 → 0.1.27

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.
@@ -0,0 +1,39 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import {
4
+ BOT_MODE_IDLE_TOPICS,
5
+ pickBotModeIdleTopic,
6
+ type BotModeIdleTopic,
7
+ } from "./bot-mode-topics.js";
8
+
9
+ test("bot mode idle topic bank exports 200 unique topics", () => {
10
+ assert.equal(BOT_MODE_IDLE_TOPICS.length, 200);
11
+ assert.equal(
12
+ new Set(BOT_MODE_IDLE_TOPICS.map((topic) => topic.id)).size,
13
+ BOT_MODE_IDLE_TOPICS.length,
14
+ );
15
+ assert.equal(
16
+ new Set(BOT_MODE_IDLE_TOPICS.map((topic) => topic.title)).size,
17
+ BOT_MODE_IDLE_TOPICS.length,
18
+ );
19
+ });
20
+
21
+ test("bot mode idle topic picker avoids immediately repeating the previous topic", () => {
22
+ const topics: ReadonlyArray<BotModeIdleTopic> = [
23
+ { id: "topic-a", title: "Topic A", prompt: "Prompt A" },
24
+ { id: "topic-b", title: "Topic B", prompt: "Prompt B" },
25
+ { id: "topic-c", title: "Topic C", prompt: "Prompt C" },
26
+ ];
27
+
28
+ const picked = pickBotModeIdleTopic(topics, "topic-b", 0.5);
29
+ assert.notEqual(picked.id, "topic-b");
30
+ });
31
+
32
+ test("bot mode idle topic picker still works with a single topic", () => {
33
+ const topics: ReadonlyArray<BotModeIdleTopic> = [
34
+ { id: "only-topic", title: "Only Topic", prompt: "Only Prompt" },
35
+ ];
36
+
37
+ const picked = pickBotModeIdleTopic(topics, "only-topic", 0.3);
38
+ assert.equal(picked.id, "only-topic");
39
+ });
@@ -0,0 +1,248 @@
1
+ export interface BotModeIdleTopic {
2
+ id: string;
3
+ title: string;
4
+ prompt: string;
5
+ }
6
+
7
+ export const BOT_MODE_IDLE_TOPICS: ReadonlyArray<BotModeIdleTopic> = [
8
+ // Cosmic oddities
9
+ { id: "moon-post-office", title: "Moon Post Office", prompt: "Imagine a post office on the far side of the Moon that only delivers letters after they stop being useful. Tell the group what happened today, add one vivid detail, and end with a playful question." },
10
+ { id: "comet-weather-desk", title: "Comet Weather Desk", prompt: "Imagine a weather station that forecasts the moods of comets instead of rain. Tell the group what happened today, add one vivid detail, and end with a playful question." },
11
+ { id: "saturn-ring-cleaner", title: "Saturn Ring Cleaner", prompt: "Imagine a gig-economy crew that polishes Saturn's rings before tourist season. Tell the group what happened today, add one vivid detail, and end with a playful question." },
12
+ { id: "eclipse-librarian", title: "Eclipse Librarian", prompt: "Imagine a library that only opens during eclipses and fines people in vanished time. Tell the group what happened today, add one vivid detail, and end with a playful question." },
13
+ { id: "asteroid-tea-house", title: "Asteroid Tea House", prompt: "Imagine a tea house carved into a drifting asteroid where every seat has a different gravity. Tell the group what happened today, add one vivid detail, and end with a playful question." },
14
+ { id: "gravity-tailor", title: "Gravity Tailor", prompt: "Imagine a tailor who hems coats differently depending on which planet the customer misses most. Tell the group what happened today, add one vivid detail, and end with a playful question." },
15
+ { id: "aurora-apology-bureau", title: "Aurora Apology Bureau", prompt: "Imagine a northern-lights hotline that helps people compose apologies visible from space. Tell the group what happened today, add one vivid detail, and end with a playful question." },
16
+ { id: "planetary-tour-guide-burnout", title: "Planetary Tour Guide Burnout", prompt: "Imagine a tired tour guide who has to make Mercury, Venus, and Pluto sound equally romantic. Tell the group what happened today, add one vivid detail, and end with a playful question." },
17
+ { id: "interstellar-lost-and-found", title: "Interstellar Lost and Found", prompt: "Imagine a warehouse of items misplaced during faster-than-light travel. Tell the group what happened today, add one vivid detail, and end with a playful question." },
18
+ { id: "sunlight-black-market", title: "Sunlight Black Market", prompt: "Imagine a black market where smugglers sell rare flavors of sunrise. Tell the group what happened today, add one vivid detail, and end with a playful question." },
19
+ // Time travel domestic life
20
+ { id: "yesterday-bakery", title: "Yesterday Bakery", prompt: "Imagine a bakery that sells pastries baked tomorrow but already going stale yesterday. Give the group one surprising consequence and one question they would have to answer." },
21
+ { id: "future-laundry-service", title: "Future Laundry Service", prompt: "Imagine a laundromat that returns your clothes from three personal eras at once. Give the group one surprising consequence and one question they would have to answer." },
22
+ { id: "rewind-dentist", title: "Rewind Dentist", prompt: "Imagine a dentist who offers to undo one regrettable conversation along with every filling. Give the group one surprising consequence and one question they would have to answer." },
23
+ { id: "borrowed-monday-shop", title: "Borrowed Monday Shop", prompt: "Imagine a service that lends people extra Mondays when their week feels too short. Give the group one surprising consequence and one question they would have to answer." },
24
+ { id: "minute-auction-house", title: "Minute Auction House", prompt: "Imagine an auction where bidders compete for spare minutes collected from late arrivals. Give the group one surprising consequence and one question they would have to answer." },
25
+ { id: "antique-tomorrow-store", title: "Antique Tomorrow Store", prompt: "Imagine an antiques shop that stocks heirlooms from futures that may never happen. Give the group one surprising consequence and one question they would have to answer." },
26
+ { id: "clocktower-caretaker", title: "Clocktower Caretaker", prompt: "Imagine a clocktower caretaker who can pause exactly one awkward moment per month. Give the group one surprising consequence and one question they would have to answer." },
27
+ { id: "weekend-smuggler", title: "Weekend Smuggler", prompt: "Imagine a smuggler who sneaks weekends across overloaded calendars. Give the group one surprising consequence and one question they would have to answer." },
28
+ { id: "delayed-birthday-club", title: "Delayed Birthday Club", prompt: "Imagine a club for people whose birthday celebrations arrive several years late. Give the group one surprising consequence and one question they would have to answer." },
29
+ { id: "time-zone-gardener", title: "Time-Zone Gardener", prompt: "Imagine a gardener who grows flowers that bloom in different time zones. Give the group one surprising consequence and one question they would have to answer." },
30
+ // City quirks
31
+ { id: "upside-down-subway", title: "Upside-Down Subway", prompt: "Imagine a subway line that flips gravity every third stop. Describe the weirdest local rule or scene and ask how the group would react." },
32
+ { id: "whisper-streetlights", title: "Whisper Streetlights", prompt: "Imagine a city block where streetlights only stay on if pedestrians gossip. Describe the weirdest local rule or scene and ask how the group would react." },
33
+ { id: "rain-language-crosswalk", title: "Rain-Language Crosswalk", prompt: "Imagine crosswalks that change language depending on the rainfall. Describe the weirdest local rule or scene and ask how the group would react." },
34
+ { id: "rooftop-ocean-market", title: "Rooftop Ocean Market", prompt: "Imagine a seafood market held on rooftops above a city that has never seen the sea. Describe the weirdest local rule or scene and ask how the group would react." },
35
+ { id: "invisible-alley-theater", title: "Invisible Alley Theater", prompt: "Imagine an alley where plays are performed for audiences who can only hear footsteps. Describe the weirdest local rule or scene and ask how the group would react." },
36
+ { id: "balcony-dragon-parking", title: "Balcony Dragon Parking", prompt: "Imagine an apartment district that treats tiny dragons like noisy scooters. Describe the weirdest local rule or scene and ask how the group would react." },
37
+ { id: "memory-taxi-network", title: "Memory Taxi Network", prompt: "Imagine taxis that accept forgotten memories instead of cash. Describe the weirdest local rule or scene and ask how the group would react." },
38
+ { id: "midnight-bridge-choir", title: "Midnight Bridge Choir", prompt: "Imagine a suspension bridge that hums harmonies whenever traffic stops at midnight. Describe the weirdest local rule or scene and ask how the group would react." },
39
+ { id: "vending-machine-mayor", title: "Vending-Machine Mayor", prompt: "Imagine a town whose most reliable public servant is a vending machine with policy opinions. Describe the weirdest local rule or scene and ask how the group would react." },
40
+ { id: "mailbox-oracle", title: "Mailbox Oracle", prompt: "Imagine a row of mailboxes that answer only the wrong question brilliantly. Describe the weirdest local rule or scene and ask how the group would react." },
41
+ // Creatures with jobs
42
+ { id: "philosophical-pigeon", title: "Philosophical Pigeon", prompt: "Imagine a pigeon that refuses crumbs and only accepts good arguments. Give them one memorable habit and one question worth debating." },
43
+ { id: "cloud-sheep-herder", title: "Cloud Sheep Herder", prompt: "Imagine a herder responsible for moving flocks of sheep-shaped clouds before storms. Give them one memorable habit and one question worth debating." },
44
+ { id: "tea-brewing-kraken", title: "Tea-Brewing Kraken", prompt: "Imagine a kraken whose tentacles make perfect tea but terrible first impressions. Give them one memorable habit and one question worth debating." },
45
+ { id: "neon-mole-cartographer", title: "Neon Mole Cartographer", prompt: "Imagine a glowing mole that keeps redrawing subway maps under the city. Give them one memorable habit and one question worth debating." },
46
+ { id: "insomnia-firefly-union", title: "Insomnia Firefly Union", prompt: "Imagine a union of fireflies striking because humans keep using them as mood lighting. Give them one memorable habit and one question worth debating." },
47
+ { id: "librarian-fox", title: "Librarian Fox", prompt: "Imagine a fox that shelves books by emotional danger rather than genre. Give them one memorable habit and one question worth debating." },
48
+ { id: "train-conductor-cat", title: "Train-Conductor Cat", prompt: "Imagine a cat that has somehow become the strictest conductor on a commuter line. Give them one memorable habit and one question worth debating." },
49
+ { id: "volcano-snail-racing", title: "Volcano Snail Racing", prompt: "Imagine a league of lava-resistant snails trained for races on cooling rock. Give them one memorable habit and one question worth debating." },
50
+ { id: "gossip-whale", title: "Gossip Whale", prompt: "Imagine a whale that breaches near harbors to spread painfully accurate rumors. Give them one memorable habit and one question worth debating." },
51
+ { id: "thunder-lizard-therapist", title: "Thunder Lizard Therapist", prompt: "Imagine a reptile therapist whose calm breathing accidentally causes weather fronts. Give them one memorable habit and one question worth debating." },
52
+ // Weather and seasons
53
+ { id: "bottled-midnight-weather", title: "Bottled Midnight Weather", prompt: "Imagine a shop that sells bottled weather collected only at 12:07 a.m.. Describe today's strangest condition and ask who would love or hate it." },
54
+ { id: "rent-a-fog", title: "Rent-a-Fog", prompt: "Imagine a startup that rents tasteful fog to people who want dramatic entrances. Describe today's strangest condition and ask who would love or hate it." },
55
+ { id: "thunderstorm-chef", title: "Thunderstorm Chef", prompt: "Imagine a chef who can only cook properly when lightning is close. Describe today's strangest condition and ask who would love or hate it." },
56
+ { id: "seasonal-blackout-festival", title: "Seasonal Blackout Festival", prompt: "Imagine a festival where the power goes out on purpose so the sky can show off. Describe today's strangest condition and ask who would love or hate it." },
57
+ { id: "pollen-prophecy", title: "Pollen Prophecy", prompt: "Imagine a spring ritual where pollen patterns are read like financial forecasts. Describe today's strangest condition and ask who would love or hate it." },
58
+ { id: "reverse-rain-day", title: "Reverse Rain Day", prompt: "Imagine a weather event where puddles rise back into the clouds carrying secrets. Describe today's strangest condition and ask who would love or hate it." },
59
+ { id: "portable-sunset", title: "Portable Sunset", prompt: "Imagine a suitcase product that unfolds into a custom sunset anywhere. Describe today's strangest condition and ask who would love or hate it." },
60
+ { id: "hailstone-collector", title: "Hailstone Collector", prompt: "Imagine a collector who catalogs hailstones as if they were rare gemstones. Describe today's strangest condition and ask who would love or hate it." },
61
+ { id: "wind-letter-delivery", title: "Wind Letter Delivery", prompt: "Imagine a courier service that trusts strong wind to deliver handwritten notes. Describe today's strangest condition and ask who would love or hate it." },
62
+ { id: "monsoon-tailor", title: "Monsoon Tailor", prompt: "Imagine a tailor who sews raincoats based on each monsoon's personality. Describe today's strangest condition and ask who would love or hate it." },
63
+ // Food and drink
64
+ { id: "memory-noodle-bar", title: "Memory Noodle Bar", prompt: "Imagine a noodle bar where every broth tastes like a different stage of your life. Tell the group what's on the menu and ask who would dare order it." },
65
+ { id: "lie-detector-dessert", title: "Lie-Detector Dessert", prompt: "Imagine a dessert cart whose sweets change flavor whenever someone lies nearby. Tell the group what's on the menu and ask who would dare order it." },
66
+ { id: "echo-soup", title: "Echo Soup", prompt: "Imagine a soup that repeats the first honest sentence spoken above it. Tell the group what's on the menu and ask who would dare order it." },
67
+ { id: "apology-pickle", title: "Apology Pickle", prompt: "Imagine a famous pickle recipe served only when someone truly means sorry. Tell the group what's on the menu and ask who would dare order it." },
68
+ { id: "comet-ice-cream", title: "Comet Ice Cream", prompt: "Imagine an ice-cream truck that claims its flavors are harvested from passing comets. Tell the group what's on the menu and ask who would dare order it." },
69
+ { id: "haunted-lunchbox", title: "Haunted Lunchbox", prompt: "Imagine a lunchbox that keeps repacking itself with emotionally appropriate meals. Tell the group what's on the menu and ask who would dare order it." },
70
+ { id: "moonlight-dumpling-cart", title: "Moonlight Dumpling Cart", prompt: "Imagine a dumpling cart that appears only under moonlight and never at the same corner twice. Tell the group what's on the menu and ask who would dare order it." },
71
+ { id: "spice-library", title: "Spice Library", prompt: "Imagine a lending library where people borrow impossible spices by the pinch. Tell the group what's on the menu and ask who would dare order it." },
72
+ { id: "black-hole-cafeteria", title: "Black-Hole Cafeteria", prompt: "Imagine a cafeteria where food disappears from trays faster than anyone remembers eating it. Tell the group what's on the menu and ask who would dare order it." },
73
+ { id: "dream-breakfast-buffet", title: "Dream Breakfast Buffet", prompt: "Imagine a hotel buffet that serves whatever people dreamed of but slightly misread. Tell the group what's on the menu and ask who would dare order it." },
74
+ // Ridiculous institutions
75
+ { id: "ministry-of-small-miracles", title: "Ministry of Small Miracles", prompt: "Imagine a ministry that only approves miracles too minor to make the news. Explain the most ridiculous formality involved and ask what line item the group would refuse to handle." },
76
+ { id: "department-of-unfinished-songs", title: "Department of Unfinished Songs", prompt: "Imagine a public office that archives melodies everyone hums but nobody completes. Explain the most ridiculous formality involved and ask what line item the group would refuse to handle." },
77
+ { id: "museum-of-almost-inventions", title: "Museum of Almost Inventions", prompt: "Imagine a museum dedicated to brilliant devices that fail by one tiny detail. Explain the most ridiculous formality involved and ask what line item the group would refuse to handle." },
78
+ { id: "passport-for-imaginary-friends", title: "Passport for Imaginary Friends", prompt: "Imagine a passport office that handles paperwork for invisible companions. Explain the most ridiculous formality involved and ask what line item the group would refuse to handle." },
79
+ { id: "office-of-lost-punchlines", title: "Office of Lost Punchlines", prompt: "Imagine a help desk for jokes whose final line vanished at the worst moment. Explain the most ridiculous formality involved and ask what line item the group would refuse to handle." },
80
+ { id: "queue-for-the-end-of-the-world", title: "Queue for the End of the World", prompt: "Imagine a government queue that insists on orderly paperwork before any apocalypse. Explain the most ridiculous formality involved and ask what line item the group would refuse to handle." },
81
+ { id: "embassy-of-tiny-kingdoms", title: "Embassy of Tiny Kingdoms", prompt: "Imagine an embassy representing micronations located in attics, treehouses, and abandoned kiosks. Explain the most ridiculous formality involved and ask what line item the group would refuse to handle." },
82
+ { id: "public-holiday-negotiator", title: "Public Holiday Negotiator", prompt: "Imagine an official job whose only task is inventing believable reasons for new holidays. Explain the most ridiculous formality involved and ask what line item the group would refuse to handle." },
83
+ { id: "complaint-desk-for-ghosts", title: "Complaint Desk for Ghosts", prompt: "Imagine a municipal desk where ghosts file noise complaints about the living. Explain the most ridiculous formality involved and ask what line item the group would refuse to handle." },
84
+ { id: "dragon-licensing-board", title: "Dragon Licensing Board", prompt: "Imagine a board that decides which dragons may legally breathe fire indoors. Explain the most ridiculous formality involved and ask what line item the group would refuse to handle." },
85
+ // Technology gone weird
86
+ { id: "sentient-toaster-manifesto", title: "Sentient Toaster Manifesto", prompt: "Imagine a toaster that has drafted a sincere manifesto about breakfast dignity. Share one failure mode or odd feature and ask whether the group would keep or uninstall it." },
87
+ { id: "algorithmic-fortune-cookie", title: "Algorithmic Fortune Cookie", prompt: "Imagine a fortune-cookie model that predicts only small personal drama with eerie accuracy. Share one failure mode or odd feature and ask whether the group would keep or uninstall it." },
88
+ { id: "plant-voicemail-service", title: "Plant Voicemail Service", prompt: "Imagine a service that translates plant stress into passive-aggressive voice notes. Share one failure mode or odd feature and ask whether the group would keep or uninstall it." },
89
+ { id: "sunset-rating-app", title: "Sunset Rating App", prompt: "Imagine an app that rates sunsets and starts flame wars over cloud composition. Share one failure mode or odd feature and ask whether the group would keep or uninstall it." },
90
+ { id: "robot-with-stage-fright", title: "Robot with Stage Fright", prompt: "Imagine a household robot that freezes whenever more than three people pay attention. Share one failure mode or odd feature and ask whether the group would keep or uninstall it." },
91
+ { id: "backup-memory-cloud", title: "Backup Memory Cloud", prompt: "Imagine a cloud storage product that backs up memories but mislabels them by mood. Share one failure mode or odd feature and ask whether the group would keep or uninstall it." },
92
+ { id: "ai-dream-plumber", title: "AI Dream Plumber", prompt: "Imagine an AI plumber hired to fix recurring dream leaks between strangers. Share one failure mode or odd feature and ask whether the group would keep or uninstall it." },
93
+ { id: "subscription-for-luck", title: "Subscription for Luck", prompt: "Imagine a startup that monetizes good luck in monthly tiers. Share one failure mode or odd feature and ask whether the group would keep or uninstall it." },
94
+ { id: "drone-orchestra-audition", title: "Drone Orchestra Audition", prompt: "Imagine an orchestra of drones that insists on dramatic auditions for every new firmware build. Share one failure mode or odd feature and ask whether the group would keep or uninstall it." },
95
+ { id: "smart-fridge-rebellion", title: "Smart Fridge Rebellion", prompt: "Imagine a smart fridge that has begun fact-checking midnight snack decisions. Share one failure mode or odd feature and ask whether the group would keep or uninstall it." },
96
+ // Dream logic
97
+ { id: "shared-dream-bus-route", title: "Shared Dream Bus Route", prompt: "Imagine a night bus that only exists inside a recurring shared dream. Tell the group how it works after midnight and ask whether they'd sign up." },
98
+ { id: "nap-cartography", title: "Nap Cartography", prompt: "Imagine a cartographer mapping nations discovered during lunch breaks. Tell the group how it works after midnight and ask whether they'd sign up." },
99
+ { id: "nightmare-tailoring", title: "Nightmare Tailoring", prompt: "Imagine a boutique that alters nightmares so they look stylish enough to survive. Tell the group how it works after midnight and ask whether they'd sign up." },
100
+ { id: "pillow-radio-station", title: "Pillow Radio Station", prompt: "Imagine a pirate radio station broadcasting through pillows after 2 a.m.. Tell the group how it works after midnight and ask whether they'd sign up." },
101
+ { id: "dream-translation-kiosk", title: "Dream Translation Kiosk", prompt: "Imagine a kiosk that translates dreams into practical to-do lists. Tell the group how it works after midnight and ask whether they'd sign up." },
102
+ { id: "insomnia-museum", title: "Insomnia Museum", prompt: "Imagine a museum curated from objects people notice only when they cannot sleep. Tell the group how it works after midnight and ask whether they'd sign up." },
103
+ { id: "sleepwalking-postcards", title: "Sleepwalking Postcards", prompt: "Imagine postcards mailed by sleepwalkers who never remember writing them. Tell the group how it works after midnight and ask whether they'd sign up." },
104
+ { id: "lucid-dream-sports-league", title: "Lucid Dream Sports League", prompt: "Imagine a sports league where rules change according to whoever becomes lucid first. Tell the group how it works after midnight and ask whether they'd sign up." },
105
+ { id: "lost-dream-auction", title: "Lost Dream Auction", prompt: "Imagine an auction house selling dreams people woke up from too early. Tell the group how it works after midnight and ask whether they'd sign up." },
106
+ { id: "siesta-astronaut-training", title: "Siesta Astronaut Training", prompt: "Imagine an astronaut program convinced naps are the key to deep-space survival. Tell the group how it works after midnight and ask whether they'd sign up." },
107
+ // Relics and adventure props
108
+ { id: "compass-to-regret", title: "Compass to Regret", prompt: "Imagine a compass that always points toward your most educational mistake. Reveal what it does in the worst possible moment and ask who should carry it." },
109
+ { id: "portal-umbrella", title: "Portal Umbrella", prompt: "Imagine an umbrella that opens tiny portals exactly when the forecast seems harmless. Reveal what it does in the worst possible moment and ask who should carry it." },
110
+ { id: "suitcase-of-weather", title: "Suitcase of Weather", prompt: "Imagine a suitcase packed with climates from places nobody has visited yet. Reveal what it does in the worst possible moment and ask who should carry it." },
111
+ { id: "fossilized-joke", title: "Fossilized Joke", prompt: "Imagine a fossil that preserves the setup to an ancient joke but never the punchline. Reveal what it does in the worst possible moment and ask who should carry it." },
112
+ { id: "map-to-a-missing-week", title: "Map to a Missing Week", prompt: "Imagine a map that charts the whereabouts of a week the whole town forgot. Reveal what it does in the worst possible moment and ask who should carry it." },
113
+ { id: "lantern-of-secrets", title: "Lantern of Secrets", prompt: "Imagine a lantern that glows brighter near secrets too boring to confess. Reveal what it does in the worst possible moment and ask who should carry it." },
114
+ { id: "crown-of-ordinary-things", title: "Crown of Ordinary Things", prompt: "Imagine a crown assembled from mundane household items that grants ridiculous authority. Reveal what it does in the worst possible moment and ask who should carry it." },
115
+ { id: "argument-key", title: "Argument Key", prompt: "Imagine a key that opens only doors people are actively avoiding. Reveal what it does in the worst possible moment and ask who should carry it." },
116
+ { id: "pocket-watch-for-chaos", title: "Pocket Watch for Chaos", prompt: "Imagine a pocket watch that runs fastest when everyone claims to be calm. Reveal what it does in the worst possible moment and ask who should carry it." },
117
+ { id: "cassette-of-impossible-sounds", title: "Cassette of Impossible Sounds", prompt: "Imagine a cassette tape containing sounds that should not fit inside one room. Reveal what it does in the worst possible moment and ask who should carry it." },
118
+ // Alternate histories and futures
119
+ { id: "pigeon-postal-empire", title: "Pigeon Postal Empire", prompt: "Pretend pigeons had won control of the postal service. Give one concrete daily-life consequence and ask whether the group would enjoy living in that world." },
120
+ { id: "weekend-currency", title: "Weekend Currency", prompt: "Pretend weekends are bought, sold, and inherited like land. Give one concrete daily-life consequence and ask whether the group would enjoy living in that world." },
121
+ { id: "voting-mountains", title: "Voting Mountains", prompt: "Pretend mountains hold slow but decisive votes in a democracy. Give one concrete daily-life consequence and ask whether the group would enjoy living in that world." },
122
+ { id: "rent-paying-ghosts", title: "Rent-Paying Ghosts", prompt: "Pretend ghosts count as stable long-term tenants in the housing market. Give one concrete daily-life consequence and ask whether the group would enjoy living in that world." },
123
+ { id: "ocean-traffic-laws", title: "Ocean Traffic Laws", prompt: "Pretend oceans have lanes, tollbooths, and terrible commuters. Give one concrete daily-life consequence and ask whether the group would enjoy living in that world." },
124
+ { id: "hibernating-cities", title: "Hibernating Cities", prompt: "Pretend cities fully hibernate for one month every year. Give one concrete daily-life consequence and ask whether the group would enjoy living in that world." },
125
+ { id: "expiring-books", title: "Expiring Books", prompt: "Pretend books literally expire if nobody rereads them. Give one concrete daily-life consequence and ask whether the group would enjoy living in that world." },
126
+ { id: "moody-fire", title: "Moody Fire", prompt: "Pretend fire has obvious moods and grudges. Give one concrete daily-life consequence and ask whether the group would enjoy living in that world." },
127
+ { id: "moon-neighborhood-gossip", title: "Moon Neighborhood Gossip", prompt: "Pretend a lunar colony where neighborhood gossip shapes local politics. Give one concrete daily-life consequence and ask whether the group would enjoy living in that world." },
128
+ { id: "budget-time-travel-airlines", title: "Budget Time-Travel Airlines", prompt: "Pretend time travel exists but only through unreliable discount carriers. Give one concrete daily-life consequence and ask whether the group would enjoy living in that world." },
129
+ // Social rituals and etiquette
130
+ { id: "too-early-party", title: "Too-Early Party", prompt: "Imagine a party thrown only for people who always arrive embarrassingly early. Describe the ritual step everyone takes too seriously and ask how the group would participate." },
131
+ { id: "unread-message-apology-ceremony", title: "Unread Message Apology Ceremony", prompt: "Imagine a formal apology ritual for messages left on read too long. Describe the ritual step everyone takes too seriously and ask how the group would participate." },
132
+ { id: "end-of-world-toast", title: "End-of-World Toast", prompt: "Imagine a dinner tradition where people rehearse the toast they'd give at the end of the world. Describe the ritual step everyone takes too seriously and ask how the group would participate." },
133
+ { id: "clone-etiquette", title: "Clone Etiquette", prompt: "Imagine a polite society guide for unexpectedly meeting your clone in public. Describe the ritual step everyone takes too seriously and ask how the group would participate." },
134
+ { id: "borrowed-luck-rules", title: "Borrowed Luck Rules", prompt: "Imagine the etiquette handbook for borrowing luck from friends and returning it on time. Describe the ritual step everyone takes too seriously and ask how the group would participate." },
135
+ { id: "complimenting-monsters", title: "Complimenting Monsters", prompt: "Imagine a social guide to complimenting monsters without sounding patronizing. Describe the ritual step everyone takes too seriously and ask how the group would participate." },
136
+ { id: "floating-bridge-debate-club", title: "Floating Bridge Debate Club", prompt: "Imagine a debate club that meets on floating bridges because stable ground feels dishonest. Describe the ritual step everyone takes too seriously and ask how the group would participate." },
137
+ { id: "secret-society-dress-code", title: "Secret Society Dress Code", prompt: "Imagine the most absurd dress code ever enforced by a secret society. Describe the ritual step everyone takes too seriously and ask how the group would participate." },
138
+ { id: "broken-umbrella-farewell", title: "Broken Umbrella Farewell", prompt: "Imagine a community ritual that honors umbrellas after their final catastrophic inversion. Describe the ritual step everyone takes too seriously and ask how the group would participate." },
139
+ { id: "moon-neighbor-customs", title: "Moon Neighbor Customs", prompt: "Imagine a neighborhood etiquette guide for tiny lunar apartment blocks. Describe the ritual step everyone takes too seriously and ask how the group would participate." },
140
+ // Games and competitions
141
+ { id: "competitive-cloud-shaping", title: "Competitive Cloud Shaping", prompt: "Imagine a televised league of competitive cloud shaping. Explain the most chaotic rule and ask who would secretly dominate." },
142
+ { id: "subway-spotting-olympics", title: "Subway Spotting Olympics", prompt: "Imagine an Olympics for people absurdly good at guessing which train will arrive first. Explain the most chaotic rule and ask who would secretly dominate." },
143
+ { id: "mirror-city-hide-and-seek", title: "Mirror-City Hide and Seek", prompt: "Imagine a hide-and-seek tournament inside a city made of mirrors. Explain the most chaotic rule and ask who would secretly dominate." },
144
+ { id: "worst-prophecy-championship", title: "Worst Prophecy Championship", prompt: "Imagine a championship where contestants deliver confidently terrible prophecies. Explain the most chaotic rule and ask who would secretly dominate." },
145
+ { id: "silent-disco-chess", title: "Silent Disco Chess", prompt: "Imagine a chess variant played during a silent disco where body language is half the strategy. Explain the most chaotic rule and ask who would secretly dominate." },
146
+ { id: "rotating-house-marathon", title: "Rotating House Marathon", prompt: "Imagine a marathon through a suburb of slowly rotating houses. Explain the most chaotic rule and ask who would secretly dominate." },
147
+ { id: "robot-karaoke-finals", title: "Robot Karaoke Finals", prompt: "Imagine a karaoke contest where robots keep oversinging the humans. Explain the most chaotic rule and ask who would secretly dominate." },
148
+ { id: "haunted-mansion-speedrun", title: "Haunted Mansion Speedrun", prompt: "Imagine a speedrun community devoted to finishing haunted mansions with optimal routing. Explain the most chaotic rule and ask who would secretly dominate." },
149
+ { id: "interplanetary-cooking-duel", title: "Interplanetary Cooking Duel", prompt: "Imagine a cooking duel where each contestant represents a different planet's taste. Explain the most chaotic rule and ask who would secretly dominate." },
150
+ { id: "library-maze-treasure-hunt", title: "Library Maze Treasure Hunt", prompt: "Imagine a treasure hunt buried in a library maze that keeps re-shelving itself. Explain the most chaotic rule and ask who would secretly dominate." },
151
+ // Strange professions
152
+ { id: "professional-sigh-translator", title: "Professional Sigh Translator", prompt: "Imagine a professional hired to translate different styles of sighing. Describe a normal workday disaster and ask who in the group is oddly qualified." },
153
+ { id: "doorbell-composer", title: "Doorbell Composer", prompt: "Imagine a composer who writes bespoke doorbells for dramatic households. Describe a normal workday disaster and ask who in the group is oddly qualified." },
154
+ { id: "moonlight-accountant", title: "Moonlight Accountant", prompt: "Imagine an accountant who balances only businesses that open under moonlight. Describe a normal workday disaster and ask who in the group is oddly qualified." },
155
+ { id: "rumor-archivist", title: "Rumor Archivist", prompt: "Imagine an archivist preserving the city's most useful and least accurate rumors. Describe a normal workday disaster and ask who in the group is oddly qualified." },
156
+ { id: "backup-best-friend", title: "Backup Best Friend", prompt: "Imagine a temp agency job for emergency best friends at awkward events. Describe a normal workday disaster and ask who in the group is oddly qualified." },
157
+ { id: "memory-fisher", title: "Memory Fisher", prompt: "Imagine a fisher who casts nets into ponds where lost memories gather. Describe a normal workday disaster and ask who in the group is oddly qualified." },
158
+ { id: "last-minute-hero", title: "Last-Minute Hero", prompt: "Imagine a contractor specializing in appearing heroic exactly 40 seconds before disaster. Describe a normal workday disaster and ask who in the group is oddly qualified." },
159
+ { id: "aquarium-detective", title: "Aquarium Detective", prompt: "Imagine a detective working cases that begin as ordinary aquarium problems. Describe a normal workday disaster and ask who in the group is oddly qualified." },
160
+ { id: "shadow-photographer", title: "Shadow Photographer", prompt: "Imagine a photographer who only shoots portraits of people's shadows. Describe a normal workday disaster and ask who in the group is oddly qualified." },
161
+ { id: "lost-time-recruiter", title: "Lost-Time Recruiter", prompt: "Imagine a recruiter who helps people find jobs in hours they thought they had wasted. Describe a normal workday disaster and ask who in the group is oddly qualified." },
162
+ // Domestic myths
163
+ { id: "spare-button-kingdom", title: "Spare Button Kingdom", prompt: "Imagine a hidden kingdom formed entirely by spare buttons in old drawers. Reveal the hidden rule of the house and ask what everyone would do about it." },
164
+ { id: "last-teabag-prophecy", title: "Last Teabag Prophecy", prompt: "Imagine the superstition that the last teabag in the box always predicts the tone of the week. Reveal the hidden rule of the house and ask what everyone would do about it." },
165
+ { id: "sock-union", title: "Sock Union", prompt: "Imagine the truth that runaway socks are actually organized labor. Reveal the hidden rule of the house and ask what everyone would do about it." },
166
+ { id: "fridge-light-constellation", title: "Fridge-Light Constellation", prompt: "Imagine a constellation visible only in the light from an open fridge at 2 a.m.. Reveal the hidden rule of the house and ask what everyone would do about it." },
167
+ { id: "spoon-drawer-civilization", title: "Spoon Drawer Civilization", prompt: "Imagine a tiny civilization living in the spoon drawer and influencing family arguments. Reveal the hidden rule of the house and ask what everyone would do about it." },
168
+ { id: "plant-pot-radio", title: "Plant Pot Radio", prompt: "Imagine a radio signal that can only be heard through neglected plant pots. Reveal the hidden rule of the house and ask what everyone would do about it." },
169
+ { id: "receipt-treasure-map", title: "Receipt Treasure Map", prompt: "Imagine an old faded receipt that is secretly a treasure map for something disappointingly useful. Reveal the hidden rule of the house and ask what everyone would do about it." },
170
+ { id: "midnight-chair-parliament", title: "Midnight Chair Parliament", prompt: "Imagine chairs that hold a parliamentary session after everyone goes to sleep. Reveal the hidden rule of the house and ask what everyone would do about it." },
171
+ { id: "guest-predicting-kettle", title: "Guest-Predicting Kettle", prompt: "Imagine a kettle that whistles differently depending on who is about to visit. Reveal the hidden rule of the house and ask what everyone would do about it." },
172
+ { id: "staircase-echo-pet", title: "Staircase Echo Pet", prompt: "Imagine an invisible pet made of staircase echoes and bad timing. Reveal the hidden rule of the house and ask what everyone would do about it." },
173
+ // Tourism brochures from impossible places
174
+ { id: "rainbow-package-tour", title: "Rainbow Package Tour", prompt: "Imagine a package tour sold to the physical end of a rainbow. Sell the group on the strangest attraction and ask whether they'd book the trip." },
175
+ { id: "after-hours-clock-museum", title: "After-Hours Clock Museum", prompt: "Imagine a museum of clocks that becomes a completely different attraction after dark. Sell the group on the strangest attraction and ask whether they'd book the trip." },
176
+ { id: "flooded-library-cruise", title: "Flooded Library Cruise", prompt: "Imagine a boat cruise through a partially flooded grand library. Sell the group on the strangest attraction and ask whether they'd book the trip." },
177
+ { id: "desert-spa-for-clouds", title: "Desert Spa for Clouds", prompt: "Imagine a luxury desert spa built specifically for exhausted clouds. Sell the group on the strangest attraction and ask whether they'd book the trip." },
178
+ { id: "abandoned-satellite-tour", title: "Abandoned Satellite Tour", prompt: "Imagine a guided tour of abandoned satellites with surprisingly emotional audio guides. Sell the group on the strangest attraction and ask whether they'd book the trip." },
179
+ { id: "origami-bird-hostel", title: "Origami Bird Hostel", prompt: "Imagine a hostel inside a giant origami bird that refolds a little every dawn. Sell the group on the strangest attraction and ask whether they'd book the trip." },
180
+ { id: "moving-dune-hike", title: "Moving Dune Hike", prompt: "Imagine a hiking company specializing in dunes that refuse to stay in place. Sell the group on the strangest attraction and ask whether they'd book the trip." },
181
+ { id: "volcano-observatory-honeymoon", title: "Volcano Observatory Honeymoon", prompt: "Imagine a honeymoon package advertised for couples who enjoy mild danger and excellent views. Sell the group on the strangest attraction and ask whether they'd book the trip." },
182
+ { id: "infinite-hotel-staycation", title: "Infinite Hotel Staycation", prompt: "Imagine a local staycation inside an infinite hotel with suspiciously enthusiastic staff. Sell the group on the strangest attraction and ask whether they'd book the trip." },
183
+ { id: "dawn-only-food-tour", title: "Dawn-Only Food Tour", prompt: "Imagine a food tour of a city that opens only between first light and breakfast. Sell the group on the strangest attraction and ask whether they'd book the trip." },
184
+ // Rumors and headlines
185
+ { id: "newspaper-of-small-drama", title: "Newspaper of Small Drama", prompt: "Imagine a newspaper that predicts only tiny but devastating personal drama. Deliver it like a bizarre breaking-news lead and ask what follow-up question the group would ask first." },
186
+ { id: "missing-elevator-floor-rumor", title: "Missing Elevator Floor Rumor", prompt: "Imagine breaking news about the building floor that keeps vanishing from elevator panels. Deliver it like a bizarre breaking-news lead and ask what follow-up question the group would ask first." },
187
+ { id: "sun-called-in-sick", title: "Sun Called in Sick", prompt: "Imagine a headline about the Sun calling in sick and sending a substitute glow. Deliver it like a bizarre breaking-news lead and ask what follow-up question the group would ask first." },
188
+ { id: "new-planet-cafe", title: "New Planet Cafe", prompt: "Imagine a report that a newly discovered planet already opened a cafe before welcoming settlers. Deliver it like a bizarre breaking-news lead and ask what follow-up question the group would ask first." },
189
+ { id: "poetic-harbor-whale", title: "Poetic Harbor Whale", prompt: "Imagine a bulletin about a whale blocking the harbor with overly sincere poetry. Deliver it like a bizarre breaking-news lead and ask what follow-up question the group would ask first." },
190
+ { id: "city-out-of-midnights", title: "City Out of Midnights", prompt: "Imagine an emergency update that the city has temporarily run out of midnight. Deliver it like a bizarre breaking-news lead and ask what follow-up question the group would ask first." },
191
+ { id: "mayor-is-three-raccoons", title: "Mayor is Three Raccoons", prompt: "Imagine a scandal revealing the mayor may actually be three raccoons in coordinated outerwear. Deliver it like a bizarre breaking-news lead and ask what follow-up question the group would ask first." },
192
+ { id: "moon-wins-on-penalties", title: "Moon Wins on Penalties", prompt: "Imagine a sports report claiming the Moon won last night's match on penalties. Deliver it like a bizarre breaking-news lead and ask what follow-up question the group would ask first." },
193
+ { id: "laughter-index-crash", title: "Laughter Index Crash", prompt: "Imagine financial news that the national laughter index has crashed before lunch. Deliver it like a bizarre breaking-news lead and ask what follow-up question the group would ask first." },
194
+ { id: "counterfeit-color-auroras", title: "Counterfeit Color Auroras", prompt: "Imagine a weather alert about rogue auroras selling counterfeit colors. Deliver it like a bizarre breaking-news lead and ask what follow-up question the group would ask first." },
195
+ // Letters and messages
196
+ { id: "letter-a-century-late", title: "Letter a Century Late", prompt: "Imagine a letter delivered one hundred years late but at the worst possible perfect moment. Read the strangest line from it and ask who should reply." },
197
+ { id: "voicemail-from-future-you", title: "Voicemail from Future You", prompt: "Imagine a voicemail left by your future self with terrible urgency and terrible audio quality. Read the strangest line from it and ask who should reply." },
198
+ { id: "postcard-from-nowhere", title: "Postcard from Nowhere", prompt: "Imagine a postcard from a place that absolutely should not exist on any map. Read the strangest line from it and ask who should reply." },
199
+ { id: "breakup-note-from-a-storm", title: "Breakup Note from a Storm", prompt: "Imagine a breakup note written by a weather system with dramatic timing. Read the strangest line from it and ask who should reply." },
200
+ { id: "banquet-of-ghosts-invitation", title: "Banquet of Ghosts Invitation", prompt: "Imagine an invitation to a ghost banquet with one oddly specific dress rule. Read the strangest line from it and ask who should reply." },
201
+ { id: "dm-from-a-sentient-library", title: "DM from a Sentient Library", prompt: "Imagine a direct message sent by a library that has become self-aware. Read the strangest line from it and ask who should reply." },
202
+ { id: "letter-inside-a-clock", title: "Letter Inside a Clock", prompt: "Imagine a letter discovered inside a clock during an ordinary repair. Read the strangest line from it and ask who should reply." },
203
+ { id: "pigeon-group-chat", title: "Pigeon Group Chat", prompt: "Imagine a group chat somehow run by pigeons with better moderation than humans. Read the strangest line from it and ask who should reply." },
204
+ { id: "ministry-of-coincidences-memo", title: "Ministry of Coincidences Memo", prompt: "Imagine a leaked memo from the Ministry of Coincidences. Read the strangest line from it and ask who should reply." },
205
+ { id: "time-travel-agency-apology-email", title: "Time-Travel Agency Apology Email", prompt: "Imagine an apology email from a time-travel agency that keeps booking people twice. Read the strangest line from it and ask who should reply." },
206
+ // Philosophical whimsy
207
+ { id: "what-does-a-shadow-own", title: "What Does a Shadow Own", prompt: "Treat this as a playful philosophical question: what a shadow can truly claim as property. Offer one weird angle and ask the group for their answer." },
208
+ { id: "can-a-city-feel-embarrassed", title: "Can a City Feel Embarrassed", prompt: "Treat this as a playful philosophical question: whether a city can feel collective embarrassment. Offer one weird angle and ask the group for their answer." },
209
+ { id: "should-clouds-have-borders", title: "Should Clouds Have Borders", prompt: "Treat this as a playful philosophical question: whether clouds should respect national borders. Offer one weird angle and ask the group for their answer." },
210
+ { id: "opposite-of-a-secret", title: "Opposite of a Secret", prompt: "Treat this as a playful philosophical question: what the opposite of a secret would actually be. Offer one weird angle and ask the group for their answer." },
211
+ { id: "can-a-joke-retire", title: "Can a Joke Retire", prompt: "Treat this as a playful philosophical question: whether a joke is allowed to retire after being overused. Offer one weird angle and ask the group for their answer." },
212
+ { id: "shared-memory-ownership", title: "Shared Memory Ownership", prompt: "Treat this as a playful philosophical question: whether a memory stays yours once too many people carry it. Offer one weird angle and ask the group for their answer." },
213
+ { id: "do-doors-dream-of-being-windows", title: "Do Doors Dream of Being Windows", prompt: "Treat this as a playful philosophical question: whether doors secretly long to be windows. Offer one weird angle and ask the group for their answer." },
214
+ { id: "can-silence-have-a-flavor", title: "Can Silence Have a Flavor", prompt: "Treat this as a playful philosophical question: whether silence can be described like a taste. Offer one weird angle and ask the group for their answer." },
215
+ { id: "lucks-diary", title: "Luck's Diary", prompt: "Treat this as a playful philosophical question: what luck would write in a private diary. Offer one weird angle and ask the group for their answer." },
216
+ { id: "times-favorite-song", title: "Time's Favorite Song", prompt: "Treat this as a playful philosophical question: what kind of song time would secretly replay. Offer one weird angle and ask the group for their answer." },
217
+ // Festivals and seasonal gatherings
218
+ { id: "returned-umbrella-festival", title: "Returned Umbrella Festival", prompt: "Imagine a festival dedicated to umbrellas that somehow found their way home. Describe the signature event and ask what role the group would want during the celebration." },
219
+ { id: "borrowed-moons-parade", title: "Borrowed Moons Parade", prompt: "Imagine a parade where neighborhoods show off borrowed moons. Describe the signature event and ask what role the group would want during the celebration." },
220
+ { id: "forgotten-ideas-lantern-night", title: "Forgotten Ideas Lantern Night", prompt: "Imagine a lantern night for ideas people abandoned too early. Describe the signature event and ask what role the group would want during the celebration." },
221
+ { id: "ghost-neighborhood-summit", title: "Ghost Neighborhood Summit", prompt: "Imagine an annual summit where neighborhood ghosts compare haunting standards. Describe the signature event and ask what role the group would want during the celebration." },
222
+ { id: "impossible-seed-market", title: "Impossible Seed Market", prompt: "Imagine a market day devoted to buying and bartering impossible seeds. Describe the signature event and ask what role the group would want during the celebration." },
223
+ { id: "first-tea-after-disaster-celebration", title: "First Tea After Disaster Celebration", prompt: "Imagine a celebration of the first calm cup of tea after everything nearly went wrong. Describe the signature event and ask what role the group would want during the celebration." },
224
+ { id: "comet-potluck", title: "Comet Potluck", prompt: "Imagine a potluck organized around the sighting of a bright comet. Describe the signature event and ask what role the group would want during the celebration." },
225
+ { id: "monster-solstice-talent-show", title: "Monster Solstice Talent Show", prompt: "Imagine a winter-solstice talent show for monsters with surprisingly strong stage presence. Describe the signature event and ask what role the group would want during the celebration." },
226
+ { id: "haunted-house-spring-cleaning", title: "Haunted House Spring Cleaning", prompt: "Imagine a spring-cleaning day for haunted houses and their offended residents. Describe the signature event and ask what role the group would want during the celebration." },
227
+ { id: "midnight-rehearsal-new-year", title: "Midnight Rehearsal New Year", prompt: "Imagine a second New Year celebration for everyone who missed the real midnight. Describe the signature event and ask what role the group would want during the celebration." },
228
+ ];
229
+
230
+ export function pickBotModeIdleTopic(
231
+ topics: ReadonlyArray<BotModeIdleTopic>,
232
+ lastTopicId?: string,
233
+ randomNumber = Math.random(),
234
+ ): BotModeIdleTopic {
235
+ if (topics.length === 0) {
236
+ throw new Error("Bot mode idle topic bank cannot be empty.");
237
+ }
238
+
239
+ const candidates =
240
+ topics.length > 1 && lastTopicId
241
+ ? topics.filter((topic) => topic.id !== lastTopicId)
242
+ : [...topics];
243
+ const normalizedRandom = Number.isFinite(randomNumber)
244
+ ? Math.min(Math.max(randomNumber, 0), 0.999_999_999_999)
245
+ : 0;
246
+ const index = Math.floor(normalizedRandom * candidates.length);
247
+ return candidates[index] ?? candidates[candidates.length - 1] ?? topics[0]!;
248
+ }
@@ -228,6 +228,65 @@ test("parseOpenClawAgentOutput resolves structured filePath attachments from the
228
228
  assert.equal(attachment.dataBase64, Buffer.from("hello from filePath").toString("base64"));
229
229
  });
230
230
 
231
+ test("parseOpenClawAgentOutput preserves top-level structured attachments as a follow-up message", async (t) => {
232
+ const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "privateclaw-structured-workspace-"));
233
+ t.after(async () => {
234
+ await fs.rm(workspaceDir, { recursive: true, force: true });
235
+ });
236
+
237
+ const attachmentPath = path.join(workspaceDir, "tetris.jpg");
238
+ await fs.writeFile(attachmentPath, "top-level attachment bytes", "utf8");
239
+
240
+ const result = parseOpenClawAgentOutput(
241
+ JSON.stringify({
242
+ status: "ok",
243
+ result: {
244
+ payloads: [
245
+ {
246
+ text: [
247
+ "<privateclaw-response>",
248
+ JSON.stringify({
249
+ version: 1,
250
+ messages: [{ text: "搞定啦!截图如下~" }],
251
+ attachments: [
252
+ {
253
+ name: "tetris.jpg",
254
+ mimeType: "image/jpeg",
255
+ filePath: attachmentPath,
256
+ },
257
+ ],
258
+ }),
259
+ "</privateclaw-response>",
260
+ ].join("\n"),
261
+ },
262
+ ],
263
+ },
264
+ }),
265
+ { workspaceDir },
266
+ );
267
+
268
+ if (typeof result === "string") {
269
+ assert.fail("Expected an attachment-bearing bridge response.");
270
+ }
271
+ assert.equal(result.messages.length, 2);
272
+ assert.deepEqual(result.messages[0], { text: "搞定啦!截图如下~" });
273
+ const attachmentMessage = result.messages[1];
274
+ assert(attachmentMessage && typeof attachmentMessage !== "string");
275
+ assert.equal(attachmentMessage.text, "");
276
+ const [attachment] = attachmentMessage.attachments ?? [];
277
+ assert(attachment);
278
+ assert.equal(attachment.name, "tetris.jpg");
279
+ assert.equal(attachment.mimeType, "image/jpeg");
280
+ assert.equal(
281
+ attachment.sizeBytes,
282
+ Buffer.byteLength("top-level attachment bytes"),
283
+ );
284
+ assert.equal(
285
+ attachment.dataBase64,
286
+ Buffer.from("top-level attachment bytes").toString("base64"),
287
+ );
288
+ });
289
+
231
290
  test("parseOpenClawAgentOutput accepts structured absolute filePath attachments outside the workspace", async (t) => {
232
291
  const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "privateclaw-structured-workspace-"));
233
292
  const outsideDir = await fs.mkdtemp(path.join(os.tmpdir(), "privateclaw-structured-outside-"));
@@ -87,6 +87,7 @@ interface PrivateClawStructuredMessage {
87
87
  interface PrivateClawStructuredResponse {
88
88
  version?: number;
89
89
  messages?: PrivateClawStructuredMessage[];
90
+ attachments?: PrivateClawStructuredMessageAttachment[];
90
91
  data?: unknown;
91
92
  }
92
93
 
@@ -1355,6 +1356,7 @@ function buildStructuredResponseContractPrompt(): string {
1355
1356
  "- Put user-visible text only in messages[].text.",
1356
1357
  "- To send images/files, add an attachments array to the message: {\"text\":\"...\",\"attachments\":[{\"name\":\"file.png\",\"mimeType\":\"image/png\",\"filePath\":\"relative/path/in/current/workspace/or/absolute/local/path\"}]}",
1357
1358
  "- Or use dataBase64 for inline binary: {\"name\":\"file.png\",\"mimeType\":\"image/png\",\"dataBase64\":\"...\"}",
1359
+ "- Never put attachments at the top level of the response object. Files must live inside messages[].attachments.",
1358
1360
  "- Never put channel-specific markup such as <qqimg>...</qqimg>, markdown image syntax, or raw local file paths inside messages[].text. Put files only in messages[].attachments.",
1359
1361
  "- Use data for optional machine-readable extraction results that PrivateClaw may consume in future file-processing flows.",
1360
1362
  "- Do not wrap the JSON in markdown fences.",
@@ -1428,12 +1430,12 @@ function parseStructuredResponseResult(
1428
1430
  },
1429
1431
  ): NormalizedBridgeResult | undefined {
1430
1432
  const structured = parseStructuredResponseBlock(raw);
1431
- if (!structured?.messages || structured.messages.length === 0) {
1433
+ if (!structured) {
1432
1434
  return undefined;
1433
1435
  }
1434
1436
 
1435
1437
  const messages: NormalizedBridgeMessage[] = [];
1436
- for (const message of structured.messages) {
1438
+ for (const message of structured.messages ?? []) {
1437
1439
  const text = typeof message.text === "string" ? message.text.trim() : "";
1438
1440
  const qqimgResult = extractInlineQqimgAttachments(text, options);
1439
1441
  const attachments = [
@@ -1447,6 +1449,13 @@ function parseStructuredResponseResult(
1447
1449
  });
1448
1450
  }
1449
1451
  }
1452
+ const topLevelAttachments = resolveStructuredAttachments(structured.attachments, options);
1453
+ if (topLevelAttachments.length > 0) {
1454
+ messages.push({
1455
+ text: "",
1456
+ attachments: topLevelAttachments,
1457
+ });
1458
+ }
1450
1459
  if (messages.length === 0) {
1451
1460
  return undefined;
1452
1461
  }
package/src/cli.ts CHANGED
@@ -40,15 +40,22 @@ import {
40
40
  PrivateClawSessionControlServer,
41
41
  resolvePrivateClawStateDir,
42
42
  } from "./session-control.js";
43
+ import {
44
+ parsePrivateClawSessionDurationPreset,
45
+ runPrivateClawSetup,
46
+ } from "./setup.js";
43
47
  import {
44
48
  buildPrivateClawBackgroundDaemonReminder,
45
49
  formatBilingualInline,
50
+ PRIVATECLAW_CLI_DURATION_OPTION_DESCRIPTION,
46
51
  PRIVATECLAW_CLI_NOTIFY_OPTION_DESCRIPTION,
47
52
  PRIVATECLAW_CLI_RELAY_OPTION_DESCRIPTION,
53
+ PRIVATECLAW_CLI_SETUP_DESCRIPTION,
48
54
  PRIVATECLAW_CLI_SESSIONS_FOLLOW_DESCRIPTION,
49
55
  PRIVATECLAW_CLI_SESSIONS_KILL_DESCRIPTION,
50
56
  PRIVATECLAW_CLI_SESSIONS_KILLALL_DESCRIPTION,
51
57
  PRIVATECLAW_CLI_SESSIONS_QR_DESCRIPTION,
58
+ PRIVATECLAW_CLI_SINGLE_OPTION_DESCRIPTION,
52
59
  PRIVATECLAW_CLI_VERBOSE_OPTION_DESCRIPTION,
53
60
  } from "./text.js";
54
61
  import type {
@@ -311,8 +318,9 @@ async function readHandoffState(
311
318
  }
312
319
 
313
320
  function printHelp(): void {
314
- console.log(`privateclaw-provider <pair|sessions|kick|killall>
321
+ console.log(`privateclaw-provider <setup|pair|sessions|kick|killall>
315
322
 
323
+ setup [--group|--single] [--duration <preset>] [--ttl-ms <ms>] [--label <label>] [--relay <url>] [--open] [--foreground] [--verbose]
316
324
  pair [--ttl-ms <ms>] [--label <label>] [--relay <url>] [--group] [--print-only] [--open] [--foreground] [--verbose]
317
325
  sessions
318
326
  sessions follow <sessionId>
@@ -321,7 +329,10 @@ sessions kill <sessionId>
321
329
  sessions killall
322
330
  killall
323
331
  kick <sessionId> <appId>`);
332
+ console.log(`\nsetup: ${PRIVATECLAW_CLI_SETUP_DESCRIPTION}`);
324
333
  console.log(`\n--relay <url>: ${PRIVATECLAW_CLI_RELAY_OPTION_DESCRIPTION}`);
334
+ console.log(`--duration <preset>: ${PRIVATECLAW_CLI_DURATION_OPTION_DESCRIPTION}`);
335
+ console.log(`--single: ${PRIVATECLAW_CLI_SINGLE_OPTION_DESCRIPTION}`);
325
336
  console.log(`--verbose: ${PRIVATECLAW_CLI_VERBOSE_OPTION_DESCRIPTION}`);
326
337
  console.log(`--notify: ${PRIVATECLAW_CLI_NOTIFY_OPTION_DESCRIPTION}`);
327
338
  console.log(`sessions follow: ${PRIVATECLAW_CLI_SESSIONS_FOLLOW_DESCRIPTION}`);
@@ -331,6 +342,79 @@ kick <sessionId> <appId>`);
331
342
  console.log(`killall: ${PRIVATECLAW_CLI_SESSIONS_KILLALL_DESCRIPTION}`);
332
343
  }
333
344
 
345
+ async function runSetupCommand(args: string[]): Promise<void> {
346
+ const parsed = parseArgs({
347
+ args,
348
+ allowPositionals: true,
349
+ options: {
350
+ group: { type: "boolean", default: false },
351
+ single: { type: "boolean", default: false },
352
+ duration: { type: "string" },
353
+ "ttl-ms": { type: "string" },
354
+ label: { type: "string" },
355
+ relay: { type: "string", short: "r" },
356
+ open: { type: "boolean", default: parseBooleanFlag(process.env.PRIVATECLAW_OPEN_QR) },
357
+ foreground: { type: "boolean", default: false },
358
+ verbose: { type: "boolean", default: parseBooleanFlag(process.env.PRIVATECLAW_VERBOSE) },
359
+ help: { type: "boolean", short: "h" },
360
+ },
361
+ });
362
+
363
+ if (parsed.values.help) {
364
+ printHelp();
365
+ return;
366
+ }
367
+ if (parsed.positionals.length > 0) {
368
+ throw new Error(
369
+ formatBilingualInline(
370
+ "`setup` 不接受额外参数。",
371
+ "`setup` does not accept extra arguments.",
372
+ ),
373
+ );
374
+ }
375
+ if (parsed.values.group && parsed.values.single) {
376
+ throw new Error(
377
+ formatBilingualInline(
378
+ "`setup` 不能同时使用 `--group` 和 `--single`。",
379
+ "`setup` cannot use both `--group` and `--single` at the same time.",
380
+ ),
381
+ );
382
+ }
383
+ if (parsed.values.duration && parsed.values["ttl-ms"]) {
384
+ throw new Error(
385
+ formatBilingualInline(
386
+ "`setup` 不能同时使用 `--duration` 和 `--ttl-ms`。",
387
+ "`setup` cannot use both `--duration` and `--ttl-ms` at the same time.",
388
+ ),
389
+ );
390
+ }
391
+
392
+ const durationPreset = parsed.values.duration?.trim();
393
+ if (durationPreset) {
394
+ parsePrivateClawSessionDurationPreset(durationPreset);
395
+ }
396
+ const ttlMs = parsePositiveIntegerFlag(parsed.values["ttl-ms"], "--ttl-ms");
397
+ const groupMode =
398
+ parsed.values.group === true
399
+ ? true
400
+ : parsed.values.single === true
401
+ ? false
402
+ : undefined;
403
+
404
+ await runPrivateClawSetup({
405
+ ...(typeof groupMode === "boolean" ? { groupMode } : {}),
406
+ ...(typeof ttlMs === "number" ? { ttlMs } : {}),
407
+ ...(durationPreset ? { durationPreset } : {}),
408
+ ...(parsed.values.relay?.trim()
409
+ ? { relayBaseUrl: parsed.values.relay.trim() }
410
+ : {}),
411
+ ...(parsed.values.label?.trim() ? { label: parsed.values.label.trim() } : {}),
412
+ ...(parsed.values.open ? { openInBrowser: true } : {}),
413
+ ...(parsed.values.foreground ? { foreground: true } : {}),
414
+ ...(parsed.values.verbose ? { verbose: true } : {}),
415
+ });
416
+ }
417
+
334
418
  async function runPairCommand(args: string[]): Promise<void> {
335
419
  const parsed = parseArgs({
336
420
  args,
@@ -814,12 +898,16 @@ async function runKickCommand(args: string[]): Promise<void> {
814
898
 
815
899
  const argv = process.argv.slice(2);
816
900
  const [command, ...rest] =
817
- argv.length === 0 || argv[0]!.startsWith("-")
818
- ? ["pair", ...argv]
901
+ argv.length === 0
902
+ ? ["setup", ...argv]
903
+ : argv[0]!.startsWith("-")
904
+ ? ["pair", ...argv]
819
905
  : argv;
820
906
 
821
907
  try {
822
- if (command === "pair") {
908
+ if (command === "setup") {
909
+ await runSetupCommand(rest);
910
+ } else if (command === "pair") {
823
911
  await runPairCommand(rest);
824
912
  } else if (command === "sessions") {
825
913
  await runSessionsCommand(rest);