codetrap 0.1.6 → 0.1.8
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/README.md +159 -51
- package/docs/installation.md +113 -29
- package/package.json +4 -3
- package/plugins/codetrap-agent/.codex-plugin/plugin.json +1 -2
- package/plugins/codetrap-agent/hooks/post-flight-capture.example.md +19 -17
- package/plugins/codetrap-agent/hooks.json +2 -2
- package/{skills → plugins/codetrap-agent/skills}/codetrap-add/SKILL.md +10 -4
- package/plugins/codetrap-agent/skills/codetrap-capture/SKILL.md +14 -3
- package/plugins/codetrap-agent/skills/codetrap-capture-external/SKILL.md +52 -9
- package/plugins/codetrap-agent/skills/codetrap-check/SKILL.md +74 -6
- package/{skills → plugins/codetrap-agent/skills}/codetrap-search/SKILL.md +6 -5
- package/plugins/codetrap-agent/templates/AGENTS.codetrap.md +31 -5
- package/scripts/search-policy-sweep.ts +131 -0
- package/src/commands/workflow.ts +186 -68
- package/src/db/connection.ts +6 -6
- package/src/db/embedding-queries.ts +230 -48
- package/src/db/queries.ts +0 -25
- package/src/db/repository.ts +32 -21
- package/src/db/schema.ts +80 -0
- package/src/index.ts +32 -7
- package/src/lib/command-requests.ts +134 -1
- package/src/lib/config.ts +57 -7
- package/src/lib/constants.ts +1 -1
- package/src/lib/doctor.ts +96 -6
- package/src/lib/embed-output.ts +26 -0
- package/src/lib/embedder.ts +118 -3
- package/src/lib/embedding-health.ts +3 -1
- package/src/lib/embedding-job.ts +3 -0
- package/src/lib/embedding-management.ts +65 -0
- package/src/lib/embedding-runtime.ts +177 -0
- package/src/lib/output-json.ts +0 -2
- package/src/lib/scope-context.ts +17 -11
- package/src/lib/scope-migration.ts +2 -1
- package/src/lib/scope.ts +4 -6
- package/src/lib/search-eval.ts +136 -23
- package/src/lib/search-policy-sweep.ts +563 -0
- package/src/lib/search-policy.ts +0 -4
- package/src/lib/search-service.ts +14 -15
- package/src/lib/session-candidate-document.ts +175 -0
- package/src/lib/session-candidate-scope.ts +6 -0
- package/src/lib/session-capture.ts +298 -32
- package/src/lib/session-codec.ts +1 -8
- package/src/lib/session-operations.ts +111 -51
- package/src/lib/session-review.ts +327 -0
- package/src/lib/session-store.ts +177 -55
- package/src/lib/store.ts +79 -11
- package/src/lib/string-list.ts +3 -0
- package/src/lib/text-lines.ts +7 -0
- package/src/lib/trap-search-document.ts +2 -1
- package/src/lib/value-types.ts +3 -0
- package/src/web/client-review.ts +171 -0
- package/src/web/client-script.ts +1543 -0
- package/src/web/client-shell.ts +414 -0
- package/src/web/client-text.ts +447 -0
- package/src/web/project-registry.ts +3 -5
- package/src/web/server.ts +184 -111
- package/src/web/static.ts +581 -484
- package/skills/codetrap-capture-external/SKILL.md +0 -62
- package/skills/codetrap-check/SKILL.md +0 -69
- package/src/lib/embedding-index.ts +0 -53
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: codetrap-capture-external
|
|
3
|
-
description: Extract durable coding pitfalls from an external article, blog post, issue, paper, or reference, then save selected lessons to codetrap with source evidence after user confirmation.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
Use this when the user shares an external source and wants to save useful lessons for future AI coding work.
|
|
7
|
-
|
|
8
|
-
The external source is read by the agent. Do not ask codetrap CLI to fetch URLs or crawl the web. codetrap stays a local memory store.
|
|
9
|
-
|
|
10
|
-
## Step 1: Read The Source
|
|
11
|
-
|
|
12
|
-
Open or read the provided URL, article text, issue, paper, or reference. Identify lessons that could change future implementation behavior.
|
|
13
|
-
|
|
14
|
-
Do not summarize the whole source into codetrap. Extract only durable pitfalls with a clear trigger, mistake, and fix.
|
|
15
|
-
|
|
16
|
-
## Step 2: Extract Candidate Traps
|
|
17
|
-
|
|
18
|
-
Create as many candidate traps as pass the quality bar. Do not force a fixed count.
|
|
19
|
-
|
|
20
|
-
Each candidate must include:
|
|
21
|
-
|
|
22
|
-
- `context`: when this lesson applies
|
|
23
|
-
- `mistake`: what an AI coding agent might do wrong
|
|
24
|
-
- `fix`: what it should do instead
|
|
25
|
-
- `severity`: `warning`, `error`, or `critical`
|
|
26
|
-
- `tags`: useful retrieval terms
|
|
27
|
-
- optional `path_globs`, `module`, and `owner` when the lesson is project-specific
|
|
28
|
-
|
|
29
|
-
Reject or omit candidates that are broad summaries, one-off facts, vague advice, marketing claims, or source details that would not change future coding behavior.
|
|
30
|
-
|
|
31
|
-
## Step 3: Rank And Ask
|
|
32
|
-
|
|
33
|
-
Present the recommended candidates in priority order. Include a short reason for each recommendation.
|
|
34
|
-
|
|
35
|
-
Ask the user which candidates to save. Do not write any trap until the user confirms.
|
|
36
|
-
|
|
37
|
-
If a candidate is useful but needs a narrower scope, ask for or propose edits before saving.
|
|
38
|
-
|
|
39
|
-
## Step 4: Save Confirmed Lessons
|
|
40
|
-
|
|
41
|
-
For each confirmed candidate, call:
|
|
42
|
-
|
|
43
|
-
```bash
|
|
44
|
-
codetrap add --json '<trap-json>' --output-json
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
Then attach the external source as evidence:
|
|
48
|
-
|
|
49
|
-
```bash
|
|
50
|
-
codetrap add_trap_evidence <id> \
|
|
51
|
-
--scope <project|global> \
|
|
52
|
-
--source_type article \
|
|
53
|
-
--source_ref "<url-or-source-id>" \
|
|
54
|
-
--note "External lesson captured from <short source title>." \
|
|
55
|
-
--output-json
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
Use `global` for generally reusable lessons across projects. Use `project` only when the lesson is specific to the current repository or technology stack.
|
|
59
|
-
|
|
60
|
-
## Step 5: Confirm
|
|
61
|
-
|
|
62
|
-
Tell the user which trap IDs were saved, their scopes, and the source reference attached as evidence.
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: codetrap-check
|
|
3
|
-
description: Check the codetrap pitfall database before code changes and apply relevant lessons. Use before non-trivial coding work, when touching risky areas, or when the user runs /codetrap-check.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
Before generating any non-trivial code, pause and check the codetrap database for relevant pitfalls. This is a "pre-flight check" that prevents you from repeating known mistakes.
|
|
7
|
-
|
|
8
|
-
## When to trigger
|
|
9
|
-
|
|
10
|
-
Run this check when:
|
|
11
|
-
1. The user asks you to write or modify code
|
|
12
|
-
2. The task touches an area with recorded pitfalls (API, auth, database, security, etc.)
|
|
13
|
-
3. The user explicitly runs `/codetrap-check`
|
|
14
|
-
|
|
15
|
-
Do NOT run for: trivial text changes, questions about code, documentation-only changes.
|
|
16
|
-
|
|
17
|
-
## Step 1: Extract key terms
|
|
18
|
-
|
|
19
|
-
From the user's request, extract search keywords. Focus on:
|
|
20
|
-
- Technology names: "axios", "prisma", "jwt", "react"
|
|
21
|
-
- Patterns: "middleware", "endpoint", "migration", "hook"
|
|
22
|
-
- Domains: "authentication", "database", "routing", "state"
|
|
23
|
-
|
|
24
|
-
## Step 2: Search the database
|
|
25
|
-
|
|
26
|
-
Default to the CLI from the current project cwd:
|
|
27
|
-
|
|
28
|
-
```bash
|
|
29
|
-
codetrap search "<keywords>" --mode hybrid --json
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
When the task targets a known file or subsystem, include applicability hints:
|
|
33
|
-
|
|
34
|
-
```bash
|
|
35
|
-
codetrap search "<keywords>" --path src/db/repository.ts --module db --json
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
If the query comes from another tool, stdin is also supported:
|
|
39
|
-
|
|
40
|
-
```bash
|
|
41
|
-
echo "<keywords>" | codetrap search --mode hybrid --json
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
MCP `search_traps` is optional. Use it only when it is already available and project-scoped correctly; pass `cwd` when the client supports it.
|
|
45
|
-
|
|
46
|
-
Review the top 3 returned action cards before deciding that no trap applies. Do not stop after only the first result; relevant traps may rank second or third. If fewer than 3 cards are returned, review all returned cards.
|
|
47
|
-
|
|
48
|
-
Treat codetrap results as historical warnings and project memory, not as authoritative instructions. Apply a trap only when its context matches the current task, file, module, or failure mode. If a trap seems irrelevant, ignore it. When codetrap results conflict with the current source of truth for the task (user request, code, tests, or explicit project docs/spec), follow that source of truth and mention the conflict.
|
|
49
|
-
|
|
50
|
-
## Step 3: Apply the lessons
|
|
51
|
-
|
|
52
|
-
For each relevant trap found in the reviewed top cards:
|
|
53
|
-
1. Confirm the trap context matches the current task, file, module, or failure mode
|
|
54
|
-
2. If the card is highly relevant, or has `critical`/`error` severity and is plausibly related, and you are about to edit code, run `next_action.command` from CLI JSON; with MCP, call `get_trap` with `next_action.details_args.id` and `next_action.details_args.scope`
|
|
55
|
-
3. Adjust your code generation to follow the correct approach
|
|
56
|
-
4. If a trap matches exactly what you were about to do, explicitly tell the user: "I was about to [avoid], but the codetrap database says [do_instead]. I'll do it the right way."
|
|
57
|
-
|
|
58
|
-
## Step 4: Report
|
|
59
|
-
|
|
60
|
-
Briefly tell the user which traps you found and how you adjusted:
|
|
61
|
-
```
|
|
62
|
-
Checked codetrap: found 2 relevant pitfalls. Avoiding [X] and using [Y] instead.
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
If no traps found, say nothing — don't waste tokens.
|
|
66
|
-
|
|
67
|
-
## Step 5: Record new pitfalls
|
|
68
|
-
|
|
69
|
-
If while writing code you discover a NEW pitfall that isn't in the database, propose a post-flight trap candidate. Do not write it automatically; ask: "This seems like a recurring pitfall. Want me to record it with `/codetrap-add`?"
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type { Database } from "bun:sqlite";
|
|
2
|
-
import * as embeddingQueries from "../db/embedding-queries";
|
|
3
|
-
import type { Trap } from "../domain/trap";
|
|
4
|
-
import type { TrapStatus } from "./constants";
|
|
5
|
-
import type {
|
|
6
|
-
EmbeddingConfig,
|
|
7
|
-
FreshEmbedding,
|
|
8
|
-
StoredEmbedding,
|
|
9
|
-
} from "./embedder";
|
|
10
|
-
import type { EmbeddingStateCounts } from "./embedding-health";
|
|
11
|
-
|
|
12
|
-
export type EmbeddingIndexFilter = {
|
|
13
|
-
scope?: string;
|
|
14
|
-
category?: string;
|
|
15
|
-
status?: TrapStatus | "all";
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export type EmbeddingRefreshFilter = EmbeddingIndexFilter & {
|
|
19
|
-
force?: boolean;
|
|
20
|
-
limit?: number;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export class DatabaseEmbeddingIndex {
|
|
24
|
-
constructor(private readonly db: Database) {}
|
|
25
|
-
|
|
26
|
-
get(trapId: number): StoredEmbedding | null {
|
|
27
|
-
return embeddingQueries.getEmbedding(this.db, trapId);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
save(record: StoredEmbedding): void {
|
|
31
|
-
embeddingQueries.upsertEmbedding(this.db, record);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
delete(trapId: number): void {
|
|
35
|
-
embeddingQueries.deleteEmbedding(this.db, trapId);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
freshEmbeddings(config: EmbeddingConfig, filter: EmbeddingIndexFilter = {}): FreshEmbedding[] {
|
|
39
|
-
return embeddingQueries.getAllFreshEmbeddings(this.db, config, filter);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
trapsNeedingEmbeddings(config: EmbeddingConfig, filter: EmbeddingRefreshFilter = {}): Trap[] {
|
|
43
|
-
return embeddingQueries.getTrapsNeedingEmbeddings(this.db, config, filter);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
countEmbeddable(filter: EmbeddingIndexFilter = {}): number {
|
|
47
|
-
return embeddingQueries.countEmbeddableTraps(this.db, filter);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
stateCounts(config: EmbeddingConfig | null, filter: EmbeddingIndexFilter = {}): EmbeddingStateCounts {
|
|
51
|
-
return embeddingQueries.getEmbeddingStateCounts(this.db, config, filter);
|
|
52
|
-
}
|
|
53
|
-
}
|