@caupulican/pi-adaptative 0.80.64 → 0.80.66

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.
@@ -31,6 +31,7 @@ import { createCoreDiagnosticsToolDefinitions } from "./extensions/builtin.js";
31
31
  import { ExtensionRunner, wrapRegisteredTools, } from "./extensions/index.js";
32
32
  import { disposeExtensionEventSubscriptions } from "./extensions/loader.js";
33
33
  import { emitSessionShutdownEvent } from "./extensions/runner.js";
34
+ import { GatewayRegistry } from "./gateways/channel-provider.js";
34
35
  import { decideDemand, ReflectionEngine, } from "./learning/reflection-engine.js";
35
36
  import { EffectivenessTracker } from "./memory/effectiveness-tracker.js";
36
37
  import { MemoryManager } from "./memory/memory-manager.js";
@@ -123,6 +124,8 @@ export class AgentSession {
123
124
  _memoryManager = new MemoryManager();
124
125
  /** R4: tracks whether injected recall is actually used, to adapt the recall gate. */
125
126
  _effectivenessTracker = new EffectivenessTracker();
127
+ /** R8: registry for deployment-supplied gateway channels + schedulers (lifecycle driven by the host runner). */
128
+ _gatewayRegistry = new GatewayRegistry();
126
129
  _isChildSession;
127
130
  /** Memory providers registered by extensions via pi.registerMemoryProvider, applied on (re)init. */
128
131
  _pendingMemoryProviders = [];
@@ -659,6 +662,8 @@ export class AgentSession {
659
662
  this.abortBranchSummary();
660
663
  this.abortBash();
661
664
  this.agent.abort();
665
+ // R8: stop any deployment-registered gateway channels / schedulers.
666
+ void this._gatewayRegistry.stop().catch(() => { });
662
667
  }
663
668
  catch {
664
669
  // Dispose must succeed even if an abort hook throws.
@@ -2301,6 +2306,18 @@ export class AgentSession {
2301
2306
  this._pendingMemoryProviders.push(provider);
2302
2307
  }
2303
2308
  }
2309
+ /** R8: the gateway/scheduler registry. A deployment runner registers providers and drives start/stop. */
2310
+ get gateways() {
2311
+ return this._gatewayRegistry;
2312
+ }
2313
+ /** R8: register a deployment-supplied transport channel (gateway). */
2314
+ registerChannelProvider(provider) {
2315
+ this._gatewayRegistry.registerChannel(provider);
2316
+ }
2317
+ /** R8: register a deployment-supplied job scheduler (cron). */
2318
+ registerJobScheduler(provider) {
2319
+ this._gatewayRegistry.registerScheduler(provider);
2320
+ }
2304
2321
  _refreshToolRegistry(options) {
2305
2322
  const previousRegistryNames = new Set(this._toolRegistry.keys());
2306
2323
  const previousActiveToolNames = this.getActiveToolNames();
@@ -3389,6 +3406,12 @@ export class AgentSession {
3389
3406
  * isn't found there. Best-effort: failures are swallowed (reflection must never break a turn).
3390
3407
  */
3391
3408
  async _applyReflectionWrite(write, signal) {
3409
+ // R7 memory-to-behavior: a recurring procedure is compiled into an executable skill file rather
3410
+ // than stored as a flat fact. Written under the agent skills dir so it loads like any user skill.
3411
+ if (write.kind === "promote_skill") {
3412
+ this._promoteReflectionSkill(write.name, write.description, write.body);
3413
+ return;
3414
+ }
3392
3415
  const memTool = this._memoryManager.getToolDefinitions().find((t) => t.name === "memory");
3393
3416
  const exec = memTool?.execute;
3394
3417
  if (!exec)
@@ -3424,6 +3447,33 @@ export class AgentSession {
3424
3447
  }
3425
3448
  }
3426
3449
  }
3450
+ /**
3451
+ * R7: write a reflection-promoted skill as `<agentDir>/skills/<name>/SKILL.md` so it loads like any
3452
+ * user skill. Best-effort; never clobbers an existing (hand-authored) skill of the same name.
3453
+ */
3454
+ _promoteReflectionSkill(rawName, description, body) {
3455
+ const name = rawName
3456
+ .trim()
3457
+ .toLowerCase()
3458
+ .replace(/[^a-z0-9-]+/g, "-")
3459
+ .replace(/^-+|-+$/g, "")
3460
+ .slice(0, 64);
3461
+ if (!name || !body.trim())
3462
+ return;
3463
+ try {
3464
+ const dir = join(this._agentDir, "skills", name);
3465
+ const file = join(dir, "SKILL.md");
3466
+ if (existsSync(file))
3467
+ return; // do not overwrite an existing skill
3468
+ mkdirSync(dir, { recursive: true });
3469
+ const safeDescription = description.replace(/[\r\n]+/g, " ").trim();
3470
+ 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`;
3471
+ writeFileSync(file, content, "utf-8");
3472
+ }
3473
+ catch {
3474
+ // promotion must never break a turn
3475
+ }
3476
+ }
3427
3477
  getContextUsage() {
3428
3478
  const model = this.model;
3429
3479
  if (!model)