@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
@@ -1,10 +1,11 @@
1
1
  /**
2
- * EMET - the session graph: the monorail under the guardrails (2026-09-29;
3
- * the practice is docs/GUARDRAILS-AND-MONORAILS.md).
2
+ * EMET - the session graph: the monorail under the guardrails (2026-09-29,
3
+ * board board 120, design staging/emet-session-graph.md; the practice is
4
+ * docs/GUARDRAILS-AND-MONORAILS.md).
4
5
  *
5
- * The owner: "guardrails give a field of movement and execution to allow an AI to do
6
+ * Alex: "guardrails give a field of movement and execution to allow an AI to do
6
7
  * processes where rails guide the AI through a process flow without it
7
- * processing" (a recorded lesson). The floor, the character and the served
8
+ * processing" (semantic ref 297). The floor, the character and the served
8
9
  * instructions are the guardrails. This file is the monorail - the car cannot
9
10
  * leave the beam; where a flow forks, a small switch owned by the track (never
10
11
  * the model) picks the branch (designed 2026-09-29, not yet built): the next step of a
@@ -49,6 +50,7 @@
49
50
  */
50
51
 
51
52
  import { setting } from './env.js';
53
+ import { CodedError } from './error-codes.js';
52
54
 
53
55
  export const GRAPH_MODES = Object.freeze(['enforce']);
54
56
 
@@ -68,18 +70,19 @@ export const HANDOFF_DOC = 'HANDOFF.md';
68
70
  export const BOARD_DOC = 'STATE.md';
69
71
 
70
72
  /**
71
- * Per-bot close records (C1, 2026-10-01; the owner's decisions 1-7). The rule, stated once: a session written
73
+ * Per-bot close records (C1, 2026-10-01; review note "C1: per-bot close
74
+ * records", the owner's decisions 1-7). The rule, stated once: a session written
72
75
  * under a bot's source tag closes against that bot's own records
73
76
  * (bots/<tag>/HANDOFF.md); only that tag's own revisions in the session window
74
77
  * count; a bot tag never writes or cites the main HANDOFF.md or STATE.md.
75
78
  *
76
79
  * A tag T is a BOT TAG when bots/T/HANDOFF.md is listed in EMET_RECORD_DOCS,
77
80
  * the list that already marks ids as supersede-only records (tools.js
78
- * recordDocIds). No new setting: the owner adds one id per bot, and removing it
81
+ * recordDocIds). No new setting: Alex adds one id per bot, and removing it
79
82
  * puts that tag back on the host rules. Bot records are named by the source
80
83
  * tag itself (decision 1), so no tag-to-name mapping exists. These are pure
81
84
  * reads of settings - no database - so the graph can key its bot-handoff gate
82
- * on a write's `source` without an extra read.
85
+ * on a write's `source` without an extra read (review note section 5).
83
86
  */
84
87
  export function botRecordDir(tag) { return `bots/${tag}/`; }
85
88
  export function botHandoffDoc(tag) { return `bots/${tag}/HANDOFF.md`; }
@@ -101,7 +104,7 @@ export function mainRecordIds() {
101
104
  * The source tag a write names, read as dispatch.js sourceOf reads it
102
105
  * (`source`, then the older aliases). Repeated here because dispatch imports
103
106
  * this module. No default: a write with no source takes the host path in the
104
- * graph.
107
+ * graph (review note section 5).
105
108
  */
106
109
  export function writeSourceOf(args = {}) {
107
110
  const v = args.source ?? args.updated_by ?? args.retired_by ?? args.accepted_by ?? args.channel ?? null;
@@ -163,7 +166,7 @@ export function groupedUnder(sessionId, base) {
163
166
  /**
164
167
  * The session a call names: `session_id`, else the transcript span in
165
168
  * `metadata.derived_from` (revise_memory refuses metadata.session_id and names
166
- * its session there - live-caught 2026-09-29, a recorded lesson), else - for
169
+ * its session there - live-caught 2026-09-29, semantic ref 295), else - for
167
170
  * emet_session_close, the only tool that takes `receipts` -
168
171
  * `receipts.transcript_session_id`. The close tool's description documents
169
172
  * that shape ("receipts.transcript_session_id is used when this is omitted")
@@ -208,7 +211,7 @@ export function normalizeExchangeNumber(v) {
208
211
  let n = v;
209
212
  if (typeof n === 'string' && /^\s*\d+\s*$/.test(n)) n = Number(n);
210
213
  if (typeof n === 'number' && Number.isInteger(n) && n >= 1) return { value: n };
211
- return { error: `exchange_index must be a whole number, 1 or more (got ${JSON.stringify(v)})` };
214
+ return { error: `exchange_index must be a whole number, 1 or more (got ${JSON.stringify(v)})`, emet_code: 'EMET-TRN-010' };
212
215
  }
213
216
 
214
217
  /** The exchange a call declares, if any: `exchange` on writes, `exchange_index` on an append. */
@@ -553,7 +556,7 @@ export async function closedSessionGuard(tool, args = {}, dbManager, now = new D
553
556
  let pos;
554
557
  try {
555
558
  pos = typeof dbManager.transcriptPosition === 'function' ? await dbManager.transcriptPosition(base) : null;
556
- if (!pos || typeof pos.highest !== 'number') throw new Error('the transcript position is not available');
559
+ if (!pos || typeof pos.highest !== 'number') throw new CodedError('the transcript position is not available', { code: 'EMET-SESS-001' });
557
560
  } catch (e) { throw await unreadable(tool, base, 'the transcript position', e); }
558
561
  const highest = pos.highest;
559
562
  const declared = declaredExchange(tool, args);
@@ -767,7 +770,7 @@ export async function graphBefore(tool, args, dbManager, now = new Date()) {
767
770
  }
768
771
 
769
772
  // ---------------------------------------------------------------------------
770
- // Lab results (2026-09-29, the owner: "a 'lab results' location for storing the
773
+ // Lab results (2026-09-29, Alex: "a 'lab results' location for storing the
771
774
  // results in real time with time stamps so we can have a resource to look at
772
775
  // after the probationary period"). Every check the monorail makes - ok,
773
776
  // refuse, unknown (would_refuse in rows from before enforce-only) - is one timestamped row in
package/src/session.js CHANGED
@@ -95,7 +95,7 @@ export const CLOSE_PROTOCOL = Object.freeze([
95
95
  async function connect() {
96
96
  const { testClientActive } = await import('./mongo-connect.js');
97
97
  if (!MONGODB_URI && !testClientActive()) {
98
- throw new DatabaseError('MONGODB_URI is not set; cannot verify session artifacts.');
98
+ throw new DatabaseError('MONGODB_URI is not set; cannot verify session artifacts.', { code: 'EMET-DB-001' });
99
99
  }
100
100
  const client = await connectMongo(MONGODB_URI || 'mongodb://test', { serverSelectionTimeoutMS: 15000 });
101
101
  return { client, db: client.db(MONGODB_DB) };
@@ -322,7 +322,7 @@ export async function corroborateCoverage(db, baseId) {
322
322
  // correction makes the check permanently worse, and the flag can never
323
323
  // clear because superseded entries cannot be edited. Found live at the
324
324
  // 2026-09-11 close: nine entries superseded with correct spans, and the
325
- // check still read the old record's 31-33 against a 27-exchange session.
325
+ // check still read the old ref 314's 31-33 against a 27-exchange session.
326
326
  // Every other read in EMET hides superseded entries by default; this one
327
327
  // now does too - and says how many it set aside, because dropping
328
328
  // evidence silently is the other half of the same mistake.
@@ -354,7 +354,7 @@ export async function corroborateCoverage(db, baseId) {
354
354
  * The store check above answers "do the artifacts exist". It could not answer
355
355
  * "did the host actually do each step", and a host that skipped a step, or
356
356
  * never read the transcript back, could still walk away with `complete`
357
- * because the store happened to look fine. The owner's requirement (a decision record,
357
+ * because the store happened to look fine. the owner's requirement (procedural ref 388,
358
358
  * 389, 391): the wrap steps HAVE TO BE FOLLOWED, whichever model is hosting,
359
359
  * and a skipped step blocks the close the same way a skipped opening is caught
360
360
  * at initialize.
@@ -387,7 +387,7 @@ export const RECEIPT_FIELDS = Object.freeze({
387
387
  });
388
388
 
389
389
  /**
390
- * A bot session's receipts (C1, 2026-10-01).
390
+ * A bot session's receipts (C1, 2026-10-01; review note section 3.3).
391
391
  * Seven: no board is required - a bot that keeps one lists it under
392
392
  * bots/<tag>/ as board_doc (checked when given) or as a working document - and
393
393
  * handoff_doc names the bot's own handoff. Host receipts stay at the eight
@@ -403,7 +403,7 @@ export const BOT_RECEIPT_FIELDS = Object.freeze({
403
403
  handoff_version: RECEIPT_FIELDS.handoff_version
404
404
  });
405
405
 
406
- /** The message every bot-records refusal carries. */
406
+ /** The message every bot-records refusal carries (review note section 3.5). */
407
407
  export function hubRecordsMessage(tag) {
408
408
  return `a bot session closes against ${botRecordDir(tag)} records; the main handoff and board are the hub's`;
409
409
  }
@@ -429,7 +429,7 @@ export function sessionTagOf(rows = []) {
429
429
  * Hosts do not all pass an object argument the same way. A client working from
430
430
  * a cached tool list that predates `receipts` - or a host that serialises every
431
431
  * nested argument - sends the receipts as JSON TEXT. Found live at the first
432
- * close under the new rule (2026-09-26, cloud-host): every artifact present,
432
+ * close under the new rule (2026-09-26, cowork-cloud): every artifact present,
433
433
  * receipts sent, and the server saw none. Consistent execution across hosts
434
434
  * means accepting both forms. Text that does not parse is treated as absent,
435
435
  * so it still blocks - it is never guessed at.
@@ -485,7 +485,7 @@ export function checkReceipts(receipts, observed) {
485
485
 
486
486
  const docs = new Map((observed.documents || []).map((d) => [d.doc_id, d]));
487
487
 
488
- // A bot session never names the main records: any
488
+ // A bot session never names the main records (review note section 3.5): any
489
489
  // receipt that does is refused here, and those ids get no other check.
490
490
  const mainIds = bot ? (bot.main_records || []) : [];
491
491
  const isMain = (id) => mainIds.includes(id);
@@ -852,7 +852,7 @@ export async function sessionClose(options = {}) {
852
852
  if (row && ms !== null && ms >= startMs) {
853
853
  receiptEpisodicSource = parseMetadata(row.metadata).source || null;
854
854
  if (bot) {
855
- // A bot's session record is its own and cites this session.
855
+ // A bot's session record is its own and cites this session (review note 3.2).
856
856
  const cited = typeof row.source_session_id === 'string' && row.source_session_id ? row.source_session_id : null;
857
857
  if (receiptEpisodicSource !== bot.tag) {
858
858
  episodicRejected = `its metadata.source is ${receiptEpisodicSource || '(none)'}, not ${bot.tag}`;
@@ -968,8 +968,8 @@ export async function sessionClose(options = {}) {
968
968
  }
969
969
 
970
970
  // Store-level gaps make the session incomplete. Receipt problems, and a
971
- // transcript nothing independently corroborates, BLOCK it (the owner 2026-09-26,
972
- // A decision record: receipts required from the first deploy; the former
971
+ // transcript nothing independently corroborates, BLOCK it (Alex 2026-09-26,
972
+ // procedural ref 391: receipts required from the first deploy; the former
973
973
  // `unconfirmed` state is blocked, not passed).
974
974
  const storeMissing = [...missing];
975
975
  const receiptCheck = checkReceipts(receipts, {