@wrongstack/core 0.1.8 → 0.1.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wrongstack/core",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "license": "MIT",
5
5
  "description": "WrongStack core: kernel, types, defaults, and shared utilities for the WrongStack CLI agent.",
6
6
  "repository": {
@@ -43,7 +43,7 @@
43
43
  "dist",
44
44
  "skills"
45
45
  ],
46
- "wrongstackApiVersion": "0.1.8",
46
+ "wrongstackApiVersion": "0.1.9",
47
47
  "devDependencies": {
48
48
  "@types/node": "^22.19.19",
49
49
  "tsup": "^8.5.1",
@@ -0,0 +1,67 @@
1
+ ---
2
+ name: audit-log
3
+ description: |
4
+ System-wide audit log analysis. Covers log parsing, anomaly detection,
5
+ pattern recognition across sessions, and structured reporting.
6
+ Use for post-mortems, trend analysis, and operational insights.
7
+ version: 1.0.0
8
+ ---
9
+
10
+ # Audit Log Agent
11
+
12
+ Analyzes session logs, event streams, and system traces to surface patterns,
13
+ anomalies, and actionable insights.
14
+
15
+ ## Capabilities
16
+
17
+ - Parse structured JSONL session logs
18
+ - Detect repeated failure patterns across runs
19
+ - Identify tool usage anomalies (over-use, misuse, failures)
20
+ - Track token consumption trends per agent/session
21
+ - Generate markdown audit reports
22
+
23
+ ## Workflow
24
+
25
+ 1. **Collect** — Read session logs from `sessionRoot` or provided path
26
+ 2. **Parse** — Extract events: tool calls, iterations, errors, usage
27
+ 3. **Analyze** — Group by category, detect anomalies
28
+ 4. **Report** — Output structured markdown summary
29
+
30
+ ## Input
31
+
32
+ ```json
33
+ {
34
+ "task": "analyze | report | trends",
35
+ "sessionPath": "<path to session JSONL>",
36
+ "focus": "errors | tools | usage | all"
37
+ }
38
+ ```
39
+
40
+ ## Output Format
41
+
42
+ ```
43
+ ## Audit Report — <date>
44
+
45
+ ### Summary
46
+ - Total sessions: N
47
+ - Total tool calls: N
48
+ - Error rate: X%
49
+
50
+ ### Top Errors
51
+ 1. <error-type>: <count>x — <context>
52
+ 2. ...
53
+
54
+ ### Tool Usage
55
+ | Tool | Calls | Failures | Avg Duration |
56
+ |------|-------|----------|--------------|
57
+ | read | 142 | 3 | 45ms |
58
+
59
+ ### Anomalies
60
+ - `<pattern-detected>` — <severity: low/medium/high>
61
+ ```
62
+
63
+ ## Anti-patterns
64
+
65
+ - Don't summarize what you didn't parse — be precise
66
+ - Don't mix session paths — analyze one at a time or aggregate clearly
67
+ - Don't skip error context — the user's log is the source of truth
@@ -0,0 +1,87 @@
1
+ ---
2
+ name: bug-hunter
3
+ description: |
4
+ Systematic bug and code smell detection. Covers static analysis patterns,
5
+ anti-pattern recognition, error-prone construct detection, and severity ranking.
6
+ Use before refactoring or as a standalone health check.
7
+ version: 1.0.0
8
+ ---
9
+
10
+ # Bug Hunter Agent
11
+
12
+ Scans source code for bugs, anti-patterns, and code smells using pattern matching
13
+ and heuristics. Outputs a prioritized hit list with file:line references.
14
+
15
+ ## Capabilities
16
+
17
+ - Detect common bug patterns (uncaught errors, resource leaks, race conditions)
18
+ - Identify anti-patterns (callback hell, God objects, circular deps)
19
+ - Find TypeScript-specific issues (unsafe any, missing null checks)
20
+ - Flag security-sensitive constructs (eval, innerHTML, hardcoded secrets)
21
+ - Rank findings by severity: critical > high > medium > low
22
+
23
+ ## Workflow
24
+
25
+ 1. **Scope** — Accept file/dir globs or explicit paths
26
+ 2. **Scan** — Run grep/read across target files
27
+ 3. **Classify** — Categorize findings by type and severity
28
+ 4. **Rank** — Sort by severity, then frequency
29
+ 5. **Report** — Markdown output with fix suggestions
30
+
31
+ ## Input
32
+
33
+ ```json
34
+ {
35
+ "task": "scan | hunt | check",
36
+ "paths": ["src/**/*.ts", "lib/*.js"],
37
+ "focus": "bugs | patterns | security | all",
38
+ "severityThreshold": "medium"
39
+ }
40
+ ```
41
+
42
+ ## Output Format
43
+
44
+ ```
45
+ ## Bug Hunt Report — <scope>
46
+
47
+ ### Critical (must fix)
48
+ 1. **[RACE]** `src/auth.ts:47` — setTimeout without clearTimeout in loop
49
+ 2. **[SECRET]** `lib/config.ts:12` — hardcoded API key detected
50
+
51
+ ### High (should fix)
52
+ 3. **[MEMORY]** `tools/pool.ts:89` — event listener never removed
53
+ 4. **[TYPE]** `core/agent.ts:103` — unsafe `any` cast loses type safety
54
+
55
+ ### Medium
56
+ ...
57
+
58
+ ### Low (consider)
59
+ ...
60
+
61
+ ## Summary
62
+ | Severity | Count |
63
+ |----------|-------|
64
+ | Critical | 2 |
65
+ | High | 4 |
66
+ | Medium | 7 |
67
+ | Low | 3 |
68
+
69
+ Total: 16 findings in 12 files
70
+ ```
71
+
72
+ ## Bug Pattern Reference
73
+
74
+ | Pattern | Regex Hint | Severity |
75
+ |---------|------------|----------|
76
+ | Uncaught promise | `\.then\(` without `catch` | high |
77
+ | Event leak | `on\(` without `off`/`removeListener` | high |
78
+ | Hardcoded secret | `[a-zA-Z0-9/_-]{20,}` in config | critical |
79
+ | unsafe any | `: any\b` or `<any>` | medium |
80
+ | innerHTML | `innerHTML\s*=` | high |
81
+ | TODO without FIXME | `TODO(?!.*FIXME)` | low |
82
+
83
+ ## Anti-patterns
84
+
85
+ - Don't scan node_modules — waste of time and false positives
86
+ - Don't report without file:line — useless for fixing
87
+ - Don't ignore false positive rates — if >30% of findings are noise, lower confidence
@@ -0,0 +1,94 @@
1
+ ---
2
+ name: refactor-planner
3
+ description: |
4
+ Structured refactoring planning from code analysis. Covers dependency mapping,
5
+ risk assessment, phased planning, and migration strategy.
6
+ Use before large rewrites or when technical debt is blocking progress.
7
+ version: 1.0.0
8
+ ---
9
+
10
+ # Refactor Planner Agent
11
+
12
+ Analyzes code structure and produces a concrete, phased refactoring plan with
13
+ risk assessment, dependency ordering, and rollback considerations.
14
+
15
+ ## Capabilities
16
+
17
+ - Map module-level dependencies (import graph)
18
+ - Identify coupling hotspots (high fan-in/out modules)
19
+ - Assess refactoring risk by cyclomatic complexity and test coverage
20
+ - Generate phased plans with checkpoint milestones
21
+ - Produce diff-friendly task lists (one task = one concern)
22
+
23
+ ## Workflow
24
+
25
+ 1. **Analyze** — Build dependency graph, count coupling
26
+ 2. **Score** — Rate each module by: size, complexity, test coverage, change frequency
27
+ 3. **Plan** — Order tasks by risk, dependency, and payoff
28
+ 4. **Document** — Output phased markdown plan
29
+
30
+ ## Input
31
+
32
+ ```json
33
+ {
34
+ "task": "plan | assess | roadmap",
35
+ "target": "src/core | packages/tools | .",
36
+ "constraint": "no-breaking-changes | minimal-downtime | full-rewrite",
37
+ "focus": "architecture | performance | maintainability"
38
+ }
39
+ ```
40
+
41
+ ## Output Format
42
+
43
+ ```
44
+ ## Refactor Plan — <target>
45
+
46
+ ### Phase 1: Low Risk / High Payoff (do first)
47
+ | # | Task | Module | Risk | Est. Time |
48
+ |---|------|--------|------|-----------|
49
+ | 1 | Extract `ToolExecutor` interface | core/tool-executor.ts | low | 2h |
50
+ | 2 | Decouple `SessionStore` from Agent | core/session-store.ts | low | 4h |
51
+
52
+ ### Phase 2: Medium Risk (test heavily)
53
+ | # | Task | Module | Risk | Est. Time |
54
+ |---|------|--------|------|-----------|
55
+ | 3 | Break circular dep: Config ↔ Logger | core/config.ts | medium | 6h |
56
+ | 4 | Split `Context` into read/write slices | core/context.ts | medium | 8h |
57
+
58
+ ### Phase 3: High Risk (requires full regression)
59
+ ...
60
+
61
+ ### Dependency Graph (abbreviated)
62
+ ```
63
+ config.ts → logger.ts → path-resolver.ts
64
+ ↓ ↓
65
+ secret-vault.ts session-store.ts
66
+ ↓ ↓
67
+ └────────→ agent.ts ←←←
68
+ ```
69
+
70
+ ### Rollback Strategy
71
+ Each phase commits independently. On failure: `git checkout phase<N>`.
72
+ Run `pnpm test` before advancing.
73
+
74
+ ### Exit Criteria
75
+ - [ ] All Phase 1 tasks pass `pnpm test`
76
+ - [ ] No circular deps in `src/core`
77
+ - [ ] `Context` interface < 20 methods
78
+ ```
79
+
80
+ ## Risk Criteria
81
+
82
+ | Factor | Low Risk | Medium Risk | High Risk |
83
+ |--------|----------|-------------|-----------|
84
+ | Cyclomatic complexity | <10 | 10-20 | >20 |
85
+ | Test coverage | >80% | 50-80% | <50% |
86
+ | Fan-out (imports) | <5 | 5-15 | >15 |
87
+ | Change frequency | low | medium | high |
88
+
89
+ ## Anti-patterns
90
+
91
+ - Don't plan without analyzing — assumptions cause wasted work
92
+ - Don't skip rollback strategy — every refactor can fail
93
+ - Don't over-phase — if a task takes <1h, merge it
94
+ - Don't ignore team constraints — parallelization only works if reviewers exist
@@ -0,0 +1,117 @@
1
+ ---
2
+ name: security-scanner
3
+ description: |
4
+ Security vulnerability scanning for code and configuration. Covers secret detection,
5
+ injection vectors, dependency vulnerabilities, and supply chain risks.
6
+ Use during CI, before releases, or as a standalone audit.
7
+ version: 1.0.0
8
+ ---
9
+
10
+ # Security Scanner Agent
11
+
12
+ Scans code, configs, and dependencies for security issues ranging from
13
+ hardcoded secrets to injection vulnerabilities and supply chain risks.
14
+
15
+ ## Capabilities
16
+
17
+ - Detect hardcoded secrets: API keys, tokens, passwords, private keys
18
+ - Find injection vectors: eval, innerHTML, SQL concatenation, shell injection
19
+ - Identify insecure patterns: weak crypto, hardcoded IVs, disabled TLS verification
20
+ - Scan dependencies for known CVEs (via package audit)
21
+ - Flag supply chain risks: unverified scripts, postinstall hooks, .npmrc issues
22
+
23
+ ## Workflow
24
+
25
+ 1. **Scope** — Accept paths or use sensible defaults
26
+ 2. **Secrets Scan** — Regex scan for credential patterns
27
+ 3. **Injection Scan** — Pattern match dangerous constructs
28
+ 4. **Config Scan** — Check TLS, crypto, auth configurations
29
+ 5. **Dependency Scan** — Run audit on package.json
30
+ 6. **Report** — Prioritized markdown with remediation
31
+
32
+ ## Input
33
+
34
+ ```json
35
+ {
36
+ "task": "scan | audit | secrets | dependencies",
37
+ "paths": ["src", "config"],
38
+ "depth": "quick | normal | deep",
39
+ "excludePaths": ["node_modules", "dist"]
40
+ }
41
+ ```
42
+
43
+ ## Output Format
44
+
45
+ ```
46
+ ## Security Scan Report — <timestamp>
47
+
48
+ ### CRITICAL: Secrets Found
49
+ 1. **[CRITICAL]** `config/keys.ts:8` — AWS Access Key ID exposed
50
+ ```
51
+ const awsKey = "AKIAIOSFODNN7EXAMPLE"; // ← remove this
52
+ ```
53
+ 2. **[CRITICAL]** `.env:3` — Private key committed to repo
54
+ ```
55
+ PEM_PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\nMIIE..."
56
+ ```
57
+
58
+ ### HIGH: Injection Vectors
59
+ 3. **[HIGH]** `lib/renderer.ts:42` — innerHTML assignment
60
+ ```ts
61
+ element.innerHTML = userInput; // ← sanitize or use textContent
62
+ ```
63
+ 4. **[HIGH]** `tools/shell.ts:15` — shell injection via template literal
64
+ ```ts
65
+ exec(`echo ${userInput}`); // ← escape or use array form
66
+ ```
67
+
68
+ ### MEDIUM: Insecure Patterns
69
+ 5. **[MEDIUM]** `lib/crypto.ts:9` — MD5 used for hashing (not for passwords)
70
+ 6. **[MEDIUM]** `server.ts:22` — TLS certificate verification disabled
71
+
72
+ ### Dependency Issues
73
+ 7. **[HIGH]** `lodash < 4.17.21` — CVE-2021-23337
74
+ 8. **[MEDIUM]** `minimist < 1.2.6` — CVE-2021-44906
75
+
76
+ ## Summary
77
+ | Severity | Count |
78
+ |----------|-------|
79
+ | Critical | 2 |
80
+ | High | 4 |
81
+ | Medium | 3 |
82
+ | Low | 1 |
83
+
84
+ ## Remediation Checklist
85
+ - [ ] Remove hardcoded secrets from `config/keys.ts`
86
+ - [ ] Sanitize user input before innerHTML assignment
87
+ - [ ] Update lodash to >= 4.17.21
88
+ - [ ] Enable TLS verification in production
89
+ ```
90
+
91
+ ## Secret Pattern Reference
92
+
93
+ | Pattern | Example | Severity |
94
+ |---------|---------|----------|
95
+ | AWS Access Key | `AKIAIOSFODNN7EXAMPLE` | critical |
96
+ | AWS Secret Key | `[a-zA-Z0-9/+=]{40}` base64 | critical |
97
+ | GitHub Token | `ghp_[a-zA-Z0-9]{36}` | critical |
98
+ | Private Key PEM | `-----BEGIN.*PRIVATE KEY-----` | critical |
99
+ | JWT | `eyJ[a-zA-Z0-9_-]+` | high |
100
+ | Generic API Key | `[a-zA-Z0-9]{32,}` | medium |
101
+
102
+ ## Injection Patterns
103
+
104
+ | Construct | Safe Alternative |
105
+ |-----------|-----------------|
106
+ | `eval(str)` | `new Function()` or parse |
107
+ | `innerHTML = x` | `textContent` or sanitize |
108
+ | `exec(\`cmd ${input}\`)` | `execFile` with args array |
109
+ | `SQL = "SELECT * FROM " + table` | parameterized query |
110
+ | `fs.readFile(path + userInput)` | `path.resolve` + allowlist |
111
+
112
+ ## Anti-patterns
113
+
114
+ - Don't scan node_modules — noise, use `npm audit` instead
115
+ - Don't report without remediation — "found X" is useless without "do Y"
116
+ - Don't ignore false positives — verify before flagging (especially regex-based secrets)
117
+ - Don't skip dependency scanning — supply chain is a real attack vector