create-theokit 1.25.2 → 2.0.0-next.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 (58) hide show
  1. package/dist/cli.js +53 -54
  2. package/dist/cli.js.map +1 -1
  3. package/package.json +8 -1
  4. package/templates/_bot-preset/{agents → src/server/agents}/tools/publish.ts +1 -1
  5. package/templates/_bot-preset/{server → src/server}/crons/daily-research.ts +2 -2
  6. package/templates/default/AGENTS.md.tmpl +58 -0
  7. package/templates/default/CLAUDE.md +4 -4
  8. package/templates/default/README.md.tmpl +56 -30
  9. package/templates/default/docs/ARCHITECTURE.md +103 -58
  10. package/templates/default/docs/CUSTOMIZATION.md +10 -10
  11. package/templates/default/docs/ENVIRONMENT.md +6 -6
  12. package/templates/default/dot-claude/rules/theokit-conventions.md +3 -3
  13. package/templates/default/dot-claude/skills/theokit-agents/SKILL.md +7 -7
  14. package/templates/default/dot-claude/skills/theokit-config/SKILL.md +1 -1
  15. package/templates/default/dot-claude/skills/theokit-frontend/SKILL.md +1 -1
  16. package/templates/default/dot-claude/skills/theokit-gateways/SKILL.md +1 -1
  17. package/templates/default/dot-claude/skills/theokit-routes/SKILL.md +1 -1
  18. package/templates/default/dot-claude/skills/theokit-ui/SKILL.md +1 -1
  19. package/templates/default/dot-theokit/THEO.md +36 -0
  20. package/templates/default/dot-theokit/personalities/README.md +35 -0
  21. package/templates/default/dot-theokit/personalities/concise.md +14 -0
  22. package/templates/default/dot-theokit/personalities/teacher.md +17 -0
  23. package/templates/default/dot-theokit/rules/README.md +30 -0
  24. package/templates/default/dot-theokit/rules/server-routes.md +16 -0
  25. package/templates/default/package.json.tmpl +2 -2
  26. package/templates/default/{agents → src/server/agents}/chat.ts +6 -0
  27. package/templates/default/src/server/agents/hooks/tool-audit.ts +75 -0
  28. package/templates/default/theo.config.ts +18 -1
  29. package/templates/default/tsconfig.json +4 -5
  30. /package/templates/_bot-preset/{agents → src/server/agents}/lib/bot-scope.ts +0 -0
  31. /package/templates/_bot-preset/{agents → src/server/agents}/lib/sandbox.ts +0 -0
  32. /package/templates/_bot-preset/{agents → src/server/agents}/publisher.ts +0 -0
  33. /package/templates/_bot-preset/{agents → src/server/agents}/researcher.ts +0 -0
  34. /package/templates/_bot-preset/{agents → src/server/agents}/tools/read-notes.ts +0 -0
  35. /package/templates/_bot-preset/{agents → src/server/agents}/tools/write-note.ts +0 -0
  36. /package/templates/_bot-preset/{server → src/server}/delivery.ts +0 -0
  37. /package/templates/default/{app → src/app}/about/page.tsx +0 -0
  38. /package/templates/default/{app → src/app}/components/ChatPanel.tsx +0 -0
  39. /package/templates/default/{app → src/app}/components/Composer.tsx +0 -0
  40. /package/templates/default/{app → src/app}/components/Header.tsx +0 -0
  41. /package/templates/default/{app → src/app}/components/Nav.tsx +0 -0
  42. /package/templates/default/{app → src/app}/error.tsx +0 -0
  43. /package/templates/default/{app → src/app}/hooks/use-transcript.test.ts +0 -0
  44. /package/templates/default/{app → src/app}/hooks/use-transcript.ts +0 -0
  45. /package/templates/default/{app → src/app}/layout.tsx +0 -0
  46. /package/templates/default/{app → src/app}/lib/constants.ts +0 -0
  47. /package/templates/default/{app → src/app}/lib/renderable.ts +0 -0
  48. /package/templates/default/{app → src/app}/loading.tsx +0 -0
  49. /package/templates/default/{app → src/app}/not-found.tsx +0 -0
  50. /package/templates/default/{app → src/app}/page.test.tsx +0 -0
  51. /package/templates/default/{app → src/app}/page.tsx +0 -0
  52. /package/templates/default/{agents → src/server/agents}/prompts/instructions.ts +0 -0
  53. /package/templates/default/{agents → src/server/agents}/skills/daily-briefing.ts +0 -0
  54. /package/templates/default/{agents → src/server/agents}/tools/current-time.ts +0 -0
  55. /package/templates/default/{agents → src/server/agents}/tools/send-notification.ts +0 -0
  56. /package/templates/default/{agents → src/server/agents}/tools/weather.ts +0 -0
  57. /package/templates/default/{server → src/server}/routes/health.ts +0 -0
  58. /package/templates/default/{shared → src/shared}/agent.ts +0 -0
@@ -0,0 +1,75 @@
1
+ import type { HookHandlers } from '@theokit/agents'
2
+
3
+ /**
4
+ * Lifecycle hooks — the seam where you observe or intercept the agent loop.
5
+ *
6
+ * A tool call is the moment your agent stops talking and starts *doing*: it hits the network, writes
7
+ * a row, sends a message. This hook makes every one of those visible, with the timing, so a slow or
8
+ * looping agent is something you can see in a log rather than something you infer from a user
9
+ * complaint.
10
+ *
11
+ * Eight events exist. These two are the pair you almost always want first:
12
+ *
13
+ * | Event | When | Can it stop the call? |
14
+ * |---|---|---|
15
+ * | `pre_tool_call` | before the tool runs | **yes** — return `{ block: true, message }` |
16
+ * | `post_tool_call` | after it returns | no — fire-and-forget |
17
+ * | `transform_tool_result` | folds the turn's results before the model sees them | rewrites |
18
+ * | `transform_llm_output` | folds the model's text | rewrites |
19
+ * | `on_session_start` / `on_session_end` | session lifecycle | no |
20
+ * | `pre_user_send` / `post_assistant_reply` | around a user turn | no |
21
+ *
22
+ * ## Why this one only observes
23
+ *
24
+ * `pre_tool_call` is the only hook with veto power, and it is tempting to ship a template that uses
25
+ * it. It is deliberately not used here: a veto encodes a policy, and any policy this file could
26
+ * invent would be one your app did not ask for. `send_notification` is already gated the right way
27
+ * — by a human approval in `chat.ts` — which is where a decision belongs when a person should make
28
+ * it. Reach for the veto when you have a rule of your own:
29
+ *
30
+ * ```ts
31
+ * pre_tool_call: (ctx) =>
32
+ * ctx.name === 'delete_account' && !isAdmin(ctx)
33
+ * ? { block: true, message: 'Only an admin may delete an account.' }
34
+ * : undefined,
35
+ * ```
36
+ *
37
+ * The message goes to the MODEL, not the user — write it as an instruction the agent can act on.
38
+ */
39
+
40
+ /** Start times by `${runId}:${name}`, so a duration survives concurrent calls in one run. */
41
+ const started = new Map<string, number>()
42
+
43
+ function key(runId: string, name: string): string {
44
+ return `${runId}:${name}`
45
+ }
46
+
47
+ export const toolAuditHooks: HookHandlers = {
48
+ pre_tool_call: (ctx) => {
49
+ started.set(key(ctx.runId, ctx.name), Date.now())
50
+ // One structured line per call. Structured, not a sentence, because the thing you will want
51
+ // later is a filter (`tool=weather`), and a sentence has to be parsed back apart to give you one.
52
+ console.info(
53
+ JSON.stringify({ event: 'tool.start', tool: ctx.name, runId: ctx.runId, args: ctx.args }),
54
+ )
55
+ // `undefined` lets the call through. Returning nothing is not the same as approving nothing:
56
+ // this hook makes no decision, and that is the point of the docblock above.
57
+ return undefined
58
+ },
59
+
60
+ post_tool_call: (ctx) => {
61
+ const k = key(ctx.runId, ctx.name)
62
+ const startedAt = started.get(k)
63
+ started.delete(k)
64
+ console.info(
65
+ JSON.stringify({
66
+ event: 'tool.end',
67
+ tool: ctx.name,
68
+ runId: ctx.runId,
69
+ // Absent rather than zero when the start was never seen — a duration of 0ms would read as
70
+ // an instant call instead of as a missing measurement.
71
+ ms: startedAt === undefined ? undefined : Date.now() - startedAt,
72
+ }),
73
+ )
74
+ },
75
+ }
@@ -1,3 +1,20 @@
1
1
  import { config } from 'theokit'
2
2
 
3
- export default config().build()
3
+ /**
4
+ * The project has two surfaces, and one of them is the whole backend.
5
+ *
6
+ * `src/app` is the interface. `src/server` is everything that only runs on the server — and agents
7
+ * are part of that, not a third surface beside it. An agent shares this project's context, auth,
8
+ * services and infrastructure with every controller and route; a layout that puts `agents/` beside
9
+ * `server/` suggests two backends and invites both to grow their own copy of all four.
10
+ *
11
+ * The paths are declared rather than inherited. The defaults are still the flat layout
12
+ * (`app`, `server`, `agents`), so a project that says nothing keeps working exactly as before —
13
+ * writing them down is what lets this scaffold move without waiting for a major, and what stops a
14
+ * future default change from silently relocating anyone's code.
15
+ */
16
+ export default config()
17
+ .appDir('src/app')
18
+ .serverDir('src/server')
19
+ .agentsDir('src/server/agents')
20
+ .build()
@@ -14,11 +14,10 @@
14
14
  "emitDecoratorMetadata": true
15
15
  },
16
16
  "include": [
17
- "app/**/*.ts",
18
- "app/**/*.tsx",
19
- "server/**/*.ts",
20
- "agents/**/*.ts",
21
- "shared/**/*.ts",
17
+ "src/app/**/*.ts",
18
+ "src/app/**/*.tsx",
19
+ "src/server/**/*.ts",
20
+ "src/shared/**/*.ts",
22
21
  ".theokit/**/*.d.ts",
23
22
  "types/**/*.d.ts"
24
23
  ]
File without changes
File without changes
File without changes
File without changes