@animalabs/connectome-host 0.3.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 (123) hide show
  1. package/.env.example +20 -0
  2. package/.github/workflows/publish.yml +65 -0
  3. package/ARCHITECTURE.md +355 -0
  4. package/CHANGELOG.md +30 -0
  5. package/HEADLESS-FLEET-PLAN.md +330 -0
  6. package/README.md +189 -0
  7. package/UNIFIED-TREE-PLAN.md +242 -0
  8. package/bun.lock +288 -0
  9. package/docs/AGENT-MEMORY-GUIDE.md +214 -0
  10. package/docs/AGENT-ONBOARDING.md +541 -0
  11. package/docs/ATTENTION-AND-GATING.md +120 -0
  12. package/docs/DEPLOYMENTS.md +130 -0
  13. package/docs/DEV-ENVIRONMENT.md +215 -0
  14. package/docs/LIBRARY-PIPELINE.md +286 -0
  15. package/docs/LOCUS-ROUTING-DESIGN.md +115 -0
  16. package/docs/claudeai-evacuation.md +228 -0
  17. package/docs/debug-context-api.md +208 -0
  18. package/docs/webui-deployment.md +219 -0
  19. package/package.json +33 -0
  20. package/recipes/SETUP.md +308 -0
  21. package/recipes/TRIUMVIRATE-SETUP.md +467 -0
  22. package/recipes/claude-export-revive.json +19 -0
  23. package/recipes/clerk.json +157 -0
  24. package/recipes/knowledge-miner.json +174 -0
  25. package/recipes/knowledge-reviewer.json +76 -0
  26. package/recipes/mcpl-editor-test.json +38 -0
  27. package/recipes/prompts/transplant-addendum.md +17 -0
  28. package/recipes/triumvirate.json +63 -0
  29. package/recipes/webui-fleet-test.json +27 -0
  30. package/recipes/webui-test.json +16 -0
  31. package/recipes/zulip-miner.json +87 -0
  32. package/scripts/connectome-doctor +373 -0
  33. package/scripts/evacuator.ts +956 -0
  34. package/scripts/import-claudeai-export.ts +747 -0
  35. package/scripts/lib/line-reader.ts +53 -0
  36. package/scripts/test-historical-thinking.ts +148 -0
  37. package/scripts/warmup-session.ts +336 -0
  38. package/src/agent-name.ts +58 -0
  39. package/src/commands.ts +1074 -0
  40. package/src/headless.ts +528 -0
  41. package/src/index.ts +867 -0
  42. package/src/logging-adapter.ts +208 -0
  43. package/src/mcpl-config.ts +199 -0
  44. package/src/modules/activity-module.ts +270 -0
  45. package/src/modules/channel-mode-module.ts +260 -0
  46. package/src/modules/fleet-module.ts +1705 -0
  47. package/src/modules/fleet-types.ts +225 -0
  48. package/src/modules/lessons-module.ts +465 -0
  49. package/src/modules/mcpl-admin-module.ts +345 -0
  50. package/src/modules/retrieval-module.ts +327 -0
  51. package/src/modules/settings-module.ts +143 -0
  52. package/src/modules/subagent-module.ts +2074 -0
  53. package/src/modules/subscription-gc-module.ts +322 -0
  54. package/src/modules/time-module.ts +85 -0
  55. package/src/modules/tui-module.ts +76 -0
  56. package/src/modules/web-ui-curve-page.ts +249 -0
  57. package/src/modules/web-ui-module.ts +2595 -0
  58. package/src/recipe.ts +1003 -0
  59. package/src/session-manager.ts +278 -0
  60. package/src/state/agent-tree-reducer.ts +431 -0
  61. package/src/state/fleet-tree-aggregator.ts +195 -0
  62. package/src/strategies/frontdesk-strategy.ts +364 -0
  63. package/src/synesthete.ts +68 -0
  64. package/src/tui.ts +2200 -0
  65. package/src/types/bun-ffi.d.ts +6 -0
  66. package/src/web/protocol.ts +648 -0
  67. package/test/agent-name.test.ts +62 -0
  68. package/test/agent-tree-fleet-launch.test.ts +64 -0
  69. package/test/agent-tree-reducer-parity.test.ts +194 -0
  70. package/test/agent-tree-reducer.test.ts +443 -0
  71. package/test/agent-tree-rollup.test.ts +109 -0
  72. package/test/autobio-progress-snapshot.test.ts +40 -0
  73. package/test/claudeai-export-importer.test.ts +386 -0
  74. package/test/evacuator.test.ts +332 -0
  75. package/test/fleet-commands.test.ts +244 -0
  76. package/test/fleet-no-subfleets.test.ts +147 -0
  77. package/test/fleet-orchestration.test.ts +353 -0
  78. package/test/fleet-recipe.test.ts +124 -0
  79. package/test/fleet-route.test.ts +44 -0
  80. package/test/fleet-smoke.test.ts +479 -0
  81. package/test/fleet-subscribe-union-e2e.test.ts +123 -0
  82. package/test/fleet-subscribe-union.test.ts +85 -0
  83. package/test/fleet-tree-aggregator-e2e.test.ts +110 -0
  84. package/test/fleet-tree-aggregator.test.ts +215 -0
  85. package/test/frontdesk-strategy.test.ts +326 -0
  86. package/test/headless-describe.test.ts +182 -0
  87. package/test/headless-smoke.test.ts +190 -0
  88. package/test/logging-adapter.test.ts +87 -0
  89. package/test/mcpl-admin-module.test.ts +213 -0
  90. package/test/mcpl-agent-overlay.test.ts +126 -0
  91. package/test/mock-headless-child.ts +133 -0
  92. package/test/recipe-cache-ttl.test.ts +37 -0
  93. package/test/recipe-env.test.ts +157 -0
  94. package/test/recipe-path-resolution.test.ts +170 -0
  95. package/test/subagent-async-timeout.test.ts +381 -0
  96. package/test/subagent-fork-materialise.test.ts +241 -0
  97. package/test/subagent-peek-scoping.test.ts +180 -0
  98. package/test/subagent-peek-zombie.test.ts +148 -0
  99. package/test/subagent-reaper-in-flight.test.ts +229 -0
  100. package/test/subscription-gc-module.test.ts +136 -0
  101. package/test/warmup-handoff.test.ts +150 -0
  102. package/test/web-ui-bind.test.ts +51 -0
  103. package/test/web-ui-module.test.ts +246 -0
  104. package/test/web-ui-protocol.test.ts +0 -0
  105. package/tsconfig.json +14 -0
  106. package/web/bun.lock +357 -0
  107. package/web/index.html +12 -0
  108. package/web/package.json +24 -0
  109. package/web/src/App.tsx +1931 -0
  110. package/web/src/Context.tsx +158 -0
  111. package/web/src/ContextDocument.tsx +150 -0
  112. package/web/src/Files.tsx +271 -0
  113. package/web/src/Lessons.tsx +164 -0
  114. package/web/src/Mcpl.tsx +310 -0
  115. package/web/src/Stream.tsx +119 -0
  116. package/web/src/TreeSidebar.tsx +283 -0
  117. package/web/src/Usage.tsx +182 -0
  118. package/web/src/main.tsx +7 -0
  119. package/web/src/styles.css +26 -0
  120. package/web/src/tree.ts +268 -0
  121. package/web/src/wire.ts +120 -0
  122. package/web/tsconfig.json +21 -0
  123. package/web/vite.config.ts +32 -0
@@ -0,0 +1,143 @@
1
+ /**
2
+ * SettingsModule — runtime-tunable host settings the agent can toggle for
3
+ * itself. State persists to chronicle via ModuleContext (`setState`/`getState`)
4
+ * so changes survive restarts.
5
+ *
6
+ * First domain: **reasoning** (Anthropic extended thinking). Tools:
7
+ * - reasoning_status → show current state
8
+ * - reasoning_enable {budgetTokens?} → turn on with optional budget
9
+ * - reasoning_disable → turn off
10
+ *
11
+ * The host's adapter wrapper (LoggingAnthropicAdapter) reads `getReasoning()`
12
+ * on each call and injects `thinking: {type:'enabled', budget_tokens: N}` into
13
+ * the outgoing Anthropic request when enabled — keeping the cross-cutting
14
+ * "request mutator" plumbing out of every call site.
15
+ *
16
+ * Designed to be extensible: new domains add their own slice in
17
+ * `SettingsState` + a few tools + a typed accessor. Bundled with the host;
18
+ * recipes opt in by including `SettingsModule` in moduleInstances.
19
+ */
20
+
21
+ import type {
22
+ Module,
23
+ ModuleContext,
24
+ ProcessEvent,
25
+ ProcessState,
26
+ EventResponse,
27
+ ToolDefinition,
28
+ ToolCall,
29
+ ToolResult,
30
+ } from '@animalabs/agent-framework';
31
+
32
+ export interface ReasoningSettings {
33
+ enabled: boolean;
34
+ budgetTokens: number;
35
+ }
36
+
37
+ export interface SettingsState {
38
+ reasoning: ReasoningSettings;
39
+ }
40
+
41
+ const DEFAULTS: SettingsState = {
42
+ reasoning: { enabled: false, budgetTokens: 8192 },
43
+ };
44
+
45
+ export class SettingsModule implements Module {
46
+ readonly name = 'settings';
47
+
48
+ private ctx: ModuleContext | null = null;
49
+ private state: SettingsState = clone(DEFAULTS);
50
+
51
+ async start(ctx: ModuleContext): Promise<void> {
52
+ this.ctx = ctx;
53
+ const saved = ctx.getState<Partial<SettingsState>>();
54
+ if (saved) {
55
+ // Shallow-merge each domain so future-added fields fall back to defaults
56
+ // for state persisted by older versions.
57
+ this.state = {
58
+ reasoning: { ...DEFAULTS.reasoning, ...(saved.reasoning ?? {}) },
59
+ };
60
+ }
61
+ }
62
+
63
+ async stop(): Promise<void> {
64
+ this.ctx = null;
65
+ }
66
+
67
+ /** Read accessor for external consumers (e.g., the LLM adapter wrapper). */
68
+ getReasoning(): ReasoningSettings {
69
+ return { ...this.state.reasoning };
70
+ }
71
+
72
+ getTools(): ToolDefinition[] {
73
+ return [
74
+ {
75
+ name: 'reasoning_status',
76
+ description:
77
+ 'Show whether extended thinking (reasoning) is currently enabled and the token budget.',
78
+ inputSchema: { type: 'object', properties: {} },
79
+ },
80
+ {
81
+ name: 'reasoning_enable',
82
+ description:
83
+ 'Enable extended thinking (reasoning) on your subsequent inference calls. ' +
84
+ 'Optional budgetTokens in tokens (default: current value, initially 8192; min 1024).',
85
+ inputSchema: {
86
+ type: 'object',
87
+ properties: {
88
+ budgetTokens: {
89
+ type: 'number',
90
+ description: 'Token budget for thinking blocks (min 1024).',
91
+ },
92
+ },
93
+ },
94
+ },
95
+ {
96
+ name: 'reasoning_disable',
97
+ description:
98
+ 'Disable extended thinking (reasoning). Subsequent inference calls will not request thinking blocks.',
99
+ inputSchema: { type: 'object', properties: {} },
100
+ },
101
+ ];
102
+ }
103
+
104
+ async handleToolCall(call: ToolCall): Promise<ToolResult> {
105
+ const input = (call.input ?? {}) as Record<string, unknown>;
106
+ switch (call.name) {
107
+ case 'reasoning_status':
108
+ return ok(this.reasoningStatusText());
109
+ case 'reasoning_enable': {
110
+ const budget =
111
+ typeof input.budgetTokens === 'number'
112
+ ? Math.max(1024, Math.round(input.budgetTokens))
113
+ : this.state.reasoning.budgetTokens;
114
+ this.state.reasoning = { enabled: true, budgetTokens: budget };
115
+ this.ctx?.setState(this.state);
116
+ return ok('Reasoning enabled. ' + this.reasoningStatusText());
117
+ }
118
+ case 'reasoning_disable':
119
+ this.state.reasoning = { ...this.state.reasoning, enabled: false };
120
+ this.ctx?.setState(this.state);
121
+ return ok('Reasoning disabled. ' + this.reasoningStatusText());
122
+ default:
123
+ return { success: false, error: `Unknown tool: ${call.name}`, isError: true };
124
+ }
125
+ }
126
+
127
+ async onProcess(_event: ProcessEvent, _state: ProcessState): Promise<EventResponse> {
128
+ return {};
129
+ }
130
+
131
+ private reasoningStatusText(): string {
132
+ const r = this.state.reasoning;
133
+ return `reasoning=${r.enabled ? 'ENABLED' : 'disabled'}, budgetTokens=${r.budgetTokens}`;
134
+ }
135
+ }
136
+
137
+ function clone<T>(x: T): T {
138
+ return JSON.parse(JSON.stringify(x)) as T;
139
+ }
140
+
141
+ function ok(message: string): ToolResult {
142
+ return { success: true, data: { message }, isError: false };
143
+ }