kastell 2.2.4 → 2.2.6
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/.claude-plugin/marketplace.json +18 -18
- package/.claude-plugin/plugin.json +45 -38
- package/CHANGELOG.md +1313 -1266
- package/LICENSE +201 -201
- package/NOTICE +5 -5
- package/README.md +1 -1
- package/README.tr.md +1 -1
- package/bin/kastell +2 -2
- package/bin/kastell-mcp +5 -5
- package/dist/adapters/coolify.js +92 -92
- package/dist/adapters/dokploy.js +99 -99
- package/dist/commands/fix.d.ts +2 -0
- package/dist/commands/fix.d.ts.map +1 -1
- package/dist/commands/fix.js +26 -1
- package/dist/commands/fix.js.map +1 -1
- package/dist/commands/interactive/plugins.d.ts.map +1 -1
- package/dist/commands/interactive/plugins.js +26 -2
- package/dist/commands/interactive/plugins.js.map +1 -1
- package/dist/commands/plugin.d.ts.map +1 -1
- package/dist/commands/plugin.js +6 -2
- package/dist/commands/plugin.js.map +1 -1
- package/dist/core/audit/commands.d.ts +13 -2
- package/dist/core/audit/commands.d.ts.map +1 -1
- package/dist/core/audit/commands.js +39 -2
- package/dist/core/audit/commands.js.map +1 -1
- package/dist/core/audit/explainCheck.d.ts +1 -0
- package/dist/core/audit/explainCheck.d.ts.map +1 -1
- package/dist/core/audit/explainCheck.js +1 -1
- package/dist/core/audit/explainCheck.js.map +1 -1
- package/dist/core/audit/fix-history.d.ts +3 -1
- package/dist/core/audit/fix-history.d.ts.map +1 -1
- package/dist/core/audit/fix-history.js +6 -2
- package/dist/core/audit/fix-history.js.map +1 -1
- package/dist/core/audit/fix.d.ts.map +1 -1
- package/dist/core/audit/fix.js +22 -0
- package/dist/core/audit/fix.js.map +1 -1
- package/dist/core/audit/formatters/badge.js +20 -20
- package/dist/core/audit/index.d.ts.map +1 -1
- package/dist/core/audit/index.js +12 -3
- package/dist/core/audit/index.js.map +1 -1
- package/dist/core/audit/listChecks.d.ts.map +1 -1
- package/dist/core/audit/listChecks.js +24 -0
- package/dist/core/audit/listChecks.js.map +1 -1
- package/dist/core/audit/pluginAudit.d.ts +8 -0
- package/dist/core/audit/pluginAudit.d.ts.map +1 -0
- package/dist/core/audit/pluginAudit.js +134 -0
- package/dist/core/audit/pluginAudit.js.map +1 -0
- package/dist/core/audit/pluginFix.d.ts +19 -0
- package/dist/core/audit/pluginFix.d.ts.map +1 -0
- package/dist/core/audit/pluginFix.js +122 -0
- package/dist/core/audit/pluginFix.js.map +1 -0
- package/dist/core/audit/snapshot.d.ts +4 -4
- package/dist/core/audit/types.d.ts +2 -1
- package/dist/core/audit/types.d.ts.map +1 -1
- package/dist/core/completions.js +631 -631
- package/dist/core/plugin.d.ts +6 -0
- package/dist/core/plugin.d.ts.map +1 -1
- package/dist/core/plugin.js +2 -0
- package/dist/core/plugin.js.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/pluginTools.d.ts +5 -0
- package/dist/mcp/pluginTools.d.ts.map +1 -0
- package/dist/mcp/pluginTools.js +54 -0
- package/dist/mcp/pluginTools.js.map +1 -0
- package/dist/mcp/prompts/workflows.d.ts +17 -0
- package/dist/mcp/prompts/workflows.d.ts.map +1 -0
- package/dist/mcp/prompts/workflows.js +73 -0
- package/dist/mcp/prompts/workflows.js.map +1 -0
- package/dist/mcp/resources/checks.d.ts +4 -0
- package/dist/mcp/resources/checks.d.ts.map +1 -0
- package/dist/mcp/resources/checks.js +49 -0
- package/dist/mcp/resources/checks.js.map +1 -0
- package/dist/mcp/resources/servers.d.ts +4 -0
- package/dist/mcp/resources/servers.d.ts.map +1 -0
- package/dist/mcp/resources/servers.js +59 -0
- package/dist/mcp/resources/servers.js.map +1 -0
- package/dist/mcp/server.d.ts +1 -1
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +68 -35
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/tools/serverAudit.d.ts +1 -1
- package/dist/mcp/tools/serverExplain.d.ts.map +1 -1
- package/dist/mcp/tools/serverExplain.js.map +1 -1
- package/dist/mcp/tools/serverFix.d.ts.map +1 -1
- package/dist/mcp/tools/serverFix.js +7 -1
- package/dist/mcp/tools/serverFix.js.map +1 -1
- package/dist/mcp/tools/serverFleet.d.ts.map +1 -1
- package/dist/mcp/tools/serverFleet.js.map +1 -1
- package/dist/mcp/tools/serverInfo.d.ts +1 -1
- package/dist/mcp/tools/serverInfo.js +1 -1
- package/dist/mcp/tools/serverManage.d.ts +2 -1
- package/dist/mcp/tools/serverManage.d.ts.map +1 -1
- package/dist/mcp/tools/serverManage.js +50 -5
- package/dist/mcp/tools/serverManage.js.map +1 -1
- package/dist/mcp/tools/serverPlugin.d.ts +3 -0
- package/dist/mcp/tools/serverPlugin.d.ts.map +1 -1
- package/dist/mcp/tools/serverPlugin.js +11 -1
- package/dist/mcp/tools/serverPlugin.js.map +1 -1
- package/dist/mcp/tools/serverProvision.d.ts +5 -5
- package/dist/mcp/tools/serverProvision.d.ts.map +1 -1
- package/dist/mcp/tools/serverProvision.js +31 -9
- package/dist/mcp/tools/serverProvision.js.map +1 -1
- package/dist/mcp/tools/serverSecure.d.ts.map +1 -1
- package/dist/mcp/tools/serverSecure.js +30 -1
- package/dist/mcp/tools/serverSecure.js.map +1 -1
- package/dist/mcp/utils.d.ts +25 -0
- package/dist/mcp/utils.d.ts.map +1 -1
- package/dist/mcp/utils.js +36 -0
- package/dist/mcp/utils.js.map +1 -1
- package/dist/mcp-bundle.mjs +102301 -0
- package/dist/plugin/handlerResolver.d.ts +2 -0
- package/dist/plugin/handlerResolver.d.ts.map +1 -0
- package/dist/plugin/handlerResolver.js +16 -0
- package/dist/plugin/handlerResolver.js.map +1 -0
- package/dist/plugin/loader.d.ts.map +1 -1
- package/dist/plugin/loader.js +41 -4
- package/dist/plugin/loader.js.map +1 -1
- package/dist/plugin/registerCommands.d.ts +4 -0
- package/dist/plugin/registerCommands.d.ts.map +1 -0
- package/dist/plugin/registerCommands.js +45 -0
- package/dist/plugin/registerCommands.js.map +1 -0
- package/dist/plugin/registry.d.ts +20 -1
- package/dist/plugin/registry.d.ts.map +1 -1
- package/dist/plugin/registry.js +51 -1
- package/dist/plugin/registry.js.map +1 -1
- package/dist/plugin/sdk/constants.d.ts +2 -0
- package/dist/plugin/sdk/constants.d.ts.map +1 -1
- package/dist/plugin/sdk/constants.js +2 -0
- package/dist/plugin/sdk/constants.js.map +1 -1
- package/dist/plugin/sdk/types.d.ts +74 -1
- package/dist/plugin/sdk/types.d.ts.map +1 -1
- package/dist/plugin/validate.d.ts +2 -1
- package/dist/plugin/validate.d.ts.map +1 -1
- package/dist/plugin/validate.js +106 -1
- package/dist/plugin/validate.js.map +1 -1
- package/dist/utils/cloudInit.js +58 -58
- package/dist/utils/fileLock.d.ts +5 -1
- package/dist/utils/fileLock.d.ts.map +1 -1
- package/dist/utils/fileLock.js +70 -15
- package/dist/utils/fileLock.js.map +1 -1
- package/dist/utils/paths.d.ts +0 -1
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +1 -2
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/secureWrite.d.ts.map +1 -1
- package/dist/utils/secureWrite.js +3 -38
- package/dist/utils/secureWrite.js.map +1 -1
- package/dist/utils/version.d.ts.map +1 -1
- package/dist/utils/version.js +19 -4
- package/dist/utils/version.js.map +1 -1
- package/kastell-plugin/.claude-plugin/plugin.json +20 -20
- package/kastell-plugin/.mcp.json +15 -8
- package/kastell-plugin/README.md +113 -113
- package/kastell-plugin/agents/kastell-auditor.md +77 -77
- package/kastell-plugin/agents/scripts/bucket_mapper.sh +101 -101
- package/kastell-plugin/agents/scripts/trend_report.sh +91 -91
- package/kastell-plugin/hooks/destroy-block.cjs +31 -31
- package/kastell-plugin/hooks/hooks.json +57 -57
- package/kastell-plugin/hooks/pre-commit-audit-guard.cjs +75 -75
- package/kastell-plugin/hooks/session-audit.cjs +86 -86
- package/kastell-plugin/hooks/session-log.cjs +56 -56
- package/kastell-plugin/hooks/stop-quality-check.cjs +72 -72
- package/kastell-plugin/skills/kastell-careful/SKILL.md +64 -64
- package/kastell-plugin/skills/kastell-ops/SKILL.md +139 -139
- package/kastell-plugin/skills/kastell-ops/references/commands.md +45 -45
- package/kastell-plugin/skills/kastell-ops/references/mcp-tools.md +50 -50
- package/kastell-plugin/skills/kastell-ops/references/patterns.md +145 -145
- package/kastell-plugin/skills/kastell-ops/references/pitfalls.md +136 -136
- package/kastell-plugin/skills/kastell-ops/scripts/check_coverage.sh +101 -101
- package/kastell-plugin/skills/kastell-ops/scripts/fleet_report.sh +73 -73
- package/kastell-plugin/skills/kastell-ops/scripts/parse_audit.sh +76 -76
- package/kastell-plugin/skills/kastell-research/SKILL.md +90 -90
- package/kastell-plugin/skills/kastell-scaffold/SKILL.md +104 -104
- package/kastell-plugin/skills/kastell-scaffold/references/template-audit-check.md +150 -150
- package/kastell-plugin/skills/kastell-scaffold/references/template-command.md +80 -80
- package/kastell-plugin/skills/kastell-scaffold/references/template-mcp-tool.md +72 -72
- package/kastell-plugin/skills/kastell-scaffold/references/template-provider.md +67 -67
- package/kastell-plugin/skills/kastell-scaffold/scripts/scaffold.sh +180 -180
- package/kastell-plugin/skills/kastell-scaffold/templates/check-test.ts.tpl +27 -27
- package/kastell-plugin/skills/kastell-scaffold/templates/check.ts.tpl +50 -50
- package/kastell-plugin/skills/kastell-scaffold/templates/command-core.ts.tpl +18 -18
- package/kastell-plugin/skills/kastell-scaffold/templates/command-test.ts.tpl +17 -17
- package/kastell-plugin/skills/kastell-scaffold/templates/command.ts.tpl +25 -25
- package/kastell-plugin/skills/kastell-scaffold/templates/mcp-tool-test.ts.tpl +30 -30
- package/kastell-plugin/skills/kastell-scaffold/templates/mcp-tool.ts.tpl +29 -29
- package/kastell-plugin/skills/kastell-scaffold/templates/provider-test.ts.tpl +34 -34
- package/kastell-plugin/skills/kastell-scaffold/templates/provider.ts.tpl +32 -32
- package/package.json +125 -122
- package/dist/commands/interactive.d.ts +0 -11
- package/dist/commands/interactive.d.ts.map +0 -1
- package/dist/commands/interactive.js +0 -1079
- package/dist/commands/interactive.js.map +0 -1
- package/dist/core/lock.d.ts +0 -66
- package/dist/core/lock.d.ts.map +0 -1
- package/dist/core/lock.js +0 -556
- package/dist/core/lock.js.map +0 -1
|
@@ -1,150 +1,150 @@
|
|
|
1
|
-
# Template: Audit Check — $1
|
|
2
|
-
|
|
3
|
-
## Files to Create/Modify
|
|
4
|
-
|
|
5
|
-
1. `src/core/audit/checks/$1.ts` — check definitions + parser
|
|
6
|
-
2. `src/core/audit/commands.ts` — SSH batch section
|
|
7
|
-
3. `src/core/audit/checks/index.ts` — registry entry
|
|
8
|
-
4. `src/core/audit/compliance/mapper.ts` — compliance mapping (optional)
|
|
9
|
-
5. `src/__tests__/core/audit/checks/$1.test.ts` — test file
|
|
10
|
-
|
|
11
|
-
## Step 1: Check File
|
|
12
|
-
|
|
13
|
-
```typescript
|
|
14
|
-
// src/core/audit/checks/$1.ts
|
|
15
|
-
import type { AuditCheck, CheckParser } from "../../types.js";
|
|
16
|
-
|
|
17
|
-
interface $1CheckDef {
|
|
18
|
-
id: string; // "CATEGORY-CHECK-NAME" (uppercase, hyphen-separated)
|
|
19
|
-
name: string; // Human-readable description
|
|
20
|
-
severity: "critical" | "warning" | "info";
|
|
21
|
-
check: (output: string) => { passed: boolean; currentValue: string };
|
|
22
|
-
expectedValue: string;
|
|
23
|
-
fixCommand: string;
|
|
24
|
-
explain: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const $1_CHECKS: $1CheckDef[] = [
|
|
28
|
-
{
|
|
29
|
-
id: "CAT-CHECK-ONE",
|
|
30
|
-
name: "Check description",
|
|
31
|
-
severity: "warning",
|
|
32
|
-
check: (output) => {
|
|
33
|
-
const match = output.includes("SENTINEL_PASS");
|
|
34
|
-
return { passed: match, currentValue: match ? "configured" : "not found" };
|
|
35
|
-
},
|
|
36
|
-
expectedValue: "configured",
|
|
37
|
-
fixCommand: "command to fix",
|
|
38
|
-
explain: "Why this matters and what the fix does.",
|
|
39
|
-
},
|
|
40
|
-
];
|
|
41
|
-
|
|
42
|
-
export const parse$1Checks: CheckParser = (
|
|
43
|
-
sectionOutput: string,
|
|
44
|
-
_platform: string,
|
|
45
|
-
): AuditCheck[] => {
|
|
46
|
-
// Conditional category: return [] if not applicable (excluded from score)
|
|
47
|
-
if (!sectionOutput || sectionOutput.includes("SKIP_MARKER")) {
|
|
48
|
-
return [];
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return $1_CHECKS.map((def) => {
|
|
52
|
-
const { passed, currentValue } = def.check(sectionOutput);
|
|
53
|
-
return {
|
|
54
|
-
id: def.id,
|
|
55
|
-
category: "Category Name", // MUST match CHECK_REGISTRY.name exactly
|
|
56
|
-
name: def.name,
|
|
57
|
-
severity: def.severity,
|
|
58
|
-
passed,
|
|
59
|
-
currentValue,
|
|
60
|
-
expectedValue: def.expectedValue,
|
|
61
|
-
fixCommand: def.fixCommand,
|
|
62
|
-
explain: def.explain,
|
|
63
|
-
};
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
## Step 2: SSH Batch Section
|
|
69
|
-
|
|
70
|
-
`src/core/audit/commands.ts` — add bash commands that run on the server.
|
|
71
|
-
|
|
72
|
-
```typescript
|
|
73
|
-
function new$1Section(): string {
|
|
74
|
-
return [
|
|
75
|
-
NAMED_SEP("$1UPPER"), // MUST match CHECK_REGISTRY.sectionName exactly
|
|
76
|
-
`command1 || echo 'N/A'`,
|
|
77
|
-
`command2 || echo 'N/A'`,
|
|
78
|
-
].join("\n");
|
|
79
|
-
}
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
Add to the correct batch array:
|
|
83
|
-
- `BATCH_FAST` — fast commands (<1s)
|
|
84
|
-
- `BATCH_MEDIUM` — medium commands (1-5s)
|
|
85
|
-
- `BATCH_SLOW` — slow commands (5s+, e.g., `nginx -T`)
|
|
86
|
-
|
|
87
|
-
**Sentinel matching is critical:** `NAMED_SEP("FOO")` produces `---SECTION:FOO---`. This string MUST match `CHECK_REGISTRY.sectionName` exactly.
|
|
88
|
-
|
|
89
|
-
For conditional categories, add a skip marker as first command:
|
|
90
|
-
```bash
|
|
91
|
-
command -v nginx >/dev/null 2>&1 || echo 'NGINX_NOT_INSTALLED'
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
## Step 3: Registry
|
|
95
|
-
|
|
96
|
-
```typescript
|
|
97
|
-
// src/core/audit/checks/index.ts
|
|
98
|
-
import { parse$1Checks } from "./$1.js";
|
|
99
|
-
|
|
100
|
-
export const CHECK_REGISTRY: CategoryEntry[] = [
|
|
101
|
-
// ... existing categories ...
|
|
102
|
-
{ name: "Category Name", sectionName: "$1UPPER", parser: parse$1Checks },
|
|
103
|
-
];
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
**Triple-check:**
|
|
107
|
-
- [ ] `sectionName` === `NAMED_SEP()` parameter
|
|
108
|
-
- [ ] `name` === check file's `category` string
|
|
109
|
-
- [ ] Import path has `.js` extension (ESM)
|
|
110
|
-
|
|
111
|
-
## Step 4: Compliance Mapping (Optional)
|
|
112
|
-
|
|
113
|
-
```typescript
|
|
114
|
-
// src/core/audit/compliance/mapper.ts
|
|
115
|
-
export const COMPLIANCE_MAP: Record<string, ComplianceRef[]> = {
|
|
116
|
-
// ─── $1 ────────────────────────────────────────
|
|
117
|
-
"CAT-CHECK-ONE": [
|
|
118
|
-
cis("5.x.x", "Control description", "full"),
|
|
119
|
-
pci("x.x.x", "PCI control", "partial"),
|
|
120
|
-
],
|
|
121
|
-
};
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
Helpers: `cis()`, `pci()`, `hipaa()`. Coverage: `"full"` or `"partial"`.
|
|
125
|
-
|
|
126
|
-
## Severity Guide
|
|
127
|
-
|
|
128
|
-
| Severity | When | Score weight |
|
|
129
|
-
|----------|------|-------------|
|
|
130
|
-
| `critical` | Exploitable, immediate fix required | 3x |
|
|
131
|
-
| `warning` | Risk exists but not urgent | 2x |
|
|
132
|
-
| `info` | Best practice, informational | 1x |
|
|
133
|
-
|
|
134
|
-
## Anti-Patterns
|
|
135
|
-
|
|
136
|
-
- **DON'T:** Typo in sentinel strings — parser silently returns empty array, no error
|
|
137
|
-
- **DON'T:** Throw exceptions in `check()` — no try/catch wrapper, entire category breaks
|
|
138
|
-
- **DON'T:** Reuse check ID across categories — compliance mapping will conflict
|
|
139
|
-
- **DON'T:** Multi-step scripts in `fixCommand` — keep it one-line, reference `kastell` command if needed
|
|
140
|
-
- **DON'T:** Forget `|| echo 'N/A'` fallback in SSH commands — parser breaks if command missing
|
|
141
|
-
|
|
142
|
-
## Next Steps
|
|
143
|
-
|
|
144
|
-
- [ ] Choose correct audit category (30 categories exist)
|
|
145
|
-
- [ ] Assign unique check key: `<CATEGORY>-NN` pattern
|
|
146
|
-
- [ ] Verify `passed` logic matches `currentValue` evaluation
|
|
147
|
-
- [ ] Add SSH command to category batch (avoid extra SSH round-trips)
|
|
148
|
-
- [ ] Write test: mock SSH output, verify correct passed/failed
|
|
149
|
-
- [ ] Run: `npm test -- --testPathPattern=audit`
|
|
150
|
-
- [ ] Verify check count: `kastell audit --json | jq '.summary.totalChecks'`
|
|
1
|
+
# Template: Audit Check — $1
|
|
2
|
+
|
|
3
|
+
## Files to Create/Modify
|
|
4
|
+
|
|
5
|
+
1. `src/core/audit/checks/$1.ts` — check definitions + parser
|
|
6
|
+
2. `src/core/audit/commands.ts` — SSH batch section
|
|
7
|
+
3. `src/core/audit/checks/index.ts` — registry entry
|
|
8
|
+
4. `src/core/audit/compliance/mapper.ts` — compliance mapping (optional)
|
|
9
|
+
5. `src/__tests__/core/audit/checks/$1.test.ts` — test file
|
|
10
|
+
|
|
11
|
+
## Step 1: Check File
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
// src/core/audit/checks/$1.ts
|
|
15
|
+
import type { AuditCheck, CheckParser } from "../../types.js";
|
|
16
|
+
|
|
17
|
+
interface $1CheckDef {
|
|
18
|
+
id: string; // "CATEGORY-CHECK-NAME" (uppercase, hyphen-separated)
|
|
19
|
+
name: string; // Human-readable description
|
|
20
|
+
severity: "critical" | "warning" | "info";
|
|
21
|
+
check: (output: string) => { passed: boolean; currentValue: string };
|
|
22
|
+
expectedValue: string;
|
|
23
|
+
fixCommand: string;
|
|
24
|
+
explain: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const $1_CHECKS: $1CheckDef[] = [
|
|
28
|
+
{
|
|
29
|
+
id: "CAT-CHECK-ONE",
|
|
30
|
+
name: "Check description",
|
|
31
|
+
severity: "warning",
|
|
32
|
+
check: (output) => {
|
|
33
|
+
const match = output.includes("SENTINEL_PASS");
|
|
34
|
+
return { passed: match, currentValue: match ? "configured" : "not found" };
|
|
35
|
+
},
|
|
36
|
+
expectedValue: "configured",
|
|
37
|
+
fixCommand: "command to fix",
|
|
38
|
+
explain: "Why this matters and what the fix does.",
|
|
39
|
+
},
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
export const parse$1Checks: CheckParser = (
|
|
43
|
+
sectionOutput: string,
|
|
44
|
+
_platform: string,
|
|
45
|
+
): AuditCheck[] => {
|
|
46
|
+
// Conditional category: return [] if not applicable (excluded from score)
|
|
47
|
+
if (!sectionOutput || sectionOutput.includes("SKIP_MARKER")) {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return $1_CHECKS.map((def) => {
|
|
52
|
+
const { passed, currentValue } = def.check(sectionOutput);
|
|
53
|
+
return {
|
|
54
|
+
id: def.id,
|
|
55
|
+
category: "Category Name", // MUST match CHECK_REGISTRY.name exactly
|
|
56
|
+
name: def.name,
|
|
57
|
+
severity: def.severity,
|
|
58
|
+
passed,
|
|
59
|
+
currentValue,
|
|
60
|
+
expectedValue: def.expectedValue,
|
|
61
|
+
fixCommand: def.fixCommand,
|
|
62
|
+
explain: def.explain,
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Step 2: SSH Batch Section
|
|
69
|
+
|
|
70
|
+
`src/core/audit/commands.ts` — add bash commands that run on the server.
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
function new$1Section(): string {
|
|
74
|
+
return [
|
|
75
|
+
NAMED_SEP("$1UPPER"), // MUST match CHECK_REGISTRY.sectionName exactly
|
|
76
|
+
`command1 || echo 'N/A'`,
|
|
77
|
+
`command2 || echo 'N/A'`,
|
|
78
|
+
].join("\n");
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Add to the correct batch array:
|
|
83
|
+
- `BATCH_FAST` — fast commands (<1s)
|
|
84
|
+
- `BATCH_MEDIUM` — medium commands (1-5s)
|
|
85
|
+
- `BATCH_SLOW` — slow commands (5s+, e.g., `nginx -T`)
|
|
86
|
+
|
|
87
|
+
**Sentinel matching is critical:** `NAMED_SEP("FOO")` produces `---SECTION:FOO---`. This string MUST match `CHECK_REGISTRY.sectionName` exactly.
|
|
88
|
+
|
|
89
|
+
For conditional categories, add a skip marker as first command:
|
|
90
|
+
```bash
|
|
91
|
+
command -v nginx >/dev/null 2>&1 || echo 'NGINX_NOT_INSTALLED'
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Step 3: Registry
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
// src/core/audit/checks/index.ts
|
|
98
|
+
import { parse$1Checks } from "./$1.js";
|
|
99
|
+
|
|
100
|
+
export const CHECK_REGISTRY: CategoryEntry[] = [
|
|
101
|
+
// ... existing categories ...
|
|
102
|
+
{ name: "Category Name", sectionName: "$1UPPER", parser: parse$1Checks },
|
|
103
|
+
];
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
**Triple-check:**
|
|
107
|
+
- [ ] `sectionName` === `NAMED_SEP()` parameter
|
|
108
|
+
- [ ] `name` === check file's `category` string
|
|
109
|
+
- [ ] Import path has `.js` extension (ESM)
|
|
110
|
+
|
|
111
|
+
## Step 4: Compliance Mapping (Optional)
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
// src/core/audit/compliance/mapper.ts
|
|
115
|
+
export const COMPLIANCE_MAP: Record<string, ComplianceRef[]> = {
|
|
116
|
+
// ─── $1 ────────────────────────────────────────
|
|
117
|
+
"CAT-CHECK-ONE": [
|
|
118
|
+
cis("5.x.x", "Control description", "full"),
|
|
119
|
+
pci("x.x.x", "PCI control", "partial"),
|
|
120
|
+
],
|
|
121
|
+
};
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Helpers: `cis()`, `pci()`, `hipaa()`. Coverage: `"full"` or `"partial"`.
|
|
125
|
+
|
|
126
|
+
## Severity Guide
|
|
127
|
+
|
|
128
|
+
| Severity | When | Score weight |
|
|
129
|
+
|----------|------|-------------|
|
|
130
|
+
| `critical` | Exploitable, immediate fix required | 3x |
|
|
131
|
+
| `warning` | Risk exists but not urgent | 2x |
|
|
132
|
+
| `info` | Best practice, informational | 1x |
|
|
133
|
+
|
|
134
|
+
## Anti-Patterns
|
|
135
|
+
|
|
136
|
+
- **DON'T:** Typo in sentinel strings — parser silently returns empty array, no error
|
|
137
|
+
- **DON'T:** Throw exceptions in `check()` — no try/catch wrapper, entire category breaks
|
|
138
|
+
- **DON'T:** Reuse check ID across categories — compliance mapping will conflict
|
|
139
|
+
- **DON'T:** Multi-step scripts in `fixCommand` — keep it one-line, reference `kastell` command if needed
|
|
140
|
+
- **DON'T:** Forget `|| echo 'N/A'` fallback in SSH commands — parser breaks if command missing
|
|
141
|
+
|
|
142
|
+
## Next Steps
|
|
143
|
+
|
|
144
|
+
- [ ] Choose correct audit category (30 categories exist)
|
|
145
|
+
- [ ] Assign unique check key: `<CATEGORY>-NN` pattern
|
|
146
|
+
- [ ] Verify `passed` logic matches `currentValue` evaluation
|
|
147
|
+
- [ ] Add SSH command to category batch (avoid extra SSH round-trips)
|
|
148
|
+
- [ ] Write test: mock SSH output, verify correct passed/failed
|
|
149
|
+
- [ ] Run: `npm test -- --testPathPattern=audit`
|
|
150
|
+
- [ ] Verify check count: `kastell audit --json | jq '.summary.totalChecks'`
|
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
# Template: CLI Command — $1
|
|
2
|
-
|
|
3
|
-
## Files to Create
|
|
4
|
-
|
|
5
|
-
1. `src/commands/$1.ts` — thin wrapper (parse args, call core, display result)
|
|
6
|
-
2. `src/core/$1.ts` — all business logic (no UI imports)
|
|
7
|
-
3. `src/__tests__/core/$1.test.ts` — test the core function, not the command
|
|
8
|
-
|
|
9
|
-
## Command File (thin wrapper)
|
|
10
|
-
|
|
11
|
-
```typescript
|
|
12
|
-
// src/commands/$1.ts
|
|
13
|
-
import { program } from 'commander';
|
|
14
|
-
import chalk from 'chalk';
|
|
15
|
-
import ora from 'ora';
|
|
16
|
-
import { $1Core } from '../core/$1.js';
|
|
17
|
-
|
|
18
|
-
program
|
|
19
|
-
.command('$1')
|
|
20
|
-
.description('TODO: describe what this command does')
|
|
21
|
-
.option('--server <name>', 'Target server name or IP')
|
|
22
|
-
.option('--json', 'Output as JSON')
|
|
23
|
-
.action(async (options) => {
|
|
24
|
-
const spinner = ora('Running $1...').start();
|
|
25
|
-
try {
|
|
26
|
-
const result = await $1Core(options);
|
|
27
|
-
spinner.succeed('Done');
|
|
28
|
-
if (options.json) {
|
|
29
|
-
console.log(JSON.stringify(result, null, 2));
|
|
30
|
-
} else {
|
|
31
|
-
console.log(chalk.green(result.message));
|
|
32
|
-
}
|
|
33
|
-
} catch (error) {
|
|
34
|
-
spinner.fail(error instanceof Error ? error.message : 'Unknown error');
|
|
35
|
-
process.exitCode = 1;
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
## Core File (all logic here)
|
|
41
|
-
|
|
42
|
-
```typescript
|
|
43
|
-
// src/core/$1.ts
|
|
44
|
-
export interface $1Options { server?: string; json?: boolean; }
|
|
45
|
-
export interface $1Result { success: boolean; message: string; }
|
|
46
|
-
|
|
47
|
-
export async function $1Core(options: $1Options): Promise<$1Result> {
|
|
48
|
-
// ALL business logic here. NO chalk/ora/UI imports.
|
|
49
|
-
// assertValidIp() before SSH. getAdapter(platform) for platform ops.
|
|
50
|
-
// withProviderErrorHandling() for provider calls.
|
|
51
|
-
throw new Error('Not implemented');
|
|
52
|
-
}
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
## Test File
|
|
56
|
-
|
|
57
|
-
```typescript
|
|
58
|
-
// src/__tests__/core/$1.test.ts
|
|
59
|
-
import { $1Core } from '../../core/$1.js';
|
|
60
|
-
jest.mock('../../utils/ssh.js');
|
|
61
|
-
|
|
62
|
-
describe('$1Core', () => {
|
|
63
|
-
beforeEach(() => jest.resetAllMocks());
|
|
64
|
-
|
|
65
|
-
it('should TODO: describe expected behavior', async () => {
|
|
66
|
-
const result = await $1Core({ server: 'test-server' });
|
|
67
|
-
expect(result.success).toBe(true);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
## Next Steps
|
|
73
|
-
|
|
74
|
-
- [ ] Register command in `src/index.ts`
|
|
75
|
-
- [ ] Write tests first (TDD: test core function, not command)
|
|
76
|
-
- [ ] Add `isSafeMode()` check if operation is destructive
|
|
77
|
-
- [ ] Add `assertValidIp()` before any SSH operation
|
|
78
|
-
- [ ] Use `getAdapter(platform)` for platform-specific operations (never import adapters directly)
|
|
79
|
-
- [ ] Run `npm run build && npm test && npm run lint`
|
|
80
|
-
- [ ] Update README.md command table
|
|
1
|
+
# Template: CLI Command — $1
|
|
2
|
+
|
|
3
|
+
## Files to Create
|
|
4
|
+
|
|
5
|
+
1. `src/commands/$1.ts` — thin wrapper (parse args, call core, display result)
|
|
6
|
+
2. `src/core/$1.ts` — all business logic (no UI imports)
|
|
7
|
+
3. `src/__tests__/core/$1.test.ts` — test the core function, not the command
|
|
8
|
+
|
|
9
|
+
## Command File (thin wrapper)
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
// src/commands/$1.ts
|
|
13
|
+
import { program } from 'commander';
|
|
14
|
+
import chalk from 'chalk';
|
|
15
|
+
import ora from 'ora';
|
|
16
|
+
import { $1Core } from '../core/$1.js';
|
|
17
|
+
|
|
18
|
+
program
|
|
19
|
+
.command('$1')
|
|
20
|
+
.description('TODO: describe what this command does')
|
|
21
|
+
.option('--server <name>', 'Target server name or IP')
|
|
22
|
+
.option('--json', 'Output as JSON')
|
|
23
|
+
.action(async (options) => {
|
|
24
|
+
const spinner = ora('Running $1...').start();
|
|
25
|
+
try {
|
|
26
|
+
const result = await $1Core(options);
|
|
27
|
+
spinner.succeed('Done');
|
|
28
|
+
if (options.json) {
|
|
29
|
+
console.log(JSON.stringify(result, null, 2));
|
|
30
|
+
} else {
|
|
31
|
+
console.log(chalk.green(result.message));
|
|
32
|
+
}
|
|
33
|
+
} catch (error) {
|
|
34
|
+
spinner.fail(error instanceof Error ? error.message : 'Unknown error');
|
|
35
|
+
process.exitCode = 1;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Core File (all logic here)
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
// src/core/$1.ts
|
|
44
|
+
export interface $1Options { server?: string; json?: boolean; }
|
|
45
|
+
export interface $1Result { success: boolean; message: string; }
|
|
46
|
+
|
|
47
|
+
export async function $1Core(options: $1Options): Promise<$1Result> {
|
|
48
|
+
// ALL business logic here. NO chalk/ora/UI imports.
|
|
49
|
+
// assertValidIp() before SSH. getAdapter(platform) for platform ops.
|
|
50
|
+
// withProviderErrorHandling() for provider calls.
|
|
51
|
+
throw new Error('Not implemented');
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Test File
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
// src/__tests__/core/$1.test.ts
|
|
59
|
+
import { $1Core } from '../../core/$1.js';
|
|
60
|
+
jest.mock('../../utils/ssh.js');
|
|
61
|
+
|
|
62
|
+
describe('$1Core', () => {
|
|
63
|
+
beforeEach(() => jest.resetAllMocks());
|
|
64
|
+
|
|
65
|
+
it('should TODO: describe expected behavior', async () => {
|
|
66
|
+
const result = await $1Core({ server: 'test-server' });
|
|
67
|
+
expect(result.success).toBe(true);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Next Steps
|
|
73
|
+
|
|
74
|
+
- [ ] Register command in `src/index.ts`
|
|
75
|
+
- [ ] Write tests first (TDD: test core function, not command)
|
|
76
|
+
- [ ] Add `isSafeMode()` check if operation is destructive
|
|
77
|
+
- [ ] Add `assertValidIp()` before any SSH operation
|
|
78
|
+
- [ ] Use `getAdapter(platform)` for platform-specific operations (never import adapters directly)
|
|
79
|
+
- [ ] Run `npm run build && npm test && npm run lint`
|
|
80
|
+
- [ ] Update README.md command table
|
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
# Template: MCP Tool — $1
|
|
2
|
-
|
|
3
|
-
## Files to Create
|
|
4
|
-
|
|
5
|
-
1. `src/mcp/tools/$1.ts` — Zod schema + handler
|
|
6
|
-
2. Update `src/mcp/server.ts` — import + registerTool()
|
|
7
|
-
3. `src/__tests__/mcp/$1.test.ts` — test handler function
|
|
8
|
-
|
|
9
|
-
## Tool File (Zod schema + handler)
|
|
10
|
-
|
|
11
|
-
```typescript
|
|
12
|
-
// src/mcp/tools/$1.ts
|
|
13
|
-
import { z } from 'zod';
|
|
14
|
-
import type { McpResponse } from '../types.js';
|
|
15
|
-
|
|
16
|
-
// IMPORTANT: Schema is a flat object, NOT wrapped in z.object()
|
|
17
|
-
// The SDK wraps it automatically
|
|
18
|
-
export const $1Schema = {
|
|
19
|
-
server: z.string().optional().describe('Server name or IP. Auto-selected if only one server exists.'),
|
|
20
|
-
action: z.enum(['TODO']).describe('TODO: describe actions'),
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export async function handle$1(params: {
|
|
24
|
-
server?: string;
|
|
25
|
-
action: string;
|
|
26
|
-
}): Promise<McpResponse> {
|
|
27
|
-
// Delegate to core function (NOT direct SSH/provider calls)
|
|
28
|
-
// Example: const result = await someCoreFunction(params);
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
content: [
|
|
32
|
-
{
|
|
33
|
-
type: 'text' as const,
|
|
34
|
-
text: JSON.stringify({ success: true }, null, 2),
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
## Server Registration
|
|
42
|
-
|
|
43
|
-
```typescript
|
|
44
|
-
// In src/mcp/server.ts
|
|
45
|
-
import { $1Schema, handle$1 } from './tools/$1.js';
|
|
46
|
-
|
|
47
|
-
server.registerTool('$1', {
|
|
48
|
-
description: 'TODO: 50-150 tokens. What it does. Actions. Constraints. Requirements.',
|
|
49
|
-
inputSchema: $1Schema,
|
|
50
|
-
annotations: {
|
|
51
|
-
title: 'TODO: Human-readable title',
|
|
52
|
-
readOnlyHint: false, // true if read-only
|
|
53
|
-
destructiveHint: false, // true if destructive
|
|
54
|
-
idempotentHint: false, // true if idempotent
|
|
55
|
-
openWorldHint: true,
|
|
56
|
-
},
|
|
57
|
-
}, async (params) => {
|
|
58
|
-
return handle$1(params);
|
|
59
|
-
});
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
## Next Steps
|
|
63
|
-
|
|
64
|
-
- [ ] Define Zod schema as flat object (NOT z.object() wrapper)
|
|
65
|
-
- [ ] Handler delegates to core/ functions (not direct SSH/provider)
|
|
66
|
-
- [ ] Add `server` param as `.optional()` with standard description
|
|
67
|
-
- [ ] Set annotations correctly (readOnlyHint, destructiveHint)
|
|
68
|
-
- [ ] Write description: "What it does. Actions: 'x' does Y. Constraints. For Z, use other_tool instead."
|
|
69
|
-
- [ ] Add SAFE_MODE check if destructive: `if (isSafeMode()) throw ...`
|
|
70
|
-
- [ ] Write test: call handler directly with mock params
|
|
71
|
-
- [ ] Run `npm run build && npm test && npm run lint`
|
|
72
|
-
- [ ] Update README.md MCP tools table
|
|
1
|
+
# Template: MCP Tool — $1
|
|
2
|
+
|
|
3
|
+
## Files to Create
|
|
4
|
+
|
|
5
|
+
1. `src/mcp/tools/$1.ts` — Zod schema + handler
|
|
6
|
+
2. Update `src/mcp/server.ts` — import + registerTool()
|
|
7
|
+
3. `src/__tests__/mcp/$1.test.ts` — test handler function
|
|
8
|
+
|
|
9
|
+
## Tool File (Zod schema + handler)
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
// src/mcp/tools/$1.ts
|
|
13
|
+
import { z } from 'zod';
|
|
14
|
+
import type { McpResponse } from '../types.js';
|
|
15
|
+
|
|
16
|
+
// IMPORTANT: Schema is a flat object, NOT wrapped in z.object()
|
|
17
|
+
// The SDK wraps it automatically
|
|
18
|
+
export const $1Schema = {
|
|
19
|
+
server: z.string().optional().describe('Server name or IP. Auto-selected if only one server exists.'),
|
|
20
|
+
action: z.enum(['TODO']).describe('TODO: describe actions'),
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export async function handle$1(params: {
|
|
24
|
+
server?: string;
|
|
25
|
+
action: string;
|
|
26
|
+
}): Promise<McpResponse> {
|
|
27
|
+
// Delegate to core function (NOT direct SSH/provider calls)
|
|
28
|
+
// Example: const result = await someCoreFunction(params);
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
content: [
|
|
32
|
+
{
|
|
33
|
+
type: 'text' as const,
|
|
34
|
+
text: JSON.stringify({ success: true }, null, 2),
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Server Registration
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
// In src/mcp/server.ts
|
|
45
|
+
import { $1Schema, handle$1 } from './tools/$1.js';
|
|
46
|
+
|
|
47
|
+
server.registerTool('$1', {
|
|
48
|
+
description: 'TODO: 50-150 tokens. What it does. Actions. Constraints. Requirements.',
|
|
49
|
+
inputSchema: $1Schema,
|
|
50
|
+
annotations: {
|
|
51
|
+
title: 'TODO: Human-readable title',
|
|
52
|
+
readOnlyHint: false, // true if read-only
|
|
53
|
+
destructiveHint: false, // true if destructive
|
|
54
|
+
idempotentHint: false, // true if idempotent
|
|
55
|
+
openWorldHint: true,
|
|
56
|
+
},
|
|
57
|
+
}, async (params) => {
|
|
58
|
+
return handle$1(params);
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Next Steps
|
|
63
|
+
|
|
64
|
+
- [ ] Define Zod schema as flat object (NOT z.object() wrapper)
|
|
65
|
+
- [ ] Handler delegates to core/ functions (not direct SSH/provider)
|
|
66
|
+
- [ ] Add `server` param as `.optional()` with standard description
|
|
67
|
+
- [ ] Set annotations correctly (readOnlyHint, destructiveHint)
|
|
68
|
+
- [ ] Write description: "What it does. Actions: 'x' does Y. Constraints. For Z, use other_tool instead."
|
|
69
|
+
- [ ] Add SAFE_MODE check if destructive: `if (isSafeMode()) throw ...`
|
|
70
|
+
- [ ] Write test: call handler directly with mock params
|
|
71
|
+
- [ ] Run `npm run build && npm test && npm run lint`
|
|
72
|
+
- [ ] Update README.md MCP tools table
|