@krisada-m/ksd-intelligence 0.0.0-stage → 1.0.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 +167 -2
- package/dist/adapters/agy/skills.js +252 -0
- package/dist/adapters/cli/check-changed.js +3 -0
- package/dist/adapters/cli/main.js +1002 -0
- package/dist/adapters/cli/policy-bin.js +10 -0
- package/dist/adapters/cli/review-verdict.js +3 -0
- package/dist/adapters/omp/extension.js +893 -0
- package/dist/adapters/omp/skills.js +130 -0
- package/dist/adapters/ui/hud.js +318 -0
- package/dist/adapters/ui/tree.js +460 -0
- package/dist/core/audit/index.js +2 -0
- package/dist/core/audit/log.js +505 -0
- package/dist/core/audit/summary.js +188 -0
- package/dist/core/changes/changes.js +591 -0
- package/dist/core/changes/git.js +266 -0
- package/dist/core/changes/plan.js +109 -0
- package/dist/core/changes/render.js +356 -0
- package/dist/core/engine/build.js +178 -0
- package/dist/core/engine/child.js +389 -0
- package/dist/core/engine/host.js +206 -0
- package/dist/core/engine/lock.js +133 -0
- package/dist/core/engine/protocol.js +43 -0
- package/dist/core/engine/runtime.js +44 -0
- package/dist/core/engine/status.js +381 -0
- package/dist/core/engine/typescript.js +194 -0
- package/dist/core/engine/workspace.js +72 -0
- package/dist/core/graph/graph.js +127 -0
- package/dist/core/graph/limits.js +16 -0
- package/dist/core/impact/query.js +1292 -0
- package/dist/core/impact/render.js +590 -0
- package/dist/core/impact/session.js +694 -0
- package/dist/core/indexing/declarations.js +455 -0
- package/dist/core/indexing/differential.js +345 -0
- package/dist/core/indexing/doctor.js +120 -0
- package/dist/core/indexing/indexer.js +792 -0
- package/dist/core/indexing/keys.js +451 -0
- package/dist/core/indexing/lexical.js +212 -0
- package/dist/core/indexing/packages.js +57 -0
- package/dist/core/indexing/program.js +171 -0
- package/dist/core/indexing/resolve.js +1004 -0
- package/dist/core/indexing/stamp.js +52 -0
- package/dist/core/indexing/surface.js +335 -0
- package/dist/core/indexing/ui-progress.js +37 -0
- package/dist/core/indexing/verify.js +76 -0
- package/dist/core/kernel/config.js +383 -0
- package/dist/core/kernel/glob.js +105 -0
- package/dist/core/kernel/guards.js +4 -0
- package/dist/core/kernel/types.js +3 -0
- package/dist/core/kernel/verdict.js +142 -0
- package/dist/core/knowledge/anchors.js +139 -0
- package/dist/core/knowledge/knowledge.js +95 -0
- package/dist/core/knowledge/learning.js +102 -0
- package/dist/core/knowledge/render.js +76 -0
- package/dist/core/knowledge/store.js +109 -0
- package/dist/core/knowledge/yaml.js +87 -0
- package/dist/core/search/lexical.js +382 -0
- package/dist/core/search/render.js +98 -0
- package/dist/core/search/segments.js +118 -0
- package/dist/core/verify/parse.js +127 -0
- package/dist/core/verify/render.js +67 -0
- package/dist/core/verify/report.js +40 -0
- package/dist/core/verify/revision.js +79 -0
- package/dist/core/verify/run.js +117 -0
- package/dist/core/verify/store.js +66 -0
- package/dist/core/verify/verify.js +173 -0
- package/dist/core/workspace/init.js +267 -0
- package/dist/core/workspace/probe.js +56 -0
- package/dist/core/workspace/scan.js +420 -0
- package/dist/index.js +20 -0
- package/dist/policy/change-scope.js +500 -0
- package/dist/policy/check-changed.js +40 -0
- package/dist/policy/config.js +106 -0
- package/dist/policy/dist/policy.d.ts +17 -0
- package/dist/policy/dist/policy.js +147 -0
- package/dist/policy/dist/runtime.d.ts +40 -0
- package/dist/policy/dist/runtime.js +75 -0
- package/dist/policy/dist/sdlc.d.ts +7 -0
- package/dist/policy/dist/sdlc.js +27 -0
- package/dist/policy/eslint-rules/index.js +107 -0
- package/dist/policy/index.d.ts +2 -0
- package/dist/policy/index.js +241 -0
- package/dist/policy/package.json +33 -0
- package/dist/policy/policy.d.ts +2 -0
- package/dist/policy/policy.js +2 -0
- package/dist/policy/review-verdict.js +262 -0
- package/dist/policy/sdlc.js +2 -0
- package/dist/storage/records.js +245 -0
- package/dist/storage/sqlite.js +314 -0
- package/dist/workflow/catalog.js +69 -0
- package/dist/workflow/classify.js +55 -0
- package/dist/workflow/loader.js +140 -0
- package/dist/workflow/packs.js +469 -0
- package/dist/workflow/registry.js +359 -0
- package/dist/workflow/render.js +61 -0
- package/dist/workflow/router.js +141 -0
- package/dist/workflow/sources.js +229 -0
- package/dist/workflow/types.js +44 -0
- package/dist/workflow/updates.js +532 -0
- package/package.json +74 -4
- package/scripts/agy-mcp.mjs +27 -0
- package/scripts/mcp/stdio.mjs +304 -0
- package/scripts/mcp/tools.mjs +451 -0
- package/skills/ksd-intelligence/SKILL.md +54 -0
- package/skills/matt-sdlc/SKILL.md +42 -0
- package/skills/osmani-quality/SKILL.md +38 -0
- package/skills/poteto-mode/SKILL.md +40 -0
- package/skills/pstack-analysis/SKILL.md +36 -0
- package/skills.lock.json +71 -0
- package/skills.registry.json +181 -0
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { dirname, isAbsolute, join } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { promisify } from 'node:util';
|
|
7
|
+
import { PROVIDERS, skillIdsOf } from './catalog.js';
|
|
8
|
+
import { readSkill } from './loader.js';
|
|
9
|
+
import { PROVIDER_IDS, WorkflowError } from './types.js';
|
|
10
|
+
const execFileAsync = promisify(execFile);
|
|
11
|
+
const COMMIT = /^[0-9a-f]{40}$/;
|
|
12
|
+
const SHA256 = /^[0-9a-f]{64}$/;
|
|
13
|
+
// Resolves to <repo>/skills.lock.json from src/workflow, dist/workflow, and dist-test/src/workflow.
|
|
14
|
+
export function defaultLockPath() {
|
|
15
|
+
const fallback = fileURLToPath(new URL('../../skills.lock.json', import.meta.url));
|
|
16
|
+
let dir = dirname(fileURLToPath(import.meta.url));
|
|
17
|
+
for (let depth = 0; depth < 5; depth += 1) {
|
|
18
|
+
const candidate = join(dir, 'skills.lock.json');
|
|
19
|
+
if (existsSync(join(dir, 'package.json')) && existsSync(candidate)) {
|
|
20
|
+
return candidate;
|
|
21
|
+
}
|
|
22
|
+
const parent = dirname(dir);
|
|
23
|
+
if (parent === dir)
|
|
24
|
+
break;
|
|
25
|
+
dir = parent;
|
|
26
|
+
}
|
|
27
|
+
return fallback;
|
|
28
|
+
}
|
|
29
|
+
function isRecord(value) {
|
|
30
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
31
|
+
}
|
|
32
|
+
function lockError(message) {
|
|
33
|
+
return new WorkflowError('LOCK_INVALID', message);
|
|
34
|
+
}
|
|
35
|
+
function parseProvider(provider, raw) {
|
|
36
|
+
const where = `providers.${provider}`;
|
|
37
|
+
if (!isRecord(raw))
|
|
38
|
+
throw lockError(`${where} must be an object`);
|
|
39
|
+
const info = PROVIDERS[provider];
|
|
40
|
+
const { repo, commit, rootSubpath, skills: rawSkills } = raw;
|
|
41
|
+
if (repo !== info.repo)
|
|
42
|
+
throw lockError(`${where}.repo is ${JSON.stringify(repo)}, catalog expects ${info.repo}`);
|
|
43
|
+
if (rootSubpath !== info.rootSubpath)
|
|
44
|
+
throw lockError(`${where}.rootSubpath is ${JSON.stringify(rootSubpath)}, catalog expects ${info.rootSubpath}`);
|
|
45
|
+
if (commit !== null && !(typeof commit === 'string' && COMMIT.test(commit))) {
|
|
46
|
+
throw lockError(`${where}.commit must be null or a 40-char lowercase hex SHA`);
|
|
47
|
+
}
|
|
48
|
+
if (!isRecord(rawSkills))
|
|
49
|
+
throw lockError(`${where}.skills must be an object`);
|
|
50
|
+
const expectedIds = skillIdsOf(provider);
|
|
51
|
+
const unknown = Object.keys(rawSkills).filter((id) => !expectedIds.includes(id));
|
|
52
|
+
if (unknown.length > 0)
|
|
53
|
+
throw lockError(`${where}.skills has ids not in the catalog: ${unknown.join(', ')}`);
|
|
54
|
+
const skills = {};
|
|
55
|
+
for (const id of expectedIds) {
|
|
56
|
+
const entry = rawSkills[id];
|
|
57
|
+
if (!isRecord(entry))
|
|
58
|
+
throw lockError(`${where}.skills[${id}] missing or not an object`);
|
|
59
|
+
const { sha256 } = entry;
|
|
60
|
+
if (sha256 !== null && !(typeof sha256 === 'string' && SHA256.test(sha256))) {
|
|
61
|
+
throw lockError(`${where}.skills[${id}].sha256 must be null or 64-char lowercase hex`);
|
|
62
|
+
}
|
|
63
|
+
skills[id] = { sha256 };
|
|
64
|
+
}
|
|
65
|
+
return { repo: info.repo, commit, rootSubpath: info.rootSubpath, skills };
|
|
66
|
+
}
|
|
67
|
+
export function parseLock(text) {
|
|
68
|
+
let raw;
|
|
69
|
+
try {
|
|
70
|
+
raw = JSON.parse(text);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
throw lockError(`not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
74
|
+
}
|
|
75
|
+
if (!isRecord(raw) || raw.version !== 1)
|
|
76
|
+
throw lockError('version must be 1');
|
|
77
|
+
const providers = raw.providers;
|
|
78
|
+
if (!isRecord(providers))
|
|
79
|
+
throw lockError('providers must be an object');
|
|
80
|
+
return {
|
|
81
|
+
version: 1,
|
|
82
|
+
providers: {
|
|
83
|
+
matt: parseProvider('matt', providers.matt),
|
|
84
|
+
poteto: parseProvider('poteto', providers.poteto),
|
|
85
|
+
osmani: parseProvider('osmani', providers.osmani),
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
export async function readLock(path) {
|
|
90
|
+
let text;
|
|
91
|
+
try {
|
|
92
|
+
text = await readFile(path, 'utf8');
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
throw lockError(`cannot read lock file ${path}: ${error instanceof Error ? error.message : String(error)}`);
|
|
96
|
+
}
|
|
97
|
+
return parseLock(text);
|
|
98
|
+
}
|
|
99
|
+
export async function writeLock(path, lock) {
|
|
100
|
+
await writeFile(path, `${JSON.stringify(lock, null, 2)}\n`);
|
|
101
|
+
}
|
|
102
|
+
export function reportStatus(report) {
|
|
103
|
+
if (report.problems.length > 0)
|
|
104
|
+
return 'ERROR';
|
|
105
|
+
if (report.lockCommit === null || report.hashesVerified < report.skillsTotal)
|
|
106
|
+
return 'UNPINNED';
|
|
107
|
+
return 'OK';
|
|
108
|
+
}
|
|
109
|
+
async function gitHead(root) {
|
|
110
|
+
try {
|
|
111
|
+
const { stdout } = await execFileAsync('git', ['-C', root, 'rev-parse', 'HEAD']);
|
|
112
|
+
const head = stdout.trim();
|
|
113
|
+
return COMMIT.test(head) ? head : null;
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
async function gatherFacts(provider, roots) {
|
|
120
|
+
const ids = skillIdsOf(provider);
|
|
121
|
+
const hashes = new Map();
|
|
122
|
+
const problems = [];
|
|
123
|
+
const root = roots[provider];
|
|
124
|
+
const head = root && isAbsolute(root) ? await gitHead(root) : null;
|
|
125
|
+
for (const id of ids) {
|
|
126
|
+
try {
|
|
127
|
+
hashes.set(id, (await readSkill(id, roots)).sha256);
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
if (!(error instanceof WorkflowError))
|
|
131
|
+
throw error;
|
|
132
|
+
problems.push({ code: error.code, message: error.detail });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// A missing/nonexistent root already yields one problem per skill; collapse them into one.
|
|
136
|
+
const rootProblem = problems.find((p) => p.code === 'PROVIDER_ROOT_MISSING' || p.code === 'PROVIDER_ROOT_NOT_FOUND');
|
|
137
|
+
if (rootProblem)
|
|
138
|
+
return { root: root ?? null, head, hashes, problems: [rootProblem] };
|
|
139
|
+
if (head === null) {
|
|
140
|
+
problems.push({
|
|
141
|
+
code: 'NOT_A_GIT_CHECKOUT',
|
|
142
|
+
message: `${PROVIDERS[provider].envVar}=${root} has no readable git HEAD`,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
return { root: root ?? null, head, hashes, problems };
|
|
146
|
+
}
|
|
147
|
+
function reportFor(provider, facts, lock, written) {
|
|
148
|
+
const problems = [...facts.problems];
|
|
149
|
+
let hashesVerified = 0;
|
|
150
|
+
for (const [id, actual] of facts.hashes) {
|
|
151
|
+
const pinned = lock.skills[id]?.sha256 ?? null;
|
|
152
|
+
if (pinned === null)
|
|
153
|
+
continue;
|
|
154
|
+
if (pinned === actual)
|
|
155
|
+
hashesVerified += 1;
|
|
156
|
+
else
|
|
157
|
+
problems.push({
|
|
158
|
+
code: 'HASH_MISMATCH',
|
|
159
|
+
message: `${id}: file sha256 ${actual}, lock pins ${pinned}`,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
if (lock.commit !== null && facts.head !== null && facts.head !== lock.commit) {
|
|
163
|
+
problems.push({
|
|
164
|
+
code: 'COMMIT_MISMATCH',
|
|
165
|
+
message: `checkout HEAD ${facts.head}, lock pins ${lock.commit}`,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
provider,
|
|
170
|
+
root: facts.root,
|
|
171
|
+
head: facts.head,
|
|
172
|
+
lockCommit: lock.commit,
|
|
173
|
+
skillsFound: facts.hashes.size,
|
|
174
|
+
skillsTotal: skillIdsOf(provider).length,
|
|
175
|
+
hashesVerified,
|
|
176
|
+
problems,
|
|
177
|
+
written,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
// Never clones or fetches. With `write`, a provider's commit and hashes are replaced only when its
|
|
181
|
+
// root exists, HEAD is readable and every catalog skill passes the loader's checks.
|
|
182
|
+
export async function checkSources(lock, roots, options) {
|
|
183
|
+
const nextProviders = { ...lock.providers };
|
|
184
|
+
const reports = [];
|
|
185
|
+
for (const provider of PROVIDER_IDS) {
|
|
186
|
+
const facts = await gatherFacts(provider, roots);
|
|
187
|
+
const current = lock.providers[provider];
|
|
188
|
+
const complete = facts.problems.length === 0 && facts.head !== null;
|
|
189
|
+
if (options.write && complete) {
|
|
190
|
+
const skills = {};
|
|
191
|
+
for (const [id, sha256] of facts.hashes)
|
|
192
|
+
skills[id] = { sha256 };
|
|
193
|
+
nextProviders[provider] = { ...current, commit: facts.head, skills };
|
|
194
|
+
}
|
|
195
|
+
const next = nextProviders[provider];
|
|
196
|
+
reports.push(reportFor(provider, facts, next, options.write && complete));
|
|
197
|
+
}
|
|
198
|
+
return { reports, lock: { version: 1, providers: nextProviders } };
|
|
199
|
+
}
|
|
200
|
+
function short(sha) {
|
|
201
|
+
return sha === null ? '-' : sha.slice(0, 12);
|
|
202
|
+
}
|
|
203
|
+
export function formatReports(reports) {
|
|
204
|
+
const rows = [['provider', 'status', 'skills', 'hashes', 'HEAD', 'lock commit', 'codes']];
|
|
205
|
+
for (const r of reports) {
|
|
206
|
+
const codes = [...new Set(r.problems.map((p) => p.code))].join(',') || '-';
|
|
207
|
+
rows.push([
|
|
208
|
+
r.provider,
|
|
209
|
+
reportStatus(r),
|
|
210
|
+
`${r.skillsFound}/${r.skillsTotal}`,
|
|
211
|
+
`${r.hashesVerified}/${r.skillsTotal}`,
|
|
212
|
+
short(r.head),
|
|
213
|
+
short(r.lockCommit),
|
|
214
|
+
codes,
|
|
215
|
+
]);
|
|
216
|
+
}
|
|
217
|
+
const widths = rows[0]?.map((_, col) => Math.max(...rows.map((row) => (row[col] ?? '').length))) ?? [];
|
|
218
|
+
const lines = rows.map((row) => row
|
|
219
|
+
.map((cell, col) => cell.padEnd(widths[col] ?? 0))
|
|
220
|
+
.join(' ')
|
|
221
|
+
.trimEnd());
|
|
222
|
+
for (const r of reports) {
|
|
223
|
+
for (const p of r.problems)
|
|
224
|
+
lines.push(`${r.provider}: ${p.code}: ${p.message}`);
|
|
225
|
+
if (r.written)
|
|
226
|
+
lines.push(`${r.provider}: lock updated (commit ${short(r.head)}, ${r.skillsFound} hashes)`);
|
|
227
|
+
}
|
|
228
|
+
return lines.join('\n');
|
|
229
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export const TASK_TYPES = ['bug', 'feature', 'refactor', 'security', 'performance', 'ui'];
|
|
2
|
+
export const STAGES = ['plan', 'investigate', 'implement', 'verify', 'review', 'ship'];
|
|
3
|
+
export const RISKS = ['normal', 'high'];
|
|
4
|
+
export const PROVIDER_IDS = ['matt', 'poteto', 'osmani'];
|
|
5
|
+
export const ORCHESTRATOR_SKILL_ID = 'ksd-intelligence';
|
|
6
|
+
export const SKILL_PACK_IDS = [
|
|
7
|
+
'matt-sdlc',
|
|
8
|
+
'pstack-analysis',
|
|
9
|
+
'poteto-mode',
|
|
10
|
+
'osmani-quality',
|
|
11
|
+
];
|
|
12
|
+
export const CATALOG_SKILL_NAMES = [ORCHESTRATOR_SKILL_ID, ...SKILL_PACK_IDS];
|
|
13
|
+
export const COMPLIANCE_DIMENSIONS = ['REQ', 'Code', 'Test', 'Runtime Evidence'];
|
|
14
|
+
export const SKILL_IDS = [
|
|
15
|
+
'matt:diagnosing-bugs',
|
|
16
|
+
'matt:codebase-design',
|
|
17
|
+
'matt:tdd',
|
|
18
|
+
'matt:code-review',
|
|
19
|
+
'poteto:how',
|
|
20
|
+
'poteto:why',
|
|
21
|
+
'poteto:blast-radius',
|
|
22
|
+
'osmani:spec-driven-development',
|
|
23
|
+
'osmani:incremental-implementation',
|
|
24
|
+
'osmani:code-review-and-quality',
|
|
25
|
+
'osmani:security-and-hardening',
|
|
26
|
+
'osmani:performance-optimization',
|
|
27
|
+
'osmani:frontend-ui-engineering',
|
|
28
|
+
'osmani:browser-testing-with-devtools',
|
|
29
|
+
'osmani:shipping-and-launch',
|
|
30
|
+
];
|
|
31
|
+
export class WorkflowError extends Error {
|
|
32
|
+
code;
|
|
33
|
+
// Message without the code prefix, for tables that show the code in its own column.
|
|
34
|
+
detail;
|
|
35
|
+
constructor(code, detail) {
|
|
36
|
+
super(`${code}: ${detail}`);
|
|
37
|
+
this.name = 'WorkflowError';
|
|
38
|
+
this.code = code;
|
|
39
|
+
this.detail = detail;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export function isOneOf(list, value) {
|
|
43
|
+
return list.some((item) => item === value);
|
|
44
|
+
}
|