@unifedev/thread-pages 0.3.2 → 1.0.3

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.
Files changed (90) hide show
  1. package/README.md +77 -129
  2. package/dist/server.js +11426 -11802
  3. package/dist/server.meta.json +2 -2
  4. package/package.json +25 -18
  5. package/server.ts +3 -2175
  6. package/src/agent/cli.ts +193 -0
  7. package/src/agent/guide.ts +355 -0
  8. package/src/agent/instruction.ts +59 -0
  9. package/src/agent/seed/seed.ts +69 -0
  10. package/{theme.ts → src/agent/seed/theme-css.ts} +4 -11
  11. package/src/agent/starter-hub.ts +217 -0
  12. package/src/bb/activity.ts +59 -0
  13. package/src/bb/bb-host.ts +280 -0
  14. package/src/bb/public-origin.ts +45 -0
  15. package/src/config/settings.ts +82 -0
  16. package/src/domain/capabilities/contract.ts +48 -0
  17. package/src/domain/capabilities/index.ts +10 -0
  18. package/src/domain/capabilities/protocol.ts +112 -0
  19. package/src/domain/capabilities/registry.ts +48 -0
  20. package/src/domain/capabilities/schema.ts +198 -0
  21. package/src/domain/capabilities/specs.ts +479 -0
  22. package/src/domain/eligibility.ts +43 -0
  23. package/src/domain/errors.ts +116 -0
  24. package/src/domain/html/document.ts +109 -0
  25. package/src/domain/html/escape.ts +16 -0
  26. package/src/domain/ids.ts +37 -0
  27. package/src/domain/json/canonical.ts +19 -0
  28. package/src/domain/json/strict-json.ts +139 -0
  29. package/src/domain/limits.ts +88 -0
  30. package/src/domain/rate-limit.ts +64 -0
  31. package/src/domain/revision.ts +27 -0
  32. package/src/domain/submissions/idempotency.ts +59 -0
  33. package/src/domain/submissions/message.ts +42 -0
  34. package/src/domain/submissions/parse.ts +105 -0
  35. package/src/domain/tokens/action-token.ts +52 -0
  36. package/src/domain/tokens/confirmation.ts +99 -0
  37. package/src/domain/tokens/mac.ts +50 -0
  38. package/src/generated/kernel-runtime.ts +3 -0
  39. package/src/generated/shell-runtime.ts +3 -0
  40. package/src/host/contract.ts +65 -0
  41. package/src/host/types.ts +89 -0
  42. package/src/pages/layout.ts +65 -0
  43. package/src/pages/page-store.ts +136 -0
  44. package/src/pages/site.ts +36 -0
  45. package/src/plugin.ts +71 -0
  46. package/src/runtime/kernel/anchors.ts +45 -0
  47. package/src/runtime/kernel/api.ts +15 -0
  48. package/src/runtime/kernel/bridge-client.ts +148 -0
  49. package/src/runtime/kernel/dirty.ts +51 -0
  50. package/src/runtime/kernel/forms.ts +114 -0
  51. package/src/runtime/kernel/install.ts +156 -0
  52. package/src/runtime/kernel/labels.ts +98 -0
  53. package/src/runtime/kernel/main.ts +6 -0
  54. package/src/runtime/kernel/readonly.ts +75 -0
  55. package/src/runtime/shared/protocol.ts +125 -0
  56. package/src/runtime/shell/confirm.ts +70 -0
  57. package/src/runtime/shell/install.ts +79 -0
  58. package/src/runtime/shell/main.ts +12 -0
  59. package/src/runtime/shell/navigate.ts +64 -0
  60. package/src/runtime/shell/poll.ts +125 -0
  61. package/src/runtime/shell/relay.ts +185 -0
  62. package/src/serving/action-request.ts +32 -0
  63. package/src/serving/bridge/dispatcher.ts +112 -0
  64. package/src/serving/bridge/handler.ts +37 -0
  65. package/src/serving/bridge/handlers/index.ts +26 -0
  66. package/src/serving/bridge/handlers/navigation.ts +43 -0
  67. package/src/serving/bridge/handlers/reads.ts +186 -0
  68. package/src/serving/bridge/handlers/writes.ts +175 -0
  69. package/src/serving/bridge/selection-store.ts +58 -0
  70. package/src/serving/bridge-route.ts +23 -0
  71. package/src/serving/context.ts +34 -0
  72. package/src/serving/document-route.ts +37 -0
  73. package/src/serving/home-route.ts +23 -0
  74. package/src/serving/responses.ts +81 -0
  75. package/src/serving/routes.ts +26 -0
  76. package/src/serving/session-access.ts +22 -0
  77. package/src/serving/shell-html.ts +77 -0
  78. package/src/serving/shell-route.ts +51 -0
  79. package/src/serving/signing-key.ts +25 -0
  80. package/src/serving/submit-route.ts +47 -0
  81. package/src/serving/upload-route.ts +46 -0
  82. package/tsconfig.json +10 -6
  83. package/ARCHITECTURE.md +0 -230
  84. package/PLUGIN_OVERVIEW.md +0 -83
  85. package/authoring.ts +0 -368
  86. package/bridge.ts +0 -1721
  87. package/docs/MODEL.md +0 -211
  88. package/docs/ROADMAP.md +0 -96
  89. package/home.ts +0 -419
  90. package/page.ts +0 -782
package/README.md CHANGED
@@ -1,153 +1,101 @@
1
1
  # Thread Pages
2
2
 
3
- `@unifedev/thread-pages` part of [Unife](https://github.com/unifedev), a
4
- unified interface for everything. Thread Pages is the unified interface for
5
- working with AI agents; this plugin implements it for [bb](https://getbb.app).
6
-
7
- **Every agent session gets one web page, written for that task, that you can read
8
- and answer from on any device.**
9
-
10
- An agent usually has more to tell you than chat can carry: a comparison, a
11
- diagram, a set of choices, a thing only you can decide. Thread Pages gives it a
12
- page to say it on — and gives you a form to answer from, which arrives as the
13
- agent's next message.
14
-
15
- The page is a complete HTML document the agent writes for the task at hand. If it
16
- needs a chart, it writes a chart. If it needs a multi-screen flow, a diagram you
17
- click, or three separate forms, it writes that. The plugin supplies the secure
18
- host, never the design.
19
-
20
- ## Install
21
-
22
- ```sh
23
- bb plugin install git:https://github.com/unifedev/bb-thread-pages.git
24
- ```
25
-
26
- Then turn on **Agent initialization hint** in the plugin's settings, so new
27
- sessions use their page automatically:
3
+ A bb plugin: every agent session gets one page it writes itself, served as a
4
+ site the reader can read and answer from on any device.
28
5
 
29
6
  ```sh
30
- bb plugin config thread-pages set agentInstructions true
7
+ bb plugin install git:https://github.com/unifedev/bb-thread-pages.git@^1.0.0
31
8
  ```
32
9
 
33
- That is the whole setup. If this bb is paired with `bb connect`, every page is
34
- reachable from your phone immediately — there is no port to expose and nothing
35
- per-page to configure.
10
+ Then two things:
36
11
 
37
- ## Using it
38
-
39
- The agent's whole workflow is one command:
40
-
41
- ```sh
42
- bb thread-page init # create or locate this thread's page; prints the link
43
- ```
44
-
45
- Two others exist:
46
-
47
- ```sh
48
- bb thread-page guide # authoring reference, only when a page needs more
49
- bb thread-page home # make this thread's page the home page
50
- ```
12
+ 1. Turn on **Agent instructions** in the plugin's settings (or
13
+ `bb plugin config thread-pages set agentInstructions true`). Every new
14
+ session then writes a page for its task and answers you from it.
15
+ 2. Start a session anywhere and say *"Set up my Thread Pages home page."* The
16
+ agent runs `bb thread-page home` there, builds a hub of your sessions from
17
+ the guide's starter, and replies with the link every page links back to.
18
+ To change the hub later, ask that session.
51
19
 
52
- `bb thread-page home` writes a session hub grouped by project, with a filter,
53
- live status, and per-row open, prompt, stop and archive. Every other page then
54
- shows a **← Sessions** link back to it. Home is an ordinary page afterwards: ask
55
- the agent that owns it to regroup or restyle it.
20
+ ## This repository is the implementation only
56
21
 
57
- ## Documentation
22
+ The product is specified in a separate repository, **`unife-bb-plugin`**
23
+ (Syns): `spec/` is the buildable specification, `docs/DECISIONS.md` the
24
+ reasoning, `rewrite/` the architecture of this implementation and the
25
+ decisions taken while building it, `verify/` the fixtures and scenarios that
26
+ verify it. Nothing here decides what the product should be.
58
27
 
59
- - [docs/MODEL.md](./docs/MODEL.md) **start here**: instructions, storage,
60
- templates, and remote access
61
- - [ARCHITECTURE.md](./ARCHITECTURE.md) — the design and its reasoning
62
- - [docs/ROADMAP.md](./docs/ROADMAP.md) — what is left
63
- - [PLUGIN_OVERVIEW.md](./PLUGIN_OVERVIEW.md) — marketplace description
28
+ ## What an agent gets
64
29
 
65
- ## What a page can do
30
+ - `bb thread-page init` — creates `index.html` in the session's storage
31
+ directory from the seed (never overwrites), prints the path and the link.
32
+ - `bb thread-page guide` — the authoring guide: forms, files, uploads,
33
+ `window.threadPage`, every capability, limits, and what the sandbox silences.
34
+ - `bb thread-page home [--clear]` — makes this session's page the home page.
35
+ - `bb thread-page status` — settings, the exact instruction a new session
36
+ receives, and this session's page.
66
37
 
67
- Authored freely inside the sandbox:
38
+ The page root is the session's storage directory (`$BB_THREAD_STORAGE`):
39
+ `index.html` is the page, any file beside it is served relatively (nested
40
+ paths included), `uploads/` holds what the reader attaches.
68
41
 
69
- - any HTML, CSS and JavaScript, including Web Components, SVG, canvas, and
70
- multi-screen state;
71
- - forms that reply to the thread with no code at all — blank answers included,
72
- several forms at once, each with its own state;
73
- - file attachments, stored beside the thread and handed to the agent by path;
74
- - images, stylesheets, fonts and data from a confined per-thread asset folder;
75
- - live thread activity, so a page can show what the agent is doing now;
76
- - small state that survives a reload.
77
-
78
- Through named capabilities, with confirmation where it matters:
79
-
80
- - list sessions, projects and providers;
81
- - message, start, stop or archive a session;
82
- - create a project through the host's native folder picker;
83
- - open another page, a bb thread, or an external link.
84
-
85
- The plugin also supplies three pieces of chrome outside the page: the title bar,
86
- the Sessions link, and a working indicator while the thread is mid-turn. Its
87
- wording is a setting; blank hides it.
88
-
89
- ## Where things live
42
+ ## Layout
90
43
 
91
44
  ```
92
- ~/.bb/thread-storage/<threadId>/
93
- thread-page.html the page
94
- thread-page-assets/ what it shows you
95
- thread-page-uploads/ what you attached
45
+ server.ts entry: hands bb to the composition root
46
+ src/plugin.ts composition root
47
+ src/domain/ host-free: limits, errors, tokens, capabilities, submissions, HTML injection
48
+ src/host/ the host contract (spec 08) and its projected types
49
+ src/bb/ the bb adapter — the only package that imports the SDK's runtime shapes
50
+ src/pages/ page layout, the page store (revision, offline copy), the site strategy
51
+ src/serving/ routes, the bridge dispatcher and capability handlers
52
+ src/agent/ CLI, standing instruction, seed (with the design system), generated guide
53
+ src/config/ the five settings
54
+ src/runtime/ browser code: the kernel (inside the sandboxed page) and the shell (trusted chrome)
55
+ src/generated/ the bundled runtimes as string modules (committed; npm run build:runtime)
56
+ test/ vitest: domain, runtime (jsdom), serving (fake host), bb adapter, guide
57
+ scripts/build-runtime.mjs esbuild step for src/runtime
96
58
  ```
97
59
 
98
- The page is a normal file — read it, diff it, keep it. There is no database of
99
- pages and no separate publish step. Settings hold the instruction text and the
100
- new-page seed, so you can change what future pages start from without touching
101
- one that exists.
102
-
103
- ## Access
104
-
105
- Thread Pages needs no port share. Its routes are part of the bb server, so the
106
- origin that reaches bb reaches your pages, behind the same owner login:
107
-
108
- ```text
109
- https://<handle>.getbb.app/api/v1/plugins/thread-pages/http/page?threadId=<id>
110
- ```
111
-
112
- `bb thread-page init` prints that absolute URL whenever this bb is connected, and
113
- a relative path when it is local-only. For private access instead, point
114
- Tailscale Serve at the whole bb loopback origin — never Funnel it, and never
115
- wildcard-bind bb.
116
-
117
- ## Security
118
-
119
- The page is generated code, so it is treated as untrusted. It runs in an
120
- opaque-origin sandbox with no bb cookie, no mutation token, no parent DOM, no
121
- `localStorage`, no raw bb API, no CLI, no filesystem access, and no ordinary
122
- network access. Everything it can ask bb to do goes through one validated,
123
- named capability at a time.
124
-
125
- Anything reaching outside the current thread requires a confirmation the page
126
- cannot fake: the server answers once with a signed challenge carrying **its own**
127
- summary, the trusted shell shows that summary, and the server re-verifies the
128
- signature before acting. The challenge is bound to one request, method, parameter
129
- fingerprint, page revision and thread, and expires in two minutes.
130
-
131
- One limitation stated plainly: page JavaScript can navigate its own frame and put
132
- data in that URL. Browsers cannot prevent this while still allowing page scripts.
133
- It grants no bb authority, but a page is code you are choosing to run.
134
-
135
- ## Development
60
+ ## Working on it
136
61
 
137
62
  ```sh
138
63
  npm ci
139
- bb plugin types --check .
140
- npm test
141
- npm run typecheck
142
- npm run build
143
- bb plugin reload thread-pages
64
+ npm run check # build runtimes, typecheck, test
65
+ npm run build # runtimes + bb plugin build → dist/
66
+ bb plugin install . # try it locally
144
67
  ```
145
68
 
146
- 93 tests cover the capability contract, token scope and tampering, HTML parsing
147
- against adversarial documents, sandbox and CSP invariants, forms, uploads,
148
- confined assets, the home page, and the confirmation flow against forgery,
149
- replay and parameter-swapping.
150
-
151
- ## Licence
69
+ `src/generated/*.ts` must be rebuilt (`npm run build:runtime`) after any
70
+ change under `src/runtime/`; a test fails when they are stale.
71
+
72
+ Confirmed capabilities render a dialog in the shell; its buttons, not the
73
+ dialog's `close` event, settle the result, so they can be driven headlessly.
74
+
75
+ ## Serving on bb 0.42.1
76
+
77
+ bb's plugin router matches paths exactly, so the plugin cannot serve
78
+ `/page/<id>/*` itself. Files beside `index.html` are served by bb core's
79
+ thread-storage route through one same-origin `<base>` injected into the
80
+ document (`SiteStrategy` "core-storage"). One consequence: page script cannot
81
+ `fetch()` its own files (bb refuses the sandbox's `Origin: null`); subresources
82
+ load normally. The "plugin-prefix" strategy in `src/pages/site.ts` removes the
83
+ limitation once bb offers prefix routes.
84
+
85
+ ## Release
86
+
87
+ A release is a git tag **and** an npm publish, always both: `bb plugin install
88
+ git:…@^X.Y.0` resolves tags, `bb plugin install npm:@unifedev/thread-pages`
89
+ resolves npm, and the two must name the same code.
90
+
91
+ 1. `npm ci && npm run check && npm run build`
92
+ 2. Bump `version` in `package.json`, add the `CHANGELOG.md` entry, commit
93
+ `dist/` and `src/generated/` with it.
94
+ 3. `git tag -a vX.Y.Z -m "Thread Pages X.Y.Z" && git push origin main --tags`.
95
+ bb refuses a tag that later moves: publish a fix as a new version.
96
+ 4. `npm publish --access public` (as a member of `@unifedev`). Verify with
97
+ `npm view @unifedev/thread-pages version`.
98
+ 5. On a clean machine: `bb plugin install npm:@unifedev/thread-pages@^X.Y.0`
99
+ or the `git:` form, then `bb thread-page status`.
152
100
 
153
101
  MIT