check-post 0.1.0 → 0.2.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/README.md +66 -60
- package/dist/cli.js +18 -18
- package/dist/commands/init.js +37 -36
- package/dist/commands/list.js +1 -1
- package/dist/commands/run.js +8 -8
- package/dist/commands/shared.js +2 -2
- package/dist/commands/status.js +3 -3
- package/dist/core/adapters/claude-code.js +12 -12
- package/dist/core/adapters/index.js +2 -2
- package/dist/core/discovery.js +8 -8
- package/dist/core/gate.js +13 -13
- package/dist/core/process.js +2 -2
- package/dist/core/project.js +5 -5
- package/dist/core/runners/ai.js +9 -9
- package/dist/core/runners/command.js +3 -3
- package/dist/core/scheduler.js +11 -10
- package/dist/core/stage-file.js +4 -4
- package/dist/core/types.js +4 -2
- package/dist/ui/format.js +1 -1
- package/dist/ui/plain.js +2 -2
- package/dist/ui/tui/App.js +13 -13
- package/package.json +2 -2
- package/presets/angular/04-security/01-secrets.md +12 -12
- package/presets/angular/04-security/02-xss-audit.md +9 -9
- package/presets/angular/04-security/03-env-audit.md +7 -7
- package/presets/angular/04-security/_group.md +1 -1
- package/presets/angular/05-code-standard.md +8 -8
- package/presets/angular/context.md +2 -2
- package/presets/nextjs/04-security/01-secrets.md +12 -12
- package/presets/nextjs/04-security/02-xss-audit.md +8 -8
- package/presets/nextjs/04-security/03-env-audit.md +7 -7
- package/presets/nextjs/04-security/_group.md +1 -1
- package/presets/nextjs/05-code-standard.md +8 -8
- package/presets/nextjs/context.md +1 -1
- package/presets/node/04-security/01-secrets.md +12 -12
- package/presets/node/04-security/02-injection-audit.md +7 -7
- package/presets/node/04-security/03-env-audit.md +7 -7
- package/presets/node/04-security/_group.md +1 -1
- package/presets/node/05-code-standard.md +8 -8
- package/presets/node/context.md +1 -1
|
@@ -2,7 +2,7 @@ import { execa } from 'execa';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { killTree } from '../process.js';
|
|
4
4
|
const READ_TOOLS = ['Read', 'Grep', 'Glob'];
|
|
5
|
-
/**
|
|
5
|
+
/** Turn sensitive_paths globs into Claude Code permission deny rules. */
|
|
6
6
|
export function denyRules(globs) {
|
|
7
7
|
const rules = [];
|
|
8
8
|
for (const glob of globs) {
|
|
@@ -16,11 +16,11 @@ function describeToolUse(name, input, cwd) {
|
|
|
16
16
|
const rel = (p) => (typeof p === 'string' ? path.relative(cwd, p) || p : '');
|
|
17
17
|
switch (name) {
|
|
18
18
|
case 'Read':
|
|
19
|
-
return `
|
|
19
|
+
return `reading ${rel(input.file_path)}`;
|
|
20
20
|
case 'Grep':
|
|
21
|
-
return `
|
|
21
|
+
return `searching "${String(input.pattern ?? '')}"${input.path ? ` in ${rel(input.path)}` : ''}`;
|
|
22
22
|
case 'Glob':
|
|
23
|
-
return `
|
|
23
|
+
return `finding files ${String(input.pattern ?? '')}`;
|
|
24
24
|
default:
|
|
25
25
|
return name;
|
|
26
26
|
}
|
|
@@ -51,8 +51,8 @@ export function createClaudeCodeAdapter(bin = 'claude') {
|
|
|
51
51
|
'--permission-mode',
|
|
52
52
|
'dontAsk',
|
|
53
53
|
'--no-session-persistence',
|
|
54
|
-
//
|
|
55
|
-
// per stage
|
|
54
|
+
// Minimal context: no MCP servers, plugins, or user settings. This cuts the cost
|
|
55
|
+
// per stage from dollars to cents.
|
|
56
56
|
'--strict-mcp-config',
|
|
57
57
|
'--setting-sources',
|
|
58
58
|
'project',
|
|
@@ -113,7 +113,7 @@ export function createClaudeCodeAdapter(bin = 'claude') {
|
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
catch {
|
|
116
|
-
/* stream
|
|
116
|
+
/* stream closed when the process is killed */
|
|
117
117
|
}
|
|
118
118
|
const done = await child;
|
|
119
119
|
clearTimeout(timer);
|
|
@@ -121,14 +121,14 @@ export function createClaudeCodeAdapter(bin = 'claude') {
|
|
|
121
121
|
if (!final) {
|
|
122
122
|
const stderr = Array.isArray(done.stderr) ? done.stderr.join('\n') : String(done.stderr ?? '');
|
|
123
123
|
const reason = canceled
|
|
124
|
-
? '
|
|
124
|
+
? 'cancelled'
|
|
125
125
|
: timedOut
|
|
126
|
-
? `
|
|
127
|
-
: stderr.trim() || `claude
|
|
128
|
-
throw new Error(`Claude Code
|
|
126
|
+
? `timed out after ${Math.round(o.timeoutMs / 1000)}s`
|
|
127
|
+
: stderr.trim() || `claude exited with code ${done.exitCode}`;
|
|
128
|
+
throw new Error(`Claude Code failed: ${reason}`);
|
|
129
129
|
}
|
|
130
130
|
if (final.is_error) {
|
|
131
|
-
throw new Error(`Claude Code error: ${String(final.result ?? final.subtype ?? '
|
|
131
|
+
throw new Error(`Claude Code error: ${String(final.result ?? final.subtype ?? 'unknown')}`);
|
|
132
132
|
}
|
|
133
133
|
const denials = final.permission_denials ?? [];
|
|
134
134
|
return {
|
|
@@ -7,8 +7,8 @@ export const AGENTS = {
|
|
|
7
7
|
export function getAdapter(id) {
|
|
8
8
|
const agent = AGENTS[id];
|
|
9
9
|
if (!agent)
|
|
10
|
-
throw new Error(`
|
|
10
|
+
throw new Error(`Unknown agent "${id}". Options: ${Object.keys(AGENTS).join(', ')}`);
|
|
11
11
|
if (!agent.create)
|
|
12
|
-
throw new Error(`Agent "${agent.label}"
|
|
12
|
+
throw new Error(`Agent "${agent.label}" is not supported yet. Use claude-code for now.`);
|
|
13
13
|
return agent.create();
|
|
14
14
|
}
|
package/dist/core/discovery.js
CHANGED
|
@@ -28,7 +28,7 @@ function listEntries(dir, isRoot) {
|
|
|
28
28
|
if (fsName.startsWith('.'))
|
|
29
29
|
continue;
|
|
30
30
|
if (fsName.startsWith('_'))
|
|
31
|
-
continue; //
|
|
31
|
+
continue; // includes _group.md, which is read separately
|
|
32
32
|
if (isRoot && fsName === PIPELINE_FILE)
|
|
33
33
|
continue;
|
|
34
34
|
const full = path.join(dir, fsName);
|
|
@@ -42,7 +42,7 @@ function listEntries(dir, isRoot) {
|
|
|
42
42
|
export function discoverPipeline(root, dirName = PIPELINE_DIR) {
|
|
43
43
|
const dir = path.join(root, dirName);
|
|
44
44
|
if (!existsSync(dir) || !statSync(dir).isDirectory()) {
|
|
45
|
-
throw new DefinitionError([`Folder ${dirName}/
|
|
45
|
+
throw new DefinitionError([`Folder ${dirName}/ not found in ${root}. Run "checkpost init" first.`]);
|
|
46
46
|
}
|
|
47
47
|
const problems = [];
|
|
48
48
|
const rel = (p) => path.relative(root, p);
|
|
@@ -72,7 +72,7 @@ export function discoverPipeline(root, dirName = PIPELINE_DIR) {
|
|
|
72
72
|
continue;
|
|
73
73
|
const other = seen.get(e.prefix);
|
|
74
74
|
if (other)
|
|
75
|
-
problems.push(`${rel(current) || '.'}: prefix ${e.prefix}
|
|
75
|
+
problems.push(`${rel(current) || '.'}: prefix ${e.prefix} is used twice (${other} and ${e.fsName})`);
|
|
76
76
|
else
|
|
77
77
|
seen.set(e.prefix, e.fsName);
|
|
78
78
|
}
|
|
@@ -101,7 +101,7 @@ export function discoverPipeline(root, dirName = PIPELINE_DIR) {
|
|
|
101
101
|
continue;
|
|
102
102
|
const children = walk(e.full, groupContext, false);
|
|
103
103
|
if (children.length === 0) {
|
|
104
|
-
problems.push(`${rel(e.full)}/:
|
|
104
|
+
problems.push(`${rel(e.full)}/: empty group (no enabled .md stages)`);
|
|
105
105
|
continue;
|
|
106
106
|
}
|
|
107
107
|
const group = {
|
|
@@ -122,7 +122,7 @@ export function discoverPipeline(root, dirName = PIPELINE_DIR) {
|
|
|
122
122
|
continue;
|
|
123
123
|
const type = stageTypeOf(data.run, body);
|
|
124
124
|
if (!type) {
|
|
125
|
-
problems.push(`${rel(e.full)}: stage
|
|
125
|
+
problems.push(`${rel(e.full)}: empty stage. Add "run:" to the frontmatter, AI instructions to the body, or both.`);
|
|
126
126
|
continue;
|
|
127
127
|
}
|
|
128
128
|
const stage = {
|
|
@@ -148,13 +148,13 @@ export function discoverPipeline(root, dirName = PIPELINE_DIR) {
|
|
|
148
148
|
};
|
|
149
149
|
const children = walk(dir, rootContext, true);
|
|
150
150
|
if (problems.length === 0 && children.length === 0) {
|
|
151
|
-
problems.push(`${dirName}/:
|
|
151
|
+
problems.push(`${dirName}/: no stages yet. Add a file such as 01-build.md.`);
|
|
152
152
|
}
|
|
153
153
|
if (problems.length)
|
|
154
154
|
throw new DefinitionError(problems);
|
|
155
155
|
return { root, dir, config: pipelineConfig, children };
|
|
156
156
|
}
|
|
157
|
-
/**
|
|
157
|
+
/** Every node in display order, with its depth. */
|
|
158
158
|
export function flatten(nodes, depth = 0) {
|
|
159
159
|
const out = [];
|
|
160
160
|
for (const node of nodes) {
|
|
@@ -169,7 +169,7 @@ export function allStages(nodes) {
|
|
|
169
169
|
.map((x) => x.node)
|
|
170
170
|
.filter((n) => n.kind === 'stage');
|
|
171
171
|
}
|
|
172
|
-
/**
|
|
172
|
+
/** Find a node by exact id, id without prefixes, or name. */
|
|
173
173
|
export function findNode(nodes, query) {
|
|
174
174
|
const q = query.replace(/\.md$/i, '').replace(/\/+$/, '');
|
|
175
175
|
const all = flatten(nodes).map((x) => x.node);
|
package/dist/core/gate.js
CHANGED
|
@@ -6,7 +6,7 @@ import { allStages } from './discovery.js';
|
|
|
6
6
|
import { isBlockingFailure } from './scheduler.js';
|
|
7
7
|
export const STATE_DIR = '.checkpost';
|
|
8
8
|
const LAST_RUN = 'last-run.json';
|
|
9
|
-
/**
|
|
9
|
+
/** checkpost's own paths do not count as project changes. */
|
|
10
10
|
const isOwnPath = (file) => file.startsWith(`${STATE_DIR}/`) || file.startsWith('checkpost/') || file === '.claude/commands/checkpost.md';
|
|
11
11
|
export async function readGitState(cwd) {
|
|
12
12
|
try {
|
|
@@ -18,7 +18,7 @@ export async function readGitState(cwd) {
|
|
|
18
18
|
return { isRepo: false, sha: null, branch: null, dirtyFiles: [] };
|
|
19
19
|
}
|
|
20
20
|
const sha = await execa('git', ['rev-parse', 'HEAD'], { cwd, reject: false });
|
|
21
|
-
// symbolic-ref
|
|
21
|
+
// symbolic-ref also works in a repo with no commits (rev-parse HEAD fails there).
|
|
22
22
|
const branch = await execa('git', ['symbolic-ref', '--short', '-q', 'HEAD'], { cwd, reject: false });
|
|
23
23
|
const status = await execa('git', ['status', '--porcelain', '--untracked-files=all'], { cwd });
|
|
24
24
|
const dirtyFiles = status.stdout
|
|
@@ -33,7 +33,7 @@ export async function readGitState(cwd) {
|
|
|
33
33
|
dirtyFiles,
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
|
-
/** Hash
|
|
36
|
+
/** Hash of every stage definition, so editing a .md file invalidates old results. */
|
|
37
37
|
export function definitionsHash(pipeline) {
|
|
38
38
|
const h = createHash('sha256');
|
|
39
39
|
h.update(JSON.stringify(pipeline.config));
|
|
@@ -58,8 +58,8 @@ export function readLastRun(root) {
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
61
|
+
* Save run results. A partial run (one stage/group) is merged into the previous results
|
|
62
|
+
* as long as the commit and stage definitions are unchanged.
|
|
63
63
|
*/
|
|
64
64
|
export function saveRun(pipeline, git, results, partial) {
|
|
65
65
|
const hash = definitionsHash(pipeline);
|
|
@@ -83,29 +83,29 @@ export async function evaluateGate(pipeline) {
|
|
|
83
83
|
const lastRun = readLastRun(pipeline.root);
|
|
84
84
|
const reasons = [];
|
|
85
85
|
if (!lastRun) {
|
|
86
|
-
reasons.push('pipeline
|
|
86
|
+
reasons.push('pipeline has never been run');
|
|
87
87
|
return { green: false, reasons, lastRun, git };
|
|
88
88
|
}
|
|
89
89
|
if (git.isRepo && lastRun.sha !== git.sha) {
|
|
90
|
-
reasons.push(`
|
|
90
|
+
reasons.push(`last results are for commit ${lastRun.sha?.slice(0, 7) ?? '?'}, HEAD is now ${git.sha?.slice(0, 7) ?? '?'}`);
|
|
91
91
|
}
|
|
92
92
|
if (lastRun.definitionsHash !== definitionsHash(pipeline)) {
|
|
93
|
-
reasons.push('
|
|
93
|
+
reasons.push('stage definitions changed since the last run');
|
|
94
94
|
}
|
|
95
95
|
if (pipeline.config.require_clean_tree && git.isRepo) {
|
|
96
96
|
if (git.dirtyFiles.length)
|
|
97
|
-
reasons.push(`working tree
|
|
97
|
+
reasons.push(`working tree is dirty (${git.dirtyFiles.length} uncommitted file${git.dirtyFiles.length === 1 ? '' : 's'})`);
|
|
98
98
|
else if (lastRun.dirtyAtRun.length)
|
|
99
|
-
reasons.push('run
|
|
99
|
+
reasons.push('the last run happened on a dirty working tree');
|
|
100
100
|
}
|
|
101
101
|
for (const stage of allStages(pipeline.children)) {
|
|
102
102
|
const r = lastRun.results[stage.id];
|
|
103
103
|
if (!r)
|
|
104
|
-
reasons.push(`stage ${stage.id}
|
|
104
|
+
reasons.push(`stage ${stage.id} has not run`);
|
|
105
105
|
else if (isBlockingFailure(r))
|
|
106
|
-
reasons.push(`stage ${stage.id} ${r.status === 'error' ? '
|
|
106
|
+
reasons.push(`stage ${stage.id} ${r.status === 'error' ? 'errored' : 'failed'}`);
|
|
107
107
|
else if (r.status === 'skipped' || r.status === 'pending' || r.status === 'running')
|
|
108
|
-
reasons.push(`stage ${stage.id}
|
|
108
|
+
reasons.push(`stage ${stage.id} did not finish (${r.status})`);
|
|
109
109
|
}
|
|
110
110
|
return { green: reasons.length === 0, reasons, lastRun, git };
|
|
111
111
|
}
|
package/dist/core/process.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Stop a whole process group (SIGTERM, then SIGKILL if still alive). */
|
|
2
2
|
export function killTree(pid, graceMs = 3000) {
|
|
3
3
|
if (!pid)
|
|
4
4
|
return;
|
|
@@ -11,7 +11,7 @@ export function killTree(pid, graceMs = 3000) {
|
|
|
11
11
|
process.kill(pid, signal);
|
|
12
12
|
}
|
|
13
13
|
catch {
|
|
14
|
-
/*
|
|
14
|
+
/* already dead */
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
};
|
package/dist/core/project.js
CHANGED
|
@@ -12,7 +12,7 @@ export function detectProject(root) {
|
|
|
12
12
|
deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
13
13
|
}
|
|
14
14
|
catch {
|
|
15
|
-
/* package.json
|
|
15
|
+
/* broken package.json: treat as a project without scripts */
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
const docs = ['AGENTS.md', 'CLAUDE.md', '.claude/CLAUDE.md', 'CONTRIBUTING.md'].filter((f) => existsSync(path.join(root, f)));
|
|
@@ -25,9 +25,9 @@ export function detectProject(root) {
|
|
|
25
25
|
}
|
|
26
26
|
if (existsSync(pkgFile))
|
|
27
27
|
return { kind: 'node', label: 'Node.js', scripts, docs };
|
|
28
|
-
return { kind: 'unknown', label: '
|
|
28
|
+
return { kind: 'unknown', label: 'unknown', scripts, docs };
|
|
29
29
|
}
|
|
30
|
-
/**
|
|
30
|
+
/** npm script required by a `run` command, or null if it is not an npm command. */
|
|
31
31
|
export function npmScriptOf(run) {
|
|
32
32
|
const m = run.trim().match(/^npm\s+(?:run(?:-script)?\s+([\w:.-]+)|(test|start))\b/);
|
|
33
33
|
return m ? (m[1] ?? m[2]) : null;
|
|
@@ -41,8 +41,8 @@ export async function isIgnored(root, rel) {
|
|
|
41
41
|
return res.exitCode === 0;
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
44
|
+
* Add patterns to `.git/info/exclude` (local only) or `.gitignore` (shared),
|
|
45
|
+
* only when git does not already ignore them.
|
|
46
46
|
*/
|
|
47
47
|
export async function ignorePaths(root, patterns, where) {
|
|
48
48
|
const added = [];
|
package/dist/core/runners/ai.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { AiVerdictSchema, SEVERITIES, severityRank } from '../types.js';
|
|
3
3
|
/**
|
|
4
|
-
* JSON Schema
|
|
5
|
-
*
|
|
4
|
+
* JSON Schema sent to the AI; must stay in sync with AiVerdictSchema.
|
|
5
|
+
* The `$schema` key is dropped because Claude Code rejects the draft 2020-12 reference.
|
|
6
6
|
*/
|
|
7
7
|
export const VERDICT_JSON_SCHEMA = (() => {
|
|
8
8
|
const { $schema: _ignored, ...schema } = z.toJSONSchema(AiVerdictSchema);
|
|
9
9
|
return schema;
|
|
10
10
|
})();
|
|
11
11
|
const MAX_COMMAND_OUTPUT_CHARS = 30_000;
|
|
12
|
-
export function buildSystemPrompt(sensitivePaths) {
|
|
12
|
+
export function buildSystemPrompt(sensitivePaths, language = 'English') {
|
|
13
13
|
return [
|
|
14
14
|
'You are an automated stage in a local CI pipeline. You audit a software project and report findings.',
|
|
15
15
|
'Rules:',
|
|
@@ -21,7 +21,7 @@ export function buildSystemPrompt(sensitivePaths) {
|
|
|
21
21
|
'- Severity scale: critical (exploitable now / leaked secret), high (likely exploitable or serious bug), ' +
|
|
22
22
|
'medium (should be fixed soon), low (minor / hardening), info (observation, not a problem).',
|
|
23
23
|
'- If nothing is wrong, return an empty findings array.',
|
|
24
|
-
|
|
24
|
+
`- Write summary, message and suggestion in ${language}, regardless of the language of the code or instructions.`,
|
|
25
25
|
'- Your final answer MUST be the structured output object: { summary, findings[] }.',
|
|
26
26
|
].join('\n');
|
|
27
27
|
}
|
|
@@ -35,7 +35,7 @@ export function buildStagePrompt(stage, command) {
|
|
|
35
35
|
}
|
|
36
36
|
if (command) {
|
|
37
37
|
const out = command.output.length > MAX_COMMAND_OUTPUT_CHARS
|
|
38
|
-
? '[... output
|
|
38
|
+
? '[... earlier output truncated ...]\n' + command.output.slice(-MAX_COMMAND_OUTPUT_CHARS)
|
|
39
39
|
: command.output;
|
|
40
40
|
parts.push('## Command result', `Command: \`${command.run}\``, `Exit code: ${command.exitCode ?? 'unknown'}`, 'Output:', '```', out.trimEnd(), '```', 'Review this command result according to the stage instructions below. If the command failed because of a real problem, report it as a finding.');
|
|
41
41
|
}
|
|
@@ -48,9 +48,9 @@ export function isBlocking(finding, failOn) {
|
|
|
48
48
|
export function sortFindings(findings) {
|
|
49
49
|
return [...findings].sort((a, b) => severityRank(a.severity) - severityRank(b.severity));
|
|
50
50
|
}
|
|
51
|
-
/**
|
|
51
|
+
/** Run an AI stage; ask again once if the answer does not match the schema. */
|
|
52
52
|
export async function runAiStage(adapter, stage, opts) {
|
|
53
|
-
const systemPrompt = buildSystemPrompt(opts.sensitivePaths);
|
|
53
|
+
const systemPrompt = buildSystemPrompt(opts.sensitivePaths, opts.language);
|
|
54
54
|
let prompt = buildStagePrompt(stage, opts.command);
|
|
55
55
|
let cost = 0;
|
|
56
56
|
const denied = [];
|
|
@@ -82,10 +82,10 @@ export async function runAiStage(adapter, stage, opts) {
|
|
|
82
82
|
if (parsed.success) {
|
|
83
83
|
return { verdict: { ...parsed.data, findings: sortFindings(parsed.data.findings) }, costUsd: cost, deniedReads: denied };
|
|
84
84
|
}
|
|
85
|
-
opts.onLog(`[AI]
|
|
85
|
+
opts.onLog(`[AI] answer did not match the required format (attempt ${attempt}/2)`);
|
|
86
86
|
prompt =
|
|
87
87
|
buildStagePrompt(stage, opts.command) +
|
|
88
88
|
`\n\nIMPORTANT: your previous answer was not valid. Return ONLY the structured object with "summary" and "findings" (severity one of ${SEVERITIES.join(', ')}).`;
|
|
89
89
|
}
|
|
90
|
-
throw new Error('AI
|
|
90
|
+
throw new Error('AI did not return a validly formatted answer after 2 attempts');
|
|
91
91
|
}
|
|
@@ -2,8 +2,8 @@ import { execa } from 'execa';
|
|
|
2
2
|
import { killTree } from '../process.js';
|
|
3
3
|
const MAX_KEPT_OUTPUT = 200_000;
|
|
4
4
|
export async function runCommand(command, opts) {
|
|
5
|
-
// detached:
|
|
6
|
-
//
|
|
5
|
+
// detached: the process leads its own process group, so a timeout or cancel can stop
|
|
6
|
+
// every descendant (e.g. `ng test` spawning a browser), not just the shell.
|
|
7
7
|
const child = execa(command, {
|
|
8
8
|
shell: true,
|
|
9
9
|
cwd: opts.cwd,
|
|
@@ -39,7 +39,7 @@ export async function runCommand(command, opts) {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
catch {
|
|
42
|
-
/* stream
|
|
42
|
+
/* stream closed when the process is killed */
|
|
43
43
|
}
|
|
44
44
|
const done = await child;
|
|
45
45
|
clearTimeout(timer);
|
package/dist/core/scheduler.js
CHANGED
|
@@ -3,11 +3,11 @@ import path from 'node:path';
|
|
|
3
3
|
import { runAiStage, isBlocking } from './runners/ai.js';
|
|
4
4
|
import { runCommand } from './runners/command.js';
|
|
5
5
|
import { parseDuration } from './stage-file.js';
|
|
6
|
-
//
|
|
6
|
+
// Same as STATE_DIR in gate.ts (not imported, to avoid a circular import).
|
|
7
7
|
const STATE_DIR_NAME = '.checkpost';
|
|
8
8
|
const DEFAULT_COMMAND_TIMEOUT_MS = 15 * 60_000;
|
|
9
9
|
const DEFAULT_AI_TIMEOUT_MS = 10 * 60_000;
|
|
10
|
-
/**
|
|
10
|
+
/** A stage/group blocks the pipeline when it failed and is not allow_failure. */
|
|
11
11
|
export const isBlockingFailure = (r) => (r.status === 'failed' || r.status === 'error') && !r.allowFailure;
|
|
12
12
|
function stagesIn(node) {
|
|
13
13
|
return node.kind === 'stage' ? [node] : node.children.flatMap(stagesIn);
|
|
@@ -67,7 +67,7 @@ export async function runPipeline(pipeline, opts) {
|
|
|
67
67
|
onLine: emit,
|
|
68
68
|
});
|
|
69
69
|
if (res.canceled)
|
|
70
|
-
return finish({ status: 'skipped', summary: '
|
|
70
|
+
return finish({ status: 'skipped', summary: 'cancelled', exitCode: res.exitCode });
|
|
71
71
|
if (res.timedOut)
|
|
72
72
|
return finish({ status: 'error', error: 'timeout', exitCode: res.exitCode });
|
|
73
73
|
if (stage.type === 'command') {
|
|
@@ -78,13 +78,14 @@ export async function runPipeline(pipeline, opts) {
|
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
80
|
command = { run, exitCode: res.exitCode, output: res.output };
|
|
81
|
-
emit(`[AI]
|
|
81
|
+
emit(`[AI] reviewing the command result (exit code ${res.exitCode})…`);
|
|
82
82
|
}
|
|
83
83
|
if (!opts.adapter)
|
|
84
|
-
throw new Error('
|
|
84
|
+
throw new Error('AI stage needs an agent, but none is available');
|
|
85
85
|
const outcome = await runAiStage(opts.adapter, stage, {
|
|
86
86
|
cwd: pipeline.root,
|
|
87
87
|
model: pipeline.config.model,
|
|
88
|
+
language: pipeline.config.language,
|
|
88
89
|
sensitivePaths: pipeline.config.sensitive_paths,
|
|
89
90
|
maxBudgetUsd: pipeline.config.max_budget_usd,
|
|
90
91
|
timeoutMs: parseDuration(stage.config.timeout, DEFAULT_AI_TIMEOUT_MS),
|
|
@@ -93,7 +94,7 @@ export async function runPipeline(pipeline, opts) {
|
|
|
93
94
|
command,
|
|
94
95
|
});
|
|
95
96
|
for (const denied of outcome.deniedReads)
|
|
96
|
-
emit(`[AI]
|
|
97
|
+
emit(`[AI] access blocked: ${denied}`);
|
|
97
98
|
const blocking = outcome.verdict.findings.filter((f) => isBlocking(f, stage.config.fail_on));
|
|
98
99
|
emit(`[AI] ${outcome.verdict.summary}`);
|
|
99
100
|
return finish({
|
|
@@ -106,13 +107,13 @@ export async function runPipeline(pipeline, opts) {
|
|
|
106
107
|
}
|
|
107
108
|
catch (err) {
|
|
108
109
|
if (opts.signal?.aborted)
|
|
109
|
-
return finish({ status: 'skipped', summary: '
|
|
110
|
+
return finish({ status: 'skipped', summary: 'cancelled' });
|
|
110
111
|
const message = err.message;
|
|
111
112
|
emit(`ERROR: ${message}`);
|
|
112
113
|
return finish({ status: 'error', error: message });
|
|
113
114
|
}
|
|
114
115
|
};
|
|
115
|
-
/**
|
|
116
|
+
/** Returns true when the node ended in a blocking failure. */
|
|
116
117
|
const runNode = async (node, failFast) => {
|
|
117
118
|
if (node.kind === 'stage')
|
|
118
119
|
return isBlockingFailure(await runStage(node));
|
|
@@ -136,13 +137,13 @@ export async function runPipeline(pipeline, opts) {
|
|
|
136
137
|
let failed = false;
|
|
137
138
|
for (let i = 0; i < nodes.length; i++) {
|
|
138
139
|
if (opts.signal?.aborted) {
|
|
139
|
-
skip(nodes.slice(i), '
|
|
140
|
+
skip(nodes.slice(i), 'cancelled');
|
|
140
141
|
break;
|
|
141
142
|
}
|
|
142
143
|
if (await runNode(nodes[i], failFast)) {
|
|
143
144
|
failed = true;
|
|
144
145
|
if (failFast) {
|
|
145
|
-
skip(nodes.slice(i + 1), '
|
|
146
|
+
skip(nodes.slice(i + 1), 'skipped: an earlier stage failed');
|
|
146
147
|
break;
|
|
147
148
|
}
|
|
148
149
|
}
|
package/dist/core/stage-file.js
CHANGED
|
@@ -7,15 +7,15 @@ export class DefinitionError extends Error {
|
|
|
7
7
|
this.name = 'DefinitionError';
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
-
/** Parse frontmatter
|
|
10
|
+
/** Parse YAML frontmatter + Markdown body, then validate the frontmatter against a schema. */
|
|
11
11
|
export function parseMarkdown(source, schema, fileLabel) {
|
|
12
12
|
let parsed;
|
|
13
13
|
try {
|
|
14
|
-
//
|
|
14
|
+
// No cache: gray-matter caches by input string, which breaks tests.
|
|
15
15
|
parsed = matter(source, {});
|
|
16
16
|
}
|
|
17
17
|
catch (err) {
|
|
18
|
-
throw new DefinitionError([`${fileLabel}:
|
|
18
|
+
throw new DefinitionError([`${fileLabel}: invalid YAML frontmatter (${err.message})`]);
|
|
19
19
|
}
|
|
20
20
|
const result = schema.safeParse(parsed.data ?? {});
|
|
21
21
|
if (!result.success) {
|
|
@@ -38,7 +38,7 @@ export function stageTypeOf(run, body) {
|
|
|
38
38
|
return 'ai';
|
|
39
39
|
return null;
|
|
40
40
|
}
|
|
41
|
-
/**
|
|
41
|
+
/** Convert `30s`, `5m`, `1h`, `500ms`, or a number (seconds) to milliseconds. */
|
|
42
42
|
export function parseDuration(value, fallbackMs) {
|
|
43
43
|
if (value === undefined)
|
|
44
44
|
return fallbackMs;
|
package/dist/core/types.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
export const SEVERITIES = ['critical', 'high', 'medium', 'low', 'info'];
|
|
3
|
-
/**
|
|
3
|
+
/** Severity rank: lower number = more severe. */
|
|
4
4
|
export const severityRank = (s) => SEVERITIES.indexOf(s);
|
|
5
5
|
const duration = z.union([z.number().positive(), z.string().regex(/^\d+(\.\d+)?\s*(ms|s|m|h)?$/)]);
|
|
6
6
|
export const StageConfigSchema = z
|
|
7
7
|
.object({
|
|
8
8
|
name: z.string().optional(),
|
|
9
|
-
// YAML
|
|
9
|
+
// YAML reads `run: true` or `run: 123` as a boolean/number; treat it as a command.
|
|
10
10
|
run: z.union([z.string(), z.number(), z.boolean()]).transform(String).optional(),
|
|
11
11
|
timeout: duration.optional(),
|
|
12
12
|
fail_on: z.enum(SEVERITIES).default('high'),
|
|
@@ -42,6 +42,8 @@ export const PipelineConfigSchema = z
|
|
|
42
42
|
name: z.string().optional(),
|
|
43
43
|
agent: z.string().default('claude-code'),
|
|
44
44
|
model: z.string().default('sonnet'),
|
|
45
|
+
/** Language for AI summaries and findings, e.g. English or Indonesian. */
|
|
46
|
+
language: z.string().min(1).default('English'),
|
|
45
47
|
fail_fast: z.boolean().default(true),
|
|
46
48
|
require_clean_tree: z.boolean().default(true),
|
|
47
49
|
sensitive_paths: z.array(z.string()).default([]),
|
package/dist/ui/format.js
CHANGED
|
@@ -32,7 +32,7 @@ export function formatDuration(ms) {
|
|
|
32
32
|
}
|
|
33
33
|
export function typeLabel(node) {
|
|
34
34
|
if (node.kind === 'group')
|
|
35
|
-
return node.config.parallel ? '
|
|
35
|
+
return node.config.parallel ? 'parallel group' : 'group';
|
|
36
36
|
if (node.type === 'ai')
|
|
37
37
|
return 'AI';
|
|
38
38
|
if (node.type === 'command+ai')
|
package/dist/ui/plain.js
CHANGED
|
@@ -2,7 +2,7 @@ import pc from 'picocolors';
|
|
|
2
2
|
import { isBlocking } from '../core/runners/ai.js';
|
|
3
3
|
import { formatDuration, findingLocation } from './format.js';
|
|
4
4
|
const colorBySeverity = { critical: pc.magenta, high: pc.red, medium: pc.yellow, low: pc.cyan, info: pc.gray };
|
|
5
|
-
/** Renderer
|
|
5
|
+
/** Renderer for CI / non-TTY: one line per event, stage logs prefixed. */
|
|
6
6
|
export function createPlainRenderer(stages, opts) {
|
|
7
7
|
const write = opts.write ?? ((s) => process.stdout.write(s + '\n'));
|
|
8
8
|
return (e) => {
|
|
@@ -23,7 +23,7 @@ export function createPlainRenderer(stages, opts) {
|
|
|
23
23
|
if (r.status === 'passed')
|
|
24
24
|
write(pc.green(`✔ ${label}`));
|
|
25
25
|
else if (r.status === 'skipped')
|
|
26
|
-
write(pc.gray(`– ${e.id} (${r.summary ?? '
|
|
26
|
+
write(pc.gray(`– ${e.id} (${r.summary ?? 'skipped'})`));
|
|
27
27
|
else {
|
|
28
28
|
const tag = r.allowFailure ? pc.yellow(' [allow_failure]') : '';
|
|
29
29
|
write(pc.red(`✖ ${label}`) + tag + (r.error ? pc.red(` · ${r.error}`) : r.summary ? pc.dim(` · ${r.summary}`) : ''));
|
package/dist/ui/tui/App.js
CHANGED
|
@@ -97,7 +97,7 @@ export function App({ pipeline, header, execute, initialNodes }) {
|
|
|
97
97
|
if (input === 'q' || (key.ctrl && input === 'c')) {
|
|
98
98
|
if (running && controller.current) {
|
|
99
99
|
quitting.current = true;
|
|
100
|
-
setNotice('
|
|
100
|
+
setNotice('Cancelling running stages…');
|
|
101
101
|
controller.current.abort();
|
|
102
102
|
}
|
|
103
103
|
else
|
|
@@ -128,7 +128,7 @@ export function App({ pipeline, header, execute, initialNodes }) {
|
|
|
128
128
|
}
|
|
129
129
|
else if (input === 'r' && current) {
|
|
130
130
|
if (running)
|
|
131
|
-
setNotice('
|
|
131
|
+
setNotice('Wait for the pipeline to finish before rerunning.');
|
|
132
132
|
else
|
|
133
133
|
start([current]);
|
|
134
134
|
}
|
|
@@ -140,9 +140,9 @@ export function App({ pipeline, header, execute, initialNodes }) {
|
|
|
140
140
|
const target = current.kind === 'stage' ? current.file : current.dir;
|
|
141
141
|
const editor = process.env.CHECKPOST_EDITOR || 'code';
|
|
142
142
|
const child = spawn(editor, [target], { detached: true, stdio: 'ignore' });
|
|
143
|
-
child.on('error', () => setNotice(`
|
|
143
|
+
child.on('error', () => setNotice(`Could not open editor "${editor}". Set CHECKPOST_EDITOR.`));
|
|
144
144
|
child.unref();
|
|
145
|
-
setNotice(`
|
|
145
|
+
setNotice(`Opening ${path.relative(pipeline.root, target)} in ${editor}`);
|
|
146
146
|
}
|
|
147
147
|
});
|
|
148
148
|
if (view === 'detail' && current) {
|
|
@@ -162,23 +162,23 @@ export function App({ pipeline, header, execute, initialNodes }) {
|
|
|
162
162
|
: '';
|
|
163
163
|
const findings = st.result?.findings ?? [];
|
|
164
164
|
const blocking = node.kind === 'stage' ? findings.filter((f) => isBlocking(f, node.config.fail_on)).length : 0;
|
|
165
|
-
const tag = node.kind === 'group' ? (node.config.parallel ? '(
|
|
165
|
+
const tag = node.kind === 'group' ? (node.config.parallel ? '(parallel)' : '') : node.type === 'command' ? '' : `[${typeLabel(node)}]`;
|
|
166
166
|
const prefix = depth > 0 ? ' '.repeat(depth - 1) + '├ ' : '';
|
|
167
|
-
return (_jsxs(Text, { inverse: isSel, children: [' ', prefix, _jsx(Text, { color: STATUS_COLOR[st.status], children: icon }), " ", node.name.padEnd(Math.max(1, 22 - prefix.length)), _jsx(Text, { color: "cyan", children: tag.padEnd(10) }), _jsx(Text, { color: "gray", children: elapsed.padStart(8) }), findings.length > 0 && (_jsxs(Text, { color: blocking ? 'red' : 'yellow', children: [' ', findings.length, "
|
|
168
|
-
}), _jsx(Text, { color: "gray", children: '─'.repeat(60) }), current && (_jsxs(Box, { flexDirection: "column", height: logHeight + 1, children: [_jsxs(Text, { color: "gray", children: [current.name, " \u203A log"] }), logLines.slice(-logHeight).map((line, i) => (_jsxs(Text, { wrap: "truncate-end", color: line.startsWith('[AI]') ? 'cyan' : undefined, children: [' ', line] }, i)))] })), _jsx(Text, { color: "gray", children: '─'.repeat(60) }), gate && _jsx(GateBox, { gate: gate }), notice && _jsxs(Text, { color: "yellow", children: [" ", notice] }), _jsxs(Text, { color: "gray", children: [' ', "\u2191\u2193
|
|
167
|
+
return (_jsxs(Text, { inverse: isSel, children: [' ', prefix, _jsx(Text, { color: STATUS_COLOR[st.status], children: icon }), " ", node.name.padEnd(Math.max(1, 22 - prefix.length)), _jsx(Text, { color: "cyan", children: tag.padEnd(10) }), _jsx(Text, { color: "gray", children: elapsed.padStart(8) }), findings.length > 0 && (_jsxs(Text, { color: blocking ? 'red' : 'yellow', children: [' ', findings.length, " finding", findings.length === 1 ? '' : 's', blocking ? ` (${blocking} blocking)` : ''] })), st.result?.allowFailure && (st.status === 'failed' || st.status === 'error') && _jsx(Text, { color: "yellow", children: " allow_failure" }), st.status === 'skipped' && st.result?.summary && _jsxs(Text, { color: "gray", children: [" ", st.result.summary] })] }, node.id));
|
|
168
|
+
}), _jsx(Text, { color: "gray", children: '─'.repeat(60) }), current && (_jsxs(Box, { flexDirection: "column", height: logHeight + 1, children: [_jsxs(Text, { color: "gray", children: [current.name, " \u203A log"] }), logLines.slice(-logHeight).map((line, i) => (_jsxs(Text, { wrap: "truncate-end", color: line.startsWith('[AI]') ? 'cyan' : undefined, children: [' ', line] }, i)))] })), _jsx(Text, { color: "gray", children: '─'.repeat(60) }), gate && _jsx(GateBox, { gate: gate }), notice && _jsxs(Text, { color: "yellow", children: [" ", notice] }), _jsxs(Text, { color: "gray", children: [' ', "\u2191\u2193 select enter details r rerun stage R rerun all o open .md q quit"] })] }));
|
|
169
169
|
}
|
|
170
170
|
function GateBox({ gate }) {
|
|
171
171
|
const sha = gate.git.sha ? `${gate.git.branch}@${gate.git.sha.slice(0, 7)}` : '';
|
|
172
172
|
if (gate.green) {
|
|
173
|
-
return (_jsxs(Box, { borderStyle: "round", borderColor: "green", paddingX: 1, flexDirection: "column", children: [_jsx(Text, { color: "green", bold: true, children: "\u2714 GATE GREEN \u00B7
|
|
173
|
+
return (_jsxs(Box, { borderStyle: "round", borderColor: "green", paddingX: 1, flexDirection: "column", children: [_jsx(Text, { color: "green", bold: true, children: "\u2714 GATE GREEN \u00B7 ok to deploy" }), _jsx(Text, { color: "gray", children: sha })] }));
|
|
174
174
|
}
|
|
175
|
-
return (_jsxs(Box, { borderStyle: "round", borderColor: "red", paddingX: 1, flexDirection: "column", children: [_jsx(Text, { color: "red", bold: true, children: "\u2716 GATE RED \u00B7
|
|
175
|
+
return (_jsxs(Box, { borderStyle: "round", borderColor: "red", paddingX: 1, flexDirection: "column", children: [_jsx(Text, { color: "red", bold: true, children: "\u2716 GATE RED \u00B7 not ready to deploy" }), gate.reasons.slice(0, 6).map((r, i) => (_jsxs(Text, { color: "gray", children: ["\u2022 ", r] }, i)))] }));
|
|
176
176
|
}
|
|
177
177
|
function Detail({ node, state, log, offset, rows, pipeline, }) {
|
|
178
178
|
const result = state?.result;
|
|
179
179
|
const lines = [];
|
|
180
180
|
if (node.kind === 'group') {
|
|
181
|
-
lines.push(_jsxs(Text, { children: ["
|
|
181
|
+
lines.push(_jsxs(Text, { children: ["Group with ", node.children.length, " items. Select a stage inside it to see details."] }, "g"));
|
|
182
182
|
}
|
|
183
183
|
else {
|
|
184
184
|
if (result?.summary)
|
|
@@ -188,7 +188,7 @@ function Detail({ node, state, log, offset, rows, pipeline, }) {
|
|
|
188
188
|
if (result?.findings.length) {
|
|
189
189
|
result.findings.forEach((f, i) => {
|
|
190
190
|
const blocking = isBlocking(f, node.config.fail_on);
|
|
191
|
-
lines.push(_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsxs(Text, { children: [_jsx(Text, { color: SEVERITY_COLOR[f.severity], bold: true, children: f.severity.toUpperCase().padEnd(9) }), _jsx(Text, { underline: true, children: findingLocation(f) }), blocking && _jsx(Text, { color: "red", children: " (
|
|
191
|
+
lines.push(_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsxs(Text, { children: [_jsx(Text, { color: SEVERITY_COLOR[f.severity], bold: true, children: f.severity.toUpperCase().padEnd(9) }), _jsx(Text, { underline: true, children: findingLocation(f) }), blocking && _jsx(Text, { color: "red", children: " (blocking)" })] }), _jsxs(Text, { children: [' ', f.message] }), f.suggestion && _jsxs(Text, { color: "gray", children: [' ', "\u2192 ", f.suggestion] })] }, `f${i}`));
|
|
192
192
|
});
|
|
193
193
|
}
|
|
194
194
|
else if (node.type === 'command' || !result) {
|
|
@@ -196,12 +196,12 @@ function Detail({ node, state, log, offset, rows, pipeline, }) {
|
|
|
196
196
|
log.forEach((line, i) => lines.push(_jsxs(Text, { children: [" ", line] }, `l${i}`)));
|
|
197
197
|
}
|
|
198
198
|
if (result?.logFile)
|
|
199
|
-
lines.push(_jsxs(Text, { color: "gray", children: ["
|
|
199
|
+
lines.push(_jsxs(Text, { color: "gray", children: ["Full log: ", path.relative(pipeline.root, result.logFile)] }, "lf"));
|
|
200
200
|
}
|
|
201
201
|
const visible = Math.max(5, rows - 6);
|
|
202
202
|
const start = Math.min(offset, Math.max(0, lines.length - visible));
|
|
203
203
|
const header = node.kind === 'stage'
|
|
204
204
|
? `${node.name} · ${typeLabel(node)}${node.kind === 'stage' && node.type !== 'command' ? ` · fail_on: ${node.config.fail_on}` : ''}`
|
|
205
205
|
: node.name;
|
|
206
|
-
return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { bold: true, children: [' ', _jsx(Text, { color: STATUS_COLOR[state?.status ?? 'pending'], children: STATUS_ICON[state?.status ?? 'pending'] }), " ", header, result?.costUsd ? _jsxs(Text, { color: "gray", children: [" \u00B7 $", result.costUsd.toFixed(3)] }) : null] }), _jsx(Text, { color: "gray", children: '─'.repeat(60) }), lines.slice(start, start + visible), _jsx(Text, { color: "gray", children: '─'.repeat(60) }), _jsx(Text, { color: "gray", children: " \u2191\u2193
|
|
206
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { bold: true, children: [' ', _jsx(Text, { color: STATUS_COLOR[state?.status ?? 'pending'], children: STATUS_ICON[state?.status ?? 'pending'] }), " ", header, result?.costUsd ? _jsxs(Text, { color: "gray", children: [" \u00B7 $", result.costUsd.toFixed(3)] }) : null] }), _jsx(Text, { color: "gray", children: '─'.repeat(60) }), lines.slice(start, start + visible), _jsx(Text, { color: "gray", children: '─'.repeat(60) }), _jsx(Text, { color: "gray", children: " \u2191\u2193 scroll esc back q quit" })] }));
|
|
207
207
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "check-post",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Local CI/CD pipeline whose stages are Markdown files, run by an AI CLI (Claude Code). A green gate means ready to deploy.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ci",
|
|
7
7
|
"cd",
|