opencodekit 0.15.8 → 0.15.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/dist/index.js +9 -7
- package/dist/template/.opencode/AGENTS.md +7 -2
- package/dist/template/.opencode/agent/general.md +1 -0
- package/dist/template/.opencode/agent/looker.md +1 -0
- package/dist/template/.opencode/agent/painter.md +218 -0
- package/dist/template/.opencode/agent/plan.md +3 -0
- package/dist/template/.opencode/agent/vision.md +1 -0
- package/dist/template/.opencode/command/edit-image.md +1 -2
- package/dist/template/.opencode/command/generate-icon.md +1 -2
- package/dist/template/.opencode/command/generate-image.md +1 -2
- package/dist/template/.opencode/command/generate-pattern.md +1 -2
- package/dist/template/.opencode/command/generate-storyboard.md +1 -2
- package/dist/template/.opencode/command/restore-image.md +1 -2
- package/dist/template/.opencode/dcp.jsonc +12 -10
- package/dist/template/.opencode/opencode.json +707 -704
- package/dist/template/.opencode/package.json +1 -1
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/AGENTS.md +1490 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/SKILL.md +57 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/advanced-full-text-search.md +55 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/advanced-jsonb-indexing.md +49 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/conn-idle-timeout.md +46 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/conn-limits.md +44 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/conn-pooling.md +41 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/conn-prepared-statements.md +46 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/data-batch-inserts.md +54 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/data-n-plus-one.md +53 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/data-pagination.md +50 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/data-upsert.md +50 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/lock-advisory.md +56 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/lock-deadlock-prevention.md +68 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/lock-short-transactions.md +50 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/lock-skip-locked.md +54 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/monitor-explain-analyze.md +45 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/monitor-pg-stat-statements.md +55 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/monitor-vacuum-analyze.md +55 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/query-composite-indexes.md +44 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/query-covering-indexes.md +40 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/query-index-types.md +45 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/query-missing-indexes.md +43 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/query-partial-indexes.md +45 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/schema-data-types.md +46 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/schema-foreign-key-indexes.md +59 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/schema-lowercase-identifiers.md +55 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/schema-partitioning.md +55 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/schema-primary-keys.md +61 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/security-privileges.md +54 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/security-rls-basics.md +50 -0
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/security-rls-performance.md +57 -0
- package/package.json +1 -1
package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/schema-partitioning.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Partition Large Tables for Better Performance
|
|
3
|
+
impact: MEDIUM-HIGH
|
|
4
|
+
impactDescription: 5-20x faster queries and maintenance on large tables
|
|
5
|
+
tags: partitioning, large-tables, time-series, performance
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Partition Large Tables for Better Performance
|
|
9
|
+
|
|
10
|
+
Partitioning splits a large table into smaller pieces, improving query performance and maintenance operations.
|
|
11
|
+
|
|
12
|
+
**Incorrect (single large table):**
|
|
13
|
+
|
|
14
|
+
```sql
|
|
15
|
+
create table events (
|
|
16
|
+
id bigint generated always as identity,
|
|
17
|
+
created_at timestamptz,
|
|
18
|
+
data jsonb
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
-- 500M rows, queries scan everything
|
|
22
|
+
select * from events where created_at > '2024-01-01'; -- Slow
|
|
23
|
+
vacuum events; -- Takes hours, locks table
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**Correct (partitioned by time range):**
|
|
27
|
+
|
|
28
|
+
```sql
|
|
29
|
+
create table events (
|
|
30
|
+
id bigint generated always as identity,
|
|
31
|
+
created_at timestamptz not null,
|
|
32
|
+
data jsonb
|
|
33
|
+
) partition by range (created_at);
|
|
34
|
+
|
|
35
|
+
-- Create partitions for each month
|
|
36
|
+
create table events_2024_01 partition of events
|
|
37
|
+
for values from ('2024-01-01') to ('2024-02-01');
|
|
38
|
+
|
|
39
|
+
create table events_2024_02 partition of events
|
|
40
|
+
for values from ('2024-02-01') to ('2024-03-01');
|
|
41
|
+
|
|
42
|
+
-- Queries only scan relevant partitions
|
|
43
|
+
select * from events where created_at > '2024-01-15'; -- Only scans events_2024_01+
|
|
44
|
+
|
|
45
|
+
-- Drop old data instantly
|
|
46
|
+
drop table events_2023_01; -- Instant vs DELETE taking hours
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
When to partition:
|
|
50
|
+
|
|
51
|
+
- Tables > 100M rows
|
|
52
|
+
- Time-series data with date-based queries
|
|
53
|
+
- Need to efficiently drop old data
|
|
54
|
+
|
|
55
|
+
Reference: [Table Partitioning](https://www.postgresql.org/docs/current/ddl-partitioning.html)
|
package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/schema-primary-keys.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Select Optimal Primary Key Strategy
|
|
3
|
+
impact: HIGH
|
|
4
|
+
impactDescription: Better index locality, reduced fragmentation
|
|
5
|
+
tags: primary-key, identity, uuid, serial, schema
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Select Optimal Primary Key Strategy
|
|
9
|
+
|
|
10
|
+
Primary key choice affects insert performance, index size, and replication
|
|
11
|
+
efficiency.
|
|
12
|
+
|
|
13
|
+
**Incorrect (problematic PK choices):**
|
|
14
|
+
|
|
15
|
+
```sql
|
|
16
|
+
-- identity is the SQL-standard approach
|
|
17
|
+
create table users (
|
|
18
|
+
id serial primary key -- Works, but IDENTITY is recommended
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
-- Random UUIDs (v4) cause index fragmentation
|
|
22
|
+
create table orders (
|
|
23
|
+
id uuid default gen_random_uuid() primary key -- UUIDv4 = random = scattered inserts
|
|
24
|
+
);
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
**Correct (optimal PK strategies):**
|
|
28
|
+
|
|
29
|
+
```sql
|
|
30
|
+
-- Use IDENTITY for sequential IDs (SQL-standard, best for most cases)
|
|
31
|
+
create table users (
|
|
32
|
+
id bigint generated always as identity primary key
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
-- For distributed systems needing UUIDs, use UUIDv7 (time-ordered)
|
|
36
|
+
-- Requires pg_uuidv7 extension: create extension pg_uuidv7;
|
|
37
|
+
create table orders (
|
|
38
|
+
id uuid default uuid_generate_v7() primary key -- Time-ordered, no fragmentation
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
-- Alternative: time-prefixed IDs for sortable, distributed IDs (no extension needed)
|
|
42
|
+
create table events (
|
|
43
|
+
id text default concat(
|
|
44
|
+
to_char(now() at time zone 'utc', 'YYYYMMDDHH24MISSMS'),
|
|
45
|
+
gen_random_uuid()::text
|
|
46
|
+
) primary key
|
|
47
|
+
);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Guidelines:
|
|
51
|
+
|
|
52
|
+
- Single database: `bigint identity` (sequential, 8 bytes, SQL-standard)
|
|
53
|
+
- Distributed/exposed IDs: UUIDv7 (requires pg_uuidv7) or ULID (time-ordered, no
|
|
54
|
+
fragmentation)
|
|
55
|
+
- `serial` works but `identity` is SQL-standard and preferred for new
|
|
56
|
+
applications
|
|
57
|
+
- Avoid random UUIDs (v4) as primary keys on large tables (causes index
|
|
58
|
+
fragmentation)
|
|
59
|
+
|
|
60
|
+
Reference:
|
|
61
|
+
[Identity Columns](https://www.postgresql.org/docs/current/sql-createtable.html#SQL-CREATETABLE-PARMS-GENERATED-IDENTITY)
|
package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/security-privileges.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Apply Principle of Least Privilege
|
|
3
|
+
impact: MEDIUM
|
|
4
|
+
impactDescription: Reduced attack surface, better audit trail
|
|
5
|
+
tags: privileges, security, roles, permissions
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Apply Principle of Least Privilege
|
|
9
|
+
|
|
10
|
+
Grant only the minimum permissions required. Never use superuser for application queries.
|
|
11
|
+
|
|
12
|
+
**Incorrect (overly broad permissions):**
|
|
13
|
+
|
|
14
|
+
```sql
|
|
15
|
+
-- Application uses superuser connection
|
|
16
|
+
-- Or grants ALL to application role
|
|
17
|
+
grant all privileges on all tables in schema public to app_user;
|
|
18
|
+
grant all privileges on all sequences in schema public to app_user;
|
|
19
|
+
|
|
20
|
+
-- Any SQL injection becomes catastrophic
|
|
21
|
+
-- drop table users; cascades to everything
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
**Correct (minimal, specific grants):**
|
|
25
|
+
|
|
26
|
+
```sql
|
|
27
|
+
-- Create role with no default privileges
|
|
28
|
+
create role app_readonly nologin;
|
|
29
|
+
|
|
30
|
+
-- Grant only SELECT on specific tables
|
|
31
|
+
grant usage on schema public to app_readonly;
|
|
32
|
+
grant select on public.products, public.categories to app_readonly;
|
|
33
|
+
|
|
34
|
+
-- Create role for writes with limited scope
|
|
35
|
+
create role app_writer nologin;
|
|
36
|
+
grant usage on schema public to app_writer;
|
|
37
|
+
grant select, insert, update on public.orders to app_writer;
|
|
38
|
+
grant usage on sequence orders_id_seq to app_writer;
|
|
39
|
+
-- No DELETE permission
|
|
40
|
+
|
|
41
|
+
-- Login role inherits from these
|
|
42
|
+
create role app_user login password 'xxx';
|
|
43
|
+
grant app_writer to app_user;
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Revoke public defaults:
|
|
47
|
+
|
|
48
|
+
```sql
|
|
49
|
+
-- Revoke default public access
|
|
50
|
+
revoke all on schema public from public;
|
|
51
|
+
revoke all on all tables in schema public from public;
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Reference: [Roles and Privileges](https://supabase.com/blog/postgres-roles-and-privileges)
|
package/dist/template/.opencode/skill/supabase-postgres-best-practices/rules/security-rls-basics.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Enable Row Level Security for Multi-Tenant Data
|
|
3
|
+
impact: CRITICAL
|
|
4
|
+
impactDescription: Database-enforced tenant isolation, prevent data leaks
|
|
5
|
+
tags: rls, row-level-security, multi-tenant, security
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Enable Row Level Security for Multi-Tenant Data
|
|
9
|
+
|
|
10
|
+
Row Level Security (RLS) enforces data access at the database level, ensuring users only see their own data.
|
|
11
|
+
|
|
12
|
+
**Incorrect (application-level filtering only):**
|
|
13
|
+
|
|
14
|
+
```sql
|
|
15
|
+
-- Relying only on application to filter
|
|
16
|
+
select * from orders where user_id = $current_user_id;
|
|
17
|
+
|
|
18
|
+
-- Bug or bypass means all data is exposed!
|
|
19
|
+
select * from orders; -- Returns ALL orders
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Correct (database-enforced RLS):**
|
|
23
|
+
|
|
24
|
+
```sql
|
|
25
|
+
-- Enable RLS on the table
|
|
26
|
+
alter table orders enable row level security;
|
|
27
|
+
|
|
28
|
+
-- Create policy for users to see only their orders
|
|
29
|
+
create policy orders_user_policy on orders
|
|
30
|
+
for all
|
|
31
|
+
using (user_id = current_setting('app.current_user_id')::bigint);
|
|
32
|
+
|
|
33
|
+
-- Force RLS even for table owners
|
|
34
|
+
alter table orders force row level security;
|
|
35
|
+
|
|
36
|
+
-- Set user context and query
|
|
37
|
+
set app.current_user_id = '123';
|
|
38
|
+
select * from orders; -- Only returns orders for user 123
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Policy for authenticated role:
|
|
42
|
+
|
|
43
|
+
```sql
|
|
44
|
+
create policy orders_user_policy on orders
|
|
45
|
+
for all
|
|
46
|
+
to authenticated
|
|
47
|
+
using (user_id = auth.uid());
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Reference: [Row Level Security](https://supabase.com/docs/guides/database/postgres/row-level-security)
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Optimize RLS Policies for Performance
|
|
3
|
+
impact: HIGH
|
|
4
|
+
impactDescription: 5-10x faster RLS queries with proper patterns
|
|
5
|
+
tags: rls, performance, security, optimization
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Optimize RLS Policies for Performance
|
|
9
|
+
|
|
10
|
+
Poorly written RLS policies can cause severe performance issues. Use subqueries and indexes strategically.
|
|
11
|
+
|
|
12
|
+
**Incorrect (function called for every row):**
|
|
13
|
+
|
|
14
|
+
```sql
|
|
15
|
+
create policy orders_policy on orders
|
|
16
|
+
using (auth.uid() = user_id); -- auth.uid() called per row!
|
|
17
|
+
|
|
18
|
+
-- With 1M rows, auth.uid() is called 1M times
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**Correct (wrap functions in SELECT):**
|
|
22
|
+
|
|
23
|
+
```sql
|
|
24
|
+
create policy orders_policy on orders
|
|
25
|
+
using ((select auth.uid()) = user_id); -- Called once, cached
|
|
26
|
+
|
|
27
|
+
-- 100x+ faster on large tables
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Use security definer functions for complex checks:
|
|
31
|
+
|
|
32
|
+
```sql
|
|
33
|
+
-- Create helper function (runs as definer, bypasses RLS)
|
|
34
|
+
create or replace function is_team_member(team_id bigint)
|
|
35
|
+
returns boolean
|
|
36
|
+
language sql
|
|
37
|
+
security definer
|
|
38
|
+
set search_path = ''
|
|
39
|
+
as $$
|
|
40
|
+
select exists (
|
|
41
|
+
select 1 from public.team_members
|
|
42
|
+
where team_id = $1 and user_id = (select auth.uid())
|
|
43
|
+
);
|
|
44
|
+
$$;
|
|
45
|
+
|
|
46
|
+
-- Use in policy (indexed lookup, not per-row check)
|
|
47
|
+
create policy team_orders_policy on orders
|
|
48
|
+
using ((select is_team_member(team_id)));
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Always add indexes on columns used in RLS policies:
|
|
52
|
+
|
|
53
|
+
```sql
|
|
54
|
+
create index orders_user_id_idx on orders (user_id);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Reference: [RLS Performance](https://supabase.com/docs/guides/database/postgres/row-level-security#rls-performance-recommendations)
|
package/package.json
CHANGED