@itaila/archetype 0.3.30

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 (319) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +475 -0
  3. package/dist/audit/audit-persona.d.ts +163 -0
  4. package/dist/audit/audit-persona.d.ts.map +1 -0
  5. package/dist/audit/audit-persona.js +415 -0
  6. package/dist/audit/audit-persona.js.map +1 -0
  7. package/dist/audit/brain-reflection.d.ts +33 -0
  8. package/dist/audit/brain-reflection.d.ts.map +1 -0
  9. package/dist/audit/brain-reflection.js +148 -0
  10. package/dist/audit/brain-reflection.js.map +1 -0
  11. package/dist/audit/conversation-audit.d.ts +12 -0
  12. package/dist/audit/conversation-audit.d.ts.map +1 -0
  13. package/dist/audit/conversation-audit.js +76 -0
  14. package/dist/audit/conversation-audit.js.map +1 -0
  15. package/dist/audit/prompt-audit.d.ts +10 -0
  16. package/dist/audit/prompt-audit.d.ts.map +1 -0
  17. package/dist/audit/prompt-audit.js +153 -0
  18. package/dist/audit/prompt-audit.js.map +1 -0
  19. package/dist/audit/prompt-dump.d.ts +137 -0
  20. package/dist/audit/prompt-dump.d.ts.map +1 -0
  21. package/dist/audit/prompt-dump.js +269 -0
  22. package/dist/audit/prompt-dump.js.map +1 -0
  23. package/dist/audit/trace-integrity.d.ts +33 -0
  24. package/dist/audit/trace-integrity.d.ts.map +1 -0
  25. package/dist/audit/trace-integrity.js +109 -0
  26. package/dist/audit/trace-integrity.js.map +1 -0
  27. package/dist/audit/types.d.ts +92 -0
  28. package/dist/audit/types.d.ts.map +1 -0
  29. package/dist/audit/types.js +2 -0
  30. package/dist/audit/types.js.map +1 -0
  31. package/dist/audit/version.d.ts +14 -0
  32. package/dist/audit/version.d.ts.map +1 -0
  33. package/dist/audit/version.js +65 -0
  34. package/dist/audit/version.js.map +1 -0
  35. package/dist/brain.d.ts +7 -0
  36. package/dist/brain.d.ts.map +1 -0
  37. package/dist/brain.js +83 -0
  38. package/dist/brain.js.map +1 -0
  39. package/dist/builder/actions.d.ts +60 -0
  40. package/dist/builder/actions.d.ts.map +1 -0
  41. package/dist/builder/actions.js +257 -0
  42. package/dist/builder/actions.js.map +1 -0
  43. package/dist/builder/browser.d.ts +140 -0
  44. package/dist/builder/browser.d.ts.map +1 -0
  45. package/dist/builder/browser.js +232 -0
  46. package/dist/builder/browser.js.map +1 -0
  47. package/dist/builder/executor.d.ts +228 -0
  48. package/dist/builder/executor.d.ts.map +1 -0
  49. package/dist/builder/executor.js +1548 -0
  50. package/dist/builder/executor.js.map +1 -0
  51. package/dist/builder/index.d.ts +24 -0
  52. package/dist/builder/index.d.ts.map +1 -0
  53. package/dist/builder/index.js +24 -0
  54. package/dist/builder/index.js.map +1 -0
  55. package/dist/builder/node-test-discovery.d.ts +13 -0
  56. package/dist/builder/node-test-discovery.d.ts.map +1 -0
  57. package/dist/builder/node-test-discovery.js +45 -0
  58. package/dist/builder/node-test-discovery.js.map +1 -0
  59. package/dist/builder/sandbox.d.ts +172 -0
  60. package/dist/builder/sandbox.d.ts.map +1 -0
  61. package/dist/builder/sandbox.js +294 -0
  62. package/dist/builder/sandbox.js.map +1 -0
  63. package/dist/builder/workspace-files.d.ts +63 -0
  64. package/dist/builder/workspace-files.d.ts.map +1 -0
  65. package/dist/builder/workspace-files.js +190 -0
  66. package/dist/builder/workspace-files.js.map +1 -0
  67. package/dist/core/actions.d.ts +55 -0
  68. package/dist/core/actions.d.ts.map +1 -0
  69. package/dist/core/actions.js +311 -0
  70. package/dist/core/actions.js.map +1 -0
  71. package/dist/core/attachment-notes.d.ts +7 -0
  72. package/dist/core/attachment-notes.d.ts.map +1 -0
  73. package/dist/core/attachment-notes.js +38 -0
  74. package/dist/core/attachment-notes.js.map +1 -0
  75. package/dist/core/context.d.ts +10 -0
  76. package/dist/core/context.d.ts.map +1 -0
  77. package/dist/core/context.js +108 -0
  78. package/dist/core/context.js.map +1 -0
  79. package/dist/core/crud-prompt.d.ts +16 -0
  80. package/dist/core/crud-prompt.d.ts.map +1 -0
  81. package/dist/core/crud-prompt.js +268 -0
  82. package/dist/core/crud-prompt.js.map +1 -0
  83. package/dist/core/crud-schema.d.ts +12 -0
  84. package/dist/core/crud-schema.d.ts.map +1 -0
  85. package/dist/core/crud-schema.js +42 -0
  86. package/dist/core/crud-schema.js.map +1 -0
  87. package/dist/core/effective-config.d.ts +13 -0
  88. package/dist/core/effective-config.d.ts.map +1 -0
  89. package/dist/core/effective-config.js +33 -0
  90. package/dist/core/effective-config.js.map +1 -0
  91. package/dist/core/entities.d.ts +82 -0
  92. package/dist/core/entities.d.ts.map +1 -0
  93. package/dist/core/entities.js +116 -0
  94. package/dist/core/entities.js.map +1 -0
  95. package/dist/core/entity-helpers.d.ts +47 -0
  96. package/dist/core/entity-helpers.d.ts.map +1 -0
  97. package/dist/core/entity-helpers.js +122 -0
  98. package/dist/core/entity-helpers.js.map +1 -0
  99. package/dist/core/entity-registry.d.ts +47 -0
  100. package/dist/core/entity-registry.d.ts.map +1 -0
  101. package/dist/core/entity-registry.js +54 -0
  102. package/dist/core/entity-registry.js.map +1 -0
  103. package/dist/core/eq.d.ts +13 -0
  104. package/dist/core/eq.d.ts.map +1 -0
  105. package/dist/core/eq.js +41 -0
  106. package/dist/core/eq.js.map +1 -0
  107. package/dist/core/focus-context.d.ts +19 -0
  108. package/dist/core/focus-context.d.ts.map +1 -0
  109. package/dist/core/focus-context.js +46 -0
  110. package/dist/core/focus-context.js.map +1 -0
  111. package/dist/core/focus-mode-actions.d.ts +23 -0
  112. package/dist/core/focus-mode-actions.d.ts.map +1 -0
  113. package/dist/core/focus-mode-actions.js +74 -0
  114. package/dist/core/focus-mode-actions.js.map +1 -0
  115. package/dist/core/greeting.d.ts +10 -0
  116. package/dist/core/greeting.d.ts.map +1 -0
  117. package/dist/core/greeting.js +41 -0
  118. package/dist/core/greeting.js.map +1 -0
  119. package/dist/core/identity.d.ts +13 -0
  120. package/dist/core/identity.d.ts.map +1 -0
  121. package/dist/core/identity.js +54 -0
  122. package/dist/core/identity.js.map +1 -0
  123. package/dist/core/knowledge.d.ts +10 -0
  124. package/dist/core/knowledge.d.ts.map +1 -0
  125. package/dist/core/knowledge.js +40 -0
  126. package/dist/core/knowledge.js.map +1 -0
  127. package/dist/core/memory-actions.d.ts +38 -0
  128. package/dist/core/memory-actions.d.ts.map +1 -0
  129. package/dist/core/memory-actions.js +181 -0
  130. package/dist/core/memory-actions.js.map +1 -0
  131. package/dist/core/memory.d.ts +35 -0
  132. package/dist/core/memory.d.ts.map +1 -0
  133. package/dist/core/memory.js +168 -0
  134. package/dist/core/memory.js.map +1 -0
  135. package/dist/core/peer-actions.d.ts +15 -0
  136. package/dist/core/peer-actions.d.ts.map +1 -0
  137. package/dist/core/peer-actions.js +33 -0
  138. package/dist/core/peer-actions.js.map +1 -0
  139. package/dist/core/prompt-builder.d.ts +46 -0
  140. package/dist/core/prompt-builder.d.ts.map +1 -0
  141. package/dist/core/prompt-builder.js +543 -0
  142. package/dist/core/prompt-builder.js.map +1 -0
  143. package/dist/core/prompt-mode.d.ts +3 -0
  144. package/dist/core/prompt-mode.d.ts.map +1 -0
  145. package/dist/core/prompt-mode.js +6 -0
  146. package/dist/core/prompt-mode.js.map +1 -0
  147. package/dist/core/prompted-turn.d.ts +6 -0
  148. package/dist/core/prompted-turn.d.ts.map +1 -0
  149. package/dist/core/prompted-turn.js +48 -0
  150. package/dist/core/prompted-turn.js.map +1 -0
  151. package/dist/core/request-builder.d.ts +14 -0
  152. package/dist/core/request-builder.d.ts.map +1 -0
  153. package/dist/core/request-builder.js +64 -0
  154. package/dist/core/request-builder.js.map +1 -0
  155. package/dist/core/session-routing.d.ts +23 -0
  156. package/dist/core/session-routing.d.ts.map +1 -0
  157. package/dist/core/session-routing.js +59 -0
  158. package/dist/core/session-routing.js.map +1 -0
  159. package/dist/core/voice.d.ts +6 -0
  160. package/dist/core/voice.d.ts.map +1 -0
  161. package/dist/core/voice.js +30 -0
  162. package/dist/core/voice.js.map +1 -0
  163. package/dist/engine/chat.d.ts +45 -0
  164. package/dist/engine/chat.d.ts.map +1 -0
  165. package/dist/engine/chat.js +308 -0
  166. package/dist/engine/chat.js.map +1 -0
  167. package/dist/engine/continuity.d.ts +107 -0
  168. package/dist/engine/continuity.d.ts.map +1 -0
  169. package/dist/engine/continuity.js +320 -0
  170. package/dist/engine/continuity.js.map +1 -0
  171. package/dist/engine/crud.d.ts +62 -0
  172. package/dist/engine/crud.d.ts.map +1 -0
  173. package/dist/engine/crud.js +260 -0
  174. package/dist/engine/crud.js.map +1 -0
  175. package/dist/engine/side-effects.d.ts +93 -0
  176. package/dist/engine/side-effects.d.ts.map +1 -0
  177. package/dist/engine/side-effects.js +271 -0
  178. package/dist/engine/side-effects.js.map +1 -0
  179. package/dist/engine/staging.d.ts +29 -0
  180. package/dist/engine/staging.d.ts.map +1 -0
  181. package/dist/engine/staging.js +159 -0
  182. package/dist/engine/staging.js.map +1 -0
  183. package/dist/engine/working-set.d.ts +18 -0
  184. package/dist/engine/working-set.d.ts.map +1 -0
  185. package/dist/engine/working-set.js +246 -0
  186. package/dist/engine/working-set.js.map +1 -0
  187. package/dist/evals/action-contracts.d.ts +40 -0
  188. package/dist/evals/action-contracts.d.ts.map +1 -0
  189. package/dist/evals/action-contracts.js +208 -0
  190. package/dist/evals/action-contracts.js.map +1 -0
  191. package/dist/evals/brain-bloat.d.ts +39 -0
  192. package/dist/evals/brain-bloat.d.ts.map +1 -0
  193. package/dist/evals/brain-bloat.js +167 -0
  194. package/dist/evals/brain-bloat.js.map +1 -0
  195. package/dist/evals/brain-prescriptions.d.ts +30 -0
  196. package/dist/evals/brain-prescriptions.d.ts.map +1 -0
  197. package/dist/evals/brain-prescriptions.js +148 -0
  198. package/dist/evals/brain-prescriptions.js.map +1 -0
  199. package/dist/evals/cross-layer-duplicates.d.ts +49 -0
  200. package/dist/evals/cross-layer-duplicates.d.ts.map +1 -0
  201. package/dist/evals/cross-layer-duplicates.js +289 -0
  202. package/dist/evals/cross-layer-duplicates.js.map +1 -0
  203. package/dist/evals/entity-visibility.d.ts +28 -0
  204. package/dist/evals/entity-visibility.d.ts.map +1 -0
  205. package/dist/evals/entity-visibility.js +216 -0
  206. package/dist/evals/entity-visibility.js.map +1 -0
  207. package/dist/evals/index.d.ts +19 -0
  208. package/dist/evals/index.d.ts.map +1 -0
  209. package/dist/evals/index.js +11 -0
  210. package/dist/evals/index.js.map +1 -0
  211. package/dist/evals/judge.d.ts +22 -0
  212. package/dist/evals/judge.d.ts.map +1 -0
  213. package/dist/evals/judge.js +337 -0
  214. package/dist/evals/judge.js.map +1 -0
  215. package/dist/evals/operational-contract.d.ts +40 -0
  216. package/dist/evals/operational-contract.d.ts.map +1 -0
  217. package/dist/evals/operational-contract.js +115 -0
  218. package/dist/evals/operational-contract.js.map +1 -0
  219. package/dist/evals/prompt-content.d.ts +14 -0
  220. package/dist/evals/prompt-content.d.ts.map +1 -0
  221. package/dist/evals/prompt-content.js +104 -0
  222. package/dist/evals/prompt-content.js.map +1 -0
  223. package/dist/evals/runtime.d.ts +4 -0
  224. package/dist/evals/runtime.d.ts.map +1 -0
  225. package/dist/evals/runtime.js +197 -0
  226. package/dist/evals/runtime.js.map +1 -0
  227. package/dist/evals/sample-projects.d.ts +143 -0
  228. package/dist/evals/sample-projects.d.ts.map +1 -0
  229. package/dist/evals/sample-projects.js +644 -0
  230. package/dist/evals/sample-projects.js.map +1 -0
  231. package/dist/evals/types.d.ts +88 -0
  232. package/dist/evals/types.d.ts.map +1 -0
  233. package/dist/evals/types.js +2 -0
  234. package/dist/evals/types.js.map +1 -0
  235. package/dist/foundation/index.d.ts +158 -0
  236. package/dist/foundation/index.d.ts.map +1 -0
  237. package/dist/foundation/index.js +256 -0
  238. package/dist/foundation/index.js.map +1 -0
  239. package/dist/index.d.ts +223 -0
  240. package/dist/index.d.ts.map +1 -0
  241. package/dist/index.js +998 -0
  242. package/dist/index.js.map +1 -0
  243. package/dist/managed/autonomous-loop.d.ts +199 -0
  244. package/dist/managed/autonomous-loop.d.ts.map +1 -0
  245. package/dist/managed/autonomous-loop.js +451 -0
  246. package/dist/managed/autonomous-loop.js.map +1 -0
  247. package/dist/managed/conversation.d.ts +20 -0
  248. package/dist/managed/conversation.d.ts.map +1 -0
  249. package/dist/managed/conversation.js +40 -0
  250. package/dist/managed/conversation.js.map +1 -0
  251. package/dist/managed/knowledge.d.ts +7 -0
  252. package/dist/managed/knowledge.d.ts.map +1 -0
  253. package/dist/managed/knowledge.js +174 -0
  254. package/dist/managed/knowledge.js.map +1 -0
  255. package/dist/managed/memory-manager.d.ts +7 -0
  256. package/dist/managed/memory-manager.d.ts.map +1 -0
  257. package/dist/managed/memory-manager.js +18 -0
  258. package/dist/managed/memory-manager.js.map +1 -0
  259. package/dist/managed/memory-review.d.ts +45 -0
  260. package/dist/managed/memory-review.d.ts.map +1 -0
  261. package/dist/managed/memory-review.js +130 -0
  262. package/dist/managed/memory-review.js.map +1 -0
  263. package/dist/managed/storage.d.ts +2 -0
  264. package/dist/managed/storage.d.ts.map +1 -0
  265. package/dist/managed/storage.js +2 -0
  266. package/dist/managed/storage.js.map +1 -0
  267. package/dist/managed/work-history.d.ts +23 -0
  268. package/dist/managed/work-history.d.ts.map +1 -0
  269. package/dist/managed/work-history.js +31 -0
  270. package/dist/managed/work-history.js.map +1 -0
  271. package/dist/observability/index.d.ts +15 -0
  272. package/dist/observability/index.d.ts.map +1 -0
  273. package/dist/observability/index.js +15 -0
  274. package/dist/observability/index.js.map +1 -0
  275. package/dist/observability/render-run-markdown.d.ts +90 -0
  276. package/dist/observability/render-run-markdown.d.ts.map +1 -0
  277. package/dist/observability/render-run-markdown.js +231 -0
  278. package/dist/observability/render-run-markdown.js.map +1 -0
  279. package/dist/observability/turn-reporter.d.ts +20 -0
  280. package/dist/observability/turn-reporter.d.ts.map +1 -0
  281. package/dist/observability/turn-reporter.js +106 -0
  282. package/dist/observability/turn-reporter.js.map +1 -0
  283. package/dist/persona.d.ts +49 -0
  284. package/dist/persona.d.ts.map +1 -0
  285. package/dist/persona.js +287 -0
  286. package/dist/persona.js.map +1 -0
  287. package/dist/playbook/defaults.d.ts +25 -0
  288. package/dist/playbook/defaults.d.ts.map +1 -0
  289. package/dist/playbook/defaults.js +108 -0
  290. package/dist/playbook/defaults.js.map +1 -0
  291. package/dist/playbook/invariants.d.ts +244 -0
  292. package/dist/playbook/invariants.d.ts.map +1 -0
  293. package/dist/playbook/invariants.js +259 -0
  294. package/dist/playbook/invariants.js.map +1 -0
  295. package/dist/playbook/templates.d.ts +7 -0
  296. package/dist/playbook/templates.d.ts.map +1 -0
  297. package/dist/playbook/templates.js +437 -0
  298. package/dist/playbook/templates.js.map +1 -0
  299. package/dist/providers/gemini.d.ts +73 -0
  300. package/dist/providers/gemini.d.ts.map +1 -0
  301. package/dist/providers/gemini.js +536 -0
  302. package/dist/providers/gemini.js.map +1 -0
  303. package/dist/providers/types.d.ts +2 -0
  304. package/dist/providers/types.d.ts.map +1 -0
  305. package/dist/providers/types.js +2 -0
  306. package/dist/providers/types.js.map +1 -0
  307. package/dist/providers/zod-to-gemini.d.ts +8 -0
  308. package/dist/providers/zod-to-gemini.d.ts.map +1 -0
  309. package/dist/providers/zod-to-gemini.js +148 -0
  310. package/dist/providers/zod-to-gemini.js.map +1 -0
  311. package/dist/samples/pm-spec-agent.d.ts +22 -0
  312. package/dist/samples/pm-spec-agent.d.ts.map +1 -0
  313. package/dist/samples/pm-spec-agent.js +53 -0
  314. package/dist/samples/pm-spec-agent.js.map +1 -0
  315. package/dist/types.d.ts +920 -0
  316. package/dist/types.d.ts.map +1 -0
  317. package/dist/types.js +2 -0
  318. package/dist/types.js.map +1 -0
  319. package/package.json +68 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Archetype Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,475 @@
1
+ # Archetype
2
+
3
+ A TypeScript SDK for building AI expert personas — coaches, guides, assistants — that feel human, remember what matters, and act reliably inside real products.
4
+
5
+ Define your persona in ~50 lines of config. Archetype handles prompt assembly, structured actions, memory that compounds over time, and the behavioral guardrails that make AI companions feel natural instead of robotic.
6
+
7
+ ## Philosophy
8
+
9
+ Archetype is built on a single principle: **scenario-first, not directive-first.** The AI persona is the domain expert. Your job is to paint the situation — context, memories, history, constraints — and describe what good looks like. Not to tell the AI what to say, when to act, or how many things to do. Hard rules exist only for mechanical correctness (JSON format, schema compliance). Everything else is a thinking nudge. See [PLAYBOOK_ESSENTIALS.md](PLAYBOOK_ESSENTIALS.md) for the full design philosophy.
10
+
11
+ ## Vision
12
+
13
+ Archetype exists to help build AI experts that create real human value now: a nutritionist, trainer, financial advisor, coach, or personal assistant that feels like a real counterpart, earns trust, and improves lives through an ongoing relationship.
14
+
15
+ The long-term vision is not a boxed chatbot or a manager-worker graph. It is a network of roles where some participants are human and some are AI, collaborating through shared ledgers, channels, memory, and authority.
16
+
17
+ Archetype's bet is that most agent failure comes from poor framing, incomplete world exposure, or missing operating surfaces, not from a lack of rules. Trust the model for judgment. Use the runtime for mechanical enforcement.
18
+
19
+ That means:
20
+
21
+ - let experts think instead of boxing them into scripts
22
+ - model shared truth in ledgers, not only messages
23
+ - represent governance as much as possible through roles and institutions, not centralized orchestration
24
+ - keep a hard firewall for platform invariants like schemas, permissions, commit integrity, and auditability
25
+
26
+ ## Quick Start
27
+
28
+ ```ts
29
+ import { definePersona, withStorage, commitCrud, Gemini } from 'archetype'
30
+ import { z } from 'zod'
31
+
32
+ const engine = definePersona({
33
+ identity: {
34
+ name: 'Chief',
35
+ expertise: ['prioritization', 'follow-through'],
36
+ relationship: 'sharp chief of staff',
37
+ northStar: "the operator's clarity and leverage",
38
+ },
39
+ voice: { tone: 'balanced', style: 'quick', medium: 'desktop-panel' },
40
+ entities: {
41
+ task: {
42
+ schema: z.object({ title: z.string(), due: z.string().optional() }),
43
+ label: 'Task',
44
+ displayField: 'title',
45
+ },
46
+ },
47
+ actions: {}, // named actions are rare — most ops are entity CRUD
48
+ memory: { enabled: true, includeIds: true },
49
+ eq: { frequencyRule: true, autonomyRespect: true },
50
+ provider: Gemini({ model: 'gemini-3-flash-preview' }),
51
+ })
52
+
53
+ const managed = withStorage(engine, {
54
+ adapter: myStorageAdapter, // implements StorageAdapter
55
+ historyLimit: 30,
56
+ memoryBudget: 8000,
57
+ })
58
+
59
+ const result = await managed.chat({
60
+ message: 'Remind me to send the investor update Thursday morning.',
61
+ context: { openTasks },
62
+ userIdentity: 'Alex, CEO',
63
+ timezone: userTimezone, // send from the app/client
64
+ })
65
+
66
+ // result.message — the persona's response
67
+ // result.crudActions — entity create/update/delete (CrudAction[])
68
+ // result.actions — named actions, if any (ParsedAction[])
69
+ // result.outcomeNotes — what changed because of this turn
70
+ // result.followUps — suggested next things the user might say
71
+
72
+ // In managed mode, memory CRUD is SDK-owned.
73
+ // Commit only domain entities through your app handlers.
74
+ const memoryCrudEntities = new Set(['memory', 'craftMemory'])
75
+ const domainCrud = result.crudActions.filter(a => !memoryCrudEntities.has(a.entity))
76
+
77
+ const handlers = {
78
+ task: {
79
+ create: async (id, params) => { await db.tasks.create({ id, ...params }); return { success: true } },
80
+ update: async (id, params) => { await db.tasks.update(id, params); return { success: true } },
81
+ delete: async (id) => { await db.tasks.delete(id); return { success: true } },
82
+ },
83
+ }
84
+ const commitResults = await commitCrud(domainCrud, handlers)
85
+ if (commitResults.some(r => !r.success)) {
86
+ throw new Error('Task commit failed')
87
+ }
88
+ ```
89
+
90
+ For product apps with persistence, this is the default path: `withStorage()` + `managed.chat()` / `managed.promptedTurn()` + `entities` + `commitCrud()`.
91
+
92
+ ## Architecture
93
+
94
+ Archetype is organized in three layers.
95
+
96
+ For most user-facing products, start at Layer 2.
97
+
98
+ ```
99
+ Layer 0 (Core) Pure functions. Zero state, zero I/O.
100
+ Identity, voice, EQ, actions, memory, context → system prompt.
101
+ Testable without any LLM calls.
102
+
103
+ Layer 1 (Engine) Stateless chat. Builds prompt, calls LLM, parses response,
104
+ validates actions with retry/repair, and normalizes output.
105
+ App passes history + context in, gets result out.
106
+
107
+ Layer 2 (Managed) Optional persistence via StorageAdapter.
108
+ Auto-manages conversations, messages, memory extraction,
109
+ daily retrospectives, and working-set staging.
110
+ ```
111
+
112
+ `definePersona()` returns a stateless engine. For product apps, wrap it with `withStorage()` and stay in managed mode. Use Layer 1 directly only when another system already owns persistence and lifecycle.
113
+
114
+ ### Which Layer To Start With
115
+
116
+ - `Layer 2 (managed)`:
117
+ Product apps, chat products, assistants, coaches, guides, tools with persistence, memory, traces, or working-set state.
118
+ - `Layer 1 (stateless)`:
119
+ Advanced or embedded integrations where another control plane already owns history, storage, approvals, and execution.
120
+ - `Layer 0 (core)`:
121
+ Testing prompt assembly or building low-level SDK features.
122
+
123
+ ```ts
124
+ import { definePersona, withStorage, Gemini } from 'archetype'
125
+
126
+ const engine = definePersona({ /* config */ })
127
+
128
+ const managed = withStorage(engine, {
129
+ adapter: myStorageAdapter, // you implement this interface
130
+ historyLimit: 30,
131
+ retrospect: {
132
+ auto: true, // run daily retrospective before first turn
133
+ guidelines: 'Look for repeated patterns and stable preferences.',
134
+ },
135
+ })
136
+
137
+ const result = await managed.chat({
138
+ message: userMessage,
139
+ context: { threads: myData },
140
+ timezone: userTimezone,
141
+ })
142
+ ```
143
+
144
+ ### Smells You Are Rebuilding Layer 2 Locally
145
+
146
+ - manually loading and trimming history before every turn
147
+ - manually saving assistant messages after every turn
148
+ - manually applying memory CRUD in app code
149
+ - custom CRUD dispatch loops instead of `commitCrud()`
150
+ - converting named actions into CRUD after the fact
151
+ - patching model omissions in code instead of improving the scenario or entity contract
152
+
153
+ ### Smells You Are Boxing The Model
154
+
155
+ - adding "do not do X again" prose after a failed operational turn
156
+ - coercing malformed action names into nearby valid ones before checking the prompt
157
+ - hiding actionable objects in prose summaries instead of exposing real IDs
158
+ - duplicating large app-written API docs on top of the SDK contract block
159
+ - blaming the model before reviewing the exact provider-boundary prompt
160
+
161
+ If an operational persona fails, inspect the exact prompt and trace first.
162
+ Most early failures are operating-surface failures, not intelligence failures.
163
+
164
+ ### Inspect The Exact Provider Request
165
+
166
+ When you want to review what the model actually sees at the provider boundary, use the exact request builders instead of reconstructing prompts by hand:
167
+
168
+ - `buildChatLLMRequest(config, input)`
169
+ - `buildPromptedTurnLLMRequest(config, input)`
170
+
171
+ These return the real `systemPrompt`, `history`, `message`, and `responseSchema` that Layer 1 will send to the provider.
172
+
173
+ That matters for three common paths:
174
+
175
+ - full chat: `chat()` -> `buildChatLLMRequest(...)`
176
+ - app-initiated conversation: `promptedTurn({ turnKind: 'proactive-conversation' })` -> `buildPromptedTurnLLMRequest(...)`
177
+ - operational step without a user message: `promptedTurn({ turnKind: 'operational' })` -> `buildPromptedTurnLLMRequest(...)`
178
+
179
+ If you are doing prompt review, eval baselines, or debugging regressions, prefer these helpers over stitched prompt snippets. They keep review aligned with runtime.
180
+
181
+ For the release discipline around prompt changes, see:
182
+
183
+ - [docs/FOUNDATION_PROCESS.md](docs/FOUNDATION_PROCESS.md)
184
+
185
+ To refresh the reviewed keystone prompt fixtures for the three endpoint types, run:
186
+
187
+ - `npm run golden:update`
188
+
189
+ ## Key Concepts
190
+
191
+ ### Entity CRUD (primary pattern)
192
+
193
+ Most domain operations are create/update/delete on entities. Declare entities in your persona config with a Zod schema.
194
+ The model-side contract is: emit entity mutations inside the main `actions` array as `{ "name": "crud", "params": { ... } }`.
195
+ Archetype then validates and normalizes those entity mutations into `result.crudActions` for your app code.
196
+ If raw model output falls back to a legacy top-level `crudActions` key, Archetype still normalizes it for compatibility, but the trace marks that as contract drift.
197
+
198
+ ```ts
199
+ entities: {
200
+ meal: {
201
+ schema: z.object({ name: z.string(), calories: z.number().optional() }),
202
+ label: 'Meal',
203
+ displayField: 'name',
204
+ },
205
+ },
206
+ actions: {}, // empty — named actions are rare
207
+ ```
208
+
209
+ After `chat()`, handle normalized entity changes through `commitCrud`:
210
+
211
+ ```ts
212
+ import { commitCrud } from 'archetype'
213
+
214
+ await commitCrud(result.crudActions, {
215
+ meal: {
216
+ create: async (id, params) => { /* ... */ return { success: true } },
217
+ update: async (id, params) => { /* ... */ return { success: true } },
218
+ delete: async (id) => { /* ... */ return { success: true } },
219
+ },
220
+ })
221
+ ```
222
+
223
+ ### Named Actions (rare — non-entity operations)
224
+
225
+ Named actions exist for the rare operations that don't fit entity CRUD — things like sending an email or triggering an external workflow. Define them with Zod schemas. Archetype validates the LLM's output against the schema, retries once on invalid params, and returns `ParsedAction[]`.
226
+
227
+ ```ts
228
+ actions: {
229
+ sendEmail: {
230
+ description: 'Send an email when the user explicitly asks.',
231
+ schema: z.object({ to: z.string(), subject: z.string(), body: z.string() }),
232
+ confidence: 'low',
233
+ },
234
+ }
235
+ ```
236
+
237
+ Confidence controls the trust model: `low` auto-executes, `medium` follows the approval mode, `high` always proposes for review.
238
+
239
+ For app-initiated operational turns, Archetype renders these as execution semantics instead of human confirmation language. Use `promptedTurn()` for those turns so the persona wakes up into a system rather than pretending a person just asked it something.
240
+
241
+ ## Operational turns
242
+
243
+ Archetype supports two prompt modes:
244
+
245
+ - `conversation`
246
+ - `operational`
247
+
248
+ `chat()` defaults to `conversation`.
249
+ `promptedTurn()` defaults to `operational`.
250
+
251
+ Use `operational` when:
252
+
253
+ - nobody sent a fresh message
254
+ - the role is waking up into ledgers / queue / commitments / world state
255
+ - the role is expected to mutate shared state, not just reply conversationally
256
+
257
+ See [PROMPT_MODES.md](PROMPT_MODES.md) for the full split, launch checklist, and anti-boxing guidance.
258
+
259
+ ### Memory
260
+
261
+ Memory compounds the experience across conversations. The SDK handles:
262
+
263
+ - **Budget-aware loading** — pinned memories first, then recent, respecting a character budget
264
+ - **CRUD-native memory** — memory and craft memory are normal entities, not a parallel side channel
265
+ - **Domain categories** — declare your own taxonomy so the LLM categorizes with domain awareness
266
+ - **Silent retrospection** — periodic reflection pass that creates/updates/deletes memories without user-facing output
267
+ - **Compaction** — LLM-driven dedup of old memories to keep the set sharp
268
+
269
+ ```ts
270
+ memory: {
271
+ enabled: true,
272
+ includeIds: true,
273
+ budget: 8000,
274
+ categories: {
275
+ preference: 'Dietary preferences, food likes/dislikes',
276
+ routine: 'Eating patterns, meal timing',
277
+ health: 'Health conditions, goals, energy patterns',
278
+ },
279
+ purpose: 'The handful of things worth knowing before future conversations.',
280
+ },
281
+ ```
282
+
283
+ ### Working-Set Staging
284
+
285
+ For apps where the AI proposes changes that the user reviews before they take effect.
286
+
287
+ Two layers of mutations:
288
+ - **Meaning layer** — drafts, classifications, internal state. Become current truth immediately.
289
+ - **Transport layer** — external effects (API calls, database writes). Staged for explicit commit.
290
+
291
+ ```ts
292
+ import { reviewWorkingSetDelta } from 'archetype'
293
+
294
+ staging: { model: 'working-set' },
295
+ actions: {
296
+ setDraft: {
297
+ description: 'Set the current reply draft.',
298
+ schema: z.object({ threadId: z.string(), draft: z.string() }),
299
+ layer: 'meaning',
300
+ defaultReviewState: 'accepted',
301
+ commitMode: 'not_required',
302
+ targetKey: (params) => `thread:${params.threadId}:draft`,
303
+ },
304
+ archiveThread: {
305
+ description: 'Stage archiving this thread.',
306
+ schema: z.object({ threadId: z.string() }),
307
+ layer: 'transport',
308
+ defaultReviewState: 'pending',
309
+ commitMode: 'explicit',
310
+ targetKey: (params) => `thread:${params.threadId}:archive`,
311
+ },
312
+ }
313
+ ```
314
+
315
+ Deltas with the same `targetKey` automatically supersede earlier ones — the working set always reflects the latest intent.
316
+
317
+ Use `reviewWorkingSetDelta()` or managed `reviewWorkingSet()` to apply canonical accept/reject transitions before commit instead of hand-editing stored JSON.
318
+
319
+ ### Side Effects
320
+
321
+ After `chat()`, execute entity CRUD through `commitCrud` (the primary pattern):
322
+
323
+ ```ts
324
+ import { commitCrud } from 'archetype'
325
+
326
+ const results = await commitCrud(result.crudActions, {
327
+ task: {
328
+ create: async (id, params) => { await db.tasks.create({ id, ...params }); return { success: true } },
329
+ update: async (id, params) => { await db.tasks.update(id, params); return { success: true } },
330
+ delete: async (id) => { await db.tasks.delete(id); return { success: true } },
331
+ },
332
+ })
333
+ ```
334
+
335
+ For the rare named actions, use `executeSideEffects`:
336
+
337
+ ```ts
338
+ import { executeSideEffects } from 'archetype'
339
+
340
+ const results = await executeSideEffects(result.actions, handlers, persona.config.actions!)
341
+ ```
342
+
343
+ Handlers return `{ success, changed?, error? }`. The `changed` flag distinguishes "ran successfully" from "actually mutated state" — enabling honest outcome reporting to the user.
344
+
345
+ ### App-Initiated Turns
346
+
347
+ Use `promptedTurn()` when your app wants the persona to speak without a user message:
348
+
349
+ ```ts
350
+ const result = await persona.promptedTurn({
351
+ intent: 'Check in at the start of a new day.',
352
+ label: 'Morning greeting',
353
+ context: { todayStatus: '...' },
354
+ memories: loadedMemories,
355
+ guidelines: 'Reference what you know. Be warm, not robotic.',
356
+ })
357
+ ```
358
+
359
+ Good fits: greetings, post-interaction reflections, proactive nudges.
360
+
361
+ Important contract:
362
+
363
+ - `chat()` and `promptedTurn()` differ by who initiated the turn, not by memory semantics
364
+ - in Layer 1, both are stateless and the caller provides history, memories, and context
365
+ - in Layer 2 managed mode, `managed.chat()` and `managed.promptedTurn()` should both get the full memory lifecycle:
366
+ - load history
367
+ - load memories
368
+ - run retrospective/review as configured
369
+ - execute SDK-owned memory CRUD
370
+ - persist traces
371
+
372
+ If an app ends up treating `promptedTurn()` as a lighter or more manual memory path, that is usually contract drift, not the intended design.
373
+
374
+ ### EQ (Emotional Intelligence)
375
+
376
+ Thinking-nudges that help personas feel like experts, not bots:
377
+
378
+ - **Frequency Rule** — trust that the user heard you; find the next layer instead of repeating yourself. But if something is urgent, say it again.
379
+ - **Autonomy Respect** — when the user is processing, help them think rather than jumping to advice. When you see something important they're missing, say it directly.
380
+ - **Qualitative First** — lead with what the data *means*, not the raw numbers. Use numbers naturally when they clarify.
381
+
382
+ These are nudges, not hard rules. The persona is the expert — it uses judgment.
383
+
384
+ ## Provider
385
+
386
+ Archetype ships with a Gemini adapter. The `LLMProvider` interface is pluggable:
387
+
388
+ ```ts
389
+ const myProvider: LLMProvider = {
390
+ name: 'my-provider',
391
+ async chat(request) {
392
+ // request: { systemPrompt, history, message, responseSchema?, temperature?, attachments? }
393
+ const response = await myClient.generate(...)
394
+ return { text: response.text }
395
+ },
396
+ }
397
+ ```
398
+
399
+ ## What Archetype Owns vs. What Your App Owns
400
+
401
+ | Archetype | Your App |
402
+ |-----------|----------|
403
+ | System prompt assembly | Rendering and UI |
404
+ | Action validation + retry | Side-effect execution logic |
405
+ | Memory loading, extraction, review, prompt selection | Domain-specific storage (database, schema) |
406
+ | Working-set state management | Commit triggers and review UI |
407
+ | EQ guardrails | Onboarding and user management |
408
+ | Eval infrastructure | Domain invariants (units, ranges, merge semantics) |
409
+
410
+ For memory specifically, the app-side storage adapter should be a persistence boundary, not a policy engine.
411
+
412
+ Good adapter behavior:
413
+
414
+ - store the memory record faithfully
415
+ - load candidate memories for the requested scope
416
+ - preserve metadata like `pinned`, `source`, `stability`, `contextHint`
417
+
418
+ Bad adapter behavior:
419
+
420
+ - deciding which memories survive the prompt budget
421
+ - flattening or dropping memory metadata
422
+ - rewriting memories into app-specific shapes before Archetype sees them
423
+ - executing memory policy in app code because the SDK path was bypassed
424
+
425
+ In other words:
426
+
427
+ - the adapter should be able to do "store this memory", "update this memory", "load candidate memories"
428
+ - Archetype should decide how those memories are used
429
+
430
+ That split is intentional. Archetype handles the AI orchestration so you can focus on your domain.
431
+
432
+ ## Documentation
433
+
434
+ | Doc | What it covers |
435
+ |-----|----------------|
436
+ | [POSITIONING.md](POSITIONING.md) | What Archetype is, what it is not, and how it differs from orchestration-first or memory-first frameworks |
437
+ | [PRODUCT_APP_START_HERE.md](PRODUCT_APP_START_HERE.md) | The shortest clean default for real product apps using Layer 2 |
438
+ | [AI_PERSONA_PLAYBOOK.md](AI_PERSONA_PLAYBOOK.md) | Why good personas work, and what usually makes them feel robotic |
439
+ | [CLAUDE.md](CLAUDE.md) | SDK architecture, module structure, commands, and implementation patterns |
440
+ | [EVALS.md](EVALS.md) | Eval philosophy, sample personas, and the stress-testing harness |
441
+ | [ACTION_CONTRACTS.md](ACTION_CONTRACTS.md) | How to design action shapes that models follow reliably |
442
+ | [WORKING_SET.md](WORKING_SET.md) | When to use working-set staging vs. legacy batch proposals |
443
+ | [NEXT_RUNTIME_PRIMITIVES.md](NEXT_RUNTIME_PRIMITIVES.md) | The likely next 80/20 runtime additions after strong single-role chat |
444
+ | [ECOSYSTEM_SHORTLIST_2026-04.md](ECOSYSTEM_SHORTLIST_2026-04.md) | Dated external ecosystem shortlist: what to adopt, align with, watch, or avoid as core |
445
+ | [REFERENCE_APP.md](REFERENCE_APP.md) | The practical integration pattern for production apps |
446
+ | [BOUNDARY_NORMALIZATION.md](BOUNDARY_NORMALIZATION.md) | What validation should stay app-owned after the model responds |
447
+ | [ROLE_LEDGER_CHANNEL_ARCHITECTURE.md](ROLE_LEDGER_CHANNEL_ARCHITECTURE.md) | The longer-term architecture direction: roles, ledgers, channels, and firewalls |
448
+ | [PERSONA_NETWORK_ARCHITECTURE.md](PERSONA_NETWORK_ARCHITECTURE.md) | The narrower path from one expert role to peer consultation to multi-role systems |
449
+
450
+ ## Examples
451
+
452
+ | Example | What it demonstrates |
453
+ |---------|---------------------|
454
+ | [coach](examples/coach/index.ts) | Executive coaching with memory and thread context |
455
+ | [nutrition](examples/nutrition/index.ts) | Nutrition guide with meal context and preferences |
456
+ | [fitness](examples/fitness/index.ts) | Strength coaching with exercise schemas |
457
+ | [language-tutor](examples/language-tutor/index.ts) | Language learning with correction style |
458
+ | [chief-of-staff](examples/chief-of-staff/index.ts) | Task management with entity CRUD |
459
+ | [working-set-assistant](examples/working-set-assistant/index.ts) | Email triage with meaning/transport staging |
460
+ | [working-set-nutrition](examples/working-set-nutrition/index.ts) | Meal planning with conversational drafts |
461
+ | [nutrition-guide](examples/nutrition-guide/server.ts) | Managed-mode reference app with knowledge and domain CRUD |
462
+ | [coder-agent](examples/coder-agent/README.md) | Focus-mode builder persona using Archetype's shared builder actions |
463
+ | [pm-spec-agent](examples/pm-spec-agent/README.md) | Focus-mode product manager that writes implementation specs to files |
464
+ | [paperclip-archetype-service](examples/paperclip-archetype-service/README.md) | Local HTTP service integration with Paperclip-owned orchestration |
465
+ | [reference-app](examples/reference-app/README.md) | Full integration walkthrough |
466
+
467
+ ## Commands
468
+
469
+ ```bash
470
+ npm test # run vitest (mock providers, no API calls)
471
+ npm run test:live # live persona + Turing evals (requires GEMINI_API_KEY)
472
+ npm run build # TypeScript build → dist/
473
+ npm run lint # type-check (tsc --noEmit)
474
+ npm run audit:examples # build + audit all shipped example personas
475
+ ```
@@ -0,0 +1,163 @@
1
+ /**
2
+ * auditPersona — unified audit entry point.
3
+ *
4
+ * Composes every audit Archetype knows about, applied to one persona,
5
+ * producing one report. Replaces the per-persona audit-v3.ts pattern where
6
+ * each project hand-composes a subset of audits and silently lags whenever
7
+ * a new audit lands.
8
+ *
9
+ * Default debugging loop (documented in EVALS.md):
10
+ * 1. auditPersona({ config, ... }) ← this function. Runs everything
11
+ * applicable to the input you provide. Start here.
12
+ * 2. If findings are unclear, dumpPromptForReview({ config, ... }) to
13
+ * eyeball the exact assembled prompt.
14
+ * 3. If runtime traces look wrong, auditTraceIntegrity(trace) to confirm
15
+ * the pipeline isn't silently dropping or repairing anything.
16
+ *
17
+ * Scope gating:
18
+ * - 'static' — audits that only need the config. Always safe to run.
19
+ * - 'static-plus-scenario' — adds audits that need a representative
20
+ * context + memories. Skipped cleanly if those inputs aren't provided.
21
+ * - 'full' — adds LLM meta-judges (auditPrompt, auditByBrainReflection).
22
+ * Requires apiKey.
23
+ */
24
+ import type { PersonaConfig, Memory, PromptMode, LoadedBrainArtifact } from '../types.js';
25
+ import type { BrainBloatAuditResult, BrainPrescriptionsAuditResult, CrossLayerAuditResult, ActionContractAuditResult, EntityVisibilityResult, PromptContentAuditResult } from '../evals/index.js';
26
+ import type { PromptAuditResult } from './types.js';
27
+ import type { BrainReflectionResult } from './brain-reflection.js';
28
+ export type AuditScope = 'static' | 'static-plus-scenario' | 'full';
29
+ export type AuditSeverity = 'error' | 'warn' | 'info';
30
+ /**
31
+ * A unified finding shape every audit flattens into. Lets callers iterate
32
+ * issues across audits, sort by severity, filter by audit name, without
33
+ * having to know each audit's native result shape. The native results are
34
+ * still available via `raw` for deep inspection.
35
+ */
36
+ export interface AuditFinding {
37
+ severity: AuditSeverity;
38
+ /** Which audit produced this finding (e.g., 'brain-bloat'). */
39
+ audit: string;
40
+ /** Name of the failure mode inside that audit (e.g., 'section-size'). */
41
+ principle: string;
42
+ /** Human-readable issue. */
43
+ message: string;
44
+ /** Concrete suggestion (when the audit offers one). */
45
+ suggestion?: string;
46
+ /** The offending text when applicable. */
47
+ text?: string;
48
+ /** Location in the config/brain/prompt when applicable. */
49
+ location?: string;
50
+ }
51
+ export interface AuditPersonaInput {
52
+ config: PersonaConfig;
53
+ /**
54
+ * Optional representative context the app passes to chat(). Unlocks
55
+ * scenario-shaped audits (entity-visibility, prompt-content, invariants-
56
+ * present). Without it those audits skip with an explanation.
57
+ */
58
+ context?: Record<string, unknown>;
59
+ /** Optional memories the persona would receive at chat time. */
60
+ memories?: Memory[];
61
+ /** Optional craft memories for personas using the craftMemory entity. */
62
+ craftMemories?: Memory[];
63
+ /** Optional brain markdown or loaded brain. Unlocks brain-* audits. */
64
+ brain?: LoadedBrainArtifact | string;
65
+ /**
66
+ * Optional source path for brain (only used for diagnostics on
67
+ * brain-bloat findings).
68
+ */
69
+ brainSourcePath?: string;
70
+ /** API key for LLM judges. Required for scope: 'full'. */
71
+ apiKey?: string;
72
+ /** Which prompt mode to assemble for scenario-shaped audits. */
73
+ promptMode?: PromptMode;
74
+ /** Filter the scope. Default 'static-plus-scenario'. */
75
+ scope?: AuditScope;
76
+ /** Optional primary Gemini model for LLM judges. */
77
+ model?: string;
78
+ /** Optional fallback chain for LLM judges. */
79
+ fallbackModels?: string[];
80
+ }
81
+ export interface AuditPersonaResult {
82
+ /** True when zero `error`-severity findings across all audits that ran. */
83
+ pass: boolean;
84
+ /** All findings across all audits, unified shape, sorted by severity. */
85
+ findings: AuditFinding[];
86
+ /** Which audits actually ran. */
87
+ auditsRun: string[];
88
+ /**
89
+ * Audits that didn't run and why (e.g., "entity-visibility: no context
90
+ * provided"). Helps callers expand their inputs to get more coverage.
91
+ */
92
+ auditsSkipped: Array<{
93
+ audit: string;
94
+ reason: string;
95
+ }>;
96
+ /** One-line human-readable summary. */
97
+ summary: string;
98
+ /**
99
+ * Native per-audit results for callers that want deep structured access.
100
+ * Audits that didn't run are absent from this object.
101
+ */
102
+ raw: {
103
+ brainBloat?: BrainBloatAuditResult;
104
+ brainPrescriptions?: BrainPrescriptionsAuditResult;
105
+ crossLayerDuplicates?: CrossLayerAuditResult;
106
+ actionContracts?: ActionContractAuditResult;
107
+ entityVisibility?: EntityVisibilityResult;
108
+ promptContent?: PromptContentAuditResult;
109
+ loadBearingInvariants?: LoadBearingInvariantsResult;
110
+ contextInputIntents?: ContextInputIntentAuditResult;
111
+ prompt?: PromptAuditResult;
112
+ brainReflection?: BrainReflectionResult;
113
+ };
114
+ }
115
+ /**
116
+ * Load-bearing invariants presence check. A static audit that asserts
117
+ * the prompt this persona actually assembles contains each invariant's
118
+ * text. If a refactor (intentional or accidental) drops an invariant
119
+ * from the assembled prompt, this surfaces it at audit time.
120
+ *
121
+ * This is new — promoted from tests/load-bearing-invariants.test.ts so
122
+ * it catches issues in user personas too, not just the foundation config.
123
+ */
124
+ export interface LoadBearingInvariantsResult {
125
+ pass: boolean;
126
+ missing: Array<{
127
+ id: string;
128
+ constant: string;
129
+ sourceSection: string;
130
+ }>;
131
+ }
132
+ export interface ContextInputIntentAuditResult {
133
+ pass: boolean;
134
+ missing: Array<{
135
+ key: string;
136
+ label: string;
137
+ }>;
138
+ }
139
+ export declare function auditPersona(input: AuditPersonaInput): Promise<AuditPersonaResult>;
140
+ export interface FormatAuditReportOptions {
141
+ /** Title shown at the top (e.g., "Savor structural audit"). */
142
+ title?: string;
143
+ /** Char limit before truncating `text` / `suggestion` lines. Default 160. */
144
+ maxTextChars?: number;
145
+ /** Include findings with severity 'info'. Default true. */
146
+ includeInfo?: boolean;
147
+ }
148
+ /**
149
+ * Render an AuditPersonaResult as a human-readable multi-line string.
150
+ * Use `printAuditReport` for the common "log + set exit code" path.
151
+ */
152
+ export declare function formatAuditReport(result: AuditPersonaResult, options?: FormatAuditReportOptions): string;
153
+ export interface PrintAuditReportOptions extends FormatAuditReportOptions {
154
+ /** Call process.exit with 0 (pass) or 1 (fail). Default false. */
155
+ exitOnFail?: boolean;
156
+ }
157
+ /**
158
+ * Print the formatted report to stdout. When `exitOnFail` is true, sets
159
+ * the process exit code based on `result.pass`. Returns the formatted
160
+ * string for callers that also want to persist it.
161
+ */
162
+ export declare function printAuditReport(result: AuditPersonaResult, options?: PrintAuditReportOptions): string;
163
+ //# sourceMappingURL=audit-persona.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-persona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