agjan 0.0.0-stage → 0.0.2
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 +201 -0
- package/NOTICE +11 -0
- package/README.md +105 -2
- package/bin/agjan.mjs +12 -0
- package/docs/brand/agjan-icon.svg +14 -0
- package/docs/brand/agjan-logo-dark.svg +17 -0
- package/docs/brand/agjan-logo-light.svg +17 -0
- package/docs/guide.md +232 -0
- package/kit/domains/btp/domain.json +27 -0
- package/kit/hooks/guard.mjs +61 -0
- package/kit/mcp/servers.json +5 -0
- package/kit/skills/agjan-build/SKILL.md +61 -0
- package/kit/skills/agjan-design/SKILL.md +95 -0
- package/kit/skills/agjan-fix/SKILL.md +55 -0
- package/kit/skills/agjan-map/SKILL.md +51 -0
- package/kit/skills/agjan-spec/SKILL.md +111 -0
- package/kit/skills/agjan-verify/SKILL.md +60 -0
- package/kit/skills/btp-architect/SKILL.md +51 -0
- package/kit/skills/btp-architect/references/deployment.md +72 -0
- package/kit/skills/btp-architect/references/security.md +54 -0
- package/kit/skills/cap-developer/SKILL.md +49 -0
- package/kit/skills/cap-developer/references/handlers.md +47 -0
- package/kit/skills/cap-developer/references/modeling.md +52 -0
- package/kit/skills/cap-developer/references/services.md +53 -0
- package/kit/skills/cap-developer/references/testing.md +39 -0
- package/kit/skills/cap-developer/references/validation-security.md +49 -0
- package/kit/skills/fiori-developer/SKILL.md +64 -0
- package/kit/skills/fiori-developer/references/elements.md +77 -0
- package/kit/skills/fiori-developer/references/freestyle-ts.md +45 -0
- package/kit/skills/fiori-developer/references/testing.md +32 -0
- package/kit/skills/fiori-developer/references/ui5-basics.md +52 -0
- package/kit/skills/solution-reviewer/SKILL.md +51 -0
- package/kit/templates/agents-block.md +20 -0
- package/kit/templates/agjan-ci.yml +40 -0
- package/kit/templates/design.md +17 -0
- package/kit/templates/project.md +28 -0
- package/kit/templates/spec.md +33 -0
- package/kit/templates/tasks.md +13 -0
- package/package.json +50 -4
- package/schemas/approvals.schema.json +93 -0
- package/schemas/config.schema.json +79 -0
- package/schemas/log.schema.json +30 -0
- package/schemas/reviews.schema.json +68 -0
- package/schemas/tasks.schema.json +26 -0
- package/src/adapters/claude-code.mjs +115 -0
- package/src/adapters/copilot.mjs +88 -0
- package/src/baseline.mjs +66 -0
- package/src/cli.mjs +133 -0
- package/src/commands/check.mjs +363 -0
- package/src/commands/fix.mjs +116 -0
- package/src/commands/gates.mjs +264 -0
- package/src/commands/log.mjs +53 -0
- package/src/commands/map.mjs +47 -0
- package/src/commands/new.mjs +53 -0
- package/src/commands/pr-summary.mjs +134 -0
- package/src/commands/report.mjs +110 -0
- package/src/commands/review.mjs +49 -0
- package/src/commands/setup.mjs +269 -0
- package/src/commands/status.mjs +176 -0
- package/src/config.mjs +98 -0
- package/src/context.mjs +58 -0
- package/src/documents.mjs +188 -0
- package/src/errors.mjs +16 -0
- package/src/feature.mjs +214 -0
- package/src/fix.mjs +108 -0
- package/src/git.mjs +66 -0
- package/src/hash.mjs +33 -0
- package/src/hook.mjs +48 -0
- package/src/json-file.mjs +24 -0
- package/src/log.mjs +37 -0
- package/src/managed.mjs +178 -0
- package/src/mcp-config.mjs +83 -0
- package/src/mcp.mjs +142 -0
- package/src/plan.mjs +41 -0
- package/src/progress.mjs +85 -0
- package/src/review-policy.mjs +49 -0
- package/src/review.mjs +336 -0
- package/src/scope.mjs +30 -0
- package/src/terminal.mjs +98 -0
- package/src/test-results.mjs +111 -0
- package/src/tests-map.mjs +29 -0
- package/src/ui.mjs +110 -0
- package/src/usage.mjs +118 -0
- package/src/validate.mjs +41 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Test results (design 6.6): with `verify.<area>.results` configured, an automated AC
|
|
6
|
+
* must have a test case containing its id that ran and passed. Formats: JUnit XML (node
|
|
7
|
+
* --test, jest-junit, mocha-junit-reporter, ...), Jest JSON (`--json`) and Mocha JSON
|
|
8
|
+
* (`--reporter json`). Each result is { name, status: passed | failed | skipped }.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const ENTITIES = { lt: '<', gt: '>', amp: '&', quot: '"', apos: "'" };
|
|
12
|
+
|
|
13
|
+
function decode(text) {
|
|
14
|
+
return text.replace(/&(#x?[0-9a-fA-F]+|[a-z]+);/g, (whole, code) => {
|
|
15
|
+
if (code[0] === '#') return String.fromCodePoint(code[1] === 'x' ? parseInt(code.slice(2), 16) : Number(code.slice(1)));
|
|
16
|
+
return ENTITIES[code] ?? whole;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function attribute(tag, name) {
|
|
21
|
+
const match = new RegExp(`\\s${name}\\s*=\\s*("([^"]*)"|'([^']*)')`).exec(tag);
|
|
22
|
+
return match ? decode(match[2] ?? match[3]) : '';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function parseJUnit(text) {
|
|
26
|
+
const results = [];
|
|
27
|
+
// Attributes as quoted strings: XML allows a literal '>' inside a value (name="<next>").
|
|
28
|
+
const testcase = /<testcase\b((?:\s+[^\s=/>]+\s*=\s*(?:"[^"]*"|'[^']*'))*)\s*(\/>|>([\s\S]*?)<\/testcase>)/g;
|
|
29
|
+
for (const match of text.matchAll(testcase)) {
|
|
30
|
+
const body = match[3] ?? '';
|
|
31
|
+
const status = /<(failure|error)\b/.test(body) ? 'failed' : /<skipped\b/.test(body) ? 'skipped' : 'passed';
|
|
32
|
+
const name = [attribute(match[1], 'classname'), attribute(match[1], 'name')].filter(Boolean).join(' ');
|
|
33
|
+
results.push({ name, status });
|
|
34
|
+
}
|
|
35
|
+
return results;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function parseJson(data) {
|
|
39
|
+
// Jest: { testResults: [{ assertionResults: [{ fullName, status }] }] }
|
|
40
|
+
if (Array.isArray(data?.testResults)) {
|
|
41
|
+
return data.testResults.flatMap((file) =>
|
|
42
|
+
(file.assertionResults ?? []).map((a) => ({
|
|
43
|
+
name: a.fullName ?? a.title ?? '',
|
|
44
|
+
status: a.status === 'passed' ? 'passed' : a.status === 'failed' ? 'failed' : 'skipped',
|
|
45
|
+
})),
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
// Mocha: { passes: [{ fullTitle }], failures: [...], pending: [...] }
|
|
49
|
+
if (Array.isArray(data?.passes) || Array.isArray(data?.failures)) {
|
|
50
|
+
const list = (items, status) => (items ?? []).map((t) => ({ name: t.fullTitle ?? t.title ?? '', status }));
|
|
51
|
+
return [...list(data.passes, 'passed'), ...list(data.failures, 'failed'), ...list(data.pending, 'skipped')];
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Parses one results file; returns null when the format is not recognized. */
|
|
57
|
+
export function parseResults(text) {
|
|
58
|
+
const trimmed = text.trimStart();
|
|
59
|
+
if (trimmed.startsWith('<')) return parseJUnit(text);
|
|
60
|
+
try {
|
|
61
|
+
return parseJson(JSON.parse(trimmed));
|
|
62
|
+
} catch {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The configured results files of the given areas, read and parsed. */
|
|
68
|
+
export function loadResults(root, config, areaNames) {
|
|
69
|
+
const files = [...new Set(areaNames.flatMap((name) => {
|
|
70
|
+
const results = config.verify?.[name]?.results;
|
|
71
|
+
return results ? (Array.isArray(results) ? results : [results]) : [];
|
|
72
|
+
}))];
|
|
73
|
+
const loaded = [];
|
|
74
|
+
const missing = [];
|
|
75
|
+
const unreadable = [];
|
|
76
|
+
for (const file of files) {
|
|
77
|
+
const path = join(root, file);
|
|
78
|
+
if (!existsSync(path)) {
|
|
79
|
+
missing.push(file);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const results = parseResults(readFileSync(path, 'utf8'));
|
|
83
|
+
if (results === null) unreadable.push(file);
|
|
84
|
+
else loaded.push({ file, mtimeMs: statSync(path).mtimeMs, results });
|
|
85
|
+
}
|
|
86
|
+
return { configured: files.length > 0, files: loaded, missing, unreadable };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Per AC id of the feature: how many matching test cases passed, failed or were skipped. */
|
|
90
|
+
export function acResults(loaded, key) {
|
|
91
|
+
const pattern = new RegExp(`\\b${key}-AC[1-9][0-9]*\\b`, 'g');
|
|
92
|
+
const counts = new Map();
|
|
93
|
+
for (const { results } of loaded.files) {
|
|
94
|
+
for (const r of results) {
|
|
95
|
+
for (const id of new Set(r.name.match(pattern) ?? [])) {
|
|
96
|
+
const c = counts.get(id) ?? { passed: 0, failed: 0, skipped: 0 };
|
|
97
|
+
c[r.status] += 1;
|
|
98
|
+
counts.set(id, c);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return counts;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** A short verdict per AC for summaries: passed (n), failed, skipped, not run. */
|
|
106
|
+
export function resultLabel(counts) {
|
|
107
|
+
if (!counts) return 'not run';
|
|
108
|
+
if (counts.failed) return 'failed';
|
|
109
|
+
if (counts.passed) return `passed (${counts.passed})`;
|
|
110
|
+
return 'skipped';
|
|
111
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { git } from './git.mjs';
|
|
4
|
+
import { matcher } from './scope.mjs';
|
|
5
|
+
|
|
6
|
+
/** Tracked and untracked (not ignored) files of the repository. */
|
|
7
|
+
export function repoFiles(root) {
|
|
8
|
+
return git(root, ['ls-files', '--cached', '--others', '--exclude-standard']).split('\n').filter(Boolean);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** For each AC id of the feature key, the test files that mention it. */
|
|
12
|
+
export function acTestFiles(root, config, areaNames, key) {
|
|
13
|
+
const isTest = matcher(areaNames.flatMap((name) => config.tests[name] ?? []));
|
|
14
|
+
const pattern = new RegExp(`\\b${key}-AC[1-9][0-9]*\\b`, 'g');
|
|
15
|
+
const found = new Map();
|
|
16
|
+
for (const file of repoFiles(root).filter(isTest)) {
|
|
17
|
+
let text;
|
|
18
|
+
try {
|
|
19
|
+
text = readFileSync(join(root, file), 'utf8');
|
|
20
|
+
} catch {
|
|
21
|
+
continue; // deleted in the working tree
|
|
22
|
+
}
|
|
23
|
+
for (const match of text.matchAll(pattern)) {
|
|
24
|
+
if (!found.has(match[0])) found.set(match[0], new Set());
|
|
25
|
+
found.get(match[0]).add(file);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return found;
|
|
29
|
+
}
|
package/src/ui.mjs
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Terminal styling for human-facing output. Colors only when the stream is a terminal, so
|
|
3
|
+
* agents (whose shell tools are not terminals), pipes, CI logs and tests get plain text.
|
|
4
|
+
* NO_COLOR turns colors off (https://no-color.org), FORCE_COLOR turns them on.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const CODES = {
|
|
8
|
+
bold: [1, 22],
|
|
9
|
+
dim: [2, 22],
|
|
10
|
+
red: [31, 39],
|
|
11
|
+
green: [32, 39],
|
|
12
|
+
yellow: [33, 39],
|
|
13
|
+
blue: [34, 39],
|
|
14
|
+
magenta: [35, 39],
|
|
15
|
+
cyan: [36, 39],
|
|
16
|
+
gray: [90, 39],
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export function colorEnabled(stream, env = process.env) {
|
|
20
|
+
// FORCE_COLOR wins over NO_COLOR, as in Node itself.
|
|
21
|
+
if ('FORCE_COLOR' in env) return env.FORCE_COLOR !== '0' && env.FORCE_COLOR !== 'false';
|
|
22
|
+
if ('NO_COLOR' in env && env.NO_COLOR !== '') return false;
|
|
23
|
+
return Boolean(stream?.isTTY) && env.TERM !== 'dumb';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Style functions for one stream: `s.red('text')`; identity functions when colors are off. */
|
|
27
|
+
export function createStyle(stream, env = process.env) {
|
|
28
|
+
const enabled = colorEnabled(stream, env);
|
|
29
|
+
const style = { enabled, truecolor: enabled && /^(truecolor|24bit)$/i.test(env.COLORTERM ?? '') };
|
|
30
|
+
for (const [name, [open, close]] of Object.entries(CODES)) {
|
|
31
|
+
style[name] = enabled ? (text) => `\x1b[${open}m${text}\x1b[${close}m` : (text) => String(text);
|
|
32
|
+
}
|
|
33
|
+
return style;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Colors for the words the commands print: states, verdicts, severities, levels. */
|
|
37
|
+
const TONES = {
|
|
38
|
+
green: ['ok', 'approved', 'pass', 'done', 'resolved', 'accepted', 'current', 'created', 'installed', 'merged', 'passed'],
|
|
39
|
+
yellow: ['warn', 'draft', 'pass-with-notes', 'open', 'due', 'proposed', 'updated', 'major', 'pending', 'kept', 'removed'],
|
|
40
|
+
red: ['error', 'fail', 'stale', 'blocked', 'rejected', 'blocker', 'blocks', 'modified', 'missing', 'failed'],
|
|
41
|
+
gray: ['unchanged', 'minor', 'none'],
|
|
42
|
+
};
|
|
43
|
+
const TONE_OF = new Map(Object.entries(TONES).flatMap(([tone, words]) => words.map((w) => [w, tone])));
|
|
44
|
+
|
|
45
|
+
/** Colors a known status word (`approved` green, `stale` red, ...); other text unchanged. */
|
|
46
|
+
export function tone(style, word) {
|
|
47
|
+
const name = TONE_OF.get(String(word).trim());
|
|
48
|
+
return name ? style[name](word) : String(word);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Pads by the plain text's length, so colored columns stay aligned. */
|
|
52
|
+
export function pad(styled, plain, width) {
|
|
53
|
+
return styled + ' '.repeat(Math.max(width - String(plain).length, 0));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Summary line color: red with errors, yellow with warnings only, green otherwise. */
|
|
57
|
+
export function verdictColor(style, errors, warnings) {
|
|
58
|
+
if (errors) return style.red;
|
|
59
|
+
if (warnings) return style.yellow;
|
|
60
|
+
return style.green;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Status words inside Markdown text: whole words only, `pass-with-notes` before `pass`. */
|
|
64
|
+
const WORDS = new RegExp(`(?<![\\w-])(${[...TONE_OF.keys()].sort((a, b) => b.length - a.length).join('|')})(?![\\w-])`, 'g');
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Highlights Markdown for reading on a terminal: headings, bold text, table rules and the
|
|
68
|
+
* known status words. The text stays valid Markdown once the colors are stripped.
|
|
69
|
+
*/
|
|
70
|
+
export function highlightMarkdown(style, text) {
|
|
71
|
+
if (!style.enabled) return text;
|
|
72
|
+
return text
|
|
73
|
+
.split('\n')
|
|
74
|
+
.map((line) => {
|
|
75
|
+
if (/^#{1,6} /.test(line)) return style.bold(style.cyan(line));
|
|
76
|
+
if (/^\|[-| ]+\|$/.test(line)) return style.gray(line);
|
|
77
|
+
return line
|
|
78
|
+
.replace(/\*\*([^*]+)\*\*/g, (_, inner) => style.bold(`**${inner}**`))
|
|
79
|
+
.replace(WORDS, (word) => tone(style, word))
|
|
80
|
+
.replace(/^\||(?<= )\|/g, (bar) => style.gray(bar));
|
|
81
|
+
})
|
|
82
|
+
.join('\n');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const LOGO = ['▄▀█ █▀▀ █ ▄▀█ █▄ █', '█▀█ █▄█ █▄█ █▀█ █ ▀█'];
|
|
86
|
+
|
|
87
|
+
/** Blue to teal, left to right. */
|
|
88
|
+
function gradient(style, line) {
|
|
89
|
+
if (!style.truecolor) return style.cyan(line);
|
|
90
|
+
const from = [0, 112, 242];
|
|
91
|
+
const to = [0, 200, 180];
|
|
92
|
+
const n = Math.max(line.length - 1, 1);
|
|
93
|
+
let out = '';
|
|
94
|
+
for (let i = 0; i < line.length; i++) {
|
|
95
|
+
const [r, g, b] = from.map((c, k) => Math.round(c + ((to[k] - c) * i) / n));
|
|
96
|
+
out += line[i] === ' ' ? ' ' : `\x1b[38;2;${r};${g};${b}m${line[i]}`;
|
|
97
|
+
}
|
|
98
|
+
return `${out}\x1b[39m`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** The agjan logo with the version and a tagline beside it; empty when colors are off. */
|
|
102
|
+
export function banner(style, version) {
|
|
103
|
+
if (!style.enabled) return [];
|
|
104
|
+
return [
|
|
105
|
+
'',
|
|
106
|
+
` ${gradient(style, LOGO[0])} ${style.bold(`agjan ${version}`)}`,
|
|
107
|
+
` ${gradient(style, LOGO[1])} ${style.gray('spec-driven workflow with human gates')}`,
|
|
108
|
+
'',
|
|
109
|
+
];
|
|
110
|
+
}
|
package/src/usage.mjs
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { existsSync, readFileSync, readdirSync, realpathSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Actual model and token usage from the hosts' own session records (design 12.2,
|
|
7
|
+
* host experiments item 4), never from the model's statements. Both formats are
|
|
8
|
+
* internal to the hosts: anything unexpected is skipped, and the report then says
|
|
9
|
+
* "unknown". Each record: { at (ms), host, model, input, cacheRead, cacheWrite, output,
|
|
10
|
+
* agent: 'main' | 'subagent' }.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
function readLines(file) {
|
|
14
|
+
try {
|
|
15
|
+
return readFileSync(file, 'utf8').split('\n');
|
|
16
|
+
} catch {
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function parse(line) {
|
|
22
|
+
try {
|
|
23
|
+
return JSON.parse(line);
|
|
24
|
+
} catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function sameDir(a, b) {
|
|
30
|
+
try {
|
|
31
|
+
return realpathSync(a) === realpathSync(b);
|
|
32
|
+
} catch {
|
|
33
|
+
return a === b;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Claude Code: ~/.claude/projects/<cwd with every non [A-Za-z0-9-] as '-'>/…jsonl. */
|
|
38
|
+
export function claudeUsage(root, { home = process.env.CLAUDE_CONFIG_DIR ?? join(homedir(), '.claude') } = {}) {
|
|
39
|
+
const dir = join(home, 'projects', realpathOr(root).replace(/[^A-Za-z0-9-]/g, '-'));
|
|
40
|
+
if (!existsSync(dir)) return [];
|
|
41
|
+
const files = [];
|
|
42
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
43
|
+
if (entry.isFile() && entry.name.endsWith('.jsonl')) files.push(join(dir, entry.name));
|
|
44
|
+
const sub = join(dir, entry.name, 'subagents');
|
|
45
|
+
if (entry.isDirectory() && existsSync(sub)) {
|
|
46
|
+
for (const f of readdirSync(sub)) if (f.endsWith('.jsonl')) files.push(join(sub, f));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const seen = new Set();
|
|
50
|
+
const records = [];
|
|
51
|
+
for (const file of files) {
|
|
52
|
+
for (const line of readLines(file)) {
|
|
53
|
+
const entry = parse(line);
|
|
54
|
+
const usage = entry?.message?.usage;
|
|
55
|
+
if (entry?.type !== 'assistant' || !usage || !entry.timestamp) continue;
|
|
56
|
+
// One response can be written as several lines with the same request id.
|
|
57
|
+
const key = entry.requestId ?? entry.message.id ?? `${file}:${entry.uuid}`;
|
|
58
|
+
if (seen.has(key)) continue;
|
|
59
|
+
seen.add(key);
|
|
60
|
+
records.push({
|
|
61
|
+
at: Date.parse(entry.timestamp),
|
|
62
|
+
host: 'claude-code',
|
|
63
|
+
model: entry.message.model ?? 'unknown',
|
|
64
|
+
input: usage.input_tokens ?? 0,
|
|
65
|
+
cacheRead: usage.cache_read_input_tokens ?? 0,
|
|
66
|
+
cacheWrite: usage.cache_creation_input_tokens ?? 0,
|
|
67
|
+
output: usage.output_tokens ?? 0,
|
|
68
|
+
agent: entry.isSidechain ? 'subagent' : 'main',
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return records;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function realpathOr(path) {
|
|
76
|
+
try {
|
|
77
|
+
return realpathSync(path);
|
|
78
|
+
} catch {
|
|
79
|
+
return path;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** GitHub Copilot CLI: ~/.copilot/session-state/<id>/events.jsonl of sessions in this repository. */
|
|
84
|
+
export function copilotUsage(root, { home = process.env.COPILOT_HOME ?? join(homedir(), '.copilot') } = {}) {
|
|
85
|
+
const dir = join(home, 'session-state');
|
|
86
|
+
if (!existsSync(dir)) return [];
|
|
87
|
+
const records = [];
|
|
88
|
+
for (const id of readdirSync(dir)) {
|
|
89
|
+
const lines = readLines(join(dir, id, 'events.jsonl'));
|
|
90
|
+
const start = lines.map(parse).find((e) => e?.type === 'session.start');
|
|
91
|
+
const context = start?.data?.context ?? {};
|
|
92
|
+
const where = context.gitRoot ?? context.cwd;
|
|
93
|
+
if (!where || !sameDir(where, root)) continue;
|
|
94
|
+
for (const line of lines) {
|
|
95
|
+
const event = parse(line);
|
|
96
|
+
const usage = event?.type === 'session.usage_record' ? event.data?.usage : null;
|
|
97
|
+
if (!usage || !event.timestamp) continue;
|
|
98
|
+
records.push({
|
|
99
|
+
at: Date.parse(event.timestamp),
|
|
100
|
+
host: 'copilot',
|
|
101
|
+
model: usage.model ?? 'unknown',
|
|
102
|
+
input: usage.inputTokens ?? 0,
|
|
103
|
+
cacheRead: usage.cacheReadTokens ?? 0,
|
|
104
|
+
cacheWrite: usage.cacheWriteTokens ?? 0,
|
|
105
|
+
output: usage.outputTokens ?? 0,
|
|
106
|
+
agent: usage.initiator === 'sub-agent' ? 'subagent' : 'main',
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return records;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Usage of all hosts in this repository between `from` and `to` (ms). */
|
|
114
|
+
export function usageBetween(root, from, to, homes = {}) {
|
|
115
|
+
return [...claudeUsage(root, { home: homes.claude }), ...copilotUsage(root, { home: homes.copilot })]
|
|
116
|
+
.filter((r) => r.at >= from && r.at <= to)
|
|
117
|
+
.sort((a, b) => a.at - b.at);
|
|
118
|
+
}
|
package/src/validate.mjs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { resolveArea } from './config.mjs';
|
|
2
|
+
|
|
3
|
+
/** Structural problems of the feature's documents, prefixed with the file name. */
|
|
4
|
+
export function documentProblems(feature) {
|
|
5
|
+
const problems = [];
|
|
6
|
+
for (const name of ['spec', 'design', 'tasks']) {
|
|
7
|
+
const doc = feature[name];
|
|
8
|
+
if (doc) problems.push(...doc.parsed.problems.map((p) => `${name}.md: ${p}`));
|
|
9
|
+
}
|
|
10
|
+
return problems;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Consistency between design, tasks, spec and configuration: areas exist and are
|
|
15
|
+
* enabled, every task belongs to an approved area, every `covers` id is a spec AC, and
|
|
16
|
+
* every AC is covered by at least one task.
|
|
17
|
+
*/
|
|
18
|
+
export function designProblems(feature, config) {
|
|
19
|
+
const problems = [];
|
|
20
|
+
if (!feature.design || !feature.tasks || !feature.spec) return problems;
|
|
21
|
+
const designAreas = new Set();
|
|
22
|
+
for (const id of feature.design.parsed.areas) {
|
|
23
|
+
const area = resolveArea(config, id);
|
|
24
|
+
if (!area) problems.push(`design.md: area '${id}' is not an area of the enabled domains (${config.domains.join(', ')})`);
|
|
25
|
+
else designAreas.add(area.id);
|
|
26
|
+
}
|
|
27
|
+
const acIds = new Set(feature.spec.parsed.acs.map((ac) => ac.id));
|
|
28
|
+
const covered = new Set();
|
|
29
|
+
for (const task of feature.tasks.parsed.tasks) {
|
|
30
|
+
const area = resolveArea(config, task.area ?? '');
|
|
31
|
+
if (!area || !designAreas.has(area.id)) problems.push(`tasks.md: ${task.id} area '${task.area}' is not one of the design's areas`);
|
|
32
|
+
for (const id of task.covers) {
|
|
33
|
+
if (!acIds.has(id)) problems.push(`tasks.md: ${task.id} covers '${id}', which is not an AC of the spec`);
|
|
34
|
+
covered.add(id);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
for (const id of acIds) {
|
|
38
|
+
if (!covered.has(id)) problems.push(`${id} is not covered by any task`);
|
|
39
|
+
}
|
|
40
|
+
return problems;
|
|
41
|
+
}
|