@agentic-sdlc-kit/cli 1.1.0 → 1.2.1
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/dist/application/agent/gateway.d.ts +15 -1
- package/dist/application/agent/gateway.d.ts.map +1 -1
- package/dist/application/agent/gateway.js +60 -4
- package/dist/application/agent/gateway.js.map +1 -1
- package/dist/application/dispatcher.d.ts.map +1 -1
- package/dist/application/dispatcher.js +3 -0
- package/dist/application/dispatcher.js.map +1 -1
- package/dist/application/improvement/capture.d.ts +25 -0
- package/dist/application/improvement/capture.d.ts.map +1 -0
- package/dist/application/improvement/capture.js +45 -0
- package/dist/application/improvement/capture.js.map +1 -0
- package/dist/application/improvement/github-api.d.ts +38 -0
- package/dist/application/improvement/github-api.d.ts.map +1 -0
- package/dist/application/improvement/github-api.js +132 -0
- package/dist/application/improvement/github-api.js.map +1 -0
- package/dist/application/improvement/github-context.d.ts +19 -0
- package/dist/application/improvement/github-context.d.ts.map +1 -0
- package/dist/application/improvement/github-context.js +39 -0
- package/dist/application/improvement/github-context.js.map +1 -0
- package/dist/application/improvement/scrub-terms.d.ts +12 -0
- package/dist/application/improvement/scrub-terms.d.ts.map +1 -0
- package/dist/application/improvement/scrub-terms.js +66 -0
- package/dist/application/improvement/scrub-terms.js.map +1 -0
- package/dist/application/improvement/upstream.d.ts +18 -0
- package/dist/application/improvement/upstream.d.ts.map +1 -0
- package/dist/application/improvement/upstream.js +32 -0
- package/dist/application/improvement/upstream.js.map +1 -0
- package/dist/commands/improve-kit.d.ts +10 -0
- package/dist/commands/improve-kit.d.ts.map +1 -0
- package/dist/commands/improve-kit.js +79 -0
- package/dist/commands/improve-kit.js.map +1 -0
- package/dist/commands/improve-project.d.ts +18 -0
- package/dist/commands/improve-project.d.ts.map +1 -0
- package/dist/commands/improve-project.js +133 -0
- package/dist/commands/improve-project.js.map +1 -0
- package/dist/commands/improve-review.d.ts +12 -0
- package/dist/commands/improve-review.d.ts.map +1 -0
- package/dist/commands/improve-review.js +56 -0
- package/dist/commands/improve-review.js.map +1 -0
- package/dist/commands/improve.d.ts +12 -0
- package/dist/commands/improve.d.ts.map +1 -0
- package/dist/commands/improve.js +185 -0
- package/dist/commands/improve.js.map +1 -0
- package/dist/index.js +19 -2
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/application/agent/gateway.test.ts +80 -3
- package/src/application/agent/gateway.ts +61 -4
- package/src/application/dispatcher.ts +2 -0
- package/src/application/improvement/capture.test.ts +80 -0
- package/src/application/improvement/capture.ts +72 -0
- package/src/application/improvement/github-api.test.ts +191 -0
- package/src/application/improvement/github-api.ts +214 -0
- package/src/application/improvement/github-context.test.ts +55 -0
- package/src/application/improvement/github-context.ts +67 -0
- package/src/application/improvement/scrub-terms.ts +76 -0
- package/src/application/improvement/upstream.test.ts +70 -0
- package/src/application/improvement/upstream.ts +43 -0
- package/src/commands/improve-kit.test.ts +126 -0
- package/src/commands/improve-kit.ts +93 -0
- package/src/commands/improve-project.test.ts +194 -0
- package/src/commands/improve-project.ts +192 -0
- package/src/commands/improve-review.test.ts +126 -0
- package/src/commands/improve-review.ts +75 -0
- package/src/commands/improve.test.ts +121 -0
- package/src/commands/improve.ts +215 -0
- package/src/index.ts +18 -2
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// packages/cli/src/commands/improve.ts
|
|
2
|
+
//
|
|
3
|
+
// `kit improve` (ADR-0028). Two targets: `project` findings stay in the user's repository;
|
|
4
|
+
// `kit` feedback is sanitized, opt-in, and sent upstream only by the user.
|
|
5
|
+
//
|
|
6
|
+
// Output never contains a matched value. Exit codes: 0 ok, 1 findings with --fail-on-findings,
|
|
7
|
+
// 2 usage or runtime error.
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { improvement } from '@agentic-sdlc-kit/core';
|
|
10
|
+
import type { Command, CommandContext, CommandResult } from './types.js';
|
|
11
|
+
import { defaultGh, type GhRunner } from '../application/improvement/upstream.js';
|
|
12
|
+
import type { GitHubApi, GitHubApiOptions } from '../application/improvement/github-api.js';
|
|
13
|
+
import { kitIssues, kitScan } from './improve-kit.js';
|
|
14
|
+
import { defaultGitHub, projectIssues, type ProjectIssueDeps } from './improve-project.js';
|
|
15
|
+
import { requestReview } from './improve-review.js';
|
|
16
|
+
|
|
17
|
+
const HELP = `Usage:
|
|
18
|
+
kit improve scan [--target project|kit] [options]
|
|
19
|
+
kit improve issues --target project [--sync] [--repo owner/name] [options]
|
|
20
|
+
kit improve issues --target kit [--key <key>] [--submit [--yes]]
|
|
21
|
+
kit improve review --pr <n> [--kind <kind>] [--instruction <text>] [--repo owner/name] [--yes]
|
|
22
|
+
|
|
23
|
+
Targets (ADR-0028):
|
|
24
|
+
project Findings about this repository. They stay here and are never sent upstream.
|
|
25
|
+
kit Sanitized feedback about the kit itself. Capture is opt-in (.ai-kit/improvement.yml);
|
|
26
|
+
only you can send it, one report at a time, after previewing it.
|
|
27
|
+
|
|
28
|
+
scan --target project:
|
|
29
|
+
--changed-only <ref> Scan only files changed since <ref> (a base ref or SHA).
|
|
30
|
+
--ignore-file <path> Ignore globs, one per line (default: .ai-kit/scan-ignore).
|
|
31
|
+
--ignore <glob> Extra ignore glob. Repeatable.
|
|
32
|
+
--format json|md Output format (default json). Output never contains matched values.
|
|
33
|
+
--fail-on-findings Exit 1 when any finding is reported.
|
|
34
|
+
|
|
35
|
+
issues --target project:
|
|
36
|
+
(no flags) Dry run: draft one issue per rule and file. No token, no GitHub call.
|
|
37
|
+
--sync Create or update those issues in this repository (GITHUB_TOKEN, GH_TOKEN
|
|
38
|
+
or your gh login). Closed issues are never reopened; fixed findings are
|
|
39
|
+
reported as stale, never closed. Bodies never contain matched values.
|
|
40
|
+
--repo owner/name Target repository (default: GITHUB_REPOSITORY, then the origin remote).
|
|
41
|
+
--format json|md Output format (default json). --ignore-file and --ignore work as for scan.
|
|
42
|
+
Exit 1 when the privacy gate withholds an issue.
|
|
43
|
+
|
|
44
|
+
review:
|
|
45
|
+
Asks this repository's ai-review.yml workflow (ci-agent) for one focused AI review. The kit has
|
|
46
|
+
no review engine of its own. The workflow's review gate still applies: an open, non-draft PR
|
|
47
|
+
from this repository, every other check green, and this kind not yet reviewed at the head.
|
|
48
|
+
--kind <kind> correctness (default), security, testing, architecture, performance,
|
|
49
|
+
maintainability, documentation, or custom.
|
|
50
|
+
--instruction <text> The focus for a custom review only (up to 500 characters).
|
|
51
|
+
--yes Send it. Without --yes, nothing is sent: AI reviews cost money.
|
|
52
|
+
|
|
53
|
+
issues --target kit:
|
|
54
|
+
(no flags) Preview every local report as the issue it would become.
|
|
55
|
+
--key <key> Limit to one report.
|
|
56
|
+
--submit --key <key> Show exactly what would be sent, and where.
|
|
57
|
+
--submit --yes Send it with your own gh login, or get a prefilled link if gh is unavailable.
|
|
58
|
+
`;
|
|
59
|
+
|
|
60
|
+
function single(argv: readonly string[], name: string): string | undefined {
|
|
61
|
+
const i = argv.indexOf(name);
|
|
62
|
+
const v = i >= 0 ? argv[i + 1] : undefined;
|
|
63
|
+
return v !== undefined && !v.startsWith('--') ? v : undefined;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function repeated(argv: readonly string[], name: string): string[] {
|
|
67
|
+
const out: string[] = [];
|
|
68
|
+
for (let i = 0; i < argv.length; i++) {
|
|
69
|
+
const v = argv[i + 1];
|
|
70
|
+
if (argv[i] === name && v !== undefined && !v.startsWith('--')) out.push(v);
|
|
71
|
+
}
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function fail(ctx: CommandContext, message: string, exitCode = 1): CommandResult {
|
|
76
|
+
ctx.stderr(`kit improve: ${message}\n`);
|
|
77
|
+
return { exitCode, message };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function scan(ctx: CommandContext, root: string): Promise<CommandResult> {
|
|
81
|
+
const format = single(ctx.argv, '--format') ?? 'json';
|
|
82
|
+
if (format !== 'json' && format !== 'md') return fail(ctx, `unknown --format ${format}`, 2);
|
|
83
|
+
|
|
84
|
+
const changedOnly = single(ctx.argv, '--changed-only');
|
|
85
|
+
const ignoreFile = single(ctx.argv, '--ignore-file');
|
|
86
|
+
try {
|
|
87
|
+
const report = await improvement.scanRepo({
|
|
88
|
+
root,
|
|
89
|
+
...(changedOnly !== undefined ? { changedOnly } : {}),
|
|
90
|
+
...(ignoreFile !== undefined ? { ignoreFile: path.resolve(ctx.cwd, ignoreFile) } : {}),
|
|
91
|
+
extraIgnores: repeated(ctx.argv, '--ignore'),
|
|
92
|
+
});
|
|
93
|
+
ctx.stdout(
|
|
94
|
+
format === 'md' ? improvement.toMarkdown(report) : `${JSON.stringify(report, null, 2)}\n`,
|
|
95
|
+
);
|
|
96
|
+
const failOn = ctx.argv.includes('--fail-on-findings');
|
|
97
|
+
return { exitCode: failOn && report.findings.length > 0 ? 1 : 0 };
|
|
98
|
+
} catch (err) {
|
|
99
|
+
// Report the error class and first line only. Never print file contents from here.
|
|
100
|
+
const e = err as NodeJS.ErrnoException;
|
|
101
|
+
const first = (e.message ?? '').split('\n')[0] ?? '';
|
|
102
|
+
return fail(ctx, `scan failed: ${e.code ?? e.name}: ${first}`, 2);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
type Target = 'project' | 'kit';
|
|
107
|
+
|
|
108
|
+
function targetOf(ctx: CommandContext, fallback?: Target): Target | 'invalid' | undefined {
|
|
109
|
+
const t = single(ctx.argv, '--target') ?? fallback;
|
|
110
|
+
if (t === undefined) return undefined;
|
|
111
|
+
return t === 'project' || t === 'kit' ? t : 'invalid';
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function runScan(ctx: CommandContext, root: string): Promise<CommandResult> {
|
|
115
|
+
const target = targetOf(ctx, 'project');
|
|
116
|
+
if (target === 'invalid') return fail(ctx, 'unknown --target (use project or kit)', 2);
|
|
117
|
+
if (target === 'project') return scan(ctx, root);
|
|
118
|
+
const format = single(ctx.argv, '--format') ?? 'json';
|
|
119
|
+
if (format !== 'json' && format !== 'md') return fail(ctx, `unknown --format ${format}`, 2);
|
|
120
|
+
return kitScan(ctx, root, format);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function runProjectIssues(
|
|
124
|
+
ctx: CommandContext,
|
|
125
|
+
root: string,
|
|
126
|
+
deps: ProjectIssueDeps,
|
|
127
|
+
): Promise<CommandResult> | CommandResult {
|
|
128
|
+
const format = single(ctx.argv, '--format') ?? 'json';
|
|
129
|
+
if (format !== 'json' && format !== 'md') return fail(ctx, `unknown --format ${format}`, 2);
|
|
130
|
+
const repo = single(ctx.argv, '--repo');
|
|
131
|
+
const ignoreFile = single(ctx.argv, '--ignore-file');
|
|
132
|
+
return projectIssues(
|
|
133
|
+
ctx,
|
|
134
|
+
root,
|
|
135
|
+
{
|
|
136
|
+
sync: ctx.argv.includes('--sync'),
|
|
137
|
+
format,
|
|
138
|
+
...(repo !== undefined ? { repo } : {}),
|
|
139
|
+
...(ignoreFile !== undefined ? { ignoreFile: path.resolve(ctx.cwd, ignoreFile) } : {}),
|
|
140
|
+
extraIgnores: repeated(ctx.argv, '--ignore'),
|
|
141
|
+
},
|
|
142
|
+
deps,
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async function runIssues(
|
|
147
|
+
ctx: CommandContext,
|
|
148
|
+
root: string,
|
|
149
|
+
deps: ProjectIssueDeps,
|
|
150
|
+
): Promise<CommandResult> {
|
|
151
|
+
const target = targetOf(ctx);
|
|
152
|
+
if (target === undefined || target === 'invalid')
|
|
153
|
+
return fail(ctx, 'issues needs --target kit or --target project', 2);
|
|
154
|
+
if (target === 'project') return runProjectIssues(ctx, root, deps);
|
|
155
|
+
const key = single(ctx.argv, '--key');
|
|
156
|
+
const opts = {
|
|
157
|
+
...(key !== undefined ? { key } : {}),
|
|
158
|
+
submit: ctx.argv.includes('--submit'),
|
|
159
|
+
yes: ctx.argv.includes('--yes'),
|
|
160
|
+
};
|
|
161
|
+
return kitIssues(ctx, root, opts, deps.gh);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function runReview(ctx: CommandContext, deps: ProjectIssueDeps): Promise<CommandResult> {
|
|
165
|
+
const pick = (name: string): Record<string, string> => {
|
|
166
|
+
const v = single(ctx.argv, `--${name}`);
|
|
167
|
+
return v === undefined ? {} : { [name]: v };
|
|
168
|
+
};
|
|
169
|
+
return requestReview(
|
|
170
|
+
ctx,
|
|
171
|
+
{
|
|
172
|
+
...pick('pr'),
|
|
173
|
+
...pick('kind'),
|
|
174
|
+
...pick('instruction'),
|
|
175
|
+
...pick('repo'),
|
|
176
|
+
yes: ctx.argv.includes('--yes'),
|
|
177
|
+
},
|
|
178
|
+
deps,
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export interface ImproveDeps {
|
|
183
|
+
readonly gh?: GhRunner;
|
|
184
|
+
readonly env?: NodeJS.ProcessEnv;
|
|
185
|
+
readonly github?: (opts: GitHubApiOptions) => GitHubApi;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** `gh`, the environment and the GitHub client are injectable so tests never reach GitHub. */
|
|
189
|
+
export function createImproveCommand(deps: ImproveDeps = {}): Command {
|
|
190
|
+
const resolved: ProjectIssueDeps = {
|
|
191
|
+
gh: deps.gh ?? defaultGh,
|
|
192
|
+
env: deps.env ?? process.env,
|
|
193
|
+
github: deps.github ?? defaultGitHub,
|
|
194
|
+
};
|
|
195
|
+
return {
|
|
196
|
+
name: 'improve',
|
|
197
|
+
summary:
|
|
198
|
+
'Continuous improvement: project findings, and opt-in sanitized feedback about the kit (ADR-0028)',
|
|
199
|
+
async run(ctx: CommandContext): Promise<CommandResult> {
|
|
200
|
+
const sub = ctx.argv.find((a) => !a.startsWith('-'));
|
|
201
|
+
const help = ctx.argv.includes('--help') || ctx.argv.includes('-h');
|
|
202
|
+
if (help || sub === undefined) {
|
|
203
|
+
ctx.stdout(HELP);
|
|
204
|
+
return { exitCode: sub === undefined && !help ? 2 : 0 };
|
|
205
|
+
}
|
|
206
|
+
const root = path.resolve(ctx.cwd);
|
|
207
|
+
if (sub === 'scan') return runScan(ctx, root);
|
|
208
|
+
if (sub === 'issues') return runIssues(ctx, root, resolved);
|
|
209
|
+
if (sub === 'review') return runReview(ctx, resolved);
|
|
210
|
+
return fail(ctx, `unknown subcommand: ${sub}`, 2);
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export const improveCommand: Command = createImproveCommand();
|
package/src/index.ts
CHANGED
|
@@ -3,8 +3,13 @@
|
|
|
3
3
|
//
|
|
4
4
|
// `kit` executable entry point. Parses argv, dispatches to a command,
|
|
5
5
|
// prints output, and exits.
|
|
6
|
+
//
|
|
7
|
+
// After a failing run, opt-in kit feedback capture (ADR-0028) may record a sanitized record about
|
|
8
|
+
// the kit itself. Capture is off unless .ai-kit/improvement.yml enables it, sends nothing, and
|
|
9
|
+
// never changes the exit code.
|
|
6
10
|
|
|
7
11
|
import { createDispatcher } from './application/dispatcher.js';
|
|
12
|
+
import { afterDispatch, captureKitFailure } from './application/improvement/capture.js';
|
|
8
13
|
import type { CommandContext } from './commands/types.js';
|
|
9
14
|
|
|
10
15
|
async function main(): Promise<void> {
|
|
@@ -15,12 +20,23 @@ async function main(): Promise<void> {
|
|
|
15
20
|
stdout: (s: string) => process.stdout.write(s + '\n'),
|
|
16
21
|
stderr: (s: string) => process.stderr.write(s + '\n'),
|
|
17
22
|
};
|
|
18
|
-
const { dispatch } = createDispatcher();
|
|
19
|
-
const
|
|
23
|
+
const { dispatch, registry } = createDispatcher();
|
|
24
|
+
const isKnown = (name: string): boolean => registry.get(name) !== undefined;
|
|
25
|
+
let result;
|
|
26
|
+
try {
|
|
27
|
+
result = await dispatch(ctx);
|
|
28
|
+
} catch (e) {
|
|
29
|
+
const command = argv[0] ?? '';
|
|
30
|
+
if (isKnown(command)) {
|
|
31
|
+
await captureKitFailure({ cwd: ctx.cwd, argv, command, exitCode: 2, failure: 'internal-error', message: String(e) });
|
|
32
|
+
}
|
|
33
|
+
throw e;
|
|
34
|
+
}
|
|
20
35
|
if (result.message && result.command !== 'help' && result.command !== 'doctor') {
|
|
21
36
|
// help and doctor write their own output; everything else prints the message.
|
|
22
37
|
process.stdout.write(result.message + '\n');
|
|
23
38
|
}
|
|
39
|
+
await afterDispatch(ctx.cwd, argv, result, isKnown);
|
|
24
40
|
process.exit(result.exitCode);
|
|
25
41
|
}
|
|
26
42
|
|