counterparts 0.3.52 → 0.3.54

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 (63) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/README.md +1 -1
  3. package/docs/manual.md +3 -3
  4. package/docs/module-map.md +1 -0
  5. package/package.json +1 -1
  6. package/src/adapters/dashboard/CONTRACT.md +8 -0
  7. package/src/adapters/dashboard/web/README.md +7 -2
  8. package/src/adapters/dashboard/web/app.html +4 -0
  9. package/src/adapters/dashboard/web/app.js +31 -2
  10. package/src/adapters/dashboard/web/mechanisms/picture.js +2 -2
  11. package/src/adapters/dashboard/web/pages/flow/sections/detail.js +3 -1
  12. package/src/adapters/dashboard/web/pages/flow/sections/diagram.js +1 -1
  13. package/src/adapters/dashboard/web/pages/health/sections/archive.js +2 -1
  14. package/src/adapters/dashboard/web/pages/home/sections/hero.js +3 -0
  15. package/src/adapters/dashboard/web/pages/memories/sections/search.js +4 -1
  16. package/src/adapters/dashboard/web/pages/memories/sections/tools.js +7 -3
  17. package/src/adapters/dashboard/web/pages/self/sections/dreams.js +2 -2
  18. package/src/adapters/dashboard/web/pages/self/sections/journal.js +2 -1
  19. package/src/adapters/dashboard/web/pages/self/sections/settling.js +4 -3
  20. package/src/adapters/dashboard/web/pages/self/sections/stories.js +3 -2
  21. package/src/adapters/dashboard/web/pages/self/sections/traits.js +2 -1
  22. package/src/adapters/dashboard/web/pages/self/sections/wake.js +2 -1
  23. package/src/adapters/dashboard/web/respond.ts +349 -0
  24. package/src/adapters/dashboard/web/server.ts +41 -209
  25. package/src/adapters/dashboard/web/shared/actions.js +4 -1
  26. package/src/adapters/dashboard/web/shared/api.js +17 -1
  27. package/src/adapters/dashboard/web/shared/dom.js +50 -1
  28. package/src/adapters/dashboard/web/shared/event-modal.js +3 -0
  29. package/src/adapters/dashboard/web/shared/host.js +48 -0
  30. package/src/adapters/dashboard/web/shared/memory-modal.js +17 -9
  31. package/src/adapters/dashboard/web/shared/modal.js +8 -3
  32. package/src/adapters/dashboard/web/shared/utilities.css +5 -0
  33. package/src/adapters/dashboard/web/shared/widgets/feed.js +1 -1
  34. package/src/adapters/dashboard/web/shell/pages.js +13 -1
  35. package/src/adapters/lifecycle.ts +12 -1
  36. package/src/adapters/mcp/server-self-tools.ts +15 -2
  37. package/src/adapters/mcp/server-words.ts +2 -2
  38. package/src/adapters/mcp/server.ts +61 -0
  39. package/src/adapters/mcp/tools.ts +43 -2
  40. package/src/adapters/update-check.ts +1 -1
  41. package/src/core/counterpart-wake-shape.ts +793 -53
  42. package/src/core/counterpart.ts +37 -6
  43. package/src/core/dream/CONTRACT.md +3 -0
  44. package/src/core/dream/NOTES.md +9 -0
  45. package/src/core/dream/night-line.ts +11 -2
  46. package/src/core/dream/reflect.ts +38 -3
  47. package/src/core/encode/NOTES.md +1 -0
  48. package/src/core/encode/secrets.ts +13 -0
  49. package/src/core/handoff/CONTRACT.md +3 -1
  50. package/src/core/handoff/last-exchange.ts +24 -4
  51. package/src/core/owner-waits.ts +246 -0
  52. package/src/core/recall/INTERFACE-GAPS.md +6 -0
  53. package/src/core/recall/index.ts +5 -0
  54. package/src/core/recall/steps.ts +2 -0
  55. package/src/core/self/CONTRACT.md +76 -0
  56. package/src/core/self/NOTES.md +178 -0
  57. package/src/core/self/index.ts +105 -5
  58. package/src/core/self/set-down.ts +774 -0
  59. package/src/core/self/stories.ts +79 -0
  60. package/src/core/self/tunables.ts +134 -0
  61. package/src/core/self/writer.ts +57 -8
  62. package/src/core/store/index.ts +5 -0
  63. package/src/core/store/reads-memories.ts +14 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,56 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.54 — 2026-11-10
4
+
5
+ **Hosted gets your dashboard (read-only: home, memories, your page and dreams), and hosted sign-up can open by spots instead of invite codes (closed until we open it).** What you'll notice on hosted: the account page links "Open your dashboard", which shows Home, Memories and Self; Subjects, Flow and Health say they're not on hosted yet. The sign-in page reads "Email me a link", with an optional "Have an invite code?". For local users: the dashboard's buttons work as before (their click handling moved, nothing new). No store-format change (store v15, cache v7), no migration. Nothing to run after upgrading beyond the usual restart of the dashboard and every Claude Code session. Going back to 0.3.53 is a reinstall with no store restore: `counterparts disconnect`, 0.3.53's install, then `counterparts connect`.
6
+
7
+ - **Hosted: your dashboard, read-only.** The account page links "Open your dashboard" (`/dashboard/`): the local
8
+ dashboard's Home, Memories and Self pages (the days, the memories, the self page, the dreams), served from your
9
+ hosted memory and seen only by you. Nothing on it writes; the pages that read your computer (Subjects, Flow,
10
+ Health) say they're not on hosted yet. The local dashboard and hosted's now share one server-side answerer, and
11
+ every button's click handling moved from inline handlers to delegated listeners: the local dashboard looks and
12
+ works as before. Its pages retry a request that was told to slow down.
13
+ - **Hosted: sign up with just your email while the beta has spots left.** The operator sets how many accounts
14
+ hosted takes (`spots set N`); until it's full, a new address gets a sign-up link with no code. When it's full,
15
+ the sign-in page says so and links counterparts.ai's waiting list. Invite codes still work, and are now an
16
+ optional "Have an invite code?" field. Spots start at 0, so nothing opens until the operator says so.
17
+
18
+ ## 0.3.53 — 2026-11-09
19
+
20
+ **Your page names what it sets down and tells more than corrections; the morning wake reads cleaner; things waiting on you come up when they're relevant, not as a pile.** What you'll notice: the morning after a night's page write, the wake can say "Set down from my page last night: …"; the wake ends with a "Carried forward" line, gives overdue items as a count with the oldest date, and names the session id in its first line; and now and then a line "Waiting on <you>, ask when it fits: …" when something you owe an answer on comes up in the conversation or at the week's session start. The wake changes are in the shaped wake (on for a store created since 0.3.46, or after `counterparts wake-shape on`). `remember` takes `story: true`. No store-format change (store v15, cache v7), no migration. Nothing to run after upgrading beyond the usual restart of the dashboard and every Claude Code session. Going back to 0.3.52 is a reinstall with no store restore: `counterparts disconnect`, 0.3.52's install, then `counterparts connect`.
21
+
22
+ - **The page says what it sets down.** The self page stays within its room, so each night a new line pushes an old
23
+ one out. Now the night's page writers name the lines they take out, with a short why, and anything taken out
24
+ that wasn't named is recorded anyway; a line only reworded, or folded into a story still on the page, isn't
25
+ counted as gone. Each line set down is kept as a memory, word for word. The next morning's wake names up to two
26
+ ("Set down from my page last night: …"), and `recall "set down"` lists them all, newest first, with why and date.
27
+ When life brings one up again (it's used, or a newer memory says it again), the night's writers are shown it and
28
+ may put it back.
29
+ - **The page's stories are about growth, not only corrections.** On a store that keeps its page in its own form
30
+ (`counterparts page-form own`), the night's page writers are told to keep a mix of story kinds (corrections that
31
+ changed how the counterpart works, and also what went right, discoveries, and moments with the owner), and that a
32
+ story earns its place if it would still teach something in a different project. Day's end is shown the day's
33
+ memories about me or us with a small head start over the day's work, so a busy work day doesn't crowd them out.
34
+ A practice on the page that is only about the work may move into a skill memory, which recall brings back when
35
+ the work calls for it; the set-down record names it. On every store, `remember` takes `story: true` to nominate a
36
+ moment as a story: the night's writer sees it first and still decides, and one it passes by fades like any
37
+ other memory.
38
+ - **The wake says what it points at, once.** A reminder told in another session is listed again by title instead of
39
+ "shown earlier", which that session never saw. The night's closing line no longer repeats a sentence the page or
40
+ day's end already says, and the same line on a second morning shrinks to a clause. Overdue items get their own count
41
+ with the oldest date. A handoff waiting on an answer with nothing new sinks below the others, and one more than a week
42
+ old that nothing refers to stops being listed (still under `recall "handoffs"`). Every line under Elsewhere says when.
43
+ "Last said" quotes a whole first sentence when it fits. "Last night" stops saying the run is under way once the
44
+ dream is written up. And the wake's first line names the session id, which the `reflect` tool asks for.
45
+ - **What waits on you comes up when it's relevant, not as a pile.** An item waiting on your answer is no longer one of
46
+ the wake's still-open lines. Instead, when a turn you start touches one, it's raised once after the recall block,
47
+ with what it needs and how long it has waited; and a session's wake says at most one ("Waiting on <you>, ask
48
+ when it fits: …"), the most relevant to the folder's week first, the same item there at most once a week. Each item is raised at most once a lived day across
49
+ every session, then again after 3, 7 and 14 lived days, and then it's parked (still under `recall "still open"`).
50
+ - **"PW" before a version number is no longer read as a password.** 0.3.52's prose-password check redacted the
51
+ version in "PW 1.48" (short for Playwright); a bare Playwright version after "PW" is now left alone, and short
52
+ passwords after "PW" are still redacted. The manual and README say "most passwords" named in a sentence.
53
+
3
54
  ## 0.3.52 — 2026-11-09
4
55
 
5
56
  **Counterparts now runs on Windows (new: tell us how it goes), and a password said in a sentence is no longer kept.** It also brings memory that fades on purpose as it grows: old per-turn records roll up, older release notes give way to newer ones, finished things stop being overdue, and the night closes items itself. What you'll notice: the morning's "Last night" can say in one line which open items the night closed; doctor has new Growth lines saying what is filling up and whether it leaves as fast, and a Recall steps line saying where recall's time goes; fewer overdue and still-open items at wake. One thing goes for good: the per-turn recall records (`recall.decision`, `recall.credit`, `recall.rated`) are now kept 30 lived days instead of 90, and on the first night after updating, the ones older than that are rolled up into one summary row per day (counts, the memories credited, the sessions) and deleted. If you want them, copy your store before updating. No store-format change (store v15, cache v7), no migration. Nothing to run after upgrading beyond the usual restart of the dashboard and every Claude Code session. Going back to 0.3.50 needs no store restore: `counterparts disconnect`, 0.3.50's install, then `counterparts connect` (the rows already rolled up stay gone).
package/README.md CHANGED
@@ -71,7 +71,7 @@ walkthrough is in [`docs/QUICKSTART.md`](docs/QUICKSTART.md).
71
71
  first, the next time Counterparts runs. It is never in a backup.
72
72
  - What's stripped before anything is kept, in the memories and in that conversation text:
73
73
  credentials in recognisable shapes (API keys, tokens, private keys, passwords in URLs, a
74
- value after a name like `password=` or `api_key:`), and passwords named in a sentence
74
+ value after a name like `password=` or `api_key:`), and most passwords named in a sentence
75
75
  ("my wifi password is …", "the PIN is …"): the value goes, the sentence stays. Not every
76
76
  secret has a shape, so don't paste things you wouldn't want kept.
77
77
  - It doesn't read or change your CLAUDE.md files or Claude Code's own auto memory
package/docs/manual.md CHANGED
@@ -13,7 +13,7 @@ A memory for an AI, in its own words, not a transcript: it writes with `remember
13
13
  - Each session opens with a wake: who I am (the self page), where the work stands, what's coming up and still open, how yesterday went.
14
14
  - In Claude Code, related memories come up as footnotes as the conversation goes. `recall` is the deliberate look, everywhere.
15
15
  - It's theirs to see, export and delete. [local] It is one SQLite file on their computer, and Counterparts sends nothing about them anywhere (the details are on counterparts.ai/privacy). [hosted] It lives on Counterparts' server, one store per account; backups that leave the server are encrypted with a key for their account.
16
- - What's stripped before anything is kept, in memories and in the raw conversation text: credentials in recognisable shapes (keys, tokens, private keys, passwords in URLs, a value written after a name like password= or api_key:), and passwords named in a sentence ("my wifi password is …", "the PIN is …"), the value only. Not every secret has a shape: don't paste things you wouldn't want kept.
16
+ - What's stripped before anything is kept, in memories and in the raw conversation text: credentials in recognisable shapes (keys, tokens, private keys, passwords in URLs, a value written after a name like password= or api_key:), and most passwords named in a sentence ("my wifi password is …", "the PIN is …"), the value only. Not every secret has a shape: don't paste things you wouldn't want kept.
17
17
  - A new memory may start with a few starter notes, titled "Told: …". They were given, not lived: they start weak, come after lived memories that match as well, are never part of the self, and can be corrected or let go like any memory.
18
18
 
19
19
  ## Everyday phrases
@@ -111,8 +111,8 @@ If something seems off (no wake, no night), check before guessing: `status`, and
111
111
  [hosted] Counterparts Online is this memory on a server, used from claude.ai with the `wake` tool.
112
112
 
113
113
  - It's connected in claude.ai as a custom connector, from the setup page the person was given. In a new chat, the `wake` tool starts the conversation.
114
- - Sign-in is by an emailed link. The account page has the connected AIs, the time zone (the memory's day turns over at their midnight), "Download my memory", and delete.
115
- - There are no hooks: the `wake` tool starts each chat, and nothing asks for a write-up at the end. There are no terminal commands and no dashboard.
114
+ - Sign-up is by email while the beta has spots left; when it's full, the sign-in page links counterparts.ai's waiting list, and an invite code still signs up. Sign-in is by an emailed link. The account page has the connected AIs, the time zone (the memory's day turns over at their midnight), "Download my memory", and delete.
115
+ - There are no hooks: the `wake` tool starts each chat, and nothing asks for a write-up at the end. There are no terminal commands. The account page links a read-only dashboard (Home, Memories, Self); its other pages are local only.
116
116
  - One account is one memory, with no folders: the `scope` tool pauses it or turns it off.
117
117
  - Nights run in the day's first chat, after the `wake` and before the answer (see Nights and dreams), or from the person's own routine.
118
118
  - Limits in the beta: about 120 calls a minute and 1,500 an hour; a store of up to 1 GiB. Over a limit, the tool says so; nothing is lost.
@@ -29,6 +29,7 @@ code and the `NOTES.md` / `INTERFACE-GAPS.md` next to it.*
29
29
  | *(`reconsolidation.ts`)* | reconsolidation + interference | Two memories that disagree: flagged (a dream, today), noticed at write time (the nearest few live memories come back with a stored one), and SETTLED — `changed` (both true at their time: one strength cut, labelled earlier), `corrected` (archived, readable by id), or `open` (both kept, shown together) — by a new memory's `updates` + `how`, a `remember` settle, a dream or reflection with a plain reason, or the owner's `counterparts settle`. Every settle is on a trail (who, how, why, when) and can be undone. A file beside `revision.ts`, whose ordinary-memory arm it is; its tables are the store's (schema v10), its labels recall's (`recall/standing.ts`). **Added 2026-09-29** as `contradictions.ts`; **renamed 2026-10-11** (Group 2: noticing and updating are one process; the tables keep their names). |
30
30
  | *(`interference.ts`)* | interference (retroactive, for routine work) | A newer routine work event fades the older one on the same subject: each night (the cycle's `interfere` phase) an unsalient, never-used `about: work` status note naming a version in its headline is settled `changed` (×0.5) under the nearest later state in the same folder, through `reconsolidation.ts#supersede` (source `interference`, reason `superseded-by-newer`). Nothing the owner said, nothing felt, nothing open. Counted beside the prune on the `sleep.cycle` row. **Added 2026-11-07** (FD1 step 3). |
31
31
  | *(`close-hint.ts`)* | — (a write's hint, not a mechanism) | When a stored `remember` or `session_end` entry says something was done, the open items from any folder whose subject it matches (the same version series, the same PR, or what their `settlesWhen` names) are listed in its result, at most three, for the writing model to close or leave. Nothing closes here. Counted as `open.close-hint.shown` / `open.close-hint.closed`. **Added 2026-11-07** (SO1 step 1b). |
32
+ | *(`owner-waits.ts`)* | — (the wake's backoff for what waits on the owner) | An open memory marked `asked`, or a handoff WK3 sank, is said at most once per wake as "Waiting on <owner>, ask when it fits", the most relevant to the folder's week first, in an attended session, and after the recall block on a person's turn that touches it; each raise is latched once per item per lived day, then it waits 3/7/14 lived days (at session start at least a week) and parks, still listed under `recall "still open"`. Meta `wake.owner.raised`, event `open.owner.raised`. **Added 2026-11-09** (SO1 step 4). |
32
33
  | *(`open-close.ts`)* | — (closing what is done) | The night closes an open item a later release shows done: each night (the cycle's `close` phase) an open release step ("0.3.46 ready") in a folder closes when a later memory there says a higher patch of the series was released — `closeThread`'s write with `threadClosedBy` and a `thread.night.closed` row. Never a question to the owner, a check, or one the owner reopened. What might be done is listed `mayBeDone` under `recall "still open"`; the reflect tool's `reopen` puts one back. **Added 2026-11-07** (SO1 step 1). |
33
34
  | *(`time.ts`)* | — (a clock, not a memory) | The one module that converts: a moment (UTC ms from `store.now()`) to a person's local date or clock line, "today" in a zone, and calendar dates as said (day, month, year, range). A file, not a module; a test keeps hand-built dates out of `src/`. **Added 2026-09-25 (`docs/time.md`).** |
34
35
  | *(`feelings-wheel.ts`)* | — (a vocabulary) | The feelings wheel as a typed list: seven cores (happy, warm, calm, curious, sad, uneasy, angry), the groups and their words, default valence and intensity on every entry, blends, aliases, and the rule that re-filed the first wheel's feelings (v11). Read by `store/` to validate the `feelings` table. **Added 2026-09-25; v2 2026-09-30.** |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "counterparts",
3
- "version": "0.3.52",
3
+ "version": "0.3.54",
4
4
  "license": "MIT",
5
5
  "description": "Long-term memory for Claude Code, written by Claude itself. Local MCP server and hooks; remembers you across sessions.",
6
6
  "repository": {
@@ -64,6 +64,14 @@ persisted into dashboard state. **[M]** Totality: every registered axis appears
64
64
  marked absent. **[A]** Views stay readable by a non-engineer — the owner is the acceptance
65
65
  test.
66
66
 
67
+ **Two hosts, one page (HD2, 2026-11-10).** The local server and the hosted server
68
+ (`hosted/src/dashboard.ts`, at `/dashboard/` for the signed-in owner) serve the same page,
69
+ files and views through `web/respond.ts`, each with a `DashboardHost`. **[M]** Looking is
70
+ the same observer stance on both. **[M]** Managing is the local host's only: the shared half
71
+ never imports `web/actions.ts`, and the page hides every managing control where
72
+ `HOST.canAct` is false (`shared/host.js`). Panels about the local machine (doctor, the store's
73
+ folder path) are the local host's too. A part a host doesn't show says so in one line.
74
+
67
75
  **Which store it serves (2026-10-12).** Two stores on one machine (a throwaway trial store
68
76
  and the person's real one) can both try port 4747, so a reader must be able to tell whose
69
77
  dashboard answered. **[M]** `GET /api/whoami` returns `{ store, version }`: `store` is the
@@ -11,6 +11,7 @@ step, no dependencies. `server.ts` serves them as files (see "Serving" below).
11
11
  | file | what it is |
12
12
  |---|---|
13
13
  | `server.ts` | `node:http` on 127.0.0.1, the Host allowlist, `router()` (GET: `/`, `/brain` (now a redirect to `/#home`), the favicon (`favicon.svg`, a file beside it since 2026-10-14), `/api/*`, the static files), and the POST hand-off to `actions.ts`. A store waiting for its one-time upgrade (v6 met by v7, `../upgrade.ts`) gets one calm page instead, and is tried again on every request |
14
+ | `respond.ts` | the half both hosts serve (HD2, 2026-11-10): `staticReply` (the page, the favicon, the static files) and `viewReply` (every `/api` view) over an observer source, for a `DashboardHost` — `LOCAL_HOST` (`/`, every view, can act) or `HOSTED_HOST` (`/dashboard/`, the views in `HOSTED_VIEWS`, read-only, no machine panels, no brain). Root-absolute links in the page and CSS are rebased to the host's base at serve time; the page learns the host from `<meta name="counterparts-host">`. Never imports `actions.ts` and has no `node:fs` (the caller hands in `Files`). The hosted door is `hosted/src/dashboard.ts` |
14
15
  | `actions.ts` | managing: `POST /api/action/<name>` — the same-origin + per-launch-token guard, argument validation, and the console's own `run()` (loaded lazily; never handed the observer source). `ACTIONS` lists them: `ask`, `note`, `remove`, `backup`, `export`, `scope`, `rebrief`, `verify`, and `doctor` (a read: the health tab's checklist, `doctor --json`) |
15
16
  | `ask-voice.ts` | `toMyVoice(question, ownerName)`: Ask is the owner talking to me, so `ask` turns his question into my voice before it searches ("do you remember what I said" → "do I remember what Mike said"; his I → "you" when the store knows no name). Pure; the rules are in its header and `test/dashboard-ask-voice.test.ts`. The server reads the name (`sleep#ownerNames`) and hands `actions.ts` the string |
16
17
  | `static.ts` | `resolveStatic()`: which URL paths are static files and where they live (pure; no fs) |
@@ -43,7 +44,11 @@ shared/
43
44
  fonts/ Outfit (variable, latin) + Courier Prime 400/700 (latin) .woff2, with their OFL licences
44
45
  base.css layout.css utilities.css reset, header/nav, headings, the .cols grids, .foot/.tone-*/#err
45
46
  tip.css modal.css the tooltip and the overlay card
46
- dom.js $ esc
47
+ dom.js $ esc, and the delegated clicks: markup says `data-do="open-memory" data-id=…`
48
+ (never an inline onclick=), a module registers `onDo(name, fn)`, one listener
49
+ (`wireClicks`, from the modal's mount) runs it — so hosted's CSP needs no inline script
50
+ host.js HOST: which host serves the page (local | hosted) and what it shows — tabs, canAct,
51
+ machine, the pulse's pace; `NOT_HERE`, the one line a hidden part says instead
47
52
  format.js n2 n3 pct said livedSpan headline
48
53
  dates.js dateWords dateOr stampWords: every date the dashboard prints itself, one style
49
54
  ("Sep 30th", the year when it is not this one; "Wed, Sep 30th" for a title).
@@ -55,7 +60,7 @@ shared/
55
60
  actions.js act() (managing: the one POST, with the page's token) and resultHtml()
56
61
  canvas.js FACE (the canvas's face, Outfit) fit hitTest roundRect clip wrapText
57
62
  tip.js modal.js showTip/hideTip; openModal/closeModal/section
58
- memory-modal.js openMemory, copyId, removeMemory (window globals: rows use inline onclick)
63
+ memory-modal.js openMemory, copyId, removeMemory (data-do handlers; window globals kept for the harness)
59
64
  memory-marks.js .css a memory's kind icon/colour, feeling dots, strength meter, badges;
60
65
  feelingName (what the page CALLS a stored core: its own name
61
66
  since the wheel v2, 2026-09-30) and feelingWord (a
@@ -11,6 +11,10 @@
11
11
  <!-- The server turns this off when the brain picture's three.js is not
12
12
  installed (server.ts#BRAIN_LIBRARY); the home tab then draws without it. -->
13
13
  <meta name="counterparts-brain" content="on">
14
+ <!-- Which host serves this page (web/respond.ts#DashboardHost): "local" here,
15
+ "hosted" on app.counterparts.ai. shared/host.js reads it, and hides what
16
+ the host can't do (act) or has no business showing (the local machine). -->
17
+ <meta name="counterparts-host" content="local">
14
18
  <!--
15
19
  The shell. Styles, scripts and the two font faces are served beside this file
16
20
  (see README.md): no CDN, no network of any kind beyond this origin.
@@ -8,13 +8,23 @@
8
8
  ─────────────────────────────────────────────────────────────────────────── */
9
9
  import { api, fail } from "./shared/api.js";
10
10
  import { $ } from "./shared/dom.js";
11
+ import { HOST } from "./shared/host.js";
11
12
  import { mountModal } from "./shared/modal.js";
12
13
  import { live, tabs } from "./shared/state.js";
13
14
  import { PAGE, PAGES, TABS } from "./shell/pages.js";
14
15
  import { poll } from "./shell/pulse.js";
15
16
  import { mountNav, showTab } from "./shell/tabs.js";
16
17
 
18
+ // On hosted, one line under the header: who sees this page, and the way back.
19
+ if (HOST.name === "hosted") {
20
+ const note = document.createElement("p");
21
+ note.className = "host-note";
22
+ note.innerHTML = 'Only you see this page: it is read from your memory each time you open it. <a href="/account">Your account</a>';
23
+ $("err").before(note);
24
+ }
25
+
17
26
  // Each page writes its own markup into its section and wires its listeners.
27
+ // A tab this host doesn't show is a one-line stub (shell/pages.js).
18
28
  for (const page of PAGES) page.mount($("tab-" + page.name));
19
29
  mountNav();
20
30
  mountModal();
@@ -35,7 +45,22 @@ addEventListener("resize", () => {
35
45
  // home tab's headline, the store's path on the health tab).
36
46
  const meta = await api("/api/meta");
37
47
  live.fingerprint = { rows: meta.rows, day: meta.day };
38
- } catch (e) { fail("The header", e); }
48
+ } catch (e) {
49
+ // On hosted a store a look can't read (never connected yet, set to be
50
+ // deleted, being restored) says why in its one sentence, and nothing else
51
+ // is drawn or polled: every panel would only say the same thing again.
52
+ if (HOST.name === "hosted") {
53
+ const p = document.createElement("p");
54
+ p.className = "not-here";
55
+ p.textContent = e && e.message ? e.message : String(e);
56
+ for (const s of document.querySelectorAll("section.tab")) s.hidden = true;
57
+ $("nav").hidden = true;
58
+ $("err").before(p);
59
+ document.documentElement.dataset.loaded = "1";
60
+ return;
61
+ }
62
+ fail("The header", e);
63
+ }
39
64
  showTab(location.hash.slice(1) || "home", false);
40
65
  // Every tab is built once, up front: a screenshot of any of them should never
41
66
  // be waiting on a fetch, and the flow diagram needs its data before it can be
@@ -46,6 +71,10 @@ addEventListener("resize", () => {
46
71
  try { await document.fonts.ready; } catch { /* no FontFaceSet: the fallback face stands */ }
47
72
  const current = PAGE[tabs.current];
48
73
  if (current.redraw) current.redraw();
49
- setInterval(poll, 4000);
74
+ // The pulse: every 4 s locally; on hosted slower, and never while the tab is
75
+ // hidden (each poll opens the person's store on the server), with one look
76
+ // as soon as it is shown again (shared/host.js).
77
+ setInterval(() => { if (HOST.pulseWhenHidden || !document.hidden) void poll(); }, HOST.pulseMs);
78
+ if (!HOST.pulseWhenHidden) addEventListener("visibilitychange", () => { if (!document.hidden) void poll(); });
50
79
  document.documentElement.dataset.loaded = "1";
51
80
  })();
@@ -2,13 +2,13 @@
2
2
  markup, touches no DOM and fetches nothing, so a picture is a function of the
3
3
  `/api/mechanism` payload alone. A memory is always clickable (the page's
4
4
  `openMemory`). */
5
+ import { openMemoryAttrs } from "../shared/dom.js";
5
6
  import { esc } from "../shared/dom.js";
6
7
 
7
8
  /** A memory's words, clickable. `width` trims long ones for a tight row. */
8
9
  export function memLink(m, width) {
9
10
  const text = width && m.text.length > width ? m.text.slice(0, width - 1).trimEnd() + "…" : m.text;
10
- return '<span class="pic-mem" role="button" tabindex="0" title="' + esc(m.text) + '" onclick="openMemory(\'' +
11
- esc(m.id) + '\')" onkeydown="if(event.key===\'Enter\')openMemory(\'' + esc(m.id) + '\')">' + esc(text) + "</span>";
11
+ return '<span class="pic-mem" role="button" tabindex="0" title="' + esc(m.text) + '" ' + openMemoryAttrs(esc(m.id)) + '>' + esc(text) + "</span>";
12
12
  }
13
13
 
14
14
  /** A thin horizontal bar, `frac` of the way, with a mark at `mark` if given. */
@@ -1,6 +1,7 @@
1
1
  /* Selected mechanism — what a node does, its brain analogy, where that analogy
2
2
  deliberately breaks, and what it has actually been doing. */
3
3
  import { api, fail } from "../../../shared/api.js";
4
+ import { onDo } from "../../../shared/dom.js";
4
5
  import { $, esc } from "../../../shared/dom.js";
5
6
  import { flow } from "../state.js";
6
7
  import { drawFlow } from "./diagram.js";
@@ -41,5 +42,6 @@ function nodeEvent(ev) {
41
42
  "<span style='color:var(--faint)'>day " + ev.day + " · </span>" + esc(ev.text) + "</p>";
42
43
  }
43
44
 
44
- // The phone list's rows select through an inline `onclick` string.
45
+ // The phone list's rows select with `data-do="select-node"` (shared/dom.js).
46
+ onDo("select-node", (el) => selectNode(el.getAttribute("data-key") || ""));
45
47
  window.selectNode = selectNode;
@@ -238,7 +238,7 @@ function renderFlowList() {
238
238
  const col = ACCENT[n.accent] || COL.cyan;
239
239
  return (i === 0 ? "" : '<div class="fchain">↓</div>') +
240
240
  '<div class="fnode' + (n.silent ? " silent" : "") + (flow.selected === n.key ? " on" : "") +
241
- '" onclick="selectNode(\'' + n.key + '\')">' +
241
+ '" data-do="select-node" data-key="' + esc(n.key) + '">' +
242
242
  '<span><span class="nm" style="color:' + col + '">' + esc(n.label) + "</span>" +
243
243
  '<span class="sb">' + esc(n.sub) + "</span></span>" +
244
244
  '<span class="st">' + esc(n.state) + "</span></div>";
@@ -3,6 +3,7 @@
3
3
  segment (or its line in the legend) to list those memories; click one to
4
4
  open its card. Nothing archived is ever deleted: an archived memory keeps
5
5
  its id and its history. */
6
+ import { openMemoryAttrs } from "../../../shared/dom.js";
6
7
  import { $, esc } from "../../../shared/dom.js";
7
8
 
8
9
  export const markup = `
@@ -47,7 +48,7 @@ function list(r) {
47
48
  const items = r.items.map((m) => {
48
49
  const notes = [timesNote(m), m.note || ""].filter((x) => x !== "").map((x) => '<span class="ha-note">' + esc(x) + "</span>").join("");
49
50
  return openable
50
- ? '<button type="button" class="ha-item" onclick="openMemory(\'' + esc(m.id) + '\')">' + esc(m.label) + notes + "</button>"
51
+ ? '<button type="button" class="ha-item" ' + openMemoryAttrs(esc(m.id)) + '>' + esc(m.label) + notes + "</button>"
51
52
  : '<div class="ha-item ha-still">' + esc(m.label) + notes + "</div>";
52
53
  }).join("");
53
54
  const listed = typeof r.listed === "number" ? r.listed : r.items.length;
@@ -7,6 +7,7 @@
7
7
  `shared/doctor.js`'s reading, the same run the Health tab draws. */
8
8
  import { $, esc } from "../../../shared/dom.js";
9
9
  import { onDoctor, verdictOf } from "../../../shared/doctor.js";
10
+ import { HOST } from "../../../shared/host.js";
10
11
 
11
12
  export const markup = `
12
13
  <section class="home-top" aria-label="This memory, today">
@@ -19,6 +20,8 @@ function dot(grade) {
19
20
  }
20
21
 
21
22
  export function mount() {
23
+ // Doctor checks this machine (hooks, worker, install): only where there is one (shared/host.js).
24
+ if (!HOST.machine) { const el = $("home-health"); if (el) el.remove(); return; }
22
25
  onDoctor((r) => {
23
26
  const el = $("home-health");
24
27
  if (!el) return;
@@ -27,6 +27,7 @@ import { act, resultHtml } from "../../../shared/actions.js";
27
27
  import { api, fail } from "../../../shared/api.js";
28
28
  import { dateOr } from "../../../shared/dates.js";
29
29
  import { $, esc } from "../../../shared/dom.js";
30
+ import { HOST } from "../../../shared/host.js";
30
31
  import { withIdMarks } from "../../../shared/memory-marks.js";
31
32
  import { memRow, searchWords } from "../row.js";
32
33
  import { find, onFilter, setFilter } from "../state.js";
@@ -58,7 +59,9 @@ export const MODES = {
58
59
 
59
60
  /** The switch and the box's placeholder, as `find.mode` says. */
60
61
  function paintMode() {
61
- $("q-mode").innerHTML = Object.entries(MODES).map(([m, x]) =>
62
+ // Facts and by meaning ask the console (`act("ask")`): only where the page can act.
63
+ if (!HOST.canAct) find.mode = "word";
64
+ $("q-mode").innerHTML = Object.entries(MODES).filter(([m]) => HOST.canAct || m === "word").map(([m, x]) =>
62
65
  '<button type="button" class="fchip' + (find.mode === m ? " on" : "") + '" data-mode="' + m + '" aria-pressed="' +
63
66
  (find.mode === m) + '">' + x.label + "</button>").join("");
64
67
  $("q").placeholder = MODES[find.mode].placeholder;
@@ -4,11 +4,14 @@
4
4
  console's own command through `shared/actions.js` and says what it said.
5
5
  (Remove lives on the memory card, where the memory is.) */
6
6
  import { act, resultHtml } from "../../../shared/actions.js";
7
+ import { openMemoryAttrs } from "../../../shared/dom.js";
7
8
  import { $, esc } from "../../../shared/dom.js";
9
+ import { HOST } from "../../../shared/host.js";
8
10
  import { MY_NAME } from "../../../shared/voice.js";
9
11
  import { changed } from "../state.js";
10
12
 
11
- export const markup = `
13
+ // Every button here manages: only where the page can act (shared/host.js).
14
+ export const markup = !HOST.canAct ? "" : `
12
15
  <div class="tools">
13
16
  <button class="mbtn primary" id="note-open" type="button" aria-expanded="false">+ Add a memory</button>
14
17
  <button class="mbtn" id="backup-open" type="button">Back up…</button>
@@ -16,7 +19,7 @@ export const markup = `
16
19
  <button class="mbtn" id="delete-open" type="button">Delete data…</button>
17
20
  </div>`;
18
21
 
19
- export const notePanel = `
22
+ export const notePanel = !HOST.canAct ? "" : `
20
23
  <div class="card pad note-panel" id="note-panel" hidden>
21
24
  <div class="np-head">Remember this, on purpose</div>
22
25
  <textarea id="note-text" rows="3" spellcheck="true" placeholder="something for ${MY_NAME} to remember"></textarea>
@@ -29,6 +32,7 @@ export const notePanel = `
29
32
  </div>`;
30
33
 
31
34
  export function mount() {
35
+ if (!HOST.canAct) return;
32
36
  const panel = $("note-panel");
33
37
  const setOpen = (open) => {
34
38
  panel.hidden = !open;
@@ -49,7 +53,7 @@ export function mount() {
49
53
  const said = (r.out || []).find((l) => /^Remembered /.test(l));
50
54
  const id = said && (said.match(/\b(mem_[A-Za-z0-9_-]+)/) || [])[1];
51
55
  $("note-out").innerHTML = '<div class="act-out act-good">' + esc(said || "Remembered.") +
52
- (id ? ' <button class="linkbtn" type="button" onclick="openMemory(\'' + esc(id) + '\')">open it</button>' : "") +
56
+ (id ? ' <button class="linkbtn" type="button" ' + openMemoryAttrs(esc(id)) + '>open it</button>' : "") +
53
57
  "</div>";
54
58
  $("note-text").value = ""; $("note-title").value = "";
55
59
  changed();
@@ -4,6 +4,7 @@
4
4
  A change the owner undid is struck through. The journal is a dream, kept
5
5
  apart from the memories: nothing here is something that happened. */
6
6
  import { absenceLine } from "../../../shared/absence.js";
7
+ import { openMemoryAttrs } from "../../../shared/dom.js";
7
8
  import { $, esc } from "../../../shared/dom.js";
8
9
  import { said } from "../../../shared/format.js";
9
10
  import { renderMarkdown } from "../markdown.js";
@@ -22,8 +23,7 @@ const STATE = { begun: "dreaming", journaled: "woke", undone: "undone" };
22
23
 
23
24
  /** One memory a change touched; an original the dream had less than whole says how it saw it. */
24
25
  export function memoryRef(m) {
25
- return '<span class="dr-mem" role="button" tabindex="0" onclick="openMemory(\'' +
26
- esc(m.id) + '\')" onkeydown="if(event.key===\'Enter\')openMemory(\'' + esc(m.id) + '\')">' + said(m.text) + "</span>" +
26
+ return '<span class="dr-mem" role="button" tabindex="0" ' + openMemoryAttrs(esc(m.id)) + '>' + said(m.text) + "</span>" +
27
27
  (m.seen ? ' <span class="dr-seen">(' + esc(m.seen) + ")</span>" : "");
28
28
  }
29
29
 
@@ -4,6 +4,7 @@
4
4
  recorded), and picking a title opens its text in place. The whole entry
5
5
  still opens as a record. */
6
6
  import { absenceLine } from "../../../shared/absence.js";
7
+ import { openMemoryAttrs } from "../../../shared/dom.js";
7
8
  import { $, esc } from "../../../shared/dom.js";
8
9
  import { renderMarkdown } from "../markdown.js";
9
10
  import { chapterKey, ui } from "../state.js";
@@ -75,7 +76,7 @@ export function paint(d) {
75
76
  "</button>" +
76
77
  (open
77
78
  ? '<div class="jc-body">' + (c.text === null ? '<p class="foot">This chapter could not be read.</p>' : renderMarkdown(c.text)) +
78
- '<button type="button" class="act-btn jc-open" onclick="openMemory(\'' + c.id + '\')">open the whole entry</button></div>'
79
+ '<button type="button" class="act-btn jc-open" ' + openMemoryAttrs(esc(c.id)) + '>open the whole entry</button></div>'
79
80
  : "") +
80
81
  "</div>";
81
82
  }).join("");
@@ -4,6 +4,7 @@
4
4
  crossed lately (became core, sent back, nominated in a dream). Closeness to
5
5
  the core is measured by physics' own promotion rule (the view computes it;
6
6
  this only draws it). The explaining words sit behind `?`. */
7
+ import { openMemoryAttrs } from "../../../shared/dom.js";
7
8
  import { $, esc } from "../../../shared/dom.js";
8
9
  import { headline, n2, said } from "../../../shared/format.js";
9
10
  import { openModal } from "../../../shared/modal.js";
@@ -85,7 +86,7 @@ function history(h) {
85
86
  if (!h) return "";
86
87
  const LANE = { fast: "strongly felt, and came back", slow: "kept coming back over weeks" };
87
88
  const row = (r, tail) =>
88
- '<button type="button" class="st-row click" onclick="openMemory(\'' + esc(r.id) + '\')">' +
89
+ '<button type="button" class="st-row click" ' + openMemoryAttrs(esc(r.id)) + '>' +
89
90
  '<span class="st-text">' + said(headline(r.text)) + "</span>" +
90
91
  '<span class="st-hist-tail">' + esc(tail) + "</span></button>";
91
92
  const out = [];
@@ -112,7 +113,7 @@ function list(s, key) {
112
113
  if (key === "reconsidering") {
113
114
  // Still core; nothing leaves without a decision — mine, or yours.
114
115
  return s.reconsidering.map((r) =>
115
- '<button type="button" class="st-row click" onclick="openMemory(\'' + esc(r.id) + '\')">' +
116
+ '<button type="button" class="st-row click" ' + openMemoryAttrs(esc(r.id)) + '>' +
116
117
  '<span class="st-text">' + said(headline(r.text)) + "</span>" +
117
118
  '<span class="st-hist-tail">' + esc("since day " + r.day + " · " + r.why) + "</span></button>").join("") +
118
119
  '<p class="foot st-note">Still in the core. Nothing leaves it without a decision: keep one with <code>counterparts core --reaffirm &lt;id&gt; --reason "…"</code>, or send it back with <code>--demote</code>. I can decide too, awake or when I reflect.</p>';
@@ -141,7 +142,7 @@ function list(s, key) {
141
142
  }
142
143
 
143
144
  function row(r) {
144
- return '<button type="button" class="st-row click" onclick="openMemory(\'' + r.id + '\')">' +
145
+ return '<button type="button" class="st-row click" ' + openMemoryAttrs(esc(r.id)) + '>' +
145
146
  '<span class="st-text">' + said(r.text) + "</span></button>";
146
147
  }
147
148
 
@@ -1,6 +1,7 @@
1
1
  /* One revision story as a card: how a belief began, what it says now, and each
2
2
  credited challenge in the order it landed. The settling section opens it in
3
3
  the overlay. */
4
+ import { openMemoryAttrs } from "../../../shared/dom.js";
4
5
  import { esc } from "../../../shared/dom.js";
5
6
  import { n3, pct } from "../../../shared/format.js";
6
7
 
@@ -19,7 +20,7 @@ export function storyCard(s) {
19
20
  "<div class='verdict'>pressure " + n3(b.pressureAfter) + " against a bar of " + n3(b.bar) +
20
21
  " — " + esc(b.verdict) + "</div>" +
21
22
  (b.became
22
- ? "<div class='verdict became'" + (b.becameId ? " onclick=\"openMemory('" + b.becameId + "')\"" : "") +
23
+ ? "<div class='verdict became'" + (b.becameId ? " " + openMemoryAttrs(esc(b.becameId)) : "") +
23
24
  ">it became: " + esc(b.became) + "</div>"
24
25
  : "") +
25
26
  "</div>" +
@@ -31,7 +32,7 @@ export function storyCard(s) {
31
32
  const said = (label, text, full, id, style) =>
32
33
  '<div class="said"><span class="k">' + label + "</span>" +
33
34
  '<span class="stmt' + (id ? " click" : "") + '" title="' + esc(full) + '"' +
34
- (id ? " onclick=\"openMemory('" + id + "')\"" : "") + (style ? ' style="' + style + '"' : "") + ">" +
35
+ (id ? " " + openMemoryAttrs(esc(id)) : "") + (style ? ' style="' + style + '"' : "") + ">" +
35
36
  esc(text) + "</span></div>";
36
37
  return '<div class="story">' +
37
38
  '<div class="about">about ' + esc(s.about) + "</div>" +
@@ -9,6 +9,7 @@
9
9
  marker, never a centred one (the faint one still shows when the memories
10
10
  behind it a week ago have all left since). Tap a row for the memories behind it; each opens
11
11
  its card. What is open is kept in `state.js`, so a live refresh keeps it. */
12
+ import { openMemoryAttrs } from "../../../shared/dom.js";
12
13
  import { $, esc } from "../../../shared/dom.js";
13
14
  import { headline, said } from "../../../shared/format.js";
14
15
  import { ui } from "../state.js";
@@ -93,7 +94,7 @@ function row(a) {
93
94
  /** The memories behind one axis, the weightiest first; each opens its card. */
94
95
  function list(a) {
95
96
  const rows = a.rows.map((r) =>
96
- '<button type="button" class="st-row click tr-item" onclick="openMemory(\'' + esc(r.id) + '\')">' +
97
+ '<button type="button" class="st-row click tr-item" ' + openMemoryAttrs(esc(r.id)) + '>' +
97
98
  '<span class="st-text">' + said(headline(r.text)) +
98
99
  '<span class="tr-why">' + esc(r.carriedBy) + "</span></span>" +
99
100
  '<span class="tr-toward k-' + (r.toward === a.poles[1] ? "r" : "l") + '">' + esc(r.toward) + "</span></button>").join("");
@@ -6,6 +6,7 @@
6
6
  built (the console's `counterparts rebrief` is unchanged). */
7
7
  import { absenceLine } from "../../../shared/absence.js";
8
8
  import { dateWords } from "../../../shared/dates.js";
9
+ import { openMemoryAttrs } from "../../../shared/dom.js";
9
10
  import { $, esc } from "../../../shared/dom.js";
10
11
  import { headline, said } from "../../../shared/format.js";
11
12
  import { ui } from "../state.js";
@@ -40,7 +41,7 @@ export function pageAge(p) {
40
41
  export function memoryItem(m) {
41
42
  const name = m.title || headline(m.text);
42
43
  if (!m.id) return '<li class="wk-line-i" title="' + esc(m.text) + '">' + esc(name) + "</li>";
43
- return '<li><button type="button" class="wk-mem" onclick="openMemory(\'' + esc(m.id) + '\')" title="' +
44
+ return '<li><button type="button" class="wk-mem" ' + openMemoryAttrs(esc(m.id)) + ' title="' +
44
45
  esc(m.text) + '">' + said(name) + "</button></li>";
45
46
  }
46
47