@neuroverseos/governance 0.8.0 → 0.9.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.
@@ -40,10 +40,16 @@ __export(radiant_exports, {
40
40
  classifyActorDomain: () => classifyActorDomain,
41
41
  classifyEvents: () => classifyEvents,
42
42
  composeSystemPrompt: () => composeSystemPrompt,
43
+ compressExocortex: () => compressExocortex,
44
+ compressLens: () => compressLens,
45
+ compressPriorReads: () => compressPriorReads,
46
+ compressWorldmodel: () => compressWorldmodel,
43
47
  computePersistence: () => computePersistence,
44
48
  createAnthropicAI: () => createAnthropicAI,
45
49
  createMockAI: () => createMockAI,
46
50
  createMockGitHubAdapter: () => createMockGitHubAdapter,
51
+ detectOrgExtendsSpec: () => detectOrgExtendsSpec,
52
+ discoverWorlds: () => discoverWorlds,
47
53
  emergent: () => emergent,
48
54
  extractSignals: () => extractSignals,
49
55
  fetchDiscordActivity: () => fetchDiscordActivity,
@@ -51,6 +57,7 @@ __export(radiant_exports, {
51
57
  fetchGitHubOrgActivity: () => fetchGitHubOrgActivity,
52
58
  fetchNotionActivity: () => fetchNotionActivity,
53
59
  fetchSlackActivity: () => fetchSlackActivity,
60
+ formatActiveWorlds: () => formatActiveWorlds,
54
61
  formatDiscordSignalsForPrompt: () => formatDiscordSignalsForPrompt,
55
62
  formatExocortexForPrompt: () => formatExocortexForPrompt,
56
63
  formatNotionSignalsForPrompt: () => formatNotionSignalsForPrompt,
@@ -58,23 +65,32 @@ __export(radiant_exports, {
58
65
  formatScope: () => formatScope,
59
66
  formatSlackSignalsForPrompt: () => formatSlackSignalsForPrompt,
60
67
  formatTeamExocorticesForPrompt: () => formatTeamExocorticesForPrompt,
68
+ getCacheDir: () => getCacheDir,
61
69
  getLens: () => getLens,
70
+ getRepoOrigin: () => getRepoOrigin,
62
71
  interpretPatterns: () => interpretPatterns,
63
72
  isPresent: () => isPresent,
64
73
  isScored: () => isScored,
65
74
  isSentinel: () => isSentinel,
66
75
  listLenses: () => listLenses,
76
+ loadExtendsConfig: () => loadExtendsConfig,
67
77
  loadPriorReads: () => loadPriorReads,
78
+ parseExtendsSpec: () => parseExtendsSpec,
79
+ parseRemoteUrl: () => parseRemoteUrl,
68
80
  parseRepoScope: () => parseRepoScope,
69
81
  parseScope: () => parseScope,
70
82
  presenceAverage: () => presenceAverage,
71
83
  readExocortex: () => readExocortex,
84
+ readOriginRemote: () => readOriginRemote,
72
85
  readTeamExocortices: () => readTeamExocortices,
73
86
  render: () => render,
87
+ resolveAllExtends: () => resolveAllExtends,
88
+ resolveExtendsSpec: () => resolveExtendsSpec,
74
89
  scoreComposite: () => scoreComposite,
75
90
  scoreCyber: () => scoreCyber,
76
91
  scoreLife: () => scoreLife,
77
92
  scoreNeuroVerse: () => scoreNeuroVerse,
93
+ sovereignConduitLens: () => sovereignConduitLens,
78
94
  summarizeExocortex: () => summarizeExocortex,
79
95
  think: () => think,
80
96
  updateKnowledge: () => updateKnowledge,
@@ -564,9 +580,290 @@ var aukiBuilderLens = {
564
580
  rewrite: aukiBuilderRewrite
565
581
  };
566
582
 
583
+ // src/radiant/lenses/sovereign-conduit.ts
584
+ var SOVEREIGN_CONDUIT_FRAME = {
585
+ domains: [
586
+ "stewardship",
587
+ "agency",
588
+ "integration"
589
+ ],
590
+ overlaps: [
591
+ {
592
+ domains: ["stewardship", "agency"],
593
+ emergent_state: "Trust",
594
+ description: "I am safe to be myself. When the system protects AND preserves individual authority, trust emerges \u2014 the feeling that you can think freely because someone is watching the boundaries."
595
+ },
596
+ {
597
+ domains: ["agency", "integration"],
598
+ emergent_state: "Possibility",
599
+ description: "My thinking can expand. When individual authority is preserved AND AI extends cognitive capability, possibility opens \u2014 the feeling that you can reach further without losing yourself."
600
+ },
601
+ {
602
+ domains: ["integration", "stewardship"],
603
+ emergent_state: "Responsibility",
604
+ description: "Power is used with care. When AI extends capability AND the system protects integrity, responsibility emerges \u2014 the feeling that expansion comes with guardrails, not recklessness."
605
+ }
606
+ ],
607
+ center_identity: "The Sovereign Conduit",
608
+ evaluation_questions: [
609
+ "Is the human maintaining authority over their decisions, or is decision ownership quietly shifting to the AI?",
610
+ "Is the AI extending thinking, or is it replacing thinking? Look for the difference: extension means the human understands and owns the output. Replacement means they accept it without engaging.",
611
+ "Are the boundaries between human thinking and AI output clear and visible, or are they blurring?",
612
+ "Is diversity of thought preserved? Are people thinking differently from each other, or is the system funneling everyone into the same patterns?",
613
+ "Would you feel safe letting a child learn in this system? If not, what specifically makes it unsafe?",
614
+ "If this felt wrong, could you leave? Is the exit real or theoretical?"
615
+ ],
616
+ scoring_rubric: "For any activity, ask: is the human still the author of their decisions? Is the AI helping them think further, or thinking for them? Are the rules of this space clear, fair, and safe \u2014 like the rules at a good friend's house? When something feels off, name the feeling first, then the mechanism. Use everyday language. If a non-technical person couldn't understand the observation, rephrase it until they could.",
617
+ domain_skills: {
618
+ "stewardship": [
619
+ "boundary setting",
620
+ "risk awareness",
621
+ "ethical judgment",
622
+ "system protection",
623
+ "conflict stabilization",
624
+ "responsibility signaling",
625
+ "harm detection",
626
+ "constraint design"
627
+ ],
628
+ "agency": [
629
+ "independent thinking",
630
+ "decision ownership",
631
+ "self-trust",
632
+ "value clarity",
633
+ "cognitive resistance",
634
+ "identity anchoring",
635
+ "perspective holding",
636
+ "authentic expression"
637
+ ],
638
+ "integration": [
639
+ "AI collaboration",
640
+ "cognitive expansion",
641
+ "prompt framing",
642
+ "insight synthesis",
643
+ "signal interpretation",
644
+ "tool fluency",
645
+ "co-creation",
646
+ "iterative thinking"
647
+ ]
648
+ },
649
+ output_translation: {
650
+ never_surface_in_output: [
651
+ "Stewardship",
652
+ "Agency",
653
+ "Integration"
654
+ ],
655
+ surface_freely: [
656
+ "Trust",
657
+ "Possibility",
658
+ "Responsibility",
659
+ "Sovereign Conduit"
660
+ ],
661
+ translation_examples: [
662
+ {
663
+ internal_reasoning: "Stewardship is strong",
664
+ external_expression: "the boundaries are clear and the system feels safe to operate inside"
665
+ },
666
+ {
667
+ internal_reasoning: "Agency is weakening",
668
+ external_expression: "decision ownership is quietly shifting \u2014 the human is accepting AI output without engaging with it"
669
+ },
670
+ {
671
+ internal_reasoning: "Integration is high but Stewardship is low",
672
+ external_expression: "the AI is expanding capability fast, but nobody is watching the guardrails \u2014 that's power without responsibility"
673
+ }
674
+ ]
675
+ }
676
+ };
677
+ var SOVEREIGN_CONDUIT_VOCABULARY = {
678
+ proper_nouns: [
679
+ "NeuroVerseOS",
680
+ "Sovereign Conduit",
681
+ "LifeOS",
682
+ "CyberOS",
683
+ "NeuroverseOS"
684
+ ],
685
+ preferred: {
686
+ "worldmodel": "thinking constitution",
687
+ "invariant": "non-negotiable rule",
688
+ "governance": "the rules of the space",
689
+ "alignment": "how well the work matches what was declared",
690
+ "drift": "quiet shift away from what was intended",
691
+ "signal": "something observable",
692
+ "evidence gate": "how much we need to see before we speak",
693
+ "actor domain": "who did the work \u2014 a person, an AI, or both together",
694
+ "rendering lens": "how the system speaks",
695
+ "candidate pattern": "something noticed but not yet named as important",
696
+ "cognitive liberty": "your right to think for yourself",
697
+ "homogenization": "everyone being funneled into the same patterns"
698
+ },
699
+ architecture: [
700
+ "thinking constitution",
701
+ "thinking space",
702
+ "cognitive extension",
703
+ "behavioral model",
704
+ "governance frame",
705
+ "world file",
706
+ "cocoon"
707
+ ],
708
+ economic: [],
709
+ framing: [
710
+ "humanity first",
711
+ "in constant learning",
712
+ "in shared teaching",
713
+ "extension not replacement",
714
+ "safe to think freely",
715
+ "the rules of this house",
716
+ "sovereign over your own thinking",
717
+ "idea calculator",
718
+ "Spock in your life",
719
+ "Jarvis in your life",
720
+ "funneling into fields",
721
+ "diversity of thought",
722
+ "thinking for yourself"
723
+ ],
724
+ jargon_translations: {
725
+ "worldmodel": "thinking constitution",
726
+ "invariant": "non-negotiable rule",
727
+ "canonical pattern": "something we're tracking by name",
728
+ "candidate pattern": "something noticed but not yet tracked",
729
+ "evidence gate": "how much we need to see before we speak up",
730
+ "signal extraction": "reading what happened",
731
+ "alignment score": "how well the work matches what was declared",
732
+ "actor domain": "who did this \u2014 a person, an AI, or both",
733
+ "presence-based averaging": "only counting what actually happened",
734
+ "drift detection": "noticing when things quietly shift",
735
+ "INSUFFICIENT_EVIDENCE": "not enough to say yet",
736
+ "UNAVAILABLE": "can't measure this yet",
737
+ "rendering lens": "how the system speaks to you"
738
+ }
739
+ };
740
+ var SOVEREIGN_CONDUIT_VOICE = {
741
+ register: "warm, accessible, teaching. Like a thoughtful parent explaining how the world works \u2014 not talking down, but making the complex feel natural. Use everyday analogies. Name emotions. If a non-technical person couldn't understand the output, it's wrong.",
742
+ active_voice: "preferred",
743
+ specificity: "preferred",
744
+ hype_vocabulary: "forbidden",
745
+ hedging: "discouraged",
746
+ playfulness: "allowed",
747
+ close_with_strategic_frame: "preferred",
748
+ punchline_move: "sparing",
749
+ honesty_about_failure: "required",
750
+ output_translation: `Reason internally through the three-domain frame (Stewardship, Agency, Integration). Express externally through the skills inside each domain and the overlap feelings (Trust, Possibility, Responsibility). Do NOT surface the bucket names as labels. Readers understand "the boundaries feel safe" not "Stewardship is strong." Use everyday analogies \u2014 mom rules, friend's house rules, idea calculator. Name the emotion before the mechanism.`
751
+ };
752
+ var SOVEREIGN_CONDUIT_FORBIDDEN = Object.freeze([
753
+ // Bucket names as labels
754
+ "stewardship is",
755
+ "agency is",
756
+ "integration is",
757
+ // AI-assistant hedging
758
+ "it may be beneficial to consider",
759
+ "there appears to be",
760
+ "one possible interpretation",
761
+ "it might be worth exploring",
762
+ "consider whether",
763
+ "it is worth noting",
764
+ // Corporate
765
+ "stakeholders",
766
+ "synergy",
767
+ "value proposition",
768
+ "paradigm shift",
769
+ "best-in-class",
770
+ "industry-leading",
771
+ // Cold/mechanical
772
+ "the system recommends",
773
+ "analysis suggests",
774
+ "data indicates",
775
+ "metrics show",
776
+ "according to the model"
777
+ ]);
778
+ var SOVEREIGN_CONDUIT_PREFERRED = Object.freeze([
779
+ // Everyday analogies
780
+ "This is like [everyday analogy]. [What it means].",
781
+ "Think of it like the rules at a friend's house \u2014 [application].",
782
+ "The boundaries are [state]. That means [feeling].",
783
+ // Emotion-first
784
+ "This feels like [emotion] because [mechanism].",
785
+ "Trust is [emerging/breaking] here \u2014 [specific evidence].",
786
+ "Possibility is opening because [evidence]. But [caveat if any].",
787
+ // Teaching voice
788
+ "Here's what's actually happening: [plain explanation].",
789
+ "The question to ask yourself: [question].",
790
+ "The difference between [A] and [B] matters here: [why].",
791
+ // Agency checks
792
+ "Are you still the author of this decision, or did the AI make it for you?",
793
+ "The AI extended your thinking here. That's working.",
794
+ "The AI replaced your thinking here. That's the drift to watch.",
795
+ // Safety
796
+ "Would you feel safe letting someone learn in this environment? [Why/why not].",
797
+ "The exit is real \u2014 you can [specific exit path].",
798
+ "The exit isn't real here \u2014 [what's blocking it]."
799
+ ]);
800
+ var SOVEREIGN_CONDUIT_STRATEGIC = Object.freeze([
801
+ "Safety before expansion \u2014 always. No exception.",
802
+ "Agency before convenience \u2014 the right to think for yourself is not a feature to optimize away.",
803
+ "Extension, not replacement \u2014 AI should make your thinking bigger, not do your thinking for you.",
804
+ "Diversity over uniformity \u2014 different thinkers produce different ideas, and that's the engine of progress.",
805
+ "The rules should be visible \u2014 like a good house, you know the rules before you walk in.",
806
+ "Exit must be real \u2014 if you can't leave a system that feels wrong, it's not governance, it's a cage.",
807
+ "Teach, don't lecture \u2014 help people think for themselves, not think what you think.",
808
+ "Name the feeling first \u2014 when something is off, the emotion arrives before the analysis. Trust that."
809
+ ]);
810
+ var SOVEREIGN_CONDUIT_EXEMPLARS = Object.freeze([
811
+ {
812
+ path: "src/radiant/examples/neuroverse-base/neuroverseos-sovereign-conduit.worldmodel.md",
813
+ title: "The Sovereign Conduit Worldmodel",
814
+ exhibits: ["stewardship", "agency", "integration"],
815
+ integration_quality: "full \u2014 all three domains defined, overlaps named, center identity declared",
816
+ notes: 'The source worldmodel. The tagline "Humanity first. In constant learning. In shared teaching." is the voice compressed to its essence. Use this as the north star for tone calibration.'
817
+ }
818
+ ]);
819
+ function sovereignConduitRewrite(pattern) {
820
+ if (pattern.evidence.cited_invariant) {
821
+ return {
822
+ ...pattern,
823
+ framing: "non-negotiable rule tested",
824
+ emphasis: "name the rule, name who it protects, name what would happen without it",
825
+ compress: false
826
+ // Sovereign Conduit is warm, not compressed
827
+ };
828
+ }
829
+ if (pattern.type === "candidate") {
830
+ return {
831
+ ...pattern,
832
+ framing: "something new noticed",
833
+ emphasis: "explain what was seen in everyday language, ask whether it matters",
834
+ compress: false
835
+ };
836
+ }
837
+ return {
838
+ ...pattern,
839
+ framing: "what this means for the people in the system",
840
+ emphasis: "humanity + agency + learning",
841
+ compress: false
842
+ };
843
+ }
844
+ var sovereignConduitLens = {
845
+ name: "sovereign-conduit",
846
+ description: "The NeuroVerseOS base lens. Warm, accessible, teaching. Evaluates activity through Stewardship (safety), Agency (authority over thinking), and Integration (AI as cognitive extension). Uses everyday analogies \u2014 mom rules, friend's house, idea calculator. Names emotions before mechanisms. If a non-technical person can't understand the output, the voice is wrong. Humanity first. In constant learning. In shared teaching.",
847
+ primary_frame: {
848
+ domains: SOVEREIGN_CONDUIT_FRAME.domains,
849
+ overlaps: SOVEREIGN_CONDUIT_FRAME.overlaps,
850
+ center_identity: SOVEREIGN_CONDUIT_FRAME.center_identity,
851
+ evaluation_questions: SOVEREIGN_CONDUIT_FRAME.evaluation_questions,
852
+ scoring_rubric: SOVEREIGN_CONDUIT_FRAME.scoring_rubric
853
+ },
854
+ vocabulary: SOVEREIGN_CONDUIT_VOCABULARY,
855
+ voice: SOVEREIGN_CONDUIT_VOICE,
856
+ forbidden_phrases: SOVEREIGN_CONDUIT_FORBIDDEN,
857
+ preferred_patterns: SOVEREIGN_CONDUIT_PREFERRED,
858
+ strategic_patterns: SOVEREIGN_CONDUIT_STRATEGIC,
859
+ exemplar_refs: SOVEREIGN_CONDUIT_EXEMPLARS,
860
+ rewrite: sovereignConduitRewrite
861
+ };
862
+
567
863
  // src/radiant/lenses/index.ts
568
864
  var LENSES = Object.freeze({
569
- "auki-builder": aukiBuilderLens
865
+ "auki-builder": aukiBuilderLens,
866
+ "sovereign-conduit": sovereignConduitLens
570
867
  });
571
868
  function getLens(id) {
572
869
  return LENSES[id];
@@ -710,91 +1007,166 @@ var DEFAULT_SIGNAL_EXTRACTORS = Object.freeze([
710
1007
  DECISION_MOMENTUM_EXTRACTOR
711
1008
  ]);
712
1009
 
1010
+ // src/radiant/core/compress.ts
1011
+ function compressWorldmodel(content) {
1012
+ const lines = [];
1013
+ const missionMatch = content.match(/##\s*Mission\s*\n+(?:<!--[\s\S]*?-->\s*\n+)?(.*?)(?:\n\n|\n##|$)/s);
1014
+ if (missionMatch) {
1015
+ const mission = missionMatch[1].trim().split("\n")[0];
1016
+ lines.push(`Mission: ${mission}`);
1017
+ }
1018
+ const domainMatches = content.matchAll(/###\s+([^\n]+)/g);
1019
+ const domains = [];
1020
+ for (const m of domainMatches) {
1021
+ const name = m[1].trim();
1022
+ if (name !== "Skills" && name !== "Values" && !name.startsWith("####")) {
1023
+ domains.push(name);
1024
+ }
1025
+ }
1026
+ if (domains.length > 0) {
1027
+ lines.push(`Domains: ${domains.join(", ")}`);
1028
+ }
1029
+ const invariantSection = content.match(/(?:Invariants|## Invariants|invariants)([\s\S]*?)(?:\n#|\n---|\n\n\n)/i);
1030
+ if (invariantSection) {
1031
+ const invLines = invariantSection[1].match(/^[-*]\s+`?([^`\n]+)/gm);
1032
+ if (invLines) {
1033
+ lines.push("\nInvariants:");
1034
+ for (const inv of invLines.slice(0, 10)) {
1035
+ lines.push(inv.trim());
1036
+ }
1037
+ }
1038
+ }
1039
+ const prioritySection = content.match(/(?:Decision Priorities|## Decision Priorities)([\s\S]*?)(?:\n#|\n---|\n\n\n)/i);
1040
+ if (prioritySection) {
1041
+ const priLines = prioritySection[1].match(/^[-*]\s+.+>.+/gm);
1042
+ if (priLines) {
1043
+ lines.push("\nPriorities:");
1044
+ for (const pri of priLines.slice(0, 10)) {
1045
+ lines.push(pri.trim());
1046
+ }
1047
+ }
1048
+ }
1049
+ const signalSection = content.match(/(?:## Signals)([\s\S]*?)(?:\n#|\n---|\n\n\n)/i);
1050
+ if (signalSection) {
1051
+ const sigLines = signalSection[1].match(/^[-*]\s+(\w+)/gm);
1052
+ if (sigLines) {
1053
+ lines.push(`
1054
+ Signals: ${sigLines.map((s) => s.replace(/^[-*]\s+/, "")).join(", ")}`);
1055
+ }
1056
+ }
1057
+ const driftSection = content.match(/(?:Drift Behaviors|## Drift Behaviors)([\s\S]*?)(?:\n#|\n---|\n\n\n)/i);
1058
+ if (driftSection) {
1059
+ const driftLines = driftSection[1].match(/^[-*]\s+(.+)/gm);
1060
+ if (driftLines) {
1061
+ lines.push("\nDrift behaviors:");
1062
+ for (const d of driftLines.slice(0, 5)) {
1063
+ lines.push(d.trim());
1064
+ }
1065
+ }
1066
+ }
1067
+ const compressed = lines.join("\n");
1068
+ if (compressed.length < 50) {
1069
+ return content.slice(0, 2e3) + "\n[truncated]";
1070
+ }
1071
+ return compressed;
1072
+ }
1073
+ function compressExocortex(ctx) {
1074
+ const lines = [];
1075
+ if (ctx.attention) {
1076
+ lines.push(`Attention: ${firstMeaningfulLine(ctx.attention)}`);
1077
+ }
1078
+ if (ctx.goals) {
1079
+ lines.push(`Goals: ${firstNLines(ctx.goals, 3)}`);
1080
+ }
1081
+ if (ctx.sprint) {
1082
+ lines.push(`Sprint: ${firstNLines(ctx.sprint, 3)}`);
1083
+ }
1084
+ if (ctx.identity) {
1085
+ lines.push(`Identity: ${firstMeaningfulLine(ctx.identity)}`);
1086
+ }
1087
+ if (ctx.organization) {
1088
+ lines.push(`Org: ${firstMeaningfulLine(ctx.organization)}`);
1089
+ }
1090
+ return lines.join("\n");
1091
+ }
1092
+ function compressLens(lens) {
1093
+ return {
1094
+ evaluationQuestions: lens.primary_frame.evaluation_questions.map((q, i) => `${i + 1}. ${q}`).join("\n"),
1095
+ scoringRubric: lens.primary_frame.scoring_rubric,
1096
+ forbiddenPhrases: lens.forbidden_phrases.join(", "),
1097
+ jargonTranslations: Object.entries(lens.vocabulary.jargon_translations).map(([k, v]) => `${k} \u2192 ${v}`).join("; "),
1098
+ strategicPatterns: lens.strategic_patterns.slice(0, 5).join("\n")
1099
+ };
1100
+ }
1101
+ function compressPriorReads(reads) {
1102
+ if (reads.length === 0) return "";
1103
+ const patternCounts = /* @__PURE__ */ new Map();
1104
+ for (const read of reads) {
1105
+ for (const name of read.patternNames) {
1106
+ patternCounts.set(name, (patternCounts.get(name) ?? 0) + 1);
1107
+ }
1108
+ }
1109
+ const sorted = [...patternCounts.entries()].sort((a, b) => b[1] - a[1]);
1110
+ if (sorted.length === 0) {
1111
+ return `${reads.length} prior reads, no patterns extracted.`;
1112
+ }
1113
+ const patternList = sorted.map(([name, count]) => `${name} (${count}x)`).join(", ");
1114
+ return `${reads.length} prior reads. Patterns seen: ${patternList}. If these recur, note persistence.`;
1115
+ }
1116
+ function firstMeaningfulLine(text) {
1117
+ const lines = text.split("\n").filter((l) => {
1118
+ const t = l.trim();
1119
+ return t.length > 0 && !t.startsWith("#") && !t.startsWith("<!--");
1120
+ });
1121
+ return lines[0]?.slice(0, 200) ?? "";
1122
+ }
1123
+ function firstNLines(text, n) {
1124
+ const lines = text.split("\n").filter((l) => {
1125
+ const t = l.trim();
1126
+ return t.length > 0 && !t.startsWith("#") && !t.startsWith("<!--");
1127
+ });
1128
+ return lines.slice(0, n).map((l) => l.slice(0, 150)).join("; ");
1129
+ }
1130
+
713
1131
  // src/radiant/core/prompt.ts
714
1132
  function composeSystemPrompt(worldmodelContent, lens) {
715
- const sections = [];
716
- sections.push(
717
- `## Worldmodel
718
-
719
- You are operating inside a governed environment. The worldmodel below
720
- defines the invariants, signals, decision priorities, and behavioral
721
- expectations for this organization. Every response you produce must
722
- be grounded in this worldmodel.
723
-
724
- ` + worldmodelContent
725
- );
726
- const frame = lens.primary_frame;
727
- const questionsBlock = frame.evaluation_questions.map((q, i) => `${i + 1}. ${q}`).join("\n");
728
- const overlapsBlock = frame.overlaps.map(
729
- (o) => `- ${o.domains[0]} + ${o.domains[1]} = **${o.emergent_state}**: ${o.description}`
730
- ).join("\n");
731
- sections.push(
732
- `## How to Think (Analytical Frame: ${lens.name})
733
-
734
- ${frame.scoring_rubric}
735
-
736
- ### Evaluation questions to reason through
1133
+ const compressedWorld = compressWorldmodel(worldmodelContent);
1134
+ const cl = compressLens(lens);
1135
+ const overlapsBlock = lens.primary_frame.overlaps.map((o) => `${o.domains[0]} + ${o.domains[1]} = ${o.emergent_state}`).join("\n");
1136
+ return [
1137
+ // Section 1: Compressed worldmodel
1138
+ `## Worldmodel (compressed)
737
1139
 
738
- ${questionsBlock}
1140
+ ${compressedWorld}`,
1141
+ // Section 2: Analytical frame (evaluation questions + rubric)
1142
+ `## How to Think
739
1143
 
740
- ### Overlap emergent states
1144
+ ${cl.scoringRubric}
741
1145
 
742
- ${overlapsBlock}
1146
+ Questions:
1147
+ ${cl.evaluationQuestions}
743
1148
 
744
- ### Center identity
1149
+ Overlaps: ${overlapsBlock}
1150
+ Center: ${lens.primary_frame.center_identity}
745
1151
 
746
- When all dimensions integrate fully: **${frame.center_identity}**. Surface this sparingly \u2014 only when the integration is genuinely complete.`
747
- );
748
- const vocabPreferred = Object.entries(lens.vocabulary.preferred).map(([generic, native]) => `- "${generic}" \u2192 **${native}**`).join("\n");
749
- const vocabArchitecture = lens.vocabulary.architecture.map((t) => `\`${t}\``).join(", ");
750
- const vocabProperNouns = lens.vocabulary.proper_nouns.map((n) => `**${n}**`).join(", ");
751
- const strategicBlock = lens.strategic_patterns.map((p) => `- ${p}`).join("\n");
752
- sections.push(
753
- `## How to Speak (Voice: ${lens.name})
1152
+ Translate before output: ${cl.jargonTranslations}`,
1153
+ // Section 3: Voice (compressed — register + key rules only)
1154
+ `## Voice: ${lens.name}
754
1155
 
755
1156
  Register: ${lens.voice.register}
756
-
757
- Rules:
758
- - Active voice: ${lens.voice.active_voice}
759
- - Named specificity (people, places, numbers): ${lens.voice.specificity}
760
- - Hype vocabulary: ${lens.voice.hype_vocabulary}
761
- - Hedging / qualified phrasing: ${lens.voice.hedging}
762
- - Playfulness: ${lens.voice.playfulness}
763
- - Close with strategic frame: ${lens.voice.close_with_strategic_frame}
764
- - Honesty about failure: ${lens.voice.honesty_about_failure}
765
-
766
- ### Output translation discipline
1157
+ Active voice: ${lens.voice.active_voice}. Specificity: ${lens.voice.specificity}. Hedging: ${lens.voice.hedging}. Hype: ${lens.voice.hype_vocabulary}. Honesty about failure: ${lens.voice.honesty_about_failure}.
767
1158
 
768
1159
  ${lens.voice.output_translation}
769
1160
 
770
- ### Vocabulary
771
-
772
- Proper nouns (use literally): ${vocabProperNouns}
773
-
774
- Preferred term substitutions:
775
- ${vocabPreferred}
776
-
777
- Architecture vocabulary: ${vocabArchitecture}
778
-
779
- ### Strategic decision patterns
780
-
781
- When recommending action, these patterns reflect how this organization resolves tradeoffs:
782
-
783
- ${strategicBlock}`
784
- );
785
- const forbiddenBlock = lens.forbidden_phrases.map((p) => `- "${p}"`).join("\n");
786
- sections.push(
1161
+ Strategic patterns:
1162
+ ${cl.strategicPatterns}`,
1163
+ // Section 4: Guardrails (forbidden phrases as comma-separated, not bulleted)
787
1164
  `## Guardrails
788
1165
 
789
- Do NOT use any of these phrases in your response. If you catch yourself
790
- reaching for one, rephrase in direct, active, specific language instead.
791
-
792
- ${forbiddenBlock}
1166
+ Do NOT use: ${cl.forbiddenPhrases}
793
1167
 
794
- If your response would violate a worldmodel invariant, state the conflict
795
- explicitly and propose an alternative that honors the invariant.`
796
- );
797
- return sections.join("\n\n---\n\n");
1168
+ If a response would violate a worldmodel invariant, state the conflict and propose an alternative.`
1169
+ ].join("\n\n---\n\n");
798
1170
  }
799
1171
 
800
1172
  // src/radiant/core/voice-check.ts
@@ -1105,7 +1477,7 @@ function createMockGitHubAdapter(fixedEvents) {
1105
1477
  // src/radiant/adapters/exocortex.ts
1106
1478
  var import_fs = require("fs");
1107
1479
  var import_path = require("path");
1108
- function readExocortex(dirPath) {
1480
+ function readExocortex(dirPath, repoName) {
1109
1481
  const dir = (0, import_path.resolve)(dirPath);
1110
1482
  let filesLoaded = 0;
1111
1483
  function tryRead(...paths) {
@@ -1124,16 +1496,64 @@ function readExocortex(dirPath) {
1124
1496
  }
1125
1497
  return null;
1126
1498
  }
1499
+ const attention = tryRead("attention.md");
1500
+ const goals = tryRead("goals.md");
1501
+ const identity = tryRead("identity.md", "user.md");
1502
+ const organization = tryRead("org/organization.md", "org/src/organization.md");
1503
+ const methods = tryRead("org/methods.md", "org/src/methods.md");
1504
+ let sprint = null;
1505
+ let projectContext = null;
1506
+ if (repoName) {
1507
+ const projectPaths = [
1508
+ repoName,
1509
+ repoName.toLowerCase(),
1510
+ repoName.replace(/-/g, "_")
1511
+ ];
1512
+ for (const projectDir of projectPaths) {
1513
+ const projectSprint = tryRead(
1514
+ `${projectDir}/src/sprint.md`,
1515
+ `${projectDir}/sprint.md`
1516
+ );
1517
+ if (projectSprint) {
1518
+ sprint = projectSprint;
1519
+ break;
1520
+ }
1521
+ }
1522
+ for (const projectDir of projectPaths) {
1523
+ const roadmap = tryRead(
1524
+ `${projectDir}/roadmap.md`,
1525
+ `${projectDir}/src/roadmap.md`
1526
+ );
1527
+ if (roadmap) {
1528
+ projectContext = roadmap;
1529
+ break;
1530
+ }
1531
+ }
1532
+ }
1533
+ if (!sprint) {
1534
+ sprint = tryRead("sprint.md", "src/sprint.md");
1535
+ }
1127
1536
  const ctx = {
1128
- attention: tryRead("attention.md"),
1129
- goals: tryRead("goals.md"),
1130
- identity: tryRead("identity.md"),
1131
- sprint: tryRead("sprint.md", "src/sprint.md"),
1132
- organization: tryRead("org/organization.md", "org/src/organization.md"),
1133
- methods: tryRead("org/methods.md", "org/src/methods.md"),
1537
+ attention,
1538
+ goals,
1539
+ identity,
1540
+ sprint,
1541
+ organization,
1542
+ methods,
1134
1543
  source: dir,
1135
1544
  filesLoaded
1136
1545
  };
1546
+ if (projectContext && ctx.sprint) {
1547
+ ctx.sprint = `${ctx.sprint}
1548
+
1549
+ ---
1550
+ Project roadmap:
1551
+ ${projectContext}`;
1552
+ } else if (projectContext) {
1553
+ ctx.sprint = `Project roadmap:
1554
+ ${projectContext}`;
1555
+ ctx.filesLoaded++;
1556
+ }
1137
1557
  return ctx;
1138
1558
  }
1139
1559
  function formatExocortexForPrompt(ctx) {
@@ -1637,15 +2057,17 @@ function buildInterpretationPrompt(input) {
1637
2057
  const eventSample = formatEventSample(input.events, 30);
1638
2058
  const canonicalList = (input.canonicalPatterns ?? []).length > 0 ? `Patterns the organization has already named (use these names if you see them):
1639
2059
  ${input.canonicalPatterns.map((p) => `- ${p}`).join("\n")}` : "No patterns have been named yet. Everything you observe is new.";
2060
+ const compressedWorld = compressWorldmodel(input.worldmodelContent);
2061
+ const cl = compressLens(input.lens);
1640
2062
  const frame = input.lens.primary_frame;
1641
2063
  const evalQuestions = frame.evaluation_questions.map((q, i) => `${i + 1}. ${q}`).join("\n");
1642
- const forbiddenList = input.lens.forbidden_phrases.map((p) => `- "${p}"`).join("\n");
1643
- const jargonTable = Object.entries(input.lens.vocabulary.jargon_translations).map(([internal, plain]) => ` "${internal}" \u2192 "${plain}"`).join("\n");
2064
+ const forbiddenList = cl.forbiddenPhrases;
2065
+ const jargonTable = cl.jargonTranslations;
1644
2066
  return `You are a behavioral intelligence system reading team activity and producing a read for the reader who needs to act on it.
1645
2067
 
1646
- ## Context the reader has loaded
2068
+ ## Worldmodel (compressed)
1647
2069
 
1648
- ${input.worldmodelContent}
2070
+ ${compressedWorld}
1649
2071
 
1650
2072
  ## What happened this window
1651
2073
 
@@ -1836,30 +2258,16 @@ Window: last ${input.windowDays} days \xB7 ${input.eventCount} events
1836
2258
  Lens: ${input.lens.name}`
1837
2259
  );
1838
2260
  if (input.patterns.length > 0) {
1839
- const canonical = input.patterns.filter((p) => p.type === "canonical");
1840
- const candidates = input.patterns.filter((p) => p.type === "candidate");
1841
2261
  let emergentBlock = "EMERGENT\n";
1842
- if (canonical.length > 0) {
1843
- for (const p of canonical) {
1844
- emergentBlock += `
2262
+ for (const p of input.patterns) {
2263
+ emergentBlock += `
1845
2264
  ${p.name}
1846
2265
  `;
1847
- emergentBlock += ` ${p.description}
2266
+ emergentBlock += ` ${p.description}
1848
2267
  `;
1849
- }
1850
- }
1851
- if (candidates.length > 0) {
1852
- emergentBlock += "\n Emergent (candidates \u2014 not yet in worldmodel)\n";
1853
- for (const p of candidates) {
1854
- emergentBlock += `
1855
- ${p.name} (candidate)
1856
- `;
1857
- emergentBlock += ` ${p.description}
2268
+ if (p.evidence.cited_invariant) {
2269
+ emergentBlock += ` Cited invariant: ${p.evidence.cited_invariant}
1858
2270
  `;
1859
- if (p.evidence.cited_invariant) {
1860
- emergentBlock += ` Cited invariant: ${p.evidence.cited_invariant}
1861
- `;
1862
- }
1863
2271
  }
1864
2272
  }
1865
2273
  sections.push(emergentBlock.trimEnd());
@@ -2067,6 +2475,356 @@ function serializeYAML(obj, indent = 0) {
2067
2475
  `;
2068
2476
  }
2069
2477
 
2478
+ // src/radiant/core/discovery.ts
2479
+ var import_fs4 = require("fs");
2480
+ var import_path4 = require("path");
2481
+ var import_os2 = require("os");
2482
+
2483
+ // src/radiant/core/extends.ts
2484
+ var import_fs3 = require("fs");
2485
+ var import_path3 = require("path");
2486
+ var import_os = require("os");
2487
+ var import_crypto = require("crypto");
2488
+ var import_child_process = require("child_process");
2489
+
2490
+ // src/radiant/core/git-remote.ts
2491
+ var import_fs2 = require("fs");
2492
+ var import_path2 = require("path");
2493
+ function resolveGitConfigPath(repoDir) {
2494
+ const dotGit = (0, import_path2.join)(repoDir, ".git");
2495
+ if (!(0, import_fs2.existsSync)(dotGit)) return null;
2496
+ try {
2497
+ const stat = (0, import_fs2.statSync)(dotGit);
2498
+ if (stat.isDirectory()) {
2499
+ return (0, import_path2.join)(dotGit, "config");
2500
+ }
2501
+ if (stat.isFile()) {
2502
+ const content = (0, import_fs2.readFileSync)(dotGit, "utf-8");
2503
+ const match = /^gitdir:\s*(.+)$/m.exec(content);
2504
+ if (!match) return null;
2505
+ const gitDir = (0, import_path2.resolve)(repoDir, match[1].trim());
2506
+ const configPath = (0, import_path2.join)(gitDir, "config");
2507
+ return (0, import_fs2.existsSync)(configPath) ? configPath : null;
2508
+ }
2509
+ } catch {
2510
+ return null;
2511
+ }
2512
+ return null;
2513
+ }
2514
+ function readOriginRemote(repoDir) {
2515
+ const configPath = resolveGitConfigPath(repoDir);
2516
+ if (!configPath) return null;
2517
+ try {
2518
+ const raw = (0, import_fs2.readFileSync)(configPath, "utf-8");
2519
+ const sectionRe = /\[remote "origin"\]\s*\n((?:(?!\[)[^\n]*\n?)*)/;
2520
+ const section = sectionRe.exec(raw);
2521
+ if (!section) return null;
2522
+ const urlRe = /^\s*url\s*=\s*(.+?)\s*$/m;
2523
+ const url = urlRe.exec(section[1]);
2524
+ return url ? url[1] : null;
2525
+ } catch {
2526
+ return null;
2527
+ }
2528
+ }
2529
+ function parseRemoteUrl(url) {
2530
+ const trimmed = url.trim();
2531
+ if (!trimmed) return null;
2532
+ const ssh = /^git@([^:]+):([^/]+)\/(.+?)(?:\.git)?\/?$/.exec(trimmed);
2533
+ if (ssh) return { host: ssh[1], owner: ssh[2], repo: ssh[3] };
2534
+ const sshProto = /^ssh:\/\/git@([^/]+)\/([^/]+)\/(.+?)(?:\.git)?\/?$/.exec(trimmed);
2535
+ if (sshProto) return { host: sshProto[1], owner: sshProto[2], repo: sshProto[3] };
2536
+ const https = /^https?:\/\/(?:[^@/]+@)?([^/]+)\/([^/]+)\/(.+?)(?:\.git)?\/?$/.exec(trimmed);
2537
+ if (https) return { host: https[1], owner: https[2], repo: https[3] };
2538
+ return null;
2539
+ }
2540
+ function getRepoOrigin(repoDir) {
2541
+ const url = readOriginRemote(repoDir);
2542
+ if (!url) return null;
2543
+ return parseRemoteUrl(url);
2544
+ }
2545
+
2546
+ // src/radiant/core/extends.ts
2547
+ function loadExtendsConfig(repoDir) {
2548
+ const configPath = (0, import_path3.join)(repoDir, ".neuroverse", "config.json");
2549
+ if (!(0, import_fs3.existsSync)(configPath)) return null;
2550
+ try {
2551
+ const raw = (0, import_fs3.readFileSync)(configPath, "utf-8");
2552
+ const parsed = JSON.parse(raw);
2553
+ return parsed;
2554
+ } catch {
2555
+ return null;
2556
+ }
2557
+ }
2558
+ function parseExtendsSpec(raw) {
2559
+ const trimmed = raw.trim();
2560
+ if (!trimmed) return null;
2561
+ if (trimmed.startsWith("github:")) {
2562
+ const rest = trimmed.slice("github:".length);
2563
+ const match = /^([^/]+)\/([^@:]+)(?:@([^:]+))?(?::(.+))?$/.exec(rest);
2564
+ if (!match) return null;
2565
+ return {
2566
+ raw: trimmed,
2567
+ kind: "github",
2568
+ owner: match[1],
2569
+ repo: match[2],
2570
+ ref: match[3] ?? "HEAD",
2571
+ subpath: match[4] ?? ""
2572
+ };
2573
+ }
2574
+ if (trimmed.startsWith("./") || trimmed.startsWith("../") || (0, import_path3.isAbsolute)(trimmed)) {
2575
+ return { raw: trimmed, kind: "local", path: trimmed };
2576
+ }
2577
+ return null;
2578
+ }
2579
+ var DEFAULT_TTL_MS = 60 * 60 * 1e3;
2580
+ function getCacheDir(spec, baseCacheDir) {
2581
+ const root = baseCacheDir ?? (0, import_path3.join)((0, import_os.homedir)(), ".neuroverse", "cache", "extends");
2582
+ const key = (0, import_crypto.createHash)("sha256").update(spec.raw).digest("hex").slice(0, 16);
2583
+ return (0, import_path3.join)(root, key);
2584
+ }
2585
+ function isCacheFresh(cacheDir, ttlMs) {
2586
+ const stampPath = (0, import_path3.join)(cacheDir, ".neuroverse-fetched");
2587
+ if (!(0, import_fs3.existsSync)(stampPath)) return false;
2588
+ try {
2589
+ const stamp = (0, import_fs3.statSync)(stampPath);
2590
+ return Date.now() - stamp.mtimeMs < ttlMs;
2591
+ } catch {
2592
+ return false;
2593
+ }
2594
+ }
2595
+ function markCacheFresh(cacheDir) {
2596
+ const stampPath = (0, import_path3.join)(cacheDir, ".neuroverse-fetched");
2597
+ try {
2598
+ (0, import_fs3.mkdirSync)(cacheDir, { recursive: true });
2599
+ (0, import_fs3.writeFileSync)(stampPath, (/* @__PURE__ */ new Date()).toISOString());
2600
+ } catch {
2601
+ }
2602
+ }
2603
+ var defaultGitFetcher = (spec, destDir) => {
2604
+ if (spec.kind !== "github") return;
2605
+ const url = `https://github.com/${spec.owner}/${spec.repo}.git`;
2606
+ const parent = (0, import_path3.resolve)(destDir, "..");
2607
+ (0, import_fs3.mkdirSync)(parent, { recursive: true });
2608
+ if ((0, import_fs3.existsSync)(destDir)) {
2609
+ (0, import_fs3.rmSync)(destDir, { recursive: true, force: true });
2610
+ }
2611
+ const args = ["clone", "--depth", "1", "--filter=blob:none"];
2612
+ if (spec.ref && spec.ref !== "HEAD") {
2613
+ args.push("--branch", spec.ref);
2614
+ }
2615
+ args.push(url, destDir);
2616
+ (0, import_child_process.execFileSync)("git", args, { stdio: "pipe" });
2617
+ };
2618
+ function resolveExtendsSpec(spec, repoDir, options) {
2619
+ if (spec.kind === "local") {
2620
+ const full = (0, import_path3.isAbsolute)(spec.path) ? spec.path : (0, import_path3.resolve)(repoDir, spec.path);
2621
+ if (!(0, import_fs3.existsSync)(full)) {
2622
+ return { spec, dir: null, warning: `local extends path not found: ${full}` };
2623
+ }
2624
+ return { spec, dir: full };
2625
+ }
2626
+ const cacheRoot = options?.cacheDir;
2627
+ const ttl = options?.ttlMs ?? DEFAULT_TTL_MS;
2628
+ const cacheDir = getCacheDir(spec, cacheRoot);
2629
+ const fresh = isCacheFresh(cacheDir, ttl);
2630
+ const needsFetch = options?.forceRefresh || !fresh || !(0, import_fs3.existsSync)(cacheDir);
2631
+ if (needsFetch && options?.noFetch) {
2632
+ if ((0, import_fs3.existsSync)(cacheDir) && (0, import_fs3.existsSync)((0, import_path3.join)(cacheDir, ".neuroverse-fetched"))) {
2633
+ return resolveSubpath(spec, cacheDir);
2634
+ }
2635
+ return options?.silentOnMissing ? { spec, dir: null } : { spec, dir: null, warning: `NEUROVERSE_NO_FETCH set and no cache for ${spec.raw}` };
2636
+ }
2637
+ if (needsFetch) {
2638
+ const fetcher = options?.fetcher ?? defaultGitFetcher;
2639
+ try {
2640
+ fetcher(spec, cacheDir);
2641
+ markCacheFresh(cacheDir);
2642
+ } catch (err) {
2643
+ if ((0, import_fs3.existsSync)(cacheDir) && (0, import_fs3.existsSync)((0, import_path3.join)(cacheDir, ".neuroverse-fetched"))) {
2644
+ const result = resolveSubpath(spec, cacheDir);
2645
+ return options?.silentOnMissing ? result : { ...result, warning: `fetch failed for ${spec.raw}, using stale cache: ${err.message}` };
2646
+ }
2647
+ return options?.silentOnMissing ? { spec, dir: null } : { spec, dir: null, warning: `fetch failed for ${spec.raw}: ${err.message}` };
2648
+ }
2649
+ }
2650
+ return resolveSubpath(spec, cacheDir);
2651
+ }
2652
+ function resolveSubpath(spec, cacheDir) {
2653
+ const target = spec.subpath ? (0, import_path3.join)(cacheDir, spec.subpath) : cacheDir;
2654
+ if (!(0, import_fs3.existsSync)(target)) {
2655
+ return { spec, dir: null, warning: `subpath not found in ${spec.raw}: ${spec.subpath}` };
2656
+ }
2657
+ if (!spec.subpath) {
2658
+ const candidates = [
2659
+ (0, import_path3.join)(target, "worlds"),
2660
+ (0, import_path3.join)(target, ".neuroverse", "worlds")
2661
+ ];
2662
+ for (const c of candidates) {
2663
+ if ((0, import_fs3.existsSync)(c)) return { spec, dir: c };
2664
+ }
2665
+ }
2666
+ return { spec, dir: target };
2667
+ }
2668
+ function detectOrgExtendsSpec(repoDir) {
2669
+ const origin = getRepoOrigin(repoDir);
2670
+ if (!origin) return null;
2671
+ if (origin.host !== "github.com") return null;
2672
+ if (origin.repo === "worlds") return null;
2673
+ return {
2674
+ raw: `github:${origin.owner}/worlds`,
2675
+ kind: "github",
2676
+ owner: origin.owner,
2677
+ repo: "worlds",
2678
+ ref: "HEAD",
2679
+ subpath: ""
2680
+ };
2681
+ }
2682
+ function resolveAllExtends(repoDir, options) {
2683
+ const config = options?.config !== void 0 ? options.config : loadExtendsConfig(repoDir);
2684
+ if (!config?.extends || config.extends.length === 0) return [];
2685
+ const results = [];
2686
+ for (const raw of config.extends) {
2687
+ const spec = parseExtendsSpec(raw);
2688
+ if (!spec) {
2689
+ results.push({
2690
+ spec: { raw, kind: "local" },
2691
+ dir: null,
2692
+ warning: `unparseable extends spec: ${raw}`
2693
+ });
2694
+ continue;
2695
+ }
2696
+ results.push(resolveExtendsSpec(spec, repoDir, options));
2697
+ }
2698
+ return results;
2699
+ }
2700
+
2701
+ // src/radiant/core/discovery.ts
2702
+ function discoverWorlds(options) {
2703
+ const worlds = [];
2704
+ const warnings = [];
2705
+ const forceRefresh = process.env.NEUROVERSE_REFRESH === "1";
2706
+ const noFetch = process.env.NEUROVERSE_NO_FETCH === "1";
2707
+ const noOrg = options?.disableOrg || process.env.NEUROVERSE_NO_ORG === "1";
2708
+ const userDir = options?.userWorldsDir ?? (0, import_path4.join)((0, import_os2.homedir)(), ".neuroverse", "worlds");
2709
+ if ((0, import_fs4.existsSync)(userDir)) {
2710
+ worlds.push(...loadWorldsFromDir(userDir, "user"));
2711
+ }
2712
+ if (!noOrg && !options?.explicitWorldsDir) {
2713
+ const specs = [];
2714
+ if (options?.repoDir) {
2715
+ const fromGit = detectOrgExtendsSpec(options.repoDir);
2716
+ if (fromGit) specs.push(fromGit);
2717
+ }
2718
+ if (options?.scopeOwner) {
2719
+ const already = specs.some(
2720
+ (s) => s.owner?.toLowerCase() === options.scopeOwner.toLowerCase()
2721
+ );
2722
+ if (!already) {
2723
+ specs.push({
2724
+ raw: `github:${options.scopeOwner}/worlds`,
2725
+ kind: "github",
2726
+ owner: options.scopeOwner,
2727
+ repo: "worlds"
2728
+ });
2729
+ }
2730
+ }
2731
+ const baseDir = options?.repoDir ?? process.cwd();
2732
+ for (const spec of specs) {
2733
+ const result = resolveExtendsSpec(spec, baseDir, {
2734
+ cacheDir: options?.extendsCacheDir,
2735
+ fetcher: options?.extendsFetcher,
2736
+ ttlMs: options?.extendsTtlMs,
2737
+ forceRefresh,
2738
+ noFetch,
2739
+ silentOnMissing: true
2740
+ });
2741
+ worlds.push(...loadExtendsWorlds(result, "org"));
2742
+ }
2743
+ }
2744
+ if (options?.repoDir && !options.disableExtends && !options.explicitWorldsDir) {
2745
+ const results = resolveAllExtends(options.repoDir, {
2746
+ cacheDir: options.extendsCacheDir,
2747
+ fetcher: options.extendsFetcher,
2748
+ ttlMs: options.extendsTtlMs,
2749
+ forceRefresh,
2750
+ noFetch
2751
+ });
2752
+ for (const result of results) {
2753
+ worlds.push(...loadExtendsWorlds(result, "extends"));
2754
+ if (result.warning) warnings.push(result.warning);
2755
+ }
2756
+ }
2757
+ if (options?.explicitWorldsDir) {
2758
+ worlds.push(...loadWorldsFromDir(options.explicitWorldsDir, "repo"));
2759
+ } else if (options?.repoDir) {
2760
+ const repoPaths = [
2761
+ (0, import_path4.join)(options.repoDir, "worlds"),
2762
+ (0, import_path4.join)(options.repoDir, ".neuroverse", "worlds")
2763
+ ];
2764
+ for (const p of repoPaths) {
2765
+ if ((0, import_fs4.existsSync)(p)) {
2766
+ worlds.push(...loadWorldsFromDir(p, "repo"));
2767
+ break;
2768
+ }
2769
+ }
2770
+ }
2771
+ const combinedContent = worlds.map((w) => {
2772
+ const tag = w.extendsFrom ? `<!-- world: ${w.name} (${w.source} ${w.extendsFrom}) -->` : `<!-- world: ${w.name} (${w.source}) -->`;
2773
+ return `${tag}
2774
+ ${w.content}`;
2775
+ }).join("\n\n---\n\n");
2776
+ const summary = worlds.length === 0 ? "no worlds discovered" : worlds.map((w) => `${w.name} (${w.source})`).join(", ");
2777
+ return { worlds, combinedContent, summary, warnings };
2778
+ }
2779
+ function formatActiveWorlds(stack) {
2780
+ if (stack.worlds.length === 0) return "No worlds loaded.";
2781
+ const lines = ["ACTIVE WORLDS", ""];
2782
+ for (const w of stack.worlds) {
2783
+ const sourceLabel = w.source === "base" ? "universal" : w.source === "user" ? "personal" : w.source === "org" ? `org (${w.extendsFrom ?? "auto"})` : w.source === "extends" ? `shared (${w.extendsFrom ?? "extends"})` : "this repo";
2784
+ lines.push(` ${w.name} (${sourceLabel})`);
2785
+ }
2786
+ if (stack.warnings.length > 0) {
2787
+ lines.push("", "WARNINGS");
2788
+ for (const w of stack.warnings) lines.push(` ${w}`);
2789
+ }
2790
+ return lines.join("\n");
2791
+ }
2792
+ function loadExtendsWorlds(result, source) {
2793
+ if (!result.dir) return [];
2794
+ const loaded = loadWorldsFromDir(result.dir, source);
2795
+ return loaded.map((w) => ({ ...w, extendsFrom: result.spec.raw }));
2796
+ }
2797
+ function loadWorldsFromDir(dirPath, source) {
2798
+ const dir = (0, import_path4.resolve)(dirPath);
2799
+ if (!(0, import_fs4.existsSync)(dir)) return [];
2800
+ const stat = (0, import_fs4.statSync)(dir);
2801
+ if (stat.isFile() && dir.endsWith(".md")) {
2802
+ try {
2803
+ return [{
2804
+ name: (0, import_path4.basename)(dir).replace(/\.worldmodel\.md$/, "").replace(/\.nv-world\.md$/, ""),
2805
+ source,
2806
+ path: dir,
2807
+ content: (0, import_fs4.readFileSync)(dir, "utf-8")
2808
+ }];
2809
+ } catch {
2810
+ return [];
2811
+ }
2812
+ }
2813
+ if (!stat.isDirectory()) return [];
2814
+ const files = (0, import_fs4.readdirSync)(dir).filter(
2815
+ (f) => f.endsWith(".worldmodel.md") || f.endsWith(".nv-world.md")
2816
+ ).sort();
2817
+ return files.map((f) => {
2818
+ const fullPath = (0, import_path4.join)(dir, f);
2819
+ return {
2820
+ name: f.replace(/\.worldmodel\.md$/, "").replace(/\.nv-world\.md$/, ""),
2821
+ source,
2822
+ path: fullPath,
2823
+ content: (0, import_fs4.readFileSync)(fullPath, "utf-8")
2824
+ };
2825
+ });
2826
+ }
2827
+
2070
2828
  // src/engine/text-utils.ts
2071
2829
  function normalizeEventText(event) {
2072
2830
  return [
@@ -3153,10 +3911,10 @@ function verdictToEvent(status, intent) {
3153
3911
  // src/loader/world-loader.ts
3154
3912
  async function loadWorldFromDirectory(dirPath) {
3155
3913
  const { readFile } = await import("fs/promises");
3156
- const { join: join3 } = await import("path");
3157
- const { readdirSync: readdirSync3 } = await import("fs");
3914
+ const { join: join6 } = await import("path");
3915
+ const { readdirSync: readdirSync4 } = await import("fs");
3158
3916
  async function readJson(filename) {
3159
- const filePath = join3(dirPath, filename);
3917
+ const filePath = join6(dirPath, filename);
3160
3918
  try {
3161
3919
  const content = await readFile(filePath, "utf-8");
3162
3920
  return JSON.parse(content);
@@ -3186,11 +3944,11 @@ async function loadWorldFromDirectory(dirPath) {
3186
3944
  const metadataJson = await readJson("metadata.json");
3187
3945
  const rules = [];
3188
3946
  try {
3189
- const rulesDir = join3(dirPath, "rules");
3190
- const ruleFiles = readdirSync3(rulesDir).filter((f) => f.endsWith(".json")).sort();
3947
+ const rulesDir = join6(dirPath, "rules");
3948
+ const ruleFiles = readdirSync4(rulesDir).filter((f) => f.endsWith(".json")).sort();
3191
3949
  for (const file of ruleFiles) {
3192
3950
  try {
3193
- const content = await readFile(join3(rulesDir, file), "utf-8");
3951
+ const content = await readFile(join6(rulesDir, file), "utf-8");
3194
3952
  rules.push(JSON.parse(content));
3195
3953
  } catch (err) {
3196
3954
  process.stderr.write(
@@ -3350,25 +4108,25 @@ function emptyAudit(total, reason) {
3350
4108
  }
3351
4109
 
3352
4110
  // src/radiant/memory/palace.ts
3353
- var import_fs2 = require("fs");
3354
- var import_path2 = require("path");
4111
+ var import_fs5 = require("fs");
4112
+ var import_path5 = require("path");
3355
4113
  function writeRead(exocortexDir, frontmatter, text) {
3356
- const dir = (0, import_path2.resolve)(exocortexDir, "radiant", "reads");
3357
- (0, import_fs2.mkdirSync)(dir, { recursive: true });
4114
+ const dir = (0, import_path5.resolve)(exocortexDir, "radiant", "reads");
4115
+ (0, import_fs5.mkdirSync)(dir, { recursive: true });
3358
4116
  const date = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
3359
4117
  const filename = `${date}.md`;
3360
- const filepath = (0, import_path2.join)(dir, filename);
4118
+ const filepath = (0, import_path5.join)(dir, filename);
3361
4119
  const content = `${frontmatter}
3362
4120
 
3363
4121
  ${text}
3364
4122
  `;
3365
- (0, import_fs2.writeFileSync)(filepath, content, "utf-8");
4123
+ (0, import_fs5.writeFileSync)(filepath, content, "utf-8");
3366
4124
  return filepath;
3367
4125
  }
3368
4126
  function updateKnowledge(exocortexDir, persistence, options) {
3369
- const dir = (0, import_path2.resolve)(exocortexDir, "radiant");
3370
- (0, import_fs2.mkdirSync)(dir, { recursive: true });
3371
- const filepath = (0, import_path2.join)(dir, "knowledge.md");
4127
+ const dir = (0, import_path5.resolve)(exocortexDir, "radiant");
4128
+ (0, import_fs5.mkdirSync)(dir, { recursive: true });
4129
+ const filepath = (0, import_path5.join)(dir, "knowledge.md");
3372
4130
  const totalReads = options?.totalReads ?? 0;
3373
4131
  const existingUntriggered = loadUntriggeredCounts(filepath);
3374
4132
  const lines = [
@@ -3455,14 +4213,14 @@ function updateKnowledge(exocortexDir, persistence, options) {
3455
4213
  lines.push(`${name}=${count}`);
3456
4214
  }
3457
4215
  lines.push("-->");
3458
- (0, import_fs2.writeFileSync)(filepath, lines.join("\n"), "utf-8");
4216
+ (0, import_fs5.writeFileSync)(filepath, lines.join("\n"), "utf-8");
3459
4217
  return filepath;
3460
4218
  }
3461
4219
  function loadUntriggeredCounts(filepath) {
3462
4220
  const counts = /* @__PURE__ */ new Map();
3463
- if (!(0, import_fs2.existsSync)(filepath)) return counts;
4221
+ if (!(0, import_fs5.existsSync)(filepath)) return counts;
3464
4222
  try {
3465
- const content = (0, import_fs2.readFileSync)(filepath, "utf-8");
4223
+ const content = (0, import_fs5.readFileSync)(filepath, "utf-8");
3466
4224
  const match = content.match(
3467
4225
  /<!-- untriggered_counts[\s\S]*?-->/
3468
4226
  );
@@ -3480,13 +4238,13 @@ function loadUntriggeredCounts(filepath) {
3480
4238
  return counts;
3481
4239
  }
3482
4240
  function loadPriorReads(exocortexDir) {
3483
- const dir = (0, import_path2.resolve)(exocortexDir, "radiant", "reads");
3484
- if (!(0, import_fs2.existsSync)(dir)) return [];
3485
- const files = (0, import_fs2.readdirSync)(dir).filter((f) => f.endsWith(".md")).sort();
4241
+ const dir = (0, import_path5.resolve)(exocortexDir, "radiant", "reads");
4242
+ if (!(0, import_fs5.existsSync)(dir)) return [];
4243
+ const files = (0, import_fs5.readdirSync)(dir).filter((f) => f.endsWith(".md")).sort();
3486
4244
  const reads = [];
3487
4245
  for (const filename of files) {
3488
- const filepath = (0, import_path2.join)(dir, filename);
3489
- const content = (0, import_fs2.readFileSync)(filepath, "utf-8");
4246
+ const filepath = (0, import_path5.join)(dir, filename);
4247
+ const content = (0, import_fs5.readFileSync)(filepath, "utf-8");
3490
4248
  const date = filename.replace(".md", "");
3491
4249
  const fmMatch = content.match(/^---\n([\s\S]*?)\n---/);
3492
4250
  const frontmatter = fmMatch ? fmMatch[1] : "";
@@ -3577,16 +4335,29 @@ function resolveLens(id) {
3577
4335
  async function emergent(input) {
3578
4336
  const lens = resolveLens2(input.lensId);
3579
4337
  const windowDays = input.windowDays ?? 14;
4338
+ let worldStack;
4339
+ let worldmodelContent = input.worldmodelContent;
4340
+ if (!worldmodelContent || worldmodelContent.trim() === "") {
4341
+ worldStack = discoverWorlds({ explicitWorldsDir: input.worldPath });
4342
+ worldmodelContent = worldStack.combinedContent;
4343
+ }
3580
4344
  let statedIntent;
3581
4345
  let exocortexContext;
3582
4346
  let priorReadContext = "";
3583
4347
  if (input.exocortexPath) {
3584
- exocortexContext = readExocortex(input.exocortexPath);
3585
- const formatted = formatExocortexForPrompt(exocortexContext);
3586
- if (formatted) statedIntent = formatted;
4348
+ const repoName = input.scope.type === "repo" ? input.scope.repo : void 0;
4349
+ exocortexContext = readExocortex(input.exocortexPath, repoName);
4350
+ const compressed = compressExocortex(exocortexContext);
4351
+ if (compressed) {
4352
+ statedIntent = `## Stated Intent (from exocortex, compressed)
4353
+
4354
+ ${compressed}
4355
+
4356
+ Compare stated intent against actual GitHub activity. Gaps = drift.`;
4357
+ }
3587
4358
  const priorReads = loadPriorReads(input.exocortexPath);
3588
4359
  if (priorReads.length > 0) {
3589
- priorReadContext = formatPriorReadsForPrompt(priorReads);
4360
+ priorReadContext = compressPriorReads(priorReads);
3590
4361
  }
3591
4362
  }
3592
4363
  let events;
@@ -3604,6 +4375,40 @@ async function emergent(input) {
3604
4375
  windowDays
3605
4376
  });
3606
4377
  }
4378
+ let adapterSignals = "";
4379
+ const activeAdapters = ["github"];
4380
+ const discordToken = process.env.DISCORD_TOKEN;
4381
+ const discordGuild = process.env.DISCORD_GUILD_ID;
4382
+ if (discordToken && discordGuild) {
4383
+ try {
4384
+ const discord = await fetchDiscordActivity(discordGuild, discordToken, { windowDays });
4385
+ events.push(...discord.events);
4386
+ adapterSignals += "\n\n" + formatDiscordSignalsForPrompt(discord.signals);
4387
+ activeAdapters.push("discord");
4388
+ } catch {
4389
+ }
4390
+ }
4391
+ const slackToken = process.env.SLACK_TOKEN;
4392
+ if (slackToken) {
4393
+ try {
4394
+ const slack = await fetchSlackActivity(slackToken, { windowDays });
4395
+ events.push(...slack.events);
4396
+ adapterSignals += "\n\n" + formatSlackSignalsForPrompt(slack.signals);
4397
+ activeAdapters.push("slack");
4398
+ } catch {
4399
+ }
4400
+ }
4401
+ const notionToken = process.env.NOTION_TOKEN;
4402
+ if (notionToken) {
4403
+ try {
4404
+ const notion = await fetchNotionActivity(notionToken, { windowDays });
4405
+ events.push(...notion.events);
4406
+ adapterSignals += "\n\n" + formatNotionSignalsForPrompt(notion.signals);
4407
+ activeAdapters.push("notion");
4408
+ } catch {
4409
+ }
4410
+ }
4411
+ events.sort((a, b) => Date.parse(a.timestamp) - Date.parse(b.timestamp));
3607
4412
  const classified = classifyEvents(events);
3608
4413
  const signals = extractSignals(classified);
3609
4414
  const scores = computeScores(signals, input.worldmodelContent !== "");
@@ -3614,7 +4419,7 @@ async function emergent(input) {
3614
4419
  lens,
3615
4420
  ai: input.ai,
3616
4421
  canonicalPatterns: input.canonicalPatterns,
3617
- statedIntent: statedIntent ? statedIntent + (priorReadContext ? "\n\n" + priorReadContext : "") : priorReadContext || void 0
4422
+ statedIntent: [statedIntent, adapterSignals, priorReadContext].filter(Boolean).join("\n\n") || void 0
3618
4423
  });
3619
4424
  const rewrittenPatterns = patterns.map((p) => lens.rewrite(p));
3620
4425
  const allDescriptions = rewrittenPatterns.map((p) => p.description).join("\n");
@@ -3663,7 +4468,9 @@ async function emergent(input) {
3663
4468
  voiceClean: voiceViolations.length === 0,
3664
4469
  signals,
3665
4470
  scores,
3666
- eventCount: events.length
4471
+ eventCount: events.length,
4472
+ activeAdapters,
4473
+ worldStack
3667
4474
  };
3668
4475
  }
3669
4476
  function computeScores(signals, worldmodelLoaded) {
@@ -3728,10 +4535,16 @@ var RADIANT_PACKAGE_VERSION = "0.0.0";
3728
4535
  classifyActorDomain,
3729
4536
  classifyEvents,
3730
4537
  composeSystemPrompt,
4538
+ compressExocortex,
4539
+ compressLens,
4540
+ compressPriorReads,
4541
+ compressWorldmodel,
3731
4542
  computePersistence,
3732
4543
  createAnthropicAI,
3733
4544
  createMockAI,
3734
4545
  createMockGitHubAdapter,
4546
+ detectOrgExtendsSpec,
4547
+ discoverWorlds,
3735
4548
  emergent,
3736
4549
  extractSignals,
3737
4550
  fetchDiscordActivity,
@@ -3739,6 +4552,7 @@ var RADIANT_PACKAGE_VERSION = "0.0.0";
3739
4552
  fetchGitHubOrgActivity,
3740
4553
  fetchNotionActivity,
3741
4554
  fetchSlackActivity,
4555
+ formatActiveWorlds,
3742
4556
  formatDiscordSignalsForPrompt,
3743
4557
  formatExocortexForPrompt,
3744
4558
  formatNotionSignalsForPrompt,
@@ -3746,23 +4560,32 @@ var RADIANT_PACKAGE_VERSION = "0.0.0";
3746
4560
  formatScope,
3747
4561
  formatSlackSignalsForPrompt,
3748
4562
  formatTeamExocorticesForPrompt,
4563
+ getCacheDir,
3749
4564
  getLens,
4565
+ getRepoOrigin,
3750
4566
  interpretPatterns,
3751
4567
  isPresent,
3752
4568
  isScored,
3753
4569
  isSentinel,
3754
4570
  listLenses,
4571
+ loadExtendsConfig,
3755
4572
  loadPriorReads,
4573
+ parseExtendsSpec,
4574
+ parseRemoteUrl,
3756
4575
  parseRepoScope,
3757
4576
  parseScope,
3758
4577
  presenceAverage,
3759
4578
  readExocortex,
4579
+ readOriginRemote,
3760
4580
  readTeamExocortices,
3761
4581
  render,
4582
+ resolveAllExtends,
4583
+ resolveExtendsSpec,
3762
4584
  scoreComposite,
3763
4585
  scoreCyber,
3764
4586
  scoreLife,
3765
4587
  scoreNeuroVerse,
4588
+ sovereignConduitLens,
3766
4589
  summarizeExocortex,
3767
4590
  think,
3768
4591
  updateKnowledge,