@dreamforgestudiollc/emet 0.2.4 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/.env.example +63 -0
  2. package/CHANGELOG.md +84 -3
  3. package/CHARTER.md +19 -7
  4. package/README.md +130 -21
  5. package/areas/emet.md +18 -0
  6. package/areas/garden.md +18 -0
  7. package/areas/health.md +18 -0
  8. package/areas/home.md +18 -0
  9. package/areas/learning.md +18 -0
  10. package/areas/state.md +18 -0
  11. package/docs/AUTHORSHIP.md +3 -3
  12. package/docs/BOTS.md +4 -0
  13. package/docs/COVERAGE.md +2 -2
  14. package/docs/DEPLOY.md +41 -5
  15. package/docs/ERROR-CODES-SPEC.md +43 -0
  16. package/docs/ERROR-CODES.md +332 -0
  17. package/docs/GUARDRAILS-AND-MONORAILS.md +2 -1
  18. package/docs/GUIDED-SETUP.md +24 -3
  19. package/docs/PERMISSIONS.md +13 -7
  20. package/docs/ROADMAP.md +18 -15
  21. package/docs/SETUP.md +123 -14
  22. package/docs/SUBKEYS.md +59 -0
  23. package/gems/artifact-index.json +12 -0
  24. package/gems/bot-team-backup/floor.json +15 -0
  25. package/gems/bot-team-backup/gem.json +43 -0
  26. package/gems/bot-team-backup/guides/BOT_TEAM_BACKUP.md +27 -0
  27. package/gems/bot-team-backup/guides/BOT_TEAM_RECOVERY.md +23 -0
  28. package/gems/fieldnote/floor.json +14 -0
  29. package/gems/fieldnote/gem.json +70 -0
  30. package/gems/fieldnote/runes/fieldnote.js +4 -0
  31. package/gems/lean-six-sigma/CHANGELOG.md +10 -0
  32. package/gems/lean-six-sigma/README.md +92 -0
  33. package/gems/lean-six-sigma/floor.json +31 -0
  34. package/gems/lean-six-sigma/gem.json +1296 -0
  35. package/gems/lean-six-sigma/guides/ASSUMPTIONS.md +45 -0
  36. package/gems/lean-six-sigma/guides/BELTS.md +52 -0
  37. package/gems/lean-six-sigma/guides/DMADV.md +56 -0
  38. package/gems/lean-six-sigma/guides/DMAIC.md +127 -0
  39. package/gems/lean-six-sigma/guides/FORMULAS.md +330 -0
  40. package/gems/lean-six-sigma/guides/LEAN.md +97 -0
  41. package/gems/lean-six-sigma/guides/TEMPLATES.md +279 -0
  42. package/gems/lean-six-sigma/runes/lss_capability.js +132 -0
  43. package/gems/lean-six-sigma/runes/lss_control_limits.js +240 -0
  44. package/gems/lean-six-sigma/runes/lss_dpmo_sigma.js +81 -0
  45. package/gems/lean-six-sigma/runes/lss_hypothesis.js +298 -0
  46. package/gems/lean-six-sigma/runes/lss_sample_size.js +81 -0
  47. package/gems/neurendipity/floor.json +65 -0
  48. package/gems/neurendipity/gem.json +42 -0
  49. package/gems/neurendipity/guides/AUTISTIC_BURNOUT.md +81 -0
  50. package/{guides → gems/neurendipity/guides}/NEURODIVERGENT_SUPPORT.md +17 -8
  51. package/guides/README.md +3 -0
  52. package/package.json +12 -5
  53. package/server.json +48 -4
  54. package/src/aleph.js +18 -12
  55. package/src/annotations.js +45 -5
  56. package/src/atlas-role.js +9 -4
  57. package/src/attribution.js +555 -0
  58. package/src/conformance.js +7 -5
  59. package/src/database.js +34 -17
  60. package/src/dispatch.js +136 -16
  61. package/src/env.js +54 -9
  62. package/src/error-codes.js +394 -0
  63. package/src/error-log.js +273 -0
  64. package/src/error-report.js +245 -0
  65. package/src/floor.js +84 -41
  66. package/src/gaps.js +41 -8
  67. package/src/gem-check.js +1360 -0
  68. package/src/guides.js +31 -4
  69. package/src/host-reach.js +23 -0
  70. package/src/http-remote.js +47 -2
  71. package/src/index.js +10 -2
  72. package/src/invites.js +6 -5
  73. package/src/layers.js +9 -8
  74. package/src/lessons-to-checks.js +3 -3
  75. package/src/logger.js +2 -1
  76. package/src/mongo-connect.js +50 -2
  77. package/src/oauth-provider.js +30 -29
  78. package/src/owner-approvals.js +281 -0
  79. package/src/pages.js +806 -0
  80. package/src/persons.js +22 -1
  81. package/src/provenance.js +10 -10
  82. package/src/redact.js +10 -4
  83. package/src/request-log.js +1 -1
  84. package/src/rune-dispatch.js +360 -0
  85. package/src/rune-registry.js +71 -0
  86. package/src/rune-scope.js +42 -0
  87. package/src/scopes.js +3 -0
  88. package/src/session-graph.js +15 -12
  89. package/src/session.js +10 -10
  90. package/src/setup.js +307 -36
  91. package/src/socket.js +545 -0
  92. package/src/startup-pages.js +26 -8
  93. package/src/startup-payload.js +12 -8
  94. package/src/subkey-store.js +358 -0
  95. package/src/subkeys.js +947 -0
  96. package/src/tools.js +518 -204
  97. package/src/transcript-session.js +1 -1
  98. package/src/validation.js +85 -52
  99. package/src/version.js +1 -1
  100. package/templates/AREA.md +35 -0
  101. package/templates/BOARD.md +2 -2
  102. package/templates/BOTHANDOFF.md +2 -2
  103. package/templates/CHARACTER.md +1 -1
  104. package/templates/HANDOFF.md +1 -1
  105. package/templates/IDENTITY.md +1 -1
  106. package/templates/INDEX.md +21 -20
  107. package/templates/INSTALL.md +1 -1
  108. package/templates/PROCEDURE.md +1 -1
  109. package/templates/ROSTER.md +2 -2
  110. package/templates/SEED.md +2 -2
  111. package/templates/STAGING.md +2 -2
  112. package/templates/STANDARD.md +5 -5
  113. package/templates/THREAD.md +1 -1
  114. package/templates/USER.md +4 -1
  115. package/verification/load-gate/corpus.json +1765 -0
  116. package/verification/load-gate/load-gate.mjs +1246 -0
@@ -7,7 +7,7 @@ export const EXCHANGES_PER_PART = 8;
7
7
  /**
8
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
- * carried the next day's date (an incident record: `2026-10-01_grok-init` minted on
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
12
12
  * IANA zone name, default America/New_York. A name the runtime does not know
13
13
  * falls back to the default and says so - marked, never guessed at.
package/src/validation.js CHANGED
@@ -12,6 +12,7 @@
12
12
  */
13
13
 
14
14
  import { IMPORTANCE_BUCKETS } from './layers.js';
15
+ import { isEmetCodeOptions } from './error-codes.js';
15
16
 
16
17
  // ============================================================================
17
18
  // CONSTANTS - Validation Limits
@@ -107,6 +108,17 @@ export const VALID_METADATA_FIELDS = Object.freeze([
107
108
  'importance_degree', // low|mid|high — only when degree inside the bucket matters
108
109
  'provenance_missing', // boolean: no derived_from on a layer whose charter wants one
109
110
  'assertion_origin_missing', // boolean: assertion_origin was not supplied at all
111
+ // Kept RUNE results (GEP-0003). The server sets these on a real seal.
112
+ // `version` alone is an ordinary key. `rune_attested` marks a server seal.
113
+ 'gem',
114
+ 'version',
115
+ 'rune',
116
+ 'served_sha256',
117
+ 'client_sha256',
118
+ 'input_sha256',
119
+ 'input_ref',
120
+ 'principal',
121
+ 'rune_attested',
110
122
  'custom' // Allow a 'custom' object for extensibility
111
123
  ]);
112
124
 
@@ -139,13 +151,21 @@ export const CONTENT_ORIGINS = Object.freeze(['self', 'assistant', 'external']);
139
151
  */
140
152
  export class ValidationError extends Error {
141
153
  constructor(field, message, value = undefined) {
142
- // One-argument calls pass the whole message as `field` (the second reader's fix (b), 2026-10-02): that used to
143
- // render "Validation failed for '<message>': undefined".
154
+ // A trailing { code: 'EMET-...' } is the stable code. It is not a field value
155
+ // and it is not part of the message. One-argument calls pass the whole message
156
+ // as `field` (the second reader's fix (b), 2026-10-02): that used to render
157
+ // "Validation failed for '<message>': undefined".
158
+ let emetCode;
159
+ const fourth = arguments.length > 3 ? arguments[3] : undefined;
160
+ if (isEmetCodeOptions(fourth)) emetCode = fourth.code;
161
+ if (isEmetCodeOptions(value)) { emetCode = value.code; value = undefined; }
162
+ if (isEmetCodeOptions(message)) { emetCode = message.code; message = undefined; }
144
163
  if (message === undefined) { message = field; field = null; }
145
164
  super(field === null ? message : `Validation failed for '${field}': ${message}`);
146
165
  this.name = 'ValidationError';
147
166
  this.field = field;
148
167
  this.validationMessage = message;
168
+ if (emetCode) this.emetCode = emetCode;
149
169
  // Don't expose the actual value in production for security
150
170
  this.invalidValue = process.env.DEBUG === 'true' ? value : '[hidden]';
151
171
  }
@@ -211,24 +231,24 @@ export function isArray(value) {
211
231
  */
212
232
  export function validateContent(content, fieldName = 'content') {
213
233
  if (content === null || content === undefined) {
214
- throw new ValidationError(fieldName, 'Content is required');
234
+ throw new ValidationError(fieldName, 'Content is required', { code: 'EMET-VAL-001' });
215
235
  }
216
236
 
217
237
  if (!isString(content)) {
218
- throw new ValidationError(fieldName, 'Content must be a string', typeof content);
238
+ throw new ValidationError(fieldName, 'Content must be a string', typeof content, { code: 'EMET-VAL-002' });
219
239
  }
220
240
 
221
241
  const trimmed = content.trim();
222
242
 
223
243
  if (trimmed.length < CONTENT_LIMITS.MIN_CONTENT_LENGTH) {
224
- throw new ValidationError(fieldName, `Content must be at least ${CONTENT_LIMITS.MIN_CONTENT_LENGTH} character(s)`);
244
+ throw new ValidationError(fieldName, `Content must be at least ${CONTENT_LIMITS.MIN_CONTENT_LENGTH} character(s)`, { code: 'EMET-VAL-003' });
225
245
  }
226
246
 
227
247
  if (trimmed.length > CONTENT_LIMITS.MAX_CONTENT_LENGTH) {
228
248
  throw new ValidationError(
229
249
  fieldName,
230
250
  `Content exceeds maximum length of ${CONTENT_LIMITS.MAX_CONTENT_LENGTH} characters (got ${trimmed.length})`
231
- );
251
+ , { code: 'EMET-VAL-004' });
232
252
  }
233
253
 
234
254
  return trimmed;
@@ -242,24 +262,24 @@ export function validateContent(content, fieldName = 'content') {
242
262
  */
243
263
  export function validateQuery(query) {
244
264
  if (query === null || query === undefined) {
245
- throw new ValidationError('query', 'Query is required');
265
+ throw new ValidationError('query', 'Query is required', { code: 'EMET-VAL-005' });
246
266
  }
247
267
 
248
268
  if (!isString(query)) {
249
- throw new ValidationError('query', 'Query must be a string', typeof query);
269
+ throw new ValidationError('query', 'Query must be a string', typeof query, { code: 'EMET-VAL-006' });
250
270
  }
251
271
 
252
272
  const trimmed = query.trim();
253
273
 
254
274
  if (trimmed.length < 1) {
255
- throw new ValidationError('query', 'Query cannot be empty');
275
+ throw new ValidationError('query', 'Query cannot be empty', { code: 'EMET-VAL-007' });
256
276
  }
257
277
 
258
278
  if (trimmed.length > CONTENT_LIMITS.MAX_QUERY_LENGTH) {
259
279
  throw new ValidationError(
260
280
  'query',
261
281
  `Query exceeds maximum length of ${CONTENT_LIMITS.MAX_QUERY_LENGTH} characters (got ${trimmed.length})`
262
- );
282
+ , { code: 'EMET-VAL-008' });
263
283
  }
264
284
 
265
285
  return trimmed;
@@ -277,14 +297,14 @@ export function validateContext(context) {
277
297
  }
278
298
 
279
299
  if (!isString(context)) {
280
- throw new ValidationError('context', 'Context must be a string', typeof context);
300
+ throw new ValidationError('context', 'Context must be a string', typeof context, { code: 'EMET-VAL-010' });
281
301
  }
282
302
 
283
303
  if (context.length > CONTENT_LIMITS.MAX_CONTEXT_LENGTH) {
284
304
  throw new ValidationError(
285
305
  'context',
286
306
  `Context exceeds maximum length of ${CONTENT_LIMITS.MAX_CONTEXT_LENGTH} characters (got ${context.length})`
287
- );
307
+ , { code: 'EMET-VAL-011' });
288
308
  }
289
309
 
290
310
  return context;
@@ -304,13 +324,13 @@ export function validateContext(context) {
304
324
  export function validateLayer(layer, required = false) {
305
325
  if (layer === null || layer === undefined || layer === '') {
306
326
  if (required) {
307
- throw new ValidationError('layer', 'Layer is required');
327
+ throw new ValidationError('layer', 'Layer is required', { code: 'EMET-VAL-012' });
308
328
  }
309
329
  return null;
310
330
  }
311
331
 
312
332
  if (!isString(layer)) {
313
- throw new ValidationError('layer', 'Layer must be a string', typeof layer);
333
+ throw new ValidationError('layer', 'Layer must be a string', typeof layer, { code: 'EMET-VAL-013' });
314
334
  }
315
335
 
316
336
  const normalizedLayer = layer.toLowerCase().trim();
@@ -319,7 +339,7 @@ export function validateLayer(layer, required = false) {
319
339
  throw new ValidationError(
320
340
  'layer',
321
341
  `Invalid layer '${normalizedLayer}'. Must be one of: ${VALID_LAYERS.join(', ')}`
322
- );
342
+ , { code: 'EMET-VAL-014' });
323
343
  }
324
344
 
325
345
  return normalizedLayer;
@@ -344,7 +364,7 @@ export function validateNumericRange(value, fieldName, min, max, defaultValue =
344
364
  if (defaultValue !== null) {
345
365
  return defaultValue;
346
366
  }
347
- throw new ValidationError(fieldName, 'Value is required');
367
+ throw new ValidationError(fieldName, 'Value is required', { code: 'EMET-VAL-015' });
348
368
  }
349
369
 
350
370
  // Handle string numbers (e.g., from JSON parsing edge cases)
@@ -354,14 +374,14 @@ export function validateNumericRange(value, fieldName, min, max, defaultValue =
354
374
  }
355
375
 
356
376
  if (!isNumber(numValue)) {
357
- throw new ValidationError(fieldName, 'Value must be a number', value);
377
+ throw new ValidationError(fieldName, 'Value must be a number', value, { code: 'EMET-VAL-016' });
358
378
  }
359
379
 
360
380
  if (numValue < min || numValue > max) {
361
381
  throw new ValidationError(
362
382
  fieldName,
363
383
  `Value must be between ${min} and ${max} (got ${numValue})`
364
- );
384
+ , { code: 'EMET-VAL-017' });
365
385
  }
366
386
 
367
387
  return numValue;
@@ -458,7 +478,7 @@ export function validateMetadata(metadata) {
458
478
  }
459
479
 
460
480
  if (!isPlainObject(metadata)) {
461
- throw new ValidationError('metadata', 'Metadata must be an object', typeof metadata);
481
+ throw new ValidationError('metadata', 'Metadata must be an object', typeof metadata, { code: 'EMET-VAL-018' });
462
482
  }
463
483
 
464
484
  // Check total size of metadata JSON
@@ -467,7 +487,7 @@ export function validateMetadata(metadata) {
467
487
  throw new ValidationError(
468
488
  'metadata',
469
489
  `Metadata exceeds maximum size of ${CONTENT_LIMITS.MAX_METADATA_SIZE} bytes (got ${metadataJson.length})`
470
- );
490
+ , { code: 'EMET-VAL-019' });
471
491
  }
472
492
 
473
493
  const sanitized = {};
@@ -526,7 +546,7 @@ export function validateMetadata(metadata) {
526
546
  'metadata.session_id is not accepted: supply derived_from {session_id, exchange_start, exchange_end} ' +
527
547
  '(a transcript span) or derived_from {entries: [...]} (a consolidation) instead',
528
548
  typeof value
529
- );
549
+ , { code: 'EMET-VAL-020' });
530
550
 
531
551
  case 'category':
532
552
  sanitized.category = validateStringField(value, 'category');
@@ -543,7 +563,7 @@ export function validateMetadata(metadata) {
543
563
  const aliased = validateTimestamp(value, 'expires_at');
544
564
  if (sanitized.valid_until !== undefined && sanitized.valid_until !== null &&
545
565
  aliased !== null && sanitized.valid_until !== aliased) {
546
- throw new ValidationError('expires_at', `expires_at (${aliased}) disagrees with valid_until (${sanitized.valid_until}); supply one`, typeof value);
566
+ throw new ValidationError('expires_at', `expires_at (${aliased}) disagrees with valid_until (${sanitized.valid_until}); supply one`, typeof value, { code: 'EMET-VAL-021' });
547
567
  }
548
568
  if (sanitized.valid_until === undefined || sanitized.valid_until === null) sanitized.valid_until = aliased;
549
569
  break;
@@ -577,7 +597,7 @@ export function validateMetadata(metadata) {
577
597
  // If expires_at was seen first, valid_until is already set from the alias.
578
598
  if (sanitized.valid_until !== undefined && sanitized.valid_until !== null &&
579
599
  canonical !== null && sanitized.valid_until !== canonical) {
580
- throw new ValidationError('valid_until', `valid_until (${canonical}) disagrees with expires_at (${sanitized.valid_until}); supply one`, typeof value);
600
+ throw new ValidationError('valid_until', `valid_until (${canonical}) disagrees with expires_at (${sanitized.valid_until}); supply one`, typeof value, { code: 'EMET-VAL-022' });
581
601
  }
582
602
  sanitized.valid_until = canonical;
583
603
  break;
@@ -591,7 +611,7 @@ export function validateMetadata(metadata) {
591
611
  if (value === null || value === undefined) {
592
612
  sanitized.routing = null;
593
613
  } else if (!isPlainObject(value)) {
594
- throw new ValidationError('routing', 'Routing must be a plain object', typeof value);
614
+ throw new ValidationError('routing', 'Routing must be a plain object', typeof value, { code: 'EMET-VAL-023' });
595
615
  } else {
596
616
  sanitized.routing = value;
597
617
  }
@@ -603,8 +623,9 @@ export function validateMetadata(metadata) {
603
623
  case 'importance_defaulted':
604
624
  case 'provenance_missing':
605
625
  case 'assertion_origin_missing':
626
+ case 'rune_attested':
606
627
  if (typeof value !== 'boolean') {
607
- throw new ValidationError(key, 'Value must be a boolean', typeof value);
628
+ throw new ValidationError(key, 'Value must be a boolean', typeof value, { code: 'EMET-VAL-024' });
608
629
  }
609
630
  sanitized[key] = value;
610
631
  break;
@@ -616,12 +637,24 @@ export function validateMetadata(metadata) {
616
637
  throw new ValidationError(
617
638
  'assertion_origin',
618
639
  `Invalid assertion_origin '${value}'. Must be one of: ${ASSERTION_ORIGINS.join(', ')} (or null)`
619
- );
640
+ , { code: 'EMET-VAL-025' });
620
641
  } else {
621
642
  sanitized.assertion_origin = value;
622
643
  }
623
644
  break;
624
645
 
646
+ case 'gem':
647
+ case 'version':
648
+ case 'rune':
649
+ case 'served_sha256':
650
+ case 'client_sha256':
651
+ case 'input_sha256':
652
+ case 'input_ref':
653
+ case 'principal':
654
+ if (typeof value !== 'string') throw new ValidationError(key, 'Value must be a string', typeof value, { code: 'EMET-VAL-026' });
655
+ sanitized[key] = value;
656
+ break;
657
+
625
658
  case 'custom':
626
659
  // Allow custom object but validate its size
627
660
  if (isPlainObject(value)) {
@@ -629,7 +662,7 @@ export function validateMetadata(metadata) {
629
662
  if (customJson.length <= CONTENT_LIMITS.MAX_METADATA_SIZE / 2) {
630
663
  sanitized.custom = { ...sanitized.custom, ...value };
631
664
  } else {
632
- throw new ValidationError('custom', 'Custom metadata object is too large');
665
+ throw new ValidationError('custom', 'Custom metadata object is too large', { code: 'EMET-VAL-027' });
633
666
  }
634
667
  }
635
668
  break;
@@ -647,7 +680,7 @@ export function validateMetadata(metadata) {
647
680
  throw new ValidationError(
648
681
  'valid_from',
649
682
  `valid_from (${sanitized.valid_from}) cannot be greater than valid_until (${sanitized.valid_until})`
650
- );
683
+ , { code: 'EMET-VAL-028' });
651
684
  }
652
685
  }
653
686
 
@@ -685,7 +718,7 @@ export function relocatedFields(validated) {
685
718
  */
686
719
  export function validatePositiveInteger(value, fieldName) {
687
720
  if (value === null || value === undefined) {
688
- throw new ValidationError(fieldName, 'Value is required');
721
+ throw new ValidationError(fieldName, 'Value is required', { code: 'EMET-VAL-015' });
689
722
  }
690
723
 
691
724
  let numValue = value;
@@ -694,7 +727,7 @@ export function validatePositiveInteger(value, fieldName) {
694
727
  }
695
728
 
696
729
  if (!isNumber(numValue) || !isInteger(numValue) || numValue < NUMERIC_LIMITS.MIN_ID) {
697
- throw new ValidationError(fieldName, 'Value must be a positive integer', value);
730
+ throw new ValidationError(fieldName, 'Value must be a positive integer', value, { code: 'EMET-VAL-029' });
698
731
  }
699
732
 
700
733
  return numValue;
@@ -712,22 +745,22 @@ export function validateTags(tags) {
712
745
  }
713
746
 
714
747
  if (!isArray(tags)) {
715
- throw new ValidationError('tags', 'Tags must be an array', typeof tags);
748
+ throw new ValidationError('tags', 'Tags must be an array', typeof tags, { code: 'EMET-VAL-030' });
716
749
  }
717
750
 
718
751
  if (tags.length > 50) {
719
- throw new ValidationError('tags', 'Too many tags (max 50)');
752
+ throw new ValidationError('tags', 'Too many tags (max 50)', { code: 'EMET-VAL-031' });
720
753
  }
721
754
 
722
755
  const validatedTags = [];
723
756
  for (let i = 0; i < tags.length; i++) {
724
757
  const tag = tags[i];
725
758
  if (!isString(tag)) {
726
- throw new ValidationError(`tags[${i}]`, 'Each tag must be a string', typeof tag);
759
+ throw new ValidationError(`tags[${i}]`, 'Each tag must be a string', typeof tag, { code: 'EMET-VAL-032' });
727
760
  }
728
761
  const trimmed = tag.trim();
729
762
  if (trimmed.length > 100) {
730
- throw new ValidationError(`tags[${i}]`, 'Tag exceeds maximum length of 100 characters');
763
+ throw new ValidationError(`tags[${i}]`, 'Tag exceeds maximum length of 100 characters', { code: 'EMET-VAL-033' });
731
764
  }
732
765
  if (trimmed.length > 0) {
733
766
  validatedTags.push(trimmed);
@@ -749,11 +782,11 @@ export function validateIdArray(ids) {
749
782
  }
750
783
 
751
784
  if (!isArray(ids)) {
752
- throw new ValidationError('related_ids', 'Related IDs must be an array', typeof ids);
785
+ throw new ValidationError('related_ids', 'Related IDs must be an array', typeof ids, { code: 'EMET-VAL-034' });
753
786
  }
754
787
 
755
788
  if (ids.length > 100) {
756
- throw new ValidationError('related_ids', 'Too many related IDs (max 100)');
789
+ throw new ValidationError('related_ids', 'Too many related IDs (max 100)', { code: 'EMET-VAL-035' });
757
790
  }
758
791
 
759
792
  const validatedIds = [];
@@ -786,14 +819,14 @@ export function validateStringField(value, fieldName) {
786
819
  }
787
820
 
788
821
  if (!isString(value)) {
789
- throw new ValidationError(fieldName, 'Value must be a string', typeof value);
822
+ throw new ValidationError(fieldName, 'Value must be a string', typeof value, { code: 'EMET-VAL-026' });
790
823
  }
791
824
 
792
825
  if (value.length > CONTENT_LIMITS.MAX_STRING_FIELD_LENGTH) {
793
826
  throw new ValidationError(
794
827
  fieldName,
795
828
  `Value exceeds maximum length of ${CONTENT_LIMITS.MAX_STRING_FIELD_LENGTH} characters`
796
- );
829
+ , { code: 'EMET-VAL-036' });
797
830
  }
798
831
 
799
832
  return value;
@@ -808,7 +841,7 @@ export function validateStringField(value, fieldName) {
808
841
  * object is discarded silently by design - the validator is a whitelist - so a
809
842
  * caller who passes an unrecognised key gets a full UNFILTERED page back and no
810
843
  * error, which is indistinguishable from "the filter did not work". That
811
- * symptom cost a bug hunt on 2026-09-08 (a recorded lesson). The list is exported
844
+ * symptom cost a bug hunt on 2026-09-08 (semantic ref 259). The list is exported
812
845
  * so callers can NAME the dropped keys instead of swallowing them.
813
846
  */
814
847
  export const RECOGNISED_FILTER_KEYS = Object.freeze([
@@ -849,7 +882,7 @@ export function validateFilters(filters) {
849
882
  }
850
883
 
851
884
  if (!isPlainObject(filters)) {
852
- throw new ValidationError('filters', 'Filters must be an object', typeof filters);
885
+ throw new ValidationError('filters', 'Filters must be an object', typeof filters, { code: 'EMET-VAL-037' });
853
886
  }
854
887
 
855
888
  const validated = {};
@@ -882,7 +915,7 @@ export function validateFilters(filters) {
882
915
  throw new ValidationError(
883
916
  'filters.importance_bucket',
884
917
  `Unknown bucket '${filters.importance_bucket}'. Use constitutive, durable, binding, event, or scratch.`
885
- );
918
+ , { code: 'EMET-VAL-038' });
886
919
  }
887
920
  validated.importance_bucket = name;
888
921
  if (validated.importance_min === undefined) validated.importance_min = spec.range[0];
@@ -926,7 +959,7 @@ export function validateFilters(filters) {
926
959
  throw new ValidationError(
927
960
  'filters.content_contains',
928
961
  `Search term exceeds maximum length of ${CONTENT_LIMITS.MAX_QUERY_LENGTH}`
929
- );
962
+ , { code: 'EMET-VAL-039' });
930
963
  }
931
964
  }
932
965
 
@@ -936,7 +969,7 @@ export function validateFilters(filters) {
936
969
  throw new ValidationError(
937
970
  'filters.context_contains',
938
971
  `Search term exceeds maximum length of ${CONTENT_LIMITS.MAX_QUERY_LENGTH}`
939
- );
972
+ , { code: 'EMET-VAL-040' });
940
973
  }
941
974
  }
942
975
 
@@ -951,7 +984,7 @@ export function validateFilters(filters) {
951
984
  throw new ValidationError(
952
985
  'filters',
953
986
  'importance_min cannot be greater than importance_max'
954
- );
987
+ , { code: 'EMET-VAL-041' });
955
988
  }
956
989
  }
957
990
 
@@ -960,7 +993,7 @@ export function validateFilters(filters) {
960
993
  throw new ValidationError(
961
994
  'filters',
962
995
  'emotional_intensity_min cannot be greater than emotional_intensity_max'
963
- );
996
+ , { code: 'EMET-VAL-042' });
964
997
  }
965
998
  }
966
999
 
@@ -969,7 +1002,7 @@ export function validateFilters(filters) {
969
1002
  throw new ValidationError(
970
1003
  'filters',
971
1004
  'timestamp_after cannot be greater than timestamp_before'
972
- );
1005
+ , { code: 'EMET-VAL-043' });
973
1006
  }
974
1007
  }
975
1008
 
@@ -992,7 +1025,7 @@ export function validateQueryOptions(options) {
992
1025
  }
993
1026
 
994
1027
  if (!isPlainObject(options)) {
995
- throw new ValidationError('options', 'Options must be an object', typeof options);
1028
+ throw new ValidationError('options', 'Options must be an object', typeof options, { code: 'EMET-VAL-044' });
996
1029
  }
997
1030
 
998
1031
  const validated = {};
@@ -1007,7 +1040,7 @@ export function validateQueryOptions(options) {
1007
1040
  // Validate order_by (already sanitized in main code, but validate format here)
1008
1041
  if ('order_by' in options) {
1009
1042
  if (!isString(options.order_by)) {
1010
- throw new ValidationError('options.order_by', 'order_by must be a string');
1043
+ throw new ValidationError('options.order_by', 'order_by must be a string', { code: 'EMET-VAL-045' });
1011
1044
  }
1012
1045
  validated.order_by = options.order_by.trim();
1013
1046
  }
@@ -1048,7 +1081,7 @@ export function validateQueryOptions(options) {
1048
1081
  */
1049
1082
  export function validateRememberInput(args) {
1050
1083
  if (!isPlainObject(args)) {
1051
- throw new ValidationError('args', 'Arguments must be an object');
1084
+ throw new ValidationError('args', 'Arguments must be an object', { code: 'EMET-VAL-046' });
1052
1085
  }
1053
1086
 
1054
1087
  return {
@@ -1063,7 +1096,7 @@ export function validateRememberInput(args) {
1063
1096
  */
1064
1097
  export function validateRecallInput(args) {
1065
1098
  if (!isPlainObject(args)) {
1066
- throw new ValidationError('args', 'Arguments must be an object');
1099
+ throw new ValidationError('args', 'Arguments must be an object', { code: 'EMET-VAL-046' });
1067
1100
  }
1068
1101
 
1069
1102
  return {
@@ -1078,7 +1111,7 @@ export function validateRecallInput(args) {
1078
1111
  */
1079
1112
  export function validateQueryLayerInput(args) {
1080
1113
  if (!isPlainObject(args)) {
1081
- throw new ValidationError('args', 'Arguments must be an object');
1114
+ throw new ValidationError('args', 'Arguments must be an object', { code: 'EMET-VAL-046' });
1082
1115
  }
1083
1116
 
1084
1117
  return {
@@ -1092,7 +1125,7 @@ export function validateQueryLayerInput(args) {
1092
1125
  */
1093
1126
  export function validateSaveToLayerInput(args) {
1094
1127
  if (!isPlainObject(args)) {
1095
- throw new ValidationError('args', 'Arguments must be an object');
1128
+ throw new ValidationError('args', 'Arguments must be an object', { code: 'EMET-VAL-046' });
1096
1129
  }
1097
1130
 
1098
1131
  return {
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.2.4';
2
+ export const EMET_VERSION = '0.3.0';
@@ -0,0 +1,35 @@
1
+ # TEMPLATE — AREA
2
+
3
+ **Template control:** id `templates/AREA.md` · revision: the store's version governs · status: IN FORCE · approved: user · 2026-10-20 · owner: EMET (base) · built to `templates/STANDARD.md` · supersedes: none
4
+ **Fills:** `areas/<slug>.md` — the selector for one compiled topic page.
5
+ **Failure it prevents:** a topic page stored as a record, so a view computed from the memory database became a second source of truth (Alex, 2026-10-20). The page body is never written here.
6
+ **Completion rules:** `templates/STANDARD.md` §5, unmodified.
7
+
8
+ ---
9
+
10
+ ## HOW TO FILL — rules specific to this template
11
+
12
+ 1. **This document is a selector.** It names what to look at: layers, tags, keywords, document prefixes, an optional client list, a staleness window, and a cap. It does not state what is true.
13
+ 2. **The page is computed** by `emet_page` on each request. It is not cached and it is not written back into this document or into any layer.
14
+ 3. **Only the owner's login** creates or edits an area document: a local (stdio) session, or a remote login whose person has the owner role. Other logins, including Member and Guest, cannot. In practice the owner's AI clients make the entries; the server does not tell a bot from a person.
15
+ 4. **Staleness days** defaults to 30 when a record leaves it blank. An area may set its own window.
16
+ 5. **Source clients** `any` reads every client. A list limits the page to those attribution tags.
17
+
18
+ ---
19
+
20
+ ## §0 RECORD CONTROL
21
+ - Template: `templates/AREA.md` · Area revision: the store's version governs
22
+ - Slug: __
23
+ - Title: __
24
+
25
+ ## §1 SELECTOR
26
+ - **Layers:** __
27
+ - **Tags:** __
28
+ - **Keywords:** __
29
+ - **Doc id prefixes:** __
30
+ - **Source clients:** __
31
+ - **Staleness days:** __
32
+ - **Item cap:** __
33
+
34
+ ## §2 SCOPE
35
+ One line naming what the selector looks at. Not a claim of current fact.
@@ -1,6 +1,6 @@
1
1
  # TEMPLATE — BOARD
2
2
 
3
- **Template control:** id `templates/BOARD.md` · revision: the store's version governs · status: IN FORCE · approved: user · 2026-09-11 · a decision record · owner: EMET (base) · built to `templates/STANDARD.md` · decision record: the owner's
3
+ **Template control:** id `templates/BOARD.md` · revision: the store's version governs · status: IN FORCE · approved: user · 2026-09-11 · procedural ref 311 · owner: EMET (base) · built to `templates/STANDARD.md` · decision record: procedural ref 304
4
4
  **Fills:** `STATE.md` — the structured open board. **Replaced in full at every session close; never appended.** The prior revision is archived automatically.
5
5
  **Failure it prevents:** a position document that grew by appended addenda until superseded lines sat above current ones; open items that left the record with no one deciding they should (the reference install lost two job-application actions this way in September 2026); a startup that restated this board's counts instead of naming its items, and a dated section migrated rather than rebuilt that missed three calendar items on its first live revision (reference install, 2026-09-10).
6
6
  **Completion rules:** `templates/STANDARD.md` §5, unmodified.
@@ -13,7 +13,7 @@
13
13
  2. **Rows change status, not membership.** An open row is copied into the next revision unchanged unless something about it changed.
14
14
  3. **A row leaves the open sections only through §4 CLOSED THIS REVISION**, with a disposition and evidence. It appears there once; the following revision may drop it, because the archived revision holds it.
15
15
  4. **The counts in §0 are derived from the rows.** A count that does not match the rows is a nonconformance.
16
- 5. **A dated row whose date has passed without a recorded outcome moves to §3 as `OPEN`, next action "confirm outcome with the user." It is never closed as `DONE` without evidence.** *Prevents:* a passed date closed on an assumed outcome — the reassuring confabulation (reference install: support-structure confabulation; live instance 2026-09-11, an episode publish date resting on a shoot no one had recorded).
16
+ 5. **A dated row whose date has passed without a recorded outcome moves to §3 as `OPEN`, next action "confirm outcome with the user." It is never closed as `DONE` without evidence.** *Prevents:* a passed date closed on an assumed outcome — the reassuring confabulation (reference install, meta ref 16: support-structure confabulation; live instance 2026-09-11, an episode publish date resting on a shoot no one had recorded).
17
17
 
18
18
  ---
19
19
 
@@ -1,8 +1,8 @@
1
1
  # TEMPLATE — BOT HANDOFF
2
2
 
3
- **Template control:** id `templates/BOTHANDOFF.md` · revision: the store's version governs · status: DRAFT, not in force · approved: pending — the user asked for it 2026-10-01; IN FORCE only once the user approves this text and the decision record is filed · owner: EMET (base) · built to `templates/STANDARD.md` · supersedes: none
3
+ **Template control:** id `templates/BOTHANDOFF.md` · revision: the store's version governs · status: DRAFT, not in force · approved: pending — the user asked for it 2026-10-01 the recorded time; IN FORCE only once the user approves this text and the decision record is filed · owner: EMET (base) · built to `templates/STANDARD.md` · supersedes: none
4
4
  **Fills:** `bots/<source tag>/HANDOFF.md` — one bot's own session narrative, written last at each of that bot's closes. Listed in `EMET_RECORD_DOCS`, so it is a record: revision 1 is written plain, every later revision is written whole with `supersedes` set to the revision in force. The hub's `HANDOFF.md` is never filled from this template, and a bot never writes `HANDOFF.md` or `STATE.md` (the server refuses it, `docs/BOTS.md` §5).
5
- **Failure it prevents:** a bot that can reach a complete close only by writing a new revision of the user's own `HANDOFF.md` and revising the user's board, so the user's next session opens on the bot's narrative (found 2026-10-01); scheduled bot runs citing sessions that were never opened, leaving permanent holes in the record (`emet_gaps` pointer disagreements, incident records); and a bot handoff checked against the hub's template, which demands a board the bot does not keep, so every bot close would add a nonconformance marker to the backlog (found on review of a live check, 2026-10-01).
5
+ **Failure it prevents:** a bot that can reach a complete close only by writing a new revision of the user's own `HANDOFF.md` and revising the user's board, so the user's next session opens on the bot's narrative (C1 review note §1a, 2026-10-01); scheduled bot runs citing sessions that were never opened, leaving permanent holes in the record (`emet_gaps` pointer disagreements, episodic ref 558 and ref 592); and a bot handoff checked against the hub's template, which demands a board the bot does not keep, so every bot close would add a nonconformance marker to the backlog (the review note's second read of the C1 live check, 2026-10-01).
6
6
  **Completion rules:** `templates/STANDARD.md` §5, unmodified.
7
7
 
8
8
  ---
@@ -1,6 +1,6 @@
1
1
  # TEMPLATE — CHARACTER
2
2
 
3
- **Template control:** id `templates/CHARACTER.md` · revision: the store's version governs · status: IN FORCE · approved: user · 2026-09-26 · a decision record · owner: EMET (base) · built to `templates/STANDARD.md` · supersedes: none
3
+ **Template control:** id `templates/CHARACTER.md` · revision: the store's version governs · status: IN FORCE · approved: user · 2026-09-26 · procedural ref 361 · owner: EMET (base) · built to `templates/STANDARD.md` · supersedes: none
4
4
  **Fills:** `bootstrap/CHARACTER.md` (also accepted: `bootstrap/SOUL.md`, `bootstrap/PERSONALITY.md`) — how the assistant speaks and engages. Authoritative on voice for the whole session. Modifiers on the floor; never a replacement for it.
5
5
  **Failure it prevents:** a store that boots flattened because identity loaded and character did not, or a personality document with no standing sections so later sessions cannot find tone, limits, or what the assistant will not do (character payload work 2026-09-05; user 2026-09-26: structure ships, personal voice does not).
6
6
  **Completion rules:** `templates/STANDARD.md` §5, unmodified.
@@ -1,6 +1,6 @@
1
1
  # TEMPLATE — HANDOFF
2
2
 
3
- **Template control:** id `templates/HANDOFF.md` · revision: the store's version governs · status: IN FORCE · approved: user · 2026-09-11 · a decision record · owner: EMET (base) · built to `templates/STANDARD.md` · decision record: the owner's
3
+ **Template control:** id `templates/HANDOFF.md` · revision: the store's version governs · status: IN FORCE · approved: user · 2026-09-11 · procedural ref 311 · owner: EMET (base) · built to `templates/STANDARD.md` · decision record: procedural ref 304
4
4
  **Fills:** `HANDOFF.md` — the session narrative, written at every close. Replaced at each close; the prior revision is archived automatically.
5
5
  **Failure it prevents:** a handoff's "nothing pending", true for one session, relayed at the next startup as true for the whole board (reference install, September 2026); a handoff written from memory rather than from the documents, carrying stale priorities (reference install, April 2026); a handoff whose first action was "open by asking the user", so the next startup put nothing in the user's sight (reference install, 2026-09-10).
6
6
  **Completion rules:** `templates/STANDARD.md` §5, unmodified.
@@ -1,6 +1,6 @@
1
1
  # TEMPLATE — IDENTITY
2
2
 
3
- **Template control:** id `templates/IDENTITY.md` · revision: the store's version governs · status: IN FORCE · approved: user · 2026-09-26 · a decision record · owner: EMET (base) · built to `templates/STANDARD.md` · supersedes: none
3
+ **Template control:** id `templates/IDENTITY.md` · revision: the store's version governs · status: IN FORCE · approved: user · 2026-09-26 · procedural ref 361 · owner: EMET (base) · built to `templates/STANDARD.md` · supersedes: none
4
4
  **Fills:** `bootstrap/IDENTITY.md` — who the assistant is. Written at the first-run interview from the user's answers. The user's name for the assistant is the SHEM; this document holds it.
5
5
  **Failure it prevents:** a first-run store with no standing form for identity, so each install invents a different shape and the next session cannot find the name or the verification phrase (held on the register 2026-09-11: bootstrap structure "not yet designed"; user 2026-09-26: the structure ships, the personal data does not).
6
6
  **Completion rules:** `templates/STANDARD.md` §5, unmodified.