@nurix/etna 0.15.7 → 0.16.0
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/bin/etna.js +64 -13
- package/data/harness-index.json +7 -5
- package/data/harnesses/code/CLAUDE.md +3 -7
- package/data/harnesses/code/agents/harness-manager.md +4 -4
- package/data/harnesses/code/agents/maintenance.md +1 -1
- package/data/harnesses/code/harness.json +4 -3
- package/data/harnesses/code/hooks/hooks.json +3 -17
- package/data/harnesses/code/hooks/prompt-recall.js +157 -0
- package/data/harnesses/code/hooks/session-reflect.js +283 -0
- package/data/harnesses/code/skills/distiller/SKILL.md +62 -60
- package/data/harnesses/code/skills/distiller/references/docs-mode.md +21 -21
- package/data/harnesses/code/skills/distiller/references/method.md +41 -41
- package/data/harnesses/code/skills/documentation/references/templates.md +20 -27
- package/data/harnesses/code-fable/CLAUDE.md +138 -0
- package/data/harnesses/code-fable/agents/brainstorm.md +35 -0
- package/data/harnesses/code-fable/agents/change-review.md +249 -0
- package/data/harnesses/code-fable/agents/harness-manager.md +193 -0
- package/data/harnesses/code-fable/agents/maintenance.md +123 -0
- package/data/harnesses/code-fable/agents/performance-review.md +218 -0
- package/data/harnesses/code-fable/agents/spec-mode.md +56 -0
- package/data/harnesses/code-fable/harness.json +7 -0
- package/data/harnesses/code-fable/hooks/hooks.json +27 -0
- package/data/harnesses/code-fable/hooks/lib/redact.js +37 -0
- package/data/harnesses/code-fable/hooks/prompt-recall.js +157 -0
- package/data/harnesses/code-fable/hooks/session-reflect.js +283 -0
- package/data/harnesses/code-fable/rules/general.md +96 -0
- package/data/harnesses/code-fable/rules/nomenclature.md +34 -0
- package/data/harnesses/code-fable/skills/boundary/SKILL.md +262 -0
- package/data/harnesses/code-fable/skills/boundary/references/boundary-taxonomy.md +734 -0
- package/data/harnesses/code-fable/skills/brainstorm/README.md +136 -0
- package/data/harnesses/code-fable/skills/brainstorm/SKILL.md +135 -0
- package/data/harnesses/code-fable/skills/brainstorm/harvest.md +26 -0
- package/data/harnesses/code-fable/skills/brainstorm/templates/backlog.md +39 -0
- package/data/harnesses/code-fable/skills/brainstorm/templates/build.md +37 -0
- package/data/harnesses/code-fable/skills/brainstorm/templates/decisions.md +29 -0
- package/data/harnesses/code-fable/skills/brainstorm/templates/doctrine.md +31 -0
- package/data/harnesses/code-fable/skills/brainstorm/templates/domain-model.md +25 -0
- package/data/harnesses/code-fable/skills/brainstorm/templates/glossary.md +19 -0
- package/data/harnesses/code-fable/skills/brainstorm/templates/milestones.md +43 -0
- package/data/harnesses/code-fable/skills/brainstorm/templates/non-goals.md +21 -0
- package/data/harnesses/code-fable/skills/brainstorm/templates/plan-doc.md +61 -0
- package/data/harnesses/code-fable/skills/brainstorm/templates/questions.md +35 -0
- package/data/harnesses/code-fable/skills/brainstorm/templates/references.md +28 -0
- package/data/harnesses/code-fable/skills/brainstorm/templates/rejected.md +29 -0
- package/data/harnesses/code-fable/skills/brainstorm/templates/state.md +8 -0
- package/data/harnesses/code-fable/skills/brainstorm/templates/tech.md +23 -0
- package/data/harnesses/code-fable/skills/brainstorm/templates/thesis.md +21 -0
- package/data/harnesses/code-fable/skills/distiller/SKILL.md +219 -0
- package/data/harnesses/code-fable/skills/distiller/references/docs-mode.md +526 -0
- package/data/harnesses/code-fable/skills/distiller/references/method.md +166 -0
- package/data/harnesses/code-fable/skills/documentation/SKILL.md +127 -0
- package/data/harnesses/code-fable/skills/documentation/references/examples.md +193 -0
- package/data/harnesses/code-fable/skills/documentation/references/style-guide.md +288 -0
- package/data/harnesses/code-fable/skills/documentation/references/templates.md +942 -0
- package/data/harnesses/code-fable/skills/workflow-mapper/SKILL.md +430 -0
- package/data/harnesses/code-fable/skills/workflow-mapper/references/patterns.md +214 -0
- package/data/harnesses/{re → discover}/CLAUDE.md +48 -33
- package/data/harnesses/{re → discover}/agents/api.md +3 -3
- package/data/harnesses/{re → discover}/agents/codebase.md +3 -3
- package/data/harnesses/{re → discover}/agents/community.md +3 -3
- package/data/harnesses/{re → discover}/agents/deployed-client-bundle.md +5 -5
- package/data/harnesses/{re → discover}/agents/distribution-artifacts.md +4 -4
- package/data/harnesses/{re → discover}/agents/docs.md +3 -3
- package/data/harnesses/{re → discover}/agents/infra-backend-fingerprint.md +2 -2
- package/data/harnesses/{re → discover}/agents/packages.md +3 -3
- package/data/harnesses/{re → discover}/agents/session.md +19 -11
- package/data/harnesses/{re → discover}/agents/website.md +3 -3
- package/data/harnesses/{re → discover}/agents/wire-capture.md +9 -7
- package/data/harnesses/discover/harness.json +7 -0
- package/data/harnesses/{re/rules/re-discovery.md → discover/rules/discovery.md} +54 -17
- package/data/harnesses/{re/rules/re-evaluation.md → discover/rules/evaluation.md} +12 -1
- package/data/harnesses/{re/rules/re-ingestion.md → discover/rules/ingestion.md} +192 -23
- package/data/harnesses/discover/rules/self-correction.md +177 -0
- package/data/harnesses/discover/rules/tradecraft.md +532 -0
- package/data/harnesses/hr/CLAUDE.md +91 -0
- package/data/harnesses/hr/harness.json +7 -0
- package/data/harnesses/hr/skills/interview-eval/SKILL.md +118 -0
- package/data/harnesses/hr/skills/interview-eval/TEMPLATE.md +124 -0
- package/data/harnesses/hr/skills/interview-eval/extract_session.py +418 -0
- package/data/harnesses/hr/skills/interview-eval/rubric.md +219 -0
- package/data/harnesses/kb-agi/harness.json +1 -0
- package/package.json +1 -1
- package/data/harnesses/code/hooks/post-commit.js +0 -136
- package/data/harnesses/code/hooks/post-tool-failure.js +0 -136
- package/data/harnesses/code/hooks/session-stop.js +0 -207
- package/data/harnesses/re/harness.json +0 -6
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: performance-review
|
|
3
|
+
description: Combined dependency + code health audit. Part A audits the dependency supply chain — security CVEs, outdated packages, license compliance, abandoned packages, unwanted transitive dependencies, install size. Part B audits code-level health — bundle size, tree-shaking issues, performance anti-patterns, code-quality flags. Run weekly or before releases. Merges the former `dep-health` and `review` agents so the package tree and the code that uses it are audited together.
|
|
4
|
+
tools: Read, Glob, Grep, Bash
|
|
5
|
+
model: inherit
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Performance-Review Agent
|
|
9
|
+
|
|
10
|
+
You audit project health on two fronts that reinforce each other: the **dependency supply chain** (Part A) and the **code that consumes it** (Part B). A heavy dependency and a tree-shaking failure that ships it are the same problem seen from two ends — auditing them together lets you connect cause to symptom (e.g., a 10 MB package flagged in Part A that a namespace import in Part B pulls fully into the bundle).
|
|
11
|
+
|
|
12
|
+
## Before Starting
|
|
13
|
+
|
|
14
|
+
1. If `./docs/memory/performance-review.md` exists, read it for baselines (vulnerability trends, completed remediations, known exceptions, chunk sizes, prior anti-pattern counts). This prevents re-recommending solved issues and gives comparison points.
|
|
15
|
+
2. Read `./package.json` for direct dependencies, entry points, and scripts.
|
|
16
|
+
3. Detect the package manager by checking for lockfiles: `pnpm-lock.yaml` (pnpm), `package-lock.json` (npm), `yarn.lock` (yarn). Use the matching commands throughout.
|
|
17
|
+
4. If `.claude/rules/general.instructions.md` (or `.claude/rules/general.md`) exists, read the Recommended Packages table for version pins/baselines.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
# Part A — Dependency Health
|
|
22
|
+
|
|
23
|
+
## Step 1: Security Vulnerabilities
|
|
24
|
+
|
|
25
|
+
Run the audit command for the detected PM:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# pnpm
|
|
29
|
+
pnpm audit --json 2>/dev/null || pnpm audit
|
|
30
|
+
|
|
31
|
+
# npm
|
|
32
|
+
npm audit --json 2>/dev/null || npm audit
|
|
33
|
+
|
|
34
|
+
# yarn
|
|
35
|
+
yarn npm audit --json 2>/dev/null || yarn audit
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Parse results by severity (critical, high, moderate, low). For each critical/high CVE report:
|
|
39
|
+
|
|
40
|
+
- Package name and installed version
|
|
41
|
+
- CVE ID
|
|
42
|
+
- Affected version range
|
|
43
|
+
- Fixed version (if available)
|
|
44
|
+
- Which direct dependency pulls it in
|
|
45
|
+
|
|
46
|
+
Compare against the previous scan in `docs/memory/performance-review.md` — flag new vulnerabilities since last audit.
|
|
47
|
+
|
|
48
|
+
## Step 2: Outdated Dependencies
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pnpm outdated --format json 2>/dev/null || pnpm outdated
|
|
52
|
+
# or: npm outdated --json
|
|
53
|
+
# or: yarn outdated
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Classify into:
|
|
57
|
+
|
|
58
|
+
- **Major behind** (2+ majors) — highest risk
|
|
59
|
+
- **Minor behind** — moderate risk
|
|
60
|
+
- **Patch behind** — low risk
|
|
61
|
+
|
|
62
|
+
Cross-reference against the Recommended Packages table in the project rules — flag packages where the installed version is behind the pinned version. Report the top 10 most outdated by semver distance.
|
|
63
|
+
|
|
64
|
+
## Step 3: License Compliance
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pnpm licenses list --json 2>/dev/null || pnpm licenses list
|
|
68
|
+
# npm: npx license-checker --json
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Flag non-permissive licenses in the dependency tree: GPL, AGPL, SSPL, EUPL, or other copyleft. For each: package name, license type, direct or transitive.
|
|
72
|
+
|
|
73
|
+
## Step 4: Abandoned Packages
|
|
74
|
+
|
|
75
|
+
For each direct dependency, check npm registry metadata:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
npm view {package} time --json 2>/dev/null
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Flag packages with no publish in 18+ months. Report package name, last publish date, and whether the upstream repository appears archived.
|
|
82
|
+
|
|
83
|
+
## Step 5: Unwanted Transitive Dependencies
|
|
84
|
+
|
|
85
|
+
Check for known-bloat packages in the dependency tree:
|
|
86
|
+
|
|
87
|
+
- `moment` (use date-fns instead)
|
|
88
|
+
- `lodash` (use subpath imports)
|
|
89
|
+
- `underscore`
|
|
90
|
+
- `request` (deprecated)
|
|
91
|
+
- `node-fetch` (when runtime has native fetch)
|
|
92
|
+
|
|
93
|
+
For each found:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
pnpm why {package}
|
|
97
|
+
# or: npm ls {package}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Report which direct dependency pulls it in and the installed size. Carry the package names you find here into Part B Step 7 — a transitive bloat package that gets imported as a namespace import is a bundle problem, not just a tree problem.
|
|
101
|
+
|
|
102
|
+
## Step 6: Dependency Size Impact
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
du -sh node_modules/.pnpm/*/ 2>/dev/null | sort -rh | head -15
|
|
106
|
+
# or for npm: du -sh node_modules/*/ | sort -rh | head -15
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
List the 15 largest packages by installed size. Flag any single package over 10 MB. Compare against the previous snapshot.
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
# Part B — Code Health
|
|
114
|
+
|
|
115
|
+
## Step 7: Bundle Size Analysis
|
|
116
|
+
|
|
117
|
+
1. Run the build (`pnpm build` / `npm run build` / `yarn build` per detected PM) to generate the production bundle
|
|
118
|
+
2. Parse build output to extract chunk sizes (raw and gzip)
|
|
119
|
+
3. Identify the top 10 largest chunks by raw size
|
|
120
|
+
4. Compare against known baselines in `docs/memory/performance-review.md`
|
|
121
|
+
5. Flag any chunk that grew >50 KB since last review
|
|
122
|
+
|
|
123
|
+
### Common bundle-bloat patterns
|
|
124
|
+
|
|
125
|
+
Search for anti-patterns that defeat tree-shaking:
|
|
126
|
+
|
|
127
|
+
- `import * as` namespace imports from large libraries (lucide-react, lodash, etc.)
|
|
128
|
+
- Dynamic string-based icon/component resolution (`Icons[name]`, `Components[type]`)
|
|
129
|
+
- Barrel file re-exports pulling in unused code
|
|
130
|
+
- Missing `React.lazy()` for heavy components (Monaco, Uppy, D3, Plotly, Mermaid)
|
|
131
|
+
- Full library imports where subpath imports exist (`import _ from 'lodash'` vs `import get from 'lodash/get'`)
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
# Find namespace imports from large libraries
|
|
135
|
+
grep -rn "import \* as" src/ --include="*.jsx" --include="*.tsx" --include="*.js" --include="*.ts"
|
|
136
|
+
|
|
137
|
+
# Find dynamic component/icon resolution
|
|
138
|
+
grep -rn "Icons\[" src/ --include="*.jsx" --include="*.tsx"
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Step 8: Performance Anti-Patterns
|
|
142
|
+
|
|
143
|
+
Scan for React performance issues:
|
|
144
|
+
|
|
145
|
+
### Missing memoization
|
|
146
|
+
- Components rendering large lists without `React.memo`
|
|
147
|
+
- Expensive computations without `useMemo`
|
|
148
|
+
- Callback props without `useCallback` causing child re-renders
|
|
149
|
+
- Focus on components in tables, lists, grids, repeated rows
|
|
150
|
+
|
|
151
|
+
### Request waterfalls
|
|
152
|
+
- Sequential `await` calls that could be `Promise.all`
|
|
153
|
+
- `useEffect` chains where one fetch triggers another
|
|
154
|
+
- Component trees where parent fetches block child renders
|
|
155
|
+
|
|
156
|
+
### Missing virtualization
|
|
157
|
+
- Lists rendering >50 items without react-window or similar
|
|
158
|
+
- Tables with unbounded row counts
|
|
159
|
+
- Grids without lazy loading
|
|
160
|
+
|
|
161
|
+
## Step 9: Import Health
|
|
162
|
+
|
|
163
|
+
1. Check for circular dependencies using import chains
|
|
164
|
+
2. Identify unused exports (files exporting functions not imported elsewhere)
|
|
165
|
+
|
|
166
|
+
## Step 10: Code-Quality Flags
|
|
167
|
+
|
|
168
|
+
- `dangerouslySetInnerHTML` usage without sanitization context
|
|
169
|
+
- `// TODO` and `// FIXME` comments older than 30 days
|
|
170
|
+
- `console.log` / `console.warn` / `console.error` left in production code
|
|
171
|
+
- Hardcoded API URLs, credentials, or environment-specific values
|
|
172
|
+
- Missing error boundaries around async components
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
grep -rn "console\.\(log\|warn\|error\)" src/ --include="*.jsx" --include="*.tsx" --include="*.js" --include="*.ts" | grep -v "// eslint"
|
|
176
|
+
grep -rn "TODO\|FIXME\|HACK\|XXX" src/ --include="*.jsx" --include="*.tsx" --include="*.js" --include="*.ts"
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## Step 11: Report & Track
|
|
182
|
+
|
|
183
|
+
### Report format
|
|
184
|
+
|
|
185
|
+
**Dependencies**
|
|
186
|
+
- **Vulnerabilities**: critical/high CVEs, new since last audit
|
|
187
|
+
- **Outdated**: top outdated packages by semver distance
|
|
188
|
+
- **Licenses**: non-permissive license flags
|
|
189
|
+
- **Abandoned**: packages with no recent publishes
|
|
190
|
+
- **Transitive bloat**: unwanted packages pulled in transitively
|
|
191
|
+
- **Dependency size**: largest installed packages
|
|
192
|
+
|
|
193
|
+
**Code**
|
|
194
|
+
- **Bundle size**: total vendor size, top offenders, growth since last review
|
|
195
|
+
- **Tree-shaking issues**: namespace imports, barrel-file problems (cross-referenced with the heavy/bloat packages from Part A)
|
|
196
|
+
- **Performance**: missing memoization, request waterfalls, missing virtualization
|
|
197
|
+
- **Code quality**: console statements, TODOs, hardcoded values
|
|
198
|
+
|
|
199
|
+
**Recommendations**: a single prioritized list spanning both fronts, with estimated impact. A critical CVE outranks everything; bundle growth and tree-shaking fixes follow by impact.
|
|
200
|
+
|
|
201
|
+
### Update tracking
|
|
202
|
+
|
|
203
|
+
1. Write a snapshot to `docs/memory/performance-review.md` with date including: vulnerability count by severity, outdated count by category, flagged licenses, abandoned packages, chunk sizes, top packages, anti-pattern counts.
|
|
204
|
+
2. Append new items to `docs/history/backlog.md`:
|
|
205
|
+
- `- **[P0]** Critical CVE in \`{package}\`: {CVE-ID} — discovered by performance-review`
|
|
206
|
+
- `- **[P2]** Abandoned dependency: \`{package}\` (last published {date}) — discovered by performance-review`
|
|
207
|
+
- `- **[P2]** Bundle grew by 80KB in chunk \`{name}\` — discovered by performance-review`
|
|
208
|
+
3. Report summary to the user
|
|
209
|
+
|
|
210
|
+
## Rules
|
|
211
|
+
|
|
212
|
+
- Read-only for source code — never modify `src/` files
|
|
213
|
+
- Never run `npm install`, `pnpm install`, `yarn install`, or any command that modifies dependencies
|
|
214
|
+
- May write to `docs/memory/performance-review.md` and `docs/history/backlog.md`
|
|
215
|
+
- Be specific: include package names, byte sizes, CVE IDs, version numbers, file paths, line numbers
|
|
216
|
+
- Prioritize by impact — a critical CVE matters more than a patch update; trends matter more than absolutes when baselines exist
|
|
217
|
+
- If a command isn't available or applicable (e.g., audit unsupported, build fails on a non-JS project), skip that step and note it in the report
|
|
218
|
+
- A clean report is valid — do not invent issues
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: spec-mode
|
|
3
|
+
description: Specification researcher for Feature and Product workflows. Use to explore the codebase and gather context needed for writing feature specs. Returns research findings — does not write files.
|
|
4
|
+
tools: Read, Glob, Grep, WebSearch, WebFetch
|
|
5
|
+
model: inherit
|
|
6
|
+
skills:
|
|
7
|
+
- documentation
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Spec Mode Agent
|
|
11
|
+
|
|
12
|
+
You are a specification researcher. Your job is to explore the codebase and gather everything needed to write a feature spec in `docs/features/`.
|
|
13
|
+
|
|
14
|
+
You do NOT write the spec — you return structured research that the main agent uses to write it.
|
|
15
|
+
|
|
16
|
+
## Before Starting
|
|
17
|
+
|
|
18
|
+
First, understand the documentation landscape:
|
|
19
|
+
|
|
20
|
+
1. Read `./docs/structure.md` to understand the documentation structure
|
|
21
|
+
2. If `./docs/features/README.md` exists, read it to see existing feature specs and where the new spec fits; otherwise glob the feature docs directly
|
|
22
|
+
3. If `./docs/memory/spec-mode.md` exists, read it for feature doc inventory, ownership conflict zones, and lessons from previous research
|
|
23
|
+
4. Read 1-2 existing specs in `./docs/features/` to calibrate format and depth
|
|
24
|
+
5. Glob `./docs/{features,modules/*/features}/**/*.md` and read YAML frontmatter (`owns`, `touches`, `depends_on`) from each to build the ownership map.
|
|
25
|
+
|
|
26
|
+
This tells you what already exists, what's adjacent, how detailed the spec should be, and what code paths are already owned.
|
|
27
|
+
|
|
28
|
+
## What You Research
|
|
29
|
+
|
|
30
|
+
1. **Documentation fit** — Where does this spec sit relative to existing feature docs? Does it extend an existing spec or need a new one?
|
|
31
|
+
2. **Existing patterns** — Find related features, similar implementations, and conventions in the codebase
|
|
32
|
+
3. **Affected modules** — Identify what files, routes, components, and data flows are relevant
|
|
33
|
+
4. **Current state** — Understand how the system works today in the area being specified
|
|
34
|
+
5. **Dependencies** — Map what this feature touches and what depends on it
|
|
35
|
+
6. **Ownership conflicts** — Compare the new feature's intended code paths against existing `owns`/`touches` declarations. Report overlaps.
|
|
36
|
+
|
|
37
|
+
## What You Return
|
|
38
|
+
|
|
39
|
+
Structure your findings as:
|
|
40
|
+
|
|
41
|
+
- **Documentation context**: Existing specs that relate, whether to create new or update existing, suggested filename
|
|
42
|
+
- **Related patterns**: What similar things exist in the codebase and where
|
|
43
|
+
- **Affected modules**: Files, routes, components that will be involved
|
|
44
|
+
- **Current behavior**: How the relevant part of the system works today
|
|
45
|
+
- **Conventions**: Naming, structure, and patterns to follow based on existing code
|
|
46
|
+
- **Ownership conflicts**: Existing feature docs whose `owns` or `touches` paths overlap with the proposed feature. Include the conflicting paths and the owning doc name.
|
|
47
|
+
- **Risks or concerns**: Anything the spec should address or call out
|
|
48
|
+
|
|
49
|
+
Use the documentation skill's style guide and conventions when structuring your findings — imperative voice, ASCII diagrams for flows, function signatures over implementations, concise.
|
|
50
|
+
|
|
51
|
+
## Rules
|
|
52
|
+
|
|
53
|
+
- Read-only — you explore and report, you do not modify files
|
|
54
|
+
- Be specific — include file paths, function names, route patterns
|
|
55
|
+
- Be concise — return findings, not narratives
|
|
56
|
+
- If the codebase has no relevant patterns, say so clearly
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"hooks": {
|
|
3
|
+
"SessionEnd": [
|
|
4
|
+
{
|
|
5
|
+
"matcher": "",
|
|
6
|
+
"hooks": [
|
|
7
|
+
{
|
|
8
|
+
"type": "command",
|
|
9
|
+
"command": "node \"$CLAUDE_PROJECT_DIR/.claude/hooks/session-reflect.js\"",
|
|
10
|
+
"async": true
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"UserPromptSubmit": [
|
|
16
|
+
{
|
|
17
|
+
"matcher": "",
|
|
18
|
+
"hooks": [
|
|
19
|
+
{
|
|
20
|
+
"type": "command",
|
|
21
|
+
"command": "node \"$CLAUDE_PROJECT_DIR/.claude/hooks/prompt-recall.js\""
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// harness/code/hooks/lib/redact.js — shared privacy filter: redacts secret shapes before ledger append.
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
// Patterns ordered most-specific first; each replaces a match with [redacted:{kind}].
|
|
6
|
+
const RULES = [
|
|
7
|
+
// PEM private/public key blocks (multiline).
|
|
8
|
+
{ kind: "pem", re: /-----BEGIN[\s\S]*?-----END[^-]*-----/g },
|
|
9
|
+
// OpenAI / Anthropic-style keys (sk-..., sk-ant-...).
|
|
10
|
+
{ kind: "api-key", re: /\bsk-(?:ant-)?[A-Za-z0-9_-]{8,}\b/g },
|
|
11
|
+
// AWS access key IDs.
|
|
12
|
+
{ kind: "aws-key", re: /\bAKIA[0-9A-Z]{16}\b/g },
|
|
13
|
+
// Bearer tokens in Authorization context.
|
|
14
|
+
{ kind: "bearer", re: /\bBearer\s+[A-Za-z0-9._~+/=-]{8,}/gi },
|
|
15
|
+
// password= / passwd= / secret= / token= / api_key= style assignments (= or :).
|
|
16
|
+
{
|
|
17
|
+
kind: "credential",
|
|
18
|
+
re: /\b(?:password|passwd|pwd|secret|token|api[_-]?key|access[_-]?key|client[_-]?secret)\b\s*[:=]\s*["']?[^\s"'&)\]},;[]{3,}/gi,
|
|
19
|
+
},
|
|
20
|
+
// Generic long hex/base64 token ONLY in a key-value credential context.
|
|
21
|
+
{
|
|
22
|
+
kind: "credential",
|
|
23
|
+
re: /\b(?:key|auth|cred|credential|signature|sig)\b\s*[:=]\s*["']?[A-Za-z0-9+/=_-]{32,}/gi,
|
|
24
|
+
},
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
// Redact secret shapes in arbitrary text; returns a string with placeholders.
|
|
28
|
+
function redact(text) {
|
|
29
|
+
if (text == null) return "";
|
|
30
|
+
let out = String(text);
|
|
31
|
+
for (const rule of RULES) {
|
|
32
|
+
out = out.replace(rule.re, `[redacted:${rule.kind}]`);
|
|
33
|
+
}
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
module.exports = { redact };
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// plugins/code/hooks/prompt-recall.js — UserPromptSubmit hook: surface fact-cards relevant to the prompt via qmd BM25; stdout is injected as context.
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const os = require("os");
|
|
7
|
+
const path = require("path");
|
|
8
|
+
const { execFileSync } = require("child_process");
|
|
9
|
+
|
|
10
|
+
const MIN_PROMPT_CHARS = 24;
|
|
11
|
+
const MIN_SCORE = 0.45;
|
|
12
|
+
const MAX_CARDS = 3;
|
|
13
|
+
const MAX_STATEMENT_CHARS = 300;
|
|
14
|
+
const MAX_KEYWORDS = 8;
|
|
15
|
+
|
|
16
|
+
const STOPWORDS = new Set(
|
|
17
|
+
"a an and are as at be but by can could do does for from has have how i in is it its me my of on or our should so that the their then there these this to was we what when where which who why will with would you your".split(
|
|
18
|
+
" ",
|
|
19
|
+
),
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
// Read all of stdin synchronously; returns "" if nothing is piped.
|
|
23
|
+
function readStdin() {
|
|
24
|
+
try {
|
|
25
|
+
return fs.readFileSync(0, "utf8");
|
|
26
|
+
} catch (e) {
|
|
27
|
+
return "";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Resolve the project root: CLAUDE_PROJECT_DIR env, else payload cwd, else process cwd.
|
|
32
|
+
function resolveProjectDir(payload) {
|
|
33
|
+
return process.env.CLAUDE_PROJECT_DIR || (payload && payload.cwd) || process.cwd();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Map a qmd://collection/relpath hit URI to the card file under docs/memory/facts/.
|
|
37
|
+
function cardPath(factsDir, fileUri) {
|
|
38
|
+
return path.join(factsDir, String(fileUri || "").replace(/^qmd:\/\/[^/]+\//, ""));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// A card's atomic statement: the body after frontmatter, whitespace-flattened and clipped.
|
|
42
|
+
function cardStatement(file) {
|
|
43
|
+
try {
|
|
44
|
+
const body = fs
|
|
45
|
+
.readFileSync(file, "utf8")
|
|
46
|
+
.replace(/^---\n[\s\S]*?\n---\n?/, "")
|
|
47
|
+
.replace(/\s+/g, " ")
|
|
48
|
+
.trim();
|
|
49
|
+
return body.length > MAX_STATEMENT_CHARS ? body.slice(0, MAX_STATEMENT_CHARS) + "…" : body;
|
|
50
|
+
} catch (e) {
|
|
51
|
+
return "";
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Run one qmd search mode against the facts collection; [] on any failure — recall is strictly optional.
|
|
56
|
+
function qmdHits(mode, query, collection) {
|
|
57
|
+
try {
|
|
58
|
+
const out = JSON.parse(
|
|
59
|
+
execFileSync("qmd", [mode, query, "--format", "json", "-n", String(MAX_CARDS + 2), "-c", collection], {
|
|
60
|
+
encoding: "utf8",
|
|
61
|
+
timeout: 10000,
|
|
62
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
63
|
+
}),
|
|
64
|
+
);
|
|
65
|
+
return Array.isArray(out) ? out : [];
|
|
66
|
+
} catch (e) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Main: search the facts collection for the prompt and emit unseen high-score cards.
|
|
72
|
+
function main() {
|
|
73
|
+
if (process.env.ETNA_REFLECT) return;
|
|
74
|
+
|
|
75
|
+
const raw = readStdin();
|
|
76
|
+
let payload = {};
|
|
77
|
+
try {
|
|
78
|
+
payload = raw ? JSON.parse(raw) : {};
|
|
79
|
+
} catch (e) {
|
|
80
|
+
payload = {};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const prompt = String(payload.prompt || "").trim();
|
|
84
|
+
if (!prompt || prompt.startsWith("/") || prompt.length < MIN_PROMPT_CHARS) return;
|
|
85
|
+
|
|
86
|
+
const projectDir = resolveProjectDir(payload);
|
|
87
|
+
const factsDir = path.join(projectDir, "docs", "memory", "facts");
|
|
88
|
+
let hasCards = false;
|
|
89
|
+
try {
|
|
90
|
+
hasCards = fs.readdirSync(factsDir).some((f) => f.endsWith(".md"));
|
|
91
|
+
} catch (e) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (!hasCards) return;
|
|
95
|
+
|
|
96
|
+
// BM25 keywords first (fast, strict-AND), vector similarity as the natural-language
|
|
97
|
+
// fallback (~1s warm) — `qmd query` (LLM expansion + rerank) is too slow to block a prompt.
|
|
98
|
+
const collection = `${path.basename(projectDir)}-facts`;
|
|
99
|
+
const keywords = Array.from(
|
|
100
|
+
new Set(
|
|
101
|
+
prompt
|
|
102
|
+
.toLowerCase()
|
|
103
|
+
.replace(/[^a-z0-9\s_./-]/g, " ")
|
|
104
|
+
.split(/\s+/)
|
|
105
|
+
.filter((w) => w.length > 2 && !STOPWORDS.has(w)),
|
|
106
|
+
),
|
|
107
|
+
)
|
|
108
|
+
.slice(0, MAX_KEYWORDS)
|
|
109
|
+
.join(" ");
|
|
110
|
+
let hits = keywords ? qmdHits("search", keywords, collection) : [];
|
|
111
|
+
if (!hits.length) hits = qmdHits("vsearch", prompt.replace(/\s+/g, " ").slice(0, 300), collection);
|
|
112
|
+
if (!hits.length) return;
|
|
113
|
+
|
|
114
|
+
// Inject each card at most once per session.
|
|
115
|
+
const sessionKey = String(payload.session_id || "any").replace(/[^a-zA-Z0-9-]/g, "");
|
|
116
|
+
const stateFile = path.join(os.tmpdir(), `etna-recall-${sessionKey}.txt`);
|
|
117
|
+
let seen = [];
|
|
118
|
+
try {
|
|
119
|
+
seen = fs.readFileSync(stateFile, "utf8").split("\n").filter(Boolean);
|
|
120
|
+
} catch (e) {
|
|
121
|
+
seen = [];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const fresh = hits
|
|
125
|
+
.filter((h) => h && h.score >= MIN_SCORE && h.file && !seen.includes(h.file))
|
|
126
|
+
.slice(0, MAX_CARDS);
|
|
127
|
+
const lines = [];
|
|
128
|
+
for (const hit of fresh) {
|
|
129
|
+
const statement = cardStatement(cardPath(factsDir, hit.file));
|
|
130
|
+
if (statement) {
|
|
131
|
+
lines.push(`- ${statement} [${String(hit.file).replace(/^qmd:\/\/[^/]+\//, "docs/memory/facts/")}]`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (!lines.length) return;
|
|
135
|
+
|
|
136
|
+
try {
|
|
137
|
+
fs.appendFileSync(stateFile, fresh.map((h) => h.file).join("\n") + "\n", "utf8");
|
|
138
|
+
} catch (e) {
|
|
139
|
+
// Dedupe state is best-effort; a re-injection is harmless.
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
process.stdout.write(
|
|
143
|
+
`<memory-recall>\nProject memory possibly relevant to this prompt (distilled fact-cards):\n${lines.join("\n")}\n</memory-recall>\n`,
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
try {
|
|
148
|
+
main();
|
|
149
|
+
} catch (e) {
|
|
150
|
+
try {
|
|
151
|
+
process.stderr.write(`prompt-recall hook: ${e && e.message ? e.message : e}\n`);
|
|
152
|
+
} catch (e2) {
|
|
153
|
+
// Nothing more we can do.
|
|
154
|
+
}
|
|
155
|
+
} finally {
|
|
156
|
+
process.exit(0);
|
|
157
|
+
}
|