history-sql-retrieval

history-sql-retrieval is a skill for Claude Code, Codex from datagallery-ai/dataagent. It costs 130 tokens per session (3,315 once invoked), scanned A, original, Apache-2.0.

A search workflow for finding similar SQL files in a local history. It returns evidence from previous queries, such as filters, grouped fields, source tables, joins, and function usage, without treating old SQL as verified truth.

In plain words
What is it for?
Use it as a reference during new feature development when you need examples of earlier SQL for similar user actions, output keys, or source tables.
Why use it?
It saves time when designing a new warehouse query and helps reveal how related data was handled before. It also makes clear that older SQL may no longer match the current schema or rules.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it as a reference during new feature development when you need examples of earlier SQL for similar user actions, output keys, or source tables.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/datagallery-ai/dataagent/history-sql-retrieval
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add datagallery-ai/dataagent --skill history-sql-retrieval
Clone the repo
git clone --depth 1 https://github.com/datagallery-ai/dataagent

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for history-sql-retrieval

README.md
[![agentmods](https://agentmods.dev/badge/skills/datagallery-ai/dataagent/history-sql-retrieval/github.svg)](https://agentmods.dev/skills/datagallery-ai/dataagent/history-sql-retrieval)
Your own site
<a href="https://agentmods.dev/skills/datagallery-ai/dataagent/history-sql-retrieval"><img src="https://agentmods.dev/badge/skills/datagallery-ai/dataagent/history-sql-retrieval/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for history-sql-retrieval

Your own site · 80×15
<a href="https://agentmods.dev/skills/datagallery-ai/dataagent/history-sql-retrieval"><img src="https://agentmods.dev/badge/skills/datagallery-ai/dataagent/history-sql-retrieval.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 130 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,315 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00130 $0.03315
Opus 5.5 $0.00052 $0.01326
Sonnet 5.5 $0.00026 $0.00663
Haiku 4.5 $0.00013 $0.00331

Measured 2d ago against content hash 3fbd19a714dd, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

history-sql-retrieval scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

dataagent/plugins/de-agent/history-skills/history-sql-retrieval/SKILL.md · 147 lines

How it starts

The opening of the file, as written. The whole thing — 147 lines — stays where its author put it; the contents beside it link to each section on GitHub.

历史SQL检索(相似历史SQL召回)

主 Agent 会以自然语言发起历史SQL检索请求,请求中会给出:计划输出的特征清单及每个特征的用户行为、本次输出主键、可选的"源表必须包含"要求、加分项。你的任务是只使用本地文件工具(glob / grep / read_file / ls),从历史 SQL 文件库中找出最相近的历史SQL并结构化返回。

职责边界

  • 你返回的是"历史SQL里实际怎么写"的证据摘录(过滤条件、GROUP BY、UDF 调用、列用法),不是"建议怎么写"的 SQL 设计--设计由主 Agent 负责。
  • 历史SQL是未验证的参考:schema 可能已经漂移,摘录时如实转述,不做正确性背书。
  • 只读文件,绝不修改任何文件;绝不编造历史SQL;找不到就如实说找不到。

历史SQL文件库长什么样

  • 位于 本次委派明确提供的语料根目录下的 .sql 文件,用 ls / glob 即可发现。glob/grep 必须显式传 path = 本次委派中的语料根目录绝对路径(不传时缺省只搜 workspace 根,会漏掉整个语料库)。
  • 文件名 = 该SQL的输出表名(全大写下划线风格),与数仓表名小写一一对应:ADS_AGALG_FEATURE_USERID_CALL_PACKAGE_APP_SEQ_14D_DM.sql ↔ 表 biads.ads_agalg_feature_userid_call_package_app_seq_14d_dm。
  • 少数输出表存在多份历史SQL,其文件名带 _ + 12 位十六进制后缀--后缀仅用于区分同表多份文件,不属于表名;⌈输出表⌋一律以 SQL 正文(INSERT/CREATE 目标)为准,不得按文件名直接小写化还原表名。
  • 文件内容以 INSERT OVERWRITE TABLE ... PARTITION(...) SELECT ... 为主体,可从中解析出:输出表、GROUP BY(输出主键)、FROM/JOIN(源表)、WHERE(过滤口径)、UDF 调用、输出列。

第一步:识别检索请求

从主 Agent 的请求中提取:

要素 说明 必填
输出特征 + 用户行为 每个计划输出特征及其行为标注(曝光/点击/下载/激活/使用/卸载/通话/搜索/推送/计费/注册...) 是
本次输出主键 特征主键字段组合(如 imei + app_id、user_id) 是
源表必须包含 已确认源表时主 Agent 会指定(如 agapdw.dwd_hispace_client_down_tf_dm) 否
加分项 特征类型 / 时间周期 / 排序维度等 否

第二步:候选生成(只靠本地文件,两条战术并用)

T1 文件名词法预筛:用"行为词表 × 主体词表"对文件名做 glob(词表见文末),两条结果取交集;无交集时放宽为仅行为词 glob。 例:行为=下载、主键含 user_id → glob *DOWNLOAD* ∩ glob *USERID*(注意:glob 模式必须带 * 包裹关键词,裸词只能匹配字面同名的文件)。

T2 内容 grep 收敛(覆盖文件名不含行为的文件):

  • 主 Agent 指定了"源表必须包含"时:grep 该源表全名,命中的文件直接入围。
  • 未指定源表时:用行为关键词 grep 文件内容--源表名本身就编码了行为(如 down_tf、exposure、click),能命中输出表名不含行为、但源表是行为事实表的文件。
  • 候选仍多时可按主键列名(如 user_id)grep 做辅助收敛。

候选总量仍多时,按词表命中数排序,保留前 8~10 个进入第三步。

第三步:精读校验(read_file,最多读 5 个文件)

对每个候选文件解析并校验:

必须满足(M)-- 任一不满足则淘汰:

# 标准 判定方式
M1 用户行为相同 读 FROM/JOIN 的源表名判断行为(dwd_hispace_client_down_tf_dm=下载明细、*_exposure_*=曝光、*_click_*=点击…);文件头注释、过滤字段可作辅助。文件名关键词只用于预筛,不作 M1 判定依据。
M2 输出主键相同 结合最终 SELECT 投影、聚合粒度和唯一性证据判断是否与请求中的输出主键相同。GROUP BY(去掉分区列)只是粒度证据,不能自动等同用户业务主键;复杂 CTE、无 GROUP BY 或派生键无法确认时报告不确定,不得强行匹配。主键比对按 ID 体系严格区分:imei / dsid / udid / did / user_id / app_id 各自独立,绝不混同;仅做命名风格归一(user_id≈userid≈UPPER(user_id))。

Read the full file on GitHub · 147 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 147 lines · 130 tokens per session scan A 3fbd19a714dd

Subscribe to this mod's changes

history-sql-retrieval is a skill published in the GitHub repository datagallery-ai/dataagent (748 stars, last pushed 3d ago), licensed Apache-2.0. It adds 130 tokens to every session and 3,315 once invoked, about $0.0005 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-11-28.

Related

history-sql-retrieval compared with skills from other repositories

history-sql-retrieval next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
history-sql-retrievaldatagallery-ai/dataagentSkill7483d agoApache-2.0A130Claude Code, Codex
fetch-dataagentscope-ai/QwenPaw-DataSkill2085d agoApache-2.0A286Claude Code, Codex
cm-skillsagentscope-ai/QwenPaw-DataSkill2085d agoApache-2.0A73Claude Code, Codex
query-odpsagentscope-ai/QwenPaw-DataSkill2085d agoApache-2.0A111Claude Code, Codex
sql-analysisrunxhq/runxSkill106yesterdayApache-2.0A43Claude Code, Codex
setup-data-workspacedanielrosehill/Claude-Data-Analyst-pluginSkill1327d agoMITA73Claude Code
documentdb-collection-adminKnuckles-Team/documentdb-mcpSkill24d agoMITA78Claude Code, Codex