@dreamforgestudiollc/emet 0.2.6 → 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 (56) hide show
  1. package/.env.example +10 -0
  2. package/CHANGELOG.md +18 -1
  3. package/README.md +31 -7
  4. package/areas/emet.md +18 -0
  5. package/areas/garden.md +18 -0
  6. package/areas/health.md +18 -0
  7. package/areas/home.md +18 -0
  8. package/areas/learning.md +18 -0
  9. package/areas/state.md +18 -0
  10. package/docs/DEPLOY.md +32 -1
  11. package/docs/ERROR-CODES-SPEC.md +43 -0
  12. package/docs/ERROR-CODES.md +332 -0
  13. package/docs/GUIDED-SETUP.md +16 -0
  14. package/docs/PERMISSIONS.md +8 -5
  15. package/docs/ROADMAP.md +10 -10
  16. package/docs/SETUP.md +115 -12
  17. package/package.json +3 -2
  18. package/server.json +7 -3
  19. package/src/aleph.js +16 -10
  20. package/src/annotations.js +8 -3
  21. package/src/atlas-role.js +8 -3
  22. package/src/attribution.js +12 -12
  23. package/src/conformance.js +6 -4
  24. package/src/database.js +28 -12
  25. package/src/dispatch.js +33 -16
  26. package/src/error-codes.js +394 -0
  27. package/src/error-log.js +273 -0
  28. package/src/error-report.js +245 -0
  29. package/src/floor.js +6 -4
  30. package/src/gaps.js +2 -2
  31. package/src/gem-check.js +27 -26
  32. package/src/http-remote.js +2 -1
  33. package/src/index.js +1 -0
  34. package/src/invites.js +6 -5
  35. package/src/layers.js +8 -7
  36. package/src/mongo-connect.js +5 -0
  37. package/src/oauth-provider.js +28 -27
  38. package/src/pages.js +806 -0
  39. package/src/persons.js +2 -1
  40. package/src/provenance.js +10 -10
  41. package/src/rune-dispatch.js +10 -10
  42. package/src/session-graph.js +16 -15
  43. package/src/session.js +1 -1
  44. package/src/setup.js +21 -17
  45. package/src/startup-pages.js +3 -2
  46. package/src/startup-payload.js +3 -2
  47. package/src/subkey-store.js +3 -2
  48. package/src/tools.js +254 -177
  49. package/src/validation.js +61 -52
  50. package/src/version.js +1 -1
  51. package/templates/AREA.md +35 -0
  52. package/templates/INDEX.md +7 -6
  53. package/templates/PROCEDURE.md +1 -1
  54. package/templates/SEED.md +2 -2
  55. package/templates/STAGING.md +1 -1
  56. package/templates/THREAD.md +1 -1
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
@@ -150,13 +151,21 @@ export const CONTENT_ORIGINS = Object.freeze(['self', 'assistant', 'external']);
150
151
  */
151
152
  export class ValidationError extends Error {
152
153
  constructor(field, message, value = undefined) {
153
- // One-argument calls pass the whole message as `field` (the reviewer's fix (b), 2026-10-02): that used to
154
- // 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; }
155
163
  if (message === undefined) { message = field; field = null; }
156
164
  super(field === null ? message : `Validation failed for '${field}': ${message}`);
157
165
  this.name = 'ValidationError';
158
166
  this.field = field;
159
167
  this.validationMessage = message;
168
+ if (emetCode) this.emetCode = emetCode;
160
169
  // Don't expose the actual value in production for security
161
170
  this.invalidValue = process.env.DEBUG === 'true' ? value : '[hidden]';
162
171
  }
@@ -222,24 +231,24 @@ export function isArray(value) {
222
231
  */
223
232
  export function validateContent(content, fieldName = 'content') {
224
233
  if (content === null || content === undefined) {
225
- throw new ValidationError(fieldName, 'Content is required');
234
+ throw new ValidationError(fieldName, 'Content is required', { code: 'EMET-VAL-001' });
226
235
  }
227
236
 
228
237
  if (!isString(content)) {
229
- 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' });
230
239
  }
231
240
 
232
241
  const trimmed = content.trim();
233
242
 
234
243
  if (trimmed.length < CONTENT_LIMITS.MIN_CONTENT_LENGTH) {
235
- 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' });
236
245
  }
237
246
 
238
247
  if (trimmed.length > CONTENT_LIMITS.MAX_CONTENT_LENGTH) {
239
248
  throw new ValidationError(
240
249
  fieldName,
241
250
  `Content exceeds maximum length of ${CONTENT_LIMITS.MAX_CONTENT_LENGTH} characters (got ${trimmed.length})`
242
- );
251
+ , { code: 'EMET-VAL-004' });
243
252
  }
244
253
 
245
254
  return trimmed;
@@ -253,24 +262,24 @@ export function validateContent(content, fieldName = 'content') {
253
262
  */
254
263
  export function validateQuery(query) {
255
264
  if (query === null || query === undefined) {
256
- throw new ValidationError('query', 'Query is required');
265
+ throw new ValidationError('query', 'Query is required', { code: 'EMET-VAL-005' });
257
266
  }
258
267
 
259
268
  if (!isString(query)) {
260
- 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' });
261
270
  }
262
271
 
263
272
  const trimmed = query.trim();
264
273
 
265
274
  if (trimmed.length < 1) {
266
- throw new ValidationError('query', 'Query cannot be empty');
275
+ throw new ValidationError('query', 'Query cannot be empty', { code: 'EMET-VAL-007' });
267
276
  }
268
277
 
269
278
  if (trimmed.length > CONTENT_LIMITS.MAX_QUERY_LENGTH) {
270
279
  throw new ValidationError(
271
280
  'query',
272
281
  `Query exceeds maximum length of ${CONTENT_LIMITS.MAX_QUERY_LENGTH} characters (got ${trimmed.length})`
273
- );
282
+ , { code: 'EMET-VAL-008' });
274
283
  }
275
284
 
276
285
  return trimmed;
@@ -288,14 +297,14 @@ export function validateContext(context) {
288
297
  }
289
298
 
290
299
  if (!isString(context)) {
291
- 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' });
292
301
  }
293
302
 
294
303
  if (context.length > CONTENT_LIMITS.MAX_CONTEXT_LENGTH) {
295
304
  throw new ValidationError(
296
305
  'context',
297
306
  `Context exceeds maximum length of ${CONTENT_LIMITS.MAX_CONTEXT_LENGTH} characters (got ${context.length})`
298
- );
307
+ , { code: 'EMET-VAL-011' });
299
308
  }
300
309
 
301
310
  return context;
@@ -315,13 +324,13 @@ export function validateContext(context) {
315
324
  export function validateLayer(layer, required = false) {
316
325
  if (layer === null || layer === undefined || layer === '') {
317
326
  if (required) {
318
- throw new ValidationError('layer', 'Layer is required');
327
+ throw new ValidationError('layer', 'Layer is required', { code: 'EMET-VAL-012' });
319
328
  }
320
329
  return null;
321
330
  }
322
331
 
323
332
  if (!isString(layer)) {
324
- 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' });
325
334
  }
326
335
 
327
336
  const normalizedLayer = layer.toLowerCase().trim();
@@ -330,7 +339,7 @@ export function validateLayer(layer, required = false) {
330
339
  throw new ValidationError(
331
340
  'layer',
332
341
  `Invalid layer '${normalizedLayer}'. Must be one of: ${VALID_LAYERS.join(', ')}`
333
- );
342
+ , { code: 'EMET-VAL-014' });
334
343
  }
335
344
 
336
345
  return normalizedLayer;
@@ -355,7 +364,7 @@ export function validateNumericRange(value, fieldName, min, max, defaultValue =
355
364
  if (defaultValue !== null) {
356
365
  return defaultValue;
357
366
  }
358
- throw new ValidationError(fieldName, 'Value is required');
367
+ throw new ValidationError(fieldName, 'Value is required', { code: 'EMET-VAL-015' });
359
368
  }
360
369
 
361
370
  // Handle string numbers (e.g., from JSON parsing edge cases)
@@ -365,14 +374,14 @@ export function validateNumericRange(value, fieldName, min, max, defaultValue =
365
374
  }
366
375
 
367
376
  if (!isNumber(numValue)) {
368
- 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' });
369
378
  }
370
379
 
371
380
  if (numValue < min || numValue > max) {
372
381
  throw new ValidationError(
373
382
  fieldName,
374
383
  `Value must be between ${min} and ${max} (got ${numValue})`
375
- );
384
+ , { code: 'EMET-VAL-017' });
376
385
  }
377
386
 
378
387
  return numValue;
@@ -469,7 +478,7 @@ export function validateMetadata(metadata) {
469
478
  }
470
479
 
471
480
  if (!isPlainObject(metadata)) {
472
- 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' });
473
482
  }
474
483
 
475
484
  // Check total size of metadata JSON
@@ -478,7 +487,7 @@ export function validateMetadata(metadata) {
478
487
  throw new ValidationError(
479
488
  'metadata',
480
489
  `Metadata exceeds maximum size of ${CONTENT_LIMITS.MAX_METADATA_SIZE} bytes (got ${metadataJson.length})`
481
- );
490
+ , { code: 'EMET-VAL-019' });
482
491
  }
483
492
 
484
493
  const sanitized = {};
@@ -537,7 +546,7 @@ export function validateMetadata(metadata) {
537
546
  'metadata.session_id is not accepted: supply derived_from {session_id, exchange_start, exchange_end} ' +
538
547
  '(a transcript span) or derived_from {entries: [...]} (a consolidation) instead',
539
548
  typeof value
540
- );
549
+ , { code: 'EMET-VAL-020' });
541
550
 
542
551
  case 'category':
543
552
  sanitized.category = validateStringField(value, 'category');
@@ -554,7 +563,7 @@ export function validateMetadata(metadata) {
554
563
  const aliased = validateTimestamp(value, 'expires_at');
555
564
  if (sanitized.valid_until !== undefined && sanitized.valid_until !== null &&
556
565
  aliased !== null && sanitized.valid_until !== aliased) {
557
- 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' });
558
567
  }
559
568
  if (sanitized.valid_until === undefined || sanitized.valid_until === null) sanitized.valid_until = aliased;
560
569
  break;
@@ -588,7 +597,7 @@ export function validateMetadata(metadata) {
588
597
  // If expires_at was seen first, valid_until is already set from the alias.
589
598
  if (sanitized.valid_until !== undefined && sanitized.valid_until !== null &&
590
599
  canonical !== null && sanitized.valid_until !== canonical) {
591
- 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' });
592
601
  }
593
602
  sanitized.valid_until = canonical;
594
603
  break;
@@ -602,7 +611,7 @@ export function validateMetadata(metadata) {
602
611
  if (value === null || value === undefined) {
603
612
  sanitized.routing = null;
604
613
  } else if (!isPlainObject(value)) {
605
- 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' });
606
615
  } else {
607
616
  sanitized.routing = value;
608
617
  }
@@ -616,7 +625,7 @@ export function validateMetadata(metadata) {
616
625
  case 'assertion_origin_missing':
617
626
  case 'rune_attested':
618
627
  if (typeof value !== 'boolean') {
619
- 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' });
620
629
  }
621
630
  sanitized[key] = value;
622
631
  break;
@@ -628,7 +637,7 @@ export function validateMetadata(metadata) {
628
637
  throw new ValidationError(
629
638
  'assertion_origin',
630
639
  `Invalid assertion_origin '${value}'. Must be one of: ${ASSERTION_ORIGINS.join(', ')} (or null)`
631
- );
640
+ , { code: 'EMET-VAL-025' });
632
641
  } else {
633
642
  sanitized.assertion_origin = value;
634
643
  }
@@ -642,7 +651,7 @@ export function validateMetadata(metadata) {
642
651
  case 'input_sha256':
643
652
  case 'input_ref':
644
653
  case 'principal':
645
- if (typeof value !== 'string') throw new ValidationError(key, 'Value must be a string', typeof value);
654
+ if (typeof value !== 'string') throw new ValidationError(key, 'Value must be a string', typeof value, { code: 'EMET-VAL-026' });
646
655
  sanitized[key] = value;
647
656
  break;
648
657
 
@@ -653,7 +662,7 @@ export function validateMetadata(metadata) {
653
662
  if (customJson.length <= CONTENT_LIMITS.MAX_METADATA_SIZE / 2) {
654
663
  sanitized.custom = { ...sanitized.custom, ...value };
655
664
  } else {
656
- 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' });
657
666
  }
658
667
  }
659
668
  break;
@@ -671,7 +680,7 @@ export function validateMetadata(metadata) {
671
680
  throw new ValidationError(
672
681
  'valid_from',
673
682
  `valid_from (${sanitized.valid_from}) cannot be greater than valid_until (${sanitized.valid_until})`
674
- );
683
+ , { code: 'EMET-VAL-028' });
675
684
  }
676
685
  }
677
686
 
@@ -709,7 +718,7 @@ export function relocatedFields(validated) {
709
718
  */
710
719
  export function validatePositiveInteger(value, fieldName) {
711
720
  if (value === null || value === undefined) {
712
- throw new ValidationError(fieldName, 'Value is required');
721
+ throw new ValidationError(fieldName, 'Value is required', { code: 'EMET-VAL-015' });
713
722
  }
714
723
 
715
724
  let numValue = value;
@@ -718,7 +727,7 @@ export function validatePositiveInteger(value, fieldName) {
718
727
  }
719
728
 
720
729
  if (!isNumber(numValue) || !isInteger(numValue) || numValue < NUMERIC_LIMITS.MIN_ID) {
721
- 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' });
722
731
  }
723
732
 
724
733
  return numValue;
@@ -736,22 +745,22 @@ export function validateTags(tags) {
736
745
  }
737
746
 
738
747
  if (!isArray(tags)) {
739
- 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' });
740
749
  }
741
750
 
742
751
  if (tags.length > 50) {
743
- throw new ValidationError('tags', 'Too many tags (max 50)');
752
+ throw new ValidationError('tags', 'Too many tags (max 50)', { code: 'EMET-VAL-031' });
744
753
  }
745
754
 
746
755
  const validatedTags = [];
747
756
  for (let i = 0; i < tags.length; i++) {
748
757
  const tag = tags[i];
749
758
  if (!isString(tag)) {
750
- 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' });
751
760
  }
752
761
  const trimmed = tag.trim();
753
762
  if (trimmed.length > 100) {
754
- 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' });
755
764
  }
756
765
  if (trimmed.length > 0) {
757
766
  validatedTags.push(trimmed);
@@ -773,11 +782,11 @@ export function validateIdArray(ids) {
773
782
  }
774
783
 
775
784
  if (!isArray(ids)) {
776
- 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' });
777
786
  }
778
787
 
779
788
  if (ids.length > 100) {
780
- 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' });
781
790
  }
782
791
 
783
792
  const validatedIds = [];
@@ -810,14 +819,14 @@ export function validateStringField(value, fieldName) {
810
819
  }
811
820
 
812
821
  if (!isString(value)) {
813
- 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' });
814
823
  }
815
824
 
816
825
  if (value.length > CONTENT_LIMITS.MAX_STRING_FIELD_LENGTH) {
817
826
  throw new ValidationError(
818
827
  fieldName,
819
828
  `Value exceeds maximum length of ${CONTENT_LIMITS.MAX_STRING_FIELD_LENGTH} characters`
820
- );
829
+ , { code: 'EMET-VAL-036' });
821
830
  }
822
831
 
823
832
  return value;
@@ -873,7 +882,7 @@ export function validateFilters(filters) {
873
882
  }
874
883
 
875
884
  if (!isPlainObject(filters)) {
876
- 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' });
877
886
  }
878
887
 
879
888
  const validated = {};
@@ -906,7 +915,7 @@ export function validateFilters(filters) {
906
915
  throw new ValidationError(
907
916
  'filters.importance_bucket',
908
917
  `Unknown bucket '${filters.importance_bucket}'. Use constitutive, durable, binding, event, or scratch.`
909
- );
918
+ , { code: 'EMET-VAL-038' });
910
919
  }
911
920
  validated.importance_bucket = name;
912
921
  if (validated.importance_min === undefined) validated.importance_min = spec.range[0];
@@ -950,7 +959,7 @@ export function validateFilters(filters) {
950
959
  throw new ValidationError(
951
960
  'filters.content_contains',
952
961
  `Search term exceeds maximum length of ${CONTENT_LIMITS.MAX_QUERY_LENGTH}`
953
- );
962
+ , { code: 'EMET-VAL-039' });
954
963
  }
955
964
  }
956
965
 
@@ -960,7 +969,7 @@ export function validateFilters(filters) {
960
969
  throw new ValidationError(
961
970
  'filters.context_contains',
962
971
  `Search term exceeds maximum length of ${CONTENT_LIMITS.MAX_QUERY_LENGTH}`
963
- );
972
+ , { code: 'EMET-VAL-040' });
964
973
  }
965
974
  }
966
975
 
@@ -975,7 +984,7 @@ export function validateFilters(filters) {
975
984
  throw new ValidationError(
976
985
  'filters',
977
986
  'importance_min cannot be greater than importance_max'
978
- );
987
+ , { code: 'EMET-VAL-041' });
979
988
  }
980
989
  }
981
990
 
@@ -984,7 +993,7 @@ export function validateFilters(filters) {
984
993
  throw new ValidationError(
985
994
  'filters',
986
995
  'emotional_intensity_min cannot be greater than emotional_intensity_max'
987
- );
996
+ , { code: 'EMET-VAL-042' });
988
997
  }
989
998
  }
990
999
 
@@ -993,7 +1002,7 @@ export function validateFilters(filters) {
993
1002
  throw new ValidationError(
994
1003
  'filters',
995
1004
  'timestamp_after cannot be greater than timestamp_before'
996
- );
1005
+ , { code: 'EMET-VAL-043' });
997
1006
  }
998
1007
  }
999
1008
 
@@ -1016,7 +1025,7 @@ export function validateQueryOptions(options) {
1016
1025
  }
1017
1026
 
1018
1027
  if (!isPlainObject(options)) {
1019
- 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' });
1020
1029
  }
1021
1030
 
1022
1031
  const validated = {};
@@ -1031,7 +1040,7 @@ export function validateQueryOptions(options) {
1031
1040
  // Validate order_by (already sanitized in main code, but validate format here)
1032
1041
  if ('order_by' in options) {
1033
1042
  if (!isString(options.order_by)) {
1034
- 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' });
1035
1044
  }
1036
1045
  validated.order_by = options.order_by.trim();
1037
1046
  }
@@ -1072,7 +1081,7 @@ export function validateQueryOptions(options) {
1072
1081
  */
1073
1082
  export function validateRememberInput(args) {
1074
1083
  if (!isPlainObject(args)) {
1075
- throw new ValidationError('args', 'Arguments must be an object');
1084
+ throw new ValidationError('args', 'Arguments must be an object', { code: 'EMET-VAL-046' });
1076
1085
  }
1077
1086
 
1078
1087
  return {
@@ -1087,7 +1096,7 @@ export function validateRememberInput(args) {
1087
1096
  */
1088
1097
  export function validateRecallInput(args) {
1089
1098
  if (!isPlainObject(args)) {
1090
- throw new ValidationError('args', 'Arguments must be an object');
1099
+ throw new ValidationError('args', 'Arguments must be an object', { code: 'EMET-VAL-046' });
1091
1100
  }
1092
1101
 
1093
1102
  return {
@@ -1102,7 +1111,7 @@ export function validateRecallInput(args) {
1102
1111
  */
1103
1112
  export function validateQueryLayerInput(args) {
1104
1113
  if (!isPlainObject(args)) {
1105
- throw new ValidationError('args', 'Arguments must be an object');
1114
+ throw new ValidationError('args', 'Arguments must be an object', { code: 'EMET-VAL-046' });
1106
1115
  }
1107
1116
 
1108
1117
  return {
@@ -1116,7 +1125,7 @@ export function validateQueryLayerInput(args) {
1116
1125
  */
1117
1126
  export function validateSaveToLayerInput(args) {
1118
1127
  if (!isPlainObject(args)) {
1119
- throw new ValidationError('args', 'Arguments must be an object');
1128
+ throw new ValidationError('args', 'Arguments must be an object', { code: 'EMET-VAL-046' });
1120
1129
  }
1121
1130
 
1122
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.6';
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
  # EMET CONTROLLED DOCUMENT LIBRARY — REGISTER
2
2
 
3
- **Status:** **ADOPTED by the user 2026-09-11** (*"Yes I do"*; procedural ref 311). **IN FORCE with the repository commit** (board 014), because the shipped copy governs (`templates/STANDARD.md` §9a L1; `CHARTER.md` §9). Revision: the store's version governs. Decision records: procedural ref 300 → ref 301 (scope), ref 302 (latitude), ref 303 → ref 304 (validation not optional; mark for audit and review); review of 2026-09-11: ref 306 (validation v1, shipping), ref 307 (locks), ref 308 (close order), ref 309 (charter lock), ref 310 (seed statuses and triggers).
3
+ **Status:** **ADOPTED by the user 2026-09-11** (*"Yes I do"*; procedural ref 311). **IN FORCE with the repository commit** (board 14), because the shipped copy governs (`templates/STANDARD.md` §9a L1; `CHARTER.md` §9). Revision: the store's version governs. Decision records: procedural ref 300 → ref 301 (scope), ref 302 (latitude), ref 303 → ref 304 (validation not optional; mark for audit and review); review of 2026-09-11: ref 306 (validation v1, shipping), ref 307 (locks), ref 308 (close order), ref 309 (charter lock), ref 310 (seed statuses and triggers).
4
4
  **Written:** 2026-09-10. **Brought current** 2026-09-11, session `2026-09-11_morning-mobile-init`, source `mobile`, after the user's full review of the set. **This revision also removes install-specific names** — the reference install's orchestrator, private documents, named employers, machine paths and seed names — under the scope rule that shipped forms are generic (ref 301). The reference install's own records keep them.
5
5
 
6
6
  ---
@@ -22,7 +22,7 @@
22
22
  | **1 — Charter** | What EMET is, what it is for, how it is structured, how information flows, how documents are controlled | `CHARTER.md` — DRAFT; locked like the base templates: ships with the release, a store copy is not authoritative, and it is present before any first-run interview |
23
23
  | **2 — Procedures** | How a session runs, start to close | The floor, layer charter, startup instructions and close protocol — in server code, pointed to. The close order is stated once, in `CHARTER.md` §6. An install may add its own orchestrator; it points here and restates nothing |
24
24
  | **3 — Work instructions and reference** | How to do a specific thing | `procedures/*` (PROCEDURE template) · an install's own reference and debug documents |
25
- | **4 — Forms and records** | Templates (forms) and the documents filled from them (records) | `templates/*` → `HANDOFF.md`, `STATE.md`, `threads/*`, `seeds/*`, `staging/*`, `procedures/*` · layer entries and transcripts (structure enforced by code) |
25
+ | **4 — Forms and records** | Templates (forms) and the documents filled from them (records) | `templates/*` → `HANDOFF.md`, `STATE.md`, `threads/*`, `seeds/*`, `staging/*`, `procedures/*`, `areas/*` · layer entries and transcripts (structure enforced by code) |
26
26
 
27
27
  ---
28
28
 
@@ -45,6 +45,7 @@ Every document listed under **Fills** is validated against its template by its i
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
47
  | `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
+ | `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 (Alex, 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 |
48
49
 
49
50
  **Deliberately NOT templated:** an install's own orchestrator (a single document, not a type) · layer entries and transcripts (structure already enforced by the write-path door) · an install's private reference documents that have their own convention and no recorded failure.
50
51
 
@@ -56,13 +57,13 @@ Every document listed under **Fills** is validated against its template by its i
56
57
 
57
58
  0. ~~STANDARD~~ — written 2026-09-10.
58
59
  1. ~~HANDOFF + BOARD~~ — written 2026-09-10; in trial use.
59
- 2. ~~CHARTER~~ — written 2026-09-10; §1 intended use awaits the user's words (board 010).
60
+ 2. ~~CHARTER~~ — written 2026-09-10; §1 intended use awaits the user's words (board 10).
60
61
  3. ~~SEED + THREAD~~ — written 2026-09-10 evening.
61
62
  4. ~~STAGING + PROCEDURE~~ — written 2026-09-10 evening.
62
63
  5. ~~Migrate the position document into the BOARD form~~ — done 2026-09-10.
63
64
  6. ~~Review of the full set with the user~~ — done 2026-09-11.
64
65
  7. **Validation v1** — DECIDED 2026-09-11 (ref 306, ref 307): the priced scope plus locks L1–L6. Not built — bridged session.
65
- 8. **Repository commit** (board 014) — the charter and templates ship in the release; the set becomes IN FORCE with it.
66
+ 8. **Repository commit** (board 14) — the charter and templates ship in the release; the set becomes IN FORCE with it.
66
67
 
67
68
  ## LATITUDE — DECIDED (user, 2026-09-10; procedural ref 302)
68
69
  *"They must be followed but can be expanded and there can be a generic template standard guidlines for anything added above and beyond will be created within those guidelines."* Base templates: required sections fixed; installs may expand, never loosen. Anything beyond the base is built to `templates/STANDARD.md`.
@@ -78,5 +79,5 @@ Every document listed under **Fills** is validated against its template by its i
78
79
  ## OPEN — the user's
79
80
  - **Adoption — DECIDED 2026-09-11** (procedural ref 311). IN FORCE with the repository commit.
80
81
  - **Where local templates live** in an install's store.
81
- - **Intended-use statement** for the charter (board 010).
82
- - **The disclosure line** (board 016) — before the repository goes public.
82
+ - **Intended-use statement** for the charter (board 10).
83
+ - **The disclosure line** (board 16) — before the repository goes public.
@@ -1,6 +1,6 @@
1
1
  # TEMPLATE — PROCEDURE
2
2
 
3
- **Template control:** id `templates/PROCEDURE.md` · revision: the store's version governs · status: IN FORCE · approved: user · 2026-09-11 · procedural ref 311 (board 011) · owner: EMET (base) · built to `templates/STANDARD.md` · supersedes: none
3
+ **Template control:** id `templates/PROCEDURE.md` · revision: the store's version governs · status: IN FORCE · approved: user · 2026-09-11 · procedural ref 311 (board 11) · owner: EMET (base) · built to `templates/STANDARD.md` · supersedes: none
4
4
  **Fills:** `procedures/<name>.md` — reference procedures and work instructions: how to do one specific thing on one specific system (Tier 3). **Every `procedures/*` document is validated against this template by its id** (`templates/STANDARD.md` §9 map); leaving out the control block does not exempt it (§9a L4). Work instructions that exist outside the store come in when they are next rewritten, not before.
5
5
  **Failure it prevents:** recorded paths and commands that went stale unverified and failed silently when followed — an interpreter path that no longer existed carried in two bootstrap documents for months; a deploy command naming the project instead of the service (reference install, August–September 2026).
6
6
  **Completion rules:** `templates/STANDARD.md` §5, unmodified.
package/templates/SEED.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # TEMPLATE — SEED
2
2
 
3
- **Template control:** id `templates/SEED.md` · revision: the store's version governs · status: IN FORCE · approved: user · 2026-09-13 (record control stated once, as front matter — the user's instruction; prior approval 2026-09-11 · procedural ref 311 (board 011)) · owner: EMET (base) · built to `templates/STANDARD.md` · supersedes: none
3
+ **Template control:** id `templates/SEED.md` · revision: the store's version governs · status: IN FORCE · approved: user · 2026-09-13 (record control stated once, as front matter — the user's instruction; prior approval 2026-09-11 · procedural ref 311 (board 11)) · owner: EMET (base) · built to `templates/STANDARD.md` · supersedes: none
4
4
  **Fills:** `seeds/<name>.md` — an idea that is valid but wrongly timed, parked with the condition that brings it back.
5
5
  **Failure it prevents:** a met trigger that sat unsurfaced for weeks because nothing at startup could tell it had fired (reference install, 2026-09-10); triggers that name an event nobody scheduled, so they could never fire (three seeds waiting on a "post-certification review" that was never put on a calendar, same date); a seed that had already been executed still sitting as a seed, read at every startup as live (reference install, supersession work, August 2026).
6
6
  **Completion rules:** `templates/STANDARD.md` §5, unmodified.
@@ -13,7 +13,7 @@
13
13
 
14
14
  1. **Every trigger is testable without asking the user.** It is one of four kinds, and nothing else:
15
15
  - `DATE` — a calendar date. Fires on or after it.
16
- - `ROW` — a board row id and the change that fires it (`board 018 opens`, `board 011 closes`). The board row must exist when the seed is planted; if it does not, open one.
16
+ - `ROW` — a board row id and the change that fires it (`board 18 opens`, `board 11 closes`). The board row must exist when the seed is planted; if it does not, open one.
17
17
  - `SIGNAL` — something a startup can observe by name: a named document reaching a named state, a named external item closing. **Name where it is checked.**
18
18
  - `TOPIC` — the user raises a named subject. **Checked during the session, not at startup:** list the subject words in the trigger so any session that has scanned the seed recognises them when they come up. *Prevents:* outlawing a trigger that works — the reference install's first-run-experience seed fired correctly this way on 2026-09-11.
19
19
  A trigger that names an event with no date and no board row ("after the review", "when there is time") is a nonconformance: plant it as `ROW` against a row that schedules the event, or as `DATE`.
@@ -1,6 +1,6 @@
1
1
  # TEMPLATE — STAGING
2
2
 
3
- **Template control:** id `templates/STAGING.md` · revision: the store's version governs · status: IN FORCE · approved: user · 2026-09-11 · procedural ref 311 (board 011) · owner: EMET (base) · built to `templates/STANDARD.md` · supersedes: none
3
+ **Template control:** id `templates/STAGING.md` · revision: the store's version governs · status: IN FORCE · approved: user · 2026-09-11 · procedural ref 311 (board 11) · owner: EMET (base) · built to `templates/STANDARD.md` · supersedes: none
4
4
  **Fills:** `staging/<name>-<yyyy-mm>.md` — work lists, proposals, pricings, research notes: anything that is worked on before it is decided.
5
5
  **Failure it prevents:** an instance-authored proposal read later as a decision — a delete tool was specified from a staging note nobody had approved, and the note contradicted itself (reference install, procedural ref 296); drafts with no visible status, so a reader could not tell a priced option from an adopted one.
6
6
  **Completion rules:** `templates/STANDARD.md` §5, unmodified.
@@ -1,6 +1,6 @@
1
1
  # TEMPLATE — THREAD
2
2
 
3
- **Template control:** id `templates/THREAD.md` · revision: the store's version governs · status: IN FORCE · approved: user · 2026-09-11 · procedural ref 311 (board 011) · owner: EMET (base) · built to `templates/STANDARD.md` · supersedes: none
3
+ **Template control:** id `templates/THREAD.md` · revision: the store's version governs · status: IN FORCE · approved: user · 2026-09-11 · procedural ref 311 (board 11) · owner: EMET (base) · built to `templates/STANDARD.md` · supersedes: none
4
4
  **Fills:** `threads/<name>.md` — the working document for one project or line of work: its current position, its decisions and their reasons, and a dated log.
5
5
  **Failure it prevents:** threads grown by appended sections until the current state sat under hundreds of kilobytes of history (reference install: two threads at 147 KB and 328 KB). A phone session did not read one — the mobile startup skips threads by rule — so the board marked its career rows `NOT COMPLETED` (2026-09-10); whether a phone session could read a thread that size was never tested. When it was read, its priority list still told the user to submit an application that had been submitted two weeks earlier — the current state was never rewritten, only appended to.
6
6
  **Completion rules:** `templates/STANDARD.md` §5, unmodified.