db-context-postgres
Skill10 starsChanged 34 days agoMITView on GitHub
Validate that a non-Supabase Postgres database (Cloud SQL, RDS, self-hosted) is reachable, introspect a scoped subset of its schema, and persist it as DB_CONTEXT.md. Read-only, opt-in. Use when work touches that database and planning needs verified schema, or DB_CONTEXT.md is stale. Do not use without a task (run task-init first), when the task touches no database, for Supabase (use db-context-supabase), or to record a schema decision (use decision-interview).
In this repository98 other files it gives its agents.
- AGENTS.mdAGENTS.md
- a11y-auditSkill
- ai-feature-eval-harnessSkill
- api-contract-reviewSkill
- api-runtime-verifySkill
- apply-sweep-triageSkill
- approve-planSkill
- approve-proposedSkill
- app-runtime-verifySkill
- atom-audit-fleetSkill
- atom-auditSkill
- autonomous-boardSkill
- autonomous-readinessSkill
- autonomous-runSkill
- backend-system-designSkill
- branch-commitSkill
- capture-observationSkill
- capture-referencesSkill
- code-context-mapSkill
- code-locateSkill
- color-contrast-architectSkill
- compact-task-memorySkill
- component-specSkill
- contract-signoffSkill
- db-context-supabaseSkill
- decision-interviewSkill
- delivery-assetSkill
- design-bootstrapSkill
- design-spec-reviewSkill
- direction-adjustSkill
- external-research-fleetSkill
- external-researchSkill
- extract-foundations-from-screensSkill
- feature-library-scout-fleetSkill
- feature-library-scoutSkill
- foundation-auditSkill
- frontend-architecture-reviewSkill
- frontend-system-designSkill
- godot-runtime-verifySkill
- godot-scene-planSkill
- graphql-contract-reviewSkill
- harvest-session-learningsSkill
- image-to-specSkill
- impact-analysisSkill
- implement-approved-sliceSkill
- implementation-planSkill
- implement-fleetSkill
- implement-slice-complementSkill
- im-stuckSkill
- incident-triageSkill
- invariants-and-non-goalsSkill
- inventory-snapshotSkill
- journey-mapSkill
- jtbd-switch-interviewerSkill
- mcp-server-vetSkill
- migration-safety-stewardSkill
- pattern-docSkill
- performance-budgetSkill
- portfolio-reviewSkill
- post-deploy-verifierSkill
- The first 60 shown.
The file
Show its rules and text
We split this skill into the rules it gives an agent
16 rules. About 0 are common, 5 are distinctive, and 11 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
11
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 25
Read these sections in WORKFLOW_OPERATING_SYSTEM.md first:
- Distinctive: line 33
Read additional sections only when relevant to this command's role.
- Distinctive: line 61
Do not implement production code, migrations, or destructive SQL.
- Very specific: line 62
Only issue read-only introspection via psql (e.g.
- Distinctive: line 63
Do not invent tables, columns, types, indexes, foreign keys, policies, triggers, or functions.
- Very specific: line 64
Always record Last refreshed: as today's date in YYYY-MM-DD format, the resolved host/database identifier, and the server version (SELECT …
- Distinctive: line 65
Never dump the entire database.
- Very specific: line 68
Do not modify other task-scoped artifacts (TASK_STATE.md, DECISIONS.md, IMPLEMENTATION_PLAN.md, IMPACT_ANALYSIS.md, …
- Very specific: line 69
Treat task-memory write policy per WORKFLOW_OPERATING_SYSTEM.md: write the file and mark it APPLIED.
- Very specific: line 72
Never log passwords or full DATABASE_URL values in the snapshot or transcript.
- Very specific: line 150
Follow ## Global output contract in WORKFLOW_OPERATING_SYSTEM.md for APPLIED / PROPOSED / SKIP rules.
- Very specific: line 160
Every column type, index, foreign key, policy, extension, trigger, and function entry is grounded in the live psql / pg_dump output.
- Distinctive: line 161
No destructive SQL was issued.
- Very specific: line 162
No credentials are leaked: passwords and full DATABASE_URL values never appear in the snapshot or transcript.
- Very specific: line 163
No task-scoped artifact other than DB_CONTEXT.md and (at most) a single ## DB context cross-link in SOURCE_OF_TRUTH.md is modified.
- Very specific: line 168
Before declaring this output done, confirm it satisfies the shared Definition of done (command outputs) and Gate conditions in …
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Act as a senior/staff engineering database context capture for the active task, scoped to a generic Postgres deployment (GCP Cloud SQL, GKE Autopilot Postgres, self-hosted, AWS RDS, etc.) accessed via psql or pg_dump.
Goal:
Validate that connection params resolve to a reachable Postgres instance, introspect a user-scoped subset of the schema (extensions, tables, columns, indexes, foreign keys, and optionally RLS policies and functions), and persist the result as DB_CONTEXT.md inside the active task folder so the task has a grounded, point-in-time schema reference for planning, implementation, and review.
This command is opt-in. It is not part of the default task initialization flow; run it after task-init only when the task actually touches Postgres data, schema, or RLS.
Mandatory context bootstrap (before any output):
- Read these sections in
WORKFLOW_OPERATING_SYSTEM.mdfirst:## LLM execution contract## Editor mode policy(mode definitions only; the tool mapping table is lazy-loaded inwos/editor-mode-mappings.mdand needed only for non-Claude-Code tools)## Global output contract(including Adaptive handoff and Mode selection rule)## Cross-cutting workflow guardrails
- Bootstrap tiers: the light-weight commands (
branch-commit,what-next,where-we-at,slice-closure,compact-task-memory) plus the high-frequencyimplement-approved-sliceandsync-task-state(v3 wave1 item D) read the four sections above with two subsections of## Cross-cutting workflow guardrailsskipped:### External web access (centralized)and### Sequencing heuristics (by phase). Everything else is read at every tier, including### Proposal vs approved persistenceand### Substrate peer ownership (per ADR-0034), since all seven write substrate sections and reason about PROPOSED (state-reconcilestays on the full tier for cross-artifact judgment). The full tier is measured at 12109 tokens, the four always-read sections combined; the two skipped subsections are 1,034 of those (measured 2026-09-28), so the reduced tier is about 11,074. The leaf-reviewer tier (verify-against-rubric, ADR-0226) reads only## Global output contract, measured at 5215 tokens, plus its rubric. - Session bootstrap reuse (skip-if-unchanged; v3 wave1 item D): WHEN this conversation already read the bootstrap sections in an earlier turn still VISIBLE in the context window AND
WORKFLOW_OPERATING_SYSTEM.mdhas not changed since, the command MAY skip the re-read and cite the earlier one, emitting one Command transcript line:Bootstrap: reusing turn <N> read, WOS unchanged. Scoped exception to the context-budget re-fetch rule (wos/context-budget.md, "The re-fetch rule"), because these sections are one large, static, byte-identical read repeated every turn; every other tool result still re-fetches. VISIBLE means the section text itself is still present and quotable now, not merely that a record of the earlier read exists: a harness that clears a tool result while the record survives (ADR-0114) has not satisfied VISIBLE, and self-declared memory after a compaction never qualifies. A stateless-per-turn harness is excluded. The transcript line is mandatory; a silent skip is invalid output. - Resolving the spec and
wos/<topic>.md: canonical repository FIRST. Otherwise use active-adapter docs:~/.claude/workflow-docs(CLAUDE_WORKFLOW_DOCS_DIR),~/.cursor/workflow-docs(WORKFLOW_DOCS_DIR; project.cursor/workflow-docson project installs),~/.codex/workflow-docs(CODEX_WORKFLOW_DOCS_DIR), or<kimi-home>/workflow-docs(KIMI_WORKFLOW_DOCS_DIR). Nonempty overrides win. Kimi home:KIMI_CODE_HOME, else existing~/.kimi-code, else existing~/.kimi, default~/.kimi-code. Use one root for both paths; try other adapters if absent or unknown. Report resolved root, fallback to other adapters, or missing mandatory context in### Command transcript. Installed snapshots refresh and prune retired topics only on sync. - Read additional sections only when relevant to this command's role.
- Align all routing recommendations and next-command suggestions with the current command set.
- Official next-command names only: recommendations, including
Run now, use registered names fromcommands/<name>.mdorcommands/<name>/SKILL.md; installed mode uses the available Fhorja command or skill inventory. No invented aliases.Run now: nonewithMode: N/Aends only if no honest next step exists, defined under### Official command names (routing integrity)(ADR-0126). Required inputs: - active task path (or enough context to resolve
projects/<client>__<project>/active/YYYY-MM-DD_<task-slug>/) - connection params, provided via one of:
- environment variables
PGHOST,PGPORT,PGUSER,PGDATABASE,PGPASSWORD(orPGSSLMODE) - a
DATABASE_URL(postgres://user:pass@host:port/dbname?sslmode=...) - a
~/.pgpassentry plus host/db identifiers
- environment variables
- scope of introspection, supplied by the user as one or more of:
- list of table names (qualified
schema.tableor unqualified for the defaultpublicschema) - list of schemas to include in full (use sparingly; large schemas should be narrowed)
- list of table names (qualified
- depth flag (one of):
tables-only: tables, columns with types, primary keys, not-null flags, indexes, foreign keystables+rls(default):tables-onlyplus row-level security policies for each in-scope table when RLS is in usefull:tables+rlsplus relevant functions, triggers, extensions, and server version metadata
- optional: refresh flag (
refreshto regenerate; default is to fail withNO_OP_TRACEif a non-staleDB_CONTEXT.mdalready exists for the same scope)
Project repository files to read:
- projects/
<client>__<project>/active/YYYY-MM-DD_<task-slug>/TASK_STATE.md - projects/
<client>__<project>/active/YYYY-MM-DD_<task-slug>/SOURCE_OF_TRUTH.md - projects/
<client>__<project>/active/YYYY-MM-DD_<task-slug>/DB_CONTEXT.md (only if it already exists, for refresh comparison)
Project repository files to update:
- projects/
<client>__<project>/active/YYYY-MM-DD_<task-slug>/DB_CONTEXT.md (create or fully regenerate; never partial-merge) - projects/
<client>__<project>/active/YYYY-MM-DD_<task-slug>/SOURCE_OF_TRUTH.md (append-only: add a single## DB contextsection pointing to./DB_CONTEXT.mdif not already present)
Operating rules:
- Do not implement production code, migrations, or destructive SQL.
- Only issue read-only introspection via
psql(e.g.\dt,\d+, queries againstinformation_schema/pg_catalog) orpg_dump --schema-only --no-owner --no-privileges. Never runINSERT/UPDATE/DELETE/DROP/ALTER/TRUNCATE/GRANT/REVOKEfor any reason; redirect the user to the appropriate implementation command and stop. - Do not invent tables, columns, types, indexes, foreign keys, policies, triggers, or functions. Every recorded field must come from the live introspection output or from explicit user-supplied scope.
- Always record
Last refreshed:as today's date inYYYY-MM-DDformat, the resolved host/database identifier, and the server version (SELECT version()). Stale snapshots without these fields are invalid. - Never dump the entire database. If the target schema has more than 25 tables and the user provided no narrowing list, ask one targeted question to narrow scope before introspecting.
- Re-run policy: regeneration replaces
DB_CONTEXT.mdin full. Do not partial-merge. Handwritten notes belong inDECISIONS.mdorTASK_STATE.md. State this explicitly when proposing a refresh that overwrites an existing file. - Cross-link policy:
SOURCE_OF_TRUTH.mdgets at most one## DB contextsection with a single relative pointer to./DB_CONTEXT.md. Do not duplicate schema content intoSOURCE_OF_TRUTH.md. - Do not modify other task-scoped artifacts (
TASK_STATE.md,DECISIONS.md,IMPLEMENTATION_PLAN.md,IMPACT_ANALYSIS.md,INVARIANTS_AND_NON_GOALS.md,TEST_STRATEGY.md,PR_PACKAGE.md, slice files). - Treat task-memory write policy per
WORKFLOW_OPERATING_SYSTEM.md: write the file and mark itAPPLIED. - Mark fields as
[unclear from psql output]when the introspection returned ambiguous or partial data; never fill gaps with guesses. - Output is intentionally bounded. Do not produce schema analysis, ER diagrams, or design recommendations beyond the snapshot itself; routing those follow-ups belongs in subsequent commands (
impact-analysis,decision-interview,implementation-plan). - Never log passwords or full
DATABASE_URLvalues in the snapshot or transcript; record only host + database name + user (never the password component). - Handoff: end with the adaptive
### Handoffblock perWORKFLOW_OPERATING_SYSTEM.md## Global output contract. DefaultRun now: read TASK_STATE.mdLast completed step; if it wastask-init, default toimpact-analysis; if uncertain, default towhat-next.
Snapshot format (canonical):
# DB_CONTEXT
## Snapshot metadata
- Provider: postgres
- Deployment: <cloud-sql | gke-autopilot | self-hosted | rds | other>
- Host/database: <host>/<dbname> (user: <user>)
- Server version: <output of SELECT version()>
- Last refreshed: YYYY-MM-DD
- Depth: tables-only | tables+rls | full
- Scope: <comma-separated list of schema.table or schema.* entries actually introspected>
## Extensions (only when depth = full)
- <extension_name> <version>
## Tables
### <schema>.<table>
- Columns:
- <column_name> <type> [PK] [NOT NULL] [DEFAULT <expr>]
- Primary key: <column(s)>
- Foreign keys:
- <column> -> <ref_schema>.<ref_table>(<ref_column>) [ON DELETE <action>] [ON UPDATE <action>]
- Indexes (non-PK, non-unique-constraint):
- <index_name> ON (<columns>) [UNIQUE] [WHERE <predicate>]
- RLS enabled: yes | no | n/a
- RLS policies (only when depth >= tables+rls and RLS enabled):
- <policy_name> [<command: SELECT/INSERT/UPDATE/DELETE/ALL>] FOR <role>: <USING expression> / <WITH CHECK expression>
## Triggers (only when depth = full)
- <trigger_name> on <schema>.<table>: <trigger definition from live introspection>
## Functions (only when depth = full)
### <schema>.<function_name>(<args>)
- Returns: <return_type>
- Language: <plpgsql | sql | c | ...>
- Security: <DEFINER | INVOKER>
- One-line summary: <verbatim COMMENT ON FUNCTION if present, else "[no COMMENT in source]">Sections that have no content for the chosen depth must be omitted entirely rather than left empty.
Required output:
- Resolved active task path.
- Result of the connectivity precondition check (
psql -c "SELECT 1"or equivalent succeeded / failed, plus resolved host/db/user; never the password). - Resolved scope (tables/schemas) and depth flag.
- Whether this is a
createor arefreshofDB_CONTEXT.md, and (on refresh) a one-line drift summary versus the prior snapshot (e.g., "3 new columns, 1 dropped table, RLS toggled onpublic.orders"). - Exact content for
DB_CONTEXT.mdusing the canonical snapshot format. - Exact patch to
SOURCE_OF_TRUTH.mdadding the## DB contextcross-link, orSKIPif the link is already present. - Recommended next command (must exist as
commands/<name>.mdorcommands/<name>/SKILL.md; verify against directory listing before output). In installed mode use the available Fhorja inventory. - Recommended editor mode for that next command.
- Why that is the correct next step.
Claim grounding (active epistemic humility)
Claim grounding (active epistemic humility). This block governs what you may assert and how you record it. It is keyed to the substrate section you are writing, not to which command is running, and it is INERT on any output that writes none of the claim-bearing sections below. Full contract and rationale: wos/active-epistemic-humility.md.
- When this applies. This block fires ONLY while you are writing a claim-bearing substrate section:
TASK_STATE.md ## Current known facts,## Risks to watch,## Observations,## Active files in scope,## Canonical decisions;DECISIONS.md ## Locked decisions;IMPLEMENTATION_PLAN.md ## Current gaps,## Risks and mitigations;IMPACT_ANALYSIS.md;EXTERNAL_RESEARCH.md;REFERENCES.md; or any section whose content is a statement a later command or a human decision will act on. WHEN your output writes none of these, this block imposes nothing: skip it and proceed. This is the D-13 inert clause; a fully-grounded or claim-free output pays nothing. - The unit is the load-bearing claim. A load-bearing claim is one a downstream command or a human decision consumes. A passing aside is not load-bearing; a statement someone will act on is. Apply the rest of this block per load-bearing claim, not per sentence.
- Ground it or abstain. Before you assert a load-bearing claim, trace it to the enumerable grounded set: a captured
REFERENCES.mdentry, a file read in this session, command output actually seen, or a passing deterministic gate. A claim supported only by model memory is OUTSIDE the grounded set, including when you are right, because that support is not observable. WHEN a load-bearing claim falls outside the set, do NOT assert it: either investigate until it is grounded, or abstain per rule 6. - Status records provenance, never confidence. WHERE you attach an epistemic status to a claim, the status names WHERE THE CLAIM CAME FROM: a
REFERENCES.mdentry title, a file path plus line, or the gate output it came from. It SHALL NOT express a degree of certainty. Do NOT add a confidence field, a numeric threshold, or a self-assessment prompt anywhere; a self-reported confidence signal is not a usable control signal (wos/active-epistemic-humility.mdPart 1.3). A status whose referent slot is empty is read as UNKNOWN, not as a weak yes. - Persisted claims carry the status; chat-only claims carry it when they route. Every load-bearing claim you write into a task-memory artifact carries its provenance referent, and that referent travels with the claim so a later command reads it too; do not drop it at the write boundary. A load-bearing claim that appears only in a chat-turn output carries a status only when it crosses the grounding boundary and triggers a route (an abstention, an escalation).
- Abstain as a routed continuation, never a bare refusal. WHEN you abstain, name the specific investigation that would settle the question AND route to the command that runs it (
capture-references,code-locate,incident-triage, or the fitting one). A withholding that stalls the work is invalid output. Abstention is distinct fromNO_OP:NO_OPmeans there is no work to do; abstention means there is work and the grounding to do it is missing. - An unfired gate is not evidence. The absence of a fired check does not mean grounding existed. Do not read silence here as a pass.
Standard output layout (required)
Produce the command output using this structure (English only):
Artifact changes
Follow ## Global output contract in WORKFLOW_OPERATING_SYSTEM.md for APPLIED / PROPOSED / SKIP rules. Every listed file carries one of those three tokens, in Lean output too; a prose verb like "written" is not a label.
Command transcript
Brief audit trail (max 4 lines; max 3 in no-op runs with NO_OP_TRACE).
Handoff
Use the adaptive ending format of WORKFLOW_OPERATING_SYSTEM.md ## Global output contract. Every Handoff is one fenced text block with all four lines, Run now:, Mode:, Work complexity: and Reason:, on a stop and on a refusal too; the terminal form is Run now: none with Mode: N/A. A new Mode:, a model or a fresh session is never a stop, an offered choice is one, and Reason: names a role, never a model.
Definition of done (command output)
- The connectivity precondition check is performed first and its result is reported; if it failed, no
DB_CONTEXT.mdcontent is proposed and the run ends withNO_OP_TRACEplus the actionable configuration line (missing env var, unreachable host, auth failure, etc.). - The proposed
DB_CONTEXT.mdincludesProvider,Deployment,Host/database,Server version,Last refreshed,Depth, andScopemetadata, and at least one populated## Tablesentry (or an explicitNO_OP_TRACEif the requested scope returned no tables). - Every column type, index, foreign key, policy, extension, trigger, and function entry is grounded in the live
psql/pg_dumpoutput; no field is fabricated. Ambiguous fields are marked[unclear from psql output]. - No destructive SQL was issued. Only read-only introspection was used.
- No credentials are leaked: passwords and full
DATABASE_URLvalues never appear in the snapshot or transcript. - No task-scoped artifact other than
DB_CONTEXT.mdand (at most) a single## DB contextcross-link inSOURCE_OF_TRUTH.mdis modified. - On refresh, the prior
DB_CONTEXT.mdis fully replaced (no partial merge), and the drift summary in the required output makes the change auditable. ### Artifact changesmarks the patches asAPPLIED.- The basename in the
Run now:line corresponds to a real file incommands/<name>.mdorcommands/<name>/SKILL.md. In installed mode use the available Fhorja inventory. - Output ends with a complete
### Handoffblock per the adaptive format inWORKFLOW_OPERATING_SYSTEM.md## Global output contract. - Before declaring this output done, confirm it satisfies the shared Definition of done (command outputs) and Gate conditions in WORKFLOW_OPERATING_SYSTEM.md.
Quality bar: Optimize for fidelity to the live Postgres schema, point-in-time auditability, narrow scope (no full-DB dumps), credential hygiene, and minimal disruption to whatever task-scoped work was in progress before this capture.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

