check-post 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +147 -2
- package/dist/cli.js +51 -0
- package/dist/commands/init.js +219 -0
- package/dist/commands/list.js +50 -0
- package/dist/commands/run.js +149 -0
- package/dist/commands/shared.js +12 -0
- package/dist/commands/status.js +31 -0
- package/dist/core/adapters/claude-code.js +145 -0
- package/dist/core/adapters/index.js +14 -0
- package/dist/core/adapters/types.js +1 -0
- package/dist/core/discovery.js +183 -0
- package/dist/core/events.js +1 -0
- package/dist/core/gate.js +111 -0
- package/dist/core/process.js +20 -0
- package/dist/core/project.js +67 -0
- package/dist/core/runners/ai.js +91 -0
- package/dist/core/runners/command.js +48 -0
- package/dist/core/scheduler.js +158 -0
- package/dist/core/stage-file.js +61 -0
- package/dist/core/types.js +64 -0
- package/dist/ui/format.js +46 -0
- package/dist/ui/plain.js +47 -0
- package/dist/ui/tui/App.js +207 -0
- package/package.json +67 -4
- package/presets/angular/01-lint.md +4 -0
- package/presets/angular/02-unit-test.md +4 -0
- package/presets/angular/03-build.md +4 -0
- package/presets/angular/04-security/01-secrets.md +19 -0
- package/presets/angular/04-security/02-xss-audit.md +17 -0
- package/presets/angular/04-security/03-env-audit.md +11 -0
- package/presets/angular/04-security/04-dependency.md +5 -0
- package/presets/angular/04-security/_group.md +4 -0
- package/presets/angular/05-code-standard.md +15 -0
- package/presets/angular/context.md +2 -0
- package/presets/nextjs/01-lint.md +4 -0
- package/presets/nextjs/02-unit-test.md +4 -0
- package/presets/nextjs/03-build.md +4 -0
- package/presets/nextjs/04-security/01-secrets.md +19 -0
- package/presets/nextjs/04-security/02-xss-audit.md +16 -0
- package/presets/nextjs/04-security/03-env-audit.md +11 -0
- package/presets/nextjs/04-security/04-dependency.md +5 -0
- package/presets/nextjs/04-security/_group.md +4 -0
- package/presets/nextjs/05-code-standard.md +15 -0
- package/presets/nextjs/context.md +1 -0
- package/presets/node/01-lint.md +4 -0
- package/presets/node/02-unit-test.md +4 -0
- package/presets/node/03-build.md +4 -0
- package/presets/node/04-security/01-secrets.md +19 -0
- package/presets/node/04-security/02-injection-audit.md +15 -0
- package/presets/node/04-security/03-env-audit.md +11 -0
- package/presets/node/04-security/04-dependency.md +5 -0
- package/presets/node/04-security/_group.md +4 -0
- package/presets/node/05-code-standard.md +15 -0
- package/presets/node/context.md +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Raisul khairi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,148 @@
|
|
|
1
|
-
#
|
|
1
|
+
# check-post
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A CI/CD-style pipeline that runs on your own machine. Stages are Markdown files, and stages that need judgment are run by an AI CLI (currently Claude Code). When every stage is green, the gate says the project is ready to deploy.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
Checkpost · claude-code · main@a1b2c3d
|
|
7
|
+
──────────────────────────────────────────
|
|
8
|
+
✔ lint 4.1s
|
|
9
|
+
✔ unit-test 12.4s
|
|
10
|
+
✔ build 31.0s
|
|
11
|
+
⠹ security (parallel)
|
|
12
|
+
├ ✔ secrets [AI] 9.8s
|
|
13
|
+
├ ✖ xss-audit [AI] 22.3s 2 findings (1 blocking)
|
|
14
|
+
├ ⠹ env-audit [AI] 18.0s
|
|
15
|
+
○ code-standard [AI]
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Requirements
|
|
19
|
+
- Node.js 22+
|
|
20
|
+
- [Claude Code](https://docs.claude.com/claude-code), installed and logged in (`claude`)
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
Use it without installing:
|
|
24
|
+
```bash
|
|
25
|
+
npx check-post init
|
|
26
|
+
npx check-post run
|
|
27
|
+
```
|
|
28
|
+
Or install it globally:
|
|
29
|
+
```bash
|
|
30
|
+
npm install -g check-post
|
|
31
|
+
```
|
|
32
|
+
The command is available as both `check-post` and `checkpost`.
|
|
33
|
+
|
|
34
|
+
Latest version straight from GitHub:
|
|
35
|
+
```bash
|
|
36
|
+
npx github:raisulkhairi/check-post init
|
|
37
|
+
```
|
|
38
|
+
Avoid `npm install -g github:…`: npm fails to build git packages in global mode (`tsc: not found`). For a permanent install of the GitHub version:
|
|
39
|
+
```bash
|
|
40
|
+
git clone https://github.com/raisulkhairi/check-post.git
|
|
41
|
+
cd check-post && npm install && npm link
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Getting started
|
|
45
|
+
Run these in the root of the project you want to check:
|
|
46
|
+
```bash
|
|
47
|
+
checkpost init # wizard: detect the project, pick a preset and stages
|
|
48
|
+
checkpost list # check the stage order
|
|
49
|
+
checkpost run # run with the terminal UI
|
|
50
|
+
checkpost status # GREEN/RED, exit code 0/1
|
|
51
|
+
```
|
|
52
|
+
You don't need to open `claude` first. Checkpost calls Claude Code itself for AI stages.
|
|
53
|
+
|
|
54
|
+
## Stages are Markdown files
|
|
55
|
+
```
|
|
56
|
+
checkpost/
|
|
57
|
+
pipeline.md # global config + project context for every AI stage
|
|
58
|
+
01-lint.md
|
|
59
|
+
02-unit-test.md
|
|
60
|
+
03-build.md
|
|
61
|
+
04-security/ # subfolder = group
|
|
62
|
+
_group.md # parallel: true
|
|
63
|
+
01-secrets.md
|
|
64
|
+
02-xss-audit.md
|
|
65
|
+
05-code-standard.md
|
|
66
|
+
_draft.md # a _ or . prefix = ignored
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**Order** follows the numeric prefix (`2-` comes before `10-`). Items without a prefix go last, alphabetically. Prefixes are not shown in the UI.
|
|
70
|
+
|
|
71
|
+
**The stage type comes from the file's content:**
|
|
72
|
+
|
|
73
|
+
| Content | Behavior | Passes when |
|
|
74
|
+
|---|---|---|
|
|
75
|
+
| `run:` only | runs the command | exit code 0 |
|
|
76
|
+
| body only | the body becomes the AI's instructions | no findings ≥ `fail_on` |
|
|
77
|
+
| `run:` + body | runs the command, then the AI reviews its output | no findings ≥ `fail_on` |
|
|
78
|
+
|
|
79
|
+
```md
|
|
80
|
+
---
|
|
81
|
+
paths: ["src/**/*.ts", "src/**/*.html"]
|
|
82
|
+
fail_on: high
|
|
83
|
+
---
|
|
84
|
+
# XSS audit
|
|
85
|
+
Look for bypassSecurityTrustHtml and [innerHTML] bindings fed with user data...
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
AI summaries and findings are written in the language set by `language:` in `pipeline.md` (default `English`).
|
|
89
|
+
|
|
90
|
+
### Frontmatter
|
|
91
|
+
|
|
92
|
+
| Field | Where | Default | Description |
|
|
93
|
+
|---|---|---|---|
|
|
94
|
+
| `run` | stage | – | shell command |
|
|
95
|
+
| `timeout` | stage | 15m (command), 10m (AI) | `30s`, `5m`, `1h`, or a number of seconds |
|
|
96
|
+
| `fail_on` | stage | `high` | `critical`, `high`, `medium`, `low`, `info` |
|
|
97
|
+
| `paths` | stage | – | limit the files the AI inspects |
|
|
98
|
+
| `allow_failure` | stage | `false` | a failure does not block the gate |
|
|
99
|
+
| `enabled` | stage, group | `true` | |
|
|
100
|
+
| `name` | stage, group | file name | display name |
|
|
101
|
+
| `model`, `max_budget_usd` | stage, pipeline | `sonnet`, `1` | |
|
|
102
|
+
| `language` | pipeline | `English` | language of AI summaries and findings |
|
|
103
|
+
| `parallel` | group | `false` | run the group's children concurrently |
|
|
104
|
+
| `fail_fast` | group, pipeline | `true` | stop at the first failure |
|
|
105
|
+
| `require_clean_tree` | pipeline | `true` | gate is RED when there are uncommitted changes |
|
|
106
|
+
| `sensitive_paths` | pipeline | `.env*`, `.npmrc`, `*.pem`, `*.key` | paths the AI must never read |
|
|
107
|
+
| `confirm_ai` | pipeline | `true` | ask once before using your AI quota |
|
|
108
|
+
|
|
109
|
+
The body of `pipeline.md` and `_group.md` is passed as context to every AI stage below it.
|
|
110
|
+
|
|
111
|
+
## AI stage safety
|
|
112
|
+
- The AI only gets read tools (Read, Grep, Glob). It cannot change files or run commands.
|
|
113
|
+
- `sensitive_paths` are blocked with Claude Code permission deny rules. Attempts to read them show up in the log as `access blocked`.
|
|
114
|
+
- Claude Code runs without MCP servers, plugins, or user settings, so the context stays small and a stage costs cents, not dollars.
|
|
115
|
+
- The AI must answer with validated, structured JSON. An invalid answer is retried once. If it is still invalid, the stage ends as `error`, never as passed.
|
|
116
|
+
|
|
117
|
+
## Gate
|
|
118
|
+
`checkpost status` is only GREEN when:
|
|
119
|
+
- every stage passed (or is `allow_failure`),
|
|
120
|
+
- the results are for the same commit as `HEAD`,
|
|
121
|
+
- stage definitions have not changed since the run,
|
|
122
|
+
- the working tree is clean (turn off with `require_clean_tree: false`).
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
checkpost status && vercel --prod
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## CI and scripts
|
|
129
|
+
```bash
|
|
130
|
+
checkpost run --ci # plain output + exit code
|
|
131
|
+
checkpost run --ci --json # final JSON result on stdout, logs on stderr
|
|
132
|
+
checkpost run security # a single group/stage (id or name)
|
|
133
|
+
```
|
|
134
|
+
`init` can also install a `/checkpost` slash command for Claude Code.
|
|
135
|
+
|
|
136
|
+
## Repos you don't own
|
|
137
|
+
`checkpost init --share local` adds `checkpost/`, `.checkpost/`, and the slash command to `.git/info/exclude`. The repo itself is not changed at all.
|
|
138
|
+
|
|
139
|
+
## Development
|
|
140
|
+
```bash
|
|
141
|
+
npm install
|
|
142
|
+
npm test # vitest
|
|
143
|
+
npm run build # tsc → dist/
|
|
144
|
+
npm link # make the checkpost command available globally from this folder
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## License
|
|
148
|
+
MIT
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command, Option } from 'commander';
|
|
3
|
+
import { initCommand } from './commands/init.js';
|
|
4
|
+
import { listCommand } from './commands/list.js';
|
|
5
|
+
import { runCommand } from './commands/run.js';
|
|
6
|
+
import { statusCommand } from './commands/status.js';
|
|
7
|
+
const program = new Command();
|
|
8
|
+
program
|
|
9
|
+
.name('checkpost')
|
|
10
|
+
.description('Local CI/CD pipeline: stages are Markdown files, run by an AI CLI')
|
|
11
|
+
.version('0.1.0')
|
|
12
|
+
.option('-C, --cwd <dir>', 'project root', process.cwd());
|
|
13
|
+
const cwd = () => program.opts().cwd;
|
|
14
|
+
const finish = (code) => {
|
|
15
|
+
process.exitCode = code;
|
|
16
|
+
};
|
|
17
|
+
program
|
|
18
|
+
.command('init')
|
|
19
|
+
.description('create the checkpost/ folder from a preset')
|
|
20
|
+
.addOption(new Option('--preset <name>', 'stage preset').choices(['angular', 'nextjs', 'node', 'empty']))
|
|
21
|
+
.addOption(new Option('--share <mode>', 'keep local only or share with the team').choices(['local', 'team']))
|
|
22
|
+
.option('--no-slash-command', 'do not install the /checkpost slash command')
|
|
23
|
+
.option('-y, --yes', 'use defaults without prompting')
|
|
24
|
+
.option('--force', 'overwrite an existing checkpost/ folder')
|
|
25
|
+
.action(async (o) => {
|
|
26
|
+
const slashCommand = process.argv.includes('--no-slash-command') ? false : o.yes ? true : undefined;
|
|
27
|
+
finish(await initCommand({ cwd: cwd(), preset: o.preset, share: o.share, slashCommand, yes: o.yes, force: o.force }));
|
|
28
|
+
});
|
|
29
|
+
program
|
|
30
|
+
.command('list')
|
|
31
|
+
.description('show the stage order without running it')
|
|
32
|
+
.option('--json', 'JSON output')
|
|
33
|
+
.action((o) => finish(listCommand({ cwd: cwd(), json: o.json })));
|
|
34
|
+
program
|
|
35
|
+
.command('run')
|
|
36
|
+
.argument('[stage]', 'run a single stage or group (id or name)')
|
|
37
|
+
.description('run the pipeline')
|
|
38
|
+
.option('--ci', 'non-interactive mode (automatic when not a terminal)')
|
|
39
|
+
.option('--json', 'print the final result as JSON on stdout')
|
|
40
|
+
.option('-y, --yes', 'skip the AI usage confirmation')
|
|
41
|
+
.option('-v, --verbose', 'show full command logs in CI mode')
|
|
42
|
+
.action(async (stage, o) => finish(await runCommand(stage, { cwd: cwd(), ci: o.ci, json: o.json, yes: o.yes, verbose: o.verbose })));
|
|
43
|
+
program
|
|
44
|
+
.command('status')
|
|
45
|
+
.description('check the gate: GREEN (ok to deploy) or RED; exit code 0/1')
|
|
46
|
+
.option('--json', 'JSON output')
|
|
47
|
+
.action(async (o) => finish(await statusCommand({ cwd: cwd(), json: o.json })));
|
|
48
|
+
program.parseAsync().catch((err) => {
|
|
49
|
+
console.error(err instanceof Error ? err.message : err);
|
|
50
|
+
process.exitCode = 1;
|
|
51
|
+
});
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { checkbox, confirm, select } from '@inquirer/prompts';
|
|
5
|
+
import pc from 'picocolors';
|
|
6
|
+
import { AGENTS } from '../core/adapters/index.js';
|
|
7
|
+
import { GROUP_FILE, PIPELINE_DIR, splitPrefix } from '../core/discovery.js';
|
|
8
|
+
import { STATE_DIR, readGitState } from '../core/gate.js';
|
|
9
|
+
import { detectProject, ignorePaths, npmScriptOf } from '../core/project.js';
|
|
10
|
+
import { parseMarkdown } from '../core/stage-file.js';
|
|
11
|
+
import { StageConfigSchema } from '../core/types.js';
|
|
12
|
+
const PRESETS_DIR = fileURLToPath(new URL('../../presets/', import.meta.url));
|
|
13
|
+
const PRESETS = [
|
|
14
|
+
{ id: 'angular', label: 'Angular' },
|
|
15
|
+
{ id: 'nextjs', label: 'Next.js' },
|
|
16
|
+
{ id: 'node', label: 'Node.js / API' },
|
|
17
|
+
{ id: 'empty', label: 'Empty (one example stage)' },
|
|
18
|
+
];
|
|
19
|
+
const EXTRA_SENSITIVE = {
|
|
20
|
+
angular: ['src/environments/**'],
|
|
21
|
+
};
|
|
22
|
+
const SLASH_COMMAND_PATH = '.claude/commands/checkpost.md';
|
|
23
|
+
function presetStages(presetDir, scripts) {
|
|
24
|
+
const out = [];
|
|
25
|
+
const walk = (dir, depth) => {
|
|
26
|
+
for (const name of readdirSync(dir).sort()) {
|
|
27
|
+
const full = path.join(dir, name);
|
|
28
|
+
const rel = path.relative(presetDir, full);
|
|
29
|
+
if (statSync(full).isDirectory()) {
|
|
30
|
+
walk(full, depth + 1);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (name === GROUP_FILE || name === 'context.md' || !name.endsWith('.md'))
|
|
34
|
+
continue;
|
|
35
|
+
const { data, body } = parseMarkdown(readFileSync(full, 'utf8'), StageConfigSchema, rel);
|
|
36
|
+
const script = data.run ? npmScriptOf(data.run) : null;
|
|
37
|
+
const missingScript = script && script !== 'test' ? (scripts[script] ? null : script) : script === 'test' && !scripts.test ? 'test' : null;
|
|
38
|
+
const groupName = depth > 0 ? splitPrefix(path.basename(path.dirname(full))).name + '/' : '';
|
|
39
|
+
const kind = data.run ? (body ? `${data.run} + AI` : data.run) : 'AI';
|
|
40
|
+
out.push({
|
|
41
|
+
rel,
|
|
42
|
+
label: `${groupName}${splitPrefix(name).name} ${pc.gray(kind)}${missingScript ? pc.yellow(` (no "${missingScript}" script)`) : ''}`,
|
|
43
|
+
missingScript,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
walk(presetDir, 0);
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
function pipelineMd(opts) {
|
|
51
|
+
const sensitive = EXTRA_SENSITIVE[opts.kind] ?? [];
|
|
52
|
+
const front = [
|
|
53
|
+
'---',
|
|
54
|
+
'agent: claude-code',
|
|
55
|
+
'model: sonnet # model for AI stages (sonnet | opus | haiku)',
|
|
56
|
+
'fail_fast: true # stop at the first failing stage',
|
|
57
|
+
'require_clean_tree: true # gate is only green with no uncommitted changes',
|
|
58
|
+
'max_budget_usd: 1 # cost limit per AI stage',
|
|
59
|
+
'language: English # language of AI summaries and findings',
|
|
60
|
+
];
|
|
61
|
+
if (sensitive.length) {
|
|
62
|
+
front.push('sensitive_paths: # never read by the AI (in addition to .env*, .npmrc, *.pem, *.key)');
|
|
63
|
+
for (const s of sensitive)
|
|
64
|
+
front.push(` - ${s}`);
|
|
65
|
+
}
|
|
66
|
+
front.push('---', '');
|
|
67
|
+
const body = [`Project: ${opts.label}.`, opts.context.trim()];
|
|
68
|
+
if (opts.docs.length)
|
|
69
|
+
body.push(`Project conventions are documented in: ${opts.docs.join(', ')}. Read them when relevant.`);
|
|
70
|
+
return front.join('\n') + body.join('\n\n') + '\n';
|
|
71
|
+
}
|
|
72
|
+
const SLASH_COMMAND = `---
|
|
73
|
+
description: Run Checkpost (stages in checkpost/) and summarize the result
|
|
74
|
+
allowed-tools: Bash(checkpost:*), Bash(npx checkpost:*)
|
|
75
|
+
---
|
|
76
|
+
Run this command in the project root (it can take a few minutes):
|
|
77
|
+
|
|
78
|
+
\`\`\`
|
|
79
|
+
checkpost run --ci --json --yes $ARGUMENTS
|
|
80
|
+
\`\`\`
|
|
81
|
+
|
|
82
|
+
The JSON result is on stdout. Then summarize:
|
|
83
|
+
1. Gate status (GREEN = ok to deploy, RED = not yet) and why.
|
|
84
|
+
2. Failed stages with their main findings (severity, file:line, message).
|
|
85
|
+
3. Suggested next steps. Do not change code unless asked.
|
|
86
|
+
`;
|
|
87
|
+
export async function initCommand(flags) {
|
|
88
|
+
const root = path.resolve(flags.cwd);
|
|
89
|
+
const interactive = Boolean(process.stdin.isTTY && !flags.yes);
|
|
90
|
+
const targetDir = path.join(root, PIPELINE_DIR);
|
|
91
|
+
console.log(pc.bold('\n◆ Checkpost · setup\n'));
|
|
92
|
+
if (existsSync(targetDir) && !flags.force) {
|
|
93
|
+
console.error(pc.red(` ${PIPELINE_DIR}/ already exists. Use --force to overwrite the preset files.`));
|
|
94
|
+
return 2;
|
|
95
|
+
}
|
|
96
|
+
const git = await readGitState(root);
|
|
97
|
+
console.log(git.isRepo ? pc.green(` ✔ Git repository (branch: ${git.branch})`) : pc.yellow(' ⚠ Not a git repository: the gate cannot check commits'));
|
|
98
|
+
const project = detectProject(root);
|
|
99
|
+
console.log(project.kind === 'unknown' ? pc.yellow(' ⚠ Project type not recognized') : pc.green(` ✔ Project: ${project.label}`));
|
|
100
|
+
const claude = AGENTS['claude-code'].create();
|
|
101
|
+
const detected = await claude.detect();
|
|
102
|
+
if (!detected.installed) {
|
|
103
|
+
console.error(pc.red(' ✖ Claude Code not found. Install it: npm install -g @anthropic-ai/claude-code, then run "claude" once to log in.'));
|
|
104
|
+
return 2;
|
|
105
|
+
}
|
|
106
|
+
console.log(pc.green(` ✔ AI CLI: Claude Code ${detected.version ?? ''}`));
|
|
107
|
+
if (project.docs.length)
|
|
108
|
+
console.log(pc.green(` ✔ Convention docs: ${project.docs.join(', ')}`));
|
|
109
|
+
console.log('');
|
|
110
|
+
if (interactive) {
|
|
111
|
+
await select({
|
|
112
|
+
message: 'Choose an AI agent',
|
|
113
|
+
choices: Object.entries(AGENTS).map(([id, a]) => ({
|
|
114
|
+
value: id,
|
|
115
|
+
name: a.available ? a.label : `${a.label} ${pc.gray('(coming soon)')}`,
|
|
116
|
+
disabled: !a.available,
|
|
117
|
+
})),
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
const detectedPreset = PRESETS.find((p) => p.id === project.kind)?.id ?? 'empty';
|
|
121
|
+
let preset = (flags.preset ?? detectedPreset);
|
|
122
|
+
if (!PRESETS.some((p) => p.id === preset)) {
|
|
123
|
+
console.error(pc.red(` Unknown preset "${preset}". Options: ${PRESETS.map((p) => p.id).join(', ')}`));
|
|
124
|
+
return 2;
|
|
125
|
+
}
|
|
126
|
+
if (interactive && !flags.preset) {
|
|
127
|
+
preset = await select({
|
|
128
|
+
message: 'Choose a stage preset',
|
|
129
|
+
default: detectedPreset,
|
|
130
|
+
choices: PRESETS.map((p) => ({
|
|
131
|
+
value: p.id,
|
|
132
|
+
name: p.id === detectedPreset && p.id !== 'empty' ? `${p.label} ${pc.green('(Recommended, detected)')}` : p.label,
|
|
133
|
+
})),
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
let chosen = [];
|
|
137
|
+
let context = '';
|
|
138
|
+
const presetDir = path.join(PRESETS_DIR, preset);
|
|
139
|
+
if (preset !== 'empty') {
|
|
140
|
+
context = readFileSync(path.join(presetDir, 'context.md'), 'utf8');
|
|
141
|
+
const stages = presetStages(presetDir, project.scripts);
|
|
142
|
+
chosen = stages.filter((s) => !s.missingScript).map((s) => s.rel);
|
|
143
|
+
if (interactive) {
|
|
144
|
+
chosen = await checkbox({
|
|
145
|
+
message: 'Which stages should be enabled? (space = toggle, enter = continue)',
|
|
146
|
+
choices: stages.map((s) => ({ value: s.rel, name: s.label, checked: !s.missingScript })),
|
|
147
|
+
pageSize: 15,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
let share = flags.share ?? 'local';
|
|
152
|
+
if (interactive && !flags.share) {
|
|
153
|
+
share = await select({
|
|
154
|
+
message: 'How should the checkpost/ folder be kept?',
|
|
155
|
+
choices: [
|
|
156
|
+
{ value: 'local', name: `Only on this machine ${pc.gray('(.git/info/exclude, repo unchanged)')}` },
|
|
157
|
+
{ value: 'team', name: `Share with the team ${pc.gray('(commit checkpost/, state in .gitignore)')}` },
|
|
158
|
+
],
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
let installSlash = flags.slashCommand ?? true;
|
|
162
|
+
if (interactive && flags.slashCommand === undefined) {
|
|
163
|
+
installSlash = await confirm({ message: 'Install the /checkpost slash command for Claude Code?', default: true });
|
|
164
|
+
}
|
|
165
|
+
// Write files
|
|
166
|
+
mkdirSync(targetDir, { recursive: true });
|
|
167
|
+
writeFileSync(path.join(targetDir, 'pipeline.md'), pipelineMd({ kind: preset === 'empty' ? project.kind : preset, context, docs: project.docs, label: project.label }));
|
|
168
|
+
const written = ['pipeline.md'];
|
|
169
|
+
if (preset === 'empty') {
|
|
170
|
+
writeFileSync(path.join(targetDir, '01-build.md'), '---\nrun: npm run build\n---\n');
|
|
171
|
+
written.push('01-build.md');
|
|
172
|
+
}
|
|
173
|
+
const groups = new Set();
|
|
174
|
+
for (const rel of chosen) {
|
|
175
|
+
const dest = path.join(targetDir, rel);
|
|
176
|
+
mkdirSync(path.dirname(dest), { recursive: true });
|
|
177
|
+
cpSync(path.join(presetDir, rel), dest);
|
|
178
|
+
written.push(rel);
|
|
179
|
+
const dir = path.dirname(rel);
|
|
180
|
+
if (dir !== '.' && !groups.has(dir) && existsSync(path.join(presetDir, dir, GROUP_FILE))) {
|
|
181
|
+
groups.add(dir);
|
|
182
|
+
cpSync(path.join(presetDir, dir, GROUP_FILE), path.join(targetDir, dir, GROUP_FILE));
|
|
183
|
+
written.push(path.join(dir, GROUP_FILE));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (installSlash) {
|
|
187
|
+
const slash = path.join(root, SLASH_COMMAND_PATH);
|
|
188
|
+
mkdirSync(path.dirname(slash), { recursive: true });
|
|
189
|
+
writeFileSync(slash, SLASH_COMMAND);
|
|
190
|
+
}
|
|
191
|
+
const ignored = [];
|
|
192
|
+
if (git.isRepo) {
|
|
193
|
+
if (share === 'local') {
|
|
194
|
+
const patterns = [`/${PIPELINE_DIR}/`, `/${STATE_DIR}/`];
|
|
195
|
+
if (installSlash)
|
|
196
|
+
patterns.push(`/${SLASH_COMMAND_PATH}`);
|
|
197
|
+
ignored.push(...(await ignorePaths(root, patterns, 'exclude')));
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
ignored.push(...(await ignorePaths(root, [`/${STATE_DIR}/`], 'gitignore')));
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
console.log(pc.green('\n ✔ Created:'));
|
|
204
|
+
for (const f of written.sort())
|
|
205
|
+
console.log(pc.gray(` ${PIPELINE_DIR}/${f.split(path.sep).join('/')}`));
|
|
206
|
+
if (installSlash)
|
|
207
|
+
console.log(pc.gray(` ${SLASH_COMMAND_PATH}`));
|
|
208
|
+
if (ignored.length) {
|
|
209
|
+
const where = share === 'local' ? '.git/info/exclude' : '.gitignore';
|
|
210
|
+
console.log(pc.green(` ✔ Added to ${where}: ${ignored.join(', ')}`));
|
|
211
|
+
}
|
|
212
|
+
console.log(`
|
|
213
|
+
Next steps:
|
|
214
|
+
1. Adjust the .md files in ${PIPELINE_DIR}/ (optional)
|
|
215
|
+
2. checkpost list → check the stage order
|
|
216
|
+
3. checkpost run → run the pipeline
|
|
217
|
+
`);
|
|
218
|
+
return 0;
|
|
219
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import pc from 'picocolors';
|
|
3
|
+
import { discoverPipeline, flatten } from '../core/discovery.js';
|
|
4
|
+
import { typeLabel } from '../ui/format.js';
|
|
5
|
+
import { printDefinitionError } from './shared.js';
|
|
6
|
+
export function listCommand(flags) {
|
|
7
|
+
const root = path.resolve(flags.cwd);
|
|
8
|
+
let pipeline;
|
|
9
|
+
try {
|
|
10
|
+
pipeline = discoverPipeline(root);
|
|
11
|
+
}
|
|
12
|
+
catch (err) {
|
|
13
|
+
return printDefinitionError(err);
|
|
14
|
+
}
|
|
15
|
+
const rows = flatten(pipeline.children);
|
|
16
|
+
if (flags.json) {
|
|
17
|
+
console.log(JSON.stringify(rows.map(({ node, depth }) => ({
|
|
18
|
+
id: node.id,
|
|
19
|
+
name: node.name,
|
|
20
|
+
depth,
|
|
21
|
+
kind: node.kind,
|
|
22
|
+
type: node.kind === 'stage' ? node.type : node.config.parallel ? 'parallel' : 'sequential',
|
|
23
|
+
run: node.kind === 'stage' ? node.config.run : undefined,
|
|
24
|
+
})), null, 2));
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
const c = pipeline.config;
|
|
28
|
+
console.log(pc.bold(`Checkpost · ${c.agent} (${c.model}) · fail_fast: ${c.fail_fast}`));
|
|
29
|
+
let top = 0;
|
|
30
|
+
for (const { node, depth } of rows) {
|
|
31
|
+
const num = depth === 0 ? String(++top).padStart(2) : ' ';
|
|
32
|
+
const indent = depth === 0 ? '' : ' '.repeat(depth - 1) + '├ ';
|
|
33
|
+
const name = (indent + node.name).padEnd(24);
|
|
34
|
+
const kind = typeLabel(node).padEnd(15);
|
|
35
|
+
let detail = '';
|
|
36
|
+
if (node.kind === 'stage') {
|
|
37
|
+
const bits = [];
|
|
38
|
+
if (node.config.run)
|
|
39
|
+
bits.push(node.config.run);
|
|
40
|
+
if (node.type !== 'command')
|
|
41
|
+
bits.push(`fail_on: ${node.config.fail_on}`);
|
|
42
|
+
if (node.config.allow_failure)
|
|
43
|
+
bits.push('allow_failure');
|
|
44
|
+
detail = bits.join(' · ');
|
|
45
|
+
}
|
|
46
|
+
const color = node.kind === 'group' ? pc.bold : node.type === 'command' ? (s) => s : pc.cyan;
|
|
47
|
+
console.log(`${pc.gray(num)} ${color(name)} ${pc.gray(kind)} ${pc.dim(detail)}`);
|
|
48
|
+
}
|
|
49
|
+
return 0;
|
|
50
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { render } from 'ink';
|
|
5
|
+
import { confirm } from '@inquirer/prompts';
|
|
6
|
+
import pc from 'picocolors';
|
|
7
|
+
import { getAdapter } from '../core/adapters/index.js';
|
|
8
|
+
import { allStages, discoverPipeline, findNode } from '../core/discovery.js';
|
|
9
|
+
import { evaluateGate, readGitState, saveRun, STATE_DIR } from '../core/gate.js';
|
|
10
|
+
import { ignorePaths } from '../core/project.js';
|
|
11
|
+
import { runPipeline } from '../core/scheduler.js';
|
|
12
|
+
import { App } from '../ui/tui/App.js';
|
|
13
|
+
import { createPlainRenderer } from '../ui/plain.js';
|
|
14
|
+
import { printDefinitionError } from './shared.js';
|
|
15
|
+
function readUiState(root) {
|
|
16
|
+
try {
|
|
17
|
+
return JSON.parse(readFileSync(path.join(root, STATE_DIR, 'state.json'), 'utf8'));
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function writeUiState(root, state) {
|
|
24
|
+
mkdirSync(path.join(root, STATE_DIR), { recursive: true });
|
|
25
|
+
writeFileSync(path.join(root, STATE_DIR, 'state.json'), JSON.stringify(state, null, 2));
|
|
26
|
+
}
|
|
27
|
+
const stagesOf = (nodes) => allStages(nodes);
|
|
28
|
+
export async function runCommand(target, flags) {
|
|
29
|
+
const root = path.resolve(flags.cwd);
|
|
30
|
+
let pipeline;
|
|
31
|
+
try {
|
|
32
|
+
pipeline = discoverPipeline(root);
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
return printDefinitionError(err);
|
|
36
|
+
}
|
|
37
|
+
let nodes;
|
|
38
|
+
if (target) {
|
|
39
|
+
const node = findNode(pipeline.children, target);
|
|
40
|
+
if (!node) {
|
|
41
|
+
console.error(pc.red(`Stage or group "${target}" not found. See "checkpost list".`));
|
|
42
|
+
return 2;
|
|
43
|
+
}
|
|
44
|
+
nodes = [node];
|
|
45
|
+
}
|
|
46
|
+
const selected = stagesOf(nodes ?? pipeline.children);
|
|
47
|
+
const aiStages = selected.filter((s) => s.type !== 'command');
|
|
48
|
+
const interactive = Boolean(process.stdout.isTTY && process.stdin.isTTY && !flags.ci && !flags.json);
|
|
49
|
+
let adapter;
|
|
50
|
+
if (aiStages.length) {
|
|
51
|
+
try {
|
|
52
|
+
adapter = getAdapter(pipeline.config.agent);
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
console.error(pc.red(err.message));
|
|
56
|
+
return 2;
|
|
57
|
+
}
|
|
58
|
+
const detected = await adapter.detect();
|
|
59
|
+
if (!detected.installed) {
|
|
60
|
+
console.error(pc.red(`${adapter.label} not found. Install it first: npm install -g @anthropic-ai/claude-code`));
|
|
61
|
+
return 2;
|
|
62
|
+
}
|
|
63
|
+
const ui = readUiState(root);
|
|
64
|
+
if (interactive && !flags.yes && pipeline.config.confirm_ai && !ui.aiConfirmed) {
|
|
65
|
+
const ok = await confirm({
|
|
66
|
+
message: `${aiStages.length} AI stage${aiStages.length === 1 ? '' : 's'} will use your ${adapter.label} quota (model: ${pipeline.config.model}, limit $${pipeline.config.max_budget_usd}/stage). Continue?`,
|
|
67
|
+
default: true,
|
|
68
|
+
});
|
|
69
|
+
if (!ok)
|
|
70
|
+
return 1;
|
|
71
|
+
writeUiState(root, { ...ui, aiConfirmed: true });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// Run state must not dirty the project's working tree.
|
|
75
|
+
await ignorePaths(root, [`${STATE_DIR}/`], 'exclude');
|
|
76
|
+
const git = await readGitState(root);
|
|
77
|
+
const header = [
|
|
78
|
+
adapter ? pipeline.config.agent : null,
|
|
79
|
+
git.sha ? `${git.branch}@${git.sha.slice(0, 7)}` : null,
|
|
80
|
+
path.basename(root),
|
|
81
|
+
]
|
|
82
|
+
.filter(Boolean)
|
|
83
|
+
.join(' · ');
|
|
84
|
+
const execute = async (runNodes, onEvent, signal) => {
|
|
85
|
+
const gitBefore = await readGitState(root);
|
|
86
|
+
const outcome = await runPipeline(pipeline, { nodes: runNodes, adapter, onEvent, signal });
|
|
87
|
+
if (!signal.aborted)
|
|
88
|
+
saveRun(pipeline, gitBefore, outcome.results, Boolean(runNodes));
|
|
89
|
+
return evaluateGate(pipeline);
|
|
90
|
+
};
|
|
91
|
+
if (interactive) {
|
|
92
|
+
let lastGate = null;
|
|
93
|
+
const wrapped = async (n, onEvent, signal) => {
|
|
94
|
+
lastGate = await execute(n, onEvent, signal);
|
|
95
|
+
return lastGate;
|
|
96
|
+
};
|
|
97
|
+
const app = render(_jsx(App, { pipeline: pipeline, header: header, execute: wrapped, initialNodes: nodes }), { exitOnCtrlC: false });
|
|
98
|
+
await app.waitUntilExit();
|
|
99
|
+
const gate = lastGate;
|
|
100
|
+
return gate?.green ? 0 : 1;
|
|
101
|
+
}
|
|
102
|
+
// CI / non-TTY mode
|
|
103
|
+
const write = flags.json ? (s) => process.stderr.write(s + '\n') : undefined;
|
|
104
|
+
const stageMap = new Map(allStages(pipeline.children).map((s) => [s.id, s]));
|
|
105
|
+
const renderer = createPlainRenderer(stageMap, { verbose: Boolean(flags.verbose), write });
|
|
106
|
+
const out = write ?? ((s) => console.log(s));
|
|
107
|
+
out(pc.bold(`Checkpost · ${header}`));
|
|
108
|
+
const ac = new AbortController();
|
|
109
|
+
const onSigint = () => ac.abort();
|
|
110
|
+
process.once('SIGINT', onSigint);
|
|
111
|
+
const gate = await execute(nodes, renderer, ac.signal);
|
|
112
|
+
process.off('SIGINT', onSigint);
|
|
113
|
+
if (flags.json) {
|
|
114
|
+
const results = gate.lastRun?.results ?? {};
|
|
115
|
+
process.stdout.write(JSON.stringify({
|
|
116
|
+
gate: gate.green ? 'green' : 'red',
|
|
117
|
+
reasons: gate.reasons,
|
|
118
|
+
commit: gate.git.sha,
|
|
119
|
+
branch: gate.git.branch,
|
|
120
|
+
stages: allStages(pipeline.children).map((s) => {
|
|
121
|
+
const r = results[s.id];
|
|
122
|
+
return {
|
|
123
|
+
id: s.id,
|
|
124
|
+
status: r?.status ?? 'not-run',
|
|
125
|
+
allowFailure: s.config.allow_failure,
|
|
126
|
+
durationMs: r?.durationMs,
|
|
127
|
+
costUsd: r?.costUsd,
|
|
128
|
+
summary: r?.summary,
|
|
129
|
+
error: r?.error,
|
|
130
|
+
findings: r?.findings ?? [],
|
|
131
|
+
};
|
|
132
|
+
}),
|
|
133
|
+
}, null, 2) + '\n');
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
out('');
|
|
137
|
+
if (gate.green)
|
|
138
|
+
out(pc.green(pc.bold('✔ GATE GREEN · ok to deploy')));
|
|
139
|
+
else {
|
|
140
|
+
out(pc.red(pc.bold('✖ GATE RED · not ready to deploy')));
|
|
141
|
+
for (const r of gate.reasons)
|
|
142
|
+
out(pc.gray(` • ${r}`));
|
|
143
|
+
}
|
|
144
|
+
const cost = Object.values(gate.lastRun?.results ?? {}).reduce((sum, r) => sum + (r.costUsd ?? 0), 0);
|
|
145
|
+
if (cost)
|
|
146
|
+
out(pc.gray(` AI cost: $${cost.toFixed(3)}`));
|
|
147
|
+
}
|
|
148
|
+
return gate.green ? 0 : 1;
|
|
149
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import pc from 'picocolors';
|
|
2
|
+
import { DefinitionError } from '../core/stage-file.js';
|
|
3
|
+
/** Print stage definition errors and return exit code 2; rethrow anything else. */
|
|
4
|
+
export function printDefinitionError(err) {
|
|
5
|
+
if (err instanceof DefinitionError) {
|
|
6
|
+
console.error(pc.red(pc.bold('Invalid pipeline definition:')));
|
|
7
|
+
for (const p of err.problems)
|
|
8
|
+
console.error(pc.red(` • ${p}`));
|
|
9
|
+
return 2;
|
|
10
|
+
}
|
|
11
|
+
throw err;
|
|
12
|
+
}
|