@xynogen/pix-pretty 1.31.0 → 1.32.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.
- package/package.json +4 -3
- package/src/grammar-consent.ts +44 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xynogen/pix-pretty",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.32.1",
|
|
4
4
|
"description": "Enhanced tool output rendering with syntax highlighting, file icons, tree views, diff rendering, and FFF search",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
"./tool-status": "./src/tool-status.ts",
|
|
34
34
|
"./test-utils": "./src/test-utils.ts",
|
|
35
35
|
"./transient-error": "./src/transient-error.ts",
|
|
36
|
-
"./chips": "./src/chips.ts"
|
|
36
|
+
"./chips": "./src/chips.ts",
|
|
37
|
+
"./grammar-consent": "./src/grammar-consent.ts"
|
|
37
38
|
},
|
|
38
39
|
"scripts": {
|
|
39
40
|
"test": "bun test"
|
|
@@ -68,7 +69,7 @@
|
|
|
68
69
|
"access": "public"
|
|
69
70
|
},
|
|
70
71
|
"dependencies": {
|
|
71
|
-
"@xynogen/pix-runtime": "^0.
|
|
72
|
+
"@xynogen/pix-runtime": "^0.15.0",
|
|
72
73
|
"chalk": "^4.1.2",
|
|
73
74
|
"cli-highlight": "^2.1.11",
|
|
74
75
|
"@ff-labs/fff-node": "^0.10.6",
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pix-pretty/grammar-consent — one-time user consent to install an ast-grep grammar.
|
|
3
|
+
*
|
|
4
|
+
* A tool's `execute` receives a Pi UI context. This turns it into a `ConsentFn`
|
|
5
|
+
* for `parseWithGrammar` (`@xynogen/pix-runtime/ast`): it shows a confirm overlay once per package. Without
|
|
6
|
+
* a UI (non-interactive session), it defers — the package installs nothing
|
|
7
|
+
* without a person saying yes.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { type ConsentFn, grammarCacheDir } from "@xynogen/pix-runtime/ast";
|
|
11
|
+
import { showOverlay } from "./gate-overlay.ts";
|
|
12
|
+
|
|
13
|
+
// Minimal shape of the execute `ctx` we need. No hard dep on the host type.
|
|
14
|
+
export interface ExecuteCtx {
|
|
15
|
+
hasUI?: boolean;
|
|
16
|
+
ui: Parameters<typeof showOverlay>[0];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const INSTALL_TIMEOUT_MS = 60_000;
|
|
20
|
+
|
|
21
|
+
/** Build a consent function that asks once per grammar package. */
|
|
22
|
+
export function grammarConsent(ctx?: ExecuteCtx): ConsentFn | undefined {
|
|
23
|
+
if (!ctx?.hasUI) return undefined;
|
|
24
|
+
return async (pkg: string): Promise<boolean> => {
|
|
25
|
+
const result = await showOverlay(ctx.ui, {
|
|
26
|
+
mode: "confirm",
|
|
27
|
+
title: "Install ast-grep grammar",
|
|
28
|
+
body: [
|
|
29
|
+
`This language needs the grammar package:`,
|
|
30
|
+
` ${pkg}`,
|
|
31
|
+
``,
|
|
32
|
+
`Install it into the pix cache (${grammarCacheDir()})?`,
|
|
33
|
+
`If another grammar is already active, restart the agent after installation.`,
|
|
34
|
+
],
|
|
35
|
+
accent: "accent",
|
|
36
|
+
timeoutMs: INSTALL_TIMEOUT_MS,
|
|
37
|
+
choices: [
|
|
38
|
+
{ value: "yes", label: "Install", description: "Download and use this grammar" },
|
|
39
|
+
{ value: "no", label: "Skip", description: "Do not install; skip this language" },
|
|
40
|
+
],
|
|
41
|
+
});
|
|
42
|
+
return result.action === "approved";
|
|
43
|
+
};
|
|
44
|
+
}
|