@groeponline/pi-wishcraft 0.26.0 → 0.27.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * skill-registry.ts
3
3
  * ---------------------------------------------------------------------------
4
- * Data-laag voor de skills manager v2: discovery via pi core's eigen
5
- * `loadSkills()` (recursieve SKILL.md-discovery, loose .md children,
6
- * SourceInfo, diagnostics) plus rijke metadata per skill en een
7
- * usage-ledger. Cache met TTL + expliciete invalidatie (session_start,
8
- * manager-open) zodat nieuwe skills zonder herstart zichtbaar worden.
4
+ * Data layer for skills manager v2: discovery via pi core `loadSkills()`
5
+ * (recursive SKILL.md discovery, loose .md children, SourceInfo,
6
+ * diagnostics) plus rich per-skill metadata and a usage ledger. Cache with
7
+ * TTL + explicit invalidation (session_start, manager-open) so new skills
8
+ * show up without a restart.
9
9
  * ---------------------------------------------------------------------------
10
10
  */
11
11
 
@@ -15,7 +15,7 @@ import { basename, dirname, join, relative } from "node:path";
15
15
  import { getAgentDir, getAgentPath } from "../../paths/agent-dirs.ts";
16
16
  import { parseSkillFrontmatter, stripFrontmatter } from "../../core/frontmatter.ts";
17
17
 
18
- /** Categorie: waar de skill vandaan komt. */
18
+ /** Category: where the skill came from. */
19
19
  export type SkillCategory = "global" | "project" | "prompts" | "extra";
20
20
 
21
21
  export interface SkillUsage {
@@ -28,22 +28,22 @@ export interface SkillEntry {
28
28
  description: string;
29
29
  filePath: string;
30
30
  baseDir: string;
31
- /** Alleen true voor core skills die een eigen skill-directory bezitten. */
31
+ /** True only for core skills that own a skill directory. */
32
32
  isDirectorySkill?: boolean;
33
33
  category: SkillCategory;
34
34
  disableModelInvocation: boolean;
35
35
  sizeBytes: number;
36
36
  lineCount: number;
37
37
  mtimeMs: number;
38
- /** Alle frontmatter-keys (raw, inclusief onbekende). */
38
+ /** All frontmatter keys (raw, including unknown). */
39
39
  frontmatterKeys: string[];
40
- /** Diagnostische melding (core diagnostics, of lege description). */
40
+ /** Diagnostic message (core diagnostics, or empty description). */
41
41
  warning?: string;
42
42
  }
43
43
 
44
- /** Losse .md/.txt in extra-dirs (prompts/legacy) die core weigert (geen
45
- * frontmatter-description). Core-dirs houden core's strenge regels; alleen
46
- * de extra dirs krijgen deze lakse fallback zodat oude prompts blijven werken. */
44
+ /** Loose .md/.txt in extra dirs (prompts/legacy) that core rejects (no
45
+ * frontmatter description). Core dirs keep core's strict rules; only extra
46
+ * dirs get this lax fallback so old prompts keep working. */
47
47
  function scanLooseExtraFiles(
48
48
  extras: { path: string; category: SkillCategory }[],
49
49
  knownPaths: Set<string>,
@@ -82,7 +82,7 @@ function scanLooseExtraFiles(
82
82
  lineCount: content.split("\n").length,
83
83
  mtimeMs,
84
84
  frontmatterKeys: parseFrontmatterKeys(content),
85
- warning: "geen description — model ziet deze skill niet in de prompt",
85
+ warning: "no description — the model will not see this skill in the prompt",
86
86
  });
87
87
  knownPaths.add(filePath);
88
88
  }
@@ -105,7 +105,7 @@ export function setSkillCacheInvalidationHandler(handler: (() => void) | null):
105
105
  const usageCache = new Map<string, SkillUsage>();
106
106
  let usageLoaded = false;
107
107
 
108
- /** Verwijder de discovery-cache (volgende leesactie scant opnieuw). */
108
+ /** Drop the discovery cache (the next read scans again). */
109
109
  export function invalidateSkillCache(): void {
110
110
  cachedAt = 0;
111
111
  cachedEntries = null;
@@ -114,7 +114,7 @@ export function invalidateSkillCache(): void {
114
114
  onCacheInvalidated?.();
115
115
  }
116
116
 
117
- /** Legacy prompts/loose-md dirs die inline-invocation altijd al scanden. */
117
+ /** Legacy prompts/loose-md dirs that inline-invocation already scanned. */
118
118
  function extraSkillPaths(cwd: string): { path: string; category: SkillCategory }[] {
119
119
  const agent = getAgentDir();
120
120
  return [
@@ -144,7 +144,7 @@ function categorize(
144
144
  return "extra";
145
145
  }
146
146
 
147
- /** Parse alle top-level frontmatter-keys (naam + waarde-indicator niet nodig). */
147
+ /** Parse all top-level frontmatter keys (name only; value is unused). */
148
148
  function parseFrontmatterKeys(content: string): string[] {
149
149
  const lines = content.split("\n");
150
150
  if (lines[0]?.trim() !== "---") return [];
@@ -275,10 +275,10 @@ export function loadSkillCatalog(cwd: string = process.cwd()): SkillEntry[] {
275
275
  lineCount = content.split("\n").length;
276
276
  mtimeMs = statSync(s.filePath).mtimeMs;
277
277
  } catch {
278
- warning = "bestand niet leesbaar";
278
+ warning = "file not readable";
279
279
  }
280
280
  if (!warning && !s.description.trim()) {
281
- warning = "geen description — model ziet deze skill niet in de prompt";
281
+ warning = "no description — the model will not see this skill in the prompt";
282
282
  }
283
283
  if (!warning && s.filePath && diagByPath.has(s.filePath)) {
284
284
  warning = diagByPath.get(s.filePath);
@@ -299,7 +299,7 @@ export function loadSkillCatalog(cwd: string = process.cwd()): SkillEntry[] {
299
299
  };
300
300
  });
301
301
 
302
- // loose entries achteraan; bij naam-collisie wint core
302
+ // loose entries last; on a name collision core wins
303
303
  const looseNames = new Set(loose.map((e) => e.name));
304
304
  const catalogPaths = new Set([
305
305
  ...entries.map((e) => e.filePath),
@@ -322,7 +322,7 @@ export function loadSkillCatalog(cwd: string = process.cwd()): SkillEntry[] {
322
322
  return cachedEntries;
323
323
  }
324
324
 
325
- /** Compat: naam → bestandspad (voor inline-invocation). */
325
+ /** Compat: name → file path (for inline-invocation). */
326
326
  export function getAvailableSkills(): Map<string, string> {
327
327
  loadSkillCatalog();
328
328
  return cachedPathMap ?? new Map();
@@ -346,11 +346,11 @@ function loadUsage(): void {
346
346
  usageCache.set(name, { count: u.count ?? 0, lastUsed: u.lastUsed ?? 0 });
347
347
  }
348
348
  } catch {
349
- // geen bestand of kapot JSON → lege ledger
349
+ // missing file or broken JSON → empty ledger
350
350
  }
351
351
  }
352
352
 
353
- /** Usage voor alle skills (naam → {count, lastUsed}). */
353
+ /** Usage for every skill (name → {count, lastUsed}). */
354
354
  export function getSkillUsage(): Map<string, SkillUsage> {
355
355
  loadUsage();
356
356
  return usageCache;
@@ -359,7 +359,7 @@ export function getSkillUsage(): Map<string, SkillUsage> {
359
359
  let usageFlushTimer: ReturnType<typeof setTimeout> | null = null;
360
360
  let exitFlushRegistered = false;
361
361
 
362
- /** Schrijf de ledger nu naar schijf (best-effort, sync). */
362
+ /** Write the ledger to disk now (best-effort, sync). */
363
363
  export function flushSkillUsage(): void {
364
364
  if (usageFlushTimer) {
365
365
  clearTimeout(usageFlushTimer);
@@ -371,14 +371,14 @@ export function flushSkillUsage(): void {
371
371
  mkdirSync(getAgentDir(), { recursive: true });
372
372
  writeFileSync(usageFile(), JSON.stringify(obj, null, 2), "utf8");
373
373
  } catch {
374
- // best-effort: tracking mag de hot path nooit breken
374
+ // best-effort: tracking must never break the hot path
375
375
  }
376
376
  }
377
377
 
378
378
  /**
379
- * Log een skill-gebruik. De in-memory ledger wordt meteen bijgewerkt (zodat
380
- * getSkillUsage() klopt), maar de schijf-write wordt gedebounced zodat de
381
- * input hot path niet per keystroke een sync writeFileSync doet.
379
+ * Log a skill use. The in-memory ledger updates immediately (so
380
+ * getSkillUsage() is correct), but the disk write is debounced so the
381
+ * input hot path does not do a sync writeFileSync per keystroke.
382
382
  */
383
383
  export function recordSkillUsage(name: string): void {
384
384
  loadUsage();
@@ -407,6 +407,25 @@ export function readSkillBody(path: string): string {
407
407
  }
408
408
  }
409
409
 
410
+ export function readSkillBodyStrict(path: string): string {
411
+ return stripFrontmatter(readFileSync(path, "utf8")).trim();
412
+ }
413
+
414
+ export function insertSkillBody(
415
+ ctx: any,
416
+ skillName: string,
417
+ body: string,
418
+ appendedText = "",
419
+ ): void {
420
+ const chunk = appendedText.trim()
421
+ ? `${body.trim()}\n\n${appendedText.trim()}`
422
+ : body.trim();
423
+ const current = ctx.ui.getEditorText?.() ?? "";
424
+ const separator = current && !current.endsWith("\n") ? "\n\n" : "";
425
+ ctx.ui.setEditorText(`${current}${separator}${chunk}\n`);
426
+ recordSkillUsage(skillName);
427
+ }
428
+
410
429
  /** Compat-export: catalogus als ouderwets SkillInfo[] (manager v1 API). */
411
430
  export function listSkills(): { name: string; description: string; path: string; source: string }[] {
412
431
  return loadSkillCatalog().map((e) => ({
@@ -417,7 +436,7 @@ export function listSkills(): { name: string; description: string; path: string;
417
436
  }));
418
437
  }
419
438
 
420
- /** Pure filter/sorteer-logica voor de manager-lijst (testbaar zonder TUI). */
439
+ /** Pure filter/sort for the manager list (testable without a TUI). */
421
440
  export function applySkillFilter(
422
441
  entries: SkillEntry[],
423
442
  query: string,
@@ -84,7 +84,7 @@ function listForQuery(
84
84
  ? filtered
85
85
  : [
86
86
  {
87
- label: `geen match voor '${query}'`,
87
+ label: `no match for '${query}'`,
88
88
  value: NONE_VALUE,
89
89
  },
90
90
  ];
@@ -9,6 +9,7 @@ import { estimateInitialContextTokens } from "../../usage/context.ts";
9
9
  import { isRecord } from "../settings/settings-io.ts";
10
10
  import type { RuntimeState } from "../core/types.ts";
11
11
  import { getQueueContext } from "../queue/queue-context.ts";
12
+ import { pickNextReviewIdea } from "../queue/idea-review.ts";
12
13
 
13
14
  export function setupWelcomeHeader(rt: RuntimeState, ctx: any) {
14
15
  const modelName = ctx.model?.name || ctx.model?.id || "No model";
@@ -20,6 +21,9 @@ export function setupWelcomeHeader(rt: RuntimeState, ctx: any) {
20
21
  const queueCount = queueSummary.queueCount + queueSummary.ideaCount;
21
22
  const hasStash =
22
23
  rt.stashedEditorText !== null || rt.stashedPromptHistory.length > 0;
24
+ const nextIdeaText = pickNextReviewIdea(
25
+ rt.queueStore.activeItems(getQueueContext(ctx)),
26
+ )?.text;
23
27
  const whatsNew = discoverWhatsNew();
24
28
 
25
29
  const header = new WelcomeHeader(
@@ -31,6 +35,7 @@ export function setupWelcomeHeader(rt: RuntimeState, ctx: any) {
31
35
  queueCount,
32
36
  hasStash,
33
37
  whatsNew,
38
+ nextIdeaText,
34
39
  );
35
40
  rt.welcomeHeaderActive = true;
36
41
 
@@ -86,6 +91,9 @@ export function setupWelcomeOverlay(rt: RuntimeState, ctx: any) {
86
91
  const queueCount = queueSummary.queueCount + queueSummary.ideaCount;
87
92
  const hasStash =
88
93
  rt.stashedEditorText !== null || rt.stashedPromptHistory.length > 0;
94
+ const nextIdeaText = pickNextReviewIdea(
95
+ rt.queueStore.activeItems(getQueueContext(ctx)),
96
+ )?.text;
89
97
  const whatsNew = discoverWhatsNew();
90
98
 
91
99
  ctx.ui
@@ -105,6 +113,7 @@ export function setupWelcomeOverlay(rt: RuntimeState, ctx: any) {
105
113
  queueCount,
106
114
  hasStash,
107
115
  whatsNew,
116
+ nextIdeaText,
108
117
  );
109
118
 
110
119
  let countdown = 30;
@@ -24,6 +24,7 @@ export class WelcomeHeader implements Component {
24
24
  queueCount?: number,
25
25
  hasStash?: boolean,
26
26
  whatsNew?: string[],
27
+ nextIdeaText?: string,
27
28
  ) {
28
29
  this.data = {
29
30
  modelName,
@@ -34,6 +35,7 @@ export class WelcomeHeader implements Component {
34
35
  queueCount,
35
36
  hasStash,
36
37
  whatsNew,
38
+ nextIdeaText,
37
39
  };
38
40
  }
39
41
 
@@ -30,6 +30,7 @@ export class WelcomeComponent implements Component {
30
30
  queueCount?: number,
31
31
  hasStash?: boolean,
32
32
  whatsNew?: string[],
33
+ nextIdeaText?: string,
33
34
  ) {
34
35
  this.data = {
35
36
  modelName,
@@ -40,6 +41,7 @@ export class WelcomeComponent implements Component {
40
41
  queueCount,
41
42
  hasStash,
42
43
  whatsNew,
44
+ nextIdeaText,
43
45
  };
44
46
  }
45
47
 
@@ -18,6 +18,7 @@ export interface WelcomeData {
18
18
  initialContextTokens: number | null;
19
19
  queueCount?: number;
20
20
  hasStash?: boolean;
21
+ nextIdeaText?: string;
21
22
  whatsNew?: string[];
22
23
  }
23
24
 
@@ -5,9 +5,19 @@ export const QueueWidget: WelcomeWidget = {
5
5
  render(ctx: WidgetRenderContext): string[] {
6
6
  const { data, dim, color } = ctx;
7
7
  const lines: string[] = [];
8
-
8
+
9
9
  const prefix = dim("- ");
10
- if (data.queueCount && data.queueCount > 0) {
10
+ const idea = data.nextIdeaText?.trim();
11
+ if (idea) {
12
+ const singleLine = idea.replace(/\s+/g, " ");
13
+ const budget = Math.max(1, ctx.width - prefix.length - 3 - "/ideas next".length - 2);
14
+ const preview = singleLine.length > budget
15
+ ? `${singleLine.slice(0, Math.max(0, budget - 1))}…`
16
+ : singleLine;
17
+ lines.push(
18
+ ` ${prefix}${color("gitClean", preview)} · ${color("model", "/ideas next")}`,
19
+ );
20
+ } else if (data.queueCount && data.queueCount > 0) {
11
21
  lines.push(` ${prefix}${color("gitClean", `${data.queueCount}`)} queued items ready`);
12
22
  } else {
13
23
  lines.push(` ${prefix}type ${color("model", "# <idea>")} to capture a thought`);
@@ -20,7 +30,7 @@ export const QueueWidget: WelcomeWidget = {
20
30
  }
21
31
 
22
32
  lines.push(` ${prefix}${dim("dreaming & mission queue ready")}`);
23
-
33
+
24
34
  return lines;
25
35
  }
26
36
  };