@ngockhoale/ukit 3.5.4 → 3.5.6

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 (68) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/manifests/engineConformance.yaml +0 -13
  3. package/manifests/platform.full.yaml +25 -0
  4. package/package.json +3 -9
  5. package/src/cli/commands/indexTools.js +1 -0
  6. package/src/cli/commands/memory.js +44 -4
  7. package/src/core/applyPlan.js +25 -72
  8. package/src/core/diffPlan.js +38 -9
  9. package/src/core/managedTemplateMerge.js +146 -0
  10. package/src/core/memory/memoryCheckRun.js +13 -1
  11. package/src/core/memory/memoryFlags.js +5 -6
  12. package/src/core/memory/memoryHit.js +31 -15
  13. package/src/core/memory/policy.js +5 -0
  14. package/src/core/memory/recallEngine.js +39 -3
  15. package/src/core/memory/recallLanes.js +182 -0
  16. package/src/core/memory/retrieval.js +13 -1
  17. package/src/core/memory/store.js +17 -0
  18. package/src/core/memory/topicCommand.js +75 -0
  19. package/src/core/memory/topicPages.js +545 -0
  20. package/src/core/metadata.js +12 -8
  21. package/src/core/runInstallPipeline.js +16 -10
  22. package/src/core/runtimeConfig.js +59 -83
  23. package/src/core/uninstall.js +8 -1
  24. package/src/decision/registry.js +33 -16
  25. package/src/decision/runtimeDecide.js +5 -5
  26. package/src/index/buildIndex.js +287 -6
  27. package/src/index/languageTools.js +100 -0
  28. package/src/index/paths.js +2 -1
  29. package/src/index/queryIndex.js +174 -10
  30. package/src/index/routeResolver.js +2 -2
  31. package/src/index/semanticLane.js +269 -0
  32. package/src/learning/lessonClass.js +110 -0
  33. package/src/learning/patternProposals.js +111 -7
  34. package/src/learning/reeditMiner.js +104 -0
  35. package/src/learning/selfImprove.js +9 -1
  36. package/template_project/.claude/skills/canvas-design/SKILL.md +2 -2
  37. package/template_project/.claude/skills/canvas-design/canvas-fonts/{InstrumentSans-OFL.txt → InstrumentSerif-OFL.txt} +3 -3
  38. package/template_project/.claude/skills/canvas-design/scripts/fetch-fonts.mjs +148 -0
  39. package/template_project/.claude/ukit/index/embed-index.mjs +26 -0
  40. package/template_project/.claude/ukit/index/lib/index-core.mjs +561 -14
  41. package/template_project/.claude/ukit/index/lib/semantic-lane.mjs +269 -0
  42. package/template_project/.claude/ukit/index/query-index.mjs +9 -1
  43. package/template_project/.claude/ukit/index/refresh-index.mjs +11 -0
  44. package/template_project/.claude/ukit/index/route-resolver.mjs +2 -2
  45. package/template_project/.claude/ukit/runtime/memory-lanes.mjs +9 -2
  46. package/template_project/.claude/ukit/runtime/memory-policy.mjs +5 -0
  47. package/template_project/.claude/ukit/runtime/memory-recall.mjs +39 -3
  48. package/template_project/.claude/ukit/runtime/memory-topics.mjs +545 -0
  49. package/template_project/ukit/storage/config.json +19 -34
  50. package/manifests/instructionRules.yaml +0 -442
  51. package/template_project/.claude/skills/canvas-design/canvas-fonts/BricolageGrotesque-Bold.ttf +0 -0
  52. package/template_project/.claude/skills/canvas-design/canvas-fonts/BricolageGrotesque-OFL.txt +0 -93
  53. package/template_project/.claude/skills/canvas-design/canvas-fonts/BricolageGrotesque-Regular.ttf +0 -0
  54. package/template_project/.claude/skills/canvas-design/canvas-fonts/InstrumentSans-Bold.ttf +0 -0
  55. package/template_project/.claude/skills/canvas-design/canvas-fonts/InstrumentSans-BoldItalic.ttf +0 -0
  56. package/template_project/.claude/skills/canvas-design/canvas-fonts/InstrumentSans-Italic.ttf +0 -0
  57. package/template_project/.claude/skills/canvas-design/canvas-fonts/InstrumentSans-Regular.ttf +0 -0
  58. package/template_project/.claude/skills/canvas-design/canvas-fonts/InstrumentSerif-Italic.ttf +0 -0
  59. package/template_project/.claude/skills/canvas-design/canvas-fonts/JetBrainsMono-Bold.ttf +0 -0
  60. package/template_project/.claude/skills/canvas-design/canvas-fonts/Lora-Bold.ttf +0 -0
  61. package/template_project/.claude/skills/canvas-design/canvas-fonts/Lora-BoldItalic.ttf +0 -0
  62. package/template_project/.claude/skills/canvas-design/canvas-fonts/Lora-Italic.ttf +0 -0
  63. package/template_project/.claude/skills/canvas-design/canvas-fonts/Lora-OFL.txt +0 -93
  64. package/template_project/.claude/skills/canvas-design/canvas-fonts/Lora-Regular.ttf +0 -0
  65. package/template_project/.claude/skills/canvas-design/canvas-fonts/Outfit-Bold.ttf +0 -0
  66. package/template_project/.claude/skills/canvas-design/canvas-fonts/Tektur-Medium.ttf +0 -0
  67. package/template_project/.claude/skills/canvas-design/canvas-fonts/YoungSerif-OFL.txt +0 -93
  68. 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
  }));
@@ -87,9 +87,9 @@ With both the philosophy and the conceptual framework established, express it on
87
87
 
88
88
  To create museum or magazine quality work, use the design philosophy as the foundation. Create one single page, highly visual, design-forward PDF or PNG output (unless asked for more pages). Generally use repeating patterns and perfect shapes. Treat the abstract philosophical design as if it were a scientific bible, borrowing the visual language of systematic observation—dense accumulation of marks, repeated elements, or layered patterns that build meaning through patient repetition and reward sustained viewing. Add sparse, clinical typography and systematic reference markers that suggest this could be a diagram from an imaginary discipline, treating the invisible subject with the same reverence typically reserved for documenting observable phenomena. Anchor the piece with simple phrase(s) or details positioned subtly, using a limited color palette that feels intentional and cohesive. Embrace the paradox of using analytical visual language to express ideas about human experience: the result should feel like an artifact that proves something ephemeral can be studied, mapped, and understood through careful attention. This is true art.
89
89
 
90
- **Text as a contextual element**: Text is always minimal and visual-first, but let context guide whether that means whisper-quiet labels or bold typographic gestures. A punk venue poster might have larger, more aggressive type than a minimalist ceramics studio identity. Most of the time, font should be thin. All use of fonts must be design-forward and prioritize visual communication. Regardless of text scale, nothing falls off the page and nothing overlaps. Every element must be contained within the canvas boundaries with proper margins. Check carefully that all text, graphics, and visual elements have breathing room and clear separation. This is non-negotiable for professional execution. **IMPORTANT: Use different fonts if writing text. Start with the curated built-in font set in `./canvas-fonts` (sans, serif, mono, display, script). Only widen beyond that when the task truly needs it. Regardless of approach, sophistication is non-negotiable.**
90
+ **Text as a contextual element**: Text is always minimal and visual-first, but let context guide whether that means whisper-quiet labels or bold typographic gestures. A punk venue poster might have larger, more aggressive type than a minimalist ceramics studio identity. Most of the time, font should be thin. All use of fonts must be design-forward and prioritize visual communication. Regardless of text scale, nothing falls off the page and nothing overlaps. Every element must be contained within the canvas boundaries with proper margins. Check carefully that all text, graphics, and visual elements have breathing room and clear separation. This is non-negotiable for professional execution. **IMPORTANT: Use different fonts if writing text. Start with the curated built-in font set in `./canvas-fonts`: Outfit (sans), Instrument Serif (serif), JetBrains Mono (mono), Tektur (display), Nothing You Could Do (script). Only widen beyond that when the task truly needs it: more faces (Bricolage Grotesque, Instrument Sans, Lora, Young Serif, plus bold/italic variable files) can be downloaded with `node ./scripts/fetch-fonts.mjs --list` / `node ./scripts/fetch-fonts.mjs <Family>` when the network is available. Regardless of approach, sophistication is non-negotiable.**
91
91
 
92
- Prefer the bundled curated font set first so the skill stays fast, portable, and production-friendly after a simple install. Get creative by making the typography actually part of the art itself -- if the art is abstract, bring the font onto the canvas, not typeset digitally.
92
+ Prefer the bundled curated font set first so the skill stays fast, portable, and production-friendly after a simple install; if the network is unavailable, stay with the bundled faces. Get creative by making the typography actually part of the art itself -- if the art is abstract, bring the font onto the canvas, not typeset digitally.
93
93
 
94
94
  To push boundaries, follow design instinct/intuition while using the philosophy as a guiding principle. Embrace ultimate design freedom and choice. Push aesthetics and design to the frontier.
95
95
 
@@ -1,8 +1,8 @@
1
- Copyright 2022 The Instrument Sans Project Authors (https://github.com/Instrument/instrument-sans)
1
+ Copyright 2022 The Instrument Serif Project Authors (https://github.com/Instrument/instrument-serif)
2
2
 
3
3
  This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
4
  This license is copied below, and is also available with a FAQ at:
5
- https://openfontlicense.org
5
+ https://scripts.sil.org/OFL
6
6
 
7
7
 
8
8
  -----------------------------------------------------------
@@ -18,7 +18,7 @@ with others.
18
18
 
19
19
  The OFL allows the licensed fonts to be used, studied, modified and
20
20
  redistributed freely as long as they are not sold by themselves. The
21
- fonts, including any derivative works, can be bundled, embedded,
21
+ fonts, including any derivative works, can be bundled, embedded,
22
22
  redistributed and/or sold with any software provided that any reserved
23
23
  names are not used by derivative works. The fonts and derivatives,
24
24
  however, cannot be released under any other type of license. The
@@ -0,0 +1,148 @@
1
+ #!/usr/bin/env node
2
+ // Fetch optional canvas-design fonts on demand (dependency-free, OFL fonts only).
3
+ // Usage: node fetch-fonts.mjs --list | --all | <Family> [<Family> ...]
4
+ // Source: google/fonts at a pinned commit (immutable raw URLs). Every file is
5
+ // SHA-256 verified before it is written into ../canvas-fonts/.
6
+ import { createHash } from 'node:crypto';
7
+ import { mkdir, rename, writeFile, access, unlink } from 'node:fs/promises';
8
+ import path from 'node:path';
9
+ import { fileURLToPath } from 'node:url';
10
+
11
+ export const PINNED_SHA = 'cc39c4c2c304bc368c9b7c311ea2bcc6013299fe';
12
+ export const REQUEST_TIMEOUT_MS = 30_000;
13
+ const RAW = `https://raw.githubusercontent.com/google/fonts/${PINNED_SHA}/ofl`;
14
+
15
+ const url = (dir, file) =>
16
+ `${RAW}/${dir}/${file.replace(/\[/g, '%5B').replace(/\]/g, '%5D').replace(/,/g, '%2C')}`;
17
+
18
+ // local = file name written into canvas-fonts/. Variable fonts cover all weights.
19
+ const FAMILIES = {
20
+ BricolageGrotesque: {
21
+ dir: 'bricolagegrotesque',
22
+ licenseSha256: '4b5a7d8f37f5602621c8a8d7358a6a2e71317e6c231c661e15aef0275d3e07ba',
23
+ files: [{ local: 'BricolageGrotesque-Variable.ttf', remote: 'BricolageGrotesque[opsz,wdth,wght].ttf', sha256: '413e7357809ddd12fd80a96a8a396de0e401638d4acd3cb3e37532f0472ac682' }],
24
+ },
25
+ InstrumentSans: {
26
+ dir: 'instrumentsans',
27
+ licenseSha256: '9e27a72ed30eb49a08678f6a5d6ed98ec7ba5368f541637ee0683ec9134ef966',
28
+ files: [
29
+ { local: 'InstrumentSans-Variable.ttf', remote: 'InstrumentSans[wdth,wght].ttf', sha256: 'b24f1812584816958afcf22e22d08e44318c5e51651e25d2438efdde389b33b1' },
30
+ { local: 'InstrumentSans-Italic-Variable.ttf', remote: 'InstrumentSans-Italic[wdth,wght].ttf', sha256: 'a74203cc5066a3b2f8de1a7b0887ef897773c2319dc86c911f8e85350cde0d07' },
31
+ ],
32
+ },
33
+ InstrumentSerif: {
34
+ dir: 'instrumentserif',
35
+ licenseSha256: '129ed7618959716959f2941fdd5b49e0ad6e6c1d78726761786a00253d865521',
36
+ files: [{ local: 'InstrumentSerif-Italic.ttf', remote: 'InstrumentSerif-Italic.ttf', sha256: '08939b8bdf534afec24ae0ef5e03f948940cd9a8fe08e7fecbad040e62327385' }],
37
+ },
38
+ JetBrainsMono: {
39
+ dir: 'jetbrainsmono',
40
+ licenseSha256: 'b2fe5e8987594e9ffd1d2ca52a2f5d73eb8335243893c5d6254b5ad69269591d',
41
+ files: [
42
+ { local: 'JetBrainsMono-Variable.ttf', remote: 'JetBrainsMono[wght].ttf', sha256: '48715a42ec242c21e9f02692891e147d022299a52e48d5e413e1a942193ffeda' },
43
+ { local: 'JetBrainsMono-Italic-Variable.ttf', remote: 'JetBrainsMono-Italic[wght].ttf', sha256: '85ae2a5cd3f56baf1ce1c21a851322c58e3d8fbe8e8ad4a4d090a820dd7fe558' },
44
+ ],
45
+ },
46
+ Lora: {
47
+ dir: 'lora',
48
+ licenseSha256: '1d9a970809ac804b582a6ce7f0ebc4e7fefcbfd7ff6299cad35ee656a21be716',
49
+ files: [
50
+ { local: 'Lora-Variable.ttf', remote: 'Lora[wght].ttf', sha256: '822a6621ccbe8d97d20ac88c1c41f5615c9c2c202eaa75f272cd452aac6475a7' },
51
+ { local: 'Lora-Italic-Variable.ttf', remote: 'Lora-Italic[wght].ttf', sha256: '22d8d8854b53807aa664ca34f2031a9ed57a1d0dea296b8b96cdd3aad937a2b3' },
52
+ ],
53
+ },
54
+ Outfit: {
55
+ dir: 'outfit',
56
+ licenseSha256: 'c676351bf8576b9aba743cd5eaa8c0e7ee0d51f805d720447b4df4ddb6a2e416',
57
+ files: [{ local: 'Outfit-Variable.ttf', remote: 'Outfit[wght].ttf', sha256: 'fc7287273e66929776e2ba54f144fe699080bec29f61bf649d70d871468aeade' }],
58
+ },
59
+ Tektur: {
60
+ dir: 'tektur',
61
+ licenseSha256: 'ff4bb37f716836feb5038e1bf5c47e5a1946717fcfabb175086ed49f85ea47fd',
62
+ files: [{ local: 'Tektur-Variable.ttf', remote: 'Tektur[wdth,wght].ttf', sha256: 'a4c451e5336874811267c2a514efa09bca7bc8cabf32a310f0b44e111eacb933' }],
63
+ },
64
+ YoungSerif: {
65
+ dir: 'youngserif',
66
+ licenseSha256: '737d8d343b674c6894f373de71a044b6782c130f2aebf180933d63ddf7a3dc19',
67
+ files: [{ local: 'YoungSerif-Regular.ttf', remote: 'YoungSerif-Regular.ttf', sha256: '42bb2602364b28569fdce5eeb6ab3d81cf8090ba81b211f1229ed69f33155523' }],
68
+ },
69
+ };
70
+
71
+ /** Flat manifest: [{ family, local, url, sha256, license }] */
72
+ export function buildManifest() {
73
+ const out = [];
74
+ for (const [family, def] of Object.entries(FAMILIES)) {
75
+ for (const f of def.files) {
76
+ out.push({ family, local: f.local, url: url(def.dir, f.remote), sha256: f.sha256, license: false });
77
+ }
78
+ out.push({ family, local: `${family}-OFL.txt`, url: url(def.dir, 'OFL.txt'), sha256: def.licenseSha256, license: true });
79
+ }
80
+ return out;
81
+ }
82
+
83
+ export function familyNames() {
84
+ return Object.keys(FAMILIES);
85
+ }
86
+
87
+ /** Resolve a local name inside fontsDir; throws if it would escape. */
88
+ export function safeTarget(fontsDir, local) {
89
+ const root = path.resolve(fontsDir);
90
+ const target = path.resolve(root, local);
91
+ if (path.dirname(target) !== root || local !== path.basename(local)) {
92
+ throw new Error(`refusing to write outside canvas-fonts: ${local}`);
93
+ }
94
+ return target;
95
+ }
96
+
97
+ async function download(u) {
98
+ const res = await fetch(u, { signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS), redirect: 'follow' });
99
+ if (!res.ok) throw new Error(`HTTP ${res.status} for ${u}`);
100
+ return Buffer.from(await res.arrayBuffer());
101
+ }
102
+
103
+ async function exists(p) {
104
+ try { await access(p); return true; } catch { return false; }
105
+ }
106
+
107
+ async function main(argv) {
108
+ const here = path.dirname(fileURLToPath(import.meta.url));
109
+ const fontsDir = path.resolve(here, '..', 'canvas-fonts');
110
+ const names = familyNames();
111
+ if (argv.includes('--list') || argv.length === 0) {
112
+ console.log('Available families (OFL, google/fonts @ ' + PINNED_SHA.slice(0, 12) + '):\n ' + names.join('\n '));
113
+ console.log('\nUsage: node fetch-fonts.mjs <Family...> | --all');
114
+ return 0;
115
+ }
116
+ const wanted = argv.includes('--all') ? names : argv;
117
+ const unknown = wanted.filter((n) => !names.includes(n));
118
+ if (unknown.length) {
119
+ console.error(`Unknown family: ${unknown.join(', ')}. Use --list.`);
120
+ return 1;
121
+ }
122
+ await mkdir(fontsDir, { recursive: true });
123
+ for (const entry of buildManifest().filter((e) => wanted.includes(e.family))) {
124
+ const target = safeTarget(fontsDir, entry.local);
125
+ // Keep an already bundled licence file; it is the same OFL family text.
126
+ if (entry.license && (await exists(target))) continue;
127
+ const data = await download(entry.url);
128
+ const got = createHash('sha256').update(data).digest('hex');
129
+ if (got !== entry.sha256) throw new Error(`SHA-256 mismatch for ${entry.local}: expected ${entry.sha256}, got ${got}`);
130
+ const tmp = `${target}.${process.pid}.tmp`;
131
+ try {
132
+ await writeFile(tmp, data);
133
+ await rename(tmp, target);
134
+ } catch (err) {
135
+ await unlink(tmp).catch(() => {});
136
+ throw err;
137
+ }
138
+ console.log(`fetched ${entry.local}`);
139
+ }
140
+ return 0;
141
+ }
142
+
143
+ if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
144
+ main(process.argv.slice(2)).then(
145
+ (code) => process.exit(code),
146
+ (err) => { console.error(`fetch-fonts failed: ${err.message}`); process.exit(1); },
147
+ );
148
+ }
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+ // Explicit, opt-in step: embed one short descriptor per indexed file through UKIT_INDEX_EMBED_URL
3
+ // (OpenAI-compatible /v1/embeddings). PRIVACY: this sends file text (path, symbol names, leading
4
+ // comment; at most ~240 characters per file) to that endpoint. Never part of index build/refresh
5
+ // and never run from a hook. Usage: node .claude/ukit/index/embed-index.mjs [--dims N] [--root DIR]
6
+ import path from 'node:path';
7
+ import { buildSemanticVectors, embedConfig } from './lib/semantic-lane.mjs';
8
+
9
+ const args = process.argv.slice(2);
10
+ const flag = (name, fallback) => {
11
+ const i = args.indexOf(name);
12
+ return i >= 0 && args[i + 1] ? args[i + 1] : fallback;
13
+ };
14
+ try {
15
+ const cfg = embedConfig();
16
+ if (cfg) console.log(`[ukit:index:embed] sending file descriptors (path, symbols, leading comment) to ${new URL(cfg.url).host}`);
17
+ const started = Date.now();
18
+ const result = await buildSemanticVectors({
19
+ rootDir: path.resolve(flag('--root', process.cwd())),
20
+ dims: Number.parseInt(flag('--dims', '0'), 10) || 0,
21
+ });
22
+ console.log(`[ukit:index:embed] ${result.embedded} embedded, ${result.reused} reused, ${result.files} files, dims=${result.dims}, ${result.bytes} bytes, ${Date.now() - started} ms`);
23
+ } catch (error) {
24
+ console.error(`[ukit:index:embed] ${error && error.message ? error.message : error}`);
25
+ process.exitCode = 1;
26
+ }