pi-caveman 1.0.7 → 1.0.9
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 +2 -2
- package/extensions/caveman.ts +43 -12
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -62,7 +62,7 @@ The config dialog lets you:
|
|
|
62
62
|
- **Default level** — Set a level that activates automatically on every new session (e.g. `full` to always start in caveman mode)
|
|
63
63
|
- **Show status bar** — Toggle the animated campfire indicator in the footer
|
|
64
64
|
|
|
65
|
-
Settings are saved to `~/.pi/agent/caveman.json` and persist across all sessions.
|
|
65
|
+
Settings are saved to `~/.pi/agent/caveman.json` by default and persist across all sessions. If `XDG_CONFIG_HOME` is set, the path becomes `$XDG_CONFIG_HOME/pi/agent/caveman.json`; `PI_CODING_AGENT_DIR` overrides both.
|
|
66
66
|
|
|
67
67
|
### Status Bar
|
|
68
68
|
|
|
@@ -82,7 +82,7 @@ When active, a status bar displays caveman level and an animated campfire flicke
|
|
|
82
82
|
|
|
83
83
|
## How It Works
|
|
84
84
|
|
|
85
|
-
The extension hooks `before_agent_start` to append caveman communication rules to the system prompt at the selected intensity. Within a session, the active level is stored as a custom session entry and restored on resume. Across sessions, persistent config (`~/.pi/agent/caveman.json`) provides the default level and status bar preference. Auto-clarity rules tell the model to drop caveman mode for security warnings or irreversible actions.
|
|
85
|
+
The extension hooks `before_agent_start` to append caveman communication rules to the system prompt at the selected intensity. Within a session, the active level is stored as a custom session entry and restored on resume. Across sessions, persistent config (`~/.pi/agent/caveman.json` by default, or `$XDG_CONFIG_HOME/pi/agent/caveman.json` when `XDG_CONFIG_HOME` is set; `PI_CODING_AGENT_DIR` overrides both) provides the default level and status bar preference. Auto-clarity rules tell the model to drop caveman mode for security warnings or irreversible actions.
|
|
86
86
|
|
|
87
87
|
## Warning
|
|
88
88
|
|
package/extensions/caveman.ts
CHANGED
|
@@ -13,7 +13,11 @@
|
|
|
13
13
|
import { readFile, writeFile, mkdir } from "node:fs/promises";
|
|
14
14
|
import { homedir } from "node:os";
|
|
15
15
|
import { join } from "node:path";
|
|
16
|
-
import type {
|
|
16
|
+
import type {
|
|
17
|
+
BeforeAgentStartEventResult,
|
|
18
|
+
ExtensionAPI,
|
|
19
|
+
ExtensionContext,
|
|
20
|
+
} from "@earendil-works/pi-coding-agent";
|
|
17
21
|
import { getSettingsListTheme } from "@earendil-works/pi-coding-agent";
|
|
18
22
|
import { Container, type SettingItem, SettingsList, Text } from "@earendil-works/pi-tui";
|
|
19
23
|
|
|
@@ -43,6 +47,18 @@ const CAVEMAN_COMMAND_OPTIONS = [
|
|
|
43
47
|
// Persistent config (survives across sessions)
|
|
44
48
|
// ---------------------------------------------------------------------------
|
|
45
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Resolve the pi agent config directory, mirroring pi itself and pi-web-access:
|
|
52
|
+
* 1. PI_CODING_AGENT_DIR env override (already points at the agent dir)
|
|
53
|
+
* 2. $XDG_CONFIG_HOME/pi/agent
|
|
54
|
+
* 3. ~/.pi/agent
|
|
55
|
+
*/
|
|
56
|
+
function getConfigDir(): string {
|
|
57
|
+
if (process.env.PI_CODING_AGENT_DIR) return process.env.PI_CODING_AGENT_DIR;
|
|
58
|
+
if (process.env.XDG_CONFIG_HOME) return join(process.env.XDG_CONFIG_HOME, "pi", "agent");
|
|
59
|
+
return join(homedir(), ".pi", "agent");
|
|
60
|
+
}
|
|
61
|
+
|
|
46
62
|
interface CavemanConfig {
|
|
47
63
|
/** Level to apply on new sessions. "off" means don't auto-enable. */
|
|
48
64
|
defaultLevel: Level;
|
|
@@ -50,7 +66,7 @@ interface CavemanConfig {
|
|
|
50
66
|
showStatus: boolean;
|
|
51
67
|
}
|
|
52
68
|
|
|
53
|
-
const CONFIG_PATH = join(
|
|
69
|
+
const CONFIG_PATH = join(getConfigDir(), "caveman.json");
|
|
54
70
|
const DEFAULT_CONFIG: CavemanConfig = { defaultLevel: "full", showStatus: true };
|
|
55
71
|
let saveConfigQueue: Promise<void> = Promise.resolve();
|
|
56
72
|
|
|
@@ -70,7 +86,7 @@ async function loadConfig(): Promise<CavemanConfig> {
|
|
|
70
86
|
async function saveConfig(config: CavemanConfig): Promise<void> {
|
|
71
87
|
const snapshot = JSON.stringify(config, null, 2) + "\n";
|
|
72
88
|
saveConfigQueue = saveConfigQueue.then(async () => {
|
|
73
|
-
await mkdir(
|
|
89
|
+
await mkdir(getConfigDir(), { recursive: true });
|
|
74
90
|
await writeFile(CONFIG_PATH, snapshot, "utf8");
|
|
75
91
|
});
|
|
76
92
|
return saveConfigQueue;
|
|
@@ -172,6 +188,18 @@ Auto-clarity: drop caveman for security warnings, irreversible action confirmati
|
|
|
172
188
|
or when user is confused. Resume after.
|
|
173
189
|
Boundaries: write normal code. Only compress explanations. "stop caveman" or "normal mode" reverts.`;
|
|
174
190
|
|
|
191
|
+
/** OMP passes ordered string[] blocks; upstream Pi passes one string. */
|
|
192
|
+
function appendSystemPrompt(
|
|
193
|
+
systemPrompt: string | string[] | null | undefined,
|
|
194
|
+
addition: string,
|
|
195
|
+
): string | string[] {
|
|
196
|
+
if (Array.isArray(systemPrompt)) {
|
|
197
|
+
return [...systemPrompt, addition];
|
|
198
|
+
}
|
|
199
|
+
const basePrompt = typeof systemPrompt === "string" ? systemPrompt : String(systemPrompt ?? "");
|
|
200
|
+
return basePrompt ? `${basePrompt}\n\n${addition}` : addition;
|
|
201
|
+
}
|
|
202
|
+
|
|
175
203
|
// ---------------------------------------------------------------------------
|
|
176
204
|
// Extension
|
|
177
205
|
// ---------------------------------------------------------------------------
|
|
@@ -208,13 +236,16 @@ export default function caveman(pi: ExtensionAPI) {
|
|
|
208
236
|
|
|
209
237
|
function syncStatus(ctx: Pick<ExtensionContext, "ui">) {
|
|
210
238
|
stopAnimation();
|
|
211
|
-
const theme = ctx.ui.theme;
|
|
212
239
|
|
|
213
240
|
if (level === "off" || !config.showStatus) {
|
|
214
241
|
ctx.ui.setStatus("caveman", "");
|
|
215
242
|
return;
|
|
216
243
|
}
|
|
217
244
|
|
|
245
|
+
// Hosts like pi-web-ui expose setStatus without a TUI theme — bail instead of throwing on theme.fg.
|
|
246
|
+
if (!ctx.ui.theme?.fg) return;
|
|
247
|
+
const theme = ctx.ui.theme;
|
|
248
|
+
|
|
218
249
|
const anim = ANIMATIONS[level];
|
|
219
250
|
const setFrame = (frame: string) => {
|
|
220
251
|
ctx.ui.setStatus("caveman", frame + " " + theme.fg("muted", "caveman level: ") + theme.fg("text", anim.label));
|
|
@@ -336,7 +367,7 @@ export default function caveman(pi: ExtensionAPI) {
|
|
|
336
367
|
|
|
337
368
|
const container = new Container();
|
|
338
369
|
container.addChild(new Text(theme.fg("accent", theme.bold(" Caveman Config")), 0, 0));
|
|
339
|
-
container.addChild(new Text(theme.fg("dim",
|
|
370
|
+
container.addChild(new Text(theme.fg("dim", ` Saved to ${CONFIG_PATH}`), 0, 0));
|
|
340
371
|
container.addChild(new Text(theme.fg("dim", " Default level applies to future sessions."), 0, 0));
|
|
341
372
|
container.addChild(new Text("", 0, 0));
|
|
342
373
|
|
|
@@ -406,13 +437,13 @@ export default function caveman(pi: ExtensionAPI) {
|
|
|
406
437
|
pi.on("before_agent_start", async (event) => {
|
|
407
438
|
await ensureConfigLoaded();
|
|
408
439
|
if (level === "off") return;
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
systemPrompt: `${event.systemPrompt}\n\n${MICRO_PROMPT}`,
|
|
412
|
-
};
|
|
413
|
-
}
|
|
440
|
+
const addition =
|
|
441
|
+
level === "micro" ? MICRO_PROMPT : `${BASE}\n\n${INTENSITY[level]}\n\n${SAFETY}`;
|
|
414
442
|
return {
|
|
415
|
-
systemPrompt:
|
|
416
|
-
|
|
443
|
+
systemPrompt: appendSystemPrompt(
|
|
444
|
+
event.systemPrompt as string | string[] | null | undefined,
|
|
445
|
+
addition,
|
|
446
|
+
),
|
|
447
|
+
} as unknown as BeforeAgentStartEventResult;
|
|
417
448
|
});
|
|
418
449
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-caveman",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Why use many token when few do trick. Caveman mode for pi
|
|
3
|
+
"version": "1.0.9",
|
|
4
|
+
"description": "Why use many token when few do trick. Caveman mode for pi — cuts ~75% output tokens while keeping full technical accuracy.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
7
7
|
"pi-extension",
|