atris 3.72.5 → 3.73.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.
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Trust commands for Atris CLI, see who trusts an account and vouch for people.
3
+ *
4
+ * Usage:
5
+ * atris trust Your own trust
6
+ * atris trust <handle> Someone else's trust, and what you share
7
+ * atris trust vouch <handle> Vouch for someone (the same as following them)
8
+ * atris trust unvouch <handle> Take a vouch back
9
+ *
10
+ * <handle> can be @handle, handle, a user id, or an email. A leading @ is
11
+ * stripped before it is sent.
12
+ *
13
+ * Backend: GET /api/trust/me, GET /api/trust/{handle_or_id},
14
+ * POST and DELETE /api/trust/vouch/{handle_or_id}.
15
+ */
16
+
17
+ const { isHelpToken, argsWantHelp } = require('../lib/noninteractive');
18
+ const { cleanTarget, targetLabel, createIo, call, reportError } = require('./pay');
19
+
20
+ function splitFlags(args) {
21
+ const list = Array.isArray(args) ? args : [];
22
+ return {
23
+ json: list.includes('--json'),
24
+ rest: list.filter((a) => a !== '--json'),
25
+ };
26
+ }
27
+
28
+ function yesNo(value) {
29
+ if (value === true) return 'yes';
30
+ if (value === false) return 'no';
31
+ return null;
32
+ }
33
+
34
+ function trustLines(view, isMe) {
35
+ const v = view || {};
36
+ const name = v.handle ? `@${String(v.handle).replace(/^@+/, '')}` : (v.user_id || 'this account');
37
+ const friends = Number(v.friends) || 0;
38
+ const lines = [isMe ? `${name} (you)` : name];
39
+ lines.push(` Trust score ${v.trust_score ?? 0}, from ${friends} ${friends === 1 ? 'friend' : 'friends'}`);
40
+ const trusted = yesNo(v.trusted_with_me);
41
+ if (trusted) lines.push(` Trusted with you: ${trusted}`);
42
+ if (v.shared_friends !== null && v.shared_friends !== undefined) {
43
+ lines.push(` Friends you share: ${v.shared_friends}`);
44
+ }
45
+ return lines;
46
+ }
47
+
48
+ async function view(io, who, json) {
49
+ const isMe = !who;
50
+ const path = isMe ? '/trust/me' : `/trust/${encodeURIComponent(cleanTarget(who))}`;
51
+ const res = await call(io, path);
52
+ if (!res.ok) return reportError(io, res, `Could not load trust (${res.status})`);
53
+ if (json) {
54
+ io.log(JSON.stringify(res.data || {}, null, 2));
55
+ return 0;
56
+ }
57
+ for (const line of trustLines(res.data, isMe)) io.log(line);
58
+ if (isMe && !(Number(res.data && res.data.friends) > 0)) {
59
+ io.log('\nTrust grows when people vouch for you. Find people: atris people <name>');
60
+ }
61
+ return 0;
62
+ }
63
+
64
+ async function vouch(io, who, remove, json) {
65
+ const verb = remove ? 'unvouch' : 'vouch';
66
+ const target = cleanTarget(who);
67
+ if (!target || isHelpToken(target)) {
68
+ io.error(`Usage: atris trust ${verb} <handle>`);
69
+ return 2;
70
+ }
71
+ const res = await call(io, `/trust/vouch/${encodeURIComponent(target)}`, {
72
+ method: remove ? 'DELETE' : 'POST',
73
+ });
74
+ if (!res.ok) return reportError(io, res, `Could not ${verb} (${res.status})`);
75
+ if (json) {
76
+ io.log(JSON.stringify(res.data || {}, null, 2));
77
+ return 0;
78
+ }
79
+ const label = targetLabel(who);
80
+ if (remove) {
81
+ io.log(`You took back your vouch for ${label}.`);
82
+ } else if (res.data && res.data.is_mutual) {
83
+ io.log(`You vouched for ${label}. You vouch for each other now.`);
84
+ } else {
85
+ io.log(`You vouched for ${label}.`);
86
+ }
87
+ return 0;
88
+ }
89
+
90
+ function printHelp(log = console.log) {
91
+ log(`atris trust, who trusts an account and who you vouch for
92
+
93
+ atris trust Your trust
94
+ atris trust <handle> Their trust, and the friends you share
95
+ atris trust vouch <handle> Vouch for someone (same as following them)
96
+ atris trust unvouch <handle> Take your vouch back
97
+
98
+ <handle> is @handle, a user id, or an email.
99
+ Trust score is how many friends an account has (people who follow each other).
100
+ Add --json for the raw answer.
101
+ Pay someone: atris pay <handle> <amount>`);
102
+ }
103
+
104
+ async function trustCommand(argv, ioOverrides) {
105
+ const io = createIo(ioOverrides);
106
+ const { json, rest } = splitFlags(argv || process.argv.slice(3));
107
+ const sub = rest[0];
108
+ if (isHelpToken(sub) || argsWantHelp(rest)) {
109
+ printHelp(io.log);
110
+ return 0;
111
+ }
112
+ if (sub === 'vouch') return vouch(io, rest[1], false, json);
113
+ if (sub === 'unvouch') return vouch(io, rest[1], true, json);
114
+ return view(io, sub, json);
115
+ }
116
+
117
+ module.exports = { trustCommand, trustLines };
package/commands/zen.js CHANGED
@@ -3,9 +3,11 @@
3
3
  const { abandonedDaysFromEnv, checkZen, sideCopyLines } = require('../lib/zen');
4
4
  const { applyZen } = require('../lib/zen-apply');
5
5
  const { workspaceZen } = require('../lib/zen-workspace');
6
+ const { fleetFile, fleetRepos, fleetZen, printFleet } = require('../lib/zen-fleet');
6
7
 
7
8
  function showZenHelp() {
8
9
  console.log('usage: atris zen [--check] [--no-fetch] [--json]');
10
+ console.log(' atris zen --all [repo ...]');
9
11
  console.log('');
10
12
  console.log('Brings this repo to zen: code matches origin, nothing left lying around.');
11
13
  console.log('Old stashes are archived, idle side copies put away, finished branches');
@@ -21,6 +23,9 @@ function showZenHelp() {
21
23
  console.log(' --check Only look. Report what is out of place and change nothing.');
22
24
  console.log(' --no-fetch Use the last fetched origin instead of fetching.');
23
25
  console.log(' --json Print machine-readable results.');
26
+ console.log(' --all Zen every repo you list, one line each. Repos come from the');
27
+ console.log(' command line or ~/.atris/zen.json: {"repos": ["~/code/app"]}.');
28
+ console.log(' A repo with unsaved live data or secrets is skipped for you.');
24
29
  console.log('');
25
30
  console.log('Add more team-state paths in .atris/zen.json: {"team_state": ["logs/"]}');
26
31
  }
@@ -151,6 +156,18 @@ function zenCommand(args = [], cwd = process.cwd()) {
151
156
  const fetch = !args.includes('--no-fetch');
152
157
  const json = args.includes('--json');
153
158
 
159
+ if (args.includes('--all')) {
160
+ const repos = fleetRepos(args.filter((a) => !a.startsWith('--')));
161
+ if (!repos.length) {
162
+ console.log(`zen: no repos listed. Name them (atris zen --all ~/code/app ~/code/site) or list them in ${fleetFile()}.`);
163
+ return 2;
164
+ }
165
+ const results = fleetZen({ repos, fetch });
166
+ if (json) console.log(JSON.stringify(results, null, 2));
167
+ else printFleet(results);
168
+ return results.every((r) => r.state === 'zen' || r.state === 'skipped') ? 0 : 1;
169
+ }
170
+
154
171
  if (args.includes('--check')) {
155
172
  const result = checkZen({ cwd, fetch });
156
173
  if (json) {