@caupulican/pi-adaptative 0.80.64 → 0.80.65

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.
@@ -3389,6 +3389,12 @@ export class AgentSession {
3389
3389
  * isn't found there. Best-effort: failures are swallowed (reflection must never break a turn).
3390
3390
  */
3391
3391
  async _applyReflectionWrite(write, signal) {
3392
+ // R7 memory-to-behavior: a recurring procedure is compiled into an executable skill file rather
3393
+ // than stored as a flat fact. Written under the agent skills dir so it loads like any user skill.
3394
+ if (write.kind === "promote_skill") {
3395
+ this._promoteReflectionSkill(write.name, write.description, write.body);
3396
+ return;
3397
+ }
3392
3398
  const memTool = this._memoryManager.getToolDefinitions().find((t) => t.name === "memory");
3393
3399
  const exec = memTool?.execute;
3394
3400
  if (!exec)
@@ -3424,6 +3430,33 @@ export class AgentSession {
3424
3430
  }
3425
3431
  }
3426
3432
  }
3433
+ /**
3434
+ * R7: write a reflection-promoted skill as `<agentDir>/skills/<name>/SKILL.md` so it loads like any
3435
+ * user skill. Best-effort; never clobbers an existing (hand-authored) skill of the same name.
3436
+ */
3437
+ _promoteReflectionSkill(rawName, description, body) {
3438
+ const name = rawName
3439
+ .trim()
3440
+ .toLowerCase()
3441
+ .replace(/[^a-z0-9-]+/g, "-")
3442
+ .replace(/^-+|-+$/g, "")
3443
+ .slice(0, 64);
3444
+ if (!name || !body.trim())
3445
+ return;
3446
+ try {
3447
+ const dir = join(this._agentDir, "skills", name);
3448
+ const file = join(dir, "SKILL.md");
3449
+ if (existsSync(file))
3450
+ return; // do not overwrite an existing skill
3451
+ mkdirSync(dir, { recursive: true });
3452
+ const safeDescription = description.replace(/[\r\n]+/g, " ").trim();
3453
+ const content = `---\nname: ${name}\ndescription: ${safeDescription}\n---\n\n<!-- Auto-generated by the reflection engine (R7 memory-to-behavior). Review and refine. -->\n\n${body.trim()}\n`;
3454
+ writeFileSync(file, content, "utf-8");
3455
+ }
3456
+ catch {
3457
+ // promotion must never break a turn
3458
+ }
3459
+ }
3427
3460
  getContextUsage() {
3428
3461
  const model = this.model;
3429
3462
  if (!model)