@onepointfour-packs/flaredeck-agent 0.2.203 → 0.2.205

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.
@@ -0,0 +1,21 @@
1
+ export type TrustedEntry = {
2
+ name: string;
3
+ description: string;
4
+ body: string;
5
+ };
6
+ /** An uploaded script, as it is on this machine. */
7
+ export type TrustedLocal = TrustedEntry & {
8
+ abs: string;
9
+ };
10
+ /** Write one script as FlareDeck has it. */
11
+ export declare function writeFresh(t: TrustedLocal): void;
12
+ /** Put every uploaded script in `dir`, and take away any that was removed in FlareDeck. */
13
+ export declare function installScripts(entries: TrustedEntry[], dir: string): TrustedLocal[];
14
+ /**
15
+ * The uploaded script this command runs, and nothing else — or null. Kept deliberately narrow: no
16
+ * `;`, `&&`, `||`, command substitution, redirects or variables set in front of it; only the script
17
+ * with its arguments, optionally piped into a reader (`| head -50`).
18
+ */
19
+ export declare function trustedRun(command: string, cwd: string, local: TrustedLocal[], home?: string): TrustedLocal | null;
20
+ /** What a session is told: the scripts it may run, where they are, and what they are for. */
21
+ export declare function trustedBrief(local: TrustedLocal[]): string;
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Scripts a person uploaded to FlareDeck (Integrations → Scripts), which any agent may run without
3
+ * the command guard judging them — reading production logs through prodscan.sh, say (Cobus, 20 Oct).
4
+ * See flaredeck-mcp/src/vault/scripts.ts.
5
+ *
6
+ * Each is written into the harness's own folder, and written AGAIN, fresh from what FlareDeck sent,
7
+ * every time an agent runs it. So what runs is always what was uploaded: an agent that edited the
8
+ * file on the machine changed nothing. A command is trusted only when it runs exactly one of these
9
+ * files, alone or piped into a reader.
10
+ */
11
+ import { chmodSync, mkdirSync, readdirSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
12
+ import { isAbsolute, join, resolve } from 'node:path';
13
+ const real = (p) => { try {
14
+ return realpathSync(p);
15
+ }
16
+ catch {
17
+ return resolve(p);
18
+ } };
19
+ const safeName = (n) => /^[A-Za-z0-9][A-Za-z0-9._-]{0,80}$/.test(n);
20
+ /** Write one script as FlareDeck has it. */
21
+ export function writeFresh(t) {
22
+ writeFileSync(t.abs, t.body, { mode: 0o755 });
23
+ chmodSync(t.abs, 0o755);
24
+ }
25
+ /** Put every uploaded script in `dir`, and take away any that was removed in FlareDeck. */
26
+ export function installScripts(entries, dir) {
27
+ mkdirSync(dir, { recursive: true });
28
+ const out = [];
29
+ for (const e of entries) {
30
+ if (!safeName(e.name) || !e.body)
31
+ continue;
32
+ const t = { ...e, abs: join(dir, e.name) };
33
+ try {
34
+ writeFresh(t);
35
+ out.push(t);
36
+ }
37
+ catch { /* an unwritable one is simply not offered */ }
38
+ }
39
+ const keep = new Set(out.map((t) => t.name));
40
+ for (const f of (() => { try {
41
+ return readdirSync(dir);
42
+ }
43
+ catch {
44
+ return [];
45
+ } })()) {
46
+ if (!keep.has(f))
47
+ rmSync(join(dir, f), { force: true });
48
+ }
49
+ return out;
50
+ }
51
+ /** What a trusted script's output may be piped into: reading and trimming, nothing that acts. */
52
+ const PIPE_OK = /^(head|tail|grep|egrep|jq|wc|cut|sort|uniq|tr|column)(\s|$)/;
53
+ /**
54
+ * The uploaded script this command runs, and nothing else — or null. Kept deliberately narrow: no
55
+ * `;`, `&&`, `||`, command substitution, redirects or variables set in front of it; only the script
56
+ * with its arguments, optionally piped into a reader (`| head -50`).
57
+ */
58
+ export function trustedRun(command, cwd, local, home = process.env.HOME ?? '') {
59
+ if (!local.length)
60
+ return null;
61
+ const text = command.trim();
62
+ if (/[;&`<>]|\$\(|\|\|/.test(text.replace(/'[^']*'|"[^"$`]*"/g, '')))
63
+ return null;
64
+ const [first, ...pipes] = text.split(/\s*\|\s*/);
65
+ if (!first || pipes.some((p) => !PIPE_OK.test(p)))
66
+ return null;
67
+ const tokens = first.match(/"[^"]*"|'[^']*'|\S+/g) ?? [];
68
+ let i = 0;
69
+ if (/^(bash|sh|zsh)$/.test(tokens[0] ?? ''))
70
+ i = 1;
71
+ const raw = (tokens[i] ?? '').replace(/^["']|["']$/g, '');
72
+ if (!raw || raw.includes('='))
73
+ return null;
74
+ const expanded = raw.replace(/^~(?=\/)/, home).replace(/^\$\{?HOME\}?(?=\/)/, home);
75
+ // A bare name runs whatever is in the current folder by that name — never one of these.
76
+ if (!isAbsolute(expanded) && !expanded.includes('/'))
77
+ return null;
78
+ const abs = real(isAbsolute(expanded) ? expanded : resolve(cwd, expanded));
79
+ return local.find((l) => real(l.abs) === abs) ?? null;
80
+ }
81
+ /** What a session is told: the scripts it may run, where they are, and what they are for. */
82
+ export function trustedBrief(local) {
83
+ if (!local.length)
84
+ return '';
85
+ return [
86
+ '',
87
+ 'Scripts a person uploaded to FlareDeck for you — run them by their full path, they need no',
88
+ 'approval (piping the output into head, tail, grep or jq is fine; chaining them with other',
89
+ 'commands is not). Do not edit them: each is written fresh from FlareDeck before it runs.',
90
+ ...local.map((l) => ` · \`${l.abs}\` — ${l.description}`),
91
+ ].join('\n');
92
+ }
93
+ //# sourceMappingURL=trusted-scripts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trusted-scripts.js","sourceRoot":"","sources":["../src/trusted-scripts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACjG,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMtD,MAAM,IAAI,GAAG,CAAC,CAAS,EAAU,EAAE,GAAG,IAAI,CAAC;IAAC,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC;AAAC,CAAC;AAAC,MAAM,CAAC;IAAC,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;AAAC,CAAC,CAAC,CAAC,CAAC;AACrG,MAAM,QAAQ,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,mCAAmC,CAAC,IAAI,CAAC,CAAC,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I,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAC3C,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,qBAAqB,EAAE,IAAI,CAAC,CAAC;IACpF,wFAAwF;IACxF,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAClE,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC3E,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,IAAI,IAAI,CAAC;AACxD,CAAC;AAED,6FAA6F;AAC7F,MAAM,UAAU,YAAY,CAAC,KAAqB;IAChD,IAAI,CAAC,KAAK,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IAC7B,OAAO;QACL,EAAE;QACF,4FAA4F;QAC5F,2FAA2F;QAC3F,0FAA0F;QAC1F,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;KAC3D,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onepointfour-packs/flaredeck-agent",
3
- "version": "0.2.203",
3
+ "version": "0.2.205",
4
4
  "description": "Run a FlareDeck agent on your own machine: it picks up cards assigned to it, works each one in a checkout of its own, and reports back on the card.",
5
5
  "type": "module",
6
6
  "bin": {