pi-minimal 0.1.0

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.
@@ -0,0 +1,104 @@
1
+ import assert from "node:assert/strict"
2
+ import test from "node:test"
3
+ import type { ExtensionContext } from "@earendil-works/pi-coding-agent"
4
+ import { formatTrackerLines, hideGauntletWidgets } from "../src/tracker.js"
5
+
6
+ const theme = { fg: (_name: string, s: string) => s }
7
+
8
+ type PhaseStatus = "pending" | "in_progress" | "complete" | "skipped"
9
+ type TaskStatus = "pending" | "in_progress" | "complete" | "failed"
10
+
11
+ type Snapshot = {
12
+ phases?: Record<string, { status: PhaseStatus; substep?: string | null }>
13
+ tasks?: { name: string; status: TaskStatus }[]
14
+ }
15
+
16
+ function pendingPhases(): Record<string, { status: PhaseStatus; substep?: string | null }> {
17
+ return {
18
+ brainstorm: { status: "pending" },
19
+ plan: { status: "pending" },
20
+ implement: { status: "pending" },
21
+ verify: { status: "pending" },
22
+ ship: { status: "pending" },
23
+ }
24
+ }
25
+
26
+ function ctxFrom(snapshot: Snapshot, setWidget?: (...args: unknown[]) => void): ExtensionContext {
27
+ const branch: unknown[] = []
28
+ if (snapshot.phases !== undefined) {
29
+ branch.push({
30
+ type: "message",
31
+ message: {
32
+ role: "toolResult",
33
+ toolName: "phase_tracker",
34
+ details: { phases: snapshot.phases },
35
+ },
36
+ })
37
+ }
38
+ if (snapshot.tasks !== undefined) {
39
+ branch.push({
40
+ type: "message",
41
+ message: {
42
+ role: "toolResult",
43
+ toolName: "plan_tracker",
44
+ details: { tasks: snapshot.tasks },
45
+ },
46
+ })
47
+ }
48
+ return {
49
+ sessionManager: { getBranch: () => branch },
50
+ ui: { setWidget: setWidget ?? (() => {}) },
51
+ } as unknown as ExtensionContext
52
+ }
53
+
54
+ function hasPhaseLine(lines: string[]): boolean {
55
+ return lines.some((line) => line.includes("Phases"))
56
+ }
57
+
58
+ function hasTaskLine(lines: string[]): boolean {
59
+ return lines.some((line) => line.includes("Tasks"))
60
+ }
61
+
62
+ test("phase line appears only when at least one phase is not pending", () => {
63
+ const phases = pendingPhases()
64
+ phases.implement = { status: "in_progress" }
65
+ const lines = formatTrackerLines(ctxFrom({ phases }), theme)
66
+ assert.equal(hasPhaseLine(lines), true)
67
+ })
68
+
69
+ test("all-pending phases emit no phase line", () => {
70
+ const lines = formatTrackerLines(ctxFrom({ phases: pendingPhases() }), theme)
71
+ assert.equal(hasPhaseLine(lines), false)
72
+ })
73
+
74
+ test("absent phases emit no phase line", () => {
75
+ const lines = formatTrackerLines(ctxFrom({}), theme)
76
+ assert.equal(hasPhaseLine(lines), false)
77
+ })
78
+
79
+ test("nonempty tasks emit a task line", () => {
80
+ const lines = formatTrackerLines(
81
+ ctxFrom({
82
+ tasks: [{ name: "Write tracker tests", status: "in_progress" }],
83
+ }),
84
+ theme,
85
+ )
86
+ assert.equal(hasTaskLine(lines), true)
87
+ })
88
+
89
+ test("empty tasks emit none", () => {
90
+ const lines = formatTrackerLines(ctxFrom({ tasks: [] }), theme)
91
+ assert.equal(hasTaskLine(lines), false)
92
+ })
93
+
94
+ test("hideGauntletWidgets clears phase_tracker and plan_tracker", () => {
95
+ const calls: unknown[][] = []
96
+ const ctx = ctxFrom({}, (...args: unknown[]) => {
97
+ calls.push(args)
98
+ })
99
+ hideGauntletWidgets(ctx)
100
+ assert.deepEqual(calls, [
101
+ ["phase_tracker", undefined],
102
+ ["plan_tracker", undefined],
103
+ ])
104
+ })
package/tsconfig.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "compilerOptions": {
3
+ "rootDir": "src",
4
+ "outDir": "dist",
5
+ "module": "NodeNext",
6
+ "moduleResolution": "NodeNext",
7
+ "target": "ES2022",
8
+ "strict": true,
9
+ "skipLibCheck": true
10
+ },
11
+ "include": ["src"]
12
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": ".",
5
+ "outDir": "test-dist"
6
+ },
7
+ "include": ["src", "test"]
8
+ }