@mindot/will 0.7.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.
Files changed (88) hide show
  1. package/README.md +87 -22
  2. package/dist/channels/discord.d.ts +67 -6
  3. package/dist/channels/discord.js +112 -6
  4. package/dist/channels/discord.js.map +1 -1
  5. package/dist/channels/whatsapp.d.ts +1 -1
  6. package/dist/channels/whatsapp.js +4 -1
  7. package/dist/channels/whatsapp.js.map +1 -1
  8. package/dist/cli.js +13733 -11057
  9. package/dist/cli.js.map +1 -1
  10. package/dist/index.d.ts +2 -2
  11. package/dist/index.js +3729 -1199
  12. package/dist/index.js.map +1 -1
  13. package/dist/mcp/effectors.d.ts +1 -1
  14. package/dist/{will-DAW0l-lY.d.ts → will-DbDj_TEH.d.ts} +1214 -93
  15. package/package.json +1 -1
  16. package/src/channels/discord.ts +189 -11
  17. package/src/channels/types.ts +90 -0
  18. package/src/channels/whatsapp.ts +13 -4
  19. package/src/cli.ts +9 -4
  20. package/src/cognition/agency/consequence.ts +122 -1
  21. package/src/cognition/agency/conversation.aim.ts +260 -0
  22. package/src/cognition/agency/engines/action.selector.ts +85 -3
  23. package/src/cognition/agency/engines/affordance.synthesizer.ts +90 -1
  24. package/src/cognition/agency/engines/motor.schema.executor.ts +152 -10
  25. package/src/cognition/agency/engines/reafference.engine.ts +129 -2
  26. package/src/cognition/agency/proactive.communicator.ts +19 -3
  27. package/src/cognition/agency/reconcile.learning.ts +16 -2
  28. package/src/cognition/agency/restart.ts +66 -0
  29. package/src/cognition/agency/schemas/repertoire.ts +12 -5
  30. package/src/cognition/agency/selection.scoring.ts +33 -0
  31. package/src/cognition/agency/types.ts +35 -0
  32. package/src/cognition/cache/composition.ts +232 -0
  33. package/src/cognition/cache/deliberation.cache.ts +219 -0
  34. package/src/cognition/cache/fingerprint.ts +120 -0
  35. package/src/cognition/cache/types.ts +105 -0
  36. package/src/cognition/config.mirror.entities.ts +109 -1
  37. package/src/cognition/event.schemas.ts +22 -0
  38. package/src/cognition/faculties/autobiographical.narrator.ts +5 -10
  39. package/src/cognition/faculties/episodic.consolidator.ts +59 -3
  40. package/src/cognition/faculties/executive.engine/commands.ts +189 -14
  41. package/src/cognition/faculties/executive.engine/context.ts +67 -13
  42. package/src/cognition/faculties/executive.engine/deliberate.reasoning.ts +1 -1
  43. package/src/cognition/faculties/executive.engine/engine.ts +686 -187
  44. package/src/cognition/faculties/executive.engine/escalation.buffer.ts +162 -44
  45. package/src/cognition/faculties/executive.engine/facet.supervisor.ts +310 -65
  46. package/src/cognition/faculties/executive.engine/facet.ts +89 -26
  47. package/src/cognition/faculties/executive.engine/gating.ts +14 -14
  48. package/src/cognition/faculties/executive.engine/parser.ts +21 -1
  49. package/src/cognition/faculties/executive.engine/prompt.factory.ts +169 -20
  50. package/src/cognition/faculties/executive.engine/types.ts +69 -0
  51. package/src/cognition/faculties/goal.manager.ts +94 -14
  52. package/src/cognition/faculties/known.entity.tracker.ts +267 -28
  53. package/src/cognition/faculties/moral.evaluator.ts +8 -3
  54. package/src/cognition/faculties/persona.consolidator.ts +141 -0
  55. package/src/cognition/faculties/reputation.tracker.ts +66 -2
  56. package/src/cognition/faculties/self.model.updater.ts +19 -12
  57. package/src/cognition/faculties/social.perception.ts +47 -3
  58. package/src/cognition/faculties/threat.evaluator.ts +7 -0
  59. package/src/cognition/faculties/working.memory.ts +10 -20
  60. package/src/cognition/identity.entity.ts +205 -0
  61. package/src/cognition/index.ts +11 -0
  62. package/src/cognition/memory/vector.adapter.ts +12 -3
  63. package/src/cognition/memory/vector.embedder.ts +54 -7
  64. package/src/cognition/persona.prior.ts +6 -0
  65. package/src/cognition/senses/audition.engine/engine.ts +404 -46
  66. package/src/cognition/senses/base.sense.engine.ts +1 -1
  67. package/src/cognition/senses/index.ts +12 -0
  68. package/src/cognition/social.identity.ts +273 -0
  69. package/src/cognition/utilities/token.tracker.ts +246 -98
  70. package/src/core/orchestrator.ts +38 -0
  71. package/src/host/boot.ts +78 -22
  72. package/src/index.ts +35 -0
  73. package/src/llm/index.ts +415 -97
  74. package/src/llm/routing.ts +204 -0
  75. package/src/llm/summarizer.ts +5 -1
  76. package/src/llm/wire.contracts.ts +19 -0
  77. package/src/pma/index.ts +67 -53
  78. package/src/runners/thin-shim.runner.ts +18 -6
  79. package/src/sdk/will.ts +121 -22
  80. package/src/stem/assembly.audit.ts +1 -0
  81. package/src/stem/guards/identity.coherence.ts +17 -6
  82. package/src/stem/index.ts +82 -5
  83. package/src/stem/mind.ts +327 -79
  84. package/src/stem/policy/arbiter.ts +49 -14
  85. package/src/stem/policy/rule.table.ts +2 -2
  86. package/src/stem/tracts/effector.controller.ts +56 -9
  87. package/src/stem/tracts/outbox.writer.ts +40 -2
  88. package/src/cognition/faculties/executive.engine/messages.ts +0 -102
package/src/host/boot.ts CHANGED
@@ -12,9 +12,11 @@
12
12
  // WILL_NAME display name (default "Will")
13
13
  // WILL_IDENTITY persona prompt (default a minimal self)
14
14
  // WILL_TIER basic | standard | full (default standard)
15
- // WILL_LLM mock | anthropic | glm (default: auto — anthropic when
16
- // ANTHROPIC_API_KEY is set, glm when
17
- // ZAI_API_KEY is, else mock)
15
+ // WILL_LLM mock | any provider name (default: auto — whichever
16
+ // provider's own key is set,
17
+ // else the zero-key mock)
18
+ // WILL_LLM_MODEL concrete model id (REQUIRED for a live mind —
19
+ // the engine has no default)
18
20
  // WILL_TICK_MS ms per tick (default 1000)
19
21
  // WILL_SEED deterministic seed (testing) (default unseeded/wall-time)
20
22
  // WILL_PMA_PATH PMA artifact path (default ./.will/<name>.pma.json)
@@ -25,10 +27,10 @@
25
27
  import { existsSync, readFileSync, mkdirSync, writeFileSync } from 'node:fs'
26
28
  import { dirname, resolve } from 'node:path'
27
29
  import { setLogger } from '#core/logger'
28
- import { Will, type CreateWillOptions } from '#sdk/will'
30
+ import { Will, detectProvider, type CreateWillOptions } from '#sdk/will'
29
31
  import type { PMASnapshot } from '#pma/index'
30
32
  import { connectMcpEffectors, type McpToolsSource } from '#root/mcp/effectors'
31
- import { anthropicWireHeaders, defaultBaseFor, defaultModelFor } from '#llm/index'
33
+ import { anthropicWireHeaders, defaultBaseFor, knownWireFor, providerKeyFromEnv, PROVIDER_KEY_ENV, type LLMProvider, type LLMWire } from '#llm/index'
32
34
 
33
35
  /**
34
36
  * Route every engine log line to stderr. For `will mcp`, stdout is the MCP
@@ -47,19 +49,51 @@ function slug( s: string ): string {
47
49
 
48
50
  /** The LLM mode the hosts will boot with: an explicit WILL_LLM, else whichever
49
51
  * provider's key is present, else the zero-key mock. */
50
- export function resolveLlmMode(): 'mock' | 'anthropic' | 'glm' {
51
- const explicit = process.env.WILL_LLM as 'mock' | 'anthropic' | 'glm' | undefined
52
- if( explicit ) return explicit
53
- if( process.env.ANTHROPIC_API_KEY ) return 'anthropic'
54
- if( process.env.ZAI_API_KEY ) return 'glm'
55
- return 'mock'
52
+ export function resolveLlmMode(): 'mock' | LLMProvider {
53
+ const explicit = process.env.WILL_LLM
54
+ if( explicit ) return explicit as 'mock' | LLMProvider
55
+ // The SDK's own detection, not a copy of it. Boot used to know only
56
+ // anthropic/glm, so once the provider set widened, a Will booting live on
57
+ // (say) Kimi had its preflight silently skipped — the one check that exists
58
+ // to stop a mind that boots, perceives, and never speaks.
59
+ return detectProvider()
56
60
  }
57
61
 
58
62
  /** The key for a live mode — the provider-agnostic override first, then the
59
63
  * provider's own env. */
60
- function resolveLlmKey( mode: 'anthropic' | 'glm'): string | undefined {
61
- return process.env.WILL_LLM_API_KEY
62
- ?? ( mode === 'glm' ? process.env.ZAI_API_KEY : process.env.ANTHROPIC_API_KEY )
64
+ function resolveLlmKey( mode: LLMProvider ): string | undefined {
65
+ return process.env.WILL_LLM_API_KEY ?? providerKeyFromEnv( mode )
66
+ }
67
+
68
+ /**
69
+ * The smallest real completion request, in a given wire's dialect.
70
+ *
71
+ * `null` means "this wire has no cheap ping here" — the caller raises the mind
72
+ * unchecked rather than inventing a request shape and reading its rejection as
73
+ * a broken provider.
74
+ */
75
+ export function pingRequest(
76
+ wire: LLMWire, base: string, model: string, key: string, provider: LLMProvider,
77
+ ): { url: string; headers: Record<string, string>; body: unknown } | null {
78
+ const messages = [ { role: 'user', content: 'ping' } ]
79
+ switch( wire ){
80
+ case 'anthropic':
81
+ return {
82
+ url: `${ base }/messages`,
83
+ headers: anthropicWireHeaders( provider, key ),
84
+ body: { model, max_tokens: 1, messages },
85
+ }
86
+ case 'openai':
87
+ return {
88
+ url: `${ base }/chat/completions`,
89
+ headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${ key }` },
90
+ body: { model, max_tokens: 1, messages },
91
+ }
92
+ // Gemini authenticates in the query string and nests its payload
93
+ // differently enough that a hand-rolled ping here would drift from the
94
+ // client that actually makes the calls. Better unchecked than wrong.
95
+ case 'google': return null
96
+ }
63
97
  }
64
98
 
65
99
  /**
@@ -83,7 +117,7 @@ async function preflightLLM( anatomy: string ): Promise<void> {
83
117
 
84
118
  const key = resolveLlmKey( mode )
85
119
  if( !key ){
86
- const expected = mode === 'glm' ? 'ZAI_API_KEY' : 'ANTHROPIC_API_KEY'
120
+ const expected = PROVIDER_KEY_ENV[ mode ] ?? 'WILL_LLM_API_KEY'
87
121
  console.error(`[will] WILL_LLM=${ mode } but no ${ expected } / WILL_LLM_API_KEY is set.`)
88
122
  console.error('[will] The Will would boot, perceive, and never speak. Set a key, or run keyless with WILL_LLM=mock.')
89
123
  process.exit( 2 )
@@ -91,16 +125,38 @@ async function preflightLLM( anatomy: string ): Promise<void> {
91
125
 
92
126
  // The ping validates key + balance + reachability, which is the failure class
93
127
  // that strands an operator. It uses the pinned model when there is one, so a
94
- // bad model id is caught too; otherwise the cheapest model stands in. GLM
95
- // speaks the same wire at Z.ai's compat endpoint, so one ping serves both.
96
- const base = process.env.WILL_LLM_BASE_URL ?? defaultBaseFor( mode )
128
+ // bad model id is caught too.
129
+ const base = process.env.WILL_LLM_BASE_URL ?? defaultBaseFor( mode )
130
+ if( !base ){
131
+ console.error(`[will] WILL_LLM=${ mode } has no known base URL — set WILL_LLM_BASE_URL.`)
132
+ process.exit( 2 )
133
+ }
134
+ // The ping needs *a* model id. WILL_LLM_MODEL is the one the Will will
135
+ // actually use, so preferring it means a bad id is caught here rather than at
136
+ // the first tick. Without it there is nothing honest to send: the engine no
137
+ // longer carries a default model, so say so plainly instead of guessing.
97
138
  const model = process.env.WILL_LLM_MODEL
98
- ?? ( mode === 'glm' ? defaultModelFor('glm') : 'claude-haiku-4-5-20251001')
139
+ if( !model ){
140
+ console.error(`[will] WILL_LLM_MODEL is not set. The engine has no default model —`)
141
+ console.error('[will] pick one for your provider (e.g. WILL_LLM_MODEL=claude-sonnet-4-5-20250929).')
142
+ process.exit( 2 )
143
+ }
144
+
145
+ // Ping in the provider's OWN dialect. This used to be hardcoded to the
146
+ // Anthropic wire, which was fine when boot knew only anthropic and glm. With
147
+ // the provider set widened it became a false negative: an OpenAI-wire
148
+ // provider answers 404 to `/messages`, preflight read that as "the LLM
149
+ // refused", and a perfectly working Will never got raised.
150
+ const ping = pingRequest( knownWireFor( mode ) ?? 'openai', base, model, key, mode )
151
+ if( !ping ){
152
+ console.error(`[will] no preflight ping for the ${ mode } wire — raising the mind unchecked.`)
153
+ return
154
+ }
99
155
  try {
100
- const res = await fetch(`${ base }/messages`, {
156
+ const res = await fetch( ping.url, {
101
157
  method: 'POST',
102
- headers: anthropicWireHeaders( mode, key ),
103
- body: JSON.stringify( { model, max_tokens: 1, messages: [ { role: 'user', content: 'ping' } ] } ),
158
+ headers: ping.headers,
159
+ body: JSON.stringify( ping.body ),
104
160
  signal: AbortSignal.timeout( 20_000 ),
105
161
  } )
106
162
  if( res.ok ) return
package/src/index.ts CHANGED
@@ -26,6 +26,41 @@ export {
26
26
 
27
27
  export { assembleMind, type WillConfig } from '#stem/mind'
28
28
 
29
+ // Model routing — which model serves which call.
30
+ //
31
+ // These were reachable only through `WillConfig.llm.router`'s structural type,
32
+ // which meant the reference implementation this ships *for* hosts to use could
33
+ // not be imported by one. A seam nobody can import is not a seam.
34
+ //
35
+ // The engine carries mechanism only: a router sees what kind of work a call is
36
+ // and how much the moment demands, never who is paying or what anything costs.
37
+ // The table itself is the host's.
38
+ export {
39
+ NULL_ROUTER,
40
+ TableRouter,
41
+ chainRouters,
42
+ isNullRouter,
43
+ type ModelRouter,
44
+ type ModelRoute,
45
+ type RoutingRule,
46
+ } from '#llm/routing'
47
+
48
+ // Provider vocabulary — the wire each known provider speaks and where it lives.
49
+ // A provider outside this table works identically once the host declares its
50
+ // `wire` and `baseUrl` on the `llm.providers` entry.
51
+ export {
52
+ KNOWN_PROVIDERS,
53
+ knownWireFor,
54
+ defaultBaseFor,
55
+ BACKGROUND_DEMAND,
56
+ ESCALATION_DEMAND,
57
+ type LLMProvider,
58
+ type KnownProvider,
59
+ type LLMWire,
60
+ type LLMCallMeta,
61
+ type ProviderCredential,
62
+ } from '#llm/index'
63
+
29
64
  // External transport — the unified bidirectional envelope channel between a Will
30
65
  // and its host peer (backend). Exposes the transport interface, every envelope
31
66
  // type, and the three implementations: