@dreamforgestudiollc/emet 0.3.2 → 0.3.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.
- package/CHANGELOG.md +12 -1
- package/README.md +3 -3
- package/package.json +2 -2
- package/server.json +3 -3
- package/src/carry-forward-close.js +386 -0
- package/src/owner-session.js +63 -2
- package/src/session.js +49 -6
- package/src/tools.js +21 -2
- package/src/version.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,7 +7,18 @@ change before 1.0.
|
|
|
7
7
|
|
|
8
8
|
## Unreleased
|
|
9
9
|
|
|
10
|
-
Nothing is waiting above 0.3.
|
|
10
|
+
Nothing is waiting above 0.3.3.
|
|
11
|
+
|
|
12
|
+
## 0.3.3 - 2026-11-03
|
|
13
|
+
|
|
14
|
+
Listing text from public pull request #24, plus the public parts of private #97 and #98. Private #95 (session disposition) and #96 (the 0.3.2 public sync) are already in 0.3.2. Stored data shapes are unchanged. This change does not publish to npm or the MCP Registry. Filled disposition inventories stay in the private repository.
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
- Carry-forward close. `emet_session_close` takes `carry_forward` with `disposition_doc`, `disposition_version`, and `citations` when a later session already advanced HANDOFF or STATE. The owner door, or the credential that wrote the session, cites a current conforming session disposition (`CARRIED_FORWARD`, `SUPERSEDED_BY_LATER_SESSION`, or `ABANDONED_NO_TRANSCRIPT`) and those later versions. `RETAINED_OPEN_CRITICAL` stays open. A declared source is not authority. Transcripts stay. A refused call is not counted. A receipt close blocked only because a later session holds HANDOFF or STATE stays blocked and is not counted. From private #97. ISO 9001 7.5.3 / ISO 13485 4.2.5 document-control wording is unchanged.
|
|
18
|
+
- Owner page portrait. `/owner/chooser` and `/owner/break-glass` use `site/assets/portrait.webp` as the page background, served at `/owner/assets/portrait.webp`. The sheet is a scrim. A missing file leaves the page without a portrait and does not stop startup. The npm package does not ship `site/`. The deploy image copies the portrait. From private #98. ISO 9001 7.5.3 / ISO 13485 4.2.5 document-control wording is unchanged.
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
- Version 0.3.3. `server.json`, `package.json`, and `glama.json` descriptions lead with ISO 9001 7.5.3 / ISO 13485 4.2.5 document control. The registry description stays within 100 characters. It says "Nothing is deleted.", which is `CHARTER.md` §3 commitment 2. `.cursor-plugin/plugin.json` leads with the same line. The wording landed in public pull request #24 at version 0.3.2 and was not published. `CHARTER.md` §7, `templates/STANDARD.md`, and the README document-control section are unchanged. ISO 9001 7.5.3 / ISO 13485 4.2.5 document-control wording is unchanged.
|
|
11
22
|
|
|
12
23
|
## 0.3.2 - 2026-10-28
|
|
13
24
|
|
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ See also: [CHANGELOG](CHANGELOG.md) · [CONTRIBUTING](CONTRIBUTING.md) · [SECUR
|
|
|
26
26
|
- **Per-client attribution and approvals.** Every write is attributed to the client that made it. A new client is read-limited until it is approved. The approval is recorded.
|
|
27
27
|
- **Error codes and problem reports.** Every error carries a stable `EMET-<AREA>-<NNN>` code. An operational error log keeps 10,000 entries or 90 days, plus daily summaries. The owner-only `emet_error_report` returns the report and an email draft that you send yourself. See [Reporting a problem](#reporting-a-problem).
|
|
28
28
|
- **verify-emet and the feature map.** `npm run verify` runs `scripts/verify-emet.mjs` from a checkout. It starts EMET in a temporary directory on the in-memory test database, with no `.env`, and drives every registered tool. A tool that needs a service a plain install does not have is reported as a gap. A run whose only problems are gaps exits 3. A failed tool exits 1. The map is [docs/features/README.md](docs/features/README.md).
|
|
29
|
-
- **MIT.** Version 0.3.
|
|
29
|
+
- **MIT.** Version 0.3.3. EMET is still 0.x: stored document shapes may change before 1.0. Pin a version if you depend on them.
|
|
30
30
|
|
|
31
31
|
The store has one owner, and other people can join only through the optional Guest
|
|
32
32
|
(read-only) and Member (read and write) access, both off by default.
|
|
@@ -49,8 +49,8 @@ EMET is built for document control in environments that work under ISO 9001 and
|
|
|
49
49
|
- **Setup:** [docs/SETUP.md](docs/SETUP.md) — the manual walkthrough: MongoDB, both transports, and the first-run interview.
|
|
50
50
|
- **Deploy:** [docs/DEPLOY.md](docs/DEPLOY.md) — remote HTTP with OAuth, so a phone, a browser, or another vendor's agent reaches the same store.
|
|
51
51
|
|
|
52
|
-
> **npm lags the repo.** `npx -y @dreamforgestudiollc/emet` installs 0.3.
|
|
53
|
-
> published. For 0.3.
|
|
52
|
+
> **npm lags the repo.** `npx -y @dreamforgestudiollc/emet` installs 0.3.2 until 0.3.3 is
|
|
53
|
+
> published. For 0.3.3, clone this repo and run `npm ci && npm start`, or deploy the
|
|
54
54
|
> repository itself.
|
|
55
55
|
|
|
56
56
|
> **Status: 0.x. The stored document shapes are not frozen yet.** Breaking changes to the
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dreamforgestudiollc/emet",
|
|
3
|
-
"version": "0.3.
|
|
4
|
-
"description": "EMET 0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
|
+
"description": "ISO 9001 7.5.3 / ISO 13485 4.2.5 document-control memory for AI agents. Nothing is deleted. EMET 0.3.3 — 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",
|
package/server.json
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
3
|
"name": "io.github.dreamforgestudiollc/emet",
|
|
4
4
|
"title": "EMET",
|
|
5
|
-
"description": "
|
|
6
|
-
"version": "0.3.
|
|
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.3",
|
|
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.
|
|
25
|
+
"version": "0.3.3",
|
|
26
26
|
"transport": {
|
|
27
27
|
"type": "stdio"
|
|
28
28
|
},
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Carry-forward close.
|
|
3
|
+
*
|
|
4
|
+
* emet_session_close still compares this session's receipts with the store.
|
|
5
|
+
* A later session advances HANDOFF and STATE, so those receipts no longer
|
|
6
|
+
* match, the close stays blocked, and retries used to count toward the
|
|
7
|
+
* three-close cap.
|
|
8
|
+
*
|
|
9
|
+
* A records/ session disposition (templates/SESSIONDISPOSITION.md, #95)
|
|
10
|
+
* documents that fact. The row does not close the graph and it is not a
|
|
11
|
+
* receipt. This path closes the graph only when the owner door, or the
|
|
12
|
+
* credential that wrote the session, cites that current row and the later
|
|
13
|
+
* continuity versions that superseded the receipts. Transcripts stay.
|
|
14
|
+
* A declared source is not authority. A refused call is not a blocked close
|
|
15
|
+
* and is not counted.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { COLLECTION_PREFIX } from './database.js';
|
|
19
|
+
import { actorIsOwner } from './attribution.js';
|
|
20
|
+
import { rawActor, resolveTokenSubject } from './persons.js';
|
|
21
|
+
import {
|
|
22
|
+
parseDispositionRows,
|
|
23
|
+
SESSION_DISPOSITION_TEMPLATE
|
|
24
|
+
} from './conformance.js';
|
|
25
|
+
import { readDispositionCoverage } from './checkpoint.js';
|
|
26
|
+
import { isBotTag, botHandoffDoc, mainRecordIds } from './session-graph.js';
|
|
27
|
+
|
|
28
|
+
export const CARRY_FORWARD_DISPOSITIONS = Object.freeze([
|
|
29
|
+
'CARRIED_FORWARD',
|
|
30
|
+
'SUPERSEDED_BY_LATER_SESSION',
|
|
31
|
+
'ABANDONED_NO_TRANSCRIPT'
|
|
32
|
+
]);
|
|
33
|
+
const CLOSABLE = new Set(CARRY_FORWARD_DISPOSITIONS);
|
|
34
|
+
const PART_SUFFIX = /_(?:verbatim_)?part\d+$/i;
|
|
35
|
+
|
|
36
|
+
export function closeBaseId(sessionId) {
|
|
37
|
+
const id = typeof sessionId === 'string' ? sessionId.trim() : '';
|
|
38
|
+
if (!id) return null;
|
|
39
|
+
return id.replace(PART_SUFFIX, '') || null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function toMillis(value) {
|
|
43
|
+
if (value instanceof Date) {
|
|
44
|
+
const t = value.getTime();
|
|
45
|
+
return Number.isFinite(t) ? t : null;
|
|
46
|
+
}
|
|
47
|
+
if (typeof value === 'number' && Number.isFinite(value)) return value > 1e11 ? value : value * 1000;
|
|
48
|
+
if (typeof value === 'string') {
|
|
49
|
+
const t = Date.parse(value);
|
|
50
|
+
return Number.isFinite(t) ? t : null;
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function hasCarryForward(options) {
|
|
56
|
+
return !!options && Object.prototype.hasOwnProperty.call(options, 'carry_forward') && options.carry_forward != null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function parseCarryForward(value) {
|
|
60
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) return { value, problem: null };
|
|
61
|
+
if (typeof value === 'string' && value.trim().startsWith('{')) {
|
|
62
|
+
try {
|
|
63
|
+
const parsed = JSON.parse(value);
|
|
64
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) return { value: parsed, problem: null };
|
|
65
|
+
} catch { /* text that does not parse is not a citation */ }
|
|
66
|
+
}
|
|
67
|
+
return { value: null, problem: 'carry_forward must be an object with disposition_doc, disposition_version, and citations' };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Owner door, or the credential that wrote the session. A declared source,
|
|
72
|
+
* a guest door, and a source named only on the call are not authority.
|
|
73
|
+
* No HTTP actor is the local stdio owner, the same rule as actorIsOwner.
|
|
74
|
+
*/
|
|
75
|
+
function credentialTag(actor) {
|
|
76
|
+
if (!actor || actor.sourceBasis === 'declared') return null;
|
|
77
|
+
if (actor.sourceBasis === 'subkey' || actor.sourceBasis === 'credential') {
|
|
78
|
+
const tag = typeof actor.effectiveTag === 'string' ? actor.effectiveTag.trim() : '';
|
|
79
|
+
return tag || null;
|
|
80
|
+
}
|
|
81
|
+
if (actor.sourceBasis === 'login') {
|
|
82
|
+
const tag = typeof actor.sourceTag === 'string' ? actor.sourceTag.trim() : '';
|
|
83
|
+
return tag || null;
|
|
84
|
+
}
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function carryForwardAuthority(actor, evidence = {}) {
|
|
89
|
+
const a = actor && typeof actor === 'object' ? actor : null;
|
|
90
|
+
if (!a || a.transport !== 'http') return { ok: true, basis: 'owner' };
|
|
91
|
+
if (a.door === 'guest') {
|
|
92
|
+
return { ok: false, basis: null, reason: 'a guest door cannot carry-forward close a session' };
|
|
93
|
+
}
|
|
94
|
+
if (a.sourceBasis === 'declared') {
|
|
95
|
+
return { ok: false, basis: null, reason: 'a declared source is not authority for a carry-forward close' };
|
|
96
|
+
}
|
|
97
|
+
if (actorIsOwner(a, a.ownerId) && (a.door === 'owner' || a.door == null)) {
|
|
98
|
+
return { ok: true, basis: 'owner' };
|
|
99
|
+
}
|
|
100
|
+
const opened = evidence.openedBy && typeof evidence.openedBy === 'object' ? evidence.openedBy : null;
|
|
101
|
+
if (opened && opened.person_id && a.personId && opened.person_id !== a.personId) {
|
|
102
|
+
return { ok: false, basis: null, reason: 'carry-forward close needs the owner door, or the credential that opened this session' };
|
|
103
|
+
}
|
|
104
|
+
const credTag = credentialTag(a);
|
|
105
|
+
const sameTag = !!credTag && !!evidence.sessionTag && credTag === evidence.sessionTag;
|
|
106
|
+
const sameClient = !!(opened && a.clientId && opened.client_id === a.clientId && a.personId && opened.person_id === a.personId);
|
|
107
|
+
const doorOk = a.door === 'member' || a.door === 'owner' || a.door == null;
|
|
108
|
+
if (doorOk && (sameClient || sameTag)) return { ok: true, basis: 'writer' };
|
|
109
|
+
return { ok: false, basis: null, reason: 'carry-forward close needs the owner door, or the credential that opened this session' };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function writerBase(sessionId) {
|
|
113
|
+
if (typeof sessionId !== 'string' || !sessionId.trim()) return null;
|
|
114
|
+
return sessionId.trim().replace(PART_SUFFIX, '');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function laterWriter(writers, docId, sessionBase) {
|
|
118
|
+
if (!writers || typeof writers.get !== 'function' || !sessionBase) return false;
|
|
119
|
+
const wrote = writerBase(writers.get(docId));
|
|
120
|
+
return !!wrote && wrote !== sessionBase;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* True when every receipt problem is HANDOFF or STATE having moved forward
|
|
125
|
+
* under a later session. A same-session mismatch, a missing receipt, or a
|
|
126
|
+
* working-document mismatch is false: those still count toward the cap.
|
|
127
|
+
* "Handoff was not the last write" counts as this case only together with
|
|
128
|
+
* one of those later-session mismatches.
|
|
129
|
+
*/
|
|
130
|
+
export function supersededStrikeSkipped(problems, { writers, handoffDoc, sessionBase } = {}) {
|
|
131
|
+
if (!Array.isArray(problems) || problems.length === 0 || !sessionBase) return false;
|
|
132
|
+
let sawLater = false;
|
|
133
|
+
for (const problem of problems) {
|
|
134
|
+
const handoff = /^handoff: receipt says v(\d+), store holds v(\d+)$/.exec(problem);
|
|
135
|
+
if (handoff) {
|
|
136
|
+
if (!(Number(handoff[2]) > Number(handoff[1]))) return false;
|
|
137
|
+
if (!laterWriter(writers, handoffDoc, sessionBase)) return false;
|
|
138
|
+
sawLater = true;
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
const board = /^board ([^:]+): receipt says v(\d+), store holds v(\d+)$/.exec(problem);
|
|
142
|
+
if (board) {
|
|
143
|
+
if (!(Number(board[3]) > Number(board[2]))) return false;
|
|
144
|
+
if (!laterWriter(writers, board[1], sessionBase)) return false;
|
|
145
|
+
sawLater = true;
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
if (/^handoff v\d+ was written by session /.test(problem) || /^board .+ was written by session /.test(problem)) {
|
|
149
|
+
sawLater = true;
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
if (/^handoff was not the last write /.test(problem)) continue;
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
return sawLater;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Receipt versions that match the store, written by a different session.
|
|
160
|
+
* Those numbers are the later continuity record, not this session's receipt.
|
|
161
|
+
*/
|
|
162
|
+
export function foreignContinuityProblems({ receipts, writers, handoffDoc, sessionBase, documents } = {}) {
|
|
163
|
+
if (!receipts || !sessionBase) return [];
|
|
164
|
+
const byId = new Map((documents || []).map((d) => [d.doc_id, d]));
|
|
165
|
+
const problems = [];
|
|
166
|
+
const handoff = handoffDoc ? byId.get(handoffDoc) : null;
|
|
167
|
+
if (handoff && handoff.exists && typeof receipts.handoff_version === 'number' && receipts.handoff_version === handoff.version
|
|
168
|
+
&& laterWriter(writers, handoffDoc, sessionBase)) {
|
|
169
|
+
const wrote = writerBase(writers.get(handoffDoc));
|
|
170
|
+
problems.push(`handoff v${handoff.version} was written by session ${wrote}, not ${sessionBase}; cite it with carry_forward`);
|
|
171
|
+
}
|
|
172
|
+
const boardId = typeof receipts.board_doc === 'string' ? receipts.board_doc : null;
|
|
173
|
+
const board = boardId ? byId.get(boardId) : null;
|
|
174
|
+
if (board && board.exists && typeof receipts.board_version === 'number' && receipts.board_version === board.version
|
|
175
|
+
&& laterWriter(writers, boardId, sessionBase)) {
|
|
176
|
+
const wrote = writerBase(writers.get(boardId));
|
|
177
|
+
problems.push(`board ${boardId} v${board.version} was written by session ${wrote}, not ${sessionBase}; cite it with carry_forward`);
|
|
178
|
+
}
|
|
179
|
+
return problems;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function assessCitations(citations, docs, { requiredIds = [], forbiddenIds = [], sessionBase, anchorMs } = {}) {
|
|
183
|
+
const problems = [];
|
|
184
|
+
const byId = docs instanceof Map ? docs : new Map((docs || []).map((d) => [d.doc_id, d]));
|
|
185
|
+
if (!Array.isArray(citations) || citations.length === 0) {
|
|
186
|
+
problems.push('carry_forward.citations must name the later continuity records, each as {doc_id, version}');
|
|
187
|
+
return problems;
|
|
188
|
+
}
|
|
189
|
+
const seen = new Set();
|
|
190
|
+
for (const cite of citations) {
|
|
191
|
+
const id = cite && typeof cite.doc_id === 'string' ? cite.doc_id.trim() : '';
|
|
192
|
+
const version = cite && typeof cite.version === 'number' ? cite.version : null;
|
|
193
|
+
if (!id || !Number.isInteger(version)) {
|
|
194
|
+
problems.push('each citation needs a doc_id and an integer version');
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (forbiddenIds.includes(id)) {
|
|
198
|
+
problems.push(`citation ${id} is a main record this bot session does not cite`);
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
seen.add(id);
|
|
202
|
+
const doc = byId.get(id);
|
|
203
|
+
if (!doc || doc.exists === false) {
|
|
204
|
+
problems.push(`citation ${id} is not in the store`);
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
if (doc.version !== version) { // citation-version
|
|
208
|
+
problems.push(`citation ${id} says v${version}; the version in force is v${doc.version}`);
|
|
209
|
+
}
|
|
210
|
+
const wrote = writerBase(doc.session_id);
|
|
211
|
+
if (wrote && sessionBase && wrote === sessionBase) {
|
|
212
|
+
problems.push(`citation ${id} v${version} was written in this session; use a normal receipt close`);
|
|
213
|
+
}
|
|
214
|
+
const ms = toMillis(doc.updated_at);
|
|
215
|
+
if (anchorMs == null || ms == null || ms <= anchorMs) { // citation-later
|
|
216
|
+
problems.push(`citation ${id} v${version} is not later than this session`);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
for (const id of requiredIds) {
|
|
220
|
+
if (!seen.has(id)) problems.push(`citation missing: ${id}`);
|
|
221
|
+
}
|
|
222
|
+
return problems;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function refused(problems, extra = {}) {
|
|
226
|
+
return {
|
|
227
|
+
state: 'refused',
|
|
228
|
+
speak: [
|
|
229
|
+
'Carry-forward close: refused',
|
|
230
|
+
...problems.map((p) => p),
|
|
231
|
+
'Transcript: retained',
|
|
232
|
+
'Close state: refused'
|
|
233
|
+
],
|
|
234
|
+
missing: problems,
|
|
235
|
+
warnings: [],
|
|
236
|
+
carry_forward: { closed: false, transcripts_deleted: false, ...extra },
|
|
237
|
+
close_attempts: { counted: false, escalated: false },
|
|
238
|
+
instructions:
|
|
239
|
+
'The session is NOT saved. The session graph stays open, and no transcript was deleted. ' +
|
|
240
|
+
'This refusal is not a blocked close and is not counted. ' +
|
|
241
|
+
'Cite the current records/ disposition and the later HANDOFF and STATE versions, ' +
|
|
242
|
+
'or use a normal receipt close when this session\'s receipts still match the store.'
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function anchorMillis(session, rows) {
|
|
247
|
+
const opened = toMillis(session && session.opened_at);
|
|
248
|
+
if (opened != null) return opened;
|
|
249
|
+
let max = null;
|
|
250
|
+
for (const doc of rows || []) {
|
|
251
|
+
const end = toMillis(doc && doc.session_end);
|
|
252
|
+
if (end != null && (max == null || end > max)) max = end;
|
|
253
|
+
for (const ex of (doc && doc.exchanges) || []) {
|
|
254
|
+
const t = toMillis(ex && ex.timestamp);
|
|
255
|
+
if (t != null && (max == null || t > max)) max = t;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return max;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export async function runCarryForwardClose(db, options = {}) {
|
|
262
|
+
const parsed = parseCarryForward(options.carry_forward);
|
|
263
|
+
if (parsed.problem) return refused([parsed.problem]);
|
|
264
|
+
const spec = parsed.value;
|
|
265
|
+
const requested = typeof options.session_id === 'string' ? options.session_id.trim() : '';
|
|
266
|
+
const base = closeBaseId(requested);
|
|
267
|
+
if (!base) return refused(['carry_forward requires session_id of the open session to close']);
|
|
268
|
+
|
|
269
|
+
const sessions = db.collection(`${COLLECTION_PREFIX}sessions`);
|
|
270
|
+
const session = await sessions.findOne({ _id: base });
|
|
271
|
+
if (!session || session.opened !== true) {
|
|
272
|
+
return refused([`session ${base} has no open session row`], { session_id: base });
|
|
273
|
+
}
|
|
274
|
+
if (session.closed === true) {
|
|
275
|
+
return refused([`session ${base} is already closed`], { session_id: base });
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const loaded = await (async () => {
|
|
279
|
+
const { sessionTagOf } = await import('./session.js');
|
|
280
|
+
const pattern = `^${String(base).replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}(_.*)?$`;
|
|
281
|
+
const rows = await db.collection('transcripts').find({ session_id: { $regex: pattern } }).toArray();
|
|
282
|
+
return { rows, tag: sessionTagOf(rows).tag };
|
|
283
|
+
})();
|
|
284
|
+
|
|
285
|
+
const actor = rawActor();
|
|
286
|
+
let ownerId = actor && actor.ownerId;
|
|
287
|
+
if (actor && actor.transport === 'http' && !ownerId) {
|
|
288
|
+
try { ownerId = await resolveTokenSubject(db); } catch { ownerId = null; }
|
|
289
|
+
}
|
|
290
|
+
const auth = carryForwardAuthority(actor ? { ...actor, ownerId: ownerId || actor.ownerId } : null, {
|
|
291
|
+
sessionTag: loaded.tag,
|
|
292
|
+
openedBy: session.opened_by || null
|
|
293
|
+
});
|
|
294
|
+
if (!auth.ok) return refused([auth.reason], { session_id: base });
|
|
295
|
+
|
|
296
|
+
const docId = typeof spec.disposition_doc === 'string' ? spec.disposition_doc.trim() : '';
|
|
297
|
+
const dispositionVersion = typeof spec.disposition_version === 'number' ? spec.disposition_version : null;
|
|
298
|
+
if (!docId || !docId.startsWith('records/') || !Number.isInteger(dispositionVersion)) {
|
|
299
|
+
return refused(['carry_forward.disposition_doc must be a records/ id and disposition_version its integer version in force'], { session_id: base });
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const covered = await readDispositionCoverage(db);
|
|
303
|
+
const exact = covered.get(requested) || covered.get(base);
|
|
304
|
+
if (!exact) {
|
|
305
|
+
const named = await db.collection('documents').findOne(
|
|
306
|
+
{ doc_id: docId },
|
|
307
|
+
{ projection: { content: 1, conformance: 1, retired: 1 } }
|
|
308
|
+
);
|
|
309
|
+
const rows = named ? parseDispositionRows(named.content) : [];
|
|
310
|
+
const transcriptOnly = rows.some((row) => (row.session_id === base || row.session_id === requested) && row.inserted_id);
|
|
311
|
+
const problems = transcriptOnly
|
|
312
|
+
? [`${docId} dispositions a transcript inserted_id only. That row does not close ${base}`]
|
|
313
|
+
: [`no current conforming session-level disposition covers ${base}`];
|
|
314
|
+
if (named && named.retired === true) problems.push(`${docId} is retired`);
|
|
315
|
+
if (named && named.conformance && named.conformance.template && named.conformance.template !== SESSION_DISPOSITION_TEMPLATE) {
|
|
316
|
+
problems.push(`${docId} is not a ${SESSION_DISPOSITION_TEMPLATE} record`);
|
|
317
|
+
}
|
|
318
|
+
return refused(problems, { session_id: base });
|
|
319
|
+
}
|
|
320
|
+
if (exact.doc_id !== docId || exact.version !== dispositionVersion) { // disposition-in-force
|
|
321
|
+
return refused([
|
|
322
|
+
`the disposition in force for ${base} is ${exact.doc_id} v${exact.version} (${exact.disposition}), not ${docId} v${dispositionVersion}`
|
|
323
|
+
], { session_id: base });
|
|
324
|
+
}
|
|
325
|
+
if (!CLOSABLE.has(exact.disposition)) { // closable-disposition
|
|
326
|
+
const why = exact.disposition === 'RETAINED_OPEN_CRITICAL'
|
|
327
|
+
? `${base} is RETAINED_OPEN_CRITICAL. That row keeps the session open.`
|
|
328
|
+
: `${base} is ${exact.disposition}. carry_forward closes only ${CARRY_FORWARD_DISPOSITIONS.join(', ')}. Use a normal receipt close for CLOSED_NORMAL.`;
|
|
329
|
+
return refused([why], { session_id: base, disposition: exact.disposition });
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const mains = mainRecordIds();
|
|
333
|
+
const bot = loaded.tag && isBotTag(loaded.tag);
|
|
334
|
+
const requiredIds = bot ? [botHandoffDoc(loaded.tag)] : mains;
|
|
335
|
+
const forbiddenIds = bot ? mains : [];
|
|
336
|
+
const citeIds = new Set(requiredIds);
|
|
337
|
+
for (const cite of Array.isArray(spec.citations) ? spec.citations : []) {
|
|
338
|
+
if (cite && typeof cite.doc_id === 'string' && cite.doc_id.trim()) citeIds.add(cite.doc_id.trim());
|
|
339
|
+
}
|
|
340
|
+
const found = new Map();
|
|
341
|
+
for (const id of citeIds) {
|
|
342
|
+
const row = await db.collection('documents').findOne(
|
|
343
|
+
{ doc_id: id },
|
|
344
|
+
{ projection: { doc_id: 1, version: 1, updated_at: 1, session_id: 1, retired: 1 } }
|
|
345
|
+
);
|
|
346
|
+
found.set(id, row && row.retired !== true
|
|
347
|
+
? { doc_id: id, exists: true, version: row.version, updated_at: row.updated_at, session_id: row.session_id || null }
|
|
348
|
+
: { doc_id: id, exists: false });
|
|
349
|
+
}
|
|
350
|
+
const anchorMs = anchorMillis(session, loaded.rows);
|
|
351
|
+
const citeProblems = assessCitations(spec.citations, found, {
|
|
352
|
+
requiredIds, forbiddenIds, sessionBase: base, anchorMs
|
|
353
|
+
});
|
|
354
|
+
if (citeProblems.length) return refused(citeProblems, { session_id: base, disposition: exact.disposition });
|
|
355
|
+
|
|
356
|
+
const citations = (spec.citations || []).map((cite) => ({ doc_id: cite.doc_id.trim(), version: cite.version }));
|
|
357
|
+
const citedText = citations.map((c) => `${c.doc_id} v${c.version}`).join(', ');
|
|
358
|
+
return {
|
|
359
|
+
state: 'complete',
|
|
360
|
+
speak: [
|
|
361
|
+
`Carry-forward close: ${base}`,
|
|
362
|
+
`Authority: ${auth.basis}`,
|
|
363
|
+
`Disposition: ${exact.doc_id} v${exact.version} ${exact.disposition}`,
|
|
364
|
+
`Later continuity: ${citedText}`,
|
|
365
|
+
'Transcript: retained',
|
|
366
|
+
'Close state: complete'
|
|
367
|
+
],
|
|
368
|
+
missing: [],
|
|
369
|
+
warnings: [],
|
|
370
|
+
carry_forward: {
|
|
371
|
+
closed: true,
|
|
372
|
+
authority: auth.basis,
|
|
373
|
+
disposition_doc: exact.doc_id,
|
|
374
|
+
disposition_version: exact.version,
|
|
375
|
+
disposition: exact.disposition,
|
|
376
|
+
citations,
|
|
377
|
+
transcripts_deleted: false,
|
|
378
|
+
session_id: base
|
|
379
|
+
},
|
|
380
|
+
close_attempts: { counted: false, escalated: false },
|
|
381
|
+
instructions:
|
|
382
|
+
'Say every line of `speak` to the user, in order. ' +
|
|
383
|
+
'This session is closed by carry-forward. The disposition and the later continuity versions were cited. ' +
|
|
384
|
+
'The transcript was kept. This is not a receipt close. After `speak`, tell the user the session is saved, in one line.'
|
|
385
|
+
};
|
|
386
|
+
}
|
package/src/owner-session.js
CHANGED
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import crypto from 'node:crypto';
|
|
10
|
+
import fs from 'node:fs';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
10
13
|
import express from 'express';
|
|
11
14
|
|
|
12
15
|
export const SESSION_MS = 15 * 60 * 1000;
|
|
@@ -14,6 +17,27 @@ export const COOKIE_NAME = 'emet_owner';
|
|
|
14
17
|
const SESSION_MAX = 200;
|
|
15
18
|
const NEXT_OK = new Set(['/owner/chooser', '/owner/break-glass']);
|
|
16
19
|
|
|
20
|
+
/** Full-resolution README hero. The README tag uses the 560px derivative of this file. */
|
|
21
|
+
export const OWNER_GRAPHIC_PATH = '/owner/assets/portrait.webp';
|
|
22
|
+
const OWNER_GRAPHIC_FILE = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'site', 'assets', 'portrait.webp');
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The deploy image copies this file. The npm package does not.
|
|
26
|
+
* A missing file leaves the page without a portrait. It does not stop startup.
|
|
27
|
+
*/
|
|
28
|
+
function readOwnerGraphic() {
|
|
29
|
+
try {
|
|
30
|
+
return fs.readFileSync(OWNER_GRAPHIC_FILE);
|
|
31
|
+
} catch (err) {
|
|
32
|
+
if (err && err.code === 'ENOENT') return null;
|
|
33
|
+
throw err;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const OWNER_GRAPHIC_BYTES = readOwnerGraphic();
|
|
38
|
+
|
|
39
|
+
export const OWNER_PAGE_CSP = "default-src 'none'; img-src 'self'; style-src 'unsafe-inline'; form-action 'self'; base-uri 'none'; frame-ancestors 'none'";
|
|
40
|
+
|
|
17
41
|
export function esc(s) {
|
|
18
42
|
return String(s ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
19
43
|
}
|
|
@@ -30,6 +54,16 @@ export function readCookie(req, name) {
|
|
|
30
54
|
return null;
|
|
31
55
|
}
|
|
32
56
|
|
|
57
|
+
/**
|
|
58
|
+
* The portrait is the page background. The sheet is a scrim: 0.86 of #12141a
|
|
59
|
+
* still clears WCAG AA for the text colors below when a pixel of the portrait
|
|
60
|
+
* is white. Text fields and buttons use an opaque light face.
|
|
61
|
+
*/
|
|
62
|
+
function bodyBackground() {
|
|
63
|
+
if (!OWNER_GRAPHIC_BYTES) return 'background-color: #12141a;';
|
|
64
|
+
return `background-color: #12141a; background-image: url("${OWNER_GRAPHIC_PATH}"); background-repeat: no-repeat; background-position: center; background-size: cover;`;
|
|
65
|
+
}
|
|
66
|
+
|
|
33
67
|
export function htmlPage(title, body) {
|
|
34
68
|
return `<!DOCTYPE html>
|
|
35
69
|
<html lang="en">
|
|
@@ -38,10 +72,13 @@ export function htmlPage(title, body) {
|
|
|
38
72
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
39
73
|
<title>${esc(title)}</title>
|
|
40
74
|
<style>
|
|
41
|
-
body { font-family: system-ui, sans-serif;
|
|
75
|
+
body { font-family: system-ui, sans-serif; color: #e8e6e0; margin: 0; min-height: 100vh; line-height: 1.45; ${bodyBackground()} }
|
|
76
|
+
.sheet { box-sizing: border-box; max-width: 52rem; margin: 24px; padding: 20px 22px; background: rgba(18, 20, 26, 0.86); border-radius: 12px; }
|
|
42
77
|
a { color: #8eb4d6; }
|
|
43
78
|
button, input, select { font: inherit; }
|
|
79
|
+
button, input[type="text"], input[type="password"], select { color: #12141a; background-color: #f4f5f7; border: 1px solid #3d4450; padding: 4px 8px; }
|
|
44
80
|
button { margin-right: 8px; }
|
|
81
|
+
input::placeholder { color: #3d4450; }
|
|
45
82
|
table { border-collapse: collapse; }
|
|
46
83
|
td, th { text-align: left; padding: 4px 10px 4px 0; vertical-align: top; }
|
|
47
84
|
code { color: #d9c27a; }
|
|
@@ -49,7 +86,9 @@ export function htmlPage(title, body) {
|
|
|
49
86
|
</style>
|
|
50
87
|
</head>
|
|
51
88
|
<body>
|
|
89
|
+
<div class="sheet">
|
|
52
90
|
${body}
|
|
91
|
+
</div>
|
|
53
92
|
</body>
|
|
54
93
|
</html>`;
|
|
55
94
|
}
|
|
@@ -58,7 +97,7 @@ export function sendHtml(res, status, body, title = 'EMET') {
|
|
|
58
97
|
res.status(status);
|
|
59
98
|
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
60
99
|
res.setHeader('Cache-Control', 'no-store');
|
|
61
|
-
res.setHeader('Content-Security-Policy',
|
|
100
|
+
res.setHeader('Content-Security-Policy', OWNER_PAGE_CSP);
|
|
62
101
|
res.send(htmlPage(title, body));
|
|
63
102
|
}
|
|
64
103
|
|
|
@@ -156,7 +195,29 @@ export function createOwnerGate({ checkPassphrase, throttle, now = Date.now } =
|
|
|
156
195
|
return { sessionOf, login, now, endOtherSessions };
|
|
157
196
|
}
|
|
158
197
|
|
|
198
|
+
export function mountOwnerGraphic(app) {
|
|
199
|
+
if (!app || app.get('emetOwnerGraphic')) return;
|
|
200
|
+
app.set('emetOwnerGraphic', true);
|
|
201
|
+
app.get(OWNER_GRAPHIC_PATH, (_req, res) => {
|
|
202
|
+
if (!OWNER_GRAPHIC_BYTES) {
|
|
203
|
+
res.status(404);
|
|
204
|
+
res.setHeader('Content-Type', 'text/plain; charset=utf-8');
|
|
205
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
206
|
+
res.setHeader('X-Content-Type-Options', 'nosniff');
|
|
207
|
+
res.end('Not found');
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
res.status(200);
|
|
211
|
+
res.setHeader('Content-Type', 'image/webp');
|
|
212
|
+
res.setHeader('Content-Length', String(OWNER_GRAPHIC_BYTES.length));
|
|
213
|
+
res.setHeader('Cache-Control', 'public, max-age=86400');
|
|
214
|
+
res.setHeader('X-Content-Type-Options', 'nosniff');
|
|
215
|
+
res.end(OWNER_GRAPHIC_BYTES);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
159
219
|
export function mountOwnerLogin(app, gate) {
|
|
220
|
+
mountOwnerGraphic(app);
|
|
160
221
|
if (app.get('emetOwnerLogin')) return;
|
|
161
222
|
app.set('emetOwnerLogin', true);
|
|
162
223
|
app.post('/owner/login', express.urlencoded({ extended: false }), (req, res) => gate.login(req, res));
|
package/src/session.js
CHANGED
|
@@ -38,6 +38,7 @@ import { LAYERS } from './layers.js';
|
|
|
38
38
|
import { parseMetadata } from './metadata.js';
|
|
39
39
|
import { applyCloseCap, scopeFor, escalateSpeak, CLOSE_CAP } from './lessons-to-checks.js';
|
|
40
40
|
import { isBotTag, botHandoffDoc, botRecordDir, mainRecordIds, echoId } from './session-graph.js';
|
|
41
|
+
import { hasCarryForward, runCarryForwardClose, supersededStrikeSkipped, foreignContinuityProblems } from './carry-forward-close.js';
|
|
41
42
|
|
|
42
43
|
const DOCS_COLLECTION = 'documents';
|
|
43
44
|
const TRANSCRIPTS_COLLECTION = 'transcripts';
|
|
@@ -700,6 +701,7 @@ export async function sessionClose(options = {}) {
|
|
|
700
701
|
try {
|
|
701
702
|
const conn = await connect();
|
|
702
703
|
client = conn.client;
|
|
704
|
+
if (hasCarryForward(options)) return await runCarryForwardClose(conn.db, options);
|
|
703
705
|
// Baselines are bookkeeping on the document row, not a new revision.
|
|
704
706
|
// A writeDoc here would archive a revision that changed nothing the user wrote.
|
|
705
707
|
const cutoff = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000);
|
|
@@ -783,7 +785,7 @@ export async function sessionClose(options = {}) {
|
|
|
783
785
|
const readDoc = async (docId) => {
|
|
784
786
|
const found = await docs.findOne(
|
|
785
787
|
{ doc_id: docId },
|
|
786
|
-
{ projection: { doc_id: 1, version: 1, updated_at: 1, updated_by: 1, size: 1 } }
|
|
788
|
+
{ projection: { doc_id: 1, version: 1, updated_at: 1, updated_by: 1, size: 1, session_id: 1 } }
|
|
787
789
|
);
|
|
788
790
|
const updatedMs = found ? toMillis(found.updated_at) : null;
|
|
789
791
|
return {
|
|
@@ -792,13 +794,17 @@ export async function sessionClose(options = {}) {
|
|
|
792
794
|
version: found ? found.version : null,
|
|
793
795
|
updated_at: found && found.updated_at ? new Date(updatedMs).toISOString() : null,
|
|
794
796
|
updated_by: found ? found.updated_by || null : null,
|
|
797
|
+
session_id: found && typeof found.session_id === 'string' ? found.session_id : null,
|
|
795
798
|
in_window: updatedMs !== null && updatedMs >= startMs
|
|
796
799
|
};
|
|
797
800
|
};
|
|
798
801
|
const documents = [];
|
|
802
|
+
const continuityWriters = new Map();
|
|
799
803
|
const attributionWarnings = [];
|
|
800
804
|
for (const docId of wanted) {
|
|
801
|
-
const
|
|
805
|
+
const read = await readDoc(docId);
|
|
806
|
+
continuityWriters.set(docId, read.session_id);
|
|
807
|
+
const { in_window, session_id: _writerSession, ...d } = read;
|
|
802
808
|
if (bot) {
|
|
803
809
|
// Revised this session = in the window AND by this session's tag.
|
|
804
810
|
documents.push({ ...d, updated_this_session: in_window && d.updated_by === bot.tag, updated_in_window: in_window });
|
|
@@ -817,7 +823,8 @@ export async function sessionClose(options = {}) {
|
|
|
817
823
|
const mainRecords = [];
|
|
818
824
|
if (bot) {
|
|
819
825
|
for (const docId of bot.main_records) {
|
|
820
|
-
const
|
|
826
|
+
const read = await readDoc(docId);
|
|
827
|
+
const { in_window, session_id: _writerSession, ...d } = read;
|
|
821
828
|
mainRecords.push({ ...d, revised_by_session_tag: in_window && d.updated_by === bot.tag });
|
|
822
829
|
}
|
|
823
830
|
}
|
|
@@ -981,6 +988,17 @@ export async function sessionClose(options = {}) {
|
|
|
981
988
|
...(bot ? { bot } : {})
|
|
982
989
|
});
|
|
983
990
|
for (const p of receiptCheck.problems) missing.push(p);
|
|
991
|
+
const foreign = foreignContinuityProblems({
|
|
992
|
+
receipts,
|
|
993
|
+
writers: continuityWriters,
|
|
994
|
+
handoffDoc: sessionHandoff,
|
|
995
|
+
sessionBase: transcript && transcript.base_session_id ? transcript.base_session_id : null,
|
|
996
|
+
documents
|
|
997
|
+
});
|
|
998
|
+
for (const p of foreign) {
|
|
999
|
+
receiptCheck.problems.push(p);
|
|
1000
|
+
missing.push(p);
|
|
1001
|
+
}
|
|
984
1002
|
if (uncorroborated) {
|
|
985
1003
|
missing.push(
|
|
986
1004
|
'transcript coverage is uncorroborated - no layer entry written this session cites the transcript. ' +
|
|
@@ -1003,9 +1021,19 @@ export async function sessionClose(options = {}) {
|
|
|
1003
1021
|
const row = await attempts.findOne({ base_session_id: baseId }, { projection: { blocked_count: 1 } });
|
|
1004
1022
|
priorBlocked = row && typeof row.blocked_count === 'number' ? row.blocked_count : 0;
|
|
1005
1023
|
}
|
|
1006
|
-
const
|
|
1024
|
+
const strikeSkipped = computed === 'blocked' && supersededStrikeSkipped(receiptCheck.problems, {
|
|
1025
|
+
writers: continuityWriters,
|
|
1026
|
+
handoffDoc: sessionHandoff,
|
|
1027
|
+
sessionBase: baseId
|
|
1028
|
+
});
|
|
1029
|
+
// A later session advanced HANDOFF or STATE. The receipt close stays
|
|
1030
|
+
// blocked. It does not count, and it does not escalate, including when
|
|
1031
|
+
// an earlier retry of this same mismatch already filled the cap.
|
|
1032
|
+
const capped = strikeSkipped
|
|
1033
|
+
? { state: 'blocked', blocked_count: priorBlocked, escalated: false, strike_skipped: true }
|
|
1034
|
+
: applyCloseCap(computed, priorBlocked);
|
|
1007
1035
|
const state = capped.state;
|
|
1008
|
-
if (baseId && computed === 'blocked' && capped.blocked_count !== priorBlocked) {
|
|
1036
|
+
if (baseId && computed === 'blocked' && !strikeSkipped && capped.blocked_count !== priorBlocked) {
|
|
1009
1037
|
await attempts.updateOne(
|
|
1010
1038
|
{ base_session_id: baseId },
|
|
1011
1039
|
{ $set: { blocked_count: capped.blocked_count, last_state: state, updated_at: new Date() },
|
|
@@ -1027,11 +1055,21 @@ export async function sessionClose(options = {}) {
|
|
|
1027
1055
|
});
|
|
1028
1056
|
|
|
1029
1057
|
if (state === 'escalate') speak.push(...escalateSpeak(missing));
|
|
1058
|
+
if (strikeSkipped) {
|
|
1059
|
+
const note = 'HANDOFF or STATE was written by a later session, so this receipt close stays blocked and is not counted. Close with carry_forward. Do not retry this receipt close.';
|
|
1060
|
+
warnings.push(note);
|
|
1061
|
+
speak.push(note);
|
|
1062
|
+
}
|
|
1030
1063
|
|
|
1031
1064
|
return {
|
|
1032
1065
|
state,
|
|
1033
1066
|
speak,
|
|
1034
|
-
close_attempts: {
|
|
1067
|
+
close_attempts: {
|
|
1068
|
+
blocked_count: capped.blocked_count,
|
|
1069
|
+
cap: CLOSE_CAP,
|
|
1070
|
+
escalated: state === 'escalate',
|
|
1071
|
+
...(strikeSkipped ? { strike_skipped: true, counted: false } : {})
|
|
1072
|
+
},
|
|
1035
1073
|
scope: scoped,
|
|
1036
1074
|
window,
|
|
1037
1075
|
checked: {
|
|
@@ -1075,6 +1113,11 @@ export async function sessionClose(options = {}) {
|
|
|
1075
1113
|
'Say the `speak` lines, including the list, and wait for the user\'s word. The counter does not reset ' +
|
|
1076
1114
|
'on a changed receipt; a close that would be complete is still accepted if the user directs the fix. ' +
|
|
1077
1115
|
'Each line of `missing` has a `scope` in `scope`: touch only what it names.'
|
|
1116
|
+
: strikeSkipped
|
|
1117
|
+
? 'The session is NOT saved. HANDOFF or STATE moved because a later session wrote them, so these receipts cannot match. ' +
|
|
1118
|
+
'This blocked close was not counted, and it does not escalate. Do not retry this receipt close. ' +
|
|
1119
|
+
'Close with carry_forward: the owner door, or the credential that wrote this session, cites the current records/ disposition and the later HANDOFF and STATE versions. ' +
|
|
1120
|
+
'Transcripts stay. A declared source is not authority.'
|
|
1078
1121
|
: state === 'blocked'
|
|
1079
1122
|
? 'The session is NOT saved. The store holds the artifacts, but the close is BLOCKED: a receipt is ' +
|
|
1080
1123
|
'missing or disagrees with the store, the handoff was not the last write, or the transcript is not ' +
|
package/src/tools.js
CHANGED
|
@@ -4600,7 +4600,7 @@ const TOOL_DEFINITIONS = [
|
|
|
4600
4600
|
},
|
|
4601
4601
|
{
|
|
4602
4602
|
name: "emet_session_close",
|
|
4603
|
-
description: "Call this when the session is ending - the user says goodbye, asks you to wrap up, mentions restarting or opening a new session, or you are about to run out of room. An acknowledgement of the turn just completed - thanks, great, perfect - is not a session end; if it is ambiguous, ask rather than close. Checks whether this session's work has actually been written to the store and reports exactly what is missing. It does not write anything itself. RECEIPTS ARE REQUIRED: pass `receipts` naming what you wrote and read back for each close step - working documents, the episodic session record id, the board and its version, the transcript part ids and highest exchange index as query_transcripts returned them, and the handoff version (written last). Each receipt is compared with the store; omitted or mismatched receipts, a handoff that was not the last write, or a transcript no layer entry cites (derived_from) return state 'blocked'. Each missing line carries a `scope`: touch only what it names. THREE blocked closes on one session return state 'escalate': stop retrying, say the `speak` lines, and hand the user the list - the counter does not reset on a changed receipt, only with a new session. Say every line of the returned `speak` to the user, in order - a wrap that leaves it out is a failed close. A records/ session disposition is not a receipt and does not make this call complete. Never tell the user their session is saved unless this returns state 'complete'.",
|
|
4603
|
+
description: "Call this when the session is ending - the user says goodbye, asks you to wrap up, mentions restarting or opening a new session, or you are about to run out of room. An acknowledgement of the turn just completed - thanks, great, perfect - is not a session end; if it is ambiguous, ask rather than close. Checks whether this session's work has actually been written to the store and reports exactly what is missing. It does not write anything itself. RECEIPTS ARE REQUIRED: pass `receipts` naming what you wrote and read back for each close step - working documents, the episodic session record id, the board and its version, the transcript part ids and highest exchange index as query_transcripts returned them, and the handoff version (written last). Each receipt is compared with the store; omitted or mismatched receipts, a handoff that was not the last write, or a transcript no layer entry cites (derived_from) return state 'blocked'. Each missing line carries a `scope`: touch only what it names. THREE blocked closes on one session return state 'escalate': stop retrying, say the `speak` lines, and hand the user the list - the counter does not reset on a changed receipt, only with a new session. Say every line of the returned `speak` to the user, in order - a wrap that leaves it out is a failed close. A records/ session disposition is not a receipt and does not make this call complete. Pass carry_forward only for an old open session whose HANDOFF and STATE a later session already advanced. The owner door, or the credential that wrote the session, cites the current conforming records/ disposition (CARRIED_FORWARD, SUPERSEDED_BY_LATER_SESSION, or ABANDONED_NO_TRANSCRIPT) and those later versions. RETAINED_OPEN_CRITICAL stays open. A declared source is not authority. Transcripts are not deleted. A refused carry_forward is not counted. A receipt close blocked only because a later session holds HANDOFF or STATE stays blocked and is not counted. A same-session close is unchanged. Never tell the user their session is saved unless this returns state 'complete'.",
|
|
4604
4604
|
inputSchema: {
|
|
4605
4605
|
type: "object",
|
|
4606
4606
|
properties: {
|
|
@@ -4622,7 +4622,26 @@ const TOOL_DEFINITIONS = [
|
|
|
4622
4622
|
session_id: { type: "string", description: "The session_id used (or to be used) for this session's transcript, e.g. '2026-09-03_short-description'. Without it the transcript cannot be checked; receipts.transcript_session_id is used when this is omitted." },
|
|
4623
4623
|
session_start: { type: "number", description: "Unix seconds when the session began. Defaults to 12 hours ago, which makes the answer approximate." },
|
|
4624
4624
|
thread_docs: { type: "array", items: { type: "string" }, description: "Additional document ids this session should have updated, e.g. ['threads/some-project.md']." },
|
|
4625
|
-
source: { type: "string", description: "Your host's source tag: the registered tag this session was written under. The close is never refused for it; an unregistered tag, one that did not write this session, or none (with no server default) gets a warning that the close is not attributed." }
|
|
4625
|
+
source: { type: "string", description: "Your host's source tag: the registered tag this session was written under. The close is never refused for it; an unregistered tag, one that did not write this session, or none (with no server default) gets a warning that the close is not attributed." },
|
|
4626
|
+
carry_forward: {
|
|
4627
|
+
type: "object",
|
|
4628
|
+
description: "Disposition-backed close for an old open session. Omit it for a normal receipt close. Not a receipt, and not authority by itself.",
|
|
4629
|
+
properties: {
|
|
4630
|
+
disposition_doc: { type: "string", description: "records/ document id of the current conforming session disposition." },
|
|
4631
|
+
disposition_version: { type: "number", description: "Version of that document now in force." },
|
|
4632
|
+
citations: {
|
|
4633
|
+
type: "array",
|
|
4634
|
+
description: "Later continuity records that superseded this session's receipts. A host session cites the current HANDOFF and STATE versions. A bot session cites its own handoff.",
|
|
4635
|
+
items: {
|
|
4636
|
+
type: "object",
|
|
4637
|
+
properties: {
|
|
4638
|
+
doc_id: { type: "string" },
|
|
4639
|
+
version: { type: "number" }
|
|
4640
|
+
}
|
|
4641
|
+
}
|
|
4642
|
+
}
|
|
4643
|
+
}
|
|
4644
|
+
}
|
|
4626
4645
|
}
|
|
4627
4646
|
}
|
|
4628
4647
|
}
|
package/src/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** The server's version, in one place. tests/version.test.js keeps it equal to package.json. */
|
|
2
|
-
export const EMET_VERSION = '0.3.
|
|
2
|
+
export const EMET_VERSION = '0.3.3';
|