@dreamforgestudiollc/emet 0.3.5 → 0.3.7

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 (103) hide show
  1. package/.env.example +29 -0
  2. package/CHANGELOG.md +49 -11
  3. package/CHARTER.md +1 -1
  4. package/CONTRIBUTING.md +21 -0
  5. package/README.md +25 -10
  6. package/RELEASE_NOTES-0.2.6.md +43 -0
  7. package/RELEASE_NOTES-0.3.6.md +29 -0
  8. package/RELEASE_NOTES-0.3.7.md +19 -0
  9. package/SECURITY.md +13 -0
  10. package/docs/BOTS.md +4 -4
  11. package/docs/DEPLOY.md +23 -4
  12. package/docs/ERROR-CODES-SPEC.md +4 -0
  13. package/docs/ERROR-CODES.md +7 -0
  14. package/docs/GUIDED-SETUP.md +1 -1
  15. package/docs/ROADMAP.md +62 -49
  16. package/docs/SETUP.md +11 -1
  17. package/docs/SUBKEYS.md +3 -1
  18. package/docs/continuity-currency-statechart.md +34 -0
  19. package/docs/features/README.md +21 -0
  20. package/docs/features/access.md +28 -0
  21. package/docs/features/documents.md +35 -0
  22. package/docs/features/errors.md +32 -0
  23. package/docs/features/gems.md +31 -0
  24. package/docs/features/memory.md +29 -0
  25. package/docs/features/pages.md +28 -0
  26. package/docs/features/record.md +27 -0
  27. package/docs/features/search.md +27 -0
  28. package/docs/features/startup.md +29 -0
  29. package/docs/features/subkeys.md +30 -0
  30. package/docs/features/transcripts.md +33 -0
  31. package/docs/per-tag-handoff-statechart.md +147 -0
  32. package/docs/subkey-session-statechart.md +57 -0
  33. package/package.json +6 -2
  34. package/server.json +27 -2
  35. package/src/annotations.js +5 -3
  36. package/src/attribution.js +2 -2
  37. package/src/carry-forward-close.js +1 -1
  38. package/src/chooser.js +74 -3
  39. package/src/conformance.js +2 -0
  40. package/src/continuity-currency-statechart.js +139 -0
  41. package/src/continuity-currency.js +869 -0
  42. package/src/database.js +1 -1
  43. package/src/dispatch.js +1 -1
  44. package/src/error-codes.js +7 -0
  45. package/src/gem-check.js +4 -1
  46. package/src/grants.js +28 -5
  47. package/src/host-reach.js +1 -1
  48. package/src/http-remote.js +29 -5
  49. package/src/index.js +3 -2
  50. package/src/invites.js +2 -2
  51. package/src/owl.js +12 -11
  52. package/src/pages.js +15 -0
  53. package/src/per-tag-handoff-statechart.js +264 -0
  54. package/src/per-tag-handoff.js +988 -0
  55. package/src/persons.js +16 -0
  56. package/src/session-graph.js +123 -12
  57. package/src/session.js +56 -12
  58. package/src/setup.js +32 -11
  59. package/src/startup-pages.js +13 -2
  60. package/src/subkey-lifecycle.js +105 -0
  61. package/src/subkey-session-statechart.js +253 -0
  62. package/src/subkeys.js +648 -89
  63. package/src/tools.js +171 -51
  64. package/src/transcript-session.js +2 -2
  65. package/src/version.js +1 -1
  66. package/templates/INDEX.md +1 -0
  67. package/templates/SESSIONDISPOSITION.md +2 -2
  68. package/templates/TAGHANDOFF.md +45 -0
  69. package/verification/continuity-currency/ContinuityCurrency.cfg +12 -0
  70. package/verification/continuity-currency/ContinuityCurrency.tla +239 -0
  71. package/verification/continuity-currency/tlc-output.txt +32 -0
  72. package/verification/continuity-currency/view.mjs +54 -0
  73. package/verification/load-gate/load-gate.mjs +1 -1
  74. package/verification/per-tag-handoff/PerTagHandoff.cfg +10 -0
  75. package/verification/per-tag-handoff/PerTagHandoff.tla +191 -0
  76. package/verification/per-tag-handoff/StampCounter.cfg +10 -0
  77. package/verification/per-tag-handoff/out/report.md +6 -0
  78. package/verification/per-tag-handoff/out-counter/chart.mmd +30 -0
  79. package/verification/per-tag-handoff/out-counter/report.md +15 -0
  80. package/verification/per-tag-handoff/out-counter/tlc.out +130 -0
  81. package/verification/per-tag-handoff/split/PerTagConflict.cfg +6 -0
  82. package/verification/per-tag-handoff/split/PerTagConflict.tla +104 -0
  83. package/verification/per-tag-handoff/split/PerTagTime.cfg +8 -0
  84. package/verification/per-tag-handoff/split/PerTagTime.tla +100 -0
  85. package/verification/per-tag-handoff/split/conflict-chart.mmd +47 -0
  86. package/verification/per-tag-handoff/split/conflict-report.md +8 -0
  87. package/verification/per-tag-handoff/split/conflict-tlc.txt +19 -0
  88. package/verification/per-tag-handoff/split/conflict-view.mjs +34 -0
  89. package/verification/per-tag-handoff/split/time-chart.mmd +44 -0
  90. package/verification/per-tag-handoff/split/time-report.md +8 -0
  91. package/verification/per-tag-handoff/split/time-tlc.txt +19 -0
  92. package/verification/per-tag-handoff/split/time-view.mjs +33 -0
  93. package/verification/per-tag-handoff/tlc-output.txt +19 -0
  94. package/verification/per-tag-handoff/v1-draft/PerTagHandoff.cfg +5 -0
  95. package/verification/per-tag-handoff/v1-draft/PerTagHandoff.tla +94 -0
  96. package/verification/per-tag-handoff/v1-draft/out/chart.mmd +37 -0
  97. package/verification/per-tag-handoff/v1-draft/out/report.md +7 -0
  98. package/verification/per-tag-handoff/v1-draft/out/tlc.out +19 -0
  99. package/verification/per-tag-handoff/v1-draft/view.mjs +20 -0
  100. package/verification/per-tag-handoff/view.mjs +31 -0
  101. package/verification/subkey-session/SubkeySession.cfg +11 -0
  102. package/verification/subkey-session/SubkeySession.tla +254 -0
  103. package/verification/subkey-session/tlc-output.txt +13 -0
@@ -0,0 +1,33 @@
1
+ # Transcripts
2
+
3
+ The word-for-word tier. `emet_session_open` starts a session. `emet_transcript_append` stores one exchange after each reply. `save_transcript` is the fallback when a host cannot append per reply. `query_transcripts` reads sessions back. `revise_transcript` supersedes a stored part. `emet_session_close` checks that the session's work was written. It does not write the work itself.
4
+
5
+ ## Sub-features
6
+
7
+ - transcript-open: `emet_session_open` needs `load_id` from startup. A closed id is not reopened; the next id gets a numeric suffix.
8
+ - transcript-append: `emet_transcript_append` stores one exchange. The append that opens the transcript, or that becomes the lowest stored index, must carry a measured machine line, or the words `no local shell MCP`.
9
+ - transcript-batch: `save_transcript` stores a whole session when append-per-reply is impossible.
10
+ - transcript-read: `query_transcripts` reads by time range or session id.
11
+ - transcript-revise: `revise_transcript` writes a new part and marks the parent superseded. `reason` is required.
12
+ - transcript-close: `emet_session_close` compares your receipts with the store. `complete` means the receipts matched. Anything else is not saved.
13
+ - transcript-carry-forward: pass `carry_forward` only when a later session already advanced HANDOFF or STATE. Cite the current conforming `records/` disposition and those later versions. `RETAINED_OPEN_CRITICAL` stays open. A refused call is not counted. Transcripts stay.
14
+
15
+ ## How to get to it (user POV)
16
+
17
+ Finish startup, then `emet_session_open` with the `load_id` you were given and a short slug. After every reply, `emet_transcript_append` with that session id, the user message, and your reply. At the end, `emet_session_close` with receipts taken from the tool results of this session, not from memory. Tell the user the session is saved only when the state is `complete`.
18
+
19
+ ## Driving it with verify-emet
20
+
21
+ ```
22
+ npm run verify -- feature transcripts
23
+ npm run verify -- run emet_session_open emet_transcript_append save_transcript query_transcripts revise_transcript emet_session_close
24
+ ```
25
+
26
+ The drive has no local shell, so the first append uses `no local shell MCP`. The close on that throwaway session reports what is still missing. A state other than `complete` is still a working tool: it checked, and it refused to pretend.
27
+
28
+ ## Gotchas
29
+
30
+ - The first successful append is refused without a machine line or `no local shell MCP`, whatever `exchange_index` opens the transcript. A refused exchange 1 does not let a higher index start it. Nothing is written. The code is `EMET-MEM-018`. `save_transcript` does not run that check.
31
+ - A closed session takes one closing exchange inside the grace window, then it locks.
32
+ - Close receipts have to match the store. Invented ids come back `blocked` or `incomplete`.
33
+ - A receipt close blocked only because a later session holds HANDOFF or STATE is not counted. Close that session with `carry_forward`, not by retrying the old receipts.
@@ -0,0 +1,147 @@
1
+ # Per-tag handoff statechart
2
+
3
+ `EMET_TAG_HANDOFFS` is off unless the value is `warn` or `enforce`. Off is the default. Both pictures are also on `/statechart`. The executable steps are `perTagHandoffStep` in `src/per-tag-handoff-statechart.js`.
4
+
5
+ The reference model is `verification/per-tag-handoff/PerTagHandoff.tla`, with `PerTagHandoff.cfg`, `view.mjs`, and `StampCounter.cfg`. TLC 2.19 found **958,557 distinct states** (8,532,898 generated), search depth 20, no error. `TypeOK`, `OwnHandoffOnly`, `RowPatchedOnlyByOpener`, `NoLostBoardUpdate`, `ReadOnlyWritesNothing`, `IdsCarryPerson`, `OpenWorkOnlyInProgress`, `StaleMarkOnlyWhileOpen`, and `StampReproducible` hold. The run is `verification/per-tag-handoff/tlc-output.txt`. That model is too big to draw: the chart budget is 500 states.
6
+
7
+ `StampCounter.cfg` checks `StampVersionsOnly` instead, a stamp of versions without the as-of age. It breaks in four steps: an AI starts, a write AI writes its own handoff, another start reads the view, then time passes and the line is aging. The path is `verification/per-tag-handoff/out-counter/`. The product stamp carries `as_of` so the same inputs rebuild that class.
8
+
9
+ The earlier draft, before the locked decisions, is `verification/per-tag-handoff/v1-draft/`. TLC on that draft found 187 distinct states. It does not have the opener rule, the person segment, or the as-of stamp.
10
+
11
+ The pictures below are drawn from a split of the reference, each inside the 500-state budget. The conflict module has no clock. The time module has no board. The full model checks both together, including a read-only tag trying to write another handoff. The time picture hides that refusal attempt. Both pictures hide a finish that stays in the same label.
12
+
13
+ Conflict: `verification/per-tag-handoff/split/PerTagConflict.tla`. TLC found 138 distinct states. The chart draws 7 states and 20 arrows.
14
+
15
+ ```mermaid
16
+ stateDiagram-v2
17
+ state "Legend" as legend {
18
+ lg0: refused
19
+ lg1: session
20
+ lg2: rest
21
+ }
22
+ class lg0 pink
23
+ class lg1 blue
24
+ class lg2 teal
25
+ s0: No handoffs yet
26
+ s1: In session, merged view read
27
+ s2: Write refused, nothing written
28
+ s3: Handoffs at rest
29
+ s4: In session, board moved since read
30
+ s5: In session, row conflict waiting for the hub
31
+ s6: At rest, row conflict waiting for the hub
32
+ [*] --> s0
33
+ s0 --> s1: an AI starts and reads the view
34
+ s1 --> s2: an AI tries to write another AI's handoff or an AI tries to patch a row it did not open
35
+ s1 --> s3: a write AI writes its own handoff last
36
+ s1 --> s4: a write AI opens a board row
37
+ s2 --> s1: an AI starts and reads the view or a write AI opens a board row or a write AI writes its own handoff last
38
+ s2 --> s3: a write AI writes its own handoff last
39
+ s3 --> s1: an AI starts and reads the view
40
+ s2 --> s4: a write AI opens a board row or a write AI writes its own handoff last or an AI starts and reads the view
41
+ s4 --> s2: an AI tries to patch a row it did not open or an AI tries to write another AI's handoff or a write on a moved board is refused
42
+ s4 --> s1: a write AI writes its own handoff last
43
+ s4 --> s5: a write AI writes its own handoff last
44
+ s1 --> s5: a write AI writes its own handoff last
45
+ s2 --> s5: a write AI writes its own handoff last or an AI starts and reads the view
46
+ s4 --> s3: a write AI writes its own handoff last
47
+ s4 --> s6: a write AI writes its own handoff last
48
+ s1 --> s6: a write AI writes its own handoff last
49
+ s5 --> s2: an AI tries to write another AI's handoff or an AI tries to patch a row it did not open
50
+ s5 --> s6: a write AI writes its own handoff last
51
+ s2 --> s6: a write AI writes its own handoff last
52
+ s6 --> s5: an AI starts and reads the view
53
+ class s0 teal
54
+ class s1 blue
55
+ class s2 pink
56
+ class s3 teal
57
+ class s4 blue
58
+ class s5 blue
59
+ class s6 teal
60
+ ```
61
+
62
+ Time: `verification/per-tag-handoff/split/PerTagTime.tla`. TLC found 143 distinct states. The chart draws 7 states and 19 arrows.
63
+
64
+ ```mermaid
65
+ stateDiagram-v2
66
+ state "Legend" as legend {
67
+ lg0: session
68
+ lg1: rest
69
+ }
70
+ class lg0 blue
71
+ class lg1 teal
72
+ s0: No handoff yet
73
+ s1: In session, merged view read
74
+ s2: In session, work shown in progress
75
+ s3: Handoff at rest
76
+ s4: In session, open work marked stale
77
+ s5: Handoff at rest, line aging
78
+ s6: In session, reading an aging line
79
+ [*] --> s0
80
+ s0 --> s1: an AI starts, reads the view, and stamps it
81
+ s1 --> s2: a write AI saves work in an open session
82
+ s1 --> s3: a write AI writes its own handoff last or a read-only AI leaves, writing nothing
83
+ s1 --> s0: a read-only AI leaves, writing nothing
84
+ s1 --> s4: a write AI saves work in an open session
85
+ s2 --> s4: time passes (24 hours open, 7 days aging)
86
+ s2 --> s3: a write AI writes its own handoff last
87
+ s3 --> s1: an AI starts, reads the view, and stamps it
88
+ s3 --> s5: time passes (24 hours open, 7 days aging)
89
+ s2 --> s1: a write AI writes its own handoff last
90
+ s4 --> s3: a write AI writes its own handoff last
91
+ s5 --> s6: an AI starts, reads the view, and stamps it
92
+ s4 --> s1: a write AI writes its own handoff last
93
+ s6 --> s2: a write AI saves work in an open session
94
+ s1 --> s6: an AI starts, reads the view, and stamps it
95
+ s6 --> s5: a read-only AI leaves, writing nothing
96
+ s1 --> s5: a read-only AI leaves, writing nothing
97
+ s6 --> s4: a write AI saves work in an open session
98
+ s6 --> s1: a read-only AI leaves, writing nothing
99
+ class s0 teal
100
+ class s1 blue
101
+ class s2 blue
102
+ class s3 teal
103
+ class s4 blue
104
+ class s5 teal
105
+ class s6 blue
106
+ ```
107
+
108
+ The counter-check draws only the path that breaks `StampVersionsOnly`:
109
+
110
+ ```mermaid
111
+ stateDiagram-v2
112
+ state "Legend" as legend {
113
+ lg0: session
114
+ lg1: rest
115
+ lg2: Breaks StampVersionsOnly in some cases
116
+ lg3: Path to the StampVersionsOnly bug
117
+ }
118
+ class lg0 blue
119
+ class lg1 teal
120
+ class lg2 mayBreak
121
+ class lg3 bugPath
122
+ s0: No handoffs yet
123
+ s1: In session, merged view read
124
+ s2: Handoffs at rest
125
+ [*] --> s0
126
+ s0 --> s1: an AI starts, reads the merged view, and stamps it
127
+ s1 --> s2: a write AI writes its own handoff last
128
+ s2 --> s1: an AI starts, reads the merged view, and stamps it
129
+ s1 --> s1: time passes (24 hours open, 7 days aging)
130
+ classDef mayBreak fill:#fff3e6,stroke:#e8730c,stroke-width:2.5px,color:#b85a06
131
+ class s0 teal
132
+ class s0 bugPath
133
+ class s1 blue
134
+ class s1 mayBreak
135
+ class s1 bugPath
136
+ class s2 teal
137
+ class s2 bugPath
138
+ ```
139
+
140
+ What the reader can check:
141
+
142
+ - A tag patches a board row it opened. The hub changes another tag's row only when that row is marked in conflict.
143
+ - A bot tag may patch its own rows. It still cannot write the hub handoff.
144
+ - Each write tag writes its own handoff. Another tag's handoff is refused.
145
+ - A read-only tag writes nothing.
146
+ - An open session with material work is an in-progress line. It is not a pointer and it is not a lag. After the long tick it is stale-open, and only while that session is still open. Nothing here blocks.
147
+ - A handoff line ages after the long tick. The stamp records the age it was read at, so the view can be rebuilt. A stamp of versions alone cannot.
@@ -0,0 +1,57 @@
1
+ # Sub-key session
2
+
3
+ A sub-key has one live session. The handle lasts 12 hours. The last hour is the renewal window. The hour after expiry is the grace window. Past that, or when the link is already ended, the sweep records `auto_closed`. The row stays. The transcript stays. The same diagram is served at `/statechart`.
4
+
5
+ ```mermaid
6
+ stateDiagram-v2
7
+ [*] --> opening
8
+ opening --> live: open commits
9
+ opening --> ended: open lost
10
+ live --> renewal_offered: last hour, handle still valid
11
+ renewal_offered --> live: renew with the key and the handle
12
+ live --> live: renew with the key and the handle
13
+ live --> expired: handle expires
14
+ renewal_offered --> expired: handle expires
15
+ expired --> live: renew with the key and the handle, inside grace
16
+ expired --> unwrapped: chat, no wrap-up, key still required to open
17
+ unwrapped --> live: same key opens the next session
18
+ live --> closed: owner, or same key reclaim, or a clean close
19
+ ended --> auto_closed: sweep
20
+ expired --> auto_closed: past grace, sweep
21
+ unwrapped --> auto_closed: past grace, sweep
22
+ opening --> auto_closed: past grace, sweep
23
+ live --> revoked: revoke
24
+ renewal_offered --> revoked: revoke
25
+ closed --> [*]
26
+ auto_closed --> [*]
27
+ revoked --> [*]
28
+ ```
29
+
30
+ | Start | Event | Next | Live slots |
31
+ | --- | --- | --- | --- |
32
+ | opening | the open commits | live | 1 |
33
+ | opening | the open is lost | ended | 0 |
34
+ | live | a call in the last hour | renewal_offered | 1 |
35
+ | live or renewal_offered | renew with the sub-key and the handle | live, previous closed | 1 |
36
+ | live or renewal_offered | the handle expires | expired | 0 |
37
+ | expired | renew with the sub-key and the handle, inside grace | live, previous closed | 1 |
38
+ | expired | the handle alone | expired, or unwrapped for a chat with no wrap-up | 0 |
39
+ | unwrapped, ended, or past grace | sweep | auto_closed | 0 |
40
+ | any non-closed session of this key | the owner, or a new open with this key | closed | 0, then the new open is the one live session |
41
+ | live | revoke | revoked | 0 |
42
+
43
+ A renewal is one write. The old row records `next_open_id`. The new row records `prev_open_id`. A handle that arrives without the sub-key does not mint the next session.
44
+
45
+ A chat is a key whose `client_kind` the owner stored as `chat`. A request can name a kind. That name is `requested_client_kind`. It is not the kind. A later call cannot set the kind.
46
+
47
+ A wrap-up is a record of that tag written from the handle's issue time through now: a handoff (`HANDOFF.md`, `HANDOFF/<tag>.md`, or `bots/<tag>/HANDOFF.md`) or an episodic row with `metadata.wrap_up`. When a chat has none, the old row is `unwrapped` and the reply says: The previous chat was not wrapped up. Go back to that chat and wrap it up to save it. The next open with the key still succeeds.
48
+
49
+ `emet_status` on a stranded session is not refused and does not write. It does not mark a session unwrapped and it does not write `handle_expired`. Unwrapped is recorded on the next open, or the sweep closes the session past the grace window. A write that names a stranded session returns `EMET-SESS-014` and writes nothing. That code is not `EMET-AUTH-039`.
50
+
51
+ A chat reclaim of a slot that is still inside its 12 hours is recorded on the key's collision list. The open still replaces that slot. One live session remains.
52
+
53
+ A second open while a bot key's slot is still inside its 12 hours is a collision. The collision flag stays the theft signal for that case. A chat key's next open reclaims the slot instead, because that client does not keep a process between turns. Another key cannot close this key's session.
54
+
55
+ The executable steps are `subkeySessionStep` in `src/subkey-session-statechart.js`. The model is `verification/subkey-session/SubkeySession.tla`. TLC does not enumerate handles or key bytes. `store` counts a write to the session record. A status read and a leaked handle leave `store` and the session where they are. Unwrapped is the next open that presents the key, not the leaked handle. TLC on this revision found 4,074 distinct states. The depth of the complete state graph is 19. No error. `TypeOK`, `AtMostOneLive`, `HealthyOccupies`, `NoBareMint`, `ReadLeavesStore`, `NoForeignClose`, `ClosedHasCloser`, `RevokedByOwner`, `UnwrappedIdle`, and `EventuallyClosed` hold. The run is `verification/subkey-session/tlc-output.txt`.
56
+
57
+ This changes the threat model in [EMET-0001](proposals/EMET-0001-delegated-client-sub-keys.md) §6 and §9. One live session per key stays. A second open during a bot's healthy 12 hours is still refused and flagged. A renewal replaces that session in one write, so the slot does not go empty between the two. A leaked handle cannot mint the next session after expiry. The owner, the same key, and the sweep can close a stranded session. A chat key does not raise the collision flag when its next turn opens, which is the residual for that kind: a second holder of the key can open while the chat's previous turn is still inside 12 hours. The history records the reclaim.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dreamforgestudiollc/emet",
3
- "version": "0.3.5",
4
- "description": "ISO 9001 7.5.3 / ISO 13485 4.2.5 document-control memory for AI agents. Nothing is deleted. EMET 0.3.5 — Enduring Memory & Epistemic Tiers. An MCP memory server with persistent shared memory for AI agents, bot teams and chats: layered memory, verified writes, a verbatim transcript tier, per-client attribution and approvals, and client-side GEM execution. EMET verifies the record, not the computation. A GEM is seated only when its released flag is true. Every error carries a stable code; the owner-only emet_error_report returns a report and an email draft the user sends. npm run verify drives the registered tools from a checkout, and docs/features is the map of every feature.",
3
+ "version": "0.3.7",
4
+ "description": "ISO 9001 7.5.3 / ISO 13485 4.2.5 document-control memory for AI agents. Nothing is deleted. EMET 0.3.7 — Enduring Memory & Epistemic Tiers. An MCP memory server with persistent shared memory for AI agents, bot teams and chats: layered memory, verified writes, a verbatim transcript tier, per-client attribution and approvals, and client-side GEM execution. EMET verifies the record, not the computation. A GEM is seated only when its released flag is true. Every error carries a stable code; the owner-only emet_error_report returns a report and an email draft the user sends. npm run verify drives the registered tools from a checkout, and docs/features is the map of every feature.",
5
5
  "keywords": [
6
6
  "agent-memory",
7
7
  "ai-agents",
@@ -46,8 +46,12 @@
46
46
  "guides/",
47
47
  "gems/",
48
48
  "docs/*.md",
49
+ "docs/features/**",
49
50
  "CHARTER.md",
50
51
  "CHANGELOG.md",
52
+ "RELEASE_NOTES*.md",
53
+ "SECURITY.md",
54
+ "CONTRIBUTING.md",
51
55
  "server.json",
52
56
  ".env.example",
53
57
  "README.md",
package/server.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "name": "io.github.dreamforgestudiollc/emet",
4
4
  "title": "EMET",
5
5
  "description": "ISO 9001 7.5.3 / ISO 13485 4.2.5 document-control memory for AI agents. Nothing is deleted.",
6
- "version": "0.3.5",
6
+ "version": "0.3.7",
7
7
  "websiteUrl": "https://dreamforgestudiollc.github.io/EMET/",
8
8
  "repository": {
9
9
  "url": "https://github.com/dreamforgestudiollc/EMET",
@@ -22,7 +22,7 @@
22
22
  "registryType": "npm",
23
23
  "registryBaseUrl": "https://registry.npmjs.org",
24
24
  "identifier": "@dreamforgestudiollc/emet",
25
- "version": "0.3.5",
25
+ "version": "0.3.7",
26
26
  "transport": {
27
27
  "type": "stdio"
28
28
  },
@@ -32,6 +32,30 @@
32
32
  "description": "MongoDB connection string for the memory store.",
33
33
  "isRequired": true,
34
34
  "isSecret": true
35
+ },
36
+ {
37
+ "name": "EMET_TAG_HANDOFFS",
38
+ "description": "Per-tag handoffs. Off unless set to warn or enforce.",
39
+ "isRequired": false,
40
+ "isSecret": false
41
+ },
42
+ {
43
+ "name": "EMET_HUB_TAG",
44
+ "description": "Hub tag that writes HANDOFF.md when per-tag handoffs are on.",
45
+ "isRequired": false,
46
+ "isSecret": false
47
+ },
48
+ {
49
+ "name": "EMET_HANDOFF_AGING_DAYS",
50
+ "description": "Days before a handoff line in the computed view is aging. Default 7.",
51
+ "isRequired": false,
52
+ "isSecret": false
53
+ },
54
+ {
55
+ "name": "EMET_STALE_OPEN_HOURS",
56
+ "description": "Hours before an open session with material work is marked stale-open. Default 24.",
57
+ "isRequired": false,
58
+ "isSecret": false
35
59
  }
36
60
  ]
37
61
  }
@@ -59,6 +83,7 @@
59
83
  "emet_subkey_end_session",
60
84
  "emet_subkey_request",
61
85
  "emet_subkey_revoke",
86
+ "emet_subkey_set_kind",
62
87
  "emet_transcript_append",
63
88
  "list_docs",
64
89
  "patch_doc",
@@ -55,7 +55,7 @@ const ADD = { readOnlyHint: false, destructiveHint: false, idempotentHint: false
55
55
  const REPLACE = { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false };
56
56
 
57
57
  const SUBKEY_ANNOTATION_NAMES = new Set([
58
- 'emet_subkey_request', 'emet_subkey_claim', 'emet_subkey_revoke', 'emet_subkey_end_session'
58
+ 'emet_subkey_request', 'emet_subkey_claim', 'emet_subkey_revoke', 'emet_subkey_end_session', 'emet_subkey_set_kind'
59
59
  ]);
60
60
 
61
61
  const ANNOTATION_TABLE = {
@@ -128,15 +128,17 @@ const ANNOTATION_TABLE = {
128
128
  // a health check that only reads cannot detect a broken write path.
129
129
  // Replaced emet_setup_status, get_status and emet_verify_connection on
130
130
  // 2026-09-27 (the owner: consolidate overlapping tools). -----------------------
131
- emet_status: { title: 'Store status and write-path probe', readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false }
131
+ emet_status: { title: 'Store status and write-path probe', readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
132
+ emet_subkey_set_kind: { title: 'Set a sub-key client kind', readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false }
132
133
  };
133
134
 
134
135
  function subkeyAnnotationsHidden() {
136
+ // CASCADE_SUBKEYS is a legacy environment name. EMET_SUBKEYS is the name to set.
135
137
  return process.env.EMET_SUBKEYS !== '1' && process.env.CASCADE_SUBKEYS !== '1';
136
138
  }
137
139
 
138
140
  /**
139
- * The four sub-key annotations are visible only when EMET_SUBKEYS=1, so a
141
+ * The sub-key annotations are visible only when EMET_SUBKEYS=1, so a
140
142
  * flag-off process has the same annotation set as before those tools existed.
141
143
  */
142
144
  export const TOOL_ANNOTATIONS = new Proxy(ANNOTATION_TABLE, {
@@ -32,7 +32,7 @@
32
32
  * (transcript parts, documents, layer entries): if those rows carry another
33
33
  * tag, the write is refused.
34
34
  *
35
- * OWNER (A2). Live owner tokens carry the owner's person id (e.g. "alex");
35
+ * OWNER (A2). Live owner tokens carry the owner's person id;
36
36
  * older ones carry "owner" or nothing. All three are the owner.
37
37
  */
38
38
 
@@ -48,7 +48,7 @@ export const WRITE_TOOLS = new Set([
48
48
  'patch_doc', 'retire_doc', 'rename_doc', 'restore_doc',
49
49
  'accept_nonconformance', 'emet_transcript_append', 'save_transcript', 'revise_transcript', 'emet_session_close',
50
50
  // Tester's re-review (2026-10-12): opening a session claims it; deciding a client is a write.
51
- 'emet_session_open', 'emet_client_approve',
51
+ 'emet_session_open', 'emet_client_approve', 'emet_subkey_set_kind',
52
52
  // Tester's PR 47 review: setup writes durable identity and board docs.
53
53
  'emet_setup_complete'
54
54
  ]);
@@ -6,7 +6,7 @@
6
6
  * match, the close stays blocked, and retries used to count toward the
7
7
  * three-close cap.
8
8
  *
9
- * A records/ session disposition (templates/SESSIONDISPOSITION.md, #95)
9
+ * A records/ session disposition (templates/SESSIONDISPOSITION.md)
10
10
  * documents that fact. The row does not close the graph and it is not a
11
11
  * receipt. This path closes the graph only when the owner door, or the
12
12
  * credential that wrote the session, cites that current row and the later
package/src/chooser.js CHANGED
@@ -59,6 +59,20 @@ function retainedSubkeys(data) {
59
59
  .sort((a, b) => String(a.tag).localeCompare(String(b.tag)) || String(a.key_id).localeCompare(String(b.key_id)));
60
60
  }
61
61
 
62
+ function kindForm(session, row) {
63
+ if (!session || !row || (row.status !== 'active' && row.status !== 'grace' && row.status !== 'approved')) return '';
64
+ const current = row.client_kind === 'chat' ? 'chat' : 'bot';
65
+ return `<form method="post" action="/owner/chooser/subkey-kind">
66
+ <input type="hidden" name="csrf" value="${esc(session.csrf)}">
67
+ <input type="hidden" name="key_id" value="${esc(row.key_id)}">
68
+ <label>Client <select name="client_kind">
69
+ <option value="bot"${current === 'bot' ? ' selected' : ''}>Bot</option>
70
+ <option value="chat"${current === 'chat' ? ' selected' : ''}>Chat</option>
71
+ </select></label>
72
+ <button type="submit">Save client</button>
73
+ </form>`;
74
+ }
75
+
62
76
  function historyLine(row) {
63
77
  const events = Array.isArray(row.history) ? row.history : [];
64
78
  if (!events.length) return esc(row.status);
@@ -147,6 +161,10 @@ ${doorRadios()}
147
161
  <input type="hidden" name="csrf" value="${esc(session.csrf)}">
148
162
  <input type="hidden" name="key_id" value="${esc(row.key_id)}">
149
163
  <input type="text" name="reason" maxlength="${REASON_MAX}" placeholder="Reason (optional)">
164
+ <label>Client <select name="client_kind">
165
+ <option value="bot" selected>Bot</option>
166
+ <option value="chat">Chat</option>
167
+ </select></label>
150
168
  <button type="submit" name="decision" value="approve">Approve</button>
151
169
  <button type="submit" name="decision" value="deny">Deny</button>
152
170
  </form>
@@ -160,8 +178,8 @@ ${doorRadios()}
160
178
  parts.push('<h2>Retained records</h2>');
161
179
  if (!keys.retained.length) parts.push('<p>No earlier sub-key decisions are in this store.</p>');
162
180
  else {
163
- const body = keys.retained.map((row) => `<tr><td>${esc(row.tag)}</td><td>${esc(row.status)}</td><td>${historyLine(row)}</td></tr>`).join('\n');
164
- parts.push(`<table><thead><tr><th>Tag</th><th>Status</th><th>History</th></tr></thead><tbody>${body}</tbody></table>`);
181
+ const body = keys.retained.map((row) => `<tr><td>${esc(row.tag)}</td><td>${esc(row.status)}</td><td>${esc(row.client_kind === 'chat' ? 'chat' : 'bot')}</td><td>${historyLine(row)}</td><td>${kindForm(session, row)}</td></tr>`).join('\n');
182
+ parts.push(`<table><thead><tr><th>Tag</th><th>Status</th><th>Client</th><th>History</th><th></th></tr></thead><tbody>${body}</tbody></table>`);
165
183
  }
166
184
  }
167
185
  parts.push(writerSection(session, writers));
@@ -301,6 +319,16 @@ export function mountChooser(app, options = {}) {
301
319
  });
302
320
  });
303
321
 
322
+ app.post('/owner/chooser/subkey-kind', parseBody, (req, res) => {
323
+ finishSubkeyKind(req, res).catch((e) => {
324
+ console.error('[emet] chooser subkey kind', e && e.message ? e.message : e);
325
+ if (!res.headersSent) {
326
+ res.locals.reason = 'chooser_subkey_kind_error';
327
+ sendHtml(res, 500, '<p>Something went wrong. Nothing was changed.</p>', 'EMET chooser');
328
+ }
329
+ });
330
+ });
331
+
304
332
  app.post('/owner/chooser/subkey', parseBody, (req, res) => {
305
333
  finishSubkey(req, res).catch((e) => {
306
334
  console.error('[emet] chooser subkey', e && e.message ? e.message : e);
@@ -406,6 +434,7 @@ export function mountChooser(app, options = {}) {
406
434
  const decision = req.body && req.body.decision;
407
435
  const keyId = typeof (req.body && req.body.key_id) === 'string' ? req.body.key_id.trim() : '';
408
436
  const reason = typeof (req.body && req.body.reason) === 'string' ? req.body.reason.trim() : '';
437
+ const clientKind = typeof (req.body && req.body.client_kind) === 'string' ? req.body.client_kind.trim() : '';
409
438
  if (decision !== 'approve' && decision !== 'deny') {
410
439
  res.locals.reason = 'bad_decision';
411
440
  sendHtml(res, 400, '<p>Decision must be approve or deny. Nothing was changed.</p>', 'EMET chooser');
@@ -426,7 +455,8 @@ export function mountChooser(app, options = {}) {
426
455
  let result = null;
427
456
  try {
428
457
  result = await decideSubkeyIfPending(depsOf(), ownerPageActor(personId), personId, {
429
- key_id: keyId, decision, reason, via: 'owner_chooser'
458
+ key_id: keyId, decision, reason, via: 'owner_chooser',
459
+ ...(clientKind ? { client_kind: clientKind } : {})
430
460
  }, new Date(now()));
431
461
  } catch (e) {
432
462
  if (e && e.attributionRefusal && !/sub-key store/.test(String(e.message))) {
@@ -458,6 +488,47 @@ export function mountChooser(app, options = {}) {
458
488
  await render(req, res, `${verb} ${result.tag}.`);
459
489
  }
460
490
 
491
+ async function finishSubkeyKind(req, res) {
492
+ const session = gate.sessionOf(req);
493
+ if (!session) {
494
+ res.locals.reason = 'no_owner_session';
495
+ sendHtml(res, 401, '<p>Only the owner session can set a sub-key client.</p>', 'EMET chooser');
496
+ return;
497
+ }
498
+ const posted = (req.body && req.body.csrf) || '';
499
+ if (!timingSafeEqualStr(posted, session.csrf)) {
500
+ res.locals.reason = 'bad_csrf';
501
+ sendHtml(res, 403, '<p>The form expired. Reload the page and try again.</p>', 'EMET chooser');
502
+ return;
503
+ }
504
+ const keyId = typeof (req.body && req.body.key_id) === 'string' ? req.body.key_id.trim() : '';
505
+ const clientKind = typeof (req.body && req.body.client_kind) === 'string' ? req.body.client_kind.trim() : '';
506
+ const personId = await resolveOwner();
507
+ if (!personId) {
508
+ res.locals.reason = 'owner_unavailable';
509
+ sendHtml(res, 400, '<p>The owner id is unavailable. Nothing was changed.</p>', 'EMET chooser');
510
+ return;
511
+ }
512
+ const { setSubkeyClientKind } = await import('./subkeys.js');
513
+ let result = null;
514
+ try {
515
+ result = await setSubkeyClientKind(depsOf(), ownerPageActor(personId), personId, {
516
+ key_id: keyId, client_kind: clientKind
517
+ }, new Date(now()));
518
+ } catch (e) {
519
+ if (e && e.attributionRefusal && !/sub-key store/.test(String(e.message))) {
520
+ res.locals.reason = 'kind_refused';
521
+ sendHtml(res, 400, `<p>${esc(e.message)}</p>`, 'EMET chooser');
522
+ return;
523
+ }
524
+ res.locals.reason = 'subkey_store';
525
+ sendHtml(res, 503, `<p>${STORE_MESSAGE}</p>`, 'EMET chooser');
526
+ return;
527
+ }
528
+ res.locals.reason = 'subkey_kind';
529
+ await render(req, res, `${result.tag} is ${result.client_kind}.`);
530
+ }
531
+
461
532
  async function finishWriter(req, res) {
462
533
  const session = gate.sessionOf(req);
463
534
  if (!session) {
@@ -33,6 +33,7 @@ import fs from 'fs';
33
33
  import path from 'path';
34
34
  import { resolveModulePath } from './module-path.js';
35
35
  import { setting } from './env.js';
36
+ import { tagHandoffMode, isTagHandoffDoc } from './per-tag-handoff.js';
36
37
  import { CodedError } from './error-codes.js';
37
38
 
38
39
  const HERE = resolveModulePath(import.meta.url);
@@ -287,6 +288,7 @@ export function extraMappings(raw = setting('TEMPLATE_MAP')) {
287
288
  /** Which template governs this doc_id, or null. */
288
289
  export function templateFor(doc_id) {
289
290
  if (!doc_id) return null;
291
+ if (tagHandoffMode() !== 'off' && isTagHandoffDoc(doc_id)) return 'templates/TAGHANDOFF.md';
290
292
  const base = baseMap();
291
293
  if (base.exact[doc_id]) return base.exact[doc_id];
292
294
  const { added } = extraMappings();