0xray 4.0.40 → 4.0.41

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 (129) hide show
  1. package/.grok-plugin/plugin.json +1 -1
  2. package/.opencode/agents/api-design.yml +31 -0
  3. package/.opencode/agents/architect.yml +15 -0
  4. package/.opencode/agents/architecture-patterns.yml +14 -0
  5. package/.opencode/agents/auto-format.yml +14 -0
  6. package/.opencode/agents/backend-engineer.yml +12 -0
  7. package/.opencode/agents/boot-orchestrator.yml +14 -0
  8. package/.opencode/agents/bug-triage-specialist.yml +15 -0
  9. package/.opencode/agents/code-analyzer.yml +12 -0
  10. package/.opencode/agents/code-reviewer.yml +14 -0
  11. package/.opencode/agents/content-creator.yml +12 -0
  12. package/.opencode/agents/database-engineer.yml +12 -0
  13. package/.opencode/agents/devops-engineer.yml +12 -0
  14. package/.opencode/agents/framework-compliance-audit.yml +14 -0
  15. package/.opencode/agents/frontend-engineer.yml +12 -0
  16. package/.opencode/agents/frontend-ui-ux-engineer.yml +12 -0
  17. package/.opencode/agents/git-workflow.yml +15 -0
  18. package/.opencode/agents/growth-strategist.yml +12 -0
  19. package/.opencode/agents/hermes-agent.yml +12 -0
  20. package/.opencode/agents/inference-improve.yml +12 -0
  21. package/.opencode/agents/lint.yml +14 -0
  22. package/.opencode/agents/log-monitor.yml +12 -0
  23. package/.opencode/agents/mobile-developer.yml +12 -0
  24. package/.opencode/agents/model-health-check.yml +12 -0
  25. package/.opencode/agents/multimodal-looker.yml +12 -0
  26. package/.opencode/agents/performance-analysis.yml +12 -0
  27. package/.opencode/agents/performance-engineer.yml +12 -0
  28. package/.opencode/agents/performance-optimization.yml +12 -0
  29. package/.opencode/agents/processor-pipeline.yml +14 -0
  30. package/.opencode/agents/project-analysis.yml +12 -0
  31. package/.opencode/agents/refactorer.yml +12 -0
  32. package/.opencode/agents/researcher.yml +12 -0
  33. package/.opencode/agents/security-auditor.yml +12 -0
  34. package/.opencode/agents/security-scan.yml +12 -0
  35. package/.opencode/agents/seo-consultant.yml +12 -0
  36. package/.opencode/agents/session-management.yml +12 -0
  37. package/.opencode/agents/state-manager.yml +12 -0
  38. package/.opencode/agents/storyteller.yml +12 -0
  39. package/.opencode/agents/strategist.yml +12 -0
  40. package/.opencode/agents/tech-writer.yml +12 -0
  41. package/.opencode/agents/testing-best-practices.yml +12 -0
  42. package/.opencode/agents/testing-lead.yml +12 -0
  43. package/.opencode/agents/ui-ux-design.yml +12 -0
  44. package/.opencode/codex.codex +8 -0
  45. package/.opencode/commands/auto-format.md +99 -0
  46. package/.opencode/commands/auto-summary-capture.md +90 -0
  47. package/.opencode/commands/dependency-audit.md +184 -0
  48. package/.opencode/commands/enforcer-daily-scan.md +137 -0
  49. package/.opencode/commands/framework-compliance-audit.md +205 -0
  50. package/.opencode/commands/interactive-validator.md +75 -0
  51. package/.opencode/commands/job-summary-logger.md +68 -0
  52. package/.opencode/commands/lint.md +11 -0
  53. package/.opencode/commands/mode-switch.md +95 -0
  54. package/.opencode/commands/model-health-check.md +186 -0
  55. package/.opencode/commands/performance-analysis.md +144 -0
  56. package/.opencode/commands/pre-commit-introspection.md +185 -0
  57. package/.opencode/commands/pre-commit-introspection.sh +133 -0
  58. package/.opencode/commands/security-scan.md +157 -0
  59. package/.opencode/commands/sisyphus-validation.md +128 -0
  60. package/.opencode/commands/summary-logger.md +83 -0
  61. package/.opencode/enforcer-config.json +282 -0
  62. package/.opencode/workflows/post-deployment-audit.yml +123 -0
  63. package/.xray/features.json +1 -1
  64. package/dist/CHANGELOG.md +16 -0
  65. package/dist/integrations/grok/hooks/grok-hook-utils.js +21 -1
  66. package/dist/integrations/grok/hooks/session-start.js +2 -20
  67. package/dist/integrations/hooks/goggles-mcp.mjs +36 -4
  68. package/dist/integrations/hooks/goggles-pipeline.mjs +55 -15
  69. package/dist/integrations/hooks/goggles-planes.json +9 -3
  70. package/dist/integrations/hooks/plates.cjs +22 -0
  71. package/dist/integrations/hooks/session-note-index.cjs +298 -0
  72. package/dist/integrations/hooks/session-note-index.mjs +22 -0
  73. package/dist/integrations/hooks/sleeve.cjs +335 -0
  74. package/dist/integrations/hooks/sleeve.mjs +18 -0
  75. package/dist/integrations/hooks/station-hook-runtime.cjs +205 -9
  76. package/dist/integrations/hooks/wake-cascade.cjs +102 -0
  77. package/dist/integrations/hooks/wake-cascade.mjs +16 -0
  78. package/dist/integrations/openclaw/plugin/xray-pre-tool/package.json +1 -1
  79. package/dist/memory-routing/plates.d.ts +1 -1
  80. package/dist/memory-routing/plates.js +1 -0
  81. package/docs-site/docs/plates/activity-log.md +1 -1
  82. package/docs-site/docs/plates/boot.md +2 -0
  83. package/docs-site/docs/plates/centrifuge.md +30 -0
  84. package/docs-site/docs/plates/cursor-compact.md +1 -1
  85. package/docs-site/docs/plates/glossary.md +1 -2
  86. package/docs-site/docs/plates/goggles.md +4 -0
  87. package/docs-site/docs/plates/governance.md +2 -0
  88. package/docs-site/docs/plates/grok-compact.md +1 -1
  89. package/docs-site/docs/plates/grokbot.md +1 -1
  90. package/docs-site/docs/plates/host-pack.md +2 -0
  91. package/docs-site/docs/plates/house.md +1 -1
  92. package/docs-site/docs/plates/index.md +3 -1
  93. package/docs-site/docs/plates/inference-files.md +1 -1
  94. package/docs-site/docs/plates/kept-line.md +1 -1
  95. package/docs-site/docs/plates/kits.md +2 -0
  96. package/docs-site/docs/plates/lens-gate.md +1 -1
  97. package/docs-site/docs/plates/lens-page.md +1 -1
  98. package/docs-site/docs/plates/live-mesh.md +1 -1
  99. package/docs-site/docs/plates/memory-recall.md +4 -0
  100. package/docs-site/docs/plates/notes-page.md +2 -1
  101. package/docs-site/docs/plates/orchestration.md +2 -0
  102. package/docs-site/docs/plates/package-face.md +1 -1
  103. package/docs-site/docs/plates/payload-heat.md +1 -1
  104. package/docs-site/docs/plates/pickup-stamp.md +1 -1
  105. package/docs-site/docs/plates/pre-tool.md +1 -1
  106. package/docs-site/docs/plates/processor.md +2 -0
  107. package/docs-site/docs/plates/record-map.md +2 -1
  108. package/docs-site/docs/plates/reflection-page.md +1 -1
  109. package/docs-site/docs/plates/reporting.md +2 -0
  110. package/docs-site/docs/plates/review.md +1 -1
  111. package/docs-site/docs/plates/routing.md +2 -0
  112. package/docs-site/docs/plates/session-capture.md +1 -1
  113. package/docs-site/docs/plates/site-manual.md +1 -1
  114. package/docs-site/docs/plates/stamp-plate.md +1 -1
  115. package/docs-site/docs/plates/station-card.md +4 -1
  116. package/docs-site/docs/plates/station-heat.md +1 -1
  117. package/docs-site/docs/plates/suit-organs.md +1 -1
  118. package/docs-site/docs/plates/suit-settings.md +1 -1
  119. package/docs-site/docs/plates/suit-wear.md +3 -1
  120. package/docs-site/docs/plates/suit.md +2 -0
  121. package/docs-site/docs/plates/trail-state.md +1 -1
  122. package/docs-site/docs/plates/work-fresh.md +1 -1
  123. package/docs-site/docs/plates/write-home.md +1 -1
  124. package/package.json +1 -1
  125. package/scripts/node/bridge-mcp-wiring.cjs +37 -4
  126. package/scripts/node/install-bridges.cjs +172 -19
  127. package/scripts/node/setup.cjs +2 -46
  128. package/src/integrations/openclaw/plugin/xray-pre-tool/package.json +1 -1
  129. package/xray/features.json +1 -1
@@ -9,6 +9,7 @@ import {
9
9
  clearPendingDelegationsForSessionChange,
10
10
  ensureSessionBoot,
11
11
  readStdinJson,
12
+ resolveGrokHookEvent,
12
13
  resolveSessionId,
13
14
  normalizeWorkspaceRoot,
14
15
  workspaceRoot,
@@ -25,25 +26,6 @@ import {
25
26
  import { maintainLens } from '../../hooks/goggles-pipeline.mjs';
26
27
  import { readSavedFreshness, refreshFreshness } from '../../../nucleus/work-freshness.mjs';
27
28
 
28
- function resolveHookEvent(event) {
29
- if (process.env.GROK_HOOK_EVENT) return process.env.GROK_HOOK_EVENT;
30
- const flag = process.argv.find((a) => a.startsWith('--hook-event='));
31
- if (flag) return flag.slice('--hook-event='.length);
32
- const named = event.hookEventName || event.hook;
33
- if (named === 'PreCompact' || named === 'pre_compact') return 'pre_compact';
34
- if (named === 'PostCompact' || named === 'post_compact') return 'post_compact';
35
- if (
36
- event.prompt != null ||
37
- event.userMessage != null ||
38
- event.user_prompt != null ||
39
- named === 'UserPromptSubmit' ||
40
- named === 'user_prompt_submit'
41
- ) {
42
- return 'user_prompt_submit';
43
- }
44
- return 'session_start';
45
- }
46
-
47
29
  function extractIntent(event) {
48
30
  return event.prompt || event.userMessage || event.user_prompt || event.compactContext || null;
49
31
  }
@@ -117,7 +99,7 @@ async function main() {
117
99
  let HOOK_EVENT = 'session_start';
118
100
  try {
119
101
  const event = await readStdinJson();
120
- HOOK_EVENT = resolveHookEvent(event);
102
+ HOOK_EVENT = resolveGrokHookEvent(event);
121
103
  const eventRoot = normalizeWorkspaceRoot(event.workspaceRoot || event.cwd || root);
122
104
  const sessionId = resolveSessionId(event);
123
105
  if (HOOK_EVENT === 'user_prompt_submit' && sessionId) {
@@ -2,8 +2,8 @@
2
2
  * Goggles MCP. Stdio. Server name `goggles`.
3
3
  * Tools: look, status_lens. Same organ as the CLI.
4
4
  */
5
- import { existsSync, readFileSync, realpathSync } from 'node:fs';
6
- import { basename, join, resolve } from 'node:path';
5
+ import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';
6
+ import { basename, dirname, join, resolve } from 'node:path';
7
7
  import { pathToFileURL, fileURLToPath } from 'node:url';
8
8
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
9
9
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
@@ -162,6 +162,29 @@ function publicCard(view) {
162
162
  if (view.exam) notes.push(view.exam);
163
163
  }
164
164
  const skills = view.skills ? basename(String(view.skills)) : '';
165
+ const cascade = view.cascade
166
+ ? {
167
+ plane: view.cascade.plane,
168
+ station: view.cascade.station,
169
+ notesPage: view.cascade.notesPage,
170
+ index: view.cascade.index,
171
+ laws: Array.isArray(view.cascade.laws) ? view.cascade.laws : [],
172
+ notes: Array.isArray(view.cascade.notes) ? view.cascade.notes : [],
173
+ }
174
+ : null;
175
+ const sleeve = view.sleeve
176
+ ? {
177
+ on: Boolean(view.sleeve.on),
178
+ missing: Array.isArray(view.sleeve.missing) ? view.sleeve.missing : [],
179
+ stitches: Array.isArray(view.sleeve.stitches)
180
+ ? view.sleeve.stitches.map((row) => ({
181
+ name: String(row && row.name || ''),
182
+ on: Boolean(row && row.on),
183
+ at: Array.isArray(row && row.at) ? row.at.map((item) => String(item)) : [],
184
+ }))
185
+ : [],
186
+ }
187
+ : null;
165
188
  if (view.narrow) {
166
189
  return {
167
190
  plane: view.plane,
@@ -169,6 +192,8 @@ function publicCard(view) {
169
192
  digest: view.digest || '',
170
193
  files: Array.isArray(view.files) ? view.files : [],
171
194
  notes,
195
+ ...(cascade ? { cascade } : {}),
196
+ ...(sleeve ? { sleeve } : {}),
172
197
  };
173
198
  }
174
199
  return {
@@ -185,6 +210,8 @@ function publicCard(view) {
185
210
  teardown: view.teardown || '',
186
211
  worn: view.worn || '',
187
212
  notes,
213
+ ...(cascade ? { cascade } : {}),
214
+ ...(sleeve ? { sleeve } : {}),
188
215
  };
189
216
  }
190
217
 
@@ -205,11 +232,16 @@ export async function answerLook(raw, root) {
205
232
  return { ok: true, quiet: false, mode: 'kind0', content: line };
206
233
  }
207
234
  const argv = argvFrom(args);
208
- const text = api.look(argv).text;
235
+ const text = api.look(argv, here).text;
209
236
  if (text === 'Name one plane.') return deny('name_one', 'Name one plane.');
210
- const cards = api.lookCards(argv);
237
+ const cards = api.lookCards(argv, here);
211
238
  if (Array.isArray(cards) && cards.length) {
212
239
  const shown = cards.map(publicCard);
240
+ if (shown.length === 1 && shown[0] && typeof shown[0].plane === 'string') {
241
+ const dest = join(here, '.xray', 'state', 'goggles-plane.json');
242
+ mkdirSync(dirname(dest), { recursive: true });
243
+ writeFileSync(dest, `${JSON.stringify({ plane: shown[0].plane })}\n`);
244
+ }
213
245
  return {
214
246
  ok: true,
215
247
  quiet: false,
@@ -18,7 +18,7 @@ import { fileURLToPath } from 'node:url';
18
18
  const FIELD_ORDER = ['plate', 'entry', 'exit', 'files', 'skills', 'setup', 'teardown', 'worn'];
19
19
  const HERE = dirname(fileURLToPath(import.meta.url));
20
20
  const WORN_PLANES = ['dichotomy', 'syncopate', 'synthesis', 'digest', 'triage', 'loop'];
21
- const CARD_PLANES = ['ground', 'routing', 'house', 'boot', 'governance', 'memory-recall', 'orchestration', 'processor', 'reporting', 'stamp-plate', 'record-map', 'write-home', 'activity-log', 'session-capture', 'suit-wear', 'suit-organs', 'station-card', 'notes-page', 'reflection-page', 'site-manual', 'package-face', 'suit-settings', 'trail-state', 'inference-files', 'grok-compact', 'payload-heat', 'station-heat', 'pickup-stamp', 'cursor-compact', 'work-fresh', 'kept-line', 'lens-gate', 'pre-tool', 'lens-page'];
21
+ const CARD_PLANES = ['ground', 'routing', 'house', 'boot', 'governance', 'memory-recall', 'orchestration', 'processor', 'reporting', 'stamp-plate', 'record-map', 'write-home', 'activity-log', 'session-capture', 'suit-wear', 'suit-organs', 'station-card', 'notes-page', 'reflection-page', 'site-manual', 'package-face', 'suit-settings', 'trail-state', 'inference-files', 'grok-compact', 'payload-heat', 'station-heat', 'pickup-stamp', 'cursor-compact', 'work-fresh', 'kept-line', 'lens-gate', 'pre-tool', 'lens-page', 'centrifuge'];
22
22
  const CARD_FLAVORS = ['digest', 'triage'];
23
23
  const SCOPE_ZOOM = ['ecosystem', 'part', 'one flow', 'one artifact'];
24
24
 
@@ -211,7 +211,7 @@ function namesTheSet(lower) {
211
211
  return planes.length === 1 && planes[0] === 'loop' && findScopes(lower).length === 0;
212
212
  }
213
213
 
214
- function gogglesAnswer(argv) {
214
+ function gogglesAnswer(argv, projectRoot) {
215
215
  const words = [];
216
216
  for (const raw of argv || []) {
217
217
  const arg = String(raw || '').trim();
@@ -234,14 +234,14 @@ function gogglesAnswer(argv) {
234
234
  if (flavors.length === 1) {
235
235
  const others = acceptedPlanes().filter((name) => name !== flavors[0] && lower.includes(name));
236
236
  if (others.length) return none('');
237
- const cards = collectCards(flavors[0], lower);
237
+ const cards = collectCards(flavors[0], lower, projectRoot);
238
238
  if (!cards) return none('');
239
239
  return { text: cards.map((card) => formatCardText(card)).join('\n\n'), cards };
240
240
  }
241
241
  const planes = acceptedPlanes().filter((name) => lower.includes(name));
242
242
  if (planes.length !== 1) {
243
243
  if (!planes.length && cardPlanesNamed(lower).length) {
244
- const cards = collectCards('digest', lower);
244
+ const cards = collectCards('digest', lower, projectRoot);
245
245
  if (cards && cards.length) {
246
246
  return { text: cards.map((card) => formatCardText(card)).join('\n\n'), cards };
247
247
  }
@@ -255,12 +255,12 @@ function gogglesAnswer(argv) {
255
255
  return none(file ? `${line} File: ${file}` : line);
256
256
  }
257
257
 
258
- export function readGoggles(argv) {
259
- return ok(gogglesAnswer(argv).text);
258
+ export function readGoggles(argv, projectRoot) {
259
+ return ok(gogglesAnswer(argv, projectRoot).text);
260
260
  }
261
261
 
262
- export function lookCards(argv) {
263
- return gogglesAnswer(argv).cards;
262
+ export function lookCards(argv, projectRoot) {
263
+ return gogglesAnswer(argv, projectRoot).cards;
264
264
  }
265
265
 
266
266
  function cardPlanesNamed(lower) {
@@ -271,7 +271,22 @@ function listedFiles(plane) {
271
271
  return Array.isArray(plane.files) ? plane.files.map(String) : [];
272
272
  }
273
273
 
274
- function cardView(plane, scope, flavor, root) {
274
+ function cascadeApi() {
275
+ return createRequire(import.meta.url)('./wake-cascade.cjs');
276
+ }
277
+
278
+ function sleeveApi() {
279
+ return createRequire(import.meta.url)('./sleeve.cjs');
280
+ }
281
+
282
+ function appendLining(text, view) {
283
+ let next = text;
284
+ if (view.cascade) next = `${next}\n${cascadeApi().formatCascadeReading(view.cascade)}`;
285
+ if (view.sleeve) next = `${next}\n${sleeveApi().formatSleeveReading(view.sleeve)}`;
286
+ return next;
287
+ }
288
+
289
+ function cardView(plane, scope, flavor, root, cascadeRoot) {
275
290
  const listed = listedFiles(plane);
276
291
  const view = {
277
292
  plane: plane.id,
@@ -290,6 +305,20 @@ function cardView(plane, scope, flavor, root) {
290
305
  worn: plane.worn || '',
291
306
  };
292
307
  view.exam = examinePlane(plane, root).text;
308
+ if (cascadeApi().isCascadePlane(plane.id)) {
309
+ try {
310
+ view.cascade = cascadeApi().readWakeCascade(cascadeRoot || stateRoot());
311
+ } catch {
312
+ view.cascade = null;
313
+ }
314
+ }
315
+ if (sleeveApi().isSleevePlane(plane.id)) {
316
+ try {
317
+ view.sleeve = sleeveApi().readSleeve(cascadeRoot || stateRoot());
318
+ } catch {
319
+ view.sleeve = null;
320
+ }
321
+ }
293
322
  if (flavor === 'triage') {
294
323
  const filled = new Set(filledOf(plane));
295
324
  view.empty = FIELD_ORDER.filter((name) => !filled.has(name));
@@ -328,7 +357,7 @@ function formatCardText(view) {
328
357
  } else if (typeof view.exam === 'string' && view.exam.startsWith('Drift:')) {
329
358
  text = `${text}\n${view.exam}`;
330
359
  }
331
- return text;
360
+ return appendLining(text, view);
332
361
  }
333
362
 
334
363
  export function formatCardPane(view) {
@@ -345,10 +374,11 @@ export function formatCardPane(view) {
345
374
  const top = `┌ ${title} ${'─'.repeat(Math.max(0, width - title.length - 1))}┐`;
346
375
  const mid = body.map((line) => `│ ${line.padEnd(width)} │`);
347
376
  const bot = `└${'─'.repeat(width + 2)}┘`;
348
- return [top, ...mid, bot].join('\n');
377
+ const pane = [top, ...mid, bot].join('\n');
378
+ return appendLining(pane, view);
349
379
  }
350
380
 
351
- function collectCards(flavor, lower) {
381
+ function collectCards(flavor, lower, projectRoot) {
352
382
  const named = cardPlanesNamed(lower);
353
383
  const scopes = findScopes(lower.filter((word) => word !== flavor && !named.includes(word)));
354
384
  if (scopes.length > 1) return null;
@@ -359,7 +389,7 @@ function collectCards(flavor, lower) {
359
389
  const cards = [];
360
390
  for (const id of ids) {
361
391
  const plane = growPlane(id, platesDir, stateRoot());
362
- cards.push(cardView(plane, scope, flavor, root));
392
+ cards.push(cardView(plane, scope, flavor, root, projectRoot));
363
393
  }
364
394
  return cards;
365
395
  }
@@ -929,6 +959,15 @@ function lensPage(root, names) {
929
959
  return parts.join('\n\n');
930
960
  }
931
961
 
962
+
963
+ export function holdPlane(root, id) {
964
+ const plane = String(id || "").trim();
965
+ if (!plane || plane.includes(" ")) return;
966
+ const dest = join(root, ".xray", "state", "goggles-plane.json");
967
+ mkdirSync(dirname(dest), { recursive: true });
968
+ writeFileSync(dest, `${JSON.stringify({ plane })}\n`);
969
+ }
970
+
932
971
  function stampPlane(root, id) {
933
972
  try {
934
973
  const plates = createRequire(import.meta.url)('./plates.cjs');
@@ -953,6 +992,7 @@ export function lensBeforeResearch(root, toolName, text) {
953
992
  if (!research) return null;
954
993
  const names = CARD_PLANES.filter((name) => intentWords(spoken).includes(name));
955
994
  if (names.length === 1) {
995
+ holdPlane(root, names[0]);
956
996
  stampPlane(root, names[0]);
957
997
  rememberOpened(root, spoken);
958
998
  return null;
@@ -1095,8 +1135,8 @@ export function examinePlane(plane, root) {
1095
1135
  }
1096
1136
 
1097
1137
 
1098
- export function look(argv) {
1099
- return readGoggles(argv);
1138
+ export function look(argv, projectRoot) {
1139
+ return readGoggles(argv, projectRoot);
1100
1140
  }
1101
1141
 
1102
1142
 
@@ -68,7 +68,7 @@
68
68
  "plates": ["review"]
69
69
  },
70
70
  "record-map": {
71
- "files": ["docs-site/docs/plates/record-map.md"],
71
+ "files": ["docs-site/docs/plates/record-map.md", "src/integrations/hooks/wake-cascade.cjs", "src/integrations/hooks/session-note-index.cjs"],
72
72
  "skills": ".agents/skills/record-map/SKILL.md",
73
73
  "plates": ["station-card", "notes-page", "reflection-page", "site-manual", "package-face", "write-home", "activity-log", "session-capture", "lens-page"]
74
74
  },
@@ -103,13 +103,13 @@
103
103
  "plates": ["activity-log", "session-capture", "inference-files", "trail-state"]
104
104
  },
105
105
  "station-card": {
106
- "files": ["src/integrations/hooks/station-hook-runtime.cjs"],
106
+ "files": ["src/integrations/hooks/station-hook-runtime.cjs", "src/integrations/hooks/wake-cascade.cjs"],
107
107
  "mark": "formatStationMarkdown",
108
108
  "skills": ".agents/skills/station-card/SKILL.md",
109
109
  "plates": ["notes-page", "record-map", "kept-line"]
110
110
  },
111
111
  "notes-page": {
112
- "files": ["src/integrations/hooks/station-hook-runtime.cjs"],
112
+ "files": ["src/integrations/hooks/station-hook-runtime.cjs", "src/integrations/hooks/session-note-index.cjs"],
113
113
  "mark": "stampNotesPickup",
114
114
  "skills": ".agents/skills/notes-page/SKILL.md",
115
115
  "plates": ["station-card", "record-map"]
@@ -210,6 +210,12 @@
210
210
  "mark": "export function formatCardPane",
211
211
  "skills": ".agents/skills/lens-page/SKILL.md",
212
212
  "plates": ["record-map", "lens-gate"]
213
+ },
214
+ "centrifuge": {
215
+ "files": ["src/integrations/hooks/station-hook-runtime.cjs"],
216
+ "mark": "function wakeOrder",
217
+ "skills": ".agents/skills/centrifuge/SKILL.md",
218
+ "plates": ["station-card", "goggles"]
213
219
  }
214
220
  }
215
221
 
@@ -46,6 +46,7 @@ const PLATE_IDS = Object.freeze([
46
46
  "lens-gate",
47
47
  "pre-tool",
48
48
  "lens-page",
49
+ "centrifuge",
49
50
  ]);
50
51
 
51
52
  /** Id token, then extra phrases. Equal top scores recall nothing. */
@@ -229,6 +230,11 @@ const CUES = {
229
230
  [/lens page/i, 6],
230
231
  [/plates\/lens-page/i, 6],
231
232
  ],
233
+ centrifuge: [
234
+ [/centrifuge plate/i, 6],
235
+ [/the centrifuge/i, 5],
236
+ [/plates\/centrifuge/i, 6],
237
+ ],
232
238
  };
233
239
 
234
240
  function platesDir() {
@@ -317,6 +323,21 @@ function stampPlateIfMissing(projectRoot, id) {
317
323
  return { id, path, written: true };
318
324
  }
319
325
 
326
+ function ensureWornPlate(projectRoot, id) {
327
+ const path = wornPlatePath(projectRoot, id);
328
+ const source = readFileSync(plateSourcePath(id), "utf8");
329
+ if (existsSync(path)) {
330
+ try {
331
+ if (readFileSync(path, "utf8") === source) return { id, path, written: false };
332
+ } catch {
333
+ /* rewrite a plate the process cannot keep */
334
+ }
335
+ }
336
+ mkdirSync(dirname(path), { recursive: true });
337
+ writeFileSync(path, source);
338
+ return { id, path, written: true };
339
+ }
340
+
320
341
  function organFile(intent) {
321
342
  try {
322
343
  const { suitHint } = require("./goggles-pipeline.mjs");
@@ -342,6 +363,7 @@ module.exports = {
342
363
  loadPlate,
343
364
  recallPlate,
344
365
  stampPlateIfMissing,
366
+ ensureWornPlate,
345
367
  plateStockLine,
346
368
  wornPlatePath,
347
369
  };
@@ -0,0 +1,298 @@
1
+ /**
2
+ * Session notes beside repertoire laws.
3
+ * Laws stay in curated_signals.json. This file is the index.
4
+ * Cleanup drops a lone note only after STALE_AFTER_MS without another sighting.
5
+ * A replaced note stays on disk and is left out of the short index.
6
+ * The short index is a view of current notes. It does not delete history.
7
+ */
8
+ const { createHash } = require("crypto");
9
+ const { existsSync, mkdirSync, readFileSync, writeFileSync } = require("fs");
10
+ const { join } = require("path");
11
+
12
+ const DAY_MS = 24 * 60 * 60 * 1000;
13
+ const STALE_AFTER_MS = 90 * DAY_MS;
14
+ const SHORT_INDEX_LIMIT = 12;
15
+ const LINE_MAX = 240;
16
+
17
+ function sessionNotesPath(root) {
18
+ return join(root, ".xray", "state", "repertoire", "session-notes.json");
19
+ }
20
+
21
+ function lawsPath(root) {
22
+ return join(root, ".xray", "state", "repertoire", "curated_signals.json");
23
+ }
24
+
25
+ function clipLine(raw) {
26
+ if (raw == null) return null;
27
+ const text = String(raw).replace(/\s+/g, " ").trim();
28
+ if (!text) return null;
29
+ if (text.length <= LINE_MAX) return text;
30
+ return `${text.slice(0, LINE_MAX - 1)}…`;
31
+ }
32
+
33
+ function noteId(text) {
34
+ return createHash("sha256").update(text).digest("hex").slice(0, 12);
35
+ }
36
+
37
+ function loadIndex(root) {
38
+ const dest = sessionNotesPath(root);
39
+ if (!existsSync(dest)) return { notes: [], corrupt: false };
40
+ let parsed;
41
+ try {
42
+ parsed = JSON.parse(readFileSync(dest, "utf8"));
43
+ } catch {
44
+ return { notes: [], corrupt: true };
45
+ }
46
+ if (!parsed || typeof parsed !== "object" || !Array.isArray(parsed.notes)) {
47
+ return { notes: [], corrupt: true };
48
+ }
49
+ const notes = [];
50
+ for (const row of parsed.notes) {
51
+ if (!row || typeof row.text !== "string" || !row.text.trim()) continue;
52
+ const text = clipLine(row.text);
53
+ if (!text) continue;
54
+ const added = typeof row.added === "string" ? row.added : "";
55
+ const lastSeen = typeof row.last_seen === "string" && row.last_seen ? row.last_seen : added;
56
+ if (!added || !lastSeen) continue;
57
+ const note = {
58
+ id: typeof row.id === "string" && row.id ? row.id : noteId(text),
59
+ text,
60
+ added,
61
+ last_seen: lastSeen,
62
+ };
63
+ if (typeof row.source === "string") note.source = row.source;
64
+ if (typeof row.slot === "string" && row.slot) note.slot = row.slot;
65
+ if (typeof row.superseded_by === "string" && row.superseded_by) note.superseded_by = row.superseded_by;
66
+ if (typeof row.superseded_at === "string" && row.superseded_at) note.superseded_at = row.superseded_at;
67
+ notes.push(note);
68
+ }
69
+ return { notes, corrupt: false };
70
+ }
71
+
72
+ function writeIndex(root, notes) {
73
+ const dest = sessionNotesPath(root);
74
+ try {
75
+ mkdirSync(join(root, ".xray", "state", "repertoire"), { recursive: true });
76
+ const body = notes.map((note) => {
77
+ const row = {
78
+ id: note.id,
79
+ text: note.text,
80
+ added: note.added,
81
+ last_seen: note.last_seen,
82
+ };
83
+ if (note.source) row.source = note.source;
84
+ if (note.slot) row.slot = note.slot;
85
+ if (note.superseded_by) row.superseded_by = note.superseded_by;
86
+ if (note.superseded_at) row.superseded_at = note.superseded_at;
87
+ return row;
88
+ });
89
+ writeFileSync(dest, `${JSON.stringify({ notes: body }, null, 2)}\n`);
90
+ return true;
91
+ } catch {
92
+ return false;
93
+ }
94
+ }
95
+
96
+ function nowStamp(opts) {
97
+ return typeof opts.now === "string" && opts.now ? opts.now : new Date().toISOString();
98
+ }
99
+
100
+ function isCurrent(note) {
101
+ return !note.superseded_by;
102
+ }
103
+
104
+ /** The new line becomes current. The previous holder of the same slot stays on disk. */
105
+ function closeSlot(notes, slot, keeperId, now) {
106
+ if (!slot) return 0;
107
+ let closed = 0;
108
+ for (const note of notes) {
109
+ if (note.id === keeperId) continue;
110
+ if (note.slot !== slot) continue;
111
+ if (note.superseded_by) continue;
112
+ note.superseded_by = keeperId;
113
+ note.superseded_at = now;
114
+ closed += 1;
115
+ }
116
+ return closed;
117
+ }
118
+
119
+ function rememberSessionNote(root, text, opts = {}) {
120
+ const line = clipLine(text);
121
+ if (!line) return { kept: false };
122
+ const loaded = loadIndex(root);
123
+ if (loaded.corrupt) return { kept: false, corrupt: true };
124
+ const now = nowStamp(opts);
125
+ const source = typeof opts.source === "string" ? opts.source : undefined;
126
+ const slot = typeof opts.slot === "string" && opts.slot ? opts.slot : undefined;
127
+ const existing = loaded.notes.find((note) => note.text === line);
128
+ if (existing) {
129
+ existing.last_seen = now;
130
+ if (source) existing.source = source;
131
+ // A notes page can still show the old line. That sighting must not
132
+ // revive it or demote the line that replaced it.
133
+ if (slot && !existing.superseded_by) {
134
+ existing.slot = slot;
135
+ closeSlot(loaded.notes, slot, existing.id, now);
136
+ }
137
+ const wrote = writeIndex(root, loaded.notes);
138
+ return { kept: wrote, bumped: true, id: existing.id, corrupt: false };
139
+ }
140
+ const created = {
141
+ id: noteId(line),
142
+ text: line,
143
+ added: now,
144
+ last_seen: now,
145
+ };
146
+ if (source) created.source = source;
147
+ if (slot) created.slot = slot;
148
+ loaded.notes.push(created);
149
+ if (slot) closeSlot(loaded.notes, slot, created.id, now);
150
+ const wrote = writeIndex(root, loaded.notes);
151
+ return { kept: wrote, bumped: false, id: created.id, corrupt: false };
152
+ }
153
+
154
+ function supersedeSessionNote(root, previousText, nextText, opts = {}) {
155
+ const previousLine = clipLine(previousText);
156
+ const nextLine = clipLine(nextText);
157
+ if (!previousLine || !nextLine || previousLine === nextLine) return { kept: false };
158
+ const loaded = loadIndex(root);
159
+ if (loaded.corrupt) return { kept: false, corrupt: true };
160
+ const previous = loaded.notes.find((note) => note.text === previousLine || note.id === previousLine);
161
+ if (!previous) return { kept: false, missing: true };
162
+ const now = nowStamp(opts);
163
+ const source = typeof opts.source === "string" ? opts.source : previous.source;
164
+ let next = loaded.notes.find((note) => note.text === nextLine);
165
+ if (!next) {
166
+ next = {
167
+ id: noteId(nextLine),
168
+ text: nextLine,
169
+ added: now,
170
+ last_seen: now,
171
+ };
172
+ if (source) next.source = source;
173
+ if (previous.slot) next.slot = previous.slot;
174
+ loaded.notes.push(next);
175
+ } else {
176
+ next.last_seen = now;
177
+ delete next.superseded_by;
178
+ delete next.superseded_at;
179
+ if (previous.slot) next.slot = previous.slot;
180
+ }
181
+ if (next.id === previous.id) return { kept: false };
182
+ previous.superseded_by = next.id;
183
+ previous.superseded_at = now;
184
+ if (next.slot) closeSlot(loaded.notes, next.slot, next.id, now);
185
+ const wrote = writeIndex(root, loaded.notes);
186
+ return { kept: wrote, id: next.id, supersededId: previous.id, corrupt: false };
187
+ }
188
+
189
+ function sessionNoteHistory(root, textOrId) {
190
+ const loaded = loadIndex(root);
191
+ const key = clipLine(textOrId) || String(textOrId || "");
192
+ const start = loaded.notes.find((note) => note.text === key || note.id === textOrId);
193
+ if (!start) return [];
194
+ const seen = new Set([start.id]);
195
+ const older = [];
196
+ let cursor = start.id;
197
+ while (cursor && seen.size < loaded.notes.length + 1) {
198
+ const prev = loaded.notes.find((note) => note.superseded_by === cursor && !seen.has(note.id));
199
+ if (!prev) break;
200
+ seen.add(prev.id);
201
+ older.push(prev);
202
+ cursor = prev.id;
203
+ }
204
+ return older;
205
+ }
206
+
207
+ function shortSessionIndex(root, limit = SHORT_INDEX_LIMIT) {
208
+ const loaded = loadIndex(root);
209
+ const cap = Number.isFinite(limit) && limit > 0 ? Math.floor(limit) : SHORT_INDEX_LIMIT;
210
+ const ordered = loaded.notes.filter(isCurrent).sort((a, b) => {
211
+ if (a.last_seen === b.last_seen) return a.added < b.added ? 1 : -1;
212
+ return a.last_seen < b.last_seen ? 1 : -1;
213
+ });
214
+ return ordered.slice(0, cap);
215
+ }
216
+
217
+ function dropStaleSessionNotes(root, opts = {}) {
218
+ const loaded = loadIndex(root);
219
+ if (loaded.corrupt) return { kept: 0, dropped: 0, corrupt: true };
220
+ const nowMs = typeof opts.now === "string" ? Date.parse(opts.now) : Date.now();
221
+ const windowMs = Number.isFinite(opts.staleAfterMs) ? opts.staleAfterMs : STALE_AFTER_MS;
222
+ if (!Number.isFinite(nowMs)) return { kept: loaded.notes.length, dropped: 0, corrupt: false };
223
+ const protectedIds = new Set();
224
+ for (const note of loaded.notes) {
225
+ if (!note.superseded_by) continue;
226
+ protectedIds.add(note.id);
227
+ protectedIds.add(note.superseded_by);
228
+ }
229
+ const kept = [];
230
+ let dropped = 0;
231
+ for (const note of loaded.notes) {
232
+ const seen = Date.parse(note.last_seen);
233
+ const stale = Number.isFinite(seen) && nowMs - seen > windowMs;
234
+ if (stale && !protectedIds.has(note.id)) {
235
+ dropped += 1;
236
+ continue;
237
+ }
238
+ kept.push(note);
239
+ }
240
+ if (dropped > 0) writeIndex(root, kept);
241
+ return { kept: kept.length, dropped, corrupt: false };
242
+ }
243
+
244
+ function linesFromNotes(text) {
245
+ const lines = [];
246
+ for (const raw of String(text || "").split("\n")) {
247
+ const trimmed = raw.trim();
248
+ if (!trimmed) continue;
249
+ if (/^#{1,6}\s/.test(trimmed)) continue;
250
+ const pickup = trimmed.match(/^\*\*Pickup line:\*\*\s*(.*)$/);
251
+ if (pickup) {
252
+ if (pickup[1].trim()) lines.push({ text: pickup[1].trim(), slot: "pickup" });
253
+ continue;
254
+ }
255
+ const bullet = trimmed.replace(/^[-*]\s+/, "");
256
+ if (bullet) lines.push({ text: bullet });
257
+ }
258
+ return lines;
259
+ }
260
+
261
+ function retainProjectNotes(root, opts = {}) {
262
+ const dest = join(root, ".xray", "state", "NOTES.md");
263
+ let remembered = 0;
264
+ if (existsSync(dest)) {
265
+ let text = "";
266
+ try {
267
+ text = readFileSync(dest, "utf8");
268
+ } catch {
269
+ text = "";
270
+ }
271
+ for (const line of linesFromNotes(text)) {
272
+ const saved = rememberSessionNote(root, line.text, {
273
+ ...opts,
274
+ source: opts.source || "NOTES.md",
275
+ slot: line.slot,
276
+ });
277
+ if (saved.corrupt) return { remembered, dropped: 0, kept: 0, corrupt: true };
278
+ if (saved.kept) remembered += 1;
279
+ }
280
+ }
281
+ const cleaned = dropStaleSessionNotes(root, opts);
282
+ return { remembered, ...cleaned };
283
+ }
284
+
285
+ module.exports = {
286
+ DAY_MS,
287
+ STALE_AFTER_MS,
288
+ SHORT_INDEX_LIMIT,
289
+ LINE_MAX,
290
+ sessionNotesPath,
291
+ lawsPath,
292
+ rememberSessionNote,
293
+ supersedeSessionNote,
294
+ sessionNoteHistory,
295
+ shortSessionIndex,
296
+ dropStaleSessionNotes,
297
+ retainProjectNotes,
298
+ };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * ESM face for session-note-index.cjs.
3
+ */
4
+ import { createRequire } from "node:module";
5
+ import { fileURLToPath } from "node:url";
6
+ import { dirname, join } from "node:path";
7
+
8
+ const require = createRequire(import.meta.url);
9
+ const impl = require(join(dirname(fileURLToPath(import.meta.url)), "session-note-index.cjs"));
10
+
11
+ export const DAY_MS = impl.DAY_MS;
12
+ export const STALE_AFTER_MS = impl.STALE_AFTER_MS;
13
+ export const SHORT_INDEX_LIMIT = impl.SHORT_INDEX_LIMIT;
14
+ export const LINE_MAX = impl.LINE_MAX;
15
+ export const sessionNotesPath = impl.sessionNotesPath;
16
+ export const lawsPath = impl.lawsPath;
17
+ export const rememberSessionNote = impl.rememberSessionNote;
18
+ export const supersedeSessionNote = impl.supersedeSessionNote;
19
+ export const sessionNoteHistory = impl.sessionNoteHistory;
20
+ export const shortSessionIndex = impl.shortSessionIndex;
21
+ export const dropStaleSessionNotes = impl.dropStaleSessionNotes;
22
+ export const retainProjectNotes = impl.retainProjectNotes;