sonamu 0.10.7 → 0.10.9

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 (79) hide show
  1. package/dist/api/decorators.d.ts.map +1 -1
  2. package/dist/api/decorators.js +5 -12
  3. package/dist/bin/cli.js +10 -253
  4. package/dist/database/base-model.d.ts +1 -0
  5. package/dist/database/base-model.d.ts.map +1 -1
  6. package/dist/database/base-model.js +14 -8
  7. package/dist/database/db.d.ts +2 -1
  8. package/dist/database/db.d.ts.map +1 -1
  9. package/dist/database/db.js +13 -3
  10. package/dist/database/puri-wrapper.d.ts.map +1 -1
  11. package/dist/database/puri-wrapper.js +4 -11
  12. package/dist/database/transaction-context.d.ts +8 -3
  13. package/dist/database/transaction-context.d.ts.map +1 -1
  14. package/dist/database/transaction-context.js +12 -7
  15. package/dist/migration/code-generation.js +2 -2
  16. package/dist/naite/naite-reporter.d.ts +8 -3
  17. package/dist/naite/naite-reporter.d.ts.map +1 -1
  18. package/dist/naite/naite-reporter.js +9 -4
  19. package/dist/ui-web/assets/{index-D0MHYbxl.js → index-CJf8uJYf.js} +47 -41
  20. package/dist/ui-web/assets/index-GMMIVGja.css +1 -0
  21. package/dist/ui-web/index.html +2 -2
  22. package/package.json +3 -3
  23. package/src/api/decorators.ts +11 -22
  24. package/src/bin/cli.ts +12 -375
  25. package/src/database/__tests__/transaction-scope.test.ts +227 -0
  26. package/src/database/base-model.ts +31 -6
  27. package/src/database/db.ts +17 -2
  28. package/src/database/puri-wrapper.ts +5 -22
  29. package/src/database/transaction-context.ts +14 -6
  30. package/src/migration/code-generation.ts +1 -1
  31. package/src/naite/naite-reporter.ts +8 -3
  32. package/dist/ui-web/assets/index-Dx_JX4aQ.css +0 -1
  33. package/src/skills/AGENTS.md +0 -108
  34. package/src/skills/sonamu/SKILL.md +0 -75
  35. package/src/skills/sonamu-ai-agents/SKILL.md +0 -205
  36. package/src/skills/sonamu-api/SKILL.md +0 -480
  37. package/src/skills/sonamu-auth/SKILL.md +0 -327
  38. package/src/skills/sonamu-auth/references/plugins.md +0 -310
  39. package/src/skills/sonamu-auth/references/user-id-migration-followups.md +0 -192
  40. package/src/skills/sonamu-auth/references/user-id-migration.md +0 -455
  41. package/src/skills/sonamu-config/SKILL.md +0 -203
  42. package/src/skills/sonamu-config/references/database.md +0 -452
  43. package/src/skills/sonamu-config/references/environments.md +0 -178
  44. package/src/skills/sonamu-config/references/server-options.md +0 -400
  45. package/src/skills/sonamu-entity/SKILL.md +0 -180
  46. package/src/skills/sonamu-entity/references/creation-workflow.md +0 -581
  47. package/src/skills/sonamu-entity/references/design-guides.md +0 -243
  48. package/src/skills/sonamu-entity/references/field-types.md +0 -170
  49. package/src/skills/sonamu-entity/references/relations-detail.md +0 -245
  50. package/src/skills/sonamu-entity/references/relations.md +0 -463
  51. package/src/skills/sonamu-entity/references/subset.md +0 -156
  52. package/src/skills/sonamu-fixture/SKILL.md +0 -180
  53. package/src/skills/sonamu-fixture/references/cli-usage.md +0 -439
  54. package/src/skills/sonamu-fixture/references/cone.md +0 -298
  55. package/src/skills/sonamu-frontend/SKILL.md +0 -142
  56. package/src/skills/sonamu-frontend/references/components.md +0 -323
  57. package/src/skills/sonamu-frontend/references/examples.md +0 -64
  58. package/src/skills/sonamu-frontend/references/hooks.md +0 -273
  59. package/src/skills/sonamu-frontend/references/runtime.md +0 -165
  60. package/src/skills/sonamu-frontend/references/scaffolding.md +0 -439
  61. package/src/skills/sonamu-i18n/SKILL.md +0 -287
  62. package/src/skills/sonamu-migration/SKILL.md +0 -316
  63. package/src/skills/sonamu-naite/SKILL.md +0 -266
  64. package/src/skills/sonamu-query/SKILL.md +0 -48
  65. package/src/skills/sonamu-query/references/model-patterns.md +0 -390
  66. package/src/skills/sonamu-query/references/model.md +0 -366
  67. package/src/skills/sonamu-query/references/puri.md +0 -413
  68. package/src/skills/sonamu-query/references/search.md +0 -238
  69. package/src/skills/sonamu-query/references/upsert.md +0 -324
  70. package/src/skills/sonamu-tasks/SKILL.md +0 -236
  71. package/src/skills/sonamu-testing/SKILL.md +0 -251
  72. package/src/skills/sonamu-testing/references/devrunner.md +0 -405
  73. package/src/skills/sonamu-testing/references/helpers.md +0 -185
  74. package/src/skills/sonamu-testing/references/patterns.md +0 -263
  75. package/src/skills/sonamu-testing/references/pitfalls.md +0 -588
  76. package/src/skills/sonamu-testing/references/quick-start.md +0 -285
  77. package/src/skills/sonamu-testing/references/type-safety.md +0 -172
  78. package/src/skills/sonamu-testing/references/writing-plan.md +0 -375
  79. package/src/skills/sonamu-vector/SKILL.md +0 -222
@@ -1,108 +0,0 @@
1
- # Guide for Coding Agents - modules/sonamu/src/skills
2
-
3
- Inherits rules from:
4
-
5
- - `../../../../AGENTS.md`
6
- - `../../AGENTS.md`
7
-
8
- ## Directory role
9
-
10
- Source of truth for the Sonamu skills that `sonamu skills sync` installs into user projects.
11
-
12
- ```
13
- skills/
14
- ├── sonamu/ root skill — routing table + cross-cutting conventions
15
- └── sonamu-<name>/ each directory is one agent skill
16
- ├── SKILL.md entry point (target ≤ 12KB, hard limit 20KB)
17
- └── references/*.md detail, loaded only when needed (hard limit 20KB)
18
- ```
19
-
20
- Size limits are enforced by `scripts/check-skill-size.ts`, wired into root `pnpm check`.
21
- They are derived from measured Expo (max 19.1KB) and Vercel (max 17.3KB) skill sizes.
22
-
23
- ## Skill boundary rule
24
-
25
- A document belongs in a skill only if it has a **discrete trigger moment** — a point where an
26
- agent can decide "now I need this". Content that applies to every turn (type-safety policy,
27
- lint gates, universal conventions) is horizontal and belongs in the root `sonamu` skill
28
- instead, because no specific skill will surface it at the right moment.
29
-
30
- Split criteria when adding or reorganizing:
31
-
32
- 1. Documents read together in one task belong in one skill.
33
- 2. Each skill's `description` must state its trigger moment, distinctly from every other skill.
34
- 3. Prefer small duplication over cross-skill references. Skills load independently, so pointing
35
- from one skill to another forces both into context.
36
-
37
- ## Description format
38
-
39
- Every `description` is one line in three parts, matching what Expo and Vercel ship:
40
-
41
- ```
42
- <What it does>. Use when <discrete trigger moments>. Covers <concrete symbols and commands>.
43
- ```
44
-
45
- - **What** — third-person verb, no "This skill…". "Generates and applies Sonamu database
46
- migrations."
47
- - **Use when** — the moments an agent can recognise. Name failures too, not just intentions:
48
- "a migration fails or conflicts" catches cases "modifying a schema" misses. Never restate the
49
- skill name — "Use when implementing internationalization" tells an agent nothing.
50
- - **Covers** — concrete identifiers an agent is likely to have in context: commands, decorators,
51
- function names, error strings. This is matching surface, so prefer `executeSubsetQuery` and
52
- `pg_trgm` over "query helpers".
53
-
54
- Keep it under ~400 characters. A well-formed trigger is necessary but not sufficient: Vercel
55
- measured a correctly written description that still went uninvoked in 56% of cases because its
56
- trigger was horizontal ("when writing or reviewing React code" applies to every turn). Write
57
- triggers that name a discrete moment.
58
-
59
- `pnpm skills:index` parses this shape — it takes the `Use when` sentence and drops `Covers`.
60
-
61
- ## Skill index
62
-
63
- The root `sonamu` skill carries a generated routing table. It exists because each skill's
64
- `description` only fires at its own trigger moment — work that matches none of them gets no
65
- skill at all, and the root skill's broad description catches that case.
66
-
67
- Never hand-edit the region between `<!-- SKILL-INDEX:START -->` and `<!-- SKILL-INDEX:END -->`:
68
-
69
- ```bash
70
- pnpm skills:index
71
- ```
72
-
73
- `pnpm check` fails when the index is stale.
74
-
75
- Users who want the table always in context can run `sonamu skills index`, which writes it into
76
- their project's `AGENTS.md` inside `<!-- SONAMU:START -->` markers. That edits a file the user
77
- owns, so it is never part of `skills sync` — it only runs when invoked explicitly.
78
-
79
- ## Contributing a troubleshooting resolution
80
-
81
- Only for maintainers of this repository. Skills shipped to user projects describe how to *use*
82
- Sonamu — never how to contribute to it, and never anything specific to one company or client
83
- project.
84
-
85
- Suggest capturing a resolution when all of these hold:
86
-
87
- 1. The session went error → investigation → fix → success.
88
- 2. The fix revealed internal framework behavior or an undocumented constraint.
89
- 3. The same problem is likely to hit other projects.
90
-
91
- Skip typos, missing imports, project-specific business logic bugs, and one-off environment
92
- issues.
93
-
94
- Then, before writing anything:
95
-
96
- 1. Find the skill whose trigger moment matches, and read it. Appending to an existing skill is
97
- the normal outcome; a new skill is rare and needs a distinct trigger moment of its own.
98
- 2. Check that the content is not already covered. Duplicates are the common failure here.
99
- 3. Put horizontal rules in the root `sonamu` skill, not in a task skill.
100
- 4. Get user confirmation before applying.
101
-
102
- Project-specific notes belong in that project's own skill directory
103
- (`.agents/skills/<name>/SKILL.md`), written by hand — never in this directory.
104
-
105
- ## Cross-workspace gate
106
-
107
- - For changes in this scope, root `pnpm check` (oxlint + oxfmt + skill size + skill index) must
108
- pass before handoff.
@@ -1,75 +0,0 @@
1
- ---
2
- name: sonamu
3
- description: Routes Sonamu work to the right skill and carries the conventions that apply to every change. Use when starting work in a Sonamu project, or when no specific Sonamu skill obviously covers the problem. Covers the skill index, TypeScript type-safety rules, the tsc and pnpm check gate, and the packages/api command path.
4
- ---
5
-
6
- # Sonamu
7
-
8
- Sonamu is a TypeScript full-stack framework. Work is split across focused skills — find yours
9
- below and invoke it rather than working from memory.
10
-
11
- ## Skill index
12
-
13
- <!-- SKILL-INDEX:START -->
14
-
15
- | Situation | Skill |
16
- | --- | --- |
17
- | implementing an agent class, defining its tools, or managing per-request agent state | `sonamu-ai-agents` |
18
- | adding or changing an API endpoint, choosing httpMethod/guards/clients options, or implementing a file upload | `sonamu-api` |
19
- | running auth generate, applying Guards to an endpoint, reading the session from Context, adding an auth plugin, or migrating User.id to a string primary key | `sonamu-auth` |
20
- | editing .env or sonamu.config.ts, adjusting auth, guards, storage, cache, or logging options, starting the Docker database, or resolving a port conflict | `sonamu-config` |
21
- | creating or editing an entity.json, adding a field or enum, wiring BelongsToOne/HasMany/ManyToMany/parentId, defining a subset, or resolving a schema validation or sync error | `sonamu-entity` |
22
- | running fixture gen/fetch/explore, writing cone.note metadata for LLM generation, syncing between the development, test, and fixture databases, or when a fixture fails on a foreign key or unique constraint | `sonamu-fixture` |
23
- | calling a generated Service, wiring a TanStack Query hook, building a form or list view, or when a scaffolded view fails to compile | `sonamu-frontend` |
24
- | registering labels for a new entity or enum, adding a language, or a UI string renders as a raw key | `sonamu-i18n` |
25
- | a schema change needs a migration, a migration fails or conflicts, FK ordering breaks an apply, or a primary key type must change | `sonamu-migration` |
26
- | a query or save produces the wrong result and the cause is unclear, or when a test needs to assert on internal state | `sonamu-naite` |
27
- | implementing a Model CRUD method, writing a SELECT/WHERE/JOIN query, batch-saving relation data, or when a query returns unexpected rows or an excessively deep type error | `sonamu-query` |
28
- | implementing a background job, scheduling recurring work, or building a multi-step process that must survive a restart | `sonamu-tasks` |
29
- | authoring a Model or API test, asserting on query behaviour, mocking a dependency, or when sonamu test fails to run | `sonamu-testing` |
30
- | generating embeddings, chunking documents, or combining vector similarity with full-text search | `sonamu-vector` |
31
-
32
- <!-- SKILL-INDEX:END -->
33
-
34
- Nothing matched? The problem is probably not Sonamu-specific — proceed normally.
35
-
36
- ---
37
-
38
- ## Conventions that apply to every change
39
-
40
- These are not tied to one task, so no skill will surface them at the right moment. Copy them
41
- into your project's own `AGENTS.md` if you want them enforced on every turn.
42
-
43
- ### TypeScript type safety
44
-
45
- - `as any` and `as unknown as T` are strictly prohibited.
46
- - Resolve type errors through correct type annotations, generic constraints, type narrowing, or
47
- interface extension.
48
- - Do not use `as any` to work around "excessively deep" or similar TypeScript inference limits —
49
- find the correct access pattern instead (e.g. use `getPuri("r")` directly rather than casting
50
- the result).
51
- - Chaining methods after `as any` bypasses all TypeScript signature checks and leads directly to
52
- runtime bugs.
53
- - Non-null assertion (`!`) is prohibited. Use optional chaining (`?.`) or type guard filters
54
- instead.
55
-
56
- ### Code quality gate
57
-
58
- After editing any `.ts` or `.tsx` file, run both before considering the task done:
59
-
60
- 1. `npx tsc --noEmit --skipLibCheck` — type errors
61
- 2. `pnpm check` — lint and format (oxlint + oxfmt)
62
-
63
- Do not skip lint/format even when tsc passes. oxlint catches `noNonNullAssertion`, import order,
64
- and other issues that tsc does not.
65
-
66
- ### Command execution path
67
-
68
- All `pnpm` commands are run from the **`packages/api`** directory.
69
-
70
- ```bash
71
- cd packages/api
72
- pnpm dev
73
- pnpm sonamu test
74
- pnpm sonamu migrate run
75
- ```
@@ -1,205 +0,0 @@
1
- ---
2
- name: sonamu-ai-agents
3
- description: Builds tool-using AI agents on Sonamu. Use when implementing an agent class, defining its tools, or managing per-request agent state. Covers BaseAgentClass, the @tools decorator, ToolLoopAgent, and AsyncLocalStorage state.
4
- ---
5
-
6
- # AI Agent Guide
7
-
8
- Sonamu provides a framework that wraps Vercel AI SDK's `ToolLoopAgent` to build class-based AI Agents.
9
-
10
- **Source code:** `modules/sonamu/src/ai/agents/`
11
-
12
- ---
13
-
14
- ## Structure
15
-
16
- | File | Role |
17
- | ---------- | ----------------------------------------------------------------------- |
18
- | `agent.ts` | `BaseAgentClass`, `tools` decorator |
19
- | `types.ts` | `AgentConfig`, `ToolDecoratorOptions`, `RegisteredToolDefinition`, etc. |
20
-
21
- ---
22
-
23
- ## BaseAgentClass
24
-
25
- The base class for Agents. Extend it to create a custom Agent.
26
-
27
- ```typescript
28
- import { BaseAgentClass, tools } from "sonamu/ai/agents";
29
- import { z } from "zod/v4";
30
-
31
- class MyAgentClass extends BaseAgentClass<{ count: number }> {
32
- constructor() {
33
- super("MyAgent"); // agentName (used as logger category)
34
- }
35
-
36
- @tools({
37
- description: "Adds two numbers",
38
- schema: {
39
- input: z.object({ a: z.number(), b: z.number() }),
40
- output: z.object({ result: z.number() }),
41
- },
42
- })
43
- async add(input: { a: number; b: number }) {
44
- return { result: input.a + input.b };
45
- }
46
- }
47
-
48
- export const MyAgent = new MyAgentClass();
49
- ```
50
-
51
- ### Key Features
52
-
53
- | Feature | Description |
54
- | ------------- | ------------------------------------------- |
55
- | `this.logger` | LogTape logger (agent category) |
56
- | `this.store` | AsyncLocalStorage-based state access |
57
- | `this.tools` | Registered toolset (ToolSet) |
58
- | `this.use()` | Run the Agent (ALS context + ToolLoopAgent) |
59
-
60
- ---
61
-
62
- ## @tools Decorator
63
-
64
- Registers a method as an AI tool. Define input/output using Zod v4 schema.
65
-
66
- ```typescript
67
- @tools({
68
- name?: string, // Tool name (default: "className.methodName" format)
69
- description?: string, // Description shown to the LLM
70
- schema: {
71
- input: z.ZodType, // Input schema (required)
72
- output?: z.ZodType, // Output schema (optional)
73
- },
74
- needsApproval?: boolean | function, // Whether user approval is required
75
- toModelOutput?: function, // Transform output returned to the model
76
- providerOptions?: ProviderOptions, // Provider-specific options
77
- })
78
- ```
79
-
80
- ### Automatic Name Generation Rule
81
-
82
- If `name` is omitted, it is auto-generated as `{ModelName(camelCase)}.{methodName(camelCase)}`.
83
-
84
- ```typescript
85
- class SearchAgentClass extends BaseAgentClass<...> {
86
- @tools({ ... })
87
- async findDocuments(input: ...) { ... }
88
- // → Tool name: "searchAgent.findDocuments"
89
- }
90
- ```
91
-
92
- The suffixes `Class`, `Model`, and `Frame` are automatically stripped from the class name.
93
-
94
- ---
95
-
96
- ## Running an Agent (use)
97
-
98
- Run the Agent with the `use()` method. ToolLoopAgent operates within the AsyncLocalStorage context.
99
-
100
- ```typescript
101
- import { anthropic } from "@ai-sdk/anthropic";
102
-
103
- const result = await MyAgent.use(
104
- // AgentConfig
105
- {
106
- model: anthropic("claude-sonnet-4-6"),
107
- instructions: "You are a math assistant.",
108
- toolChoice: "auto", // "auto" | "none" | "required"
109
- maxOutputTokens: 1000,
110
- temperature: 0.7,
111
- },
112
- // Initial state (stored in AsyncLocalStorage)
113
- { count: 0 },
114
- // Callback (receives Agent instance)
115
- async (agent) => {
116
- // agent is a ToolLoopAgent instance
117
- // Use Vercel AI SDK's agent API
118
- return agent;
119
- },
120
- );
121
- ```
122
-
123
- ### AgentConfig Options
124
-
125
- | Option | Type | Description |
126
- | -------------------------------------- | -------------------------------- | ------------------------------------ |
127
- | `model` | `LanguageModel` | AI SDK model (required) |
128
- | `instructions` | `string` | System prompt |
129
- | `toolChoice` | `"auto" \| "none" \| "required"` | Tool selection strategy |
130
- | `stopWhen` | `StopCondition` | Stop condition |
131
- | `activeTools` | `string[]` | List of tool names to activate |
132
- | `maxOutputTokens` | `number` | Maximum output tokens |
133
- | `temperature` | `number` | Temperature |
134
- | `topP` / `topK` | `number` | Sampling parameters |
135
- | `presencePenalty` / `frequencyPenalty` | `number` | Penalties |
136
- | `seed` | `number` | Seed for reproducibility |
137
- | `stopSequences` | `string[]` | Generation stop sequences |
138
- | `providerOptions` | `ProviderOptions` | Additional provider-specific options |
139
- | `headers` | `Record<string, string>` | Custom HTTP headers |
140
-
141
- ---
142
-
143
- ## State Management (AsyncLocalStorage)
144
-
145
- `BaseAgentClass` defines the state type with the generic `TStore`. When you pass the initial state to `use()`, it can be accessed via `this.store` during tool execution.
146
-
147
- ```typescript
148
- class StatefulAgentClass extends BaseAgentClass<{ processedItems: string[] }> {
149
- @tools({ ... })
150
- async processItem(input: { item: string }) {
151
- // Access state
152
- this.store?.processedItems.push(input.item);
153
- return { ok: true };
154
- }
155
- }
156
- ```
157
-
158
- **Note:** `this.store` is `undefined` outside of a `use()` context.
159
-
160
- ---
161
-
162
- ## Tool Isolation
163
-
164
- Tools for each Agent class are isolated per class. The `toolSet` getter filters by `def.from === this.constructor.name`.
165
-
166
- ```typescript
167
- class AgentA extends BaseAgentClass<void> {
168
- @tools({ ... }) async toolX() { ... }
169
- }
170
- class AgentB extends BaseAgentClass<void> {
171
- @tools({ ... }) async toolY() { ... }
172
- }
173
-
174
- // AgentA.tools → { contains only toolX }
175
- // AgentB.tools → { contains only toolY }
176
- ```
177
-
178
- ---
179
-
180
- ## Logging
181
-
182
- `this.logger` uses LogTape. The category is generated with `convertDomainToCategory(agentName, "agent")`.
183
-
184
- Debug logs are automatically recorded on tool execution:
185
-
186
- ```
187
- tools: {model}.{method} with args: {args}
188
- ```
189
-
190
- ---
191
-
192
- ## Related Packages
193
-
194
- - `ai`: Vercel AI SDK (`ToolLoopAgent`, `Agent`, `ToolSet`)
195
- - `@ai-sdk/provider-utils`: `tool()`, `Tool`, `ToolExecutionOptions`
196
- - `zod/v4`: Schema definitions
197
- - `@logtape/logtape`: Logging
198
-
199
- ---
200
-
201
- ## References
202
-
203
- - **Source code**: `modules/sonamu/src/ai/agents/`
204
- - **Vercel AI SDK**: https://sdk.vercel.ai/docs
205
- - **Vector search**: `sonamu-vector`