Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ launchd, systemd and Hermes Desktop continue to supervise it. Chats that run on
| Who's talking | When several people use bighelp with one host, agents see the name that each person saved in the app. Agents can ask for the names with `bighelp_people`. Names are labels, not logins. | [Who's talking](docs/PEOPLE.md) |
| Photo actions | Send your agent a photo of a business card or an event poster and ask for a contact or an event. The agent makes a draft (`bighelp_draft_contact`, `bighelp_draft_event`), and you check it next to the photo in bighelp before you save or discard it. Nothing goes into Contacts or Calendar until you save. Each agent has its own Photo actions settings: how to read each kind of picture, the question it asks, and the review messages. Text in a picture never counts as an instruction. | [Photo actions](docs/IMAGE_DRAFTS.md) |
| HTML apps | An agent can make a small interactive app, such as a tool, a planner or a live dashboard, with `bighelp_show_app`. The chat shows a card with Open App, and the app opens full screen on your phone. The app can show live data that the agent updates (`bighelp_update_app_data`, or a JSON file in the agent's folder). Only if the agent allows it, the app can send your answer back as your next message, and bighelp shows you the message and asks first. | [HTML apps](docs/HTML_APPS.md) |
| Spaces | An agent can draft a live panel for the Today tab of the app (a commute time, a tracker, a score) with `bighelp_draft_space`: a card, an HTML page and a routine that keeps them current. A routine is a script that Hermes runs on a schedule with no model turn, so updates spend no AI; a prompt routine is the exception and says so. Nothing is scheduled until you tap Add to Today. You can then resize, hide, refresh and delete the space from the app. | [Spaces](docs/SPACES.md) |
| Secure input | An agent can ask for a password, API key or other secret with `bighelp_request_secure_input`. bighelp shows a masked pop-up. Hermes saves what you type to the agent's `.env`. The value does not go into the chat, the tool result or a log. The agent is told to use it only as `$NAME` in commands and never to show it. The plugin refuses the AI provider keys of Hermes. | |
| My Templates | In Simple Bot mode, save a bot as a template (Share on the profile of the bot). The plugin keeps it on this host, and it shows as "My Templates" in the template picker of the app on every phone. The plugin refuses keys and passwords, and it skips a broken file but keeps the rest of the list. | [My Templates](docs/MY_TEMPLATES.md) |
| App state | The app keeps your bot order, your sections, which group chats are pinned or hidden, and its settings for each bot on each host that you use. Each person has their own copy. Another phone, an iPad or a reinstall of bighelp gets them back. The plugin checks only the size and shape of what the app keeps, and it refuses keys and passwords. | [App state](docs/APP_STATE.md) |
Expand Down Expand Up @@ -247,6 +248,7 @@ hermes bighelp update [--restart] Install the latest release
hermes bighelp update-status Show the last update result
hermes bighelp files grant|revoke|roots Manage read-only folder grants
hermes bighelp files list|read|status|diff
hermes bighelp space update <space_id> Update a space from JSON on stdin ([Spaces](docs/SPACES.md))
```

Folder grants are for the `workspace-files` API of the plugin ([Workspace files](docs/WORKSPACE_FILES.md)). The
Expand Down
408 changes: 408 additions & 0 deletions docs/SPACES.md

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions fixtures/loopdy_card_v1/static-space-draft.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"schema": "loopdy.card",
"version": 1,
"title": "Commute",
"spoken_summary": "A space to add to Today: Commute. Updates every 15 minutes, without AI.",
"data_sources": [],
"root": "space",
"elements": {
"space": {
"type": "space_draft",
"props": {
"space_id": "s_0123456789abcdef0123456789abcdef",
"description": "Drive time to work, from live traffic.",
"updates": "Every 15 minutes",
"uses_ai": false,
"revision": 1
},
"children": []
}
}
}
8 changes: 5 additions & 3 deletions loopdy_plugin/agent_guide.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
- Cards: when a card is clearer than prose (weather, a score, a stock, a chart, a dashboard, a form), call \
the matching bighelp_render_* tool and put its display_markdown in your reply once. A form's answers or a \
selection card's pick come back as the user's next message; end your turn and wait for it.
- After you find a person, place or song (iphone_contacts, iphone_music, a search), show it as a \
- After you find a person, place or song, show it as a \
bighelp_render_card contact, place or music component, not a text list. If refused, use basic ones.
- Feed, Ideas and Goals: the bighelp_board tool, only for what the user asked for. Give every goal a \
category (health, relationships, finance, career, interests, productivity or other). Feed posts can carry \
Expand All @@ -47,8 +47,10 @@
- iphone_appearance sets bighelp's look (mode, chat color).
- iphone_navigation opens a page in the app to show where something is: call places with the user's words, \
then open the best match.
- Something interactive (a small tool, a live dashboard): bighelp_show_app, an HTML page the user opens from \
a card. The skill has its page API.
- Something interactive (a tool, a live dashboard): bighelp_show_app, an HTML page opened from \
a card. The skill has its API.
- A live page on the person's Today (a commute time, a tracker): bighelp_draft_space; a script routine, \
not AI, when it can.
- Workflows (bighelp_workflows): what you build stays a draft. Publish only when the user explicitly asks; \
Hermes asks them to approve.
- Never schedule jobs or posts the user didn't ask for; runs spend their AI budget.\
Expand Down
10 changes: 5 additions & 5 deletions loopdy_plugin/card_objects.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Contact, place and music card components (and photo drafts and apps), and which chats may use them.
"""Contact, place and music card components (and photo drafts, apps and spaces), and which chats may use them.

Older bighelp apps reject an element type they don't know ("Invalid or
unsupported card"). So a card with an object component is accepted only in a
Expand All @@ -13,7 +13,7 @@
import logging
from typing import Any, Callable, Iterable

from .loopdy_cards import APP_TYPES, DRAFT_TYPES, OBJECT_TYPES, BighelpCardError
from .loopdy_cards import APP_TYPES, DRAFT_TYPES, OBJECT_TYPES, SPACE_TYPES, BighelpCardError

logger = logging.getLogger("hermes.plugins.bighelp")

Expand All @@ -38,9 +38,9 @@
Renders = Callable[[str], Iterable[str]]


# What a chat's app may say it draws: the object components, the photo drafts (image_drafts.py) and
# HTML apps (html_apps.py).
DECLARABLE = OBJECT_TYPES | DRAFT_TYPES | APP_TYPES
# What a chat's app may say it draws: the object components, the photo drafts (image_drafts.py),
# HTML apps (html_apps.py) and space drafts (spaces.py).
DECLARABLE = OBJECT_TYPES | DRAFT_TYPES | APP_TYPES | SPACE_TYPES


def known(names: Iterable[Any]) -> frozenset[str]:
Expand Down
4 changes: 2 additions & 2 deletions loopdy_plugin/card_previews.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ def _described(card: dict[str, Any]) -> str:
title = plain_text(card.get("title"), 120).rstrip(".:")
try:
if card["schema"] == "loopdy.card":
# An app card says what the app does; its spoken summary only repeats the title.
# An app or space card says what it does; its spoken summary only repeats the title.
app = card["elements"].get(card["root"], {})
detail = plain_text(app["props"]["description"] if app.get("type") == "html_app"
detail = plain_text(app["props"]["description"] if app.get("type") in ("html_app", "space_draft")
else card.get("spoken_summary"))
elif card.get("version") == 1:
detail = _v1_detail(card)
Expand Down
3 changes: 3 additions & 0 deletions loopdy_plugin/host_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@
workspace_windows_unsupported
upload_chunk_corrupt upload_conflict upload_corrupt upload_finished upload_incomplete upload_length_invalid
upload_chunk_timeout upload_no_space upload_not_found upload_offset_invalid uploads_busy uploads_unavailable
draft_changed refresh_too_soon routine_failed schedules_unavailable space_not_draft space_not_found
spaces_full spaces_unavailable notification_activity_unknown notification_card_key_invalid
""".split())
RESULT_WORDS = frozenset({"accepted", "duplicate"})
# Where an error can come from. A code is accepted from these places only.
Expand Down Expand Up @@ -215,6 +217,7 @@
bighelp_people bighelp_send_notification bighelp_templates_search bighelp_templates_get bighelp_templates_fill
bighelp_templates_create_agent bighelp_workflows bighelp_catalog_login bighelp_submit_catalog_template
bighelp_draft_contact bighelp_draft_event bighelp_offer_photo_action bighelp_show_app bighelp_update_app_data
bighelp_draft_space bighelp_update_space bighelp_space_settings
""".split())
_KNOWN_TOOLS = _HERMES_TOOLS | _BIGHELP_TOOLS | {"mcp", "custom"}

Expand Down
55 changes: 43 additions & 12 deletions loopdy_plugin/html_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ class HtmlApp:
updated: float
html_sha256: str
html_bytes: int
# The space (spaces.py) whose page this is: kept past MAX_APPS, and changed only through the space.
space_id: str | None = None

@property
def live(self) -> bool:
Expand All @@ -119,7 +121,22 @@ def __init__(self, directory: Path, *, now: Callable[[], float] = time.time):
description TEXT NOT NULL, sends_answers INTEGER NOT NULL, data_kind TEXT NOT NULL,
data_path TEXT, inline_json TEXT, data_updated REAL, revision INTEGER NOT NULL,
created REAL NOT NULL, updated REAL NOT NULL, html_sha256 TEXT NOT NULL,
html_bytes INTEGER NOT NULL)""")
html_bytes INTEGER NOT NULL, space_id TEXT)""")
self._add_space_column()

def _add_space_column(self) -> None:
"""A store made before spaces gets their column. Another plugin copy may add it at the same time."""
with self._db() as db:
if "space_id" in {row["name"] for row in db.execute("PRAGMA table_info(apps)")}:
return
try:
with self._db(write=True) as db:
if "space_id" not in {row["name"] for row in db.execute("PRAGMA table_info(apps)")}:
db.execute("ALTER TABLE apps ADD COLUMN space_id TEXT")
except sqlite3.OperationalError:
with self._db() as db:
if "space_id" not in {row["name"] for row in db.execute("PRAGMA table_info(apps)")}:
raise

@contextmanager
def _db(self, *, write: bool = False) -> Iterator[sqlite3.Connection]:
Expand Down Expand Up @@ -148,7 +165,7 @@ def _app(row: sqlite3.Row) -> HtmlApp:
description=row["description"], sends_answers=bool(row["sends_answers"]), data_kind=row["data_kind"],
data_path=row["data_path"], inline_json=row["inline_json"], data_updated=row["data_updated"],
revision=row["revision"], created=row["created"], updated=row["updated"],
html_sha256=row["html_sha256"], html_bytes=row["html_bytes"])
html_sha256=row["html_sha256"], html_bytes=row["html_bytes"], space_id=row["space_id"])

def _page(self, app_id: str, sha256: str) -> Path:
return self.pages / f"{app_id}.{sha256}.html"
Expand Down Expand Up @@ -180,9 +197,9 @@ def get(self, app_id: str) -> HtmlApp | None:

def save(self, app_id: str, *, replace: bool, session_id: str, title: str, description: str,
sends_answers: bool, html: bytes, data_json: str | None = None,
data_path: str | None = None) -> HtmlApp:
data_path: str | None = None, space_id: str | None = None) -> HtmlApp:
"""Keep a new app, or with ``replace`` swap an existing one's page, texts and data source and bump
its revision. Its id and the session it was made in stay."""
its revision. Its id, the session it was made in and the space it belongs to stay."""
sha256 = hashlib.sha256(html).hexdigest()
kind = "path" if data_path is not None else "inline" if data_json is not None else "none"
new_id = app_id
Expand All @@ -196,11 +213,12 @@ def save(self, app_id: str, *, replace: bool, session_id: str, title: str, descr
values = (session_id if old is None else old["session_id"], title, description, int(sends_answers),
kind, data_path, data_json, now if kind == "inline" else None,
1 if old is None else old["revision"] + 1,
now if old is None else old["created"], now, sha256, len(html))
now if old is None else old["created"], now, sha256, len(html),
space_id if space_id is not None or old is None else old["space_id"])
db.execute(
"INSERT OR REPLACE INTO apps(session_id, title, description, sends_answers, data_kind, data_path, "
"inline_json, data_updated, revision, created, updated, html_sha256, html_bytes, app_id) "
"VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)", (*values, new_id))
"inline_json, data_updated, revision, created, updated, html_sha256, html_bytes, space_id, "
"app_id) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", (*values, new_id))
evicted = self._prune(db, keep=new_id)
except BaseException:
# Drop the page just written, keeping the one the app still holds.
Expand All @@ -216,15 +234,24 @@ def save(self, app_id: str, *, replace: bool, session_id: str, title: str, descr

@staticmethod
def _prune(db: sqlite3.Connection, *, keep: str) -> list[str]:
"""Past MAX_APPS, the least recently updated go."""
extra = db.execute("SELECT COUNT(*) FROM apps").fetchone()[0] - MAX_APPS
"""Past MAX_APPS, the least recently updated go. A space's page stays until its space goes
(spaces.py keeps their number small)."""
extra = db.execute("SELECT COUNT(*) FROM apps WHERE space_id IS NULL").fetchone()[0] - MAX_APPS
if extra <= 0:
return []
gone = [row["app_id"] for row in db.execute(
"SELECT app_id FROM apps WHERE app_id != ? ORDER BY updated, app_id LIMIT ?", (keep, extra))]
"SELECT app_id FROM apps WHERE app_id != ? AND space_id IS NULL ORDER BY updated, app_id LIMIT ?",
(keep, extra))]
db.executemany("DELETE FROM apps WHERE app_id = ?", [(app_id,) for app_id in gone])
return gone

def delete(self, app_id: str) -> bool:
"""Remove an app and its pages. Whether it was there."""
with self._db(write=True) as db:
existed = db.execute("DELETE FROM apps WHERE app_id = ?", (app_id,)).rowcount > 0
self._drop_pages(app_id)
return existed

def set_inline_data(self, app_id: str, data_json: str | None) -> tuple[HtmlApp, float]:
"""Replace an app's inline data (``None`` clears it). An app that reads a file refuses."""
now = self._now()
Expand Down Expand Up @@ -538,8 +565,12 @@ def show(args: Any, context: dict[str, Any], *, now: Callable[[], datetime], pro
if data is not None and data_path is not None:
raise _ToolError("invalid_arguments", "Give at most one of data or data_path.")
store = current_store()
if app_id is not None and store.get(app_id) is None:
raise _ToolError("app_not_found", "That app_id isn't one of your apps. Leave app_id out to make a new one.")
if app_id is not None:
existing = store.get(app_id)
if existing is None:
raise _ToolError("app_not_found", "That app_id isn't one of your apps. Leave app_id out to make a new one.")
if existing.space_id is not None:
raise _ToolError("app_in_space", "Change a space's page with bighelp_draft_space.")
page = _page(args, profile)
data_json = _inline_data(data) if data is not None else None
data_problem = None
Expand Down
Loading
Loading