lattris 0.2.0 → 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 CHANGED
@@ -49,7 +49,7 @@ lattris memory read and manage blocks
49
49
  lattris link connect two blocks
50
50
  lattris get read your blocks, questions and invites, and your datasets' rows
51
51
  lattris ask ask a question of a tree
52
- lattris invite invite someone
52
+ lattris invite invite someone, naming the email address the invitation admits
53
53
  lattris contact manage contacts
54
54
  ```
55
55
 
package/dist/build.json CHANGED
@@ -1,4 +1 @@
1
- {
2
- "commit": "8b66c9fde9fb6cd5cf716c08fa0e1ed1234c0651",
3
- "builtAt": "2026-09-27T23:55:25.807Z"
4
- }
1
+ {"commit":"cd0e945f0414da75fcda6791858d868210416e73","builtAt":"2026-10-10T02:56:29Z"}
@@ -1,14 +1,19 @@
1
1
  import { audiencesOf } from "./nouns/index.js";
2
2
  import { emit } from "./render/output.js";
3
3
  import { confirmAction } from "./render/prompt.js";
4
- import { ambiguousText, formatContact } from "./render/rows.js";
4
+ import { ambiguousText, formatContact, groupsNotBuilt, isGroupWord } from "./render/rows.js";
5
5
  import { renderRunHint, sanitizeForTerminal } from "./render/text.js";
6
6
  import { signedIn } from "./request/access-token.js";
7
7
  import { refusalOf } from "./request/api-fetch.js";
8
8
  import { EXIT, isRefusal } from "./store/exit.js";
9
- import { buildBody, describeAudience, fillIn, readWords, refuse, resolveContact, urlOf } from "./dispatch-words.js";
9
+ import { buildBody, describeAudience, fillIn, fillPath, readWords, refuse, resolveContact, urlOf } from "./dispatch-words.js";
10
10
  export const runForm = async (cfg, io, form, rest) => {
11
- const typed = readWords(form, rest);
11
+ const words = form.dropLeadingWords !== undefined &&
12
+ rest.length > 0 &&
13
+ form.dropLeadingWords.includes(rest[0])
14
+ ? rest.slice(1)
15
+ : rest;
16
+ const typed = readWords(form, words);
12
17
  if (isRefusal(typed))
13
18
  return typed;
14
19
  const steps = form.steps ?? {};
@@ -34,6 +39,10 @@ export const runForm = async (cfg, io, form, rest) => {
34
39
  if (steps.requireFlag && typed.flags[steps.requireFlag.key] === undefined) {
35
40
  return refuse(steps.requireFlag.message);
36
41
  }
42
+ if (selector !== undefined && isGroupWord(selector))
43
+ return refuse(groupsNotBuilt(selector));
44
+ if (steps.contact?.createIfMissing && selector?.includes('@'))
45
+ return refuse(`${form.usage}\n`);
37
46
  if (steps.pipedNeedsYes && !io.stdin.isTTY && !typed.on.has('--yes')) {
38
47
  return refuse(steps.pipedNeedsYes.message);
39
48
  }
@@ -53,8 +62,18 @@ export const runForm = async (cfg, io, form, rest) => {
53
62
  if (typeof accessToken !== 'string')
54
63
  return accessToken;
55
64
  let missingName;
65
+ let recording = false;
66
+ const reserved = [
67
+ ...(steps.contact?.publicWord === undefined ? [] : [steps.contact.publicWord]),
68
+ ...(steps.contact?.reserved ?? [])
69
+ ];
70
+ const refusedWord = selector !== undefined ? steps.contact?.refusedWords?.[selector] : undefined;
71
+ if (refusedWord !== undefined)
72
+ return refuse(refusedWord);
56
73
  const wantsPublic = steps.contact?.publicWord !== undefined && selector === steps.contact.publicWord;
57
- if (steps.contact && selector !== undefined && !wantsPublic) {
74
+ if (selector !== undefined && reserved.includes(selector))
75
+ context.reserved = selector;
76
+ if (steps.contact && selector !== undefined && context.reserved === undefined) {
58
77
  const contacts = await io.api(accessToken, `${cfg.apiUrl}/contacts`);
59
78
  if (!contacts.ok)
60
79
  return refusalOf(contacts);
@@ -84,6 +103,27 @@ export const runForm = async (cfg, io, form, rest) => {
84
103
  missingName = resolution.displayName;
85
104
  }
86
105
  }
106
+ if (steps.contact?.email && context.reserved === undefined && !wantsPublic) {
107
+ const rule = steps.contact.email;
108
+ const typedEmail = typed.flags[rule.flag]?.trim();
109
+ const held = context.contact?.email || undefined;
110
+ const name = sanitizeForTerminal(context.contact?.displayName ?? missingName ?? '');
111
+ if (typedEmail === undefined && held === undefined) {
112
+ return refuse(fillIn(missingName === undefined ? rule.required : rule.requiredNew, { name }));
113
+ }
114
+ if (typedEmail !== undefined &&
115
+ held !== undefined &&
116
+ typedEmail.toLowerCase() !== held.toLowerCase()) {
117
+ return refuse(fillIn(rule.conflict, {
118
+ name,
119
+ typed: sanitizeForTerminal(typedEmail),
120
+ held: sanitizeForTerminal(held),
121
+ 'contact.id': context.contact?.id ?? ''
122
+ }), EXIT.GENERIC);
123
+ }
124
+ context.email = held ?? typedEmail;
125
+ recording = held === undefined && context.contact !== undefined;
126
+ }
87
127
  if (steps.memory === 'always' || (steps.memory === 'at-tty' && io.stdin.isTTY)) {
88
128
  const fetched = await io.api(accessToken, `${cfg.apiUrl}/memories/${encodeURIComponent(typed.positionals[0])}`);
89
129
  if (!fetched.ok)
@@ -103,11 +143,15 @@ export const runForm = async (cfg, io, form, rest) => {
103
143
  const name = sanitizeForTerminal(context.contact?.displayName ?? missingName ?? '');
104
144
  const question = fillIn(missingName !== undefined && steps.confirm.whenMissing
105
145
  ? steps.confirm.whenMissing
106
- : steps.confirm.question, {
146
+ : recording && steps.confirm.whenRecording
147
+ ? steps.confirm.whenRecording
148
+ : steps.confirm.question, {
107
149
  ...Object.fromEntries(typed.positionals.map((p, i) => [`p${i}`, sanitizeForTerminal(p)])),
108
150
  name,
109
151
  title: sanitizeForTerminal(context.memory?.title ?? '(untitled)'),
110
152
  'memory.id': context.memory?.id ?? '',
153
+ 'contact.id': context.contact?.id ?? '',
154
+ email: sanitizeForTerminal(context.email ?? ''),
111
155
  audience: context.contact?.displayName ?? describeAudience(selector ?? '')
112
156
  });
113
157
  const answer = await confirmAction(io, question);
@@ -126,7 +170,11 @@ export const runForm = async (cfg, io, form, rest) => {
126
170
  const created = await io.api(accessToken, `${cfg.apiUrl}/contacts`, {
127
171
  method: 'POST',
128
172
  headers: { 'Content-Type': 'application/json' },
129
- body: JSON.stringify({ displayName: missingName, type: 'person' })
173
+ body: JSON.stringify({
174
+ displayName: missingName,
175
+ type: 'person',
176
+ ...(context.email === undefined ? {} : { email: context.email })
177
+ })
130
178
  });
131
179
  if (!created.ok)
132
180
  return refusalOf(created);
@@ -134,19 +182,40 @@ export const runForm = async (cfg, io, form, rest) => {
134
182
  context.createdContact = true;
135
183
  body = buildBody(form, typed, stdin, context);
136
184
  }
137
- else if (context.contact !== undefined || wantsPublic) {
185
+ else if (recording && context.contact !== undefined) {
186
+ const updated = await io.api(accessToken, `${cfg.apiUrl}/contacts/${encodeURIComponent(context.contact.id)}`, {
187
+ method: 'PATCH',
188
+ headers: { 'Content-Type': 'application/json' },
189
+ body: JSON.stringify({ email: context.email })
190
+ });
191
+ if (!updated.ok)
192
+ return refusalOf(updated);
193
+ context.contact = updated.data;
194
+ context.recordedEmail = true;
195
+ body = buildBody(form, typed, stdin, context);
196
+ }
197
+ else if (context.contact !== undefined || wantsPublic || context.reserved !== undefined) {
138
198
  body = buildBody(form, typed, stdin, context);
139
199
  }
140
200
  const url = urlOf(cfg.apiUrl, form, typed, stdin, context);
141
- const result = await io.api(accessToken, url, body === undefined
201
+ const send = (at) => io.api(accessToken, at, body === undefined
142
202
  ? { method: form.request.method }
143
203
  : {
144
204
  method: form.request.method,
145
205
  headers: { 'Content-Type': 'application/json' },
146
206
  body: JSON.stringify(body)
147
207
  });
208
+ let result = await send(url);
209
+ const fallback = form.request.fallback;
210
+ if (!result.ok &&
211
+ fallback !== undefined &&
212
+ result.status === fallback.status &&
213
+ context.contact?.claimedPersonId) {
214
+ result = await send(new URL(`${cfg.apiUrl}${fillPath(fallback.path, typed, context)}`));
215
+ }
148
216
  if (!result.ok) {
149
- return refusalOf(result, form.ambiguousRefusal ? ambiguousText(result.body) : '');
217
+ return refusalOf(result, (form.ambiguousRefusal ? ambiguousText(result.body) : '') +
218
+ (form.refusalWords?.(result.body, context) ?? ''));
150
219
  }
151
220
  const typedView = context;
152
221
  if (form.pickFromList) {
@@ -1,9 +1,11 @@
1
- import { renderRunHint } from "./render/text.js";
1
+ import { resolveContact } from "./render/rows.js";
2
+ import { renderRunHint, sanitizeForTerminal } from "./render/text.js";
2
3
  import { parseArgs } from "./request/flags.js";
3
4
  import { EXIT, refusal } from "./store/exit.js";
4
5
  import { isUuidKey } from "./store/write-identity.js";
5
6
  export const refuse = (message, exit = EXIT.USAGE) => refusal(message, exit);
6
7
  export const fillIn = (template, values) => template.replace(/\{([\w.]+)(?::([^}]*))?\}/g, (_m, key, arg) => key === 'hint' ? renderRunHint((arg ?? '').split(' ')) : (values[key] ?? ''));
8
+ const looksLikeAnAddress = (word) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(word);
7
9
  export const readWords = (form, rest) => {
8
10
  const on = new Set();
9
11
  const counts = new Map();
@@ -21,6 +23,11 @@ export const readWords = (form, rest) => {
21
23
  }
22
24
  if (notAnId !== undefined)
23
25
  return refuse(notAnId);
26
+ if (form.joinPositionals && positionals.length > 1) {
27
+ if (positionals.some((word) => isUuidKey(word)))
28
+ return refuse(`${form.usage}\n`);
29
+ positionals.splice(0, positionals.length, positionals.join(' '));
30
+ }
24
31
  const typed = { positionals, flags: flags, on };
25
32
  const tooMany = form.positionalsAtMost ?? form.positionals;
26
33
  if (positionals.length < form.positionals ||
@@ -60,6 +67,12 @@ export const readWords = (form, rest) => {
60
67
  return refuse(fillIn(rule.message, { value }));
61
68
  }
62
69
  }
70
+ for (const rule of form.addressFlags ?? []) {
71
+ const value = typed.flags[rule.key];
72
+ if (value !== undefined && !looksLikeAnAddress(value.trim())) {
73
+ return refuse(fillIn(rule.message, { value: sanitizeForTerminal(value.trim()) }));
74
+ }
75
+ }
63
76
  for (const rule of form.requireWhen ?? []) {
64
77
  const value = typed.flags[rule.key];
65
78
  if (value !== undefined &&
@@ -77,13 +90,17 @@ export const valueOf = (source, typed, stdin, context) => {
77
90
  return typed.positionals[source.positional];
78
91
  if ('stdin' in source)
79
92
  return stdin;
80
- if ('context' in source)
81
- return context.contact?.id;
93
+ if ('context' in source) {
94
+ return source.context === 'email' ? context.email : context.contact?.id;
95
+ }
82
96
  if (!('switch' in source))
83
97
  return source.value;
84
98
  return typed.on.has(source.switch) ? source.value : source.otherwise;
85
99
  };
86
100
  export const buildBody = (form, typed, stdin, context) => {
101
+ if (context.reserved !== undefined && form.request.bodyFor?.[context.reserved]) {
102
+ return form.request.bodyFor[context.reserved];
103
+ }
87
104
  if (form.request.bodyWithPublic && context.contact === undefined) {
88
105
  return form.request.bodyWithPublic;
89
106
  }
@@ -99,16 +116,16 @@ export const buildBody = (form, typed, stdin, context) => {
99
116
  }
100
117
  return body;
101
118
  };
102
- export const pathOf = (form, typed, context) => {
103
- const template = form.request.pathWithPublic && context.contact === undefined
119
+ export const pathOf = (form, typed, context) => fillPath((context.reserved !== undefined && form.request.pathFor?.[context.reserved]) ||
120
+ (form.request.pathWithPublic && context.contact === undefined
104
121
  ? form.request.pathWithPublic
105
- : form.request.path;
106
- return template
107
- .replace(/\{(--[a-z-]+):([^}]*)\}/g, (_m, name, text) => typed.on.has(name) ? text : '')
108
- .replace(/\{p(\d+)\}/g, (_m, i) => encodeURIComponent(typed.positionals[Number(i)] ?? ''))
109
- .replace('{memory.id}', encodeURIComponent(context.memory?.id ?? typed.positionals[0] ?? ''))
110
- .replace('{contact.claimedPersonId}', () => encodeURIComponent(String(context.contact?.claimedPersonId ?? '')));
111
- };
122
+ : form.request.path), typed, context);
123
+ export const fillPath = (template, typed, context) => template
124
+ .replace(/\{(--[a-z-]+):([^}]*)\}/g, (_m, name, text) => typed.on.has(name) ? text : '')
125
+ .replace(/\{p(\d+)\}/g, (_m, i) => encodeURIComponent(typed.positionals[Number(i)] ?? ''))
126
+ .replace('{memory.id}', encodeURIComponent(context.memory?.id ?? typed.positionals[0] ?? ''))
127
+ .replace('{contact.claimedPersonId}', () => encodeURIComponent(String(context.contact?.claimedPersonId ?? '')))
128
+ .replace('{contact.id}', () => encodeURIComponent(String(context.contact?.id ?? '')));
112
129
  export const urlOf = (apiUrl, form, typed, stdin, context) => {
113
130
  const url = new URL(`${apiUrl}${pathOf(form, typed, context)}`);
114
131
  for (const [key, sources] of Object.entries(form.request.query ?? {})) {
@@ -120,18 +137,10 @@ export const urlOf = (apiUrl, form, typed, stdin, context) => {
120
137
  }
121
138
  return url;
122
139
  };
123
- export const resolveContact = (contacts, selector) => {
124
- if (isUuidKey(selector)) {
125
- const contact = contacts.find((c) => c.id.toLowerCase() === selector.toLowerCase());
126
- return contact ? { kind: 'found', contact } : { kind: 'missing-id' };
127
- }
128
- const folded = selector.toLowerCase();
129
- const matches = contacts.filter((c) => c.displayName.toLowerCase() === folded);
130
- if (matches.length === 1)
131
- return { kind: 'found', contact: matches[0] };
132
- if (matches.length > 1)
133
- return { kind: 'ambiguous', matches };
134
- return { kind: 'missing-name', displayName: selector };
135
- };
136
- export const describeAudience = (audience) => audience === 'public' ? 'public — anyone, including people without accounts' : audience;
140
+ export { resolveContact };
141
+ export const describeAudience = (audience) => audience === 'public'
142
+ ? 'public — anyone, including people without accounts'
143
+ : audience === 'all-contacts'
144
+ ? 'all your contacts'
145
+ : audience;
137
146
  //# sourceMappingURL=dispatch-words.js.map
package/dist/dispatch.js CHANGED
@@ -1,4 +1,4 @@
1
- import { VERB_ALIASES } from "./nouns/words.js";
1
+ import { resolveVerb } from "./nouns/words.js";
2
2
  import { renderRefusal } from "./render/output.js";
3
3
  import { sanitizeForTerminal } from "./render/text.js";
4
4
  import { HELP_TOKENS } from "./request/flags.js";
@@ -18,8 +18,8 @@ export const dispatch = async (cfg, io, registry, argv) => {
18
18
  const typedWord = argv[0];
19
19
  if (typedWord === undefined)
20
20
  return false;
21
- const word = VERB_ALIASES[typedWord] ?? typedWord;
22
21
  const rest = argv.slice(1);
22
+ const word = resolveVerb(typedWord, rest[0]);
23
23
  const nounFirst = registry.nouns.find((n) => n.grammar === 'noun-first' && wordsOf(n).includes(word));
24
24
  if (nounFirst) {
25
25
  const first = rest[0];
@@ -1,12 +1,14 @@
1
+ import { randomUUID } from 'node:crypto';
1
2
  import { dirname, join, resolve } from 'node:path';
2
3
  import { promptLine } from "../render/prompt.js";
3
4
  import { LATTRIS_PERMISSION_RULE, SETUP_FLAG_NAMES, SETUP_HELP, buildBootFile, buildTransitionInstructions, parseBootRootId, withLattrisPermission } from "../entry/setup-boot.js";
4
5
  import { parseArgs } from "../request/flags.js";
5
6
  import { HELP_TOKENS } from "../request/flags.js";
6
7
  import { sanitizeForTerminal } from "../render/text.js";
7
- import { refusal } from "../store/exit.js";
8
+ import { isRefusal, refusal } from "../store/exit.js";
8
9
  import { refusalOf } from "../request/api-fetch.js";
9
10
  import { signedIn } from "../request/access-token.js";
11
+ import { noteWriteHeaders, requireWriteIdentity } from "../store/write-identity.js";
10
12
  export const promptAnswer = (answer) => {
11
13
  if (answer === null)
12
14
  return 'no';
@@ -91,6 +93,13 @@ export const setup = async (cfg, io, args) => {
91
93
  return;
92
94
  }
93
95
  }
96
+ let identity;
97
+ if (flags.root === undefined) {
98
+ const found = requireWriteIdentity(io.store, io.stdin.isTTY);
99
+ if (isRefusal(found))
100
+ return found;
101
+ identity = found;
102
+ }
94
103
  let name = flags.name;
95
104
  if (flags.root === undefined && name === undefined) {
96
105
  if (!io.stdin.isTTY) {
@@ -118,7 +127,10 @@ export const setup = async (cfg, io, args) => {
118
127
  else {
119
128
  const created = await io.api(accessToken, `${cfg.apiUrl}/memories/notes`, {
120
129
  method: 'POST',
121
- headers: { 'Content-Type': 'application/json' },
130
+ headers: {
131
+ 'Content-Type': 'application/json',
132
+ ...(identity ? noteWriteHeaders(identity, randomUUID()) : {})
133
+ },
122
134
  body: JSON.stringify({
123
135
  title: name,
124
136
  content: 'Root of this memory tree. Freshly scaffolded by `lattris setup` — ' +
package/dist/main.js CHANGED
@@ -17,7 +17,7 @@ import { machinesRoot, resolveActorDir, resolveSessionHome, stateHome } from "./
17
17
  import { sessionIdentityWarning } from "./store/session.js";
18
18
  import { currentPackageVersion, printVersion } from "./version.js";
19
19
  import { checkForNewVersion } from "./request/version-check.js";
20
- import { COMMAND_WORDS, VERB_ALIASES } from "./nouns/words.js";
20
+ import { COMMAND_WORDS, resolveVerb } from "./nouns/words.js";
21
21
  import { validAccessToken } from "./request/access-token.js";
22
22
  import { apiFetch } from "./request/api-fetch.js";
23
23
  import { ask, readAll } from "./request/stdin.js";
@@ -147,11 +147,7 @@ const main = async () => {
147
147
  if (isRefusal(cfg))
148
148
  return cfg;
149
149
  const rawCommand = argv[2];
150
- const command = rawCommand !== undefined
151
- ? Object.hasOwn(VERB_ALIASES, rawCommand)
152
- ? VERB_ALIASES[rawCommand]
153
- : rawCommand
154
- : rawCommand;
150
+ const command = rawCommand !== undefined ? resolveVerb(rawCommand, argv[3]) : rawCommand;
155
151
  void checkForNewVersion({ files: here.files, network: io.network, stderr: io.stderr }, {
156
152
  currentVersion: currentPackageVersion(here.files),
157
153
  stateDir: join(stateHome(here), 'lattris'),
@@ -0,0 +1,88 @@
1
+ import { HELP_TOKENS, parseArgs } from "../request/flags.js";
2
+ import { emit } from "../render/output.js";
3
+ import { ambiguousText, describeForContact, formatAccessRow, formatContact, resolveContact } from "../render/rows.js";
4
+ import { renderRunHint, sanitizeForTerminal } from "../render/text.js";
5
+ import { signedIn } from "../request/access-token.js";
6
+ import { refusalOf } from "../request/api-fetch.js";
7
+ import { EXIT, refusal } from "../store/exit.js";
8
+ export const GET_ACCESS_HELP = [
9
+ 'get access — may one contact, or one phone number, see a memory of yours,',
10
+ 'or one someone shared with you, and because of which share. For a shared',
11
+ "memory the answer comes from your own shares and the owner's public one.",
12
+ '',
13
+ 'Usage:',
14
+ ' lattris get access <memory-id-or-prefix> --for <contact | number>',
15
+ '',
16
+ ' --for an exact contact name or id from `lattris contact list`, or a',
17
+ ' phone number in full international form (+ then digits). A',
18
+ ' number no contact holds is a stranger, who sees public memories',
19
+ ' only.',
20
+ '',
21
+ 'Answers open or shut, and the rows that decided it: the denies that reach',
22
+ 'the contact when one does, the allows that reach them when open, or',
23
+ 'nothing when nothing is set.'
24
+ ].join('\n');
25
+ const ACCESS_FLAGS = { '--for': 'for' };
26
+ const isPhoneWord = (word) => word.startsWith('+');
27
+ const formatAccessDecision = (d, asked) => {
28
+ const contact = d.forContact ?? null;
29
+ const who = contact === null ? sanitizeForTerminal(asked) : sanitizeForTerminal(contact.displayName);
30
+ const stranger = contact === null ? ` (${describeForContact(null, asked)})` : '';
31
+ const verdict = d.open
32
+ ? `open — ${who} may see it${stranger}`
33
+ : `shut — ${who} may not see it${stranger}`;
34
+ const because = (d.decidedBy ?? []).length === 0
35
+ ? contact === null
36
+ ? 'because: no public share'
37
+ : 'because: nothing is set for them'
38
+ : `because: ${(d.decidedBy ?? []).map(formatAccessRow).join('; ')}`;
39
+ return `${verdict}\n${because}`;
40
+ };
41
+ export const contactIdFor = async (cfg, io, accessToken, word) => {
42
+ const contacts = await io.api(accessToken, `${cfg.apiUrl}/contacts`);
43
+ if (!contacts.ok)
44
+ return refusalOf(contacts);
45
+ const shown = sanitizeForTerminal(word);
46
+ const resolution = resolveContact(contacts.data, word.trim());
47
+ if (resolution.kind === 'ambiguous') {
48
+ const list = resolution.matches.map((c) => ` ${formatContact(c)}`).join('\n');
49
+ return refusal(`${shown} matches more than one of your contacts:\n${list}\nUse a contact id instead.\n`);
50
+ }
51
+ if (resolution.kind !== 'found') {
52
+ return refusal(`No contact ${shown} among yours. ${renderRunHint(['contact', 'list'])} shows them.\n`, EXIT.GENERIC);
53
+ }
54
+ return { id: resolution.contact.id };
55
+ };
56
+ export const getAccess = async (cfg, io, rest) => {
57
+ if (rest.length === 0 || rest.some((t) => HELP_TOKENS.has(t))) {
58
+ io.stdout.write(`${GET_ACCESS_HELP}\n`);
59
+ return;
60
+ }
61
+ const { flags, positionals, unknown, notAnId } = parseArgs(ACCESS_FLAGS, rest, [0]);
62
+ if (unknown)
63
+ return refusal(`Unknown flag: ${unknown}\n`);
64
+ if (notAnId)
65
+ return refusal(notAnId);
66
+ if (positionals.length !== 1 || flags.for === undefined) {
67
+ return refusal(`Usage: lattris get access <memory-id-or-prefix> --for <contact | number>\n`);
68
+ }
69
+ const accessToken = await signedIn(io, cfg);
70
+ if (typeof accessToken !== 'string')
71
+ return accessToken;
72
+ const url = new URL(`${cfg.apiUrl}/memories/${encodeURIComponent(positionals[0])}/access`);
73
+ if (isPhoneWord(flags.for)) {
74
+ url.searchParams.set('forPhone', flags.for);
75
+ }
76
+ else {
77
+ const contact = await contactIdFor(cfg, io, accessToken, flags.for);
78
+ if ('exit' in contact)
79
+ return contact;
80
+ url.searchParams.set('forContact', contact.id);
81
+ }
82
+ const result = await io.api(accessToken, url);
83
+ if (!result.ok)
84
+ return refusalOf(result, ambiguousText(result.body));
85
+ const asked = flags.for;
86
+ emit(io, result.data, result.rawText, (d) => formatAccessDecision(d, asked));
87
+ };
88
+ //# sourceMappingURL=access.js.map
@@ -1,5 +1,110 @@
1
+ import { formatContact, groupsNotBuilt, isGroupWord, resolveContact, waitsForNameLines } from "../render/rows.js";
1
2
  import { renderRunHint, sanitizeForTerminal } from "../render/text.js";
2
- export const buildCreateNoteBody = (content, flags, allowBannedWords = false) => {
3
+ import { refusalOf } from "../request/api-fetch.js";
4
+ import { EXIT, refusal } from "../store/exit.js";
5
+ const PUBLIC_WORDS = 'public — anyone, including people without accounts';
6
+ export const takeShareFlags = (args) => {
7
+ const rest = [];
8
+ const shareWith = [];
9
+ const deny = [];
10
+ for (let i = 0; i < args.length; i++) {
11
+ const arg = args[i];
12
+ const eq = arg.indexOf('=');
13
+ const name = eq === -1 ? arg : arg.slice(0, eq);
14
+ if (name !== '--share-with' && name !== '--deny') {
15
+ rest.push(arg);
16
+ continue;
17
+ }
18
+ let value;
19
+ if (eq !== -1)
20
+ value = arg.slice(eq + 1);
21
+ else {
22
+ value = args[i + 1];
23
+ if (value === undefined || value.startsWith('--')) {
24
+ return { rest, shareWith, deny, unknown: name };
25
+ }
26
+ i++;
27
+ }
28
+ (name === '--share-with' ? shareWith : deny).push(value);
29
+ }
30
+ return { rest, shareWith, deny };
31
+ };
32
+ export const checkShareWords = (shareWith, deny) => {
33
+ const group = [...shareWith, ...deny].find(isGroupWord);
34
+ if (group !== undefined)
35
+ return refusal(groupsNotBuilt(group));
36
+ if (deny.includes('public')) {
37
+ return refusal('public cannot be denied: --deny names a contact or all-contacts. Leave --share-with public off to keep it private.\n');
38
+ }
39
+ const seen = new Set();
40
+ for (const word of [...shareWith, ...deny]) {
41
+ const key = word.trim().toLowerCase();
42
+ if (seen.has(key)) {
43
+ return refusal(`${sanitizeForTerminal(word)} is named twice — name each audience once, with one effect.\n`);
44
+ }
45
+ seen.add(key);
46
+ }
47
+ return undefined;
48
+ };
49
+ export const allowWords = (shareWith) => shareWith.map((w) => w === 'public'
50
+ ? PUBLIC_WORDS
51
+ : w === 'all-contacts'
52
+ ? 'all your contacts'
53
+ : sanitizeForTerminal(w));
54
+ const sharePhrase = (allows) => allows.length === 1 && allows[0] === PUBLIC_WORDS
55
+ ? `make it ${PUBLIC_WORDS}`
56
+ : `share it with ${allows.join(', ')}`;
57
+ export const needsYesWords = (noun, allows) => {
58
+ const arrived = noun === 'session' ? 'the turns' : 'the content';
59
+ return (`This will save the ${noun} AND ${sharePhrase(allows)}. There is no prompt here (${arrived} already ` +
60
+ 'arrived on a pipe) — pass --yes once the person has confirmed both facts.\n');
61
+ };
62
+ export const resolveBornShares = async (cfg, io, accessToken, shareWith, deny) => {
63
+ const shares = { access: [], allows: allowWords(shareWith) };
64
+ const words = [
65
+ ...shareWith.map((w) => [w, 'allow']),
66
+ ...deny.map((w) => [w, 'deny'])
67
+ ];
68
+ let contacts;
69
+ for (const [word, effect] of words) {
70
+ if (word === 'public') {
71
+ shares.audience = 'public';
72
+ continue;
73
+ }
74
+ if (word === 'all-contacts') {
75
+ shares.access.push({ kind: 'all_contacts', effect });
76
+ continue;
77
+ }
78
+ if (contacts === undefined) {
79
+ const read = await io.api(accessToken, `${cfg.apiUrl}/contacts`);
80
+ if (!read.ok)
81
+ return refusalOf(read);
82
+ contacts = read.data;
83
+ }
84
+ const shown = sanitizeForTerminal(word);
85
+ const resolution = resolveContact(contacts, word.trim());
86
+ if (resolution.kind === 'ambiguous') {
87
+ const list = resolution.matches.map((c) => ` ${formatContact(c)}`).join('\n');
88
+ return refusal(`${shown} matches more than one of your contacts:\n${list}\nUse a contact id instead.\n`);
89
+ }
90
+ if (resolution.kind !== 'found') {
91
+ return refusal(`No contact ${shown} among yours. ${renderRunHint(['contact', 'list'])} shows them.\n`, EXIT.GENERIC);
92
+ }
93
+ if (shares.access.some((a) => a.kind === 'contact' && a.contactId === resolution.contact.id)) {
94
+ return refusal(`${shown} is named twice — name each audience once, with one effect.\n`);
95
+ }
96
+ shares.access.push({ kind: 'contact', contactId: resolution.contact.id, effect });
97
+ }
98
+ return shares;
99
+ };
100
+ export const isRefusalValue = (value) => typeof value === 'object' && value !== null && 'exit' in value && 'message' in value;
101
+ export const withShares = (body, shares) => {
102
+ if (shares?.audience !== undefined)
103
+ body.audience = shares.audience;
104
+ if (shares !== undefined && shares.access.length > 0)
105
+ body.access = shares.access;
106
+ };
107
+ export const buildCreateNoteBody = (content, flags, allowBannedWords = false, shares) => {
3
108
  const body = { content };
4
109
  if (flags.intent !== undefined)
5
110
  body.intent = flags.intent;
@@ -7,8 +112,7 @@ export const buildCreateNoteBody = (content, flags, allowBannedWords = false) =>
7
112
  body.title = flags.title;
8
113
  if (flags.capturedAt !== undefined)
9
114
  body.capturedAt = flags.capturedAt;
10
- if (flags.shareWith !== undefined)
11
- body.audience = flags.shareWith;
115
+ withShares(body, shares);
12
116
  if (flags.contributor !== undefined)
13
117
  body.contributor = flags.contributor;
14
118
  if (flags.aiSummary !== undefined)
@@ -32,6 +136,8 @@ export const formatSaved = (b, address) => {
32
136
  lines.push(` revisionNo ${b.revisionNo}`);
33
137
  if (address)
34
138
  lines.push(` address ${address}`);
139
+ for (const sentence of waitsForNameLines(b.access))
140
+ lines.push(` website ${sentence}`);
35
141
  return lines.join('\n');
36
142
  };
37
143
  export const CAPTURE_MEMORY_FLAG_NAMES = {
@@ -40,7 +146,6 @@ export const CAPTURE_MEMORY_FLAG_NAMES = {
40
146
  '--intent': 'intent',
41
147
  '--title': 'title',
42
148
  '--captured-at': 'capturedAt',
43
- '--share-with': 'shareWith',
44
149
  '--source': 'source',
45
150
  '--conversation-id': 'conversationId',
46
151
  '--extends': 'extends',
@@ -63,5 +168,4 @@ export const SESSION_ONLY_FLAGS = [
63
168
  ['--forked-from', 'forkedFrom']
64
169
  ];
65
170
  export const retryWords = (path) => renderRunHint(['resend', path]);
66
- export const SHARE_AUDIENCES = ['public'];
67
171
  //# sourceMappingURL=capture-common.js.map
@@ -70,12 +70,18 @@ to save text arrives on stdin — no quoting; up to 5MB.
70
70
  --intent <name> optional; default none
71
71
  --title <text> optional; one line, what this is about
72
72
  --captured-at <time> optional; when it happened, if not now
73
- --share-with public optional; makes it public immediately — one
74
- confirmation covers both facts. Omit to stay
75
- private (the default). Requires --yes: there
76
- is no prompt here, the content already
77
- arrived on a pipe — pass it once the person
78
- has confirmed both saving AND publishing.
73
+ --share-with <who> optional, repeatable; who may see it from birth:
74
+ public, all-contacts, or one of your contacts
75
+ by name or id; group:<name> is reserved for
76
+ groups, which are not built yet. Omit to stay private (the
77
+ default). Requires --yes: there is no prompt
78
+ here, the content already arrived on a pipe —
79
+ pass it once the person has confirmed both
80
+ saving AND sharing.
81
+ --deny <who> optional, repeatable; who may not, whatever else
82
+ allows it: all-contacts or one contact. Needs
83
+ no --yes. public cannot be denied, and a deny
84
+ beside --share-with public is refused.
79
85
 
80
86
  --ai-summary <text> optional; an AI-written abstract beside the
81
87
  title — a finding aid, never the record;
@@ -173,9 +179,12 @@ is the conversation, not the machinery.
173
179
  --contributor <uuid> optional; whose expression — a contact id, attributed
174
180
  to that person's voice. Applied to EVERY epoch in a
175
181
  transcript chain (re-running heals older epochs too)
176
- --share-with public optional; public from birth — requires --yes, same law
177
- as a note
178
- --yes confirms save AND publish together
182
+ --share-with <who> optional, repeatable; public, all-contacts or a contact,
183
+ from birth — requires --yes, same law as a note;
184
+ group:<name> is reserved for groups, not built yet
185
+ --deny <who> optional, repeatable; all-contacts or a contact shut out
186
+ from birth, whatever else allows it
187
+ --yes confirms save AND share together
179
188
 
180
189
  A divergence refusal (the thread differs from the stored session) means a fork:
181
190
  nothing was written; re-run with --as-new --forked-from <that block> once the