@noisybrood/cli 0.1.0 → 0.4.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 +16 -6
- package/dist/brood/api/src/client.js +71 -0
- package/dist/brood/api/src/origin.js +7 -0
- package/dist/brood/api/src/values.js +281 -2
- package/dist/brood/figures/index.js +2 -6
- package/dist/brood/tokens/dark.js +2 -0
- package/dist/brood.js +22 -0
- package/dist/client.js +7 -7
- package/dist/commands.js +1022 -14
- package/dist/keychain.js +104 -0
- package/dist/main.js +108 -8
- package/dist/sign-in.js +8 -8
- package/dist/store.js +62 -7
- package/dist/wren.js +7 -13
- package/package.json +3 -3
- package/dist/brood/api/src/fields.js +0 -335
- package/dist/brood/api/src/index.js +0 -528
- package/dist/brood/tokens/dark.css +0 -86
- package/dist/brood/tokens/src/contrast.js +0 -109
package/dist/keychain.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
/**
|
|
3
|
+
* The longest command line handed to `security -i`, with room to spare: past
|
|
4
|
+
* about 4,000 characters it cuts the line and keeps what it read (DD10 §6).
|
|
5
|
+
* The line is the session in base64 and the command around it, so a session
|
|
6
|
+
* past about 2,500 characters goes to the file.
|
|
7
|
+
*/
|
|
8
|
+
export const MAC_LINE_MAX = 3_500;
|
|
9
|
+
/** How long a keychain command may take: a locked keyring waiting on a desktop prompt is no keychain. */
|
|
10
|
+
export const KEYCHAIN_TIMEOUT_MS = 5_000;
|
|
11
|
+
/** Where the session is kept in the keychain: the item's service and account. */
|
|
12
|
+
export const SERVICE = "com.noisybrood.cli";
|
|
13
|
+
export const ACCOUNT = "session";
|
|
14
|
+
/**
|
|
15
|
+
* The session as the keychain holds it: base64, so no character in it can
|
|
16
|
+
* end `security -i`'s command line or need quoting there.
|
|
17
|
+
*/
|
|
18
|
+
const encode = (secret) => Buffer.from(secret, "utf8").toString("base64");
|
|
19
|
+
// An item brood cannot decode is still brood's: "" says it is there, so the
|
|
20
|
+
// store removes it rather than taking it for none.
|
|
21
|
+
const decode = (held) => {
|
|
22
|
+
const text = held.trim();
|
|
23
|
+
if (!/^[A-Za-z0-9+/]+={0,2}$/.test(text))
|
|
24
|
+
return "";
|
|
25
|
+
return Buffer.from(text, "base64").toString("utf8");
|
|
26
|
+
};
|
|
27
|
+
/** macOS's login keychain, through `security`. */
|
|
28
|
+
export const macKeychain = (run) => ({
|
|
29
|
+
async read() {
|
|
30
|
+
const r = await run("security", [
|
|
31
|
+
"find-generic-password",
|
|
32
|
+
"-a",
|
|
33
|
+
ACCOUNT,
|
|
34
|
+
"-s",
|
|
35
|
+
SERVICE,
|
|
36
|
+
"-w",
|
|
37
|
+
]);
|
|
38
|
+
return r.status === 0 ? decode(r.stdout) : null;
|
|
39
|
+
},
|
|
40
|
+
async write(secret) {
|
|
41
|
+
const line = `add-generic-password -U -a ${ACCOUNT} -s ${SERVICE} -l brood -w ${encode(secret)}\n`;
|
|
42
|
+
if (line.length > MAC_LINE_MAX)
|
|
43
|
+
return false;
|
|
44
|
+
const r = await run("security", ["-i"], line);
|
|
45
|
+
return r.status === 0;
|
|
46
|
+
},
|
|
47
|
+
async remove() {
|
|
48
|
+
const r = await run("security", [
|
|
49
|
+
"delete-generic-password",
|
|
50
|
+
"-a",
|
|
51
|
+
ACCOUNT,
|
|
52
|
+
"-s",
|
|
53
|
+
SERVICE,
|
|
54
|
+
]);
|
|
55
|
+
// 44 is security's "not found": nothing there is gone too.
|
|
56
|
+
return r.status === 0 || r.status === 44;
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
/** A Linux desktop's Secret Service, through `secret-tool`. */
|
|
60
|
+
export const linuxKeychain = (run) => {
|
|
61
|
+
const attributes = ["service", SERVICE, "account", ACCOUNT];
|
|
62
|
+
return {
|
|
63
|
+
async read() {
|
|
64
|
+
const r = await run("secret-tool", ["lookup", ...attributes]);
|
|
65
|
+
return r.status === 0 ? decode(r.stdout) : null;
|
|
66
|
+
},
|
|
67
|
+
async write(secret) {
|
|
68
|
+
const r = await run("secret-tool", ["store", "--label=brood", ...attributes], encode(secret));
|
|
69
|
+
return r.status === 0;
|
|
70
|
+
},
|
|
71
|
+
async remove() {
|
|
72
|
+
const r = await run("secret-tool", ["clear", ...attributes]);
|
|
73
|
+
return r.status === 0;
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Runs a command with its input on standard input and nothing on its command
|
|
79
|
+
* line but what is given; a command that cannot start answers a null status.
|
|
80
|
+
* Its standard error is dropped: a keychain's complaint can echo what it was
|
|
81
|
+
* handed.
|
|
82
|
+
*/
|
|
83
|
+
export const runCommand = (command, args, input) => new Promise((resolve) => {
|
|
84
|
+
const child = spawn(command, args, {
|
|
85
|
+
stdio: ["pipe", "pipe", "ignore"],
|
|
86
|
+
// Killed past it, which closes with a null status: no keychain.
|
|
87
|
+
timeout: KEYCHAIN_TIMEOUT_MS,
|
|
88
|
+
});
|
|
89
|
+
let stdout = "";
|
|
90
|
+
child.stdout.setEncoding("utf8");
|
|
91
|
+
child.stdout.on("data", (chunk) => (stdout += chunk));
|
|
92
|
+
child.on("error", () => resolve({ status: null, stdout: "" }));
|
|
93
|
+
child.on("close", (status) => resolve({ status, stdout }));
|
|
94
|
+
child.stdin.on("error", () => { });
|
|
95
|
+
child.stdin.end(input ?? "");
|
|
96
|
+
});
|
|
97
|
+
/** The keychain this machine has, or null for none brood can use. */
|
|
98
|
+
export function keychainFor(platform, run = runCommand) {
|
|
99
|
+
if (platform === "darwin")
|
|
100
|
+
return macKeychain(run);
|
|
101
|
+
if (platform === "linux")
|
|
102
|
+
return linuxKeychain(run);
|
|
103
|
+
return null;
|
|
104
|
+
}
|
package/dist/main.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { parseArgs } from "node:util";
|
|
2
|
+
import { APP_ORIGIN } from "./brood/api/src/origin.js";
|
|
2
3
|
import { call } from "./client.js";
|
|
3
4
|
import { COMMANDS } from "./commands.js";
|
|
4
5
|
import { Refused, Refusal, SessionEnded } from "./io.js";
|
|
@@ -9,8 +10,15 @@ import { VERSION } from "./version.js";
|
|
|
9
10
|
import { depthOf, wrenIn } from "./wren.js";
|
|
10
11
|
/**
|
|
11
12
|
* `brood`, the command line over Brood's index (DD10): it answers questions
|
|
12
|
-
* about a mailbox without opening one, and changes it only by `hush
|
|
13
|
-
* `unhush
|
|
13
|
+
* about a mailbox without opening one, and changes it only by `hush`,
|
|
14
|
+
* `unhush`, `keep-out`, `rules file`, `batch`, `quieted restore`, `own-rules
|
|
15
|
+
* adopt`, `proposals file`, `unsubscribe` and `keep add`, which changes
|
|
16
|
+
* Brood's filters to keep mail in view; `own-rules` reads the mailbox's own
|
|
17
|
+
* filters. `accounts disconnect`, `keep remove` and `programs allow` and
|
|
18
|
+
* `revoke` ask for a change the person approves in the app, and change
|
|
19
|
+
* nothing until they do (DD21 §4). `relationships add` changes what Brood proposes, never the
|
|
20
|
+
* mailbox, and the rule book what Brood decides on its next run, which can
|
|
21
|
+
* quiet a home or stop filing one. Bare `brood` prints this help, never a report (DD10 §3), so it is
|
|
14
22
|
* never a status glanced at, under the wren.
|
|
15
23
|
*/
|
|
16
24
|
const HELP = `brood answers questions about your mailbox from Brood's index. It never reads a message.
|
|
@@ -26,13 +34,74 @@ Structure
|
|
|
26
34
|
brood classifications [<path>] what Brood has decided, and its state
|
|
27
35
|
brood classification <id> one, with the reason for its state
|
|
28
36
|
brood rules [<id>] the filters Brood installed
|
|
37
|
+
brood rule-book the numbers Brood decides by
|
|
29
38
|
|
|
30
|
-
Suppression,
|
|
31
|
-
brood hush <domain|address|id> file
|
|
39
|
+
Suppression, which changes your mailbox
|
|
40
|
+
brood hush <domain|address|id> file a sender, proposed or not
|
|
32
41
|
brood unhush <domain|address|id> undo the filing
|
|
42
|
+
brood keep-out <address> keep one address out of its domain's filing, and bring its mail back
|
|
43
|
+
brood rules file <id> file the mail already there that a filter would have filed
|
|
44
|
+
brood batch <home> on|off bring a home's mail back at your arrival hours
|
|
45
|
+
brood quieted homes Brood quieted for their silence
|
|
46
|
+
brood quieted restore <home> bring one back, filing again
|
|
47
|
+
brood quieted leave <home> leave one quiet after its sender wrote again
|
|
48
|
+
Your own filters
|
|
49
|
+
brood own-rules your filters in each mailbox, read now
|
|
50
|
+
brood own-rules adopt <mailbox> <id>
|
|
51
|
+
let Brood take one over, filing the same sender
|
|
52
|
+
The rule book, which changes what Brood decides
|
|
53
|
+
brood rule-book set <name>=<n>... see what a change would do, then save it
|
|
54
|
+
brood rule-book reset every number back to its default
|
|
55
|
+
|
|
56
|
+
Proposals, what Brood would file
|
|
57
|
+
brood proposals what it proposes; those marked ready can be filed together
|
|
58
|
+
brood proposals file <id>... file these, or --all for those marked ready
|
|
59
|
+
brood proposals decline <id> not this one, and never proposed again
|
|
60
|
+
brood proposals again <id> put a declined one back among the proposals
|
|
61
|
+
|
|
62
|
+
Unsubscribing, which cannot be taken back
|
|
63
|
+
brood unsubscribe who Brood can ask to stop
|
|
64
|
+
brood unsubscribe <address> ask one now
|
|
65
|
+
brood unsubscribe <address>... ask several in turn, or --all for everyone listed
|
|
66
|
+
|
|
67
|
+
Keeping in view, which changes Brood's filters so it never files these senders
|
|
68
|
+
brood keep your never-quiet list
|
|
69
|
+
brood keep add [<file>] add addresses and domains, one a line, from a file or standard input
|
|
70
|
+
brood keep remove <entry> [<kind>]
|
|
71
|
+
take one off the list, once you approve it in the app
|
|
72
|
+
|
|
73
|
+
Relationships, whose mail Brood gives a home of its own
|
|
74
|
+
brood relationships who is on the list, and who Brood suggests
|
|
75
|
+
brood relationships add --group <name> [<file>]
|
|
76
|
+
add them to a group, one a line, as Name: domain, domain
|
|
77
|
+
brood relationships accept <who> --group <name>
|
|
78
|
+
take up a suggestion
|
|
79
|
+
brood relationships dismiss <who> set a suggestion aside for good
|
|
80
|
+
brood relationships move <who> --group <name>
|
|
81
|
+
put one in another group
|
|
82
|
+
brood relationships remove <who> take one off the list; its mail stays filed
|
|
83
|
+
brood groups your groups
|
|
84
|
+
brood groups add <name> make one
|
|
85
|
+
brood groups rename <name> <new> rename one
|
|
86
|
+
brood groups comes-back <name> on|off
|
|
87
|
+
whether they return after a quiet spell
|
|
88
|
+
brood groups remove <name> remove one with nobody in it
|
|
89
|
+
|
|
90
|
+
Your account
|
|
91
|
+
brood preferences the letter, the first proposals' email and your arrival hours
|
|
92
|
+
brood preferences letter off|month|week
|
|
93
|
+
brood preferences first-proposals on|off
|
|
94
|
+
brood preferences hours <h> [<h>] when batched mail comes back, in this machine's time
|
|
95
|
+
brood programs the programs you allow to call Brood for you
|
|
96
|
+
brood programs allow|revoke <name>
|
|
97
|
+
allow one again, or revoke it, once you approve it in the app
|
|
98
|
+
brood connect where to connect a mailbox, in the app
|
|
99
|
+
brood plan where to choose a plan and pay, in the app
|
|
33
100
|
|
|
34
101
|
Accounts and session
|
|
35
102
|
brood accounts your mailboxes, and whether Brood can read them
|
|
103
|
+
brood accounts disconnect <mailbox>
|
|
104
|
+
let one go, once you approve it in the app
|
|
36
105
|
brood login [--read-only] sign in, by a code you approve in a browser
|
|
37
106
|
brood logout end this session
|
|
38
107
|
brood version
|
|
@@ -45,11 +114,19 @@ Options
|
|
|
45
114
|
--state <state> classifications in one state
|
|
46
115
|
--week <monday> brood week for an earlier week
|
|
47
116
|
--classification <id> brood rules for one classification
|
|
117
|
+
--all proposals file: those marked ready; unsubscribe: everyone listed
|
|
118
|
+
--group <name> relationships add, accept, move: the group they join, made if it is new
|
|
119
|
+
--check keep add, relationships add and remove, proposals file, unsubscribe, rule-book set: say what it would do, and do nothing
|
|
120
|
+
--yes keep add, relationships add and remove, proposals file, unsubscribe, keep-out, own-rules adopt, rule-book set and reset: do it without asking
|
|
48
121
|
--owner <user id> the index of someone who granted you access
|
|
49
122
|
--no-color no dimming, as NO_COLOR also asks`;
|
|
50
123
|
async function logout(io) {
|
|
51
|
-
if (!(await readCredentials(io
|
|
124
|
+
if (!(await readCredentials(io))) {
|
|
125
|
+
// Nothing to end at Brood, but an item the keychain would not show is
|
|
126
|
+
// still asked to go (review of #1676).
|
|
127
|
+
await removeCredentials(io);
|
|
52
128
|
return io.err("Not signed in.");
|
|
129
|
+
}
|
|
53
130
|
try {
|
|
54
131
|
await call(io, "end_session", (held) => ({
|
|
55
132
|
refresh_token: held.refresh_token,
|
|
@@ -57,16 +134,16 @@ async function logout(io) {
|
|
|
57
134
|
}
|
|
58
135
|
catch (error) {
|
|
59
136
|
// Forgotten only when nothing is left to end: a session Clerk has ended,
|
|
60
|
-
// or a program Brood refuses as revoked, whose
|
|
137
|
+
// or a program Brood refuses as revoked, whose stored session would leave
|
|
61
138
|
// login refusing too. Anything else, Brood unreachable or failing, or
|
|
62
139
|
// refusing a token just renewed, may leave the session live at Clerk,
|
|
63
|
-
// so the
|
|
140
|
+
// so the stored session stays and logging out again can end it.
|
|
64
141
|
const over = error instanceof SessionEnded ||
|
|
65
142
|
(error instanceof Refused && error.code === "credential_revoked");
|
|
66
143
|
if (!over)
|
|
67
144
|
throw error;
|
|
68
145
|
}
|
|
69
|
-
await removeCredentials(io
|
|
146
|
+
await removeCredentials(io);
|
|
70
147
|
io.err("Signed out. This session can no longer be renewed.");
|
|
71
148
|
}
|
|
72
149
|
const OPTION_NAMES = [
|
|
@@ -78,6 +155,10 @@ const OPTION_NAMES = [
|
|
|
78
155
|
"week",
|
|
79
156
|
"sender",
|
|
80
157
|
"classification",
|
|
158
|
+
"group",
|
|
159
|
+
"all",
|
|
160
|
+
"check",
|
|
161
|
+
"yes",
|
|
81
162
|
];
|
|
82
163
|
/** Runs one command line, and answers its exit status. */
|
|
83
164
|
export async function run(io, argv) {
|
|
@@ -98,6 +179,10 @@ export async function run(io, argv) {
|
|
|
98
179
|
week: { type: "string" },
|
|
99
180
|
sender: { type: "string" },
|
|
100
181
|
classification: { type: "string" },
|
|
182
|
+
group: { type: "string" },
|
|
183
|
+
all: { type: "boolean" },
|
|
184
|
+
check: { type: "boolean" },
|
|
185
|
+
yes: { type: "boolean" },
|
|
101
186
|
owner: { type: "string" },
|
|
102
187
|
},
|
|
103
188
|
});
|
|
@@ -138,6 +223,17 @@ export async function run(io, argv) {
|
|
|
138
223
|
io.out(VERSION);
|
|
139
224
|
return 0;
|
|
140
225
|
}
|
|
226
|
+
// Connecting and paying happen on the mail provider's and Stripe's own
|
|
227
|
+
// pages, reached from the app (#1729), so these name the app's page and
|
|
228
|
+
// read nothing, as `brood login` names the page it approves on.
|
|
229
|
+
if (command === "connect" || command === "plan") {
|
|
230
|
+
takes([]);
|
|
231
|
+
session();
|
|
232
|
+
io.out(command === "connect"
|
|
233
|
+
? `Connect a mailbox in Brood, where your mail provider asks you to allow it: ${APP_ORIGIN}/account/connect`
|
|
234
|
+
: `Choose your plan in Brood. Paying is on Stripe's page, reached from there: ${APP_ORIGIN}/account#plan`);
|
|
235
|
+
return 0;
|
|
236
|
+
}
|
|
141
237
|
if (command === "login") {
|
|
142
238
|
takes([], true);
|
|
143
239
|
session(true);
|
|
@@ -171,6 +267,10 @@ export async function run(io, argv) {
|
|
|
171
267
|
...(values.classification === undefined
|
|
172
268
|
? {}
|
|
173
269
|
: { classification: values.classification }),
|
|
270
|
+
...(values.group === undefined ? {} : { group: values.group }),
|
|
271
|
+
...(values.all ? { all: true } : {}),
|
|
272
|
+
...(values.check ? { check: true } : {}),
|
|
273
|
+
...(values.yes ? { yes: true } : {}),
|
|
174
274
|
};
|
|
175
275
|
await runs.run(io, styleOf(io, { json: values.json, noColor: values["no-color"] }), options, args);
|
|
176
276
|
return 0;
|
package/dist/sign-in.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SIGN_IN } from "./brood/api/src/
|
|
1
|
+
import { SIGN_IN } from "./brood/api/src/client.js";
|
|
2
2
|
import { clean, isRecord, Refusal, SessionEnded } from "./io.js";
|
|
3
3
|
import { readCredentials, removeCredentials, writeCredentials, } from "./store.js";
|
|
4
4
|
import { colorOn } from "./out.js";
|
|
@@ -53,7 +53,7 @@ function credentialsOf(body, now) {
|
|
|
53
53
|
}
|
|
54
54
|
const acts = (scope) => scope.split(" ").includes("act");
|
|
55
55
|
export async function login(io, readOnly, noColor = false) {
|
|
56
|
-
if (await readCredentials(io
|
|
56
|
+
if (await readCredentials(io))
|
|
57
57
|
throw new Refusal("Already signed in. Run brood logout first, which ends this session.");
|
|
58
58
|
const scope = readOnly ? "read offline_access" : "read act offline_access";
|
|
59
59
|
const started = await post(io, DEVICE_URL, { client_id: CLIENT_ID, scope });
|
|
@@ -89,13 +89,13 @@ export async function login(io, readOnly, noColor = false) {
|
|
|
89
89
|
const credentials = credentialsOf(answer.body, io.now());
|
|
90
90
|
if (!credentials)
|
|
91
91
|
throw new Refusal("The sign-in service did not finish the sign-in. Run brood login again.");
|
|
92
|
-
await writeCredentials(io
|
|
92
|
+
await writeCredentials(io, credentials);
|
|
93
93
|
const color = colorOn(io, noColor);
|
|
94
94
|
for (const line of wrenIn(color ? depthOf(io.env) : "none"))
|
|
95
95
|
io.err(line);
|
|
96
96
|
io.err("");
|
|
97
97
|
io.err(acts(credentials.scope)
|
|
98
|
-
? "Signed in. brood can read your index,
|
|
98
|
+
? "Signed in. brood can read your index, hush and unhush senders, keep senders in view, and add relationships."
|
|
99
99
|
: "Signed in. brood can read your index, and change nothing.");
|
|
100
100
|
return;
|
|
101
101
|
}
|
|
@@ -103,7 +103,7 @@ export async function login(io, readOnly, noColor = false) {
|
|
|
103
103
|
}
|
|
104
104
|
/** The session, refreshed first if its access token is about to expire. */
|
|
105
105
|
export async function freshCredentials(io) {
|
|
106
|
-
const stored = await readCredentials(io
|
|
106
|
+
const stored = await readCredentials(io);
|
|
107
107
|
if (!stored)
|
|
108
108
|
throw new Refusal("Not signed in. Run brood login.");
|
|
109
109
|
return stored.expires_at - EARLY_MS > io.now() ? stored : refresh(io, stored);
|
|
@@ -117,12 +117,12 @@ export async function refresh(io, stored) {
|
|
|
117
117
|
});
|
|
118
118
|
const credentials = credentialsOf(answer.body, io.now());
|
|
119
119
|
if (credentials) {
|
|
120
|
-
await writeCredentials(io
|
|
120
|
+
await writeCredentials(io, credentials);
|
|
121
121
|
return credentials;
|
|
122
122
|
}
|
|
123
123
|
if (answer.body.error === "invalid_grant") {
|
|
124
|
-
// The session is over at Clerk, so the
|
|
125
|
-
await removeCredentials(io
|
|
124
|
+
// The session is over at Clerk, so the stored session holds nothing that works.
|
|
125
|
+
await removeCredentials(io);
|
|
126
126
|
throw new SessionEnded("This session has ended. Run brood login to sign in again.");
|
|
127
127
|
}
|
|
128
128
|
throw new Refusal("The sign-in service would not renew this session. Try again shortly.");
|
package/dist/store.js
CHANGED
|
@@ -14,8 +14,28 @@ const isCredentials = (v) => typeof v === "object" &&
|
|
|
14
14
|
typeof v.expires_at === "number" &&
|
|
15
15
|
"scope" in v &&
|
|
16
16
|
typeof v.scope === "string";
|
|
17
|
-
/** The stored session, or null when there is none. */
|
|
18
|
-
export async function readCredentials(
|
|
17
|
+
/** The stored session, or null when there is none: the keychain's, else the file's. */
|
|
18
|
+
export async function readCredentials(store) {
|
|
19
|
+
const held = await store.keychain?.read();
|
|
20
|
+
if (held != null) {
|
|
21
|
+
let parsed;
|
|
22
|
+
try {
|
|
23
|
+
parsed = JSON.parse(held);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
parsed = null;
|
|
27
|
+
}
|
|
28
|
+
if (isCredentials(parsed))
|
|
29
|
+
return parsed;
|
|
30
|
+
// Brood's own item, unreadable, such as one a keychain cut short: it can
|
|
31
|
+
// open nothing, and refusing over it would refuse logout too. Removed, and
|
|
32
|
+
// the file, if any, is the session; one that will not go is said.
|
|
33
|
+
if (!(await store.keychain?.remove()))
|
|
34
|
+
throw new Refusal(STUCK);
|
|
35
|
+
}
|
|
36
|
+
return readFileCredentials(store.env);
|
|
37
|
+
}
|
|
38
|
+
async function readFileCredentials(env) {
|
|
19
39
|
const path = credentialsPath(env);
|
|
20
40
|
let mode;
|
|
21
41
|
try {
|
|
@@ -42,8 +62,28 @@ export async function readCredentials(env) {
|
|
|
42
62
|
throw new Refusal(`${path} is not a session brood wrote. Delete it and run brood login again.`);
|
|
43
63
|
return parsed;
|
|
44
64
|
}
|
|
45
|
-
/**
|
|
46
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Writes the session to the keychain, read back to be sure it took, and then
|
|
67
|
+
* removes any file an earlier session left; with no keychain, or one that did
|
|
68
|
+
* not keep it, to the file, whole or not at all.
|
|
69
|
+
*/
|
|
70
|
+
export async function writeCredentials(store, credentials) {
|
|
71
|
+
const secret = JSON.stringify(credentials);
|
|
72
|
+
if (store.keychain) {
|
|
73
|
+
if ((await store.keychain.write(secret)) &&
|
|
74
|
+
(await store.keychain.read()) === secret) {
|
|
75
|
+
await removeFileCredentials(store.env);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
// Whatever it kept, an older session or part of this one, would be read
|
|
79
|
+
// ahead of the file: it goes first, or the file is not written, since a
|
|
80
|
+
// session read past would be no session at all.
|
|
81
|
+
if (!(await gone(store.keychain)))
|
|
82
|
+
throw new Refusal(STUCK);
|
|
83
|
+
}
|
|
84
|
+
await writeFileCredentials(store.env, credentials);
|
|
85
|
+
}
|
|
86
|
+
async function writeFileCredentials(env, credentials) {
|
|
47
87
|
const path = credentialsPath(env);
|
|
48
88
|
await mkdir(dirname(path), { recursive: true, mode: 0o700 });
|
|
49
89
|
// A name no earlier run left behind, created afresh ("wx"), so the mode
|
|
@@ -61,11 +101,26 @@ export async function writeCredentials(env, credentials) {
|
|
|
61
101
|
await rm(draft, { force: true });
|
|
62
102
|
}
|
|
63
103
|
}
|
|
104
|
+
/** Forgets the session: in the keychain, and in any file it was ever kept in. */
|
|
105
|
+
export async function removeCredentials(store) {
|
|
106
|
+
await removeFileCredentials(store.env);
|
|
107
|
+
if (store.keychain && !(await gone(store.keychain)))
|
|
108
|
+
throw new Refusal(STUCK);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Whether the keychain holds nothing brood would read ahead of its file:
|
|
112
|
+
* its item removed, or none it will show. One it cannot reach, with no
|
|
113
|
+
* `secret-tool` or no Secret Service running, shows none, and reads fall
|
|
114
|
+
* back to the file too, so nothing there can shadow it (review of #1676).
|
|
115
|
+
*/
|
|
116
|
+
const gone = async (keychain) => (await keychain.remove()) || (await keychain.read()) === null;
|
|
117
|
+
/** What brood says when the keychain will not let go of its item. */
|
|
118
|
+
const STUCK = "Your keychain holds a brood session it will not let go of. Unlock the keychain, or delete the item named brood (com.noisybrood.cli), then run brood login.";
|
|
64
119
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
120
|
+
* The file, and any draft of it a run that stopped between writing and
|
|
121
|
+
* renaming left behind, which holds a token too.
|
|
67
122
|
*/
|
|
68
|
-
|
|
123
|
+
async function removeFileCredentials(env) {
|
|
69
124
|
const path = credentialsPath(env);
|
|
70
125
|
const draft = `${basename(path)}.`;
|
|
71
126
|
let names = [];
|
package/dist/wren.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { fileURLToPath } from "node:url";
|
|
3
|
-
import { readColourTokens } from "./brood/tokens/src/contrast.js";
|
|
1
|
+
import { DARK_BARN } from "./brood/tokens/dark.js";
|
|
4
2
|
import { BODY, DETAIL_WEIGHT, EYE, WING } from "./brood/tokens/src/wren.js";
|
|
5
3
|
/** A path of M, L and C commands, as the wren's are, as polylines. */
|
|
6
4
|
function polylines(d) {
|
|
@@ -118,18 +116,14 @@ export function wrenArt(columns = 32) {
|
|
|
118
116
|
return lines;
|
|
119
117
|
}
|
|
120
118
|
/**
|
|
121
|
-
* Barn, as the dark scheme sets it
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
119
|
+
* Barn, as the dark scheme sets it (`DARK_BARN`). A terminal does not say
|
|
120
|
+
* whether its ground is light or dark, and this one holds 3:1 on white, on
|
|
121
|
+
* black and on Ink, where the light scheme's falls short on a dark ground. It
|
|
122
|
+
* is the screen's one drop of Barn.
|
|
125
123
|
*/
|
|
126
124
|
function barn() {
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
const hex = value?.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i);
|
|
130
|
-
if (!hex)
|
|
131
|
-
throw new Error("dark.css sets no --color-barn as six hex digits");
|
|
132
|
-
return [parseInt(hex[1], 16), parseInt(hex[2], 16), parseInt(hex[3], 16)];
|
|
125
|
+
const [r, g, b] = [1, 3, 5].map((i) => parseInt(DARK_BARN.slice(i, i + 2), 16));
|
|
126
|
+
return [r, g, b];
|
|
133
127
|
}
|
|
134
128
|
/** The levels of xterm's 256-colour cube, for a terminal with no true colour. */
|
|
135
129
|
const CUBE = [0, 95, 135, 175, 215, 255];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noisybrood/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "brood, the command line over Noisy Brood's index of who writes to you. It never reads a message.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -25,11 +25,11 @@
|
|
|
25
25
|
"provenance": true
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
|
-
"build": "tsc -p .
|
|
28
|
+
"build": "tsc -p .",
|
|
29
29
|
"test": "node --test src/*.test.ts"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@types/node": "26.6.
|
|
32
|
+
"@types/node": "26.6.6",
|
|
33
33
|
"typescript": "6.0.3"
|
|
34
34
|
},
|
|
35
35
|
"repository": {
|