@xynogen/pix-core 0.4.1 → 0.4.3
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.
- package/README.md +23 -0
- package/package.json +1 -1
- package/src/once.test.ts +103 -22
package/README.md
CHANGED
|
@@ -10,6 +10,8 @@ Pi activates extensions per installed package via each package's `pi.extensions`
|
|
|
10
10
|
|
|
11
11
|
## What's included
|
|
12
12
|
|
|
13
|
+
**UI / UX extensions**
|
|
14
|
+
|
|
13
15
|
| Package | Description |
|
|
14
16
|
|---|---|
|
|
15
17
|
| `pix-welcome` | ASCII π banner + startup health checks (version, auth, models, gitignore) |
|
|
@@ -22,6 +24,27 @@ Pi activates extensions per installed package via each package's `pi.extensions`
|
|
|
22
24
|
| `pix-skills` | Agent skill loader (`read_skills` tool + 23 bundled skills) |
|
|
23
25
|
| `pix-nudge` | Tool + capability nudge hooks |
|
|
24
26
|
|
|
27
|
+
**Tool suite** (drop-in replacements for Pi's built-in tools)
|
|
28
|
+
|
|
29
|
+
| Package | Description |
|
|
30
|
+
|---|---|
|
|
31
|
+
| `pix-read` | `read` — file read with syntax highlighting |
|
|
32
|
+
| `pix-write` | `write` — file write with split-diff rendering |
|
|
33
|
+
| `pix-edit` | `edit` — precise text replacement with per-edit diff |
|
|
34
|
+
| `pix-find` | `find` — glob search with FFF acceleration |
|
|
35
|
+
| `pix-grep` | `grep` — pattern search with FFF-prioritised results |
|
|
36
|
+
| `pix-ls` | `ls` — directory listing as an icon tree |
|
|
37
|
+
| `pix-bash` | `bash` — shell execution with framed output + exit-code summary |
|
|
38
|
+
| `pix-todo` | `todo` — durable execution checklist |
|
|
39
|
+
| `pix-ask` | `ask_user` — structured TUI questionnaire |
|
|
40
|
+
|
|
41
|
+
**Behaviour**
|
|
42
|
+
|
|
43
|
+
| Package | Description |
|
|
44
|
+
|---|---|
|
|
45
|
+
| `pix-optimizer` | Caveman mode + RTK tool rewriting + jq/TOON JSON compression (`/opt`) |
|
|
46
|
+
| `pix-gate` | Permission gate for dangerous bash commands |
|
|
47
|
+
|
|
25
48
|
## Install
|
|
26
49
|
|
|
27
50
|
```bash
|
package/package.json
CHANGED
package/src/once.test.ts
CHANGED
|
@@ -1,62 +1,143 @@
|
|
|
1
1
|
import { afterEach, describe, expect, it } from "bun:test";
|
|
2
|
+
import registerTodo from "@xynogen/pix-todo/src/todo.ts";
|
|
2
3
|
|
|
3
|
-
// Mirror of the per-
|
|
4
|
+
// Mirror of the per-instance guard. pix-core does not own once.ts (each member
|
|
4
5
|
// duplicates it to stay cross-dep-free), so we re-declare the contract here and
|
|
5
6
|
// assert the dedupe semantics that the aggregator relies on.
|
|
6
|
-
function once(key: string, fn: () => void): void {
|
|
7
|
-
const g = globalThis as {
|
|
8
|
-
const
|
|
7
|
+
function once(pi: object, key: string, fn: () => void): void {
|
|
8
|
+
const g = globalThis as { __pixOnce?: WeakMap<object, Set<string>> };
|
|
9
|
+
const registry = (g.__pixOnce ??= new WeakMap<object, Set<string>>());
|
|
10
|
+
let loaded = registry.get(pi);
|
|
11
|
+
if (!loaded) {
|
|
12
|
+
loaded = new Set<string>();
|
|
13
|
+
registry.set(pi, loaded);
|
|
14
|
+
}
|
|
9
15
|
if (loaded.has(key)) return;
|
|
10
16
|
loaded.add(key);
|
|
11
17
|
fn();
|
|
12
18
|
}
|
|
13
19
|
|
|
14
20
|
afterEach(() => {
|
|
15
|
-
delete (globalThis as {
|
|
21
|
+
delete (globalThis as { __pixOnce?: WeakMap<object, Set<string>> }).__pixOnce;
|
|
16
22
|
});
|
|
17
23
|
|
|
18
24
|
describe("once", () => {
|
|
19
25
|
it("runs the factory on first invocation", () => {
|
|
26
|
+
const pi = {};
|
|
20
27
|
let calls = 0;
|
|
21
|
-
once("pix-footer", () => {
|
|
28
|
+
once(pi, "pix-footer", () => {
|
|
22
29
|
calls++;
|
|
23
30
|
});
|
|
24
31
|
expect(calls).toBe(1);
|
|
25
32
|
});
|
|
26
33
|
|
|
27
|
-
it("skips repeated invocations of the same key", () => {
|
|
34
|
+
it("skips repeated invocations of the same key on the same pi", () => {
|
|
35
|
+
const pi = {};
|
|
28
36
|
let calls = 0;
|
|
29
37
|
const reg = () => {
|
|
30
38
|
calls++;
|
|
31
39
|
};
|
|
32
|
-
once("pix-footer", reg);
|
|
33
|
-
once("pix-footer", reg);
|
|
34
|
-
once("pix-footer", reg);
|
|
40
|
+
once(pi, "pix-footer", reg);
|
|
41
|
+
once(pi, "pix-footer", reg);
|
|
42
|
+
once(pi, "pix-footer", reg);
|
|
35
43
|
expect(calls).toBe(1);
|
|
36
44
|
});
|
|
37
45
|
|
|
38
|
-
it("isolates distinct keys", () => {
|
|
46
|
+
it("isolates distinct keys on the same pi", () => {
|
|
47
|
+
const pi = {};
|
|
39
48
|
const seen: string[] = [];
|
|
40
|
-
once("pix-footer", () => seen.push("footer"));
|
|
41
|
-
once("pix-welcome", () => seen.push("welcome"));
|
|
49
|
+
once(pi, "pix-footer", () => seen.push("footer"));
|
|
50
|
+
once(pi, "pix-welcome", () => seen.push("welcome"));
|
|
42
51
|
expect(seen).toEqual(["footer", "welcome"]);
|
|
43
52
|
});
|
|
44
53
|
|
|
45
|
-
it("shares the registry across calls via globalThis", () => {
|
|
54
|
+
it("shares the registry across calls via globalThis (same pi)", () => {
|
|
55
|
+
const pi = {};
|
|
46
56
|
let calls = 0;
|
|
47
|
-
once("pix-skills", () => {
|
|
57
|
+
once(pi, "pix-skills", () => {
|
|
48
58
|
calls++;
|
|
49
59
|
});
|
|
50
60
|
// A second loader pass (e.g. standalone install after pix-core) reuses
|
|
51
|
-
// the same globalThis registry and must not re-run.
|
|
52
|
-
once("pix-skills", () => {
|
|
61
|
+
// the same globalThis registry for the same pi and must not re-run.
|
|
62
|
+
once(pi, "pix-skills", () => {
|
|
53
63
|
calls++;
|
|
54
64
|
});
|
|
55
65
|
expect(calls).toBe(1);
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("re-runs for a new pi instance with the same key (/new rehydration)", () => {
|
|
69
|
+
const pi1 = {};
|
|
70
|
+
const pi2 = {};
|
|
71
|
+
let calls = 0;
|
|
72
|
+
once(pi1, "pix-footer", () => {
|
|
73
|
+
calls++;
|
|
74
|
+
});
|
|
75
|
+
// pi2 is a fresh instance (as built by Pi on /new, /resume, /fork, /reload).
|
|
76
|
+
// The factory must run again — this is the rehydration guarantee.
|
|
77
|
+
once(pi2, "pix-footer", () => {
|
|
78
|
+
calls++;
|
|
79
|
+
});
|
|
80
|
+
expect(calls).toBe(2);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("same key on two different pi instances dedupes within each instance", () => {
|
|
84
|
+
const pi1 = {};
|
|
85
|
+
const pi2 = {};
|
|
86
|
+
let calls1 = 0;
|
|
87
|
+
let calls2 = 0;
|
|
88
|
+
once(pi1, "pix-welcome", () => {
|
|
89
|
+
calls1++;
|
|
90
|
+
});
|
|
91
|
+
once(pi1, "pix-welcome", () => {
|
|
92
|
+
calls1++;
|
|
93
|
+
}); // second on pi1 → skip
|
|
94
|
+
once(pi2, "pix-welcome", () => {
|
|
95
|
+
calls2++;
|
|
96
|
+
});
|
|
97
|
+
once(pi2, "pix-welcome", () => {
|
|
98
|
+
calls2++;
|
|
99
|
+
}); // second on pi2 → skip
|
|
100
|
+
expect(calls1).toBe(1); // deduped within pi1
|
|
101
|
+
expect(calls2).toBe(1); // deduped within pi2
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// Behavior pin: prove a REAL guarded member dedupes when its factory runs
|
|
106
|
+
// twice against the SAME pi — the exact scenario the aggregator creates when a
|
|
107
|
+
// tool is installed both via pix-core (this boots it) and standalone (Pi boots
|
|
108
|
+
// it again). The member must register its tool only once or Pi reports a
|
|
109
|
+
// tool conflict.
|
|
110
|
+
describe("member factory dedupe (pix-todo)", () => {
|
|
111
|
+
function makeHost() {
|
|
112
|
+
const toolNames: string[] = [];
|
|
113
|
+
const pi = {
|
|
114
|
+
registerTool(def: { name: string }) {
|
|
115
|
+
toolNames.push(def.name);
|
|
116
|
+
},
|
|
117
|
+
appendEntry() {},
|
|
118
|
+
on() {},
|
|
119
|
+
} as never;
|
|
120
|
+
return { pi, toolNames };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
it("registers the tool once across core + standalone activation (same pi)", () => {
|
|
124
|
+
const { pi, toolNames } = makeHost();
|
|
125
|
+
// First pass: pix-core's aggregator invokes the member factory.
|
|
126
|
+
registerTodo(pi);
|
|
127
|
+
// Second pass: standalone install loads the same module and invokes it
|
|
128
|
+
// again. The globalThis once() registry must suppress re-registration.
|
|
129
|
+
registerTodo(pi);
|
|
130
|
+
expect(toolNames).toEqual(["todo"]);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("registers the tool again for a fresh pi instance (/new rehydration)", () => {
|
|
134
|
+
const { pi: pi1, toolNames: tools1 } = makeHost();
|
|
135
|
+
const { pi: pi2, toolNames: tools2 } = makeHost();
|
|
136
|
+
// First session.
|
|
137
|
+
registerTodo(pi1);
|
|
138
|
+
// /new: a fresh pi is built; factory must run again.
|
|
139
|
+
registerTodo(pi2);
|
|
140
|
+
expect(tools1).toEqual(["todo"]);
|
|
141
|
+
expect(tools2).toEqual(["todo"]);
|
|
61
142
|
});
|
|
62
143
|
});
|