lattris 0.2.3 → 0.2.4

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
@@ -41,7 +41,7 @@ sign you up.
41
41
  ## What it does
42
42
 
43
43
  ```
44
- lattris capture write a note, a session or a recording, or rows of a dataset
44
+ lattris capture write a note, a session, a recording or a source, or rows of a dataset
45
45
  lattris note a single note
46
46
  lattris session a session and its turns
47
47
  lattris recording a recording and its transcript
package/dist/build.json CHANGED
@@ -1 +1 @@
1
- {"commit":"2cc00908002bab8c075247652ee18d6d2f82515a","builtAt":"2026-10-11T22:49:48Z"}
1
+ {"commit":"dc66fbb3976033f182a724475ba45e03afd5ec17","builtAt":"2026-11-05T05:03:06Z"}
@@ -59,9 +59,13 @@ export const runForm = async (cfg, io, form, rest) => {
59
59
  if (body && form.request.emptyBodyMessage && Object.keys(body).length === 0) {
60
60
  return refuse(form.request.emptyBodyMessage);
61
61
  }
62
- const accessToken = await signedIn(io, cfg);
63
- if (typeof accessToken !== 'string')
64
- return accessToken;
62
+ let accessToken;
63
+ if (form.credential !== 'none') {
64
+ const signed = await signedIn(io, cfg);
65
+ if (typeof signed !== 'string')
66
+ return signed;
67
+ accessToken = signed;
68
+ }
65
69
  let missingName;
66
70
  let recording = false;
67
71
  const reserved = [
@@ -139,6 +143,13 @@ export const runForm = async (cfg, io, form, rest) => {
139
143
  return refusalOf(fetched, ambiguousText(fetched.body));
140
144
  }
141
145
  }
146
+ if (steps.subscriber) {
147
+ const fetched = await io.api(accessToken, `${cfg.apiUrl}/subscribers/${encodeURIComponent(typed.positionals[0])}`);
148
+ if (!fetched.ok) {
149
+ return refusalOf(fetched, ambiguousText(fetched.body));
150
+ }
151
+ context.subscriber = fetched.data;
152
+ }
142
153
  if (steps.noAudienceReport &&
143
154
  typed.flags[steps.noAudienceReport.key] === undefined &&
144
155
  context.gone) {
@@ -168,6 +179,7 @@ export const runForm = async (cfg, io, form, rest) => {
168
179
  'memory.id': context.memory?.id ?? sanitizeForTerminal(typed.positionals[0] ?? ''),
169
180
  'contact.id': context.contact?.id ?? '',
170
181
  email: sanitizeForTerminal(context.email ?? ''),
182
+ 'subscriber.email': sanitizeForTerminal(context.subscriber?.email ?? ''),
171
183
  audience: context.contact?.displayName ?? describeAudience(selector ?? '')
172
184
  });
173
185
  const answer = await confirmAction(io, question);
@@ -229,6 +241,10 @@ export const runForm = async (cfg, io, form, rest) => {
229
241
  context.contact?.claimedPersonId) {
230
242
  result = await send(new URL(`${cfg.apiUrl}${fillPath(fallback.path, typed, context)}`));
231
243
  }
244
+ const instead = result.ok ? undefined : form.refusalInstead?.[result.body.code ?? ''];
245
+ if (!result.ok && instead !== undefined) {
246
+ return refuse(fillIn(instead, { 'subscriber.email': sanitizeForTerminal(context.subscriber?.email ?? '') }), result.exit);
247
+ }
232
248
  if (!result.ok) {
233
249
  return refusalOf(result, (form.ambiguousRefusal ? ambiguousText(result.body) : '') +
234
250
  (form.refusalWords?.(result.body, context) ?? ''));
@@ -86,8 +86,10 @@ export const readWords = (form, rest) => {
86
86
  export const valueOf = (source, typed, stdin, context) => {
87
87
  if ('flag' in source)
88
88
  return typed.flags[source.flag];
89
- if ('positional' in source)
90
- return typed.positionals[source.positional];
89
+ if ('positional' in source) {
90
+ const value = typed.positionals[source.positional];
91
+ return source.trim && value !== undefined ? value.trim() : value;
92
+ }
91
93
  if ('stdin' in source)
92
94
  return stdin;
93
95
  if ('context' in source) {
package/dist/help.js CHANGED
@@ -40,7 +40,7 @@ export const usage = (term) => {
40
40
  ' LATTRIS_API lattris-api base (http://localhost:54301)',
41
41
  ' LATTRIS_CLIENT_ID OAuth client id (lattris-cli)',
42
42
  ' LATTRIS_REDIRECT_PORT loopback callback (4577)',
43
- ' LATTRIS_SESSION_ID names this session on every note write (required off a terminal)',
43
+ ' LATTRIS_SESSION_ID names this session on every note or source write (required off a terminal)',
44
44
  ' LATTRIS_AGENT a readable label for it (optional)',
45
45
  '',
46
46
  'Session resolution (which identity a command acts as), in order:',
@@ -5,6 +5,7 @@ export const CAPTURE_INDEX = [
5
5
  ' note written words — --type defaults to it',
6
6
  ' session a conversation with an AI, kept as an append-only ledger',
7
7
  ' recording audio, its source, and its transcript',
8
+ ' source a link you keep: a page, a post, a video',
8
9
  ' rows rows of a dataset, newline-delimited JSON',
9
10
  '',
10
11
  'Go one word deeper:',
@@ -13,6 +14,7 @@ export const CAPTURE_INDEX = [
13
14
  ' lattris capture memory --type session how to save a conversation (capture session accepted too)',
14
15
  ' lattris capture session <transcript.jsonl> save a Claude Code conversation, whole chain',
15
16
  ' lattris capture recording how to save audio + transcript',
17
+ ' lattris capture source how to keep a link',
16
18
  ' lattris capture rows how to save rows into a dataset',
17
19
  '',
18
20
  'To read what you have kept: lattris get memories',
@@ -60,7 +62,7 @@ noticed "Mum seemed quieter than usual today."
60
62
  no intent "That thing about the school waiting list — look into it."
61
63
  "Summary of the article on sleep — haven't decided what I make of it."
62
64
 
63
- to save text arrives on stdin — no quoting; up to 5MB.
65
+ to save text arrives on stdin — no quoting; up to 128KB.
64
66
 
65
67
  lattris capture which forms exist
66
68
  lattris capture memory prints this (capture note accepted too)
@@ -31,7 +31,8 @@ export const GET_HELP = [
31
31
  ' --limit <n> page size, 1-100 (default 50)',
32
32
  ' --cursor <token> the nextCursor from a previous page',
33
33
  ' --by <handle> one wall on the website address; an id without a',
34
- ' session needs it, while a full address carries it',
34
+ ' session needs it, while a full address carries it;',
35
+ ' an id shared with you is found without it',
35
36
  ' --shared-with-me list memories other people granted to you; each row',
36
37
  ' names its owner and whether it is on your graph',
37
38
  ' --for <contact> what one of your contacts may see of your memories and',
@@ -66,6 +67,7 @@ export const GET_HELP = [
66
67
  'Your own read of a memory also prints `access`: every allow and deny on it.',
67
68
  '',
68
69
  "A memory's web address is <site>/by/<owner-handle>/memories/<slug>-<memory-handle>.",
70
+ 'A website address keeps its own links, depth and content; a flag typed here wins for that lever.',
69
71
  'A /by read asks for JSON with Accept: application/json; it sends a bearer',
70
72
  'only when the session has a live one. `get memory` prints the address at a TTY.',
71
73
  '',
@@ -1,28 +1,76 @@
1
1
  import { parseArgs } from "../request/flags.js";
2
2
  import { contactIdFor } from "../memory/access.js";
3
3
  import { getRevision } from "../memory/history.js";
4
- import { composeAddress, formatMemoryDetail, formatMemoryPage, formatNodeWalk, ownHandleFor, parseWebsiteMemoryAddress } from "../memory/views.js";
4
+ import { composeAddress, formatMemoryDetail, formatMemoryPage, formatNodeWalk, leversFor, leversInAddress, ownHandleFor, parseWebsiteMemoryAddress } from "../memory/views.js";
5
5
  import { emit } from "../render/output.js";
6
6
  import { ambiguousText } from "../render/rows.js";
7
- import { renderRunHint } from "../render/text.js";
7
+ import { renderRunHint, sanitizeForTerminal } from "../render/text.js";
8
8
  import { optionalAccessToken, signedIn } from "../request/access-token.js";
9
9
  import { refusalOf } from "../request/api-fetch.js";
10
- import { refusal } from "../store/exit.js";
10
+ import { EXIT, refusal } from "../store/exit.js";
11
11
  import { loadSession, saveSession } from "../store/session.js";
12
+ import { isUuidKey } from "../store/write-identity.js";
13
+ const valuesOf = (value) => (Array.isArray(value) ? value : [value]);
12
14
  export const buildGetMemoryUrl = (webUrl, ownerHandle, ref, flags) => {
13
15
  const url = new URL(`${webUrl}/by/${encodeURIComponent(ownerHandle)}/memories/${encodeURIComponent(ref)}`);
14
16
  const links = flags.links ?? '1';
15
17
  const bare = links === '0' && flags.depth === undefined && flags.content === undefined;
16
18
  if (!bare) {
17
- url.searchParams.set('links', links);
18
- if (flags.depth !== undefined)
19
- url.searchParams.set('depth', flags.depth);
20
- if (flags.content !== undefined)
21
- url.searchParams.set('content', flags.content);
19
+ for (const value of valuesOf(links)) {
20
+ url.searchParams.append('links', value);
21
+ }
22
+ if (flags.depth !== undefined) {
23
+ for (const value of valuesOf(flags.depth)) {
24
+ url.searchParams.append('depth', value);
25
+ }
26
+ }
27
+ if (flags.content !== undefined) {
28
+ for (const value of valuesOf(flags.content)) {
29
+ url.searchParams.append('content', value);
30
+ }
31
+ }
22
32
  }
23
33
  return url;
24
34
  };
25
- const getMemory = async (cfg, io, idOrAddress, flags, by) => {
35
+ const SHARED_PAGE_SIZE = '100';
36
+ const SHARED_PAGES_MAX = 5;
37
+ const isSharedRow = (row) => typeof row.ownerHandle === 'string' && row.ownerHandle !== '';
38
+ const answersRef = (ref) => (row) => isUuidKey(ref)
39
+ ? row.id === ref.toLowerCase()
40
+ : row.handle === ref.slice(ref.lastIndexOf('-') + 1);
41
+ const sharedRows = async (cfg, io, accessToken, cursor, pagesLeft) => {
42
+ const url = new URL(`${cfg.apiUrl}/memories`);
43
+ url.searchParams.set('sharedWithMe', '1');
44
+ url.searchParams.set('content', '0');
45
+ url.searchParams.set('limit', SHARED_PAGE_SIZE);
46
+ if (cursor !== null) {
47
+ url.searchParams.set('cursor', cursor);
48
+ }
49
+ const result = await io.api(accessToken, url);
50
+ if (!result.ok) {
51
+ return undefined;
52
+ }
53
+ const rows = result.data.items.filter(isSharedRow);
54
+ if (!result.data.nextCursor || pagesLeft === 1) {
55
+ return rows;
56
+ }
57
+ const rest = await sharedRows(cfg, io, accessToken, result.data.nextCursor, pagesLeft - 1);
58
+ return rest === undefined ? undefined : rows.concat(rest);
59
+ };
60
+ const sharedMatches = async (cfg, io, accessToken, ref) => {
61
+ const rows = await sharedRows(cfg, io, accessToken, null, SHARED_PAGES_MAX);
62
+ if (rows === undefined) {
63
+ return [];
64
+ }
65
+ const byId = new Map(rows.filter(answersRef(ref)).map((row) => [row.id, row]));
66
+ return Array.from(byId.values());
67
+ };
68
+ const sharedAmbiguityText = (matches) => 'That handle names memories shared with you by more than one owner.\n' +
69
+ matches
70
+ .map((m) => ` ${m.id} @${sanitizeForTerminal(m.ownerHandle)} ${sanitizeForTerminal(m.title ?? '(untitled)')}\n`)
71
+ .join('') +
72
+ 'Use get memory <id> --by <owner-handle>.\n';
73
+ const getMemory = async (cfg, io, idOrAddress, flags, by, lookShared) => {
26
74
  const isAddress = /^https?:\/\//i.test(idOrAddress);
27
75
  const address = isAddress ? parseWebsiteMemoryAddress(cfg.webUrl, idOrAddress) : undefined;
28
76
  if (isAddress && !address) {
@@ -50,13 +98,27 @@ const getMemory = async (cfg, io, idOrAddress, flags, by) => {
50
98
  return refusal('A memory id needs its wall: use get memory <website-address> or get memory <id> --by <owner-handle>.\n');
51
99
  }
52
100
  accessToken ??= await optionalAccessToken(io, cfg);
53
- const url = buildGetMemoryUrl(cfg.webUrl, ownerHandle, address?.ref ?? idOrAddress, flags);
101
+ const levers = address === undefined ? flags : leversFor(flags, leversInAddress(idOrAddress));
102
+ const url = buildGetMemoryUrl(cfg.webUrl, ownerHandle, address?.ref ?? idOrAddress, levers);
54
103
  const enveloped = url.search !== '';
55
104
  const result = await io.api(accessToken, url, {
56
105
  headers: { Accept: 'application/json' },
57
106
  retryAnonymousOn401: true
58
107
  }, 'web');
59
108
  if (!result.ok) {
109
+ if (lookShared &&
110
+ result.body.code === 'memory:not-found' &&
111
+ !address &&
112
+ !by &&
113
+ accessToken !== undefined) {
114
+ const matches = await sharedMatches(cfg, io, accessToken, idOrAddress);
115
+ if (matches.length === 1) {
116
+ return getMemory(cfg, io, matches[0].id, flags, matches[0].ownerHandle, false);
117
+ }
118
+ if (matches.length > 1) {
119
+ return refusal(sharedAmbiguityText(matches), EXIT.GENERIC);
120
+ }
121
+ }
60
122
  return refusalOf(result, ambiguousText(result.body) +
61
123
  (result.body.code === 'memory:not-found' && !address && !by
62
124
  ? 'For another wall, use get memory <website-address> or get memory <id> --by <owner-handle>.\n'
@@ -216,7 +278,7 @@ export const getMemories = async (cfg, io, rest, noun) => {
216
278
  }
217
279
  return getRevision(cfg, io, id, flags.revision);
218
280
  }
219
- return getMemory(cfg, io, id, { links: flags.links, depth: flags.depth, content: flags.content }, flags.by);
281
+ return getMemory(cfg, io, id, { links: flags.links, depth: flags.depth, content: flags.content }, flags.by, true);
220
282
  }
221
283
  else if (noun === 'memories') {
222
284
  const walkFlag = WALK_ONLY_FLAGS.find((k) => flags[k] !== undefined);
@@ -0,0 +1,85 @@
1
+ import { sourceFacts } from "../memory/views.js";
2
+ import { emit } from "../render/output.js";
3
+ import { sanitizeForTerminal } from "../render/text.js";
4
+ import { signedIn } from "../request/access-token.js";
5
+ import { refusalOf } from "../request/api-fetch.js";
6
+ import { parseArgs } from "../request/flags.js";
7
+ import { isRefusal, refusal } from "../store/exit.js";
8
+ import { SOURCE_SESSION_ID_DOOR, noteWriteHeaders, requireWriteIdentity } from "../store/write-identity.js";
9
+ const CAPTURE_SOURCE_USAGE = 'Usage: lattris capture source <url> [--title-at-source "…"] [--site "…"] [--author "…"] [--published-at <time>] [--title "…"]';
10
+ export const CAPTURE_SOURCE_HELP = `capture source — keep a link: a page, a post, a video.
11
+
12
+ Lattris never visits the page: its title, site, author and date are what you
13
+ say here.
14
+
15
+ Keeping a link you already keep answers the source you have, even when the
16
+ address differs a little, and changes nothing, so running it again is safe.
17
+
18
+ ${CAPTURE_SOURCE_USAGE}
19
+
20
+ <url> the page's full address, starting https:// or http://
21
+ --title-at-source the page's own title, as the page gives it
22
+ --site the site it is on, such as a publication
23
+ --author who wrote it, as the page says
24
+ --published-at when it was published (ISO 8601, with its time and zone)
25
+ --title your own one line for it
26
+
27
+ It is private until you share it (lattris share memory <id> --with <audience>).
28
+ Your thoughts on it go in a note, linked to it with lattris link, from the
29
+ source to the note or from the note to the source; a verb the pair cannot take
30
+ is refused with the ones it can.
31
+
32
+ saved → prints the id and what the source keeps. lattris get memories --type
33
+ source lists your sources, and --q finds one by words of its title or address.`;
34
+ const SOURCE_FLAG_NAMES = {
35
+ '--title-at-source': 'titleAtSource',
36
+ '--site': 'site',
37
+ '--author': 'author',
38
+ '--published-at': 'publishedAt',
39
+ '--title': 'title'
40
+ };
41
+ const CREATED = 201;
42
+ const formatSourceReceipt = (s, created) => {
43
+ const lines = [
44
+ created ? `Saved source ${s.id}` : `Already kept source ${s.id}; nothing changed.`
45
+ ];
46
+ if (s.title) {
47
+ lines.push(` title ${sanitizeForTerminal(s.title)}`);
48
+ }
49
+ for (const fact of sourceFacts(s)) {
50
+ lines.push(` ${fact}`);
51
+ }
52
+ lines.push(` capturedAt ${s.capturedAt}`);
53
+ return lines.join('\n');
54
+ };
55
+ export const captureSource = async (cfg, io, args) => {
56
+ if (args.length === 0) {
57
+ io.stdout.write(`${CAPTURE_SOURCE_HELP}\n`);
58
+ return;
59
+ }
60
+ const { flags, positionals, unknown } = parseArgs(SOURCE_FLAG_NAMES, args);
61
+ if (unknown !== undefined) {
62
+ return refusal(`Unknown flag: ${unknown}\n`);
63
+ }
64
+ if (positionals.length !== 1) {
65
+ return refusal(`${CAPTURE_SOURCE_USAGE}\n`);
66
+ }
67
+ const identity = requireWriteIdentity(io.store, io.stdin.isTTY, SOURCE_SESSION_ID_DOOR);
68
+ if (isRefusal(identity)) {
69
+ return identity;
70
+ }
71
+ const accessToken = await signedIn(io, cfg);
72
+ if (typeof accessToken !== 'string') {
73
+ return accessToken;
74
+ }
75
+ const saved = await io.api(accessToken, `${cfg.apiUrl}/memories/sources`, {
76
+ method: 'POST',
77
+ headers: Object.assign({ 'Content-Type': 'application/json' }, noteWriteHeaders(identity)),
78
+ body: JSON.stringify(Object.assign({ url: positionals[0] }, flags))
79
+ });
80
+ if (!saved.ok) {
81
+ return refusalOf(saved);
82
+ }
83
+ emit(io, saved.data, saved.rawText, (s) => formatSourceReceipt(s, saved.status === CREATED));
84
+ };
85
+ //# sourceMappingURL=source.js.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -52,7 +52,7 @@ export const UPDATE_HELP = [
52
52
  ' names every word found. Rephrase first; override only when',
53
53
  ' the wording is meant.',
54
54
  '',
55
- ' Content arrives on stdin, like capture — no quoting, up to 5MB. Pipe',
55
+ ' Content arrives on stdin, like capture — no quoting, up to 128KB. Pipe',
56
56
  ' nothing and the words are left exactly as they were.',
57
57
  '',
58
58
  ' The write carries the fingerprint you read. If another session changed',
@@ -4,9 +4,35 @@ import { stripTrailingSlash } from "../store/environment.js";
4
4
  export const formatDeletedLine = (b) => `${b.id} ${b.deletedAt ?? '-'} rev ${b.revisionNo ?? '-'} ${b.fingerprint ?? '-'} ${sanitizeForTerminal(b.title ?? '(untitled)')}`;
5
5
  export const formatDeletedPage = (page) => page.items.map((i) => formatDeletedLine(i)).join('\n');
6
6
  const graphWord = (b) => b.consented === undefined ? '' : `${b.consented ? 'on graph' : 'off graph'} `;
7
+ const rowLabel = (b) => {
8
+ if (b.source === undefined) {
9
+ return sanitizeForTerminal(b.title ?? '(untitled)');
10
+ }
11
+ const named = b.title === null ? b.source.titleAtSource : b.title;
12
+ return `${sanitizeForTerminal(named ?? '(untitled)')} ${sanitizeForTerminal(b.source.url, Infinity)}`;
13
+ };
7
14
  export const formatBlockLine = (b) => b.ownerHandle === undefined
8
- ? `${b.id} ${b.handle} ${b.capturedAt} ${b.intent ?? '-'} ${b.visibility.public ? 'public' : '-'} ${sanitizeForTerminal(b.title ?? '(untitled)')}`
9
- : `${b.id} ${b.handle} ${b.capturedAt} by ${sanitizeForTerminal(b.ownerDisplayName ?? b.ownerHandle)} (@${b.ownerHandle}) ${graphWord(b)}${sanitizeForTerminal(b.title ?? '(untitled)')}`;
15
+ ? `${b.id} ${b.handle} ${b.capturedAt} ${b.intent ?? '-'} ${b.visibility.public ? 'public' : '-'} ${rowLabel(b)}`
16
+ : `${b.id} ${b.handle} ${b.capturedAt} by ${sanitizeForTerminal(b.ownerDisplayName ?? b.ownerHandle)} (@${b.ownerHandle}) ${graphWord(b)}${rowLabel(b)}`;
17
+ export const sourceFacts = (s) => {
18
+ if (s.url === undefined) {
19
+ return [];
20
+ }
21
+ const lines = [`url ${sanitizeForTerminal(s.url, Infinity)}`];
22
+ if (s.titleAtSource) {
23
+ lines.push(`page title ${sanitizeForTerminal(s.titleAtSource)}`);
24
+ }
25
+ if (s.site) {
26
+ lines.push(`site ${sanitizeForTerminal(s.site)}`);
27
+ }
28
+ if (s.author) {
29
+ lines.push(`author ${sanitizeForTerminal(s.author)}`);
30
+ }
31
+ if (s.publishedAt) {
32
+ lines.push(`published ${s.publishedAt}`);
33
+ }
34
+ return lines;
35
+ };
10
36
  const SLUG_MAX = 60;
11
37
  const slugify = (title) => (title ?? '')
12
38
  .toLowerCase()
@@ -42,6 +68,39 @@ export const parseWebsiteMemoryAddress = (webUrl, value) => {
42
68
  return undefined;
43
69
  }
44
70
  };
71
+ const WALK_LEVERS = ['links', 'depth', 'content'];
72
+ export const leversInAddress = (value) => {
73
+ const levers = {};
74
+ if (!URL.canParse(value)) {
75
+ return levers;
76
+ }
77
+ const { searchParams } = new URL(value);
78
+ for (const lever of WALK_LEVERS) {
79
+ const values = searchParams.getAll(lever);
80
+ if (values.length === 1) {
81
+ levers[lever] = values[0];
82
+ }
83
+ if (values.length > 1) {
84
+ levers[lever] = values;
85
+ }
86
+ }
87
+ return levers;
88
+ };
89
+ export const leversFor = (flags, address) => {
90
+ const levers = {};
91
+ const bareTyped = flags.links === '0';
92
+ for (const lever of WALK_LEVERS) {
93
+ const typed = flags[lever];
94
+ const carried = address[lever];
95
+ if (typed !== undefined) {
96
+ levers[lever] = typed;
97
+ }
98
+ else if (carried !== undefined && !bareTyped) {
99
+ levers[lever] = carried;
100
+ }
101
+ }
102
+ return levers;
103
+ };
45
104
  export const ownHandleFor = async (cfg, io, accessToken) => {
46
105
  try {
47
106
  const me = await io.api(accessToken, `${cfg.apiUrl}/person/me`);
@@ -74,6 +133,9 @@ export const formatMemoryDetail = (m, address) => {
74
133
  lines.push(`title ${sanitizeForTerminal(m.title)}`);
75
134
  if (m.source)
76
135
  lines.push(`source ${sanitizeForTerminal(m.source)}`);
136
+ for (const fact of sourceFacts(m)) {
137
+ lines.push(fact);
138
+ }
77
139
  lines.push(`audiences ${formatAudiences(m.audiences)}`);
78
140
  if (Array.isArray(m.access))
79
141
  lines.push(`access ${formatAccess(m.access)}`);
@@ -90,7 +152,7 @@ export const formatMemoryDetail = (m, address) => {
90
152
  if (Array.isArray(m.turns)) {
91
153
  lines.push('', m.turns.map((t) => formatSessionTurn(t)).join('\n\n'));
92
154
  }
93
- else {
155
+ else if (m.url === undefined) {
94
156
  lines.push('', sanitizeForTerminal(m.content ?? '', Infinity));
95
157
  }
96
158
  return lines.join('\n');
@@ -116,12 +178,21 @@ export const formatFindingAid = (a) => {
116
178
  lines.push(`structure ${a.structureHash}`);
117
179
  return lines.join('\n');
118
180
  };
181
+ const treeOf = (owner) => owner.displayName === null
182
+ ? "on another person's tree"
183
+ : `on ${sanitizeForTerminal(owner.displayName)}'s tree`;
119
184
  export const formatWalkLink = (l) => {
120
185
  const arrow = l.direction === 'out' ? '\u2192' : '\u2190';
121
186
  const title = l.node.title ? ` ${sanitizeForTerminal(l.node.title)}` : '';
122
187
  const reason = l.reason ? ` \u2014 ${sanitizeForTerminal(l.reason, Infinity)}` : '';
123
188
  const dir = l.direction === 'out' ? 'out' : 'in ';
124
- return `${dir} ${sanitizeForTerminal(l.verb)} ${arrow} ${l.node.handle} (${l.node.type})${title}${reason}`;
189
+ const foreign = l.node.foreign;
190
+ if (foreign === undefined) {
191
+ return `${dir} ${sanitizeForTerminal(l.verb)} ${arrow} ${l.node.handle} (${l.node.type})${title}${reason}`;
192
+ }
193
+ const name = l.node.title ? sanitizeForTerminal(l.node.title) : l.node.handle;
194
+ const why = l.reason ? ` \u2014 ${sanitizeForTerminal(l.reason, Infinity)}` : '';
195
+ return `${dir} ${sanitizeForTerminal(l.verb)} ${arrow} ${name} \u00b7 ${treeOf(foreign.owner)}${why}`;
125
196
  };
126
197
  export const formatNodeWalk = (w, address) => {
127
198
  const parts = [
@@ -20,7 +20,9 @@ const LINK_HELP = [
20
20
  ' <from> the cause-side block — full id or a >=4-char prefix; an',
21
21
  ' ambiguous prefix refuses and lists the matches',
22
22
  ' <to> the effect-side block — the FULL id (the wire addresses the',
23
- ' edge by it; it does not search)',
23
+ ' edge by it; it does not search): one of your own, or a',
24
+ ' block on another person’s tree that is public now — only',
25
+ ' references crosses',
24
26
  ' --verb required; the server’s registry is the ONE authority on the',
25
27
  ' vocabulary — an unknown verb refuses WITH the accepted set',
26
28
  ' for the exact pair sent, and the CLI carries no copy',
@@ -7,9 +7,20 @@ import { LINK_HELP, edges } from "./edges.js";
7
7
  import { INVITE_HELP, invites } from "./invite.js";
8
8
  import { ACCEPT_HELP, ACCEPT_USAGE, ASK_HELP, CLOSE_HELP, CLOSE_USAGE, DECLINE_HELP, DECLINE_USAGE, questions } from "./questions.js";
9
9
  import { DENY_HELP, REMOVE_DENY_HELP, SHARE_HELP, UNSHARE_HELP, grants } from "./share.js";
10
- export const listNouns = [contacts, questions, edges, invites, grants, datasets];
10
+ import { SUBSCRIBE_HELP, subscribers, subscriptions } from "./subscribers.js";
11
+ export const listNouns = [
12
+ contacts,
13
+ questions,
14
+ edges,
15
+ invites,
16
+ grants,
17
+ datasets,
18
+ subscribers,
19
+ subscriptions
20
+ ];
11
21
  export const listVerbs = {
12
22
  ask: { help: ASK_HELP, helpBeforeAuth: true },
23
+ subscribe: { help: SUBSCRIBE_HELP, helpBeforeAuth: true },
13
24
  close: {
14
25
  help: CLOSE_HELP,
15
26
  helpBeforeAuth: true,
@@ -1,6 +1,10 @@
1
1
  import { formatContact } from "../render/rows.js";
2
2
  import { sanitizeForTerminal } from "../render/text.js";
3
- const inviteLink = (webUrl, token) => `${webUrl}/i/${token}`;
3
+ export const inviteLink = (webUrl, token) => `${webUrl}/i/${token}`;
4
+ const NOT_EMAILED = 'Not emailed: an internal Lattris address. Hand them this link.';
5
+ export const mintedLines = (webUrl, minted, address) => `${minted.emailed ? `Sending the invite to ${address}.` : NOT_EMAILED}\n\n` +
6
+ ` ${inviteLink(webUrl, minted.token)}\n\n` +
7
+ `You can see it again with: lattris get invites`;
4
8
  const formatInvite = (webUrl, i) => {
5
9
  const label = i.targetName ? ` — ${sanitizeForTerminal(i.targetName)}` : '';
6
10
  const admits = i.email ? `\n admits ${sanitizeForTerminal(i.email)}` : '';
@@ -12,18 +16,18 @@ const formatInvite = (webUrl, i) => {
12
16
  }
13
17
  if (i.revokedAt)
14
18
  return `revoked${label}${admits}\n minted ${i.createdAt}`;
19
+ if (i.email === null || i.token === null) {
20
+ return `out of date${label}\n minted ${i.createdAt}`;
21
+ }
15
22
  return `live${label}${admits}\n ${inviteLink(webUrl, i.token)}\n minted ${i.createdAt}`;
16
23
  };
17
24
  const INVITE_HELP = [
18
25
  'invite — bring one person in.',
19
26
  '',
20
- 'Mints a single-use invitation and prints the link. Hand it to ONE person.',
21
- 'It is spent when someone signs up with it.',
22
- '',
23
- 'AN INVITATION IS NOT PERMISSION. It records who brought someone. Whether an',
24
- 'address may register at all is a separate decision, made by hand — so a',
25
- 'person can hold a good invitation and still be turned away. Tell them that',
26
- 'when you send it.',
27
+ 'Mints a single-use invitation, emails the link to the address it admits,',
28
+ 'and prints it. Only an account signed in with that address can take it, and',
29
+ 'it is spent when it is taken. An invitation from the Lattris account to a',
30
+ 'lattris.com address is not emailed: hand the person the link.',
27
31
  '',
28
32
  'Usage:',
29
33
  ' lattris invite <contact-name-or-id> [--email <address>] [--yes]',
@@ -93,12 +97,7 @@ const inviteVerb = {
93
97
  : context.recordedEmail
94
98
  ? `Recorded ${admitted} on ${sanitizeForTerminal(contact.displayName)}.\n\n`
95
99
  : '';
96
- return (first +
97
- `Invitation minted${i.targetName ? ` for ${sanitizeForTerminal(i.targetName)}` : ''}, admitting ${admitted}.\n\n` +
98
- ` ${inviteLink(context.webUrl, i.token)}\n\n` +
99
- `Hand it to ONE person — it is spent when someone signs up with it.\n` +
100
- `It is not permission to join; whether they may register is decided separately.\n` +
101
- `You can see it again with: lattris get invites`);
100
+ return first + mintedLines(context.webUrl, i, admitted);
102
101
  }
103
102
  }
104
103
  };
@@ -0,0 +1,163 @@
1
+ import { sanitizeForTerminal } from "../render/text.js";
2
+ import { mintedLines } from "./invite.js";
3
+ import { verbsOf } from "./form.js";
4
+ const relationWords = (relation) => relation.replace(/-/g, ' ');
5
+ export const formatSubscriber = (s, asking = false) => `${sanitizeForTerminal(s.email)} · ${sanitizeForTerminal(s.status)} · ${s.id}` +
6
+ `${s.name ? ` · ${sanitizeForTerminal(s.name)}` : ''}` +
7
+ `${s.relation ? ` · ${sanitizeForTerminal(relationWords(s.relation))}` : ''}` +
8
+ `${s.wantsAccess && !asking ? ' · wants to try Lattris' : ''}` +
9
+ `${s.reason ? ` · “${sanitizeForTerminal(s.reason)}”` : ''}`;
10
+ export const SUBSCRIBE_HELP = [
11
+ 'subscribe — leave your email on someone’s public page, to stay in touch.',
12
+ '',
13
+ 'Needs no account and no session: a reader’s own AI can do it for them. The',
14
+ 'page owner reads the list; nothing is sent to the address but a confirmation,',
15
+ 'and the subscription stands only once that confirmation is clicked.',
16
+ '',
17
+ 'Usage:',
18
+ ' lattris subscribe <handle> <email> [--try]',
19
+ '',
20
+ ' <handle> the page’s address, as it appears at /by/<handle>',
21
+ ' <email> the address the confirmation goes to',
22
+ ' --try say you would like to try Lattris',
23
+ '',
24
+ 'The answer is the same whatever is already true about the address: "Check',
25
+ 'your inbox to confirm." An address already confirmed is sent nothing; one',
26
+ 'that asked recently waits a minute between confirmations, three a day.',
27
+ 'The confirm page the email links to asks the optional questions. A page',
28
+ 'with nothing public, or a handle that names nobody, is answered not found,',
29
+ 'and the two are not told apart.'
30
+ ].join('\n');
31
+ const SUBSCRIBERS_HELP = [
32
+ 'subscribers — the readers who left their email on your public page.',
33
+ '',
34
+ 'Usage:',
35
+ ' lattris subscribers list [--status pending|confirmed|unsubscribed] [--wants-access]',
36
+ ' every subscriber of yours, newest first;',
37
+ ' --wants-access: only the ones who asked to',
38
+ ' try Lattris',
39
+ ' lattris subscribers get <id> one subscriber, by its full id or a unique prefix',
40
+ ' lattris subscribers delete <id> [--yes] forget one: their address and answers are',
41
+ ' deleted; asks at a terminal, needs --yes on a pipe',
42
+ ' lattris subscribers admit <id> [--yes] invite one who asked to try Lattris; asks at a',
43
+ ' terminal, needs --yes on a pipe',
44
+ '',
45
+ 'A subscriber is not an account and not a contact: an address, whether it was',
46
+ 'confirmed, and what the reader chose to say (a name, how they know you, what',
47
+ 'brought them, whether they would like to try Lattris). pending has not clicked',
48
+ 'the confirmation yet and is forgotten with its link after seven days;',
49
+ 'unsubscribed stays, with the answers cleared, so a return needs a fresh',
50
+ 'confirmation.'
51
+ ].join('\n');
52
+ const subscribeVerb = {
53
+ verb: 'subscribe',
54
+ form: {
55
+ usage: 'Usage: lattris subscribe <handle> <email> [--try]',
56
+ switches: ['--try'],
57
+ positionals: 2,
58
+ credential: 'none',
59
+ request: {
60
+ method: 'POST',
61
+ path: '/by/{p0}/subscribers',
62
+ body: {
63
+ email: { positional: 1, trim: true },
64
+ wantsAccess: { switch: '--try', value: true }
65
+ }
66
+ },
67
+ render: (data) => sanitizeForTerminal(data.message)
68
+ }
69
+ };
70
+ export const subscriptions = {
71
+ name: 'subscriptions',
72
+ words: { singular: 'subscription', plural: 'subscriptions' },
73
+ help: SUBSCRIBE_HELP,
74
+ verbs: [subscribeVerb]
75
+ };
76
+ export const subscribers = {
77
+ name: 'subscribers',
78
+ words: { singular: 'subscribers', plural: 'subscribers' },
79
+ grammar: 'noun-first',
80
+ help: SUBSCRIBERS_HELP,
81
+ helpBeforeAuth: true,
82
+ unknownVerb: 'Unknown subscribers verb: {verb}\n\n' + SUBSCRIBERS_HELP + '\n',
83
+ verbs: verbsOf({
84
+ list: {
85
+ usage: 'Usage: lattris subscribers list [--status pending|confirmed|unsubscribed] [--wants-access]',
86
+ flags: { '--status': 'status' },
87
+ switches: ['--wants-access'],
88
+ positionals: 0,
89
+ unknownFlagIsUsage: true,
90
+ request: {
91
+ method: 'GET',
92
+ path: '/subscribers',
93
+ query: {
94
+ status: { flag: 'status' },
95
+ wantsAccess: { switch: '--wants-access', value: 'true' }
96
+ }
97
+ },
98
+ render: (list, context) => {
99
+ const rows = list;
100
+ const asking = context.on.has('--wants-access');
101
+ if (rows.length === 0) {
102
+ return asking
103
+ ? 'Nobody has asked to try Lattris yet.'
104
+ : 'No subscribers yet. Nobody has left their email on your page.';
105
+ }
106
+ return rows.map((s) => formatSubscriber(s, asking)).join('\n');
107
+ }
108
+ },
109
+ get: {
110
+ usage: 'Usage: lattris subscribers get <id>',
111
+ positionals: 1,
112
+ idPositionals: [0],
113
+ unknownFlagIsUsage: true,
114
+ request: { method: 'GET', path: '/subscribers/{p0}' },
115
+ render: (s) => formatSubscriber(s)
116
+ },
117
+ delete: {
118
+ usage: 'Usage: lattris subscribers delete <id> [--yes]',
119
+ switches: ['--yes'],
120
+ positionals: 1,
121
+ idPositionals: [0],
122
+ steps: {
123
+ pipedNeedsYes: {
124
+ message: 'Refusing to forget a subscriber without confirmation on a non-interactive session. Pass --yes to skip the prompt.\n'
125
+ },
126
+ confirm: {
127
+ question: 'Forget subscriber {p0}? Their address and answers are deleted. [y/N] ',
128
+ onNo: { text: 'Cancelled.\n', to: 'stderr' },
129
+ onInterrupted: { text: 'Cancelled.\n', exit: 1 }
130
+ }
131
+ },
132
+ request: { method: 'DELETE', path: '/subscribers/{p0}' },
133
+ renderTo: 'stderr',
134
+ render: (_answer, context) => `Forgot subscriber ${sanitizeForTerminal(context.positionals[0])}`
135
+ },
136
+ admit: {
137
+ usage: 'Usage: lattris subscribers admit <id> [--yes]',
138
+ switches: ['--yes'],
139
+ positionals: 1,
140
+ idPositionals: [0],
141
+ steps: {
142
+ pipedNeedsYes: {
143
+ message: 'Refusing to admit a subscriber without confirmation on a non-interactive session. Pass --yes to skip the prompt.\n'
144
+ },
145
+ subscriber: true,
146
+ confirm: {
147
+ question: 'Invite {subscriber.email} to Lattris? [y/N] ',
148
+ onNo: { text: 'Not invited.\n', to: 'stdout' }
149
+ }
150
+ },
151
+ request: { method: 'POST', path: '/subscribers/{p0}/admit' },
152
+ refusalInstead: {
153
+ 'subscriber:already-invited': '{subscriber.email} already has an invite. Revoke it in Settings to send a new one.\n',
154
+ 'subscriber:already-joined': '{subscriber.email} has already joined.\n'
155
+ },
156
+ render: (data, context) => {
157
+ const i = data;
158
+ return mintedLines(context.webUrl, i, sanitizeForTerminal(i.email));
159
+ }
160
+ }
161
+ })
162
+ };
163
+ //# sourceMappingURL=subscribers.js.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -23,10 +23,13 @@ export const USAGE_LINES = [
23
23
  ' lattris capture memory Capture a memory — `echo "…" | lattris capture memory`',
24
24
  ' lattris capture session <transcript> Save an AI conversation — the whole chain from its file',
25
25
  ' lattris capture recording Keep a recording \u2014 held audio, a source, or a transcript file',
26
+ ' lattris capture source <url> Keep a link \u2014 a page, a post, a video \u2014 with its title, site, author and date',
26
27
  ' lattris get memories List your memories, newest first, with filters (--for <contact> for what they may see)',
27
28
  ' lattris contact create "<name>" Record a person or an AI you work with (--ai, --phone); add, list, get, update, delete, link',
28
29
  ' lattris invite <contact> [--email <address>] Mint an invitation for one of your person contacts, admitting one address',
29
30
  ' lattris get invites List the invitations you have minted',
31
+ ' lattris subscribe <handle> <email> Leave your email on someone’s public page, no account needed (--try)',
32
+ ' lattris subscribers list The readers who left their email on your page (--status, --wants-access); get, delete, admit',
30
33
  ' lattris get memory <id> Read one memory back \u2014 words and edges (--links/--depth/--content)',
31
34
  ' lattris ask <handle> Leave a question on someone\u2019s tree \u2014 `echo "\u2026" | lattris ask <handle>`',
32
35
  ' lattris get questions The questions on your tree, open first (--mine: ones you asked)',
@@ -86,6 +89,8 @@ export const COMMAND_WORDS = new Set([
86
89
  'erase',
87
90
  'resend',
88
91
  'contact',
92
+ 'subscribe',
93
+ 'subscribers',
89
94
  'logout',
90
95
  '--as'
91
96
  ]);
@@ -13,6 +13,7 @@ import { CAPTURE_RECORDING_HELP, captureRecording } from "../memory/recording.js
13
13
  import { updateRecording } from "../memory/recording-update.js";
14
14
  import { RESEND_HELP, resend } from "../memory/resend.js";
15
15
  import { RESTORE_HELP, restoreMemory } from "../memory/restore.js";
16
+ import { CAPTURE_SOURCE_HELP, captureSource } from "../memory/source.js";
16
17
  import { UPDATE_HELP } from "../memory/update-help.js";
17
18
  import { updateMemory } from "../memory/update.js";
18
19
  export const memoryNouns = [
@@ -55,6 +56,12 @@ export const memoryNouns = [
55
56
  { verb: 'capture', nouns: ['recording'], handler: captureRecording },
56
57
  { verb: 'update', nouns: ['recording', 'recordings'], handler: updateRecording }
57
58
  ]
59
+ },
60
+ {
61
+ name: 'sources',
62
+ words: { singular: 'source', plural: 'sources' },
63
+ help: CAPTURE_SOURCE_HELP,
64
+ verbs: [{ verb: 'capture', nouns: ['source'], handler: captureSource }]
58
65
  }
59
66
  ];
60
67
  const captureHelp = (args) => {
@@ -66,6 +73,8 @@ const captureHelp = (args) => {
66
73
  return CAPTURE_NOTE_HELP;
67
74
  if (args[0] === 'recording')
68
75
  return CAPTURE_RECORDING_HELP;
76
+ if (args[0] === 'source')
77
+ return CAPTURE_SOURCE_HELP;
69
78
  return CAPTURE_INDEX;
70
79
  };
71
80
  export const memoryVerbs = {
@@ -133,16 +133,17 @@ export const resolveWriteIdentityDetail = (store, atTerminal) => {
133
133
  const sessionId = mintTerminalIdentity(store, join(sessionDir(store), 'sessions'), key);
134
134
  return { kind: 'ok', identity: { sessionId, agentLabel } };
135
135
  };
136
- export const requireWriteIdentity = (store, atTerminal) => {
136
+ export const requireWriteIdentity = (store, atTerminal, door = SESSION_ID_DOOR) => {
137
137
  const r = resolveWriteIdentityDetail(store, atTerminal);
138
138
  if (r.kind === 'ok')
139
139
  return r.identity;
140
- return refusal(`${r.kind === 'invalid' ? r.words : SESSION_ID_DOOR}\n`, EXIT.USAGE);
140
+ return refusal(`${r.kind === 'invalid' ? r.words : door}\n`, EXIT.USAGE);
141
141
  };
142
- export const SESSION_ID_DOOR = 'This write changes a note’s history and has to name the session doing it. ' +
143
- 'Off a terminal there is no session to infer: set LATTRIS_SESSION_ID to a stable ' +
142
+ const NAME_THE_SESSION = 'Off a terminal there is no session to infer: set LATTRIS_SESSION_ID to a stable ' +
144
143
  'name for this worker or run (1 to 128 characters), and LATTRIS_AGENT to a readable ' +
145
144
  'label if you want one. Nothing was written.';
145
+ export const SESSION_ID_DOOR = `This write changes a note’s history and has to name the session doing it. ${NAME_THE_SESSION}`;
146
+ export const SOURCE_SESSION_ID_DOOR = `Saving a source has to name the session doing it. ${NAME_THE_SESSION}`;
146
147
  export const noteWriteHeaders = (identity, idempotencyKey) => ({
147
148
  'X-Lattris-Session-Id': identity.sessionId,
148
149
  ...(identity.agentLabel ? { 'X-Lattris-Agent': identity.agentLabel } : {}),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lattris",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "type": "module",
5
5
  "description": "First-party CLI for Lattris — sign in, capture notes and sessions, and read your own tree from the terminal.",
6
6
  "keywords": [