pi-creel 0.2.1 → 0.2.2
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 +17 -0
- package/package.json +1 -1
- package/src/capture.test.ts +12 -0
- package/src/capture.ts +9 -2
package/README.md
CHANGED
|
@@ -17,6 +17,23 @@ user pastes once, and the value goes straight from the popup into the target
|
|
|
17
17
|
- `name` — the environment-variable name, e.g. `OPENAI_API_KEY`.
|
|
18
18
|
- `dest` — path to the `.env` (relative to cwd), default `.env`.
|
|
19
19
|
|
|
20
|
+
## Consuming the secret
|
|
21
|
+
|
|
22
|
+
The value is written to `.env` mid-session, but the pi process env is frozen at
|
|
23
|
+
launch, so the model can't just read `process.env.NAME`. Two supported paths,
|
|
24
|
+
both of which keep the value out of the chat/context:
|
|
25
|
+
|
|
26
|
+
- **`creel exec NAME[,NAME2,...] -- <command>`** runs `<command>` with each
|
|
27
|
+
value in its environment **only** — never printed, never in argv, never in an
|
|
28
|
+
error (a missing key is a hard error naming just the key). This is the
|
|
29
|
+
language-agnostic way to hand a mid-session key to a child process
|
|
30
|
+
(`creel exec OPENAI_API_KEY -- node run.mjs`).
|
|
31
|
+
- **`process.env.NAME` after a relaunch**, once the new process inherits the
|
|
32
|
+
updated `.env`.
|
|
33
|
+
|
|
34
|
+
The model should **not** read the `.env` itself. The `added` / `updated` reply
|
|
35
|
+
from `request_secret` states this consumption path directly.
|
|
36
|
+
|
|
20
37
|
## Requirements
|
|
21
38
|
|
|
22
39
|
- A tmux session (`$TMUX`). Without one the tool fails fast and asks the user to
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-creel",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "request_secret for the pi coding agent: capture an API key into a local .env via a tmux popup (the creel tool) so it never enters the chat/context.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/src/capture.test.ts
CHANGED
|
@@ -33,3 +33,15 @@ test("tokenToText maps every outcome and never echoes a value", () => {
|
|
|
33
33
|
assert.match(tokenToText("", "K", ".env"), /Timed out/);
|
|
34
34
|
assert.match(tokenToText("weird", "K", ".env"), /unexpected status \(weird\)/);
|
|
35
35
|
});
|
|
36
|
+
|
|
37
|
+
test("a successful capture tells the model how to consume the secret", () => {
|
|
38
|
+
for (const token of ["added", "updated"]) {
|
|
39
|
+
const text = tokenToText(token, "TYPESAFE_API_KEY", ".env");
|
|
40
|
+
// Points at the containment path (creel exec) with the real var name...
|
|
41
|
+
assert.match(text, /creel exec TYPESAFE_API_KEY -- /);
|
|
42
|
+
// ...and the relaunch fallback...
|
|
43
|
+
assert.match(text, /process\.env\.TYPESAFE_API_KEY/);
|
|
44
|
+
// ...and steers the model away from reading the .env itself.
|
|
45
|
+
assert.match(text, /do not read|don't read/i);
|
|
46
|
+
}
|
|
47
|
+
});
|
package/src/capture.ts
CHANGED
|
@@ -46,11 +46,18 @@ export function tokenToText(
|
|
|
46
46
|
if (token === undefined || token === "") {
|
|
47
47
|
return `Timed out waiting for the creel popup; nothing was recorded for ${name}.`;
|
|
48
48
|
}
|
|
49
|
+
// howToUse tells the model the two supported ways to consume a mid-session
|
|
50
|
+
// secret without ever handling the value itself. It must never suggest
|
|
51
|
+
// reading the .env directly (the value must not enter the harness/context).
|
|
52
|
+
const howToUse =
|
|
53
|
+
` The value was not shown here. To use it, run \`creel exec ${name} -- <command>\`` +
|
|
54
|
+
` (that puts ${name} in the command's environment only), or read \`process.env.${name}\`` +
|
|
55
|
+
` after a relaunch. Do not read ${dest} yourself.`;
|
|
49
56
|
switch (token) {
|
|
50
57
|
case "added":
|
|
51
|
-
return `Added ${name} to ${dest} (chmod 600)
|
|
58
|
+
return `Added ${name} to ${dest} (chmod 600).` + howToUse;
|
|
52
59
|
case "updated":
|
|
53
|
-
return `Updated ${name} in ${dest}
|
|
60
|
+
return `Updated ${name} in ${dest}.` + howToUse;
|
|
54
61
|
case "cancelled":
|
|
55
62
|
return `Capture cancelled; nothing was written for ${name}.`;
|
|
56
63
|
default:
|