herdr-secret 0.1.2 → 0.2.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 +24 -15
- package/cli.js +41 -11
- package/engine/agents/SKILL.md +68 -0
- package/engine/agents/instructions.md +8 -0
- package/engine/bin/herdr-secret +8 -0
- package/engine/bin/herdr-secret.cmd +12 -0
- package/engine/bin/herdr_secret.py +1713 -0
- package/engine/herdr-plugin.toml +67 -0
- package/engine/mods/herdr-secret/main.js +221 -0
- package/engine/mods/herdr-secret/mod.json +1 -0
- package/package.json +6 -3
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
id = "mazemaker.secret"
|
|
2
|
+
name = "herdr-secret"
|
|
3
|
+
version = "0.2.0"
|
|
4
|
+
min_herdr_version = "0.9.5"
|
|
5
|
+
description = "A form popup where coding agents ask you for credentials. Values go straight to the OS credential store; the agent only learns OK or CANCELLED."
|
|
6
|
+
platforms = ["linux", "macos", "windows"]
|
|
7
|
+
|
|
8
|
+
# The credential form an agent opens with `herdr-secret ask`.
|
|
9
|
+
[[panes]]
|
|
10
|
+
id = "ask"
|
|
11
|
+
title = "Credential request"
|
|
12
|
+
placement = "popup"
|
|
13
|
+
width = 76
|
|
14
|
+
height = 24
|
|
15
|
+
platforms = ["linux", "macos"]
|
|
16
|
+
command = ["python3", "-I", "bin/herdr_secret.py", "form"]
|
|
17
|
+
|
|
18
|
+
[[panes]]
|
|
19
|
+
id = "ask-windows"
|
|
20
|
+
title = "Credential request"
|
|
21
|
+
placement = "popup"
|
|
22
|
+
width = 76
|
|
23
|
+
height = 24
|
|
24
|
+
platforms = ["windows"]
|
|
25
|
+
command = ["cmd", "/d", "/c", "bin\\herdr-secret.cmd", "form"]
|
|
26
|
+
|
|
27
|
+
# The interactive setup.
|
|
28
|
+
[[panes]]
|
|
29
|
+
id = "setup"
|
|
30
|
+
title = "herdr-secret setup"
|
|
31
|
+
placement = "popup"
|
|
32
|
+
width = "80%"
|
|
33
|
+
height = "85%"
|
|
34
|
+
platforms = ["linux", "macos"]
|
|
35
|
+
command = ["python3", "-I", "bin/herdr_secret.py", "setup"]
|
|
36
|
+
|
|
37
|
+
[[panes]]
|
|
38
|
+
id = "setup-windows"
|
|
39
|
+
title = "herdr-secret setup"
|
|
40
|
+
placement = "popup"
|
|
41
|
+
width = "80%"
|
|
42
|
+
height = "85%"
|
|
43
|
+
platforms = ["windows"]
|
|
44
|
+
command = ["cmd", "/d", "/c", "bin\\herdr-secret.cmd", "setup"]
|
|
45
|
+
|
|
46
|
+
[[actions]]
|
|
47
|
+
id = "setup"
|
|
48
|
+
title = "herdr-secret: run setup"
|
|
49
|
+
contexts = ["workspace"]
|
|
50
|
+
platforms = ["linux", "macos"]
|
|
51
|
+
command = ["python3", "-I", "bin/herdr_secret.py", "open-setup"]
|
|
52
|
+
|
|
53
|
+
[[actions]]
|
|
54
|
+
id = "setup-windows"
|
|
55
|
+
title = "herdr-secret: run setup"
|
|
56
|
+
contexts = ["workspace"]
|
|
57
|
+
platforms = ["windows"]
|
|
58
|
+
command = ["cmd", "/d", "/c", "bin\\herdr-secret.cmd", "open-setup"]
|
|
59
|
+
|
|
60
|
+
# If the plugin was installed without the installer script, open setup once when herdr starts.
|
|
61
|
+
[[startup]]
|
|
62
|
+
platforms = ["linux", "macos"]
|
|
63
|
+
command = ["python3", "-I", "bin/herdr_secret.py", "startup"]
|
|
64
|
+
|
|
65
|
+
[[startup]]
|
|
66
|
+
platforms = ["windows"]
|
|
67
|
+
command = ["cmd", "/d", "/c", "bin\\herdr-secret.cmd", "startup"]
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
// herdr-secret for Herdr.app: the dialog an agent's `herdr-secret ask` opens.
|
|
2
|
+
//
|
|
3
|
+
// The request (who asks, what for, which fields, a one-time pad) comes from a file the
|
|
4
|
+
// herdr-secret engine writes in its 0700 state folder. Herdr.app mods can hand data to programs
|
|
5
|
+
// only as arguments, which other processes can list, so each typed value leaves this dialog
|
|
6
|
+
// XORed with its slice of the pad, as hex. The engine undoes that, stores the value in the OS
|
|
7
|
+
// credential store and deletes the request, pad included. Every answer ends the request, so the
|
|
8
|
+
// pad never covers two values. The agent only ever learns OK, CANCELLED, TIMEOUT or FAILED.
|
|
9
|
+
import { View, div } from "gpui-kit";
|
|
10
|
+
import { v_flex, h_flex, InputState, Input } from "gpui-base";
|
|
11
|
+
import { exec, home, props, closeOverlay, theme, readTextFile, playSound, setBadge, checking, notify } from "herdr";
|
|
12
|
+
|
|
13
|
+
const REQUEST = "/.local/state/herdr-secret/app-request.json";
|
|
14
|
+
const PAD_PER_FIELD = 4096;
|
|
15
|
+
const CONTROL = /[\u0000-\u001f\u007f-\u009f]/;
|
|
16
|
+
|
|
17
|
+
// What `herdr-app check` renders: the form, without reading a request or running anything.
|
|
18
|
+
const SAMPLE = {
|
|
19
|
+
req: "check", name: "DB_LOGIN", purpose: "Staging database, read-only user", from: "terminal t1",
|
|
20
|
+
fields: [{ name: "username", label: "Username", hidden: false }, { name: "password", label: "Password", hidden: true }],
|
|
21
|
+
store: "macOS Keychain (encrypted) · never sent to the agent's chat", encrypted: true,
|
|
22
|
+
replaces: [], deadline: 0, max: 1000, pad: "", python: "", script: "",
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function utf8(text) {
|
|
26
|
+
const out = [];
|
|
27
|
+
for (const ch of text) {
|
|
28
|
+
const c = ch.codePointAt(0);
|
|
29
|
+
if (c < 0x80) out.push(c);
|
|
30
|
+
else if (c < 0x800) out.push(0xc0 | (c >> 6), 0x80 | (c & 63));
|
|
31
|
+
else if (c < 0x10000) out.push(0xe0 | (c >> 12), 0x80 | ((c >> 6) & 63), 0x80 | (c & 63));
|
|
32
|
+
else out.push(0xf0 | (c >> 18), 0x80 | ((c >> 12) & 63), 0x80 | ((c >> 6) & 63), 0x80 | (c & 63));
|
|
33
|
+
}
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function padded(text, padHex, field) {
|
|
38
|
+
const bytes = utf8(text);
|
|
39
|
+
let hex = "";
|
|
40
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
41
|
+
const at = 2 * (field * PAD_PER_FIELD + i);
|
|
42
|
+
const b = bytes[i] ^ parseInt(padHex.slice(at, at + 2), 16);
|
|
43
|
+
hex += (b < 16 ? "0" : "") + b.toString(16);
|
|
44
|
+
}
|
|
45
|
+
return hex;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default class Secret extends View {
|
|
49
|
+
init(_props, cx) {
|
|
50
|
+
this.state = "loading"; // loading | empty | form | saving | failed
|
|
51
|
+
this.error = "";
|
|
52
|
+
this.finished = false;
|
|
53
|
+
this.inputs = [];
|
|
54
|
+
this.revealed = [];
|
|
55
|
+
this.focusIndex = 0;
|
|
56
|
+
this.handle = cx.focus_handle();
|
|
57
|
+
if (checking()) {
|
|
58
|
+
this.show(SAMPLE);
|
|
59
|
+
this.finished = true; // nothing to answer
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
cx.spawn(async (cx) => {
|
|
63
|
+
let r = null;
|
|
64
|
+
try { r = JSON.parse((await readTextFile(home() + REQUEST)) || "null"); } catch (_e) { r = null; }
|
|
65
|
+
if (!r || !Array.isArray(r.fields) || r.deadline * 1000 <= Date.now()) {
|
|
66
|
+
this.state = "empty";
|
|
67
|
+
cx.notify();
|
|
68
|
+
// mod.open toggles, so a dialog left open would swallow the next request: close by itself.
|
|
69
|
+
cx.timer.after(4000, () => closeOverlay(props().overlay));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
this.show(r);
|
|
73
|
+
cx.notify();
|
|
74
|
+
playSound("blocked");
|
|
75
|
+
setBadge("1");
|
|
76
|
+
cx.timer.after(120, () => this.inputs[0]?.focus());
|
|
77
|
+
cx.timer.after(Math.max(0, r.deadline * 1000 - Date.now()), (cx) => this.finish("TIMEOUT", cx));
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
show(r) {
|
|
82
|
+
this.req = r;
|
|
83
|
+
this.inputs = r.fields.map((f, i) => {
|
|
84
|
+
const s = InputState.new({});
|
|
85
|
+
s.set_masked(Boolean(f.hidden));
|
|
86
|
+
s.on("submit", (_e, cx) => this.next(i, cx));
|
|
87
|
+
s.on("change", (_e, cx) => { if (this.error) { this.error = ""; cx.notify(); } });
|
|
88
|
+
s.on("focus", (_e, cx) => { this.focusIndex = i; cx.notify(); });
|
|
89
|
+
return s;
|
|
90
|
+
});
|
|
91
|
+
this.revealed = r.fields.map(() => false);
|
|
92
|
+
this.state = "form";
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
next(i, cx) {
|
|
96
|
+
if (i + 1 < this.inputs.length) this.inputs[i + 1].focus();
|
|
97
|
+
else this.save(cx);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
key(e, cx) {
|
|
101
|
+
if (e.key === "tab" && this.inputs.length) {
|
|
102
|
+
const step = e.modifiers?.shift ? -1 : 1;
|
|
103
|
+
const n = this.inputs.length;
|
|
104
|
+
this.inputs[(this.focusIndex + step + n) % n].focus();
|
|
105
|
+
cx.stop_propagation();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
toggle(i, cx) {
|
|
110
|
+
this.revealed[i] = !this.revealed[i];
|
|
111
|
+
this.inputs[i].set_masked(!this.revealed[i]);
|
|
112
|
+
cx.notify();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
save(cx) {
|
|
116
|
+
const r = this.req;
|
|
117
|
+
if (!r || this.state !== "form" || this.finished) return;
|
|
118
|
+
const values = this.inputs.map((s) => s.value());
|
|
119
|
+
const bad = values.findIndex((v) => !v);
|
|
120
|
+
if (bad >= 0) { this.error = "All fields are required."; this.inputs[bad].focus(); cx.notify(); return; }
|
|
121
|
+
if (values.some((v) => [...v].length > r.max)) { this.error = `Too long (max ${r.max} characters).`; cx.notify(); return; }
|
|
122
|
+
if (values.some((v) => CONTROL.test(v))) { this.error = "Control characters are not allowed."; cx.notify(); return; }
|
|
123
|
+
const hexes = values.map((v, i) => padded(v, r.pad, i));
|
|
124
|
+
this.state = "saving";
|
|
125
|
+
cx.notify();
|
|
126
|
+
cx.spawn(async (cx) => {
|
|
127
|
+
let out = "";
|
|
128
|
+
let code = 1;
|
|
129
|
+
try {
|
|
130
|
+
const res = await exec(r.python, ["-I", r.script, "app-store", r.req, ...hexes], { timeout: 30000 });
|
|
131
|
+
out = res.stdout.trim();
|
|
132
|
+
code = res.code;
|
|
133
|
+
} catch (e) {
|
|
134
|
+
out = "FAILED " + String(e);
|
|
135
|
+
}
|
|
136
|
+
this.finished = true; // app-store ends the request whatever it answers
|
|
137
|
+
for (const s of this.inputs) s.set_value("");
|
|
138
|
+
setBadge(null);
|
|
139
|
+
if (code === 0 && out.startsWith("OK")) {
|
|
140
|
+
notify({ title: `Saved ${r.name}`, body: `In ${out.slice(3)}. The agent only learns that you answered.`, level: "success" });
|
|
141
|
+
closeOverlay(props().overlay);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
this.state = "failed";
|
|
145
|
+
this.error = out.replace(/^FAILED ?/, "") || "Could not save.";
|
|
146
|
+
cx.notify();
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
finish(kind, _cx) {
|
|
151
|
+
if (this.finished || !this.req) return;
|
|
152
|
+
this.finished = true;
|
|
153
|
+
const args = ["-I", this.req.script, "app-cancel", this.req.req];
|
|
154
|
+
if (kind === "TIMEOUT") args.push("TIMEOUT");
|
|
155
|
+
exec(this.req.python, args).catch(() => null);
|
|
156
|
+
setBadge(null);
|
|
157
|
+
closeOverlay(props().overlay);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async close(_cx) {
|
|
161
|
+
setBadge(null);
|
|
162
|
+
if (this.finished || !this.req) return;
|
|
163
|
+
this.finished = true; // Esc or a closed window: the human said no
|
|
164
|
+
await exec(this.req.python, ["-I", this.req.script, "app-cancel", this.req.req]).catch(() => null);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
render() {
|
|
168
|
+
const t = theme();
|
|
169
|
+
const r = this.req;
|
|
170
|
+
const label = (text) => div().pt(14).pb(6).text_size(11.5).text_color(t.dim).child(text);
|
|
171
|
+
const button = (id, text, primary, action) => h_flex().id(id).h(32).px(14).items_center().rounded(8)
|
|
172
|
+
.border_1().border_color(primary ? t.solid : t.input).bg(primary ? t.solid : t.raised)
|
|
173
|
+
.text_color(primary ? t.solid_foreground : t.foreground).text_size(12.5).font_medium().cursor_pointer()
|
|
174
|
+
.hover((s) => s.opacity(0.88)).on_click(action).child(text);
|
|
175
|
+
const line = (key, value, color) => h_flex().gap(8).pt(4).text_size(12.5)
|
|
176
|
+
.child(div().w(52).flex_none().text_color(t.dim).child(key))
|
|
177
|
+
.child(div().flex_1().text_color(color ?? t.foreground).child(value));
|
|
178
|
+
const close = button("hs-close", "Close", true, () => closeOverlay(props().overlay));
|
|
179
|
+
const root = v_flex().id("herdr-secret").track_focus(this.handle).on_key_down((e, cx) => this.key(e, cx))
|
|
180
|
+
.w_full().min_h(0).p(18).bg(t.popover).text_color(t.foreground);
|
|
181
|
+
|
|
182
|
+
if (this.state === "loading") return root.child(div().text_color(t.dim).child("Loading the request…"));
|
|
183
|
+
if (this.state === "empty") {
|
|
184
|
+
return root
|
|
185
|
+
.child(div().text_size(15).font_semibold().child("No credential request is waiting"))
|
|
186
|
+
.child(div().pt(8).text_size(12.5).text_color(t.dim).child("Agents open this dialog with herdr-secret ask."))
|
|
187
|
+
.child(h_flex().pt(18).justify_end().child(close));
|
|
188
|
+
}
|
|
189
|
+
if (this.state === "failed") {
|
|
190
|
+
return root
|
|
191
|
+
.child(div().text_size(15).font_semibold().child(`Not saved: ${r.name}`))
|
|
192
|
+
.child(div().pt(8).text_size(12.5).text_color(t.ansi1).child(this.error))
|
|
193
|
+
.child(div().pt(4).text_size(12.5).text_color(t.dim).child("The agent was told that it failed."))
|
|
194
|
+
.child(h_flex().pt(18).justify_end().child(close));
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return root
|
|
198
|
+
.child(h_flex().items_center()
|
|
199
|
+
.child(div().flex_1().text_size(15).font_semibold().child(`Credential requested: ${r.name}`))
|
|
200
|
+
.child(div().text_size(11).text_color(t.dim).child("Esc")))
|
|
201
|
+
.child(div().pt(8)
|
|
202
|
+
.child(line("From", `${r.from} (as reported by the requester)`, t.dim))
|
|
203
|
+
.child(line("For", r.purpose || "(no description given)"))
|
|
204
|
+
.child(line("Saved", `${r.store}`, r.encrypted ? t.done : t.blocked)))
|
|
205
|
+
.when(r.replaces.length > 0, (el) => el.child(div().pt(8).text_size(12).text_color(t.blocked)
|
|
206
|
+
.child(`Replaces the stored value of: ${r.replaces.join(", ")}`)))
|
|
207
|
+
.children(r.fields.map((f, i) => v_flex()
|
|
208
|
+
.child(label(f.label + (f.hidden ? " (hidden)" : "")))
|
|
209
|
+
.child(h_flex().gap(8).items_center()
|
|
210
|
+
.child(Input.new(this.inputs[i]).flex_1().h(36).px(10).rounded(9).border_1()
|
|
211
|
+
.border_color(this.focusIndex === i ? t.accent : t.input).bg(t.background).text_size(12.8).text_color(t.foreground))
|
|
212
|
+
.when(Boolean(f.hidden), (el) => el.child(
|
|
213
|
+
h_flex().id(`hs-show-${i}`).h(36).px(10).items_center().rounded(9).border_1().border_color(t.input)
|
|
214
|
+
.bg(t.raised).text_size(12).text_color(t.muted).cursor_pointer().hover((s) => s.opacity(0.88))
|
|
215
|
+
.on_click((_e, cx) => this.toggle(i, cx)).child(this.revealed[i] ? "Hide" : "Show"))))))
|
|
216
|
+
.when(Boolean(this.error), (el) => el.child(div().pt(10).text_size(12).text_color(t.ansi1).child(this.error)))
|
|
217
|
+
.child(h_flex().pt(20).gap(8).justify_end()
|
|
218
|
+
.child(button("hs-cancel", "Cancel", false, (_e, cx) => this.finish("CANCELLED", cx)))
|
|
219
|
+
.child(button("hs-save", this.state === "saving" ? "Saving…" : "Save", true, (_e, cx) => this.save(cx))));
|
|
220
|
+
}
|
|
221
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "place": "none", "title": "Credential request", "overlay": { "kind": "dialog", "width": 560 } }
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "herdr-secret",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Installer and command for herdr-secret: a
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Installer and command for herdr-secret: a form where coding agents ask you for credentials, as a herdr popup or a Herdr.app dialog.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "mazemaker",
|
|
7
7
|
"homepage": "https://github.com/mazemaker/herdr-secret#readme",
|
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
"keywords": [
|
|
17
17
|
"herdr",
|
|
18
18
|
"herdr-plugin",
|
|
19
|
+
"herdr-app",
|
|
20
|
+
"herdr-mod",
|
|
19
21
|
"credentials",
|
|
20
22
|
"secrets",
|
|
21
23
|
"keychain",
|
|
@@ -26,7 +28,8 @@
|
|
|
26
28
|
"herdr-secret": "cli.js"
|
|
27
29
|
},
|
|
28
30
|
"files": [
|
|
29
|
-
"cli.js"
|
|
31
|
+
"cli.js",
|
|
32
|
+
"engine/"
|
|
30
33
|
],
|
|
31
34
|
"engines": {
|
|
32
35
|
"node": ">=18"
|