@tmustier/pi-agent-teams 0.4.0-beta.0 → 0.4.0-beta.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.
@@ -32,6 +32,7 @@ import {
32
32
  import { ensureTeamConfig, loadTeamConfig, upsertMember, setMemberStatus } from "../extensions/teams/team-config.js";
33
33
  import { sanitizeName } from "../extensions/teams/names.js";
34
34
  import { getTeamsNamingRules, getTeamsStrings } from "../extensions/teams/teams-style.js";
35
+ import { runTeamsHook } from "../extensions/teams/hooks.js";
35
36
  import { getTeamHelpText } from "../extensions/teams/leader-team-command.js";
36
37
  import {
37
38
  TEAM_MAILBOX_NS,
@@ -456,8 +457,69 @@ console.log("\n8. teams-style (custom styles)");
456
457
  else process.env.PI_TEAMS_ROOT_DIR = prev;
457
458
  }
458
459
 
459
- // ── 9. docs/help drift guard ────────────────────────────────────────
460
- console.log("\n9. docs/help drift guard");
460
+ // ── 9. hooks (quality gates) ────────────────────────────────────────
461
+ console.log("\n9. teams-hooks (quality gates)");
462
+ {
463
+ const prevRoot = process.env.PI_TEAMS_ROOT_DIR;
464
+ const prevEnabled = process.env.PI_TEAMS_HOOKS_ENABLED;
465
+ process.env.PI_TEAMS_ROOT_DIR = tmpRoot;
466
+ process.env.PI_TEAMS_HOOKS_ENABLED = "1";
467
+
468
+ const hooksDir = path.join(tmpRoot, "_hooks");
469
+ fs.mkdirSync(hooksDir, { recursive: true });
470
+
471
+ const outFile = path.join(tmpRoot, "hook-ran.txt");
472
+ fs.writeFileSync(
473
+ path.join(hooksDir, "on_task_completed.js"),
474
+ "" +
475
+ "const fs = require('node:fs');\n" +
476
+ `fs.writeFileSync(${JSON.stringify(outFile)}, 'ok\\n', 'utf8');\n` +
477
+ "process.exit(0);\n",
478
+ "utf8",
479
+ );
480
+
481
+ const teamId = "smoke-team";
482
+ const teamDir = path.join(tmpRoot, teamId);
483
+ fs.mkdirSync(teamDir, { recursive: true });
484
+
485
+ const res = await runTeamsHook({
486
+ invocation: {
487
+ event: "task_completed",
488
+ teamId,
489
+ teamDir,
490
+ taskListId: teamId,
491
+ style: "pirate",
492
+ memberName: "agent1",
493
+ timestamp: new Date().toISOString(),
494
+ completedTask: {
495
+ id: "1",
496
+ subject: "Test task",
497
+ description: "",
498
+ owner: "agent1",
499
+ status: "completed",
500
+ blocks: [],
501
+ blockedBy: [],
502
+ metadata: {},
503
+ createdAt: new Date().toISOString(),
504
+ updatedAt: new Date().toISOString(),
505
+ },
506
+ },
507
+ cwd: tmpRoot,
508
+ });
509
+
510
+ assert(res.ran === true, "runs on_task_completed hook");
511
+ assert(res.exitCode === 0, "hook exit code is 0");
512
+ assert(fs.existsSync(outFile), "hook wrote output file");
513
+
514
+ // restore env
515
+ if (prevRoot === undefined) delete process.env.PI_TEAMS_ROOT_DIR;
516
+ else process.env.PI_TEAMS_ROOT_DIR = prevRoot;
517
+ if (prevEnabled === undefined) delete process.env.PI_TEAMS_HOOKS_ENABLED;
518
+ else process.env.PI_TEAMS_HOOKS_ENABLED = prevEnabled;
519
+ }
520
+
521
+ // ── 10. docs/help drift guard ────────────────────────────────────────
522
+ console.log("\n10. docs/help drift guard");
461
523
  {
462
524
  const help = getTeamHelpText();
463
525
  assert(help.includes("/team style list"), "help mentions /team style list");