@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.
- package/.env.example +29 -0
- package/CHANGELOG.md +49 -11
- package/CHARTER.md +1 -1
- package/CONTRIBUTING.md +21 -0
- package/README.md +25 -10
- package/RELEASE_NOTES-0.2.6.md +43 -0
- package/RELEASE_NOTES-0.3.6.md +29 -0
- package/RELEASE_NOTES-0.3.7.md +19 -0
- package/SECURITY.md +13 -0
- package/docs/BOTS.md +4 -4
- package/docs/DEPLOY.md +23 -4
- package/docs/ERROR-CODES-SPEC.md +4 -0
- package/docs/ERROR-CODES.md +7 -0
- package/docs/GUIDED-SETUP.md +1 -1
- package/docs/ROADMAP.md +62 -49
- package/docs/SETUP.md +11 -1
- package/docs/SUBKEYS.md +3 -1
- package/docs/continuity-currency-statechart.md +34 -0
- package/docs/features/README.md +21 -0
- package/docs/features/access.md +28 -0
- package/docs/features/documents.md +35 -0
- package/docs/features/errors.md +32 -0
- package/docs/features/gems.md +31 -0
- package/docs/features/memory.md +29 -0
- package/docs/features/pages.md +28 -0
- package/docs/features/record.md +27 -0
- package/docs/features/search.md +27 -0
- package/docs/features/startup.md +29 -0
- package/docs/features/subkeys.md +30 -0
- package/docs/features/transcripts.md +33 -0
- package/docs/per-tag-handoff-statechart.md +147 -0
- package/docs/subkey-session-statechart.md +57 -0
- package/package.json +6 -2
- package/server.json +27 -2
- package/src/annotations.js +5 -3
- package/src/attribution.js +2 -2
- package/src/carry-forward-close.js +1 -1
- package/src/chooser.js +74 -3
- package/src/conformance.js +2 -0
- package/src/continuity-currency-statechart.js +139 -0
- package/src/continuity-currency.js +869 -0
- package/src/database.js +1 -1
- package/src/dispatch.js +1 -1
- package/src/error-codes.js +7 -0
- package/src/gem-check.js +4 -1
- package/src/grants.js +28 -5
- package/src/host-reach.js +1 -1
- package/src/http-remote.js +29 -5
- package/src/index.js +3 -2
- package/src/invites.js +2 -2
- package/src/owl.js +12 -11
- package/src/pages.js +15 -0
- package/src/per-tag-handoff-statechart.js +264 -0
- package/src/per-tag-handoff.js +988 -0
- package/src/persons.js +16 -0
- package/src/session-graph.js +123 -12
- package/src/session.js +56 -12
- package/src/setup.js +32 -11
- package/src/startup-pages.js +13 -2
- package/src/subkey-lifecycle.js +105 -0
- package/src/subkey-session-statechart.js +253 -0
- package/src/subkeys.js +648 -89
- package/src/tools.js +171 -51
- package/src/transcript-session.js +2 -2
- package/src/version.js +1 -1
- package/templates/INDEX.md +1 -0
- package/templates/SESSIONDISPOSITION.md +2 -2
- package/templates/TAGHANDOFF.md +45 -0
- package/verification/continuity-currency/ContinuityCurrency.cfg +12 -0
- package/verification/continuity-currency/ContinuityCurrency.tla +239 -0
- package/verification/continuity-currency/tlc-output.txt +32 -0
- package/verification/continuity-currency/view.mjs +54 -0
- package/verification/load-gate/load-gate.mjs +1 -1
- package/verification/per-tag-handoff/PerTagHandoff.cfg +10 -0
- package/verification/per-tag-handoff/PerTagHandoff.tla +191 -0
- package/verification/per-tag-handoff/StampCounter.cfg +10 -0
- package/verification/per-tag-handoff/out/report.md +6 -0
- package/verification/per-tag-handoff/out-counter/chart.mmd +30 -0
- package/verification/per-tag-handoff/out-counter/report.md +15 -0
- package/verification/per-tag-handoff/out-counter/tlc.out +130 -0
- package/verification/per-tag-handoff/split/PerTagConflict.cfg +6 -0
- package/verification/per-tag-handoff/split/PerTagConflict.tla +104 -0
- package/verification/per-tag-handoff/split/PerTagTime.cfg +8 -0
- package/verification/per-tag-handoff/split/PerTagTime.tla +100 -0
- package/verification/per-tag-handoff/split/conflict-chart.mmd +47 -0
- package/verification/per-tag-handoff/split/conflict-report.md +8 -0
- package/verification/per-tag-handoff/split/conflict-tlc.txt +19 -0
- package/verification/per-tag-handoff/split/conflict-view.mjs +34 -0
- package/verification/per-tag-handoff/split/time-chart.mmd +44 -0
- package/verification/per-tag-handoff/split/time-report.md +8 -0
- package/verification/per-tag-handoff/split/time-tlc.txt +19 -0
- package/verification/per-tag-handoff/split/time-view.mjs +33 -0
- package/verification/per-tag-handoff/tlc-output.txt +19 -0
- package/verification/per-tag-handoff/v1-draft/PerTagHandoff.cfg +5 -0
- package/verification/per-tag-handoff/v1-draft/PerTagHandoff.tla +94 -0
- package/verification/per-tag-handoff/v1-draft/out/chart.mmd +37 -0
- package/verification/per-tag-handoff/v1-draft/out/report.md +7 -0
- package/verification/per-tag-handoff/v1-draft/out/tlc.out +19 -0
- package/verification/per-tag-handoff/v1-draft/view.mjs +20 -0
- package/verification/per-tag-handoff/view.mjs +31 -0
- package/verification/subkey-session/SubkeySession.cfg +11 -0
- package/verification/subkey-session/SubkeySession.tla +254 -0
- package/verification/subkey-session/tlc-output.txt +13 -0
package/src/tools.js
CHANGED
|
@@ -19,6 +19,10 @@ import { resolveModulePath } from './module-path.js';
|
|
|
19
19
|
import { replacedByOf } from './setup.js';
|
|
20
20
|
import { currentActor, rawActor, writerStamp, boundSourceTag, declaredAttribution, LOCAL_SUBJECT } from './persons.js';
|
|
21
21
|
import { guardClaimedTag } from './claimed-tag.js';
|
|
22
|
+
import {
|
|
23
|
+
tagHandoffMode, guardTagHandoff, isTagHandoffDoc, boardWritePlan, hubTag, credentialForWrite, authorizeHandoffWrite, attachHandoffView, requireHubTag
|
|
24
|
+
} from './per-tag-handoff.js';
|
|
25
|
+
import { continuityCurrencyEnabled, loadContinuityCurrency, continuityCurrencyUnreadable } from './continuity-currency.js';
|
|
22
26
|
import { approvedTags, APPROVALS_DOC } from './attribution.js';
|
|
23
27
|
import { refuseBoundHostDoor, boundHostActor, boundHostCredentialOverrides, boundHostClaimOnSharedLogin, isBoundHostTag, isLegacyBoundHostSpelling, CLAIM_TAG } from './bound-door.js';
|
|
24
28
|
import { sealAttestation, frozenAttestation } from './rune-dispatch.js';
|
|
@@ -798,7 +802,7 @@ export async function saveMemory(dbManager, content, layer = null, metadata = {}
|
|
|
798
802
|
chain_sha256: chainSha256
|
|
799
803
|
};
|
|
800
804
|
|
|
801
|
-
// Option A correction back-pointer (
|
|
805
|
+
// Option A correction back-pointer (the owner, 2026-10-02, procedural ref 405 item 4): a new entry may name the
|
|
802
806
|
// entry it partly corrects. The parent must exist in the same layer, and is checked BEFORE the insert so a
|
|
803
807
|
// refused correction writes nothing.
|
|
804
808
|
if (validatedMetadata.corrects !== undefined && validatedMetadata.corrects !== null) {
|
|
@@ -1015,7 +1019,7 @@ export async function resolveSupersessionChain(read, entry, maxHops = 50) {
|
|
|
1015
1019
|
}
|
|
1016
1020
|
|
|
1017
1021
|
/**
|
|
1018
|
-
* Option A correction back-pointer (
|
|
1022
|
+
* Option A correction back-pointer (the owner, 2026-10-02, procedural ref 405 item 4; Reviewer's sketch in his
|
|
1019
1023
|
* second read of episodic ref 604). Episodic entries are immutable events, so a PARTIAL correction cannot
|
|
1020
1024
|
* supersede its parent: supersession would put an end date on the whole parent and present every item
|
|
1021
1025
|
* in it as replaced. Instead the new entry carries metadata.corrects = <parent id>, and the parent is MARKED:
|
|
@@ -2151,7 +2155,13 @@ export async function sessionOpen({ slug, load_id } = {}, logger = null, dbManag
|
|
|
2151
2155
|
: 'Nothing was merged into another session.')
|
|
2152
2156
|
: null;
|
|
2153
2157
|
logger?.info?.('transcript session open', { session_id, ...(suffixed ? { requested } : {}) });
|
|
2154
|
-
const
|
|
2158
|
+
const opener = rawActor();
|
|
2159
|
+
const session_handle = await subkeyHandleForOpen(opener, base, now);
|
|
2160
|
+
let subkeyNotice = null;
|
|
2161
|
+
if (session_handle && setting('SUBKEYS') === '1') {
|
|
2162
|
+
const { takeOpenNotice } = await import('./subkeys.js');
|
|
2163
|
+
subkeyNotice = takeOpenNotice(opener);
|
|
2164
|
+
}
|
|
2155
2165
|
// Startup page completion (2026-10-03). Through dispatch, an open with no
|
|
2156
2166
|
// load_id or with pages missing is refused before this runs (the
|
|
2157
2167
|
// startup_pages gate); a direct call is told what was checked.
|
|
@@ -2173,10 +2183,12 @@ export async function sessionOpen({ slug, load_id } = {}, logger = null, dbManag
|
|
|
2173
2183
|
drops_seen = null;
|
|
2174
2184
|
drops_unverified = true;
|
|
2175
2185
|
}
|
|
2176
|
-
|
|
2186
|
+
const opened = {
|
|
2177
2187
|
session_id,
|
|
2178
2188
|
base,
|
|
2179
2189
|
...(session_handle ? { session_handle } : {}),
|
|
2190
|
+
...(subkeyNotice ? { session_renewal: subkeyNotice } : {}),
|
|
2191
|
+
...(subkeyNotice && subkeyNotice.wrap_up_notice ? { wrap_up_notice: subkeyNotice.wrap_up_notice } : {}),
|
|
2180
2192
|
drops_seen,
|
|
2181
2193
|
...(drops_unverified ? { drops_unverified: true } : {}),
|
|
2182
2194
|
next_exchange_index: 1,
|
|
@@ -2188,10 +2200,25 @@ export async function sessionOpen({ slug, load_id } = {}, logger = null, dbManag
|
|
|
2188
2200
|
} : {}),
|
|
2189
2201
|
...(pages ? { startup_pages: pages } : {}),
|
|
2190
2202
|
instructions:
|
|
2203
|
+
(subkeyNotice && subkeyNotice.wrap_up_notice ? `Tell the user: ${subkeyNotice.wrap_up_notice} ` : '') +
|
|
2191
2204
|
(suffixed ? `Tell the user, in one line: ${notice} ` : '') +
|
|
2192
2205
|
(pages && pages.notice ? `${pages.notice} ` : '') +
|
|
2193
2206
|
'After EVERY reply, call emet_transcript_append with this session_id, the user message, and your reply. One exchange per call. Do not wait until the session ends. Do not reconstruct earlier turns.'
|
|
2194
2207
|
};
|
|
2208
|
+
if (continuityCurrencyEnabled() || tagHandoffMode() !== 'off') {
|
|
2209
|
+
let client;
|
|
2210
|
+
try {
|
|
2211
|
+
client = await connectMongo(MONGODB_URI, { serverSelectionTimeoutMS: 8000, maxPoolSize: 5 });
|
|
2212
|
+
const db = client.db(MONGODB_DB);
|
|
2213
|
+
if (continuityCurrencyEnabled()) opened.continuity_currency = await loadContinuityCurrency(db);
|
|
2214
|
+
if (tagHandoffMode() !== 'off') await attachHandoffView(db, opened, credentialForWrite(null).tag);
|
|
2215
|
+
} catch {
|
|
2216
|
+
if (continuityCurrencyEnabled()) opened.continuity_currency = continuityCurrencyUnreadable();
|
|
2217
|
+
} finally {
|
|
2218
|
+
if (client) await client.close();
|
|
2219
|
+
}
|
|
2220
|
+
}
|
|
2221
|
+
return opened;
|
|
2195
2222
|
}
|
|
2196
2223
|
|
|
2197
2224
|
/** Which pages of a startup load were never served (the session graph's startup_pages gate reads it here). */
|
|
@@ -2758,7 +2785,7 @@ export async function readDocHistory(doc_id, version = null, logger = null) {
|
|
|
2758
2785
|
}
|
|
2759
2786
|
|
|
2760
2787
|
/**
|
|
2761
|
-
* Records are superseded, never amended (2026-09-26,
|
|
2788
|
+
* Records are superseded, never amended (2026-09-26, the owner: "enforce
|
|
2762
2789
|
* supersession ISO practices"). ISO 9001 7.5.3 / ISO 13485 4.2.5 separate
|
|
2763
2790
|
* DOCUMENTS, which are revised under control, from RECORDS, which are evidence
|
|
2764
2791
|
* of what happened and are not altered. The handoff is a record: it attests to
|
|
@@ -2785,7 +2812,7 @@ function stateDoc() {
|
|
|
2785
2812
|
return setting('STATE_DOC', 'STATE.md');
|
|
2786
2813
|
}
|
|
2787
2814
|
function _refuseRecordAmendment(doc_id, tool) {
|
|
2788
|
-
if (isRecordDoc(doc_id)) {
|
|
2815
|
+
if (isRecordDoc(doc_id) || (tagHandoffMode() !== 'off' && isTagHandoffDoc(doc_id))) {
|
|
2789
2816
|
throw new ValidationError(
|
|
2790
2817
|
`${tool}: ${doc_id} is a record. Records are superseded, not amended (ISO 9001 7.5.3 / 13485 4.2.5). ` +
|
|
2791
2818
|
`Issue a new revision with write_doc - the whole record, with \`supersedes\` set to the version now in force. ` +
|
|
@@ -2805,7 +2832,7 @@ function _refuseRecordAmendment(doc_id, tool) {
|
|
|
2805
2832
|
* stamps as updated_by: the caller's, else EMET_SOURCE_TAG. A records rule like
|
|
2806
2833
|
* the record-amendment refusal above, so it applies in every graph mode.
|
|
2807
2834
|
*
|
|
2808
|
-
* Two further guards on the same doors (2026-10-01,
|
|
2835
|
+
* Two further guards on the same doors (2026-10-01, the owner's 4:17 PM approval to
|
|
2809
2836
|
* make the bot tags fully functional; Reviewer's review of PR 3):
|
|
2810
2837
|
* - REGISTERED HOSTS ONLY on the main records. With a source registry
|
|
2811
2838
|
* configured (EMET_SOURCE_TAGS, parsed as save_to_layer parses it), the
|
|
@@ -2944,7 +2971,12 @@ function mayCleanUpLookalike(tag) {
|
|
|
2944
2971
|
}
|
|
2945
2972
|
|
|
2946
2973
|
export function refuseBotMainRecord(doc_id, updated_by, tool, options = {}) {
|
|
2947
|
-
|
|
2974
|
+
let warning = null;
|
|
2975
|
+
for (const t of rightsTags(updated_by)) {
|
|
2976
|
+
const result = refuseBotMainRecordOne(doc_id, t, tool, options);
|
|
2977
|
+
if (result && result.warning) warning = result.warning;
|
|
2978
|
+
}
|
|
2979
|
+
return warning ? { warning } : undefined;
|
|
2948
2980
|
}
|
|
2949
2981
|
function refuseBotMainRecordOne(doc_id, updated_by, tool, options = {}) {
|
|
2950
2982
|
const tag = updated_by || setting('SOURCE_TAG') || null;
|
|
@@ -2978,7 +3010,9 @@ function refuseBotMainRecordOne(doc_id, updated_by, tool, options = {}) {
|
|
|
2978
3010
|
// set, a non-bot write under bots/ is refused unless its tag is registered; a missing source counts as
|
|
2979
3011
|
// unregistered. Without this, a misspelled or unregistered tag is not a bot tag, so the cross-bot guard
|
|
2980
3012
|
// above never fires and it can write any bot's records or the roster. A listed bot is already fenced to
|
|
2981
|
-
// its own bots/<tag>/ above
|
|
3013
|
+
// its own bots/<tag>/ above. With EMET_TAG_HANDOFFS off, a registered host may still write under bots/.
|
|
3014
|
+
// With the flag at warn, a write inside another tag's folder is kept and the warning is on the receipt.
|
|
3015
|
+
// With the flag at enforce, that write is refused (EMET-DOC-084), and the hub is refused too.
|
|
2982
3016
|
const registry = sourceRegistry();
|
|
2983
3017
|
if (!bot && registry.length && typeof doc_id === 'string' && doc_id.startsWith('bots/') && !(tag && registry.includes(tag))) {
|
|
2984
3018
|
throw new ValidationError(
|
|
@@ -2986,8 +3020,17 @@ function refuseBotMainRecordOne(doc_id, updated_by, tool, options = {}) {
|
|
|
2986
3020
|
`only a registered host or the bot itself writes under bots/. Nothing was written.`
|
|
2987
3021
|
, { code: 'EMET-DOC-012' });
|
|
2988
3022
|
}
|
|
2989
|
-
|
|
2990
|
-
|
|
3023
|
+
let handoffWarning = null;
|
|
3024
|
+
const noteHandoff = (result) => {
|
|
3025
|
+
if (result && result.warning) handoffWarning = result.warning;
|
|
3026
|
+
};
|
|
3027
|
+
if (!mainRecordIds().includes(doc_id)) {
|
|
3028
|
+
if (tagHandoffMode() !== 'off') noteHandoff(guardTagHandoff(doc_id, updated_by, tool));
|
|
3029
|
+
return handoffWarning ? { warning: handoffWarning } : undefined;
|
|
3030
|
+
}
|
|
3031
|
+
if (bot && doc_id === stateDoc() && tagHandoffMode() !== 'off') {
|
|
3032
|
+
// A write tag patches the board rows it opened. The hub handoff stays refused below.
|
|
3033
|
+
} else if (bot) {
|
|
2991
3034
|
throw new ValidationError(
|
|
2992
3035
|
`${tool}: ${doc_id} is a main record and ${tag} is a bot tag - a bot session closes against ` +
|
|
2993
3036
|
`${botRecordDir(tag)} records; the main handoff and board are the hub's. Write the bot's own ` +
|
|
@@ -2995,28 +3038,26 @@ function refuseBotMainRecordOne(doc_id, updated_by, tool, options = {}) {
|
|
|
2995
3038
|
, { code: 'EMET-DOC-013' });
|
|
2996
3039
|
}
|
|
2997
3040
|
if (options && options.serverProvision === true) return;
|
|
2998
|
-
|
|
3041
|
+
const botOwnRows = bot && doc_id === stateDoc() && tagHandoffMode() !== 'off';
|
|
3042
|
+
if (registry.length && !(tag && registry.includes(tag)) && !botOwnRows) {
|
|
2999
3043
|
throw new ValidationError(
|
|
3000
3044
|
`${tool}: ${doc_id} is a main record and ` +
|
|
3001
3045
|
`${tag ? `"${tag}" is not a registered source tag` : 'this write names no source tag'} - only a registered ` +
|
|
3002
3046
|
`host writes the main handoff and board. Pass the host's registered \`source\` (EMET_SOURCE_TAGS). Nothing was written.`
|
|
3003
3047
|
, { code: 'EMET-DOC-014' });
|
|
3004
3048
|
}
|
|
3049
|
+
if (tagHandoffMode() !== 'off') noteHandoff(guardTagHandoff(doc_id, updated_by, tool));
|
|
3050
|
+
return handoffWarning ? { warning: handoffWarning } : undefined;
|
|
3005
3051
|
}
|
|
3006
3052
|
|
|
3007
3053
|
/**
|
|
3008
|
-
* retire_doc and rename_doc are not bot tools
|
|
3009
|
-
*
|
|
3010
|
-
*
|
|
3011
|
-
*
|
|
3012
|
-
*
|
|
3013
|
-
*
|
|
3014
|
-
*
|
|
3015
|
-
* (Alex-confirmed 2026-10-02 7:50: every other Alex-only tool is
|
|
3016
|
-
* unchanged), and it retires its old id internally, so it is refused too. The tag is the
|
|
3017
|
-
* one the door would stamp: the caller's, else EMET_SOURCE_TAG. Hosts and the
|
|
3018
|
-
* hub have no bots/<tag>/HANDOFF.md record and are unaffected. Nothing is
|
|
3019
|
-
* written when refused.
|
|
3054
|
+
* retire_doc and rename_doc are not bot tools. They stay with the owner and
|
|
3055
|
+
* the hub. A profile is not a security boundary, so the door refuses them
|
|
3056
|
+
* under any bot tag, for every document, not only the main records
|
|
3057
|
+
* refuseBotMainRecord covers. Rename retires its old id, so it is refused
|
|
3058
|
+
* too. The tag is the one the door would stamp: the caller's, else
|
|
3059
|
+
* EMET_SOURCE_TAG. Hosts and the hub have no bots/<tag>/HANDOFF.md record
|
|
3060
|
+
* and are unaffected. Nothing is written when refused.
|
|
3020
3061
|
*/
|
|
3021
3062
|
export function refuseBotRetireRename(tag, tool) {
|
|
3022
3063
|
for (const t of rightsTags(tag)) refuseBotRetireRenameOne(t, tool);
|
|
@@ -3035,7 +3076,7 @@ function refuseBotRetireRenameOne(tag, tool) {
|
|
|
3035
3076
|
throw new ValidationError(
|
|
3036
3077
|
'source',
|
|
3037
3078
|
`${tool} is not a bot tool: ${t} is a bot tag, and ` +
|
|
3038
|
-
`renaming documents stays the owner
|
|
3079
|
+
`renaming documents stays with the owner and the hub` +
|
|
3039
3080
|
`. Ask the hub. Nothing was changed.`
|
|
3040
3081
|
, { code: 'EMET-MEM-020' });
|
|
3041
3082
|
}
|
|
@@ -3069,10 +3110,12 @@ export async function writeDoc(doc_id, rawContent, updated_by = null, path_hint
|
|
|
3069
3110
|
if (casOn && ((prev ? prev.version : null) ?? null) !== (options.expectedVersion ?? null)) throw casConflict();
|
|
3070
3111
|
// A record in force is superseded only by a revision that names it.
|
|
3071
3112
|
// Checked before anything is archived, so a refused write leaves no trace.
|
|
3072
|
-
|
|
3113
|
+
const tagHandoffRecord = tagHandoffMode() !== 'off' && isTagHandoffDoc(doc_id);
|
|
3114
|
+
const recordLike = isRecordDoc(doc_id) || tagHandoffRecord;
|
|
3115
|
+
if (prev && recordLike && options && options.restore_of && (options.supersedes === undefined || options.supersedes === null)) {
|
|
3073
3116
|
options = { ...options, supersedes: prev.version };
|
|
3074
3117
|
}
|
|
3075
|
-
if (prev &&
|
|
3118
|
+
if (prev && recordLike) {
|
|
3076
3119
|
const named = options && options.supersedes;
|
|
3077
3120
|
if (named === undefined || named === null) {
|
|
3078
3121
|
throw new ValidationError(
|
|
@@ -3119,7 +3162,7 @@ export async function writeDoc(doc_id, rawContent, updated_by = null, path_hint
|
|
|
3119
3162
|
}
|
|
3120
3163
|
throw new ValidationError('The board is provisioned by the server at setup (emet_setup_complete). Nothing was written.', { code: 'EMET-MEM-023' });
|
|
3121
3164
|
}
|
|
3122
|
-
if (prev && isWorkingDoc(doc_id) && !internal) {
|
|
3165
|
+
if (prev && isWorkingDoc(doc_id) && !tagHandoffRecord && !internal) {
|
|
3123
3166
|
throw new ValidationError(
|
|
3124
3167
|
`write_doc: ${doc_id} exists, so it is edited, not rewritten. Use patch_doc with \`reason\`. Nothing was written.`
|
|
3125
3168
|
, { code: 'EMET-DOC-022' });
|
|
@@ -3174,6 +3217,52 @@ export async function writeDoc(doc_id, rawContent, updated_by = null, path_hint
|
|
|
3174
3217
|
}
|
|
3175
3218
|
const sizeSamples = recentSamples.slice();
|
|
3176
3219
|
if (prev) sizeSamples.push({ size: String(prev.content || '').length, at: prev.updated_at || new Date() });
|
|
3220
|
+
let tagHandoffWarnings = [];
|
|
3221
|
+
let rowOpeners = null;
|
|
3222
|
+
let conflictSettled = null;
|
|
3223
|
+
if (tagHandoffMode() !== 'off') {
|
|
3224
|
+
requireHubTag();
|
|
3225
|
+
let personIds = [];
|
|
3226
|
+
let ownerPerson = (currentActor() && currentActor().personId) || 'owner';
|
|
3227
|
+
try {
|
|
3228
|
+
const people = await client.db(MONGODB_DB).collection('persons').find({}, { projection: { person_id: 1, role: 1 } }).toArray();
|
|
3229
|
+
personIds = (people || []).map((row) => row && row.person_id).filter(Boolean);
|
|
3230
|
+
const owner = (people || []).find((row) => row && row.role === 'owner');
|
|
3231
|
+
if (owner && owner.person_id) ownerPerson = owner.person_id;
|
|
3232
|
+
} catch { /* a store without the persons collection keeps the actor's person */ }
|
|
3233
|
+
const credential = credentialForWrite(updated_by);
|
|
3234
|
+
const registry = sourceRegistry();
|
|
3235
|
+
const auth = authorizeHandoffWrite({
|
|
3236
|
+
docId: doc_id,
|
|
3237
|
+
tool: options && options.restore_of ? 'restore_doc' : (options && options.edited ? 'patch_doc' : 'write_doc'),
|
|
3238
|
+
mode: tagHandoffMode(),
|
|
3239
|
+
credentialTag: credential.tag,
|
|
3240
|
+
claimedOnly: credential.claimedOnly,
|
|
3241
|
+
isBot: !!(credential.tag && isBotTag(credential.tag)),
|
|
3242
|
+
isHub: !!(hubTag() && credential.tag === hubTag()),
|
|
3243
|
+
registered: registry.length === 0 || (!!credential.tag && registry.includes(credential.tag)),
|
|
3244
|
+
ownerPerson,
|
|
3245
|
+
personIds
|
|
3246
|
+
});
|
|
3247
|
+
if (auth && auth.warning) tagHandoffWarnings.push(auth.warning);
|
|
3248
|
+
if (doc_id === stateDoc() && (options && (options.edited || options.provision || options.restore_of))) {
|
|
3249
|
+
const plan = await boardWritePlan(col, {
|
|
3250
|
+
previous: prev,
|
|
3251
|
+
next: content,
|
|
3252
|
+
writer: credential.tag,
|
|
3253
|
+
hub: hubTag(),
|
|
3254
|
+
mode: tagHandoffMode(),
|
|
3255
|
+
resolve: options && options.resolve_conflict,
|
|
3256
|
+
at: new Date().toISOString(),
|
|
3257
|
+
person: ownerPerson,
|
|
3258
|
+
docId: doc_id,
|
|
3259
|
+
db: client.db(MONGODB_DB)
|
|
3260
|
+
});
|
|
3261
|
+
rowOpeners = plan.openers;
|
|
3262
|
+
conflictSettled = plan.conflict_settled;
|
|
3263
|
+
tagHandoffWarnings = [...tagHandoffWarnings, ...(plan.warnings || [])];
|
|
3264
|
+
}
|
|
3265
|
+
}
|
|
3177
3266
|
const docDecision = resolvedSourceTag(updated_by);
|
|
3178
3267
|
const stampedUpdatedBy = stampedSource(docDecision, updated_by || (isDropDoc(doc_id) ? 'visitor' : (setting('SOURCE_TAG') || null)));
|
|
3179
3268
|
const docClaim = guardClaimedTag({
|
|
@@ -3227,6 +3316,8 @@ export async function writeDoc(doc_id, rawContent, updated_by = null, path_hint
|
|
|
3227
3316
|
size_session_id: base,
|
|
3228
3317
|
size_baselines: baselines,
|
|
3229
3318
|
size_samples: typeof sizeSamples !== 'undefined' ? sizeSamples : (prev && prev.size_samples) || [],
|
|
3319
|
+
...(rowOpeners ? { row_openers: rowOpeners } : {}),
|
|
3320
|
+
...(conflictSettled ? { conflict_settled: conflictSettled } : {}),
|
|
3230
3321
|
drop_bucket: (options && options.drop_bucket) || (prev && prev.drop_bucket) || null,
|
|
3231
3322
|
path_hint: path_hint || (prev && prev.path_hint) || null,
|
|
3232
3323
|
// Writing a retired document brings it back into the working view.
|
|
@@ -3268,12 +3359,16 @@ export async function writeDoc(doc_id, rawContent, updated_by = null, path_hint
|
|
|
3268
3359
|
// aleph: the write is not done because the call returned.
|
|
3269
3360
|
const check = await col.findOne({ doc_id });
|
|
3270
3361
|
verifyDocument(check, { doc_id, sha256, version });
|
|
3362
|
+
if (tagHandoffWarnings.length) {
|
|
3363
|
+
try { logger?.warn?.(tagHandoffWarnings.join(' ')); } catch { /* a failing logger never fails the write */ }
|
|
3364
|
+
}
|
|
3271
3365
|
return { doc_id, sha256, version, size: content.length, updated_at: now, verified: true,
|
|
3272
3366
|
signed: signatureIntegrityOf(check, signingKey),
|
|
3273
3367
|
signature_stored: typeof check?.signature === 'string' && check.signature.length > 0,
|
|
3274
3368
|
redacted: redaction.hits, conformance,
|
|
3275
3369
|
grant_id: docStamp.grant_id,
|
|
3276
|
-
...(docClaim.warning ? { claimed_tag_warning: docClaim.warning } : {})
|
|
3370
|
+
...(docClaim.warning ? { claimed_tag_warning: docClaim.warning } : {}),
|
|
3371
|
+
...(tagHandoffWarnings.length ? { warnings: tagHandoffWarnings } : {}) };
|
|
3277
3372
|
} finally { await client.close(); }
|
|
3278
3373
|
} catch (error) {
|
|
3279
3374
|
if (error && error.versionConflict) throw error;
|
|
@@ -3362,10 +3457,13 @@ export async function retireDoc(doc_id, reason = null, retired_by = null, logger
|
|
|
3362
3457
|
try { await assertAreaOwner(opened.client.db(MONGODB_DB), 'retire_doc'); }
|
|
3363
3458
|
finally { await opened.client.close(); }
|
|
3364
3459
|
}
|
|
3365
|
-
refuseBotMainRecord(doc_id, retired_by, 'retire_doc', { cleanup: true });
|
|
3460
|
+
const gap = refuseBotMainRecord(doc_id, retired_by, 'retire_doc', { cleanup: true });
|
|
3461
|
+
const gapWarnings = gap && gap.warning ? [gap.warning] : [];
|
|
3462
|
+
if (gapWarnings.length) logger?.warn?.(gapWarnings.join(' '));
|
|
3366
3463
|
refuseBotRetireRename(retired_by, 'retire_doc');
|
|
3367
3464
|
if (doc_id === stateDoc()) throw new ValidationError('retire_doc: the board is never retired. Edit it with patch_doc and a reason. Nothing was changed.', { code: 'EMET-DOC-027' });
|
|
3368
|
-
|
|
3465
|
+
const hubCleanup = tagHandoffMode() !== 'off' && !!hubTag() && retired_by === hubTag() && doc_id === `HANDOFF/${hubTag()}.md`;
|
|
3466
|
+
if (!isDropDoc(doc_id) && !(options && options.fromRename) && !hubCleanup) throw new ValidationError(`retire_doc: ${doc_id} is not a drop. Working documents are edited, not retired. Nothing was changed.`, { code: 'EMET-DOC-028' });
|
|
3369
3467
|
if (typeof reason !== 'string' || reason.trim().length < 10) throw new ValidationError('retire_doc needs reason (at least 10 characters), naming where the drop went. Nothing was changed.', { code: 'EMET-DOC-029' });
|
|
3370
3468
|
|
|
3371
3469
|
const { client, col } = await _docsClient();
|
|
@@ -3375,7 +3473,8 @@ export async function retireDoc(doc_id, reason = null, retired_by = null, logger
|
|
|
3375
3473
|
if (doc.retired) {
|
|
3376
3474
|
return { doc_id, retired: true, already_retired: true, verified: true,
|
|
3377
3475
|
retired_at: doc.retired_at, retired_reason: doc.retired_reason || null,
|
|
3378
|
-
version: doc.version, sha256: doc.sha256
|
|
3476
|
+
version: doc.version, sha256: doc.sha256,
|
|
3477
|
+
...(gapWarnings.length ? { warnings: gapWarnings } : {}) };
|
|
3379
3478
|
}
|
|
3380
3479
|
|
|
3381
3480
|
const now = new Date();
|
|
@@ -3431,6 +3530,7 @@ export async function retireDoc(doc_id, reason = null, retired_by = null, logger
|
|
|
3431
3530
|
return { doc_id, retired: true, verified: true, retired_at: now, conformance,
|
|
3432
3531
|
retired_reason: reason || null, version: check.version,
|
|
3433
3532
|
sha256: check.sha256, content_unchanged: true,
|
|
3533
|
+
...(gapWarnings.length ? { warnings: gapWarnings } : {}),
|
|
3434
3534
|
grant_id: retireStamp.grant_id,
|
|
3435
3535
|
...(retireClaim.warning ? { claimed_tag_warning: retireClaim.warning } : {}),
|
|
3436
3536
|
note: 'Content retained at this id. list_docs keeps it after the current documents, marked with retired_at and, when a rename replaced it, what replaced it. read_doc still returns it. Nothing was deleted.' };
|
|
@@ -3452,8 +3552,8 @@ export async function renameDoc(old_id, new_id, updated_by = null, logger = null
|
|
|
3452
3552
|
try { await assertAreaOwner(opened.client.db(MONGODB_DB), 'rename_doc'); }
|
|
3453
3553
|
finally { await opened.client.close(); }
|
|
3454
3554
|
}
|
|
3455
|
-
refuseBotMainRecord(old_id, updated_by, 'rename_doc', { cleanup: true });
|
|
3456
|
-
refuseBotMainRecord(new_id, updated_by, 'rename_doc');
|
|
3555
|
+
const sourceGap = refuseBotMainRecord(old_id, updated_by, 'rename_doc', { cleanup: true });
|
|
3556
|
+
const destGap = refuseBotMainRecord(new_id, updated_by, 'rename_doc');
|
|
3457
3557
|
refuseBotRetireRename(updated_by, 'rename_doc');
|
|
3458
3558
|
if (typeof reason !== 'string' || reason.trim().length < 10) throw new ValidationError('rename_doc needs reason (at least 10 characters). Nothing was changed.', { code: 'EMET-DOC-033' });
|
|
3459
3559
|
if (old_id === stateDoc() || new_id === stateDoc()) throw new ValidationError('rename_doc: the board is never renamed. Nothing was changed.', { code: 'EMET-DOC-034' });
|
|
@@ -3487,10 +3587,13 @@ export async function renameDoc(old_id, new_id, updated_by = null, logger = null
|
|
|
3487
3587
|
// asks for. The old id keeps its content and stays readable at its own id.
|
|
3488
3588
|
const retired = await retireDoc(old_id, `Reissued as ${new_id}`, updated_by, logger, { fromRename: true });
|
|
3489
3589
|
|
|
3590
|
+
const warnings = [sourceGap && sourceGap.warning, destGap && destGap.warning, ...(written.warnings || []), ...(retired.warnings || [])].filter(Boolean);
|
|
3591
|
+
if (warnings.length) logger?.warn?.(warnings.join(' '));
|
|
3490
3592
|
return {
|
|
3491
3593
|
from: old_id, to: new_id, verified: written.verified === true && retired.verified === true,
|
|
3492
3594
|
conformance: written.conformance || null,
|
|
3493
3595
|
sha256: written.sha256, version: written.version, size: written.size,
|
|
3596
|
+
...(warnings.length ? { warnings } : {}),
|
|
3494
3597
|
redacted: written.redacted,
|
|
3495
3598
|
old_id_retired: true, old_id_retired_at: retired.retired_at,
|
|
3496
3599
|
old_content_retained: true,
|
|
@@ -3531,7 +3634,7 @@ export async function restoreDoc(doc_id, version, updated_by = null, logger = nu
|
|
|
3531
3634
|
if (typeof reason !== 'string' || reason.trim().length < 10) throw new ValidationError('restore_doc needs reason (at least 10 characters). Nothing was written.', { code: 'EMET-DOC-037' });
|
|
3532
3635
|
if (!updated_by) throw new ValidationError('restore_doc needs a source. Nothing was written.', { code: 'EMET-DOC-038' });
|
|
3533
3636
|
if (isDropDoc(doc_id)) throw new ValidationError('restore_doc: a drop is never restored. Nothing was written.', { code: 'EMET-DOC-039' });
|
|
3534
|
-
if (isRecordDoc(doc_id)) throw new ValidationError('restore_doc: a record is not restored. Records are superseded via revise_memory, not restored. Nothing was written.', { code: 'EMET-DOC-040' });
|
|
3637
|
+
if (isRecordDoc(doc_id) || (tagHandoffMode() !== 'off' && isTagHandoffDoc(doc_id))) throw new ValidationError('restore_doc: a record is not restored. Records are superseded via revise_memory, not restored. Nothing was written.', { code: 'EMET-DOC-040' });
|
|
3535
3638
|
if (isGovernedByShippedCopy(doc_id)) throw new ValidationError('restore_doc: a shipped copy is not restored. Nothing was written.', { code: 'EMET-DOC-041' });
|
|
3536
3639
|
const allowed = (setting('RESTORE_TAGS') || setting('SOURCE_TAG') || '').split(',').map((s) => s.trim()).filter(Boolean);
|
|
3537
3640
|
if (!allowed.includes(updated_by)) throw new ValidationError(`restore_doc: ${updated_by} is not in EMET_RESTORE_TAGS. Nothing was written.`, { code: 'EMET-DOC-042' });
|
|
@@ -3624,7 +3727,9 @@ export async function acceptNonconformance(doc_id, reason, accepted_by = null, l
|
|
|
3624
3727
|
try { await assertAreaOwner(opened.client.db(MONGODB_DB), 'accept_nonconformance'); }
|
|
3625
3728
|
finally { await opened.client.close(); }
|
|
3626
3729
|
}
|
|
3627
|
-
refuseBotMainRecord(doc_id, accepted_by, 'accept_nonconformance');
|
|
3730
|
+
const gap = refuseBotMainRecord(doc_id, accepted_by, 'accept_nonconformance');
|
|
3731
|
+
const gapWarnings = gap && gap.warning ? [gap.warning] : [];
|
|
3732
|
+
if (gapWarnings.length) logger?.warn?.(gapWarnings.join(' '));
|
|
3628
3733
|
if (!doc_id || typeof doc_id !== 'string') throw new ValidationError('doc_id must be a non-empty string', { code: 'EMET-DOC-001' });
|
|
3629
3734
|
if (typeof reason !== 'string' || reason.trim().length < 10) {
|
|
3630
3735
|
throw new ValidationError(
|
|
@@ -3670,6 +3775,7 @@ export async function acceptNonconformance(doc_id, reason, accepted_by = null, l
|
|
|
3670
3775
|
return {
|
|
3671
3776
|
doc_id, verified: true, version: doc.version, covers_version: doc.version,
|
|
3672
3777
|
accepted, failures_accepted: current.failures || [],
|
|
3778
|
+
...(gapWarnings.length ? { warnings: gapWarnings } : {}),
|
|
3673
3779
|
grant_id: stamp.grant_id,
|
|
3674
3780
|
...(acceptClaim.warning ? { claimed_tag_warning: acceptClaim.warning } : {}),
|
|
3675
3781
|
note: 'The marker is retained with this acceptance beside it. It covers this revision only - the next write is validated fresh, and accepted markers stay counted at session start, separately from open ones.'
|
|
@@ -3759,7 +3865,10 @@ export async function patchDoc(doc_id, old_str, new_str, updated_by = null, expe
|
|
|
3759
3865
|
throw new ValidationError(`patch_doc: the board edit is nonconforming. ${(checked.failures || []).join('; ')} Nothing was written.`, { code: 'EMET-MEM-029' });
|
|
3760
3866
|
}
|
|
3761
3867
|
}
|
|
3762
|
-
const res = await writeDoc(doc_id, next, updated_by, null, logger, {
|
|
3868
|
+
const res = await writeDoc(doc_id, next, updated_by, null, logger, {
|
|
3869
|
+
edited: true, reason, origin: options.origin || null, session_id: options.session_id || null,
|
|
3870
|
+
resolve_conflict: options && options.resolve_conflict
|
|
3871
|
+
});
|
|
3763
3872
|
return { ...res, previous_version: cur.version, replaced: edits.length,
|
|
3764
3873
|
size_delta: next.length - cur.content.length };
|
|
3765
3874
|
} catch (error) {
|
|
@@ -4014,7 +4123,7 @@ export async function memberAccessCreate(dbManager, { display_name, days, source
|
|
|
4014
4123
|
const who = currentActor();
|
|
4015
4124
|
const aiWriter = isOwlIdentity(who) || (who.transport === 'http' && (isMasterBlasterActor(who) || actorIsCos(who) || (who.sourceTag && isBotTag(who.sourceTag))));
|
|
4016
4125
|
if (aiWriter) {
|
|
4017
|
-
throw new ValidationError('An AI cannot grant a writer.
|
|
4126
|
+
throw new ValidationError('An AI cannot grant a writer. The owner decides on /owner/chooser with an owner session. Nothing was created.', { code: 'EMET-AUTH-043' });
|
|
4018
4127
|
}
|
|
4019
4128
|
const { registeredSourceTags } = await import('./setup.js');
|
|
4020
4129
|
const actor = await codeCreator(dbManager);
|
|
@@ -4040,7 +4149,7 @@ export async function memberAccessCreate(dbManager, { display_name, days, source
|
|
|
4040
4149
|
const TOOL_DEFINITIONS = [
|
|
4041
4150
|
{
|
|
4042
4151
|
name: "emet_initialize",
|
|
4043
|
-
description: "START HERE. Call this FIRST in every session, before answering anything that might have prior context, and always when the user opens with 'initialize', 'start', 'begin', 'hello' or similar. It is the only setup step a user should ever have to know about. A large startup comes in pages: read `page_notice` first and call again with the page it names until the last page, before replying. If this memory store is new it returns a short interview to run conversationally; if it is established it returns who you are, how you speak (`character`, when the store keeps one - authoritative on voice for the whole session), who you are serving, and where things were left. The user never needs to know which case applied.",
|
|
4152
|
+
description: "START HERE. Call this FIRST in every session, before answering anything that might have prior context, and always when the user opens with 'initialize', 'start', 'begin', 'hello' or similar. It is the only setup step a user should ever have to know about. A large startup comes in pages: read `page_notice` first and call again with the page it names until the last page, before replying. If this memory store is new it returns a short interview to run conversationally; if it is established it returns who you are, how you speak (`character`, when the store keeps one - authoritative on voice for the whole session), who you are serving, and where things were left. The user never needs to know which case applied. When EMET_TAG_HANDOFFS is warn or enforce, the startup also carries handoff_view, a stamp computed on read and not stored. A write tag also receives its own handoff section and any stale-open mark. A read-only tag receives the view only. Off, the default, adds none of that.",
|
|
4044
4153
|
inputSchema: {
|
|
4045
4154
|
type: "object",
|
|
4046
4155
|
properties: {
|
|
@@ -4214,7 +4323,7 @@ const TOOL_DEFINITIONS = [
|
|
|
4214
4323
|
importance_degree: { type: "string", description: "low|mid|high — only when degree inside the bucket matters" },
|
|
4215
4324
|
emotional_intensity: { type: "number" },
|
|
4216
4325
|
context: { type: "string" },
|
|
4217
|
-
source: { type: "string", description: "Which host produced this write. A shared default tag is ambiguity, not attribution." },
|
|
4326
|
+
source: { type: "string", description: "Which host produced this write. A shared default tag is ambiguity, not attribution. With EMET_TAG_HANDOFFS off, an HTTP caller may still name a tag here. With the flag at warn or enforce, HTTP uses the credential's tag, and a declared tag that differs is refused (EMET-DOC-088). Stdio keeps the declared tag." },
|
|
4218
4327
|
tags: { type: "array", items: { type: "string" } },
|
|
4219
4328
|
valid_until: { type: "number", description: "Unix seconds. After this the entry is marked ended and stays in recall and queries, with this date as its end date. It is not hidden and it is not deleted." },
|
|
4220
4329
|
derived_from: {
|
|
@@ -4355,11 +4464,12 @@ const TOOL_DEFINITIONS = [
|
|
|
4355
4464
|
},
|
|
4356
4465
|
{
|
|
4357
4466
|
name: "emet_session_open",
|
|
4358
|
-
description: "Open a transcript session. Returns session_id, dated in the configured local time zone (EMET_TIMEZONE, default America/New_York). A slug that already begins with YYYY-MM-DD_ (month 01-12, day 01-31) is not dated again, even when that date is not the local day. A slug whose id is already CLOSED is never reopened: the session opens as <id>-2, -3, ... and the result's `notice` says so. Pass load_id from your startup pages (startup_page.load_id on every emet_initialize page) so the startup page check runs on your own startup; an open without load_id, or with a page of that startup never fetched, is refused (the refusal says how to pass). After every reply, call emet_transcript_append with that id and the one exchange that just happened. Do not dump the whole chat at close.",
|
|
4467
|
+
description: "Open a transcript session. Returns session_id, dated in the configured local time zone (EMET_TIMEZONE, default America/New_York). A slug that already begins with YYYY-MM-DD_ (month 01-12, day 01-31) is not dated again, even when that date is not the local day. A slug whose id is already CLOSED is never reopened: the session opens as <id>-2, -3, ... and the result's `notice` says so. Pass load_id from your startup pages (startup_page.load_id on every emet_initialize page) so the startup page check runs on your own startup; an open without load_id, or with a page of that startup never fetched, is refused (the refusal says how to pass). After every reply, call emet_transcript_append with that id and the one exchange that just happened. Do not dump the whole chat at close. When EMET_TAG_HANDOFFS is warn or enforce, the result also carries handoff_view (the stamp, including as_of), own_handoff, and stale_open. An open session with material work is an in-progress line. After EMET_STALE_OPEN_HOURS it is stale-open. Those fields are not part of load_id. With EMET_TAG_HANDOFFS at warn or enforce, HTTP uses the credential's tag, and a declared tag that differs is refused (EMET-DOC-088). With the flag off that check does not run.",
|
|
4359
4468
|
inputSchema: {
|
|
4360
4469
|
type: "object",
|
|
4361
4470
|
properties: {
|
|
4362
4471
|
slug: { type: "string", description: "Short name for the session, e.g. grok-init. A slug that already begins with YYYY-MM-DD_ (month 01-12, day 01-31) is the base and is not dated again, even when that date is not the local day. Any other slug receives the local day. A closed id still opens as -2, -3, .... Parts are still _verbatim_partN." },
|
|
4472
|
+
source: { type: "string", description: "The write tag opening this session. On stdio this declared tag is the session tag. With EMET_TAG_HANDOFFS at warn or enforce, HTTP uses the credential's tag, and a declared tag that differs is refused (EMET-DOC-088). With the flag off that check does not run. save_to_layer puts the same tag in metadata.source." },
|
|
4363
4473
|
load_id: { type: "string", description: "Required for the startup page check (by policy; the schema leaves it optional so older hosts can still open): the load_id from `startup_page` on your emet_initialize pages - page 1 returns it, every page carries it, and the last page names it. An open without load_id, or with a page of that load known not fetched, is refused before anything is written (gate startup_pages); the refusal names the exact calls that pass." }
|
|
4364
4474
|
}
|
|
4365
4475
|
}
|
|
@@ -4402,20 +4512,20 @@ const TOOL_DEFINITIONS = [
|
|
|
4402
4512
|
},
|
|
4403
4513
|
{
|
|
4404
4514
|
name: "write_doc",
|
|
4405
|
-
description: "Write or update a continuity document in the document store (versioned, prior copy archived to documents_history and marked obsolete, sha256 read-back verified). RECORDS - the handoff (HANDOFF.md) and any id in EMET_RECORD_DOCS - are superseded, never amended: patch_doc is refused on them, and a new revision is written here WHOLE with `supersedes` set to the version currently in force (ISO 9001 7.5.3 / 13485 4.2.5).",
|
|
4515
|
+
description: "Write or update a continuity document in the document store (versioned, prior copy archived to documents_history and marked obsolete, sha256 read-back verified). RECORDS - the handoff (HANDOFF.md) and any id in EMET_RECORD_DOCS - are superseded, never amended: patch_doc is refused on them, and a new revision is written here WHOLE with `supersedes` set to the version currently in force (ISO 9001 7.5.3 / 13485 4.2.5). When EMET_TAG_HANDOFFS is warn or enforce, a write tag's handoff is HANDOFF/<tag>.md and only that credential writes it. Only the hub tag writes HANDOFF.md. A claimed tag is refused on HANDOFF/ (EMET-DOC-087). A two-segment id and a tag equal to a person id are refused (EMET-DOC-086). Another tag's handoff is refused (EMET-DOC-084). In warn, those new-prefix refusals apply at once. A registered non-hub write of HANDOFF.md or another tag's bots/ folder warns and is kept; enforce refuses it.",
|
|
4406
4516
|
inputSchema: { type: "object", properties: {
|
|
4407
4517
|
doc_id: { type: "string" },
|
|
4408
4518
|
content: { type: "string" },
|
|
4409
4519
|
supersedes: { type: "number", description: "Required when writing a new revision of a RECORD (the handoff): the version currently in force, which this revision supersedes. Ignored for ordinary documents." },
|
|
4410
4520
|
reason: { type: "string", description: "Required on a record revision (at least 10 characters). Stored as edit_reason." },
|
|
4411
4521
|
session_id: { type: "string", description: "Transcript session id. The floor is measured from the size when this session first touched the document." },
|
|
4412
|
-
source: { type: "string", description: "Source tag - which host produced this write. One name on every write since 2026-09-27." },
|
|
4522
|
+
source: { type: "string", description: "Source tag - which host produced this write. One name on every write since 2026-09-27. With EMET_TAG_HANDOFFS at warn or enforce, HTTP refuses a declared tag that is not the credential when session_id is set (EMET-DOC-088). A call that declares no tag is kept. With the flag off that check does not run." },
|
|
4413
4523
|
updated_by: { type: "string", description: "Alias of `source` (the older name, kept one release). Prefer `source`." }
|
|
4414
4524
|
}, required: ["doc_id", "content"] }
|
|
4415
4525
|
},
|
|
4416
4526
|
{
|
|
4417
4527
|
name: "write_doc_begin",
|
|
4418
|
-
description: "Open a staged write when a document will not fit in one write_doc argument. The stage is not a document and does not change the current revision. Send each part with write_doc_append, then write_doc_commit. A record (HANDOFF.md and any id in EMET_RECORD_DOCS) still needs supersedes and reason; commit writes one whole revision through write_doc. Limits: 16000 characters per part, 128 parts, 2000000 characters total, 30 minutes from begin, 4 open stages per writer. Same source, session, and writer stamp as write_doc.",
|
|
4528
|
+
description: "Open a staged write when a document will not fit in one write_doc argument. The stage is not a document and does not change the current revision. Send each part with write_doc_append, then write_doc_commit. A record (HANDOFF.md and any id in EMET_RECORD_DOCS) still needs supersedes and reason; commit writes one whole revision through write_doc. Limits: 16000 characters per part, 128 parts, 2000000 characters total, 30 minutes from begin, 4 open stages per writer. When EMET_TAG_HANDOFFS is warn or enforce, HANDOFF/<tag>.md is that kind of record too, and the same credential check as write_doc runs at commit (EMET-DOC-088). Same source, session, and writer stamp as write_doc.",
|
|
4419
4529
|
inputSchema: { type: "object", properties: {
|
|
4420
4530
|
doc_id: { type: "string" },
|
|
4421
4531
|
supersedes: { type: "number", description: "Required when staging a new revision of a RECORD: the version currently in force. Stored on the stage and passed to write_doc at commit." },
|
|
@@ -4437,7 +4547,7 @@ const TOOL_DEFINITIONS = [
|
|
|
4437
4547
|
},
|
|
4438
4548
|
{
|
|
4439
4549
|
name: "write_doc_commit",
|
|
4440
|
-
description: "Assemble an open stage, check part_count and the sha256 of the exact assembled text (the concatenation of the parts in order, before this server redacts it), then write one revision through write_doc. A mismatch or a write_doc refusal leaves the current document unchanged and the stage open. A second commit of the same sha256 returns the first receipt and does not write another revision. A record is still one whole revision: it is superseded, never patched or appended.",
|
|
4550
|
+
description: "Assemble an open stage, check part_count and the sha256 of the exact assembled text (the concatenation of the parts in order, before this server redacts it), then write one revision through write_doc. A mismatch or a write_doc refusal leaves the current document unchanged and the stage open. A second commit of the same sha256 returns the first receipt and does not write another revision. A record is still one whole revision: it is superseded, never patched or appended. Commit uses the same handoff credential check as write_doc when EMET_TAG_HANDOFFS is warn or enforce (EMET-DOC-088). A call that declares no tag is kept.",
|
|
4441
4551
|
inputSchema: { type: "object", properties: {
|
|
4442
4552
|
stage_id: { type: "string" },
|
|
4443
4553
|
doc_id: { type: "string", description: "The same document id the stage was begun for." },
|
|
@@ -4522,7 +4632,7 @@ const TOOL_DEFINITIONS = [
|
|
|
4522
4632
|
},
|
|
4523
4633
|
{
|
|
4524
4634
|
name: "patch_doc",
|
|
4525
|
-
description: "Replace one exact substring in a document (str_replace semantics) without resending the whole file. THE PREFERRED WAY TO MAKE SMALL EDITS to large docs like STATE.md. old_str must match EXACTLY ONCE - zero or multiple matches are rejected rather than guessed. Pass new_str as an empty string to delete. Same versioning, archiving, and sha256 read-back as write_doc.",
|
|
4635
|
+
description: "Replace one exact substring in a document (str_replace semantics) without resending the whole file. THE PREFERRED WAY TO MAKE SMALL EDITS to large docs like STATE.md. old_str must match EXACTLY ONCE - zero or multiple matches are rejected rather than guessed. Pass new_str as an empty string to delete. Same versioning, archiving, and sha256 read-back as write_doc. When EMET_TAG_HANDOFFS is warn or enforce, a tag patches only the STATE.md rows it opened. Rows already on the board when the flag turns on belong to the hub tag. The hub changes another tag's row only to resolve a marked conflict, and resolve_conflict names that row and the handoff_view stamp, including as_of. A foreign row is warned and kept in warn, and refused in enforce (EMET-DOC-085). A bot tag may patch its own rows and still cannot write HANDOFF.md. patch_doc stays refused on a handoff record. HTTP refuses a declared tag that is not the credential when session_id is set (EMET-DOC-088). A call that declares no tag is kept.",
|
|
4526
4636
|
inputSchema: { type: "object", properties: {
|
|
4527
4637
|
doc_id: { type: "string" },
|
|
4528
4638
|
old_str: { type: "string", description: "Exact text to replace. Must occur exactly once in the current text. Omit when `edits` is set." },
|
|
@@ -4572,7 +4682,7 @@ const TOOL_DEFINITIONS = [
|
|
|
4572
4682
|
},
|
|
4573
4683
|
{
|
|
4574
4684
|
name: "emet_page_lint",
|
|
4575
|
-
description: "Flag problems in topic pages and the records they read. Read-only: it never edits a record. Findings cover contradictions (two current records that share a subject and disagree), superseded or retired records still claimed as current, lines with no source, duplicates, broken links, and statuses unconfirmed longer than the area's staleness window. It builds on the emet_gaps classifiers. A fix is a person's revise_memory, retire_doc, or accept_nonconformance. Owner only. Omit area to lint every area.",
|
|
4685
|
+
description: "Flag problems in topic pages and the records they read. Read-only: it never edits a record. Findings cover contradictions (two current records that share a subject and disagree), superseded or retired records still claimed as current, lines with no source, duplicates, broken links, and statuses unconfirmed longer than the area's staleness window. When EMET_TAG_HANDOFFS is warn or enforce, a handoff_conflict finding names a board row whose current handoff lines disagree. The view does not pick a winner. It builds on the emet_gaps classifiers. A fix is a person's revise_memory, retire_doc, or accept_nonconformance. Owner only. Omit area to lint every area.",
|
|
4576
4686
|
inputSchema: { type: "object", properties: {
|
|
4577
4687
|
area: { type: "string", description: "Optional area slug. Omit to lint every current area." }
|
|
4578
4688
|
} }
|
|
@@ -4603,7 +4713,7 @@ const TOOL_DEFINITIONS = [
|
|
|
4603
4713
|
},
|
|
4604
4714
|
{
|
|
4605
4715
|
name: "emet_client_approve",
|
|
4606
|
-
description: "Approve or deny a pending client tag, or prepare a new writer. decision prepare drafts a writer request: client, claimed tag, door (member or guest), reason, and correlation_id. The hub login prepares that draft. The server validates it. Validation is a check and is not approval.
|
|
4716
|
+
description: "Approve or deny a pending client tag, or prepare a new writer. decision prepare drafts a writer request: client, claimed tag, door (member or guest), reason, and correlation_id. The hub login prepares that draft. The server validates it. Validation is a check and is not approval. The owner decides a new writer on /owner/chooser with the owner session. No AI grants a writer, including the hub login and the retired owl account. The owner login may still approve or deny a pending client tag. Pending client tags are listed in emet_initialize and emet_status as client_approvals.",
|
|
4607
4717
|
inputSchema: {
|
|
4608
4718
|
type: "object",
|
|
4609
4719
|
properties: {
|
|
@@ -4649,7 +4759,7 @@ const TOOL_DEFINITIONS = [
|
|
|
4649
4759
|
},
|
|
4650
4760
|
{
|
|
4651
4761
|
name: "emet_session_close",
|
|
4652
|
-
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'.",
|
|
4762
|
+
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. When EMET_TAG_HANDOFFS is warn or enforce, every tag uses one receipt set: handoff_doc, handoff_version, and handoff_view (the stamp from initialize, including as_of). A stamp without as_of blocks the close. A board receipt is required only when this credential patched the board. The result echoes handoff_view. The continuity-currency gate stays warn-only and does not refuse the close. Never tell the user their session is saved unless this returns state 'complete'.",
|
|
4653
4763
|
inputSchema: {
|
|
4654
4764
|
type: "object",
|
|
4655
4765
|
properties: {
|
|
@@ -4665,7 +4775,8 @@ const TOOL_DEFINITIONS = [
|
|
|
4665
4775
|
transcript_parts: { type: "array", items: { type: "string" }, description: "Part ids query_transcripts returned for this session." },
|
|
4666
4776
|
transcript_exchanges: { type: "number", description: "Highest exchange index query_transcripts returned." },
|
|
4667
4777
|
handoff_version: { type: "number", description: "Version of the handoff, written last." },
|
|
4668
|
-
handoff_doc: { type: "string", description: "
|
|
4778
|
+
handoff_doc: { type: "string", description: "The handoff this credential wrote last. The hub names HANDOFF.md. Another write tag names HANDOFF/<tag>.md. A bot may still name bots/<tag>/HANDOFF.md until that id is renamed." },
|
|
4779
|
+
handoff_view: { type: "object", description: "When EMET_TAG_HANDOFFS is warn or enforce: the stamp from initialize, with as_of, person, inputs, board, and view_sha256. A stamp without as_of is refused." }
|
|
4669
4780
|
}
|
|
4670
4781
|
},
|
|
4671
4782
|
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." },
|
|
@@ -4730,6 +4841,15 @@ const SUBKEY_TOOL_DEFINITIONS = [
|
|
|
4730
4841
|
key_id: { type: "string", description: "The key whose live session to end. Pass tag or key_id." },
|
|
4731
4842
|
reason: { type: "string", description: "Why the session was ended. Kept on the record." }
|
|
4732
4843
|
} }
|
|
4844
|
+
},
|
|
4845
|
+
{
|
|
4846
|
+
name: "emet_subkey_set_kind",
|
|
4847
|
+
description: "Set the client kind stored on an approved sub-key. Owner only. bot keeps the one-live-session collision. chat is a client that wakes on a message. A key with no kind stored is a bot. The change is a history event. The key is not revoked.",
|
|
4848
|
+
inputSchema: { type: "object", properties: {
|
|
4849
|
+
tag: { type: "string", description: "The tag whose approved key to update. Pass tag or key_id." },
|
|
4850
|
+
key_id: { type: "string", description: "The key to update. Pass tag or key_id." },
|
|
4851
|
+
client_kind: { type: "string", description: "bot or chat. This is the kind the owner stores. A later call cannot set it." }
|
|
4852
|
+
}, required: ["client_kind"] }
|
|
4733
4853
|
}
|
|
4734
4854
|
];
|
|
4735
4855
|
|
|
@@ -4781,7 +4901,7 @@ function cloneTool(t) {
|
|
|
4781
4901
|
|
|
4782
4902
|
let toolCache = { flag: null, tools: null };
|
|
4783
4903
|
|
|
4784
|
-
/** The tool list a host receives. The
|
|
4904
|
+
/** The tool list a host receives. The sub-key tools and their schema fields exist only when EMET_SUBKEYS=1. */
|
|
4785
4905
|
export function hostTools() {
|
|
4786
4906
|
const on = setting('SUBKEYS') === '1';
|
|
4787
4907
|
if (toolCache.tools && toolCache.flag === on) return toolCache.tools;
|
|
@@ -5,7 +5,7 @@ import { setting } from './env.js';
|
|
|
5
5
|
export const EXCHANGES_PER_PART = 8;
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* The zone a session id is dated in (2026-10-01,
|
|
8
|
+
* The zone a session id is dated in (2026-10-01, the owner's approval; dev team plan
|
|
9
9
|
* Part B, fix 1). Ids were dated from UTC, so an evening session in New York
|
|
10
10
|
* carried the next day's date (episodic ref 600: `2026-10-01_grok-init` minted on
|
|
11
11
|
* the night of 9/30). The day is now the user's local day: EMET_TIMEZONE, an
|
|
@@ -86,7 +86,7 @@ export function shouldStartNewPart(exchangeCount) {
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
/**
|
|
89
|
-
* A closed session is never reopened (2026-10-01,
|
|
89
|
+
* A closed session is never reopened (2026-10-01, the owner's approval; episodic
|
|
90
90
|
* 598: a session_open returned the previous night's CLOSED id and the next
|
|
91
91
|
* append landed in it as exchange 9). Returns the first of base, base-2,
|
|
92
92
|
* base-3, ... that is free, and the ids it passed over with the reason.
|
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.7';
|
package/templates/INDEX.md
CHANGED
|
@@ -44,6 +44,7 @@ Every document listed under **Fills** is validated against its template by its i
|
|
|
44
44
|
| `templates/USER.md` | `bootstrap/USER.md` | A store that relearns the person's name and preferences every session | IN FORCE 2026-09-26 · procedural ref 361 |
|
|
45
45
|
| `templates/INSTALL.md` | `bootstrap/INSTALL.md` | A paste-block start that cannot check a machine or tag a write | IN FORCE 2026-09-26 · procedural ref 361 |
|
|
46
46
|
| `templates/BOTHANDOFF.md` | `bots/<tag>/HANDOFF.md` (unmapped while DRAFT) | A bot that could close only by writing the user's own handoff and board; scheduled bot runs citing sessions never opened (episodic ref 558, ref 592); bot handoffs marked nonconforming against a template that demands a board | DRAFT — requested by the user 2026-10-01; approval and decision record pending. Supersede-only after revision 1 (`EMET_RECORD_DOCS`) |
|
|
47
|
+
| `templates/TAGHANDOFF.md` | `HANDOFF/<tag>.md` when `EMET_TAG_HANDOFFS` is warn or enforce | Several write tags sharing one handoff, and a board row changed by a tag that did not open it | IN FORCE with the flag. Off, the template is not applied. The view is not a record. |
|
|
47
48
|
| `templates/ROSTER.md` | `bots/ROSTER.md` (unmapped while DRAFT) | A bot tag the server did not treat as a bot because its handoff id was never listed (a live check of per-bot close records, 2026-10-01); the hub's tag at risk of being listed with the bots | DRAFT — requested by the user 2026-10-01; approval and decision record pending. The hub is listed apart and never in `EMET_RECORD_DOCS` |
|
|
48
49
|
| `templates/AREA.md` | `areas/<slug>.md` | A topic page stored as a record, so a view computed from the memory database became a second source of truth (the owner, 2026-10-20). The area document holds the selector only | IN FORCE 2026-10-20 · user. Only the owner creates or edits an area. The page is computed on each read and is never written back |
|
|
49
50
|
| `templates/SESSIONDISPOSITION.md` | `records/*` | A close days later blocked because receipts are compared with the store that day, and a duplicate save_transcript left unmarked (inserted_id 6ae1df09c4da08b2cadc1fb4, 2026-10-28). The disposition notes the session or the transcript. It does not write a receipt and it does not delete the transcript | IN FORCE 2026-10-28 · user, session-disposition brief. A session-level row covers checkpoint overdue. An inserted_id row does not close the session |
|