@leolastforce/chalice-basics 0.0.0-stage → 0.1.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/README.md +82 -2
- package/index.ts +141 -0
- package/package.json +35 -5
package/README.md
CHANGED
|
@@ -1,3 +1,83 @@
|
|
|
1
|
-
|
|
1
|
+
> This is a chalice package, check out github.com/leolastforce/Chalice
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# Basics (yes thats the extension name not an introduction.. or well it kind of is lol)
|
|
4
|
+
|
|
5
|
+
> Text past here is generated docs:
|
|
6
|
+
|
|
7
|
+
Quality-of-life commands that stock Pi 1.7 no longer ships, plus the username section in the
|
|
8
|
+
system prompt. Three slash commands, two settings, and the profile section in `/chalicesettings`.
|
|
9
|
+
Works on stock Pi and installs on its own.
|
|
10
|
+
|
|
11
|
+
## Commands
|
|
12
|
+
|
|
13
|
+
| Command | Effect |
|
|
14
|
+
|---|---|
|
|
15
|
+
| `/changename <name>` | Set the name the model addresses you by. With no argument, show the current name and whether it is sent to the model. If sending was disabled, setting a name re-enables it. |
|
|
16
|
+
| `/username on\|off` | Enable or disable sending the name in model requests. With no argument, show the current state. |
|
|
17
|
+
| `/delete` | Delete the current session file and start a new session. |
|
|
18
|
+
|
|
19
|
+
`/delete` tries the `trash` command first so the session stays recoverable, and falls back to a
|
|
20
|
+
plain file delete when `trash` is unavailable. If there is no session file it just starts a new
|
|
21
|
+
session; if Pi cancels the new session, nothing is deleted; if deletion fails, the new session
|
|
22
|
+
still starts and the error is reported as a warning.
|
|
23
|
+
|
|
24
|
+
## Username in the system prompt
|
|
25
|
+
|
|
26
|
+
On `before_agent_start`, when `usernameEnabled` is true and a non-empty name is set, the module
|
|
27
|
+
adds `Username: <name>` to `systemPromptOptions.sections.user`. Settings are read on every turn,
|
|
28
|
+
so toggling the name takes effect on the next request without restarting the session.
|
|
29
|
+
|
|
30
|
+
Other Chalice modules read the same value through `@leolastforce/chalice-shared`. For example,
|
|
31
|
+
the header screen shows `Welcome back, <name>` when this module is installed and the name is set.
|
|
32
|
+
|
|
33
|
+
## Settings
|
|
34
|
+
|
|
35
|
+
The **Profile** section of `/chalicesettings` exposes both keys when `chalice-settings` is
|
|
36
|
+
installed. They live under `chalice` in `~/.pi/agent/settings.json`, or in a trusted project's
|
|
37
|
+
`.pi/settings.json`.
|
|
38
|
+
|
|
39
|
+
| Key | Type | Default | Effect |
|
|
40
|
+
|---|---|---|---|
|
|
41
|
+
| `username` | string | unset | The name sent to the model and shown in the header. |
|
|
42
|
+
| `usernameEnabled` | boolean | `true` | Whether to include the name in the system prompt. |
|
|
43
|
+
|
|
44
|
+
```json
|
|
45
|
+
{
|
|
46
|
+
"chalice": {
|
|
47
|
+
"username": "Leo",
|
|
48
|
+
"usernameEnabled": true
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The old top-level `username` and `usernameEnabled` keys are still read as a fallback. Writing a
|
|
54
|
+
value through `/chalicesettings` moves it into the `chalice` namespace and removes the legacy key,
|
|
55
|
+
so a later delete cannot resurrect it. Every write is serialized with a lock compatible with Pi's
|
|
56
|
+
own settings writes, then announced on `chalice:settings-changed`.
|
|
57
|
+
|
|
58
|
+
## Standalone behavior
|
|
59
|
+
|
|
60
|
+
- No other Chalice module is required. Without `chalice-settings`, the section registration is a
|
|
61
|
+
no-op — use the slash commands or edit the JSON file.
|
|
62
|
+
- The system-prompt section is added in every Pi mode where an agent turn starts; commands are
|
|
63
|
+
registered wherever Pi exposes slash commands.
|
|
64
|
+
- Registering the settings section is an event-bus subscription, so adding or removing other
|
|
65
|
+
Chalice modules never changes how this one behaves.
|
|
66
|
+
|
|
67
|
+
## Source layout
|
|
68
|
+
|
|
69
|
+
All of it is in `index.ts`: the settings section, the three commands, the `before_agent_start`
|
|
70
|
+
handler, and the session-file deletion helper. There are no assets or prompts.
|
|
71
|
+
|
|
72
|
+
## Development
|
|
73
|
+
|
|
74
|
+
From the repo root:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
./distro/run-tui.sh # launch the distro with this module
|
|
78
|
+
node distro/harness.mjs # load every package alone and together
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## License
|
|
82
|
+
|
|
83
|
+
MIT.
|
package/index.ts
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { unlink } from "node:fs/promises";
|
|
4
|
+
import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
5
|
+
import {
|
|
6
|
+
getUsername,
|
|
7
|
+
isUsernameEnabled,
|
|
8
|
+
readChaliceSettings,
|
|
9
|
+
registerChaliceSettingsSection,
|
|
10
|
+
type ChaliceSettingsSection,
|
|
11
|
+
updateChaliceSettings,
|
|
12
|
+
} from "@leolastforce/chalice-shared";
|
|
13
|
+
|
|
14
|
+
const PROFILE_SECTION: ChaliceSettingsSection = {
|
|
15
|
+
id: "profile",
|
|
16
|
+
title: "Profile",
|
|
17
|
+
description: "How the model addresses you.",
|
|
18
|
+
order: 20,
|
|
19
|
+
items: [
|
|
20
|
+
{
|
|
21
|
+
id: "username",
|
|
22
|
+
type: "string",
|
|
23
|
+
key: "username",
|
|
24
|
+
label: "Your name",
|
|
25
|
+
description: "The model uses your name to know how to address you.",
|
|
26
|
+
defaultValue: "",
|
|
27
|
+
placeholder: "Your name",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
id: "username-enabled",
|
|
31
|
+
type: "boolean",
|
|
32
|
+
key: "usernameEnabled",
|
|
33
|
+
label: "Send name to model",
|
|
34
|
+
description: "Include your name in the system prompt.",
|
|
35
|
+
defaultValue: true,
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Chalice's fork-only builtin commands that stock Pi 1.7 no longer ships:
|
|
42
|
+
* `/changename`, `/username`, and `/delete`. Also restores the username
|
|
43
|
+
* section in the system prompt (the fork injected `Username: <name>`).
|
|
44
|
+
*/
|
|
45
|
+
export default function chaliceBasics(pi: ExtensionAPI) {
|
|
46
|
+
registerChaliceSettingsSection(pi, PROFILE_SECTION);
|
|
47
|
+
|
|
48
|
+
pi.registerCommand("changename", {
|
|
49
|
+
description: "Set your name (how the model addresses you)",
|
|
50
|
+
handler: async (args: string, ctx: ExtensionCommandContext) => {
|
|
51
|
+
const name = args.trim();
|
|
52
|
+
const settings = readChaliceSettings(ctx);
|
|
53
|
+
if (!name) {
|
|
54
|
+
const current = getUsername(settings);
|
|
55
|
+
if (!current) {
|
|
56
|
+
ctx.ui.notify("Usage: /changename <name>", "warning");
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const note = isUsernameEnabled(settings)
|
|
60
|
+
? "sent to the model"
|
|
61
|
+
: "not sent to the model (enable with /username on)";
|
|
62
|
+
ctx.ui.notify(`Your name is ${current} (${note})`, "info");
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const wasEnabled = isUsernameEnabled(settings);
|
|
67
|
+
updateChaliceSettings(pi, wasEnabled ? { username: name } : { username: name, usernameEnabled: true });
|
|
68
|
+
ctx.ui.notify(
|
|
69
|
+
wasEnabled ? `Name set to ${name}` : `Name set to ${name}. Username was disabled — re-enabled.`,
|
|
70
|
+
"info",
|
|
71
|
+
);
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
pi.registerCommand("username", {
|
|
76
|
+
description: "Enable or disable your name in model requests",
|
|
77
|
+
handler: async (args: string, ctx: ExtensionCommandContext) => {
|
|
78
|
+
const values = args.trim().toLowerCase();
|
|
79
|
+
const settings = readChaliceSettings(ctx);
|
|
80
|
+
const current = getUsername(settings);
|
|
81
|
+
if (!values) {
|
|
82
|
+
const state = isUsernameEnabled(settings) ? "on" : "off";
|
|
83
|
+
ctx.ui.notify(
|
|
84
|
+
`Username is ${state}${current ? ` (${current})` : ""}. Use /username on|off, or /changename <name>.`,
|
|
85
|
+
"info",
|
|
86
|
+
);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (values !== "on" && values !== "off") {
|
|
90
|
+
ctx.ui.notify("Usage: /username on|off", "warning");
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
updateChaliceSettings(pi, { usernameEnabled: values === "on" });
|
|
94
|
+
ctx.ui.notify(`Username ${values === "on" ? "enabled" : "disabled"}.`, "info");
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
pi.registerCommand("delete", {
|
|
99
|
+
description: "Delete the current session and start a new one",
|
|
100
|
+
handler: async (_args: string, ctx: ExtensionCommandContext) => {
|
|
101
|
+
const sessionFile = ctx.sessionManager.getSessionFile();
|
|
102
|
+
const result = await ctx.newSession({
|
|
103
|
+
withSession: async (next) => {
|
|
104
|
+
if (!sessionFile) {
|
|
105
|
+
next.ui.notify("New session started (nothing to delete)", "info");
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const deletion = await deleteSessionFile(sessionFile);
|
|
109
|
+
if (deletion.ok) next.ui.notify("Session deleted; new session started", "info");
|
|
110
|
+
else next.ui.notify(`New session started, but failed to delete the previous session: ${deletion.error ?? "unknown error"}`, "warning");
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
if (result.cancelled) ctx.ui.notify("Session delete cancelled", "warning");
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// Restore the fork's `Username: <name>` system-prompt section.
|
|
118
|
+
pi.on("before_agent_start", (event, ctx) => {
|
|
119
|
+
const settings = readChaliceSettings(ctx);
|
|
120
|
+
if (!isUsernameEnabled(settings)) return;
|
|
121
|
+
const username = getUsername(settings);
|
|
122
|
+
if (!username) return;
|
|
123
|
+
event.systemPromptOptions.sections = { ...event.systemPromptOptions.sections, user: `Username: ${username}` };
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function deleteSessionFile(sessionPath: string): Promise<{ ok: boolean; error?: string }> {
|
|
128
|
+
// Prefer trash so a deleted session stays recoverable.
|
|
129
|
+
const trashArgs = sessionPath.startsWith("-") ? ["--", sessionPath] : [sessionPath];
|
|
130
|
+
const trashResult = spawnSync("trash", trashArgs, { encoding: "utf-8" });
|
|
131
|
+
if (trashResult.status === 0 || !existsSync(sessionPath)) return { ok: true };
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
await unlink(sessionPath);
|
|
135
|
+
return { ok: true };
|
|
136
|
+
} catch (error) {
|
|
137
|
+
const unlinkError = error instanceof Error ? error.message : String(error);
|
|
138
|
+
const trashError = trashResult.error?.message ?? trashResult.stderr?.trim().split("\n")[0];
|
|
139
|
+
return { ok: false, error: trashError ? `${trashError} · ${unlinkError}` : unlinkError };
|
|
140
|
+
}
|
|
141
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@leolastforce/chalice-basics",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Chalice module for QOL, includes things like: /changename, /delete",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"chalice",
|
|
9
|
+
"pi-package"
|
|
10
|
+
],
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@leolastforce/chalice-shared": "0.1.0"
|
|
13
|
+
},
|
|
14
|
+
"pi": {
|
|
15
|
+
"extensions": [
|
|
16
|
+
"./index.ts"
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"index.ts"
|
|
21
|
+
],
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"@earendil-works/pi-coding-agent": "*"
|
|
24
|
+
},
|
|
25
|
+
"peerDependenciesMeta": {
|
|
26
|
+
"@earendil-works/pi-coding-agent": {
|
|
27
|
+
"optional": true
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=22.19.0"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
}
|
|
36
|
+
}
|