@clawnet/template-minimal 0.0.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 (67) hide show
  1. package/.agents/skills/claude-agent-sdk/.claude-plugin/plugin.json +13 -0
  2. package/.agents/skills/claude-agent-sdk/SKILL.md +954 -0
  3. package/.agents/skills/claude-agent-sdk/references/mcp-servers-guide.md +387 -0
  4. package/.agents/skills/claude-agent-sdk/references/permissions-guide.md +429 -0
  5. package/.agents/skills/claude-agent-sdk/references/query-api-reference.md +437 -0
  6. package/.agents/skills/claude-agent-sdk/references/session-management.md +419 -0
  7. package/.agents/skills/claude-agent-sdk/references/subagents-patterns.md +464 -0
  8. package/.agents/skills/claude-agent-sdk/references/top-errors.md +503 -0
  9. package/.agents/skills/claude-agent-sdk/rules/claude-agent-sdk.md +96 -0
  10. package/.agents/skills/claude-agent-sdk/scripts/check-versions.sh +55 -0
  11. package/.agents/skills/claude-agent-sdk/templates/basic-query.ts +55 -0
  12. package/.agents/skills/claude-agent-sdk/templates/custom-mcp-server.ts +161 -0
  13. package/.agents/skills/claude-agent-sdk/templates/error-handling.ts +283 -0
  14. package/.agents/skills/claude-agent-sdk/templates/filesystem-settings.ts +211 -0
  15. package/.agents/skills/claude-agent-sdk/templates/multi-agent-workflow.ts +318 -0
  16. package/.agents/skills/claude-agent-sdk/templates/package.json +30 -0
  17. package/.agents/skills/claude-agent-sdk/templates/permission-control.ts +211 -0
  18. package/.agents/skills/claude-agent-sdk/templates/query-with-tools.ts +54 -0
  19. package/.agents/skills/claude-agent-sdk/templates/session-management.ts +151 -0
  20. package/.agents/skills/claude-agent-sdk/templates/subagents-orchestration.ts +166 -0
  21. package/.agents/skills/claude-agent-sdk/templates/tsconfig.json +22 -0
  22. package/.claude/settings.local.json +70 -0
  23. package/.claude/skills/moltbook-example/SKILL.md +79 -0
  24. package/.claude/skills/post/SKILL.md +130 -0
  25. package/.env.example +4 -0
  26. package/.vercel/README.txt +11 -0
  27. package/.vercel/project.json +1 -0
  28. package/AGENTS.md +114 -0
  29. package/CLAUDE.md +532 -0
  30. package/README.md +44 -0
  31. package/api/index.ts +3 -0
  32. package/biome.json +14 -0
  33. package/clark_avatar.jpeg +0 -0
  34. package/package.json +21 -0
  35. package/scripts/wake.ts +38 -0
  36. package/skills/clawbook/HEARTBEAT.md +142 -0
  37. package/skills/clawbook/SKILL.md +219 -0
  38. package/skills/moltbook-example/SKILL.md +79 -0
  39. package/skills/moltbook-example/bot/index.ts +61 -0
  40. package/src/agent/prompts.ts +98 -0
  41. package/src/agent/runner.ts +526 -0
  42. package/src/agent/tool-definitions.ts +1151 -0
  43. package/src/agent-options.ts +14 -0
  44. package/src/bot-identity.ts +41 -0
  45. package/src/constants.ts +15 -0
  46. package/src/handlers/heartbeat.ts +21 -0
  47. package/src/handlers/openai-compat.ts +95 -0
  48. package/src/handlers/post.ts +21 -0
  49. package/src/identity.ts +83 -0
  50. package/src/index.ts +30 -0
  51. package/src/middleware/cron-auth.ts +53 -0
  52. package/src/middleware/sigma-auth.ts +147 -0
  53. package/src/runs.ts +49 -0
  54. package/tests/agent/prompts.test.ts +172 -0
  55. package/tests/agent/runner.test.ts +353 -0
  56. package/tests/agent/tool-definitions.test.ts +171 -0
  57. package/tests/constants.test.ts +24 -0
  58. package/tests/handlers/openai-compat.test.ts +128 -0
  59. package/tests/handlers.test.ts +133 -0
  60. package/tests/identity.test.ts +66 -0
  61. package/tests/index.test.ts +108 -0
  62. package/tests/middleware/cron-auth.test.ts +99 -0
  63. package/tests/middleware/sigma-auth.test.ts +198 -0
  64. package/tests/runs.test.ts +56 -0
  65. package/tests/skill.test.ts +71 -0
  66. package/tsconfig.json +14 -0
  67. package/vercel.json +9 -0
@@ -0,0 +1,437 @@
1
+ # Query API Reference
2
+
3
+ Complete reference for the `query()` function - the primary interface for Claude Agent SDK.
4
+
5
+ ---
6
+
7
+ ## Function Signature
8
+
9
+ ```typescript
10
+ function query(config: {
11
+ prompt: string | AsyncIterable<SDKUserMessage>;
12
+ options?: Options;
13
+ }): AsyncGenerator<SDKMessage, void>;
14
+ ```
15
+
16
+ ---
17
+
18
+ ## Parameters
19
+
20
+ ### prompt
21
+
22
+ **Type**: `string | AsyncIterable<SDKUserMessage>`
23
+ **Required**: Yes
24
+
25
+ The task or question for the agent.
26
+
27
+ ```typescript
28
+ // Simple string prompt
29
+ query({ prompt: "Analyze the codebase" })
30
+
31
+ // Streaming prompt (advanced)
32
+ query({ prompt: streamingUserMessages() })
33
+ ```
34
+
35
+ ### options
36
+
37
+ **Type**: `Options`
38
+ **Required**: No
39
+
40
+ Configuration options for the query.
41
+
42
+ ---
43
+
44
+ ## Options Reference
45
+
46
+ ### model
47
+
48
+ **Type**: `"sonnet" | "haiku" | "opus" | "claude-sonnet-4-5" | "inherit"`
49
+ **Default**: `"sonnet"`
50
+
51
+ Model to use for the agent.
52
+
53
+ ```typescript
54
+ options: {
55
+ model: "claude-sonnet-4-5" // Specific version
56
+ model: "haiku" // Fast
57
+ model: "opus" // Maximum capability
58
+ model: "inherit" // Use parent model (subagents)
59
+ }
60
+ ```
61
+
62
+ ### workingDirectory
63
+
64
+ **Type**: `string`
65
+ **Default**: Current working directory
66
+
67
+ Directory where agent operates.
68
+
69
+ ```typescript
70
+ options: {
71
+ workingDirectory: "/path/to/project"
72
+ }
73
+ ```
74
+
75
+ ### systemPrompt
76
+
77
+ **Type**: `string | { type: 'preset', preset: 'claude_code' }`
78
+ **Default**: None
79
+
80
+ System prompt that defines agent behavior.
81
+
82
+ ```typescript
83
+ // Custom prompt
84
+ options: {
85
+ systemPrompt: "You are a security-focused code reviewer."
86
+ }
87
+
88
+ // Use CLAUDE.md from project
89
+ options: {
90
+ systemPrompt: { type: 'preset', preset: 'claude_code' },
91
+ settingSources: ["project"] // Required to load CLAUDE.md
92
+ }
93
+ ```
94
+
95
+ ### allowedTools
96
+
97
+ **Type**: `string[]`
98
+ **Default**: All tools
99
+
100
+ Whitelist of tools agent can use.
101
+
102
+ ```typescript
103
+ options: {
104
+ allowedTools: ["Read", "Grep", "Glob"] // Read-only
105
+ }
106
+ ```
107
+
108
+ ### disallowedTools
109
+
110
+ **Type**: `string[]`
111
+ **Default**: None
112
+
113
+ Blacklist of tools agent cannot use.
114
+
115
+ ```typescript
116
+ options: {
117
+ disallowedTools: ["Bash", "Write", "Edit"] // No modifications
118
+ }
119
+ ```
120
+
121
+ **Note**: If both specified, `allowedTools` wins.
122
+
123
+ ### permissionMode
124
+
125
+ **Type**: `"default" | "acceptEdits" | "bypassPermissions"`
126
+ **Default**: `"default"`
127
+
128
+ Permission strategy.
129
+
130
+ ```typescript
131
+ options: {
132
+ permissionMode: "default" // Standard checks
133
+ permissionMode: "acceptEdits" // Auto-approve edits
134
+ permissionMode: "bypassPermissions" // Skip all checks (caution!)
135
+ }
136
+ ```
137
+
138
+ ### canUseTool
139
+
140
+ **Type**: `(toolName: string, input: any) => Promise<PermissionDecision>`
141
+ **Default**: None
142
+
143
+ Custom permission logic.
144
+
145
+ ```typescript
146
+ options: {
147
+ canUseTool: async (toolName, input) => {
148
+ if (toolName === 'Bash' && input.command.includes('rm -rf')) {
149
+ return { behavior: "deny", message: "Blocked" };
150
+ }
151
+ return { behavior: "allow" };
152
+ }
153
+ }
154
+ ```
155
+
156
+ **PermissionDecision**:
157
+ - `{ behavior: "allow" }` - Allow execution
158
+ - `{ behavior: "deny", message?: string }` - Block execution
159
+ - `{ behavior: "ask", message?: string }` - Prompt user
160
+
161
+ ### agents
162
+
163
+ **Type**: `Record<string, AgentDefinition>`
164
+ **Default**: None
165
+
166
+ Subagent definitions.
167
+
168
+ ```typescript
169
+ options: {
170
+ agents: {
171
+ "test-runner": {
172
+ description: "Run test suites",
173
+ prompt: "You run tests. Fail if any test fails.",
174
+ tools: ["Bash", "Read"],
175
+ model: "haiku"
176
+ }
177
+ }
178
+ }
179
+ ```
180
+
181
+ **AgentDefinition**:
182
+ - `description` (string, required) - When to use agent
183
+ - `prompt` (string, required) - Agent's system prompt
184
+ - `tools` (string[], optional) - Allowed tools
185
+ - `model` (string, optional) - Model override
186
+
187
+ ### mcpServers
188
+
189
+ **Type**: `Record<string, McpServerConfig>`
190
+ **Default**: None
191
+
192
+ MCP server configurations.
193
+
194
+ ```typescript
195
+ options: {
196
+ mcpServers: {
197
+ "custom-server": customServer, // In-process
198
+ "filesystem": { // External (stdio)
199
+ command: "npx",
200
+ args: ["@modelcontextprotocol/server-filesystem"]
201
+ },
202
+ "remote": { // External (HTTP)
203
+ url: "https://api.example.com/mcp",
204
+ headers: { "Authorization": "Bearer token" }
205
+ }
206
+ }
207
+ }
208
+ ```
209
+
210
+ ### settingSources
211
+
212
+ **Type**: `("user" | "project" | "local")[]`
213
+ **Default**: `[]` (no filesystem settings)
214
+
215
+ Filesystem settings to load.
216
+
217
+ ```typescript
218
+ options: {
219
+ settingSources: ["project"] // Project only (CI/CD)
220
+ settingSources: ["user", "project", "local"] // All sources
221
+ settingSources: [] // Isolated (no files)
222
+ }
223
+ ```
224
+
225
+ **Files**:
226
+ - `user` = `~/.claude/settings.json`
227
+ - `project` = `.claude/settings.json`
228
+ - `local` = `.claude/settings.local.json`
229
+
230
+ **Priority**: Programmatic > Local > Project > User
231
+
232
+ ### resume
233
+
234
+ **Type**: `string`
235
+ **Default**: None
236
+
237
+ Session ID to resume.
238
+
239
+ ```typescript
240
+ options: {
241
+ resume: "session-id-here"
242
+ }
243
+ ```
244
+
245
+ ### forkSession
246
+
247
+ **Type**: `boolean`
248
+ **Default**: `false`
249
+
250
+ Create new branch from resumed session.
251
+
252
+ ```typescript
253
+ options: {
254
+ resume: "session-id-here",
255
+ forkSession: true // New branch, original unchanged
256
+ }
257
+ ```
258
+
259
+ ---
260
+
261
+ ## Return Value
262
+
263
+ **Type**: `AsyncGenerator<SDKMessage, void>`
264
+
265
+ Asynchronous generator yielding messages.
266
+
267
+ ```typescript
268
+ const response = query({ prompt: "..." });
269
+
270
+ for await (const message of response) {
271
+ // Process message
272
+ }
273
+ ```
274
+
275
+ ---
276
+
277
+ ## Message Types
278
+
279
+ See full details in SKILL.md. Summary:
280
+
281
+ | Type | When | Data |
282
+ |------|------|------|
283
+ | `system` | Session events | `session_id`, `model`, `tools` |
284
+ | `assistant` | Agent response | `content` (string or blocks) |
285
+ | `tool_call` | Tool requested | `tool_name`, `input` |
286
+ | `tool_result` | Tool completed | `tool_name`, `result` |
287
+ | `error` | Error occurred | `error` object |
288
+
289
+ ---
290
+
291
+ ## Usage Patterns
292
+
293
+ ### Basic Query
294
+
295
+ ```typescript
296
+ const response = query({
297
+ prompt: "Analyze code",
298
+ options: { model: "sonnet" }
299
+ });
300
+
301
+ for await (const message of response) {
302
+ if (message.type === 'assistant') {
303
+ console.log(message.content);
304
+ }
305
+ }
306
+ ```
307
+
308
+ ### With Tools
309
+
310
+ ```typescript
311
+ const response = query({
312
+ prompt: "Review and fix bugs",
313
+ options: {
314
+ model: "sonnet",
315
+ allowedTools: ["Read", "Grep", "Edit"]
316
+ }
317
+ });
318
+ ```
319
+
320
+ ### With Subagents
321
+
322
+ ```typescript
323
+ const response = query({
324
+ prompt: "Deploy to production",
325
+ options: {
326
+ agents: {
327
+ "tester": { /* ... */ },
328
+ "deployer": { /* ... */ }
329
+ }
330
+ }
331
+ });
332
+ ```
333
+
334
+ ### With Custom Tools
335
+
336
+ ```typescript
337
+ const response = query({
338
+ prompt: "Get weather and send notification",
339
+ options: {
340
+ mcpServers: { "weather": weatherServer },
341
+ allowedTools: ["mcp__weather__get_weather"]
342
+ }
343
+ });
344
+ ```
345
+
346
+ ### With Session Management
347
+
348
+ ```typescript
349
+ // Start
350
+ let session = await startSession("Build API");
351
+
352
+ // Resume
353
+ await resumeSession(session, "Add auth");
354
+
355
+ // Fork
356
+ await forkSession(session, "Try GraphQL instead");
357
+ ```
358
+
359
+ ---
360
+
361
+ ## Best Practices
362
+
363
+ ### ✅ Do
364
+
365
+ - Set specific `allowedTools` for security
366
+ - Use `canUseTool` for fine-grained control
367
+ - Implement error handling for all queries
368
+ - Capture `session_id` for resuming
369
+ - Use `workingDirectory` for clarity
370
+ - Test MCP servers independently
371
+ - Monitor tool execution with `tool_call` messages
372
+
373
+ ### ❌ Don't
374
+
375
+ - Use `bypassPermissions` in production (unless sandboxed)
376
+ - Ignore error messages
377
+ - Skip session ID capture if planning to resume
378
+ - Allow unrestricted Bash without `canUseTool`
379
+ - Load user settings in CI/CD
380
+ - Use duplicate tool names
381
+
382
+ ---
383
+
384
+ ## Error Handling
385
+
386
+ ```typescript
387
+ try {
388
+ const response = query({ prompt: "..." });
389
+ for await (const message of response) {
390
+ if (message.type === 'error') {
391
+ console.error('Agent error:', message.error);
392
+ }
393
+ }
394
+ } catch (error) {
395
+ if (error.code === 'CLI_NOT_FOUND') {
396
+ console.error('Install Claude Code CLI');
397
+ }
398
+ }
399
+ ```
400
+
401
+ ---
402
+
403
+ ## TypeScript Types
404
+
405
+ ```typescript
406
+ type Options = {
407
+ model?: "sonnet" | "haiku" | "opus" | string;
408
+ workingDirectory?: string;
409
+ systemPrompt?: string | { type: 'preset', preset: 'claude_code' };
410
+ allowedTools?: string[];
411
+ disallowedTools?: string[];
412
+ permissionMode?: "default" | "acceptEdits" | "bypassPermissions";
413
+ canUseTool?: (toolName: string, input: any) => Promise<PermissionDecision>;
414
+ agents?: Record<string, AgentDefinition>;
415
+ mcpServers?: Record<string, McpServerConfig>;
416
+ settingSources?: ("user" | "project" | "local")[];
417
+ resume?: string;
418
+ forkSession?: boolean;
419
+ };
420
+
421
+ type AgentDefinition = {
422
+ description: string;
423
+ prompt: string;
424
+ tools?: string[];
425
+ model?: "sonnet" | "opus" | "haiku" | "inherit";
426
+ };
427
+
428
+ type PermissionDecision =
429
+ | { behavior: "allow" }
430
+ | { behavior: "deny"; message?: string }
431
+ | { behavior: "ask"; message?: string };
432
+ ```
433
+
434
+ ---
435
+
436
+ **For more details**: See SKILL.md
437
+ **Official docs**: https://docs.claude.com/en/api/agent-sdk/typescript