@tinoy/pi-ext-lib 0.2.0 → 0.3.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.
- package/package.json +2 -1
- package/src/glob.ts +24 -0
- package/src/index.ts +1 -0
- package/src/tool-header.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinoy/pi-ext-lib",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Shared helpers for pi extensions: the hook log envelope, TUI tool headers, and the system-prompt block seam.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
".": "./src/index.ts"
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
20
|
+
"src/glob.ts",
|
|
20
21
|
"src/hook-log.ts",
|
|
21
22
|
"src/index.ts",
|
|
22
23
|
"src/neighbour.ts",
|
package/src/glob.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* glob.ts — path/glob overlap, the predicate the fleet and its claim guard must agree on.
|
|
3
|
+
*
|
|
4
|
+
* `globOverlap` answers "do these two path patterns address the same tree": an exact
|
|
5
|
+
* match, either side a directory prefix of the other, or a `*` wildcard anywhere in
|
|
6
|
+
* either side. It lives here because both extension packages that ask the question
|
|
7
|
+
* need the same answer, and a shared library is a cheaper owner than a dependency
|
|
8
|
+
* between the two packages.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** Glob/path overlap: exact, directory prefix, or '*' anywhere in either side. */
|
|
12
|
+
export function globOverlap(a: string, b: string): boolean {
|
|
13
|
+
const x = a.replace(/\/+$/, "");
|
|
14
|
+
const y = b.replace(/\/+$/, "");
|
|
15
|
+
if (x === y) return true;
|
|
16
|
+
if (x.includes("*")) return new RegExp(`^${x.split("*").map(escapeRe).join(".*")}$`).test(y);
|
|
17
|
+
if (y.includes("*")) return new RegExp(`^${y.split("*").map(escapeRe).join(".*")}$`).test(x);
|
|
18
|
+
return x.startsWith(`${y}/`) || y.startsWith(`${x}/`);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Escape every RegExp metacharacter in `s`, so it can be embedded in a pattern. */
|
|
22
|
+
export function escapeRe(s: string): string {
|
|
23
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
24
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* each was already in the tree, so the copy is the one canonical file for any
|
|
10
10
|
* package that depends on this one.
|
|
11
11
|
*/
|
|
12
|
+
export { escapeRe, globOverlap } from "./glob.ts";
|
|
12
13
|
export { HOOK_LOG_PATH, hookLog } from "./hook-log.ts";
|
|
13
14
|
export { type NeighbourReport, optionalNeighbour } from "./neighbour.ts";
|
|
14
15
|
export {
|
package/src/tool-header.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* pi bundles its TUI inside the agent and does not expose `@earendil-works/pi-tui`
|
|
5
5
|
* to extensions, so a header cannot be a `Text`; it must be a duck-typed
|
|
6
6
|
* component (`render(width)` + `invalidate()`), the shape
|
|
7
|
-
*
|
|
7
|
+
* the deepseek-cost entry uses for its entry renderer.
|
|
8
8
|
*
|
|
9
9
|
* A header is ONE line: the tool name plus the few fields a reader needs to
|
|
10
10
|
* follow the transcript. Free text is flattened and clipped before theming, so
|