tdd-enforcer 0.2.9 → 0.3.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.
@@ -430,10 +430,8 @@ describe("handleBeforeAgentStart", () => {
430
430
  };
431
431
  }
432
432
 
433
- function makeEvent(): {
434
- systemPromptOptions: { promptGuidelines: string[] };
435
- } {
436
- return { systemPromptOptions: { promptGuidelines: [] } };
433
+ function _makeEvent(): { systemPrompt: string } {
434
+ return { systemPrompt: "" };
437
435
  }
438
436
 
439
437
  beforeEach(() => {
@@ -441,7 +439,7 @@ describe("handleBeforeAgentStart", () => {
441
439
  mockLoadTddState = vi.fn();
442
440
  });
443
441
 
444
- it("pushes guidelines when TDD enabled", async () => {
442
+ it("returns instructions when TDD enabled", async () => {
445
443
  mockLoadTddState.mockReturnValue({
446
444
  ok: true,
447
445
  state: { enabled: true, current: "red" },
@@ -452,39 +450,32 @@ describe("handleBeforeAgentStart", () => {
452
450
  timeoutSeconds: 30,
453
451
  },
454
452
  });
455
- const event = makeEvent();
456
- await handleBeforeAgentStart(
457
- event as any,
453
+ const result = await handleBeforeAgentStart(
454
+ { systemPrompt: "" } as any,
458
455
  { cwd: "/test" } as any,
459
456
  makeDeps(),
460
457
  );
461
- expect(event.systemPromptOptions.promptGuidelines).toHaveLength(3);
462
- expect(event.systemPromptOptions.promptGuidelines[0]).toContain(
463
- "locked files will be blocked",
464
- );
465
- expect(event.systemPromptOptions.promptGuidelines[1]).toContain(
466
- "next_tdd_phase",
467
- );
468
- expect(event.systemPromptOptions.promptGuidelines[2]).toContain(
469
- "cycle so reverting is cheap",
470
- );
458
+ expect(result).toBeDefined();
459
+ expect(result?.systemPrompt).toContain("TDD enforcement");
460
+ expect(result?.systemPrompt).toContain("locked files will be blocked");
461
+ expect(result?.systemPrompt).toContain("cycle so reverting is cheap");
462
+ expect(result?.systemPrompt).not.toContain("next_tdd_phase");
471
463
  });
472
464
 
473
- it("does not push guidelines when TDD not setup", async () => {
465
+ it("returns undefined when TDD not setup", async () => {
474
466
  mockLoadTddState.mockReturnValue({
475
467
  ok: false,
476
468
  reason: "Missing .pi/tdd/",
477
469
  });
478
- const event = makeEvent();
479
- await handleBeforeAgentStart(
480
- event as any,
470
+ const result = await handleBeforeAgentStart(
471
+ { systemPrompt: "" } as any,
481
472
  { cwd: "/test" } as any,
482
473
  makeDeps(),
483
474
  );
484
- expect(event.systemPromptOptions.promptGuidelines).toHaveLength(0);
475
+ expect(result).toBeUndefined();
485
476
  });
486
477
 
487
- it("does not push guidelines when TDD disabled", async () => {
478
+ it("returns disabled message when TDD was disabled", async () => {
488
479
  mockLoadTddState.mockReturnValue({
489
480
  ok: true,
490
481
  state: { enabled: false, current: "red" },
@@ -495,12 +486,12 @@ describe("handleBeforeAgentStart", () => {
495
486
  timeoutSeconds: 30,
496
487
  },
497
488
  });
498
- const event = makeEvent();
499
- await handleBeforeAgentStart(
500
- event as any,
489
+ const result = await handleBeforeAgentStart(
490
+ { systemPrompt: "" } as any,
501
491
  { cwd: "/test" } as any,
502
492
  makeDeps(),
503
493
  );
504
- expect(event.systemPromptOptions.promptGuidelines).toHaveLength(0);
494
+ expect(result).toBeDefined();
495
+ expect(result?.systemPrompt).toContain("was disabled");
505
496
  });
506
497
  });
@@ -149,22 +149,28 @@ export async function handleTddStatus(
149
149
  }
150
150
 
151
151
  export async function handleBeforeAgentStart(
152
- event: {
153
- systemPromptOptions: { promptGuidelines: string[] };
154
- },
152
+ event: { systemPrompt: string },
155
153
  ctx: { cwd: string },
156
154
  deps: {
157
155
  loadTddState: typeof loadTddState;
158
156
  },
159
- ): Promise<void> {
157
+ ): Promise<{ systemPrompt: string } | undefined> {
160
158
  const tdd = deps.loadTddState(ctx.cwd);
161
- if (!tdd.ok || !tdd.state.enabled) return;
162
-
163
- event.systemPromptOptions.promptGuidelines.push(
164
- "You are working under TDD enforcement. Each phase restricts which files you can modify — locked files will be blocked automatically.",
165
- "Use `next_tdd_phase` to advance through the cycle, `previous_tdd_phase` to revert a phase, `tdd_status` to check current phase and blocked file rules.",
166
- "Minimise the scope of each TDD cycle so reverting is cheap.",
167
- );
159
+ if (!tdd.ok) return;
160
+
161
+ if (tdd.state.enabled) {
162
+ return {
163
+ systemPrompt:
164
+ event.systemPrompt +
165
+ "\n\nYou are working under TDD enforcement. Each phase restricts which files you can modify — locked files will be blocked automatically.\n" +
166
+ "Minimise the scope of each TDD cycle so reverting is cheap.",
167
+ };
168
+ }
169
+ return {
170
+ systemPrompt:
171
+ event.systemPrompt +
172
+ "\n\nTDD enforcement was disabled. File restrictions are no longer enforced.",
173
+ };
168
174
  }
169
175
 
170
176
  export async function handleTddJump(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tdd-enforcer",
3
- "version": "0.2.9",
3
+ "version": "0.3.1",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "fmt": "biome format --write .",