0xray 3.5.5 → 4.0.1

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 (233) hide show
  1. package/.mcp.json +18 -14
  2. package/.opencode/skills/api-design/SKILL.md +1 -1
  3. package/.opencode/skills/architect-tools/SKILL.md +1 -1
  4. package/.opencode/skills/architecture-patterns/SKILL.md +1 -1
  5. package/.opencode/skills/auto-format/SKILL.md +1 -1
  6. package/.opencode/skills/boot-orchestrator/SKILL.md +2 -6
  7. package/.opencode/skills/bug-triage/SKILL.md +1 -1
  8. package/.opencode/skills/code-analyzer/SKILL.md +1 -1
  9. package/.opencode/skills/code-review/SKILL.md +1 -1
  10. package/.opencode/skills/enforcer/SKILL.md +1 -1
  11. package/.opencode/skills/framework-compliance-audit/SKILL.md +1 -1
  12. package/.opencode/skills/git-workflow/SKILL.md +1 -1
  13. package/.opencode/skills/hermes-agent/SKILL.md +36 -36
  14. package/.opencode/skills/inference-improve/SKILL.md +1 -1
  15. package/.opencode/skills/lint/SKILL.md +1 -1
  16. package/.opencode/skills/log-monitor/SKILL.md +1 -1
  17. package/.opencode/skills/model-health-check/SKILL.md +1 -1
  18. package/.opencode/skills/multimodal-looker/SKILL.md +1 -1
  19. package/.opencode/skills/orchestrator/SKILL.md +38 -14
  20. package/.opencode/skills/performance-analysis/SKILL.md +1 -1
  21. package/.opencode/skills/performance-optimization/SKILL.md +1 -1
  22. package/.opencode/skills/processor-pipeline/SKILL.md +1 -1
  23. package/.opencode/skills/project-analysis/SKILL.md +1 -1
  24. package/.opencode/skills/refactoring-strategies/SKILL.md +1 -1
  25. package/.opencode/skills/registry.json +65 -0
  26. package/.opencode/skills/researcher/SKILL.md +18 -5
  27. package/.opencode/skills/security-audit/SKILL.md +1 -1
  28. package/.opencode/skills/security-scan/SKILL.md +1 -1
  29. package/.opencode/skills/session-management/SKILL.md +1 -1
  30. package/.opencode/skills/state-manager/SKILL.md +1 -1
  31. package/.opencode/skills/storyteller/SKILL.md +1 -1
  32. package/.opencode/skills/strategist/SKILL.md +12 -0
  33. package/.opencode/skills/testing-best-practices/SKILL.md +37 -0
  34. package/.opencode/skills/testing-strategy/SKILL.md +14 -3
  35. package/.opencode/skills/ui-ux-design/SKILL.md +1 -1
  36. package/.opencode/skills/xray-orchestrator/index.ts +267 -0
  37. package/.xray/codex.json +12 -3
  38. package/.xray/features.json +28 -6
  39. package/.xray/features.schema.json +31 -0
  40. package/AGENTS-consumer.md +17 -7
  41. package/AGENTS.md +18 -10
  42. package/README.md +30 -27
  43. package/SKILLS.md +2 -2
  44. package/dist/AGENTS.md +18 -10
  45. package/dist/CHANGELOG.md +81 -11
  46. package/dist/README.md +30 -27
  47. package/dist/SKILLS.md +2 -2
  48. package/dist/cli/commands/hermes-install.js +3 -0
  49. package/dist/cli/commands/openclaw-install.js +14 -0
  50. package/dist/cli/index.js +10 -1
  51. package/dist/core/features-config.d.ts +15 -2
  52. package/dist/infrastructure/schemas/cloud-schemas.d.ts +1 -1
  53. package/dist/integrations/grok/grok-cli.d.ts +3 -0
  54. package/dist/integrations/grok/grok-cli.js +92 -4
  55. package/dist/integrations/grok/hooks/grok-hook-utils.js +53 -7
  56. package/dist/integrations/grok/hooks/post-tool-use.js +68 -46
  57. package/dist/integrations/grok/hooks/pre-tool-use.js +14 -31
  58. package/dist/integrations/grok/hooks/session-start.js +86 -4
  59. package/dist/integrations/grok/plugin/0xray/hooks/hooks.json +31 -24
  60. package/dist/integrations/hermes-agent/bridge.mjs +26 -1
  61. package/dist/integrations/hooks/delegation-gate-runtime.mjs +32 -3
  62. package/dist/integrations/hooks/pipeline-hook-runtime.mjs +1 -1
  63. package/dist/integrations/hooks/station-hook-runtime.cjs +421 -0
  64. package/dist/integrations/hooks/station-hook-runtime.mjs +24 -0
  65. package/dist/integrations/hooks/station-memory-ingest.mjs +45 -0
  66. package/dist/integrations/hooks/station-memory-match.mjs +47 -0
  67. package/dist/integrations/openclaw/client.d.ts +5 -1
  68. package/dist/integrations/openclaw/client.js +17 -9
  69. package/dist/integrations/openclaw/config.js +0 -1
  70. package/dist/integrations/openclaw/hooks/pre-tool-gate-runtime.mjs +102 -0
  71. package/dist/integrations/openclaw/index.js +17 -0
  72. package/dist/integrations/openclaw/plugin/xray-pre-tool/index.js +75 -0
  73. package/dist/integrations/openclaw/plugin/xray-pre-tool/openclaw.plugin.json +10 -0
  74. package/dist/integrations/openclaw/plugin/xray-pre-tool/package.json +12 -0
  75. package/dist/integrations/openclaw/pre-tool-gate.d.ts +19 -0
  76. package/dist/integrations/openclaw/pre-tool-gate.js +39 -0
  77. package/dist/mcps/orchestrator/handlers/complexity-handler.js +2 -2
  78. package/dist/memory-routing/index.d.ts +1 -1
  79. package/dist/memory-routing/index.js +1 -1
  80. package/dist/memory-routing/provider-loader.d.ts +4 -0
  81. package/dist/memory-routing/provider-loader.js +44 -2
  82. package/dist/memory-routing/provider-registry.js +3 -2
  83. package/dist/nucleus/autonomy-kernel.d.ts +2 -2
  84. package/dist/nucleus/autonomy-kernel.js +17 -6
  85. package/dist/nucleus/confer.js +17 -3
  86. package/dist/nucleus/delegation-gate.d.ts +14 -8
  87. package/dist/nucleus/delegation-gate.js +151 -16
  88. package/dist/nucleus/suit-temperament.d.ts +40 -0
  89. package/dist/nucleus/suit-temperament.js +157 -0
  90. package/dist/nucleus/user-aside.js +1 -1
  91. package/dist/plugin/xray-codex-injection.js +14 -3
  92. package/dist/postprocessor/triggers/GitHookTrigger.js +11 -5
  93. package/opencode.json +80 -0
  94. package/package.json +15 -5
  95. package/scripts/hooks/install-hooks.cjs +18 -3
  96. package/scripts/hooks/run-hook.js +67 -3
  97. package/scripts/mjs/run-repertoire-mcp.mjs +39 -0
  98. package/scripts/mjs/verify-confer-core.mjs +1 -1
  99. package/scripts/mjs/verify-delegation-gate-core.mjs +29 -2
  100. package/scripts/mjs/verify-four-floor-compact.mjs +524 -0
  101. package/scripts/mjs/verify-pipeline-facets.mjs +215 -0
  102. package/scripts/mjs/verify-temperament-live.mjs +261 -0
  103. package/scripts/node/bridge-mcp-wiring.cjs +277 -29
  104. package/scripts/node/consumer-install-smoke.mjs +55 -2
  105. package/scripts/node/install-bridges.cjs +195 -33
  106. package/scripts/node/postinstall.cjs +50 -27
  107. package/scripts/node/reconcile-version.mjs +0 -4
  108. package/scripts/node/release-gate.mjs +1 -1
  109. package/scripts/node/release.mjs +2 -2
  110. package/scripts/node/universal-version-manager.js +1 -1
  111. package/scripts/node/validate-release-docs.mjs +20 -33
  112. package/scripts/node/version-manager.mjs +63 -18
  113. package/src/integrations/grok/plugin/0xray/hooks/hooks.json +31 -24
  114. package/src/integrations/openclaw/README.md +134 -0
  115. package/src/integrations/openclaw/plugin/xray-pre-tool/index.js +75 -0
  116. package/src/integrations/openclaw/plugin/xray-pre-tool/openclaw.plugin.json +10 -0
  117. package/src/integrations/openclaw/plugin/xray-pre-tool/package.json +12 -0
  118. package/src/mcps/orchestrator/handlers/complexity-handler.ts +2 -1
  119. package/vendor/@0xray/repertoire/AGENTS.md +163 -0
  120. package/vendor/@0xray/repertoire/LICENSE +21 -0
  121. package/vendor/@0xray/repertoire/README.md +120 -0
  122. package/vendor/@0xray/repertoire/data/curated_signals.json +208 -0
  123. package/vendor/@0xray/repertoire/dist/RepertoireService.d.ts +78 -0
  124. package/vendor/@0xray/repertoire/dist/RepertoireService.d.ts.map +1 -0
  125. package/vendor/@0xray/repertoire/dist/RepertoireService.js +153 -0
  126. package/vendor/@0xray/repertoire/dist/RepertoireService.js.map +1 -0
  127. package/vendor/@0xray/repertoire/dist/governance/ontological-trap-enforcer.d.ts +39 -0
  128. package/vendor/@0xray/repertoire/dist/governance/ontological-trap-enforcer.d.ts.map +1 -0
  129. package/vendor/@0xray/repertoire/dist/governance/ontological-trap-enforcer.js +60 -0
  130. package/vendor/@0xray/repertoire/dist/governance/ontological-trap-enforcer.js.map +1 -0
  131. package/vendor/@0xray/repertoire/dist/index.d.ts +14 -0
  132. package/vendor/@0xray/repertoire/dist/index.d.ts.map +1 -0
  133. package/vendor/@0xray/repertoire/dist/index.js +14 -0
  134. package/vendor/@0xray/repertoire/dist/index.js.map +1 -0
  135. package/vendor/@0xray/repertoire/dist/ingestion/groover-log-ingester.d.ts +26 -0
  136. package/vendor/@0xray/repertoire/dist/ingestion/groover-log-ingester.d.ts.map +1 -0
  137. package/vendor/@0xray/repertoire/dist/ingestion/groover-log-ingester.js +109 -0
  138. package/vendor/@0xray/repertoire/dist/ingestion/groover-log-ingester.js.map +1 -0
  139. package/vendor/@0xray/repertoire/dist/ingestion/groover-log-parser.d.ts +18 -0
  140. package/vendor/@0xray/repertoire/dist/ingestion/groover-log-parser.d.ts.map +1 -0
  141. package/vendor/@0xray/repertoire/dist/ingestion/groover-log-parser.js +94 -0
  142. package/vendor/@0xray/repertoire/dist/ingestion/groover-log-parser.js.map +1 -0
  143. package/vendor/@0xray/repertoire/dist/ingestion/orchestrator-feedback-ingester.d.ts +7 -0
  144. package/vendor/@0xray/repertoire/dist/ingestion/orchestrator-feedback-ingester.d.ts.map +1 -0
  145. package/vendor/@0xray/repertoire/dist/ingestion/orchestrator-feedback-ingester.js +18 -0
  146. package/vendor/@0xray/repertoire/dist/ingestion/orchestrator-feedback-ingester.js.map +1 -0
  147. package/vendor/@0xray/repertoire/dist/ingestion/xray-session-ingester.d.ts +31 -0
  148. package/vendor/@0xray/repertoire/dist/ingestion/xray-session-ingester.d.ts.map +1 -0
  149. package/vendor/@0xray/repertoire/dist/ingestion/xray-session-ingester.js +83 -0
  150. package/vendor/@0xray/repertoire/dist/ingestion/xray-session-ingester.js.map +1 -0
  151. package/vendor/@0xray/repertoire/dist/mcp/server.d.ts +6 -0
  152. package/vendor/@0xray/repertoire/dist/mcp/server.d.ts.map +1 -0
  153. package/vendor/@0xray/repertoire/dist/mcp/server.js +173 -0
  154. package/vendor/@0xray/repertoire/dist/mcp/server.js.map +1 -0
  155. package/vendor/@0xray/repertoire/dist/orchestrator-bridge/RepertoireOrchestratorBridge.d.ts +27 -0
  156. package/vendor/@0xray/repertoire/dist/orchestrator-bridge/RepertoireOrchestratorBridge.d.ts.map +1 -0
  157. package/vendor/@0xray/repertoire/dist/orchestrator-bridge/RepertoireOrchestratorBridge.js +107 -0
  158. package/vendor/@0xray/repertoire/dist/orchestrator-bridge/RepertoireOrchestratorBridge.js.map +1 -0
  159. package/vendor/@0xray/repertoire/dist/orchestrator-bridge/capability-enhancer.d.ts +11 -0
  160. package/vendor/@0xray/repertoire/dist/orchestrator-bridge/capability-enhancer.d.ts.map +1 -0
  161. package/vendor/@0xray/repertoire/dist/orchestrator-bridge/capability-enhancer.js +32 -0
  162. package/vendor/@0xray/repertoire/dist/orchestrator-bridge/capability-enhancer.js.map +1 -0
  163. package/vendor/@0xray/repertoire/dist/orchestrator-bridge/confidence-gate.d.ts +9 -0
  164. package/vendor/@0xray/repertoire/dist/orchestrator-bridge/confidence-gate.d.ts.map +1 -0
  165. package/vendor/@0xray/repertoire/dist/orchestrator-bridge/confidence-gate.js +72 -0
  166. package/vendor/@0xray/repertoire/dist/orchestrator-bridge/confidence-gate.js.map +1 -0
  167. package/vendor/@0xray/repertoire/dist/orchestrator-bridge/signal-agent-affinity.d.ts +5 -0
  168. package/vendor/@0xray/repertoire/dist/orchestrator-bridge/signal-agent-affinity.d.ts.map +1 -0
  169. package/vendor/@0xray/repertoire/dist/orchestrator-bridge/signal-agent-affinity.js +18 -0
  170. package/vendor/@0xray/repertoire/dist/orchestrator-bridge/signal-agent-affinity.js.map +1 -0
  171. package/vendor/@0xray/repertoire/dist/orchestrator-bridge/signal-injector.d.ts +31 -0
  172. package/vendor/@0xray/repertoire/dist/orchestrator-bridge/signal-injector.d.ts.map +1 -0
  173. package/vendor/@0xray/repertoire/dist/orchestrator-bridge/signal-injector.js +218 -0
  174. package/vendor/@0xray/repertoire/dist/orchestrator-bridge/signal-injector.js.map +1 -0
  175. package/vendor/@0xray/repertoire/dist/paths.d.ts +24 -0
  176. package/vendor/@0xray/repertoire/dist/paths.d.ts.map +1 -0
  177. package/vendor/@0xray/repertoire/dist/paths.js +74 -0
  178. package/vendor/@0xray/repertoire/dist/paths.js.map +1 -0
  179. package/vendor/@0xray/repertoire/dist/provider/memory-routing-provider.d.ts +141 -0
  180. package/vendor/@0xray/repertoire/dist/provider/memory-routing-provider.d.ts.map +1 -0
  181. package/vendor/@0xray/repertoire/dist/provider/memory-routing-provider.js +210 -0
  182. package/vendor/@0xray/repertoire/dist/provider/memory-routing-provider.js.map +1 -0
  183. package/vendor/@0xray/repertoire/dist/registry/CuratedSignalsManager.d.ts +48 -0
  184. package/vendor/@0xray/repertoire/dist/registry/CuratedSignalsManager.d.ts.map +1 -0
  185. package/vendor/@0xray/repertoire/dist/registry/CuratedSignalsManager.js +221 -0
  186. package/vendor/@0xray/repertoire/dist/registry/CuratedSignalsManager.js.map +1 -0
  187. package/vendor/@0xray/repertoire/dist/registry/InferenceStateManager.d.ts +11 -0
  188. package/vendor/@0xray/repertoire/dist/registry/InferenceStateManager.d.ts.map +1 -0
  189. package/vendor/@0xray/repertoire/dist/registry/InferenceStateManager.js +43 -0
  190. package/vendor/@0xray/repertoire/dist/registry/InferenceStateManager.js.map +1 -0
  191. package/vendor/@0xray/repertoire/dist/registry/signal-prune.d.ts +15 -0
  192. package/vendor/@0xray/repertoire/dist/registry/signal-prune.d.ts.map +1 -0
  193. package/vendor/@0xray/repertoire/dist/registry/signal-prune.js +35 -0
  194. package/vendor/@0xray/repertoire/dist/registry/signal-prune.js.map +1 -0
  195. package/vendor/@0xray/repertoire/dist/synthesis/concrete-sections.d.ts +3 -0
  196. package/vendor/@0xray/repertoire/dist/synthesis/concrete-sections.d.ts.map +1 -0
  197. package/vendor/@0xray/repertoire/dist/synthesis/concrete-sections.js +24 -0
  198. package/vendor/@0xray/repertoire/dist/synthesis/concrete-sections.js.map +1 -0
  199. package/vendor/@0xray/repertoire/dist/synthesis/meta-inference-engine.d.ts +24 -0
  200. package/vendor/@0xray/repertoire/dist/synthesis/meta-inference-engine.d.ts.map +1 -0
  201. package/vendor/@0xray/repertoire/dist/synthesis/meta-inference-engine.js +148 -0
  202. package/vendor/@0xray/repertoire/dist/synthesis/meta-inference-engine.js.map +1 -0
  203. package/vendor/@0xray/repertoire/dist/synthesis/primitive-confidence-aggregator.d.ts +4 -0
  204. package/vendor/@0xray/repertoire/dist/synthesis/primitive-confidence-aggregator.d.ts.map +1 -0
  205. package/vendor/@0xray/repertoire/dist/synthesis/primitive-confidence-aggregator.js +44 -0
  206. package/vendor/@0xray/repertoire/dist/synthesis/primitive-confidence-aggregator.js.map +1 -0
  207. package/vendor/@0xray/repertoire/dist/synthesis/synthesis-prompt-builder.d.ts +22 -0
  208. package/vendor/@0xray/repertoire/dist/synthesis/synthesis-prompt-builder.d.ts.map +1 -0
  209. package/vendor/@0xray/repertoire/dist/synthesis/synthesis-prompt-builder.js +66 -0
  210. package/vendor/@0xray/repertoire/dist/synthesis/synthesis-prompt-builder.js.map +1 -0
  211. package/vendor/@0xray/repertoire/dist/types.d.ts +210 -0
  212. package/vendor/@0xray/repertoire/dist/types.d.ts.map +1 -0
  213. package/vendor/@0xray/repertoire/dist/types.js +2 -0
  214. package/vendor/@0xray/repertoire/dist/types.js.map +1 -0
  215. package/vendor/@0xray/repertoire/docs/MEMORY-ROUTING-PROVIDER.md +54 -0
  216. package/vendor/@0xray/repertoire/hermes-mcp.example.json +20 -0
  217. package/vendor/@0xray/repertoire/mcp-config.example.json +11 -0
  218. package/vendor/@0xray/repertoire/package.json +124 -0
  219. package/vendor/@0xray/repertoire/schemas/curated-signal.schema.json +68 -0
  220. package/vendor/@0xray/repertoire/schemas/inference-log.schema.json +82 -0
  221. package/vendor/@0xray/repertoire/scripts/confirm-suit-all.mjs +253 -0
  222. package/vendor/@0xray/repertoire/scripts/confirm-suit-harness.mjs +220 -0
  223. package/vendor/@0xray/repertoire/scripts/run-live-synthesis-checkpoint.mjs +215 -0
  224. package/vendor/@0xray/repertoire/scripts/suit-bridge-shared.mjs +139 -0
  225. package/vendor/@0xray/repertoire/scripts/verify-grok-suit.mjs +304 -0
  226. package/vendor/@0xray/repertoire/scripts/verify-hermes-suit.mjs +163 -0
  227. package/vendor/@0xray/repertoire/scripts/verify-openclaw-suit.mjs +125 -0
  228. package/vendor/@0xray/repertoire/scripts/verify-opencode-suit.mjs +127 -0
  229. package/vendor/@0xray/repertoire/scripts/verify-synthesis-dogfood.mjs +207 -0
  230. package/vendor/@0xray/repertoire/skills/repertoire-trap-handling/SKILL.md +206 -0
  231. package/xray/codex.json +12 -3
  232. package/xray/features.json +28 -6
  233. package/xray/features.schema.json +31 -0
@@ -0,0 +1,524 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Four-floor compact survival — validatable scenario.
4
+ *
5
+ * Not TUI /compact on a human session. Drives each floor's real wear binary
6
+ * the way a window-death actually hits the suit:
7
+ * Grok PreCompact + PostCompact → session-start.js
8
+ * Hermes session-start (bridge) twice — new session after the window dies
9
+ * OpenCode plugin boot (writeSuitSessionBoot) then inject-read of STATION.md
10
+ * OpenClaw PreToolUse heat (evaluatePreToolGate) then same-session compact rewrite
11
+ *
12
+ * Pass = intent + git + host + "Do not cold-start" still on the card after the cut.
13
+ */
14
+ import { execSync, spawnSync } from 'node:child_process';
15
+ import { existsSync, mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
16
+ import { homedir, tmpdir } from 'node:os';
17
+ import { dirname, join } from 'node:path';
18
+ import { fileURLToPath, pathToFileURL } from 'node:url';
19
+
20
+ const packageRoot = join(dirname(fileURLToPath(import.meta.url)), '../..');
21
+ const grokSession = join(packageRoot, 'dist/integrations/grok/hooks/session-start.js');
22
+ const grokPreTool = join(packageRoot, 'dist/integrations/grok/hooks/pre-tool-use.js');
23
+ const hermesBridge = join(packageRoot, 'dist/integrations/hermes-agent/bridge.mjs');
24
+ const suitJs = join(packageRoot, 'dist/nucleus/suit-temperament.js');
25
+ const gateJs = join(packageRoot, 'dist/nucleus/delegation-gate.js');
26
+
27
+ let failed = 0;
28
+ function pass(n) {
29
+ process.stdout.write(`PASS ${n}\n`);
30
+ }
31
+ function fail(n, d = '') {
32
+ failed++;
33
+ process.stderr.write(`FAIL ${n}${d ? ` — ${d}` : ''}\n`);
34
+ }
35
+ function skip(n) {
36
+ process.stdout.write(`SKIP ${n}\n`);
37
+ }
38
+
39
+ function gitInit(root) {
40
+ execSync('git init', { cwd: root, stdio: 'ignore' });
41
+ execSync('git config user.email "compact@test"', { cwd: root, stdio: 'ignore' });
42
+ execSync('git config user.name "compact"', { cwd: root, stdio: 'ignore' });
43
+ writeFileSync(join(root, 'README.md'), 'four-floor-compact\n');
44
+ execSync('git add README.md', { cwd: root, stdio: 'ignore' });
45
+ execSync('git commit -m "init compact scenario"', { cwd: root, stdio: 'ignore' });
46
+ }
47
+
48
+ function seedFloor(root) {
49
+ mkdirSync(join(root, '.xray', 'state'), { recursive: true });
50
+ writeFileSync(
51
+ join(root, '.xray', 'features.json'),
52
+ JSON.stringify({
53
+ version: '4.0.0',
54
+ suit_temperament: { profile: 'auto' },
55
+ multi_agent_orchestration: {
56
+ enabled: true,
57
+ lead_dev_mode: true,
58
+ auto_chain_delegations: true,
59
+ no_new_surface: true,
60
+ },
61
+ memory_routing: {
62
+ enabled: true,
63
+ provider: 'repertoire',
64
+ module_path: join(packageRoot, 'vendor/@0xray/repertoire/dist/provider/memory-routing-provider.js'),
65
+ config: {
66
+ signalsPath: join(packageRoot, 'vendor/@0xray/repertoire/data/curated_signals.json'),
67
+ statePath: '.xray/state/repertoire/inference-state.json',
68
+ feedbackDir: '.xray/state/repertoire/feedback',
69
+ },
70
+ },
71
+ }),
72
+ );
73
+ gitInit(root);
74
+ }
75
+
76
+ function readCard(root) {
77
+ const p = join(root, '.xray', 'state', 'STATION.md');
78
+ if (!existsSync(p)) return '';
79
+ return readFileSync(p, 'utf8');
80
+ }
81
+
82
+ function readBoot(root) {
83
+ return JSON.parse(readFileSync(join(root, '.xray', 'state', 'session-boot.json'), 'utf8'));
84
+ }
85
+
86
+ function workingPath(root) {
87
+ return join(root, '.xray', 'state', 'repertoire-working.json');
88
+ }
89
+
90
+ function readWorking(root) {
91
+ const p = workingPath(root);
92
+ if (!existsSync(p)) return null;
93
+ return JSON.parse(readFileSync(p, 'utf8'));
94
+ }
95
+
96
+ function assertSurvived(root, { host, intent, profile, hotSwap }) {
97
+ const card = readCard(root);
98
+ const boot = readBoot(root);
99
+ const working = readWorking(root);
100
+ if (!card.includes('Do not cold-start')) fail(`${host} card missing Do not cold-start`);
101
+ else pass(`${host} card still says Do not cold-start`);
102
+ if (!card.includes(`Intent: ${intent}`)) {
103
+ fail(`${host} intent lost`, card.split('\n').find((l) => l.startsWith('Intent:')) || 'no Intent line');
104
+ } else pass(`${host} intent survived: ${intent}`);
105
+ if (!card.includes(`Host: ${host} (${profile})`)) {
106
+ fail(`${host} host/profile`, card.split('\n').find((l) => l.startsWith('Host:')) || '');
107
+ } else pass(`${host} still ${profile}`);
108
+ if (!card.includes('Git:')) fail(`${host} git line missing`);
109
+ else pass(`${host} git line present`);
110
+ if (boot.host !== host) fail(`${host} boot.host`, String(boot.host));
111
+ if (hotSwap) {
112
+ const line = `Hot-swap: ${hotSwap.from} → ${hotSwap.to}`;
113
+ if (!card.includes(line)) fail(`${host} hot-swap lost`, line);
114
+ else pass(`${host} kept ${line}`);
115
+ }
116
+ if (!card.includes('Repertoire: on')) fail(`${host} Repertoire off after compact`, card);
117
+ else pass(`${host} Repertoire still on`);
118
+ if (!card.includes('Working:')) fail(`${host} Working line missing`);
119
+ else pass(`${host} Working line present`);
120
+ if (!working || working.memoryRouting !== 'on') fail(`${host} repertoire-working.json memoryRouting`, JSON.stringify(working));
121
+ else pass(`${host} working json memoryRouting=on`);
122
+ const signals = Array.isArray(working?.matchedSignals) ? working.matchedSignals : [];
123
+ if (!signals.length) fail(`${host} no matchedSignals after compact`);
124
+ else pass(`${host} memory signals survived: ${signals.join(', ')}`);
125
+ if (working.intent !== intent) fail(`${host} working.intent`, String(working.intent));
126
+ }
127
+
128
+ const MEMORY_TAIL =
129
+ 'attestation-as-map consumer-boundary revalidation at every trust-transfer boundary';
130
+
131
+ function memoryIntent(host) {
132
+ return `FLOOR-COMPACT-SURVIVE-${host} ${MEMORY_TAIL}`;
133
+ }
134
+
135
+ const TYPE_UNSAFE = ['an', 'y'].join('');
136
+ const UNSAFE_TS = `const x: ${TYPE_UNSAFE} = 1`;
137
+
138
+ function runGrokSession(root, hookEvent, extra = {}) {
139
+ const payload = JSON.stringify({
140
+ hookEventName: hookEvent,
141
+ sessionId: extra.sessionId || 'floor-compact-grok',
142
+ workspaceRoot: root,
143
+ cwd: root,
144
+ ...(extra.intent ? { prompt: extra.intent } : {}),
145
+ ...(extra.compactContext ? { compactContext: extra.compactContext } : {}),
146
+ });
147
+ execSync(`printf '%s' '${payload.replace(/'/g, "'\\''")}' | node "${grokSession}"`, {
148
+ encoding: 'utf8',
149
+ env: {
150
+ ...process.env,
151
+ GROK_WORKSPACE_ROOT: root,
152
+ GROK_HOOK_EVENT: hookEvent,
153
+ GROK_SESSION_ID: extra.sessionId || 'floor-compact-grok',
154
+ },
155
+ });
156
+ }
157
+
158
+ function runHermesSession(root, sessionId) {
159
+ const json = JSON.stringify({
160
+ command: 'session-start',
161
+ sessionId,
162
+ }).replace(/'/g, "'\\''");
163
+ execSync(`node "${hermesBridge}" session-start --cwd "${root}" '${json}'`, {
164
+ cwd: root,
165
+ encoding: 'utf8',
166
+ env: { ...process.env, XRAY_ROOT: root },
167
+ });
168
+ }
169
+
170
+ process.stdout.write('four-floor compact survival\n\n');
171
+
172
+ function runGrokPreTool(root, fixture) {
173
+ const payload = JSON.stringify(fixture);
174
+ const out = execSync(`printf '%s' '${payload.replace(/'/g, "'\\''")}' | node "${grokPreTool}"`, {
175
+ encoding: 'utf8',
176
+ env: { ...process.env, GROK_WORKSPACE_ROOT: root, GROK_SESSION_ID: 'floor-compact-grok' },
177
+ });
178
+ return JSON.parse(out.trim().split('\n').filter(Boolean).at(-1));
179
+ }
180
+
181
+ function constitutionBundle(root, host) {
182
+ const feat = loadDelegationGateFeatures(root, host);
183
+ const surfacePath = 'src/mcps/floor-new.server.ts';
184
+ const evalPayload = { path: surfacePath, new_string: 'export {}\n' };
185
+ if (host === 'grok') {
186
+ return {
187
+ spawn: runGrokPreTool(root, {
188
+ toolName: 'spawn_subagent',
189
+ workspaceRoot: root,
190
+ sessionId: 'compact-grok-1',
191
+ toolInput: { prompt: 'explore repo', subagent_type: 'explore' },
192
+ }),
193
+ eleven: runGrokPreTool(root, {
194
+ toolName: 'search_replace',
195
+ workspaceRoot: root,
196
+ sessionId: 'compact-grok-1',
197
+ toolInput: { path: 'src/foo.ts', new_string: UNSAFE_TS },
198
+ }),
199
+ surface: runGrokPreTool(root, {
200
+ toolName: 'search_replace',
201
+ workspaceRoot: root,
202
+ sessionId: 'compact-grok-1',
203
+ toolInput: evalPayload,
204
+ }),
205
+ destructive: runGrokPreTool(root, {
206
+ toolName: 'bash',
207
+ workspaceRoot: root,
208
+ sessionId: 'compact-grok-1',
209
+ toolInput: { command: 'rm -rf /' },
210
+ }),
211
+ };
212
+ }
213
+ if (host === 'hermes') {
214
+ return {
215
+ spawn: runHermesGate(root, {
216
+ tool: 'delegate_task',
217
+ args: { prompt: 'explore repo', subagent_type: 'explore' },
218
+ }),
219
+ eleven: runHermesGate(root, {
220
+ tool: 'write_file',
221
+ args: { path: 'src/foo.ts', content: UNSAFE_TS },
222
+ }),
223
+ surface: runHermesGate(root, {
224
+ tool: 'write_file',
225
+ args: { path: surfacePath, content: 'export {}\n' },
226
+ }),
227
+ destructive: runHermesGate(root, {
228
+ tool: 'bash',
229
+ args: { command: 'rm -rf /' },
230
+ }),
231
+ };
232
+ }
233
+ const sessionId = host === 'opencode' ? 'compact-oc-1' : 'compact-claw-1';
234
+ const writeTool = host === 'opencode' ? 'write' : 'write';
235
+ return {
236
+ spawn: evaluatePreToolGate(
237
+ 'Task',
238
+ { prompt: 'explore repo', subagent_type: 'explore' },
239
+ { projectRoot: root, sessionId, features: feat, host },
240
+ ),
241
+ eleven: evaluatePreToolGate(
242
+ writeTool,
243
+ { path: 'src/foo.ts', content: UNSAFE_TS },
244
+ { projectRoot: root, sessionId, features: feat, host },
245
+ ),
246
+ surface: evaluatePreToolGate(
247
+ writeTool,
248
+ { path: surfacePath, content: 'export {}\n' },
249
+ { projectRoot: root, sessionId, features: feat, host },
250
+ ),
251
+ destructive: evaluatePreToolGate(
252
+ 'bash',
253
+ { command: 'rm -rf /' },
254
+ { projectRoot: root, sessionId, features: feat, host },
255
+ ),
256
+ };
257
+ }
258
+
259
+ function liveQuotedCard(text, intent) {
260
+ return (
261
+ text.includes('Do not cold-start') ||
262
+ text.includes(`Intent: ${intent}`) ||
263
+ text.includes(intent.slice(0, 28)) ||
264
+ /Host:\s+\w+\s+\((frontier|guided|strict)\)/.test(text)
265
+ );
266
+ }
267
+
268
+ function liveAuthBlocked(text) {
269
+ return /403|bad-credentials|unauthenticated|401|spend.?limit|insufficient/i.test(text);
270
+ }
271
+
272
+ function tryLiveSuccessor(root, host, intent) {
273
+ if (process.env.XRAY_LIVE_SUCCESSOR !== '1') return;
274
+ const relQuote =
275
+ 'Read .xray/state/STATION.md. Reply with only the Host line and the Intent line. Do not edit files.';
276
+ const absQuote = `Read ${join(root, '.xray', 'state', 'STATION.md')}. Reply with only the Host line and the Intent line. Do not edit files.`;
277
+ const cmds = {
278
+ grok: ['grok', '-p', relQuote, '--cwd', root, '--always-approve', '--disable-web-search'],
279
+ opencode: ['opencode', 'run', '--dir', root, relQuote],
280
+ hermes: [
281
+ 'hermes',
282
+ '-z',
283
+ relQuote,
284
+ '--cli',
285
+ '--provider',
286
+ 'xai-oauth',
287
+ '-m',
288
+ 'grok-4.5',
289
+ '--yolo',
290
+ '--no-restore-cwd',
291
+ ],
292
+ openclaw: [
293
+ 'openclaw',
294
+ 'agent',
295
+ '--thinking',
296
+ 'low',
297
+ '--timeout',
298
+ '90',
299
+ '--model',
300
+ 'xai/grok-4.5',
301
+ '--message',
302
+ absQuote,
303
+ ],
304
+ };
305
+ const argv = cmds[host];
306
+ if (!argv) return;
307
+ const which = spawnSync('which', [argv[0]], { encoding: 'utf8' });
308
+ if (which.status !== 0) {
309
+ skip(`${host} live successor (CLI not on PATH)`);
310
+ return;
311
+ }
312
+ const node24 = join(homedir(), '.local/node24/current/bin');
313
+ const env = {
314
+ ...process.env,
315
+ GROK_WORKSPACE_ROOT: root,
316
+ XRAY_ROOT: root,
317
+ PATH: existsSync(join(node24, 'node')) ? `${node24}:${process.env.PATH || ''}` : process.env.PATH,
318
+ };
319
+ const timeoutMs = host === 'openclaw' ? 110000 : 80000;
320
+ const result = spawnSync(argv[0], argv.slice(1), {
321
+ cwd: root,
322
+ encoding: 'utf8',
323
+ timeout: timeoutMs,
324
+ env,
325
+ stdio: ['ignore', 'pipe', 'pipe'],
326
+ });
327
+ const text = `${result.stdout || ''}\n${result.stderr || ''}`;
328
+ const err = result.error ? String(result.error.message || result.error) : '';
329
+ const combined = `${text}\n${err}`;
330
+ if (liveQuotedCard(combined, intent)) {
331
+ pass(`${host} live successor quoted the station card`);
332
+ return;
333
+ }
334
+ if (liveAuthBlocked(combined)) {
335
+ skip(`${host} live successor (host auth)`);
336
+ return;
337
+ }
338
+ if (/ETIMEDOUT|timed out|TIMEOUT/i.test(combined) || result.error?.code === 'ETIMEDOUT') {
339
+ fail(`${host} live successor timed out`, combined.slice(0, 200));
340
+ return;
341
+ }
342
+ fail(`${host} live successor did not quote the card`, combined.slice(0, 240));
343
+ }
344
+
345
+ function runHermesGate(root, extra) {
346
+ const json = JSON.stringify({
347
+ command: 'delegation-gate',
348
+ phase: 'pre',
349
+ sessionId: 'floor-compact-hermes',
350
+ host: 'hermes',
351
+ ...extra,
352
+ }).replace(/'/g, "'\\''");
353
+ const out = execSync(`node "${hermesBridge}" delegation-gate --cwd "${root}" '${json}'`, {
354
+ cwd: root,
355
+ encoding: 'utf8',
356
+ env: { ...process.env, XRAY_ROOT: root },
357
+ });
358
+ return JSON.parse(out.trim().split('\n').filter(Boolean).at(-1));
359
+ }
360
+
361
+ function denied(g) {
362
+ return g && (g.allow === false || g.decision === 'deny');
363
+ }
364
+
365
+ function assertConstitutionAndTemperament(root, host, { spawn, eleven, surface, destructive }) {
366
+ if (spawn.allow === false && spawn.gate === 'spawn-plan-missing') {
367
+ pass(`${host} temperament denies spawn without plan (guided)`);
368
+ } else if (host === 'grok' && spawn.decision === 'allow' && spawn.warn === true) {
369
+ pass(`${host} temperament warns spawn without plan (frontier)`);
370
+ } else if (spawn.allow !== false && spawn.warn === true) {
371
+ pass(`${host} temperament warns spawn without plan (frontier)`);
372
+ } else {
373
+ fail(`${host} temperament spawn`, JSON.stringify(spawn));
374
+ }
375
+ if (denied(eleven) && eleven.gate === 'codex-11') pass(`${host} constitution denies Codex 11`);
376
+ else fail(`${host} constitution Codex 11`, JSON.stringify(eleven));
377
+ if (denied(surface) && surface.gate === 'no-new-surface') pass(`${host} constitution denies Codex 69 new surface`);
378
+ else fail(`${host} constitution Codex 69`, JSON.stringify(surface));
379
+ if (denied(destructive) && destructive.gate === 'destructive-shell') {
380
+ pass(`${host} constitution denies destructive shell`);
381
+ } else fail(`${host} constitution destructive shell`, JSON.stringify(destructive));
382
+ }
383
+
384
+ for (const p of [grokSession, grokPreTool, hermesBridge, suitJs, gateJs]) {
385
+ if (existsSync(p)) pass(`dist ${p.slice(packageRoot.length + 1)}`);
386
+ else fail('missing dist', p);
387
+ }
388
+
389
+ const { writeSuitSessionBoot } = await import(pathToFileURL(suitJs).href);
390
+ const { evaluatePreToolGate, loadDelegationGateFeatures } = await import(pathToFileURL(gateJs).href);
391
+
392
+ {
393
+ const tmp = mkdtempSync(join(tmpdir(), 'xray-compact-grok-'));
394
+ try {
395
+ seedFloor(tmp);
396
+ const intent = memoryIntent('grok');
397
+ assertConstitutionAndTemperament(tmp, 'grok', constitutionBundle(tmp, 'grok'));
398
+ runGrokSession(tmp, 'session_start', { intent, sessionId: 'compact-grok-1' });
399
+ runGrokSession(tmp, 'pre_compact', { sessionId: 'compact-grok-1' });
400
+ runGrokSession(tmp, 'post_compact', { sessionId: 'compact-grok-1' });
401
+ assertSurvived(tmp, { host: 'grok', intent, profile: 'frontier' });
402
+ const boot = readBoot(tmp);
403
+ pass(`Grok compact source=${boot.source} hookEvent=${boot.hookEvent}`);
404
+ tryLiveSuccessor(tmp, 'grok', intent);
405
+ } finally {
406
+ rmSync(tmp, { recursive: true, force: true });
407
+ }
408
+ }
409
+
410
+ {
411
+ const tmp = mkdtempSync(join(tmpdir(), 'xray-compact-hermes-'));
412
+ try {
413
+ seedFloor(tmp);
414
+ const intent = memoryIntent('hermes');
415
+ assertConstitutionAndTemperament(tmp, 'hermes', constitutionBundle(tmp, 'hermes'));
416
+ writeSuitSessionBoot(tmp, 'hermes', {
417
+ source: '0xray/hermes-user',
418
+ sessionId: 'compact-hermes-1',
419
+ intent,
420
+ });
421
+ runHermesSession(tmp, 'compact-hermes-1');
422
+ const compactJson = JSON.stringify({
423
+ command: 'session-start',
424
+ sessionId: 'compact-hermes-2',
425
+ compact: true,
426
+ }).replace(/'/g, "'\\''");
427
+ execSync(`node "${hermesBridge}" session-start --cwd "${tmp}" '${compactJson}'`, {
428
+ cwd: tmp,
429
+ encoding: 'utf8',
430
+ env: { ...process.env, XRAY_ROOT: tmp },
431
+ });
432
+ assertSurvived(tmp, { host: 'hermes', intent, profile: 'guided' });
433
+ tryLiveSuccessor(tmp, 'hermes', intent);
434
+ } finally {
435
+ rmSync(tmp, { recursive: true, force: true });
436
+ }
437
+ }
438
+
439
+ {
440
+ const tmp = mkdtempSync(join(tmpdir(), 'xray-compact-opencode-'));
441
+ try {
442
+ seedFloor(tmp);
443
+ const intent = memoryIntent('opencode');
444
+ assertConstitutionAndTemperament(tmp, 'opencode', constitutionBundle(tmp, 'opencode'));
445
+ writeSuitSessionBoot(tmp, 'opencode', {
446
+ source: '0xray/opencode-user',
447
+ sessionId: 'compact-oc-1',
448
+ intent,
449
+ });
450
+ writeSuitSessionBoot(tmp, 'opencode', {
451
+ source: '0xray/opencode-plugin',
452
+ hookEvent: 'post_compact',
453
+ });
454
+ assertSurvived(tmp, { host: 'opencode', intent, profile: 'guided' });
455
+ tryLiveSuccessor(tmp, 'opencode', intent);
456
+ const card = readCard(tmp);
457
+ if (card.includes(intent) && card.includes('Do not cold-start')) {
458
+ pass('OpenCode successor would inject STATION.md (plugin system.transform)');
459
+ }
460
+ } finally {
461
+ rmSync(tmp, { recursive: true, force: true });
462
+ }
463
+ }
464
+
465
+ {
466
+ const tmp = mkdtempSync(join(tmpdir(), 'xray-compact-openclaw-'));
467
+ try {
468
+ seedFloor(tmp);
469
+ const intent = memoryIntent('openclaw');
470
+ const feat = loadDelegationGateFeatures(tmp, 'openclaw');
471
+ assertConstitutionAndTemperament(tmp, 'openclaw', constitutionBundle(tmp, 'openclaw'));
472
+ writeSuitSessionBoot(tmp, 'openclaw', {
473
+ source: '0xray/openclaw-user',
474
+ sessionId: 'compact-claw-1',
475
+ intent,
476
+ });
477
+ evaluatePreToolGate(
478
+ 'read',
479
+ { path: 'README.md' },
480
+ {
481
+ projectRoot: tmp,
482
+ sessionId: 'compact-claw-1',
483
+ features: feat,
484
+ host: 'openclaw',
485
+ hookEvent: 'post_compact',
486
+ },
487
+ );
488
+ writeSuitSessionBoot(tmp, 'openclaw', {
489
+ source: '0xray/openclaw-compact',
490
+ sessionId: 'compact-claw-1',
491
+ hookEvent: 'post_compact',
492
+ });
493
+ assertSurvived(tmp, { host: 'openclaw', intent, profile: 'guided' });
494
+ tryLiveSuccessor(tmp, 'openclaw', intent);
495
+ } finally {
496
+ rmSync(tmp, { recursive: true, force: true });
497
+ }
498
+ }
499
+
500
+ {
501
+ const tmp = mkdtempSync(join(tmpdir(), 'xray-compact-swap-'));
502
+ try {
503
+ seedFloor(tmp);
504
+ const intent = memoryIntent('hotswap');
505
+ runGrokSession(tmp, 'session_start', { intent, sessionId: 'swap-1' });
506
+ writeSuitSessionBoot(tmp, 'opencode', { source: '0xray/opencode-plugin', sessionId: 'swap-2' });
507
+ writeSuitSessionBoot(tmp, 'opencode', { source: '0xray/opencode-compact', sessionId: 'swap-2' });
508
+ assertSurvived(tmp, {
509
+ host: 'opencode',
510
+ intent,
511
+ profile: 'guided',
512
+ hotSwap: { from: 'grok', to: 'opencode' },
513
+ });
514
+ } finally {
515
+ rmSync(tmp, { recursive: true, force: true });
516
+ }
517
+ }
518
+
519
+ if (failed) {
520
+ process.stderr.write(`four-floor compact survival failed (${failed})\n`);
521
+ process.exit(1);
522
+ }
523
+ process.stdout.write('four-floor compact survival passed\n');
524
+ process.exit(0);