@ngockhoale/ukit 3.5.5 → 3.5.7

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.
Files changed (59) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/manifests/engineConformance.yaml +0 -13
  3. package/manifests/platform.full.yaml +25 -0
  4. package/package.json +1 -8
  5. package/src/cli/commands/indexTools.js +1 -0
  6. package/src/cli/commands/memory.js +33 -4
  7. package/src/core/applyPlan.js +37 -72
  8. package/src/core/diffPlan.js +39 -9
  9. package/src/core/managedTemplateMerge.js +231 -0
  10. package/src/core/memory/memoryFlags.js +5 -6
  11. package/src/core/memory/policy.js +5 -0
  12. package/src/core/memory/store.js +17 -0
  13. package/src/core/metadata.js +12 -8
  14. package/src/core/runInstallPipeline.js +16 -10
  15. package/src/core/runtimeConfig.js +14 -83
  16. package/src/core/uninstall.js +8 -1
  17. package/src/decision/registry.js +17 -17
  18. package/src/decision/runtimeDecide.js +5 -5
  19. package/src/index/playbookRegistry.js +6 -1
  20. package/src/index/queryIndex.js +41 -4
  21. package/src/index/routeResolver.js +2 -2
  22. package/src/index/semanticLane.js +277 -0
  23. package/src/learning/lessonClass.js +110 -0
  24. package/src/learning/patternProposals.js +111 -7
  25. package/src/learning/reeditMiner.js +104 -0
  26. package/src/learning/selfImprove.js +9 -1
  27. package/template_project/.claude/hooks/skill-router.sh +273 -5
  28. package/template_project/.claude/skills/canvas-design/SKILL.md +2 -2
  29. package/template_project/.claude/skills/canvas-design/canvas-fonts/{InstrumentSans-OFL.txt → InstrumentSerif-OFL.txt} +3 -3
  30. package/template_project/.claude/skills/canvas-design/scripts/fetch-fonts.mjs +148 -0
  31. package/template_project/.claude/ukit/index/embed-index.mjs +26 -0
  32. package/template_project/.claude/ukit/index/lib/index-core.mjs +43 -4
  33. package/template_project/.claude/ukit/index/lib/semantic-lane.mjs +277 -0
  34. package/template_project/.claude/ukit/index/playbook-registry.mjs +6 -1
  35. package/template_project/.claude/ukit/index/publication-intent.mjs +159 -1
  36. package/template_project/.claude/ukit/index/query-index.mjs +9 -1
  37. package/template_project/.claude/ukit/index/route-resolver.mjs +2 -2
  38. package/template_project/.claude/ukit/index/route-task.mjs +14 -3
  39. package/template_project/.claude/ukit/runtime/memory-policy.mjs +5 -0
  40. package/template_project/.claude/ukit/runtime/stop-coordinator.mjs +12 -1
  41. package/template_project/ukit/storage/config.json +0 -32
  42. package/template_project/.claude/skills/canvas-design/canvas-fonts/BricolageGrotesque-Bold.ttf +0 -0
  43. package/template_project/.claude/skills/canvas-design/canvas-fonts/BricolageGrotesque-OFL.txt +0 -93
  44. package/template_project/.claude/skills/canvas-design/canvas-fonts/BricolageGrotesque-Regular.ttf +0 -0
  45. package/template_project/.claude/skills/canvas-design/canvas-fonts/InstrumentSans-Bold.ttf +0 -0
  46. package/template_project/.claude/skills/canvas-design/canvas-fonts/InstrumentSans-BoldItalic.ttf +0 -0
  47. package/template_project/.claude/skills/canvas-design/canvas-fonts/InstrumentSans-Italic.ttf +0 -0
  48. package/template_project/.claude/skills/canvas-design/canvas-fonts/InstrumentSans-Regular.ttf +0 -0
  49. package/template_project/.claude/skills/canvas-design/canvas-fonts/InstrumentSerif-Italic.ttf +0 -0
  50. package/template_project/.claude/skills/canvas-design/canvas-fonts/JetBrainsMono-Bold.ttf +0 -0
  51. package/template_project/.claude/skills/canvas-design/canvas-fonts/Lora-Bold.ttf +0 -0
  52. package/template_project/.claude/skills/canvas-design/canvas-fonts/Lora-BoldItalic.ttf +0 -0
  53. package/template_project/.claude/skills/canvas-design/canvas-fonts/Lora-Italic.ttf +0 -0
  54. package/template_project/.claude/skills/canvas-design/canvas-fonts/Lora-OFL.txt +0 -93
  55. package/template_project/.claude/skills/canvas-design/canvas-fonts/Lora-Regular.ttf +0 -0
  56. package/template_project/.claude/skills/canvas-design/canvas-fonts/Outfit-Bold.ttf +0 -0
  57. package/template_project/.claude/skills/canvas-design/canvas-fonts/Tektur-Medium.ttf +0 -0
  58. package/template_project/.claude/skills/canvas-design/canvas-fonts/YoungSerif-OFL.txt +0 -93
  59. package/template_project/.claude/skills/canvas-design/canvas-fonts/YoungSerif-Regular.ttf +0 -0
@@ -15,6 +15,7 @@
15
15
 
16
16
  import fs from 'node:fs/promises';
17
17
  import path from 'node:path';
18
+ import { classifyPattern, classifyReedit, refineWithDecision } from './lessonClass.js';
18
19
  import {
19
20
  listPendingPatternCandidates,
20
21
  proposePatternCandidate,
@@ -22,16 +23,49 @@ import {
22
23
 
23
24
  const ARTIFACT_REL = path.join('.ukit', 'storage', 'cache', 'failure-patterns.json');
24
25
  const MIN_SESSIONS = 2;
26
+ // Unapproved mined lessons expire; approval clears it (store.resolvePatternCandidate).
27
+ const LESSON_TTL_DAYS = 90;
25
28
 
26
29
  function normalizeText(text) {
27
30
  return String(text ?? '').toLowerCase().replace(/\s+/g, ' ').trim();
28
31
  }
29
32
 
33
+ // Keys the rules (and, when staged on, the decision plane) call noise. Downgrade
34
+ // only: nothing here approves a candidate. `result.decision` reports how many
35
+ // real provider answers there were, so a fallback run is distinguishable.
36
+ async function noiseSet(items, { client, stage }, result) {
37
+ const refined = await refineWithDecision(items, { client, stage });
38
+ result.decision = refined.meta;
39
+ return new Set(refined.items.filter((i) => i.cls === 'noise').map((i) => i.key));
40
+ }
41
+
42
+ function errorClass(pattern) {
43
+ if (pattern.timedOut) return 'timed out';
44
+ const code = Array.isArray(pattern.exitCodes) ? pattern.exitCodes.find((c) => c !== 0) : undefined;
45
+ return Number.isInteger(code) ? `exit ${code}` : 'exit unproven';
46
+ }
47
+
48
+ // A lesson must name something concrete: the command it failed on and/or a file.
49
+ // Returns null when there is nothing to say (no candidate is created then).
30
50
  function candidateText(pattern) {
31
- const firstFile = Array.isArray(pattern.files) && pattern.files.length > 0
32
- ? pattern.files[0]
33
- : 'the affected files';
34
- return `Verification pattern "${pattern.signature}" failed ${pattern.count}× across ${pattern.sessions} sessions — check ${firstFile} before retrying.`;
51
+ const files = Array.isArray(pattern.files) ? pattern.files : [];
52
+ const commands = Array.isArray(pattern.commands) ? pattern.commands : [];
53
+ if (files.length === 0 && commands.length === 0) return null;
54
+ const seen = files.length > 0 ? `; seen on ${files.slice(0, 2).join(', ')}` : '';
55
+ return `Command "${pattern.signature}" failed ${pattern.count}× across ${pattern.sessions} sessions (${errorClass(pattern)})${seen}.`;
56
+ }
57
+
58
+ async function fileEvidence(projectRoot, files) {
59
+ const out = [];
60
+ for (const file of (Array.isArray(files) ? files : []).slice(0, 2)) {
61
+ try {
62
+ const abs = path.resolve(projectRoot, file);
63
+ if (abs.startsWith(path.resolve(projectRoot) + path.sep) && (await fs.stat(abs)).isFile()) {
64
+ out.push({ kind: 'file', locator: file });
65
+ }
66
+ } catch { /* missing file: no evidence entry */ }
67
+ }
68
+ return out;
35
69
  }
36
70
 
37
71
  async function loadPatterns(projectRoot) {
@@ -86,6 +120,63 @@ async function knownSignaturesAndTexts(projectRoot, projectId) {
86
120
  return { signatures, texts };
87
121
  }
88
122
 
123
+ /**
124
+ * Propose pending candidates from git re-edit mining (reeditMiner.js).
125
+ * Each lesson names the file and carries `commit:<sha>` evidence. Same
126
+ * contracts as proposeFromPatterns: never throws, dry-run by default, nothing
127
+ * auto-promotes.
128
+ *
129
+ * @param {{ reedits: Array<{file:string, fixes:number, sha:string}>, dryRun?: boolean }} options
130
+ */
131
+ export async function proposeFromReedits(projectRoot, projectId, {
132
+ reedits = [], dryRun = true, client = null, stage = 'off',
133
+ } = {}) {
134
+ const result = { generatedAt: new Date().toISOString(), proposed: [], dryRun };
135
+ try {
136
+ const known = await knownSignaturesAndTexts(projectRoot, projectId);
137
+ const textFor = (r) => `${r.file} needed ${r.fixes} fix commits in the last 90 days (latest ${String(r.sha).slice(0, 7)}); re-read its tests and mirrors before editing.`;
138
+ const valid = (Array.isArray(reedits) ? reedits : []).filter((r) => r?.file && r?.sha);
139
+ const noise = await noiseSet(
140
+ valid.map((r) => ({ key: r.file, text: textFor(r), cls: classifyReedit(r) })),
141
+ { client, stage }, result,
142
+ );
143
+ for (const r of valid) {
144
+ const signature = `reedit:${r.file}`;
145
+ const text = textFor(r);
146
+ if (noise.has(r.file)) {
147
+ result.proposed.push({ signature, text, status: 'skipped' });
148
+ continue;
149
+ }
150
+ if (known.signatures.has(signature)) {
151
+ result.proposed.push({ signature, text, status: 'duplicate' });
152
+ continue;
153
+ }
154
+ if (dryRun) {
155
+ result.proposed.push({ signature, text, status: 'proposed' });
156
+ continue;
157
+ }
158
+ try {
159
+ await proposePatternCandidate(projectRoot, projectId, {
160
+ text,
161
+ category: 'reedit',
162
+ signature,
163
+ detectedFrom: 'git-reedit',
164
+ ttlDays: LESSON_TTL_DAYS,
165
+ evidence: [{ kind: 'command', locator: `commit:${r.sha}` }, ...(await fileEvidence(projectRoot, [r.file]))],
166
+ });
167
+ known.signatures.add(signature);
168
+ result.proposed.push({ signature, text, status: 'proposed' });
169
+ } catch (err) {
170
+ result.proposed.push({ signature, text, status: 'skipped' });
171
+ result.error = err?.message ?? String(err);
172
+ }
173
+ }
174
+ } catch (err) {
175
+ result.error = err?.message ?? String(err);
176
+ }
177
+ return result;
178
+ }
179
+
89
180
  /**
90
181
  * Propose pending pattern-candidates from mined failure patterns.
91
182
  *
@@ -96,7 +187,9 @@ async function knownSignaturesAndTexts(projectRoot, projectId) {
96
187
  * proposed: Array<{signature: string, text: string,
97
188
  * status: 'proposed'|'duplicate'|'skipped'}>, dryRun: boolean, error?: string}>}
98
189
  */
99
- export async function proposeFromPatterns(projectRoot, projectId, { minCount = 3, dryRun = true } = {}) {
190
+ export async function proposeFromPatterns(projectRoot, projectId, {
191
+ minCount = 3, dryRun = true, client = null, stage = 'off',
192
+ } = {}) {
100
193
  const result = {
101
194
  generatedAt: new Date().toISOString(),
102
195
  patternsScanned: 0,
@@ -109,6 +202,12 @@ export async function proposeFromPatterns(projectRoot, projectId, { minCount = 3
109
202
  const patterns = await loadPatterns(projectRoot);
110
203
  result.patternsScanned = patterns.length;
111
204
  const known = await knownSignaturesAndTexts(projectRoot, projectId);
205
+ const noise = await noiseSet(
206
+ patterns.filter((p) => typeof p?.signature === 'string'
207
+ && (Number(p.count) || 0) >= minCount && (Number(p.sessions) || 0) >= MIN_SESSIONS)
208
+ .map((p) => ({ key: p.signature, text: candidateText({ ...p }) ?? '', cls: classifyPattern(p) })),
209
+ { client, stage }, result,
210
+ );
112
211
 
113
212
  for (const pattern of patterns) {
114
213
  const signature = typeof pattern?.signature === 'string' ? pattern.signature : null;
@@ -116,9 +215,12 @@ export async function proposeFromPatterns(projectRoot, projectId, { minCount = 3
116
215
  const sessions = Number(pattern?.sessions) || 0;
117
216
  if (!signature) continue;
118
217
 
119
- const text = candidateText({ signature, count, sessions, files: pattern.files });
218
+ const text = candidateText({
219
+ signature, count, sessions, files: pattern.files, commands: pattern.commands,
220
+ exitCodes: pattern.exitCodes, timedOut: pattern.timedOut,
221
+ });
120
222
  const eligible = count >= minCount && sessions >= MIN_SESSIONS;
121
- if (!eligible) {
223
+ if (!eligible || text === null || noise.has(signature)) {
122
224
  result.proposed.push({ signature, text, status: 'skipped' });
123
225
  continue;
124
226
  }
@@ -140,6 +242,8 @@ export async function proposeFromPatterns(projectRoot, projectId, { minCount = 3
140
242
  category: 'failure-pattern',
141
243
  signature,
142
244
  detectedFrom: 'memory-learn',
245
+ ttlDays: LESSON_TTL_DAYS,
246
+ evidence: await fileEvidence(projectRoot, pattern.files),
143
247
  });
144
248
  known.signatures.add(signature);
145
249
  known.texts.add(normalizeText(text));
@@ -0,0 +1,104 @@
1
+ // reeditMiner.js — git-history miner: files that keep needing fixes.
2
+ //
3
+ // A file touched by >= minFixes "fix" commits inside the window is a repeated
4
+ // correction. The latest fixing sha is the evidence the memory write gate
5
+ // accepts (`commit:<sha>`). Session-end / explicit command only — never call
6
+ // this from a hook path (it spawns git). Degrades to [] when git is absent,
7
+ // the repo is shallow, or git times out. Never throws.
8
+
9
+ import { execFile } from 'node:child_process';
10
+ import fs from 'node:fs/promises';
11
+ import path from 'node:path';
12
+
13
+ const FIX_RE = /^(fix|hotfix)(\(|:|!|\s)/i;
14
+ // Release churn (version files, changelog, docs), generated/live mirrors, manifests,
15
+ // and tests (a test co-changes with the source it covers; the source is the lesson).
16
+ const IGNORE_RE = new RegExp([
17
+ '(^|/)(package\\.json|yarn\\.lock|package-lock\\.json|CHANGELOG\\.md)$',
18
+ '^docs/', '\\.md$', '^\\.ukit/', '^\\.claude/', '^\\.omp/', '^\\.codex/', '^manifests/',
19
+ '^tests?/', '\\.(test|spec)\\.[cm]?[jt]sx?$',
20
+ ].join('|'));
21
+ const MAX_FILES_PER_COMMIT = 25;
22
+ const GIT_TIMEOUT_MS = 5000;
23
+
24
+ export function parseGitLog(raw) {
25
+ const commits = [];
26
+ let cur = null;
27
+ for (const line of String(raw ?? '').split('\n')) {
28
+ if (line.startsWith('C\u0001')) {
29
+ const [, sha, ts, ...subject] = line.split('\u0001');
30
+ cur = { sha, ts: Number(ts), subject: subject.join('\u0001'), files: [] };
31
+ commits.push(cur);
32
+ } else if (cur && line.trim()) {
33
+ cur.files.push(line.trim());
34
+ }
35
+ }
36
+ return commits;
37
+ }
38
+
39
+ /**
40
+ * @param {Array<{sha:string, ts:number, subject:string, files:string[]}>} commits newest first
41
+ * @returns {Array<{file:string, fixes:number, sha:string, shas:string[]}>}
42
+ */
43
+ export function mineReedits(commits, { minFixes = 3 } = {}) {
44
+ if (!Array.isArray(commits)) return [];
45
+ const byFile = new Map();
46
+ for (const c of commits) {
47
+ if (!c || !FIX_RE.test(String(c.subject ?? '')) || !Array.isArray(c.files)) continue;
48
+ if (c.files.length > MAX_FILES_PER_COMMIT) continue;
49
+ for (const file of c.files) {
50
+ if (IGNORE_RE.test(file)) continue;
51
+ const g = byFile.get(file) ?? { file, ts: -Infinity, sha: null, shas: [] };
52
+ g.shas.push(c.sha);
53
+ if (c.ts > g.ts) { g.ts = c.ts; g.sha = c.sha; }
54
+ byFile.set(file, g);
55
+ }
56
+ }
57
+ return [...byFile.values()]
58
+ .filter((g) => g.shas.length >= minFixes)
59
+ .map((g) => ({ file: g.file, fixes: g.shas.length, sha: g.sha, shas: g.shas.slice(0, 5) }))
60
+ .sort((a, b) => b.fixes - a.fixes || a.file.localeCompare(b.file));
61
+ }
62
+
63
+ function git(cwd, args) {
64
+ return new Promise((resolve) => {
65
+ execFile('git', args, { cwd, timeout: GIT_TIMEOUT_MS, maxBuffer: 4 * 1024 * 1024 }, (err, stdout) => {
66
+ resolve(err ? null : String(stdout));
67
+ });
68
+ });
69
+ }
70
+
71
+ export async function readGitCommits(projectRoot, { sinceDays = 90, limit = 400 } = {}) {
72
+ try {
73
+ const shallow = await git(projectRoot, ['rev-parse', '--is-shallow-repository']);
74
+ if (shallow === null || shallow.trim() !== 'false') return [];
75
+ const raw = await git(projectRoot, [
76
+ 'log', `--since=${sinceDays}.days`, '--no-merges', '--name-only', `-n${limit}`,
77
+ '--format=C%x01%H%x01%ct%x01%s',
78
+ ]);
79
+ return raw === null ? [] : parseGitLog(raw);
80
+ } catch {
81
+ return [];
82
+ }
83
+ }
84
+
85
+ /**
86
+ * Deterministic rule: a lesson about a file that is gone is useless, so drop
87
+ * re-edit candidates whose path is not a regular file in the working tree
88
+ * (existence only; renames are not followed). Async, bounded by candidate count.
89
+ */
90
+ export async function dropMissingFiles(projectRoot, reedits) {
91
+ const root = path.resolve(projectRoot);
92
+ const kept = [];
93
+ for (const r of Array.isArray(reedits) ? reedits : []) {
94
+ try {
95
+ const abs = path.resolve(root, String(r?.file ?? ''));
96
+ if (abs.startsWith(root + path.sep) && (await fs.stat(abs)).isFile()) kept.push(r);
97
+ } catch { /* missing or unreadable: dropped */ }
98
+ }
99
+ return kept;
100
+ }
101
+
102
+ export async function mineGitReedits(projectRoot, options = {}) {
103
+ return dropMissingFiles(projectRoot, mineReedits(await readGitCommits(projectRoot, options), options));
104
+ }
@@ -44,6 +44,7 @@ import { collectFeedbackEvents } from '../diagnostics/feedbackEvents.js';
44
44
  import { collectSkillAccuracy } from '../diagnostics/skillAccuracy.js';
45
45
  import { computeTuningSuggestions } from './tuning.js';
46
46
  import { proposeFromPatterns } from './patternProposals.js';
47
+ import { createLessonClient, resolveLessonStage } from './lessonClass.js';
47
48
  import { proposeCodeFixTasks } from './codeProposals.js';
48
49
  import {
49
50
  TUNABLE_KEYS,
@@ -253,10 +254,17 @@ export async function runSelfImprove(projectRoot, {
253
254
  steps.push(await step('proposals', async () => {
254
255
  const projectId = (await detectProjectContext(root, { homeDir })).project.name;
255
256
  const minCount = Number(config?.learning?.proposals?.minCount) || undefined;
256
- const res = await proposeFromPatterns(root, projectId, { minCount, dryRun: false });
257
+ // Session end is an allowed call site for the decision plane; stage off
258
+ // (the default) or an unreachable provider leaves the rule result.
259
+ const stage = resolveLessonStage(config);
260
+ const client = createLessonClient({ config, projectRoot: root, homeDir });
261
+ const res = await proposeFromPatterns(root, projectId, { minCount, dryRun: false, client, stage });
257
262
  return {
258
263
  status: res.error ? 'failed' : 'ok',
259
264
  proposed: res.proposed.filter((p) => p.status === 'proposed').length,
265
+ ...(res.decision && res.decision.stage !== 'off'
266
+ ? { decision: { asked: res.decision.asked, answered: res.decision.answered, changed: res.decision.changed } }
267
+ : {}),
260
268
  reason: res.error,
261
269
  };
262
270
  }));