ultimate-pi 0.1.6 → 0.1.7
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/.env.example +3 -1
- package/.pi/extensions/soundboard.ts +533 -0
- package/.pi/mcp.json +7 -0
- package/.pi/pi-vcc-config.json +4 -0
- package/.pi/prompts/harness-setup.md +164 -15
- package/.pi/settings.json +2 -2
- package/CHANGELOG.md +16 -0
- package/CONTRIBUTING.md +1 -1
- package/firecrawl/.env.template +49 -45
- package/package.json +3 -4
- package/vault/wiki/concepts/vcc-conversation-compaction-for-pi.md +3 -1
- package/vault/wiki/decisions/2026-05-07-replace-lean-ctx-with-context-mode.md +59 -0
- package/vault/wiki/decisions/adr-027.md +94 -0
- package/vault/wiki/log.md +5 -1
- package/.pi/extensions/ck-enforce.ts +0 -216
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ck-enforce — intercepts grep tool calls and steers model to ck.
|
|
3
|
-
*
|
|
4
|
-
* Layer 2 of semantic search enforcement:
|
|
5
|
-
* Overrides lean-ctx's `grep` tool on session_start.
|
|
6
|
-
* Conceptual queries (multi-word, no regex) → BLOCKED with error
|
|
7
|
-
* steering model to use ck --hybrid directly.
|
|
8
|
-
* Literal/exact queries → native ripgrep via lean-ctx.
|
|
9
|
-
*
|
|
10
|
-
* Config (env vars):
|
|
11
|
-
* CK_ENFORCE_DISABLE — "true" to disable interception
|
|
12
|
-
* CK_ENFORCE_LOG — "true" to log reroutes to stderr
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
16
|
-
import { Type } from "@sinclair/typebox";
|
|
17
|
-
import {
|
|
18
|
-
existsSync,
|
|
19
|
-
} from "node:fs";
|
|
20
|
-
import { resolve } from "node:path";
|
|
21
|
-
import { execSync } from "node:child_process";
|
|
22
|
-
import { homedir } from "node:os";
|
|
23
|
-
|
|
24
|
-
// ── Config ──────────────────────────────────────────────────────
|
|
25
|
-
|
|
26
|
-
const DISABLED = process.env.CK_ENFORCE_DISABLE === "true";
|
|
27
|
-
const LOG_REROUTES = process.env.CK_ENFORCE_LOG === "true";
|
|
28
|
-
|
|
29
|
-
// ── Helpers ────────────────────────────────────────────────────
|
|
30
|
-
|
|
31
|
-
function shellQuote(value: string): string {
|
|
32
|
-
if (!value) return "''";
|
|
33
|
-
if (/^[A-Za-z0-9_./=:@,+%^-]+$/.test(value)) return value;
|
|
34
|
-
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function findBinary(name: string): string | null {
|
|
38
|
-
try {
|
|
39
|
-
return execSync(`which ${name}`, { encoding: "utf8", timeout: 5_000 }).trim() || null;
|
|
40
|
-
} catch {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function resolveLeanCtx(): string {
|
|
46
|
-
const home = homedir();
|
|
47
|
-
const candidates = [
|
|
48
|
-
resolve(home, ".cargo", "bin", "lean-ctx"),
|
|
49
|
-
resolve(home, ".local", "bin", "lean-ctx"),
|
|
50
|
-
"/usr/local/bin/lean-ctx",
|
|
51
|
-
];
|
|
52
|
-
for (const c of candidates) {
|
|
53
|
-
if (existsSync(c)) return c;
|
|
54
|
-
}
|
|
55
|
-
return "lean-ctx";
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// ── Heuristic ──────────────────────────────────────────────────
|
|
59
|
-
|
|
60
|
-
const REGEX_CHARS = /[\^\$\.\*\[\]\\|()+{}]/;
|
|
61
|
-
|
|
62
|
-
function isConceptualPattern(pattern: string): boolean {
|
|
63
|
-
if (REGEX_CHARS.test(pattern)) return false;
|
|
64
|
-
if (pattern.includes(" ")) return true;
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// ── grep schema ────────────────────────────────────────────────
|
|
69
|
-
|
|
70
|
-
const grepSchema = Type.Object({
|
|
71
|
-
pattern: Type.String({ description: "Search pattern (regex or literal string)" }),
|
|
72
|
-
path: Type.Optional(
|
|
73
|
-
Type.String({ description: "Directory or file to search (default: current directory)" }),
|
|
74
|
-
),
|
|
75
|
-
glob: Type.Optional(
|
|
76
|
-
Type.String({ description: "Filter files by glob pattern, e.g. '*.ts'" }),
|
|
77
|
-
),
|
|
78
|
-
ignoreCase: Type.Optional(
|
|
79
|
-
Type.Boolean({ description: "Case-insensitive search (default: false)" }),
|
|
80
|
-
),
|
|
81
|
-
literal: Type.Optional(
|
|
82
|
-
Type.Boolean({ description: "Treat pattern as literal string (default: false)" }),
|
|
83
|
-
),
|
|
84
|
-
context: Type.Optional(
|
|
85
|
-
Type.Number({ description: "Lines of context around each match (default: 0)" }),
|
|
86
|
-
),
|
|
87
|
-
limit: Type.Optional(
|
|
88
|
-
Type.Number({ description: "Maximum number of matches (default: 100)" }),
|
|
89
|
-
),
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
// ── Extension ──────────────────────────────────────────────────
|
|
93
|
-
|
|
94
|
-
export default async function ckEnforce(pi: ExtensionAPI) {
|
|
95
|
-
const ckPath = findBinary("ck");
|
|
96
|
-
if (!ckPath) {
|
|
97
|
-
console.log("[ck-enforce] ck not found in PATH — interception disabled");
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (DISABLED) {
|
|
102
|
-
console.log("[ck-enforce] Disabled via CK_ENFORCE_DISABLE=true");
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const leanCtxBin = resolveLeanCtx();
|
|
107
|
-
let grepRegistered = false;
|
|
108
|
-
|
|
109
|
-
// Status command
|
|
110
|
-
pi.registerCommand("ck-enforce", {
|
|
111
|
-
description: "Show ck-enforce status: ck path, grep interception",
|
|
112
|
-
handler: async (_args, ctx) => {
|
|
113
|
-
const lines = [
|
|
114
|
-
"ck-enforce status:",
|
|
115
|
-
` ck: ${ckPath}`,
|
|
116
|
-
` lean-ctx: ${leanCtxBin}`,
|
|
117
|
-
` grep interception: ${DISABLED ? "disabled" : "enabled"}`,
|
|
118
|
-
` grep registered: ${grepRegistered ? "yes" : "no (not yet)"}`,
|
|
119
|
-
` logging: ${LOG_REROUTES ? "on" : "off"}`,
|
|
120
|
-
"",
|
|
121
|
-
"Blocking heuristic:",
|
|
122
|
-
" Multi-word + no regex chars → BLOCKED (use ck --hybrid)",
|
|
123
|
-
" Single word / regex / literal=true / glob → native rg",
|
|
124
|
-
];
|
|
125
|
-
ctx.ui.notify(lines.join("\n"), "info");
|
|
126
|
-
},
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
// Register grep override on session_start
|
|
130
|
-
pi.on("session_start", () => {
|
|
131
|
-
if (grepRegistered) return;
|
|
132
|
-
grepRegistered = true;
|
|
133
|
-
|
|
134
|
-
pi.registerTool({
|
|
135
|
-
name: "grep",
|
|
136
|
-
label: "grep",
|
|
137
|
-
description:
|
|
138
|
-
"Search file contents. For exact/literal/regex patterns, uses ripgrep. " +
|
|
139
|
-
"Multi-word/conceptual queries are BLOCKED — use ck --hybrid instead. " +
|
|
140
|
-
"Use limit to cap matches and context for surrounding lines.",
|
|
141
|
-
promptSnippet: "Search file contents for patterns",
|
|
142
|
-
parameters: grepSchema,
|
|
143
|
-
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
144
|
-
const requestedPath = params.path || ".";
|
|
145
|
-
const absolutePath = resolve(ctx.cwd, requestedPath);
|
|
146
|
-
const limit = params.limit || 100;
|
|
147
|
-
const pattern = params.pattern;
|
|
148
|
-
|
|
149
|
-
const useCk =
|
|
150
|
-
!params.literal &&
|
|
151
|
-
!params.glob &&
|
|
152
|
-
!params.context &&
|
|
153
|
-
isConceptualPattern(pattern);
|
|
154
|
-
|
|
155
|
-
if (useCk) {
|
|
156
|
-
if (LOG_REROUTES) {
|
|
157
|
-
console.error(`[ck-enforce] BLOCKED: grep "${pattern}" → steer to ck`);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const suggestPath = requestedPath !== "." ? ` ${shellQuote(requestedPath)}` : " .";
|
|
161
|
-
const suggestLimit = limit !== 100 ? ` --limit ${limit}` : "";
|
|
162
|
-
const msg = [
|
|
163
|
-
`⛔ grep BLOCKED for multi-word/conceptual query: "${pattern}"`,
|
|
164
|
-
``,
|
|
165
|
-
`Use ck instead — grep is for exact literal matches only.`,
|
|
166
|
-
``,
|
|
167
|
-
`Suggested command:`,
|
|
168
|
-
` ck --hybrid "${pattern}"${suggestPath}${suggestLimit}`,
|
|
169
|
-
``,
|
|
170
|
-
`Options:`,
|
|
171
|
-
` ck --hybrid "query" path/ # semantic + lexical (default)`,
|
|
172
|
-
` ck --sem "concept" src/ # purely semantic`,
|
|
173
|
-
` ck --lex "exact" . # purely lexical`,
|
|
174
|
-
` grep pattern path/ --literal true # only for exact string matches`,
|
|
175
|
-
].join("\n");
|
|
176
|
-
|
|
177
|
-
throw new Error(msg);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// Native rg via lean-ctx
|
|
181
|
-
const rgArgs = ["rg", "--line-number", "--color=never"];
|
|
182
|
-
if (params.ignoreCase) rgArgs.push("-i");
|
|
183
|
-
if (params.literal) rgArgs.push("-F");
|
|
184
|
-
if (params.context && params.context > 0) rgArgs.push(`-C${params.context}`);
|
|
185
|
-
if (params.glob) rgArgs.push("--glob", params.glob);
|
|
186
|
-
if (limit > 0) rgArgs.push("-m", String(limit));
|
|
187
|
-
rgArgs.push(pattern, absolutePath);
|
|
188
|
-
|
|
189
|
-
try {
|
|
190
|
-
// pi.exec doesn't type-check env, but lean-ctx uses it at runtime
|
|
191
|
-
const execOpts = { env: { ...process.env, LEAN_CTX_COMPRESS: "1" } } as Record<string, unknown>;
|
|
192
|
-
const result = await pi.exec(leanCtxBin, ["-c", ...rgArgs], execOpts as Parameters<typeof pi.exec>[2]);
|
|
193
|
-
|
|
194
|
-
if (result.code === 1) {
|
|
195
|
-
return {
|
|
196
|
-
content: [{ type: "text", text: "" }],
|
|
197
|
-
details: { path: absolutePath, pattern, source: "lean-ctx-rg", rerouted: false },
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
if (result.code !== 0) {
|
|
202
|
-
throw new Error((result.stderr || result.stdout || "").trim());
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
return {
|
|
206
|
-
content: [{ type: "text", text: result.stdout }],
|
|
207
|
-
details: { path: absolutePath, pattern, source: "lean-ctx-rg", rerouted: false },
|
|
208
|
-
};
|
|
209
|
-
} catch (err) {
|
|
210
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
211
|
-
throw new Error(`grep failed: ${msg}`);
|
|
212
|
-
}
|
|
213
|
-
},
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
}
|