@lebronj/pi-suite 0.1.7 → 0.1.8

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/README.md CHANGED
@@ -15,7 +15,7 @@ pi install npm:pi-subagents
15
15
  Or use the bootstrap script to install Pi, configure the team OpenAI-compatible endpoint, install this suite, and set up Bun + qmd for memory search:
16
16
 
17
17
  ```bash
18
- curl -fsSL https://registry.npmjs.org/@lebronj/pi-suite/-/pi-suite-0.1.7.tgz | tar -xzO package/scripts/bootstrap.sh | bash
18
+ curl -fsSL https://registry.npmjs.org/@lebronj/pi-suite/-/pi-suite-0.1.8.tgz | tar -xzO package/scripts/bootstrap.sh | bash
19
19
  ```
20
20
 
21
21
  ## What Is Included
@@ -67,7 +67,7 @@ qmd collection add ~/.pi/agent/memory --name pi-memory
67
67
  qmd embed
68
68
  ```
69
69
 
70
- Memory versioning is enabled by default. It snapshots `~/.pi/agent/memory` and `~/.pi/agent/skill-drafts` into `~/.pi/agent/evolution`, commits local changes automatically, and leaves push manual by default.
70
+ Memory versioning is enabled by default. It snapshots `~/.pi/agent/memory` and `~/.pi/agent/skill-drafts` into `~/.pi/agent/evolution`, commits local changes automatically, and leaves push manual by default. `memory_curate` also scans yesterday's daily log into `REVIEW.md` when learning is enabled and the daily file changed since the last scan.
71
71
 
72
72
  Useful commands:
73
73
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lebronj/pi-suite",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "JHP's Pi extension suite for team coding workflows",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -46,7 +46,7 @@ Memory tools:
46
46
  - `memory_edit`: read/add/replace/remove/replace_all/compact structured entries in `MEMORY.md`, `USER.md`, `STATE.md`, and `REVIEW.md`.
47
47
  - `scratchpad`: add/done/undo/clear/list checklist items.
48
48
  - `memory_search`: qmd-backed keyword, semantic, or deep search across memory files.
49
- - `memory_curate`: manually run curator lifecycle rules.
49
+ - `memory_curate`: manually run curator lifecycle rules and scan yesterday's daily log into `REVIEW.md` when learning is enabled.
50
50
  - `memory_learning_approve`: approve a proposed memory promotion or disabled skill draft by exact id.
51
51
  - `memory_learning_reject`: reject or archive a review candidate/proposal without deleting it.
52
52
  - `memory_skill_drafts`: list proposed skill drafts.
@@ -74,6 +74,7 @@ Curator and learning behavior:
74
74
  - Quotas reset when `month` or `reset` rolls over.
75
75
  - Mutations are audited to `audit/curator.jsonl`.
76
76
  - Session shutdown may extract conservative learning candidates into `REVIEW.md`; they are not injected as normal memory and are not auto-enabled.
77
+ - `memory_curate` scans yesterday's daily log once per content hash into review candidates, then curator lifecycle and proposal rules process those candidates.
77
78
  - Repeated candidates can become proposed memory promotions or proposed disabled skill drafts after `memory_curate`.
78
79
  - Approval is explicit by default: memory proposals write to memory stores; skill proposals write disabled drafts under `~/.pi/agent/skill-drafts/`.
79
80
  - The curator avoids semantic auto-delete/merge; ambiguous learning stays in review first.
@@ -196,7 +196,7 @@ Pi-memory mirrors the authoritative runtime directories into a local evolution r
196
196
 
197
197
  Authoritative runtime data remains `~/.pi/agent/memory` and `~/.pi/agent/skill-drafts`; `~/.pi/agent/evolution` is a versioned mirror and backup repo.
198
198
 
199
- Automatic hooks snapshot before and sync/commit after `memory_write`, mutating `memory_edit`, mutating `scratchpad`, `memory_curate`, learning approve/reject, session summary/handoff writes, compaction handoffs, and external `jhp-pi-memory-curator run-once`. Read-only operations do not snapshot.
199
+ Automatic hooks snapshot before and sync/commit after `memory_write`, mutating `memory_edit`, mutating `scratchpad`, `memory_curate`, learning approve/reject, session summary/handoff writes, compaction handoffs, and external `jhp-pi-memory-curator run-once`. `memory_curate` also scans yesterday's daily log into `REVIEW.md` when learning is enabled and that daily file changed since the last scan. Read-only operations do not snapshot.
200
200
 
201
201
  Tools and slash commands:
202
202
 
@@ -242,7 +242,7 @@ The controller uses a systemd user timer when available and falls back to cron.
242
242
  | `PI_MEMORY_QMD_UPDATE` | `background`, `manual`, `off` | `background` | Control qmd update after writes |
243
243
  | `PI_MEMORY_NO_SEARCH` | `1` | unset | Disable per-turn search injection |
244
244
  | `PI_MEMORY_SUMMARIZE_TRANSITIONS` | `1`, `true`, `yes`, `on` | unset | Also summarize lifecycle transitions |
245
- | `PI_MEMORY_LEARNING` | `off`, `review`, `auto-review` | `review` | Control session learning candidate extraction |
245
+ | `PI_MEMORY_LEARNING` | `off`, `review`, `auto-review` | `review` | Control session and curator daily learning candidate extraction |
246
246
  | `PI_MEMORY_LEARNING_MIN_CONFIDENCE` | `low`, `medium`, `high` | `medium` | Minimum extractor confidence to keep |
247
247
  | `PI_MEMORY_SKILL_DRAFTS` | `off`, `review` | `review` | Allow curator to propose disabled skill drafts |
248
248
  | `PI_MEMORY_AUTO_APPROVE_MEMORY` | `1`, `true`, `yes`, `on` | unset | YOLO mode for approving newly created memory proposals |
@@ -26,6 +26,7 @@
26
26
  */
27
27
 
28
28
  import { type ExecFileOptions, execFile } from "node:child_process";
29
+ import { createHash } from "node:crypto";
29
30
  import * as fs from "node:fs";
30
31
  import * as path from "node:path";
31
32
  import { complete, type Message, StringEnum } from "@earendil-works/pi-ai";
@@ -89,6 +90,7 @@ let USER_FILE = path.join(MEMORY_DIR, "USER.md");
89
90
  let STATE_FILE = path.join(MEMORY_DIR, "STATE.md");
90
91
  let REVIEW_FILE = path.join(MEMORY_DIR, "REVIEW.md");
91
92
  let SCRATCHPAD_FILE = path.join(MEMORY_DIR, "SCRATCHPAD.md");
93
+ let LEARNING_STATE_FILE = path.join(MEMORY_DIR, ".learning-state.json");
92
94
  let DAILY_DIR = path.join(MEMORY_DIR, "daily");
93
95
  let SKILL_DRAFTS_DIR = path.join(path.dirname(MEMORY_DIR), "skill-drafts");
94
96
 
@@ -104,6 +106,7 @@ export function _setBaseDir(baseDir: string) {
104
106
  STATE_FILE = path.join(baseDir, "STATE.md");
105
107
  REVIEW_FILE = path.join(baseDir, "REVIEW.md");
106
108
  SCRATCHPAD_FILE = path.join(baseDir, "SCRATCHPAD.md");
109
+ LEARNING_STATE_FILE = path.join(baseDir, ".learning-state.json");
107
110
  DAILY_DIR = path.join(baseDir, "daily");
108
111
  SKILL_DRAFTS_DIR = path.join(path.dirname(baseDir), "skill-drafts");
109
112
  }
@@ -562,9 +565,9 @@ function shouldKeepLearningCandidate(confidence: "low" | "medium" | "high", env:
562
565
  return confidenceRank(confidence) >= confidenceRank(getMemoryLearningMinConfidence(env));
563
566
  }
564
567
 
565
- function buildLearningExtractorPrompt(conversationText: string, truncated: boolean, totalChars: number): string {
568
+ function buildLearningExtractorPrompt(conversationText: string, truncated: boolean, totalChars: number, sourceLabel = "session transcript"): string {
566
569
  const lines = [
567
- "Extract zero or more review candidates from this session transcript.",
570
+ `Extract zero or more review candidates from this ${sourceLabel}.`,
568
571
  "Return JSON exactly shaped as: {\"candidates\":[{\"kind\":\"bug_fix|skill_candidate|preference|project_fact\",\"confidence\":\"low|medium|high\",\"signature\":\"short stable signature\",\"summary\":\"optional concise summary\",\"targetHints\":[\"memory\",\"skill\"],\"evidence\":\"optional compact evidence\"}]}",
569
572
  "Only include verified bug fixes when a failure was followed by an edit/action and successful validation.",
570
573
  "Drop one-off trivia, transient status, workflow artifacts, and loop artifacts.",
@@ -671,31 +674,90 @@ export function parseLearningExtractorResponse(raw: string): ReviewCandidateInpu
671
674
  return candidates;
672
675
  }
673
676
 
674
- async function runSessionLearningExtractor(ctx: ExtensionContext): Promise<number> {
675
- if (getMemoryLearningMode() === "off") return 0;
676
- const branch = getSessionBranch(ctx);
677
- if (!branch || !ctx.model) return 0;
677
+ type DailyLearningState = {
678
+ daily?: Record<string, { hash: string; scannedAt: string; candidates: number }>;
679
+ };
680
+
681
+ function readLearningState(): DailyLearningState {
682
+ try {
683
+ const parsed = JSON.parse(fs.readFileSync(LEARNING_STATE_FILE, "utf-8"));
684
+ return parsed && typeof parsed === "object" ? parsed as DailyLearningState : {};
685
+ } catch {
686
+ return {};
687
+ }
688
+ }
689
+
690
+ function writeLearningState(state: DailyLearningState): void {
691
+ fs.writeFileSync(LEARNING_STATE_FILE, `${JSON.stringify(state, null, 2)}\n`, "utf-8");
692
+ }
693
+
694
+ function contentHash(content: string): string {
695
+ return createHash("sha256").update(content).digest("hex");
696
+ }
697
+
698
+ async function extractLearningCandidates(
699
+ ctx: ExtensionContext,
700
+ text: string,
701
+ sourceLabel: string,
702
+ source: string,
703
+ date?: string,
704
+ ): Promise<ReviewCandidateInput[]> {
705
+ if (getMemoryLearningMode() === "off" || !ctx.model) return [];
678
706
  const apiKey = await resolveExitSummaryApiKey(ctx);
679
- if (!apiKey) return 0;
680
- const conversation = serializeSessionConversation(branch);
681
- if (!conversation.hasMessages || !conversation.text.trim()) return 0;
682
- const truncated = truncateText(conversation.text.trim(), LEARNING_EXTRACTOR_MAX_CHARS, "end");
707
+ if (!apiKey) return [];
708
+ const trimmed = text.trim();
709
+ if (!trimmed) return [];
710
+ const truncated = truncateText(trimmed, LEARNING_EXTRACTOR_MAX_CHARS, "end");
683
711
  const messages: Message[] = [{
684
712
  role: "user",
685
- content: [{ type: "text", text: buildLearningExtractorPrompt(truncated.text, truncated.truncated, conversation.text.trim().length) }],
713
+ content: [{ type: "text", text: buildLearningExtractorPrompt(truncated.text, truncated.truncated, trimmed.length, sourceLabel) }],
686
714
  timestamp: Date.now(),
687
715
  }];
716
+ const response = await complete(ctx.model, { systemPrompt: LEARNING_EXTRACTOR_SYSTEM_PROMPT, messages }, { apiKey, reasoningEffort: "low" });
717
+ const raw = response.content.filter((part): part is { type: "text"; text: string } => part.type === "text").map((part) => part.text).join("\n");
718
+ return parseLearningExtractorResponse(raw).map((candidate) => ({ ...candidate, source, date }));
719
+ }
720
+
721
+ async function writeLearningCandidates(candidates: ReviewCandidateInput[]): Promise<number> {
722
+ let written = 0;
723
+ const store = new FileMemoryStore(MEMORY_DIR);
724
+ for (const candidate of candidates) {
725
+ const result = await upsertReviewCandidate(store, candidate);
726
+ if (result.changed) written += 1;
727
+ }
728
+ return written;
729
+ }
730
+
731
+ type DailyLearningScanResult = { scanned: boolean; changed: number; skipped?: string };
732
+
733
+ async function runYesterdayDailyLearningScan(ctx: ExtensionContext): Promise<DailyLearningScanResult> {
734
+ if (getMemoryLearningMode() === "off") return { scanned: false, changed: 0, skipped: "learning off" };
735
+ const date = yesterdayStr();
736
+ const dailyContent = readFileSafe(dailyPath(date));
737
+ if (!dailyContent?.trim()) return { scanned: false, changed: 0, skipped: `daily/${date}.md empty or missing` };
738
+ const hash = contentHash(dailyContent);
739
+ const state = readLearningState();
740
+ const previous = state.daily?.[date];
741
+ if (previous?.hash === hash) return { scanned: false, changed: 0, skipped: `daily/${date}.md already scanned` };
688
742
  try {
689
- const response = await complete(ctx.model, { systemPrompt: LEARNING_EXTRACTOR_SYSTEM_PROMPT, messages }, { apiKey, reasoningEffort: "low" });
690
- const raw = response.content.filter((part): part is { type: "text"; text: string } => part.type === "text").map((part) => part.text).join("\n");
691
- const candidates = parseLearningExtractorResponse(raw);
692
- let written = 0;
693
- const store = new FileMemoryStore(MEMORY_DIR);
694
- for (const candidate of candidates) {
695
- const result = await upsertReviewCandidate(store, candidate);
696
- if (result.changed) written += 1;
697
- }
698
- return written;
743
+ const candidates = await extractLearningCandidates(ctx, dailyContent, `daily log for ${date}`, `daily/${date}`, date);
744
+ const changed = await writeLearningCandidates(candidates);
745
+ state.daily = { ...(state.daily || {}), [date]: { hash, scannedAt: new Date().toISOString(), candidates: candidates.length } };
746
+ writeLearningState(state);
747
+ return { scanned: true, changed };
748
+ } catch {
749
+ return { scanned: false, changed: 0, skipped: `daily/${date}.md scan failed` };
750
+ }
751
+ }
752
+
753
+ async function runSessionLearningExtractor(ctx: ExtensionContext): Promise<number> {
754
+ const branch = getSessionBranch(ctx);
755
+ if (!branch) return 0;
756
+ const conversation = serializeSessionConversation(branch);
757
+ if (!conversation.hasMessages || !conversation.text.trim()) return 0;
758
+ try {
759
+ const candidates = await extractLearningCandidates(ctx, conversation.text, "session transcript", "session_shutdown");
760
+ return writeLearningCandidates(candidates);
699
761
  } catch {
700
762
  return 0;
701
763
  }
@@ -1439,7 +1501,7 @@ function getSnapshotMode(): "stable" | "per-turn" {
1439
1501
  }
1440
1502
 
1441
1503
 
1442
- async function runCurator(reason: string): Promise<string> {
1504
+ async function runCurator(reason: string, ctx?: ExtensionContext): Promise<string> {
1443
1505
  ensureDirs();
1444
1506
  await evolutionBeforeChange(`curator before ${reason}`, "memory: snapshot before curate", "tool");
1445
1507
  const store = new FileMemoryStore(MEMORY_DIR);
@@ -1448,6 +1510,7 @@ async function runCurator(reason: string): Promise<string> {
1448
1510
  auditLog: new JsonlAuditLog(MEMORY_DIR),
1449
1511
  reason,
1450
1512
  });
1513
+ const dailyLearningResult = ctx ? await runYesterdayDailyLearningScan(ctx) : { scanned: false, changed: 0 };
1451
1514
  const lifecycleResult = await applyReviewLifecycle(store);
1452
1515
  const memoryResult = await proposeMemoryPromotions(store);
1453
1516
  const skillResult = getMemorySkillDraftsMode() === "off" ? { created: 0, proposals: [] } : await proposeSkillDrafts(store, { draftsDir: SKILL_DRAFTS_DIR });
@@ -1465,7 +1528,7 @@ async function runCurator(reason: string): Promise<string> {
1465
1528
  autoApprovedSkills += 1;
1466
1529
  }
1467
1530
  }
1468
- const learningChanges = lifecycleResult.changed + memoryResult.created + skillResult.created + autoApprovedMemory + autoApprovedSkills;
1531
+ const learningChanges = dailyLearningResult.changed + lifecycleResult.changed + memoryResult.created + skillResult.created + autoApprovedMemory + autoApprovedSkills;
1469
1532
  if (result.patches.length > 0 || learningChanges > 0) {
1470
1533
  snapshotDirty = true;
1471
1534
  await ensureQmdAvailableForUpdate();
@@ -1473,6 +1536,7 @@ async function runCurator(reason: string): Promise<string> {
1473
1536
  }
1474
1537
  await evolutionAfterChange("memory: sync after curate");
1475
1538
  const notes = [
1539
+ dailyLearningResult.scanned ? `scanned yesterday daily, wrote ${dailyLearningResult.changed} review candidate change(s)` : dailyLearningResult.skipped ? `daily learning skipped: ${dailyLearningResult.skipped}` : "",
1476
1540
  memoryResult.created > 0 ? `proposed ${memoryResult.created} memory promotion(s)` : "",
1477
1541
  skillResult.created > 0 ? `proposed ${skillResult.created} skill draft(s)` : "",
1478
1542
  autoApprovedMemory > 0 ? `auto-approved ${autoApprovedMemory} memory promotion(s)` : "",
@@ -2270,11 +2334,11 @@ export default function (pi: ExtensionAPI) {
2270
2334
  pi.registerTool({
2271
2335
  name: "memory_curate",
2272
2336
  label: "Memory Curate",
2273
- description: "Run the time-aware memory curator now. It deduplicates exact entries, updates event/quota lifecycle metadata, and appends stale temporary memories to REVIEW.md.",
2337
+ description: "Run the time-aware memory curator now. It scans yesterday's daily log into REVIEW.md, deduplicates exact entries, updates event/quota lifecycle metadata, and appends stale temporary memories to REVIEW.md.",
2274
2338
  parameters: Type.Object({}),
2275
2339
  async execute(_toolCallId, _params, _signal, _onUpdate, _ctx) {
2276
2340
  try {
2277
- const summary = await runCurator("memory_curate tool");
2341
+ const summary = await runCurator("memory_curate tool", _ctx);
2278
2342
  return { content: [{ type: "text", text: summary }], details: { summary } };
2279
2343
  } catch (error) {
2280
2344
  const message = error instanceof Error ? error.message : String(error);