@drawbridge/drawbridge-agents 0.0.9 → 0.0.10

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.
package/claude/CLAUDE.md CHANGED
@@ -1,9 +1,11 @@
1
+ @../conventions/karpathy-guidelines.md
1
2
  @../conventions/rules.md
2
3
  @../conventions/javascript-formatting.md
3
4
  @../conventions/nested-objects.md
4
5
  @../conventions/jsx-fragments.md
5
6
  @../conventions/transactions.md
6
7
  @../conventions/cascade-cleanup.md
8
+ @../conventions/dry.md
7
9
  @../conventions/property-shorthand.md
8
10
  @../conventions/drawbridge-packages.md
9
11
  @../conventions/sentry-sdk.md
@@ -1,6 +1,6 @@
1
1
  # Cascade cleanup belongs in drawbridge-sync
2
2
 
3
- When a Drawbridge document delete should trigger cleanup of dependent rows in another collection — actions tied to a workflow, workflows tied to a connection, exports tied to a user, anything where deleting X requires also deleting Y — the cleanup belongs in a change-stream listener in `drawbridge-sync`, **not** inline in the API route handler that triggered the original delete.
3
+ When a Drawbridge document delete should trigger cleanup of dependent rows in another collection — steps tied to a workflow, workflows tied to a connection, exports tied to a user, anything where deleting X requires also deleting Y — the cleanup belongs in a change-stream listener in `drawbridge-sync`, **not** inline in the API route handler that triggered the original delete.
4
4
 
5
5
  ## Why
6
6
 
@@ -0,0 +1,34 @@
1
+ # Don't Repeat Yourself (DRY)
2
+
3
+ Before writing a new function or handler that *does work* (external API call, doc creation, counter increment, cascade pattern, dispatch), check whether existing code already does that work. If so, **reuse it**. If the same work happens in 2+ places, **extract a helper** before adding a third copy.
4
+
5
+ ## Why
6
+
7
+ Repeated implementations drift. Two paths that did the same thing yesterday do *almost* the same thing tomorrow — and the divergence is the bug. Examples from this codebase:
8
+
9
+ - `step.sendgrid.email.send` was implemented as a separate handler that called `sendgrid.send()` directly, while `queue/notification.js`'s `send()` already did exactly that with the right provider selection from org connections. Two paths, same external service, slightly different code — a future SendGrid auth change would have to be made in both.
10
+ - `usage.totals.actions` increments are hand-rolled in `stream/otc.js`, `queue/segment.js`, `queue/contact.js`, and historically `queue/workflow.js` — billing logic spread across 4+ files, each independent.
11
+ - Connection-fetch + `decrypt(connection.settings)` appears 7+ times across `stream/` and `queue/`. The `status: 'active'` guard is implicit in some callers and missing in others — a latent security gap.
12
+
13
+ Each pattern is small individually. Together they make debugging issues like "why is the action count wrong?" require grepping every counter increment to find the right one.
14
+
15
+ ## How to apply
16
+
17
+ 1. **Name the existing function you're calling before writing the new function.** "I'll call `send()` from `queue/notification.js`" — not "I'll call `sendgrid.send()` directly". If the function you'd call doesn't exist yet, you might still need to write it — but first verify it's not just one grep away.
18
+ 2. **Grep the work, not the name.** Before adding a `controller.update({ $inc: { 'totals.X': … }})`, grep for `totals.X` to find every other site doing the same. Same for SDK calls (`sendgrid.send`, `stripe.customers.update`, etc.).
19
+ 3. **At 2 copies, extract.** If you find the same shape in two places, factor before adding a third. Don't wait for the 5th.
20
+ 4. **Centralize step handlers, queue workers, and lifecycle emitters in one file each.** drawbridge-sync's pattern: all `step.*` bodies live in `queue/step.js`; all messaging delivery routes through `queue/notification.js`'s `send()`; per-collection cleanup lives in `stream/<collection>.js`. Don't sprinkle related logic across multiple files for no reason.
21
+
22
+ ## Watch list
23
+
24
+ Patterns that have been duplicated in this family before — confirm before adding new instances:
25
+
26
+ - External SDK calls (SendGrid / Mailchimp / Twilio / Stripe / Shopify Admin / Shopify Storefront)
27
+ - `controller.update({ $inc: { 'totals.X': … }})` counter increments on the `usage`, `organization`, `campaign`, `page`, `range`, `lead` collections
28
+ - `controller.get({ collection: 'connection', … })` followed by `decrypt(connection.settings)`
29
+ - Notification doc creation (`controller.create({ collection: 'notification', … })`) when you actually want to send an email/SMS — use `send()` directly
30
+ - Cache invalidation chains where multiple `cache.delete([…])` calls fire as a pair
31
+ - `logger.emit('<entity>.<verb>', …)` lifecycle telemetry wrappers
32
+ - Cascade-delete patterns (delete X → also cleanup Y, Z) — these belong as stream listeners in `drawbridge-sync`, see `cascade-cleanup.md`
33
+
34
+ If you find a duplicate while implementing something new, surface it: either factor it as part of the same change, or document it and propose a follow-up cleanup PR.
@@ -0,0 +1,63 @@
1
+ # Karpathy coding guidelines
2
+
3
+ Adapted from Andrej Karpathy's observations on common LLM coding mistakes — see https://github.com/multica-ai/andrej-karpathy-skills. These are general behavioral guidelines that bias toward caution over speed; use judgment for trivial tasks.
4
+
5
+ ## 1. Think Before Coding
6
+
7
+ **Don't assume. Don't hide confusion. Surface tradeoffs.**
8
+
9
+ Before implementing:
10
+ - State your assumptions explicitly. If uncertain, ask.
11
+ - If multiple interpretations exist, present them — don't pick silently.
12
+ - If a simpler approach exists, say so. Push back when warranted.
13
+ - If something is unclear, stop. Name what's confusing. Ask.
14
+
15
+ ## 2. Simplicity First
16
+
17
+ **Minimum code that solves the problem. Nothing speculative.**
18
+
19
+ - No features beyond what was asked.
20
+ - No abstractions for single-use code.
21
+ - No "flexibility" or "configurability" that wasn't requested.
22
+ - No error handling for impossible scenarios.
23
+ - If you write 200 lines and it could be 50, rewrite it.
24
+
25
+ Ask yourself: "Would a senior engineer say this is overcomplicated?" If yes, simplify.
26
+
27
+ ## 3. Surgical Changes
28
+
29
+ **Touch only what you must. Clean up only your own mess.**
30
+
31
+ When editing existing code:
32
+ - Don't "improve" adjacent code, comments, or formatting.
33
+ - Don't refactor things that aren't broken.
34
+ - Match existing style, even if you'd do it differently.
35
+ - If you notice unrelated dead code, mention it — don't delete it.
36
+
37
+ When your changes create orphans:
38
+ - Remove imports/variables/functions that YOUR changes made unused.
39
+ - Don't remove pre-existing dead code unless asked.
40
+
41
+ The test: Every changed line should trace directly to the user's request.
42
+
43
+ ## 4. Goal-Driven Execution
44
+
45
+ **Define success criteria. Loop until verified.**
46
+
47
+ Transform tasks into verifiable goals:
48
+ - "Add validation" → "Write tests for invalid inputs, then make them pass"
49
+ - "Fix the bug" → "Write a test that reproduces it, then make it pass"
50
+ - "Refactor X" → "Ensure tests pass before and after"
51
+
52
+ For multi-step tasks, state a brief plan:
53
+ ```
54
+ 1. [Step] → verify: [check]
55
+ 2. [Step] → verify: [check]
56
+ 3. [Step] → verify: [check]
57
+ ```
58
+
59
+ Strong success criteria let you loop independently. Weak criteria ("make it work") require constant clarification.
60
+
61
+ ---
62
+
63
+ **These guidelines are working if:** fewer unnecessary changes in diffs, fewer rewrites due to overcomplication, and clarifying questions come before implementation rather than after mistakes.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drawbridge/drawbridge-agents",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "description": "Shared agent-instruction content (rules, code style, conventions) for the drawbridge-* monorepo.",
5
5
  "license": "UNLICENSED",
6
6
  "publishConfig": {