lattris 0.2.4 → 0.2.5

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/dist/build.json CHANGED
@@ -1 +1 @@
1
- {"commit":"dc66fbb3976033f182a724475ba45e03afd5ec17","builtAt":"2026-11-05T05:03:06Z"}
1
+ {"commit":"e8530aa15f1fe801130caa1d6405e9ac2288edf5","builtAt":"2026-11-17T04:12:13Z"}
@@ -168,4 +168,13 @@ export const SESSION_ONLY_FLAGS = [
168
168
  ['--forked-from', 'forkedFrom']
169
169
  ];
170
170
  export const retryWords = (path) => renderRunHint(['resend', path]);
171
+ export const readTextFile = (io, path) => {
172
+ try {
173
+ const text = io.store.files.readFileSync(path, 'utf8');
174
+ return text.length === 0 ? refusal(`The text is empty: ${path}\n`) : text;
175
+ }
176
+ catch {
177
+ return refusal(`Cannot read the text file: ${path}\n`);
178
+ }
179
+ };
171
180
  //# sourceMappingURL=capture-common.js.map
@@ -6,6 +6,7 @@ export const CAPTURE_INDEX = [
6
6
  ' session a conversation with an AI, kept as an append-only ledger',
7
7
  ' recording audio, its source, and its transcript',
8
8
  ' source a link you keep: a page, a post, a video',
9
+ ' engagement the numbers a source had on a day: impressions, likes, comments, shares',
9
10
  ' rows rows of a dataset, newline-delimited JSON',
10
11
  '',
11
12
  'Go one word deeper:',
@@ -14,7 +15,8 @@ export const CAPTURE_INDEX = [
14
15
  ' lattris capture memory --type session how to save a conversation (capture session accepted too)',
15
16
  ' lattris capture session <transcript.jsonl> save a Claude Code conversation, whole chain',
16
17
  ' lattris capture recording how to save audio + transcript',
17
- ' lattris capture source how to keep a link',
18
+ ' lattris capture source how to keep a link, its text and its numbers',
19
+ ' lattris capture engagement how to add a dated reading of a source\u2019s numbers',
18
20
  ' lattris capture rows how to save rows into a dataset',
19
21
  '',
20
22
  'To read what you have kept: lattris get memories',
@@ -42,6 +44,9 @@ If it came from somewhere else, say so in the words.
42
44
 
43
45
  Offer a one-line title — what this is about. It's how they'll find it later.
44
46
 
47
+ To add a video, paste a YouTube link on a line by itself. Put words in
48
+ [brackets](link) to give it a title.
49
+
45
50
  Which intent? Take the first that fits.
46
51
 
47
52
  already done it → action
@@ -0,0 +1,98 @@
1
+ import { COUNTS, formatCounts } from "../memory/views.js";
2
+ import { emit } from "../render/output.js";
3
+ import { signedIn } from "../request/access-token.js";
4
+ import { refusalOf } from "../request/api-fetch.js";
5
+ import { parseArgs } from "../request/flags.js";
6
+ import { isRefusal, refusal } from "../store/exit.js";
7
+ export const READING_FLAG_NAMES = {
8
+ '--impressions': 'impressions',
9
+ '--likes': 'likes',
10
+ '--comments': 'comments',
11
+ '--shares': 'shares',
12
+ '--as-of': 'asOf'
13
+ };
14
+ const NOT_FOUND = 404;
15
+ const WHOLE_NUMBER = /^\d+$/;
16
+ export const givesNumbers = (flags) => COUNTS.some((name) => flags[name] !== undefined) || flags.asOf !== undefined;
17
+ export const buildReading = (flags, nowMs) => {
18
+ const given = COUNTS.filter((name) => flags[name] !== undefined);
19
+ if (given.length === 0) {
20
+ return refusal('A reading needs at least one of --impressions, --likes, --comments, --shares.\n');
21
+ }
22
+ const counts = {};
23
+ for (const name of given) {
24
+ const value = flags[name];
25
+ if (value === undefined || !WHOLE_NUMBER.test(value) || !Number.isSafeInteger(Number(value))) {
26
+ return refusal(`--${name} must be a whole number, 0 or more: ${value}\n`);
27
+ }
28
+ counts[name] = Number(value);
29
+ }
30
+ const asOf = flags.asOf === undefined ? new Date(nowMs).toISOString() : flags.asOf;
31
+ return Object.assign({ asOf }, counts);
32
+ };
33
+ export const postReading = (cfg, io, accessToken, id, reading) => io.api(accessToken, `${cfg.apiUrl}/memories/${encodeURIComponent(id)}/engagement`, {
34
+ method: 'POST',
35
+ headers: { 'Content-Type': 'application/json' },
36
+ body: JSON.stringify(reading)
37
+ });
38
+ export const ownerSourceFacts = async (cfg, io, accessToken, id) => {
39
+ const result = await io.api(accessToken, `${cfg.apiUrl}/memories/${encodeURIComponent(id)}`);
40
+ if (result.ok) {
41
+ return { body: result.data.body, engagement: result.data.engagement };
42
+ }
43
+ return result.status === NOT_FOUND ? undefined : refusalOf(result);
44
+ };
45
+ export const readingHistory = (cfg, io, accessToken, id) => io.api(accessToken, `${cfg.apiUrl}/memories/${encodeURIComponent(id)}/engagement`);
46
+ export const CAPTURE_ENGAGEMENT_USAGE = 'Usage: lattris capture engagement <source-id> [--impressions N] [--likes N] [--comments N] [--shares N] [--as-of <date>]';
47
+ export const CAPTURE_ENGAGEMENT_HELP = `capture engagement — keep the numbers a source had on a day.
48
+
49
+ Lattris never visits the page: the numbers are what you read off it and type
50
+ here. Each run adds one dated reading; none is ever edited, so the history
51
+ shows how the numbers moved.
52
+
53
+ ${CAPTURE_ENGAGEMENT_USAGE}
54
+
55
+ <source-id> a full id or a >=4-char prefix of a source you kept
56
+ --impressions how many saw it
57
+ --likes how many liked it
58
+ --comments how many comments it had
59
+ --shares how many times it was shared
60
+ --as-of the day the numbers were true (2026-11-16, or a full time
61
+ with its zone); default now, and no more than a day ahead
62
+
63
+ Give at least one count, each a whole number, 0 or more. Only you read the
64
+ numbers. lattris get memory <id> prints the latest; --engagement prints every
65
+ reading, latest first.
66
+
67
+ saved → prints the reading.`;
68
+ const formatReadingReceipt = (id, r) => `Saved reading for ${id}\n asOf ${r.asOf}\n ${formatCounts(r)}`;
69
+ export const captureEngagement = async (cfg, io, args) => {
70
+ if (args.length === 0) {
71
+ io.stdout.write(`${CAPTURE_ENGAGEMENT_HELP}\n`);
72
+ return;
73
+ }
74
+ const { flags, positionals, unknown, notAnId } = parseArgs(READING_FLAG_NAMES, args, [0]);
75
+ if (unknown !== undefined) {
76
+ return refusal(`Unknown flag: ${unknown}\n`);
77
+ }
78
+ if (notAnId !== undefined) {
79
+ return refusal(notAnId);
80
+ }
81
+ if (positionals.length !== 1) {
82
+ return refusal(`${CAPTURE_ENGAGEMENT_USAGE}\n`);
83
+ }
84
+ const reading = buildReading(flags, io.store.now());
85
+ if (isRefusal(reading)) {
86
+ return reading;
87
+ }
88
+ const accessToken = await signedIn(io, cfg);
89
+ if (typeof accessToken !== 'string') {
90
+ return accessToken;
91
+ }
92
+ const saved = await postReading(cfg, io, accessToken, positionals[0], reading);
93
+ if (!saved.ok) {
94
+ return refusalOf(saved);
95
+ }
96
+ emit(io, saved.data, saved.rawText, (r) => formatReadingReceipt(positionals[0], r));
97
+ };
98
+ //# sourceMappingURL=engagement.js.map
@@ -12,7 +12,7 @@ export const GET_HELP = [
12
12
  'Usage:',
13
13
  ' lattris get memories [--shared-with-me] [--q <words>] [--type <name>] [--intent <name>] [--with <audience>] [--for <contact> | --for-phone <number>] [--limit <n>] [--cursor <token>] [--content 0|1]',
14
14
  ' lattris get memories --by <owner-handle> [--limit <n>] [--cursor <token>] [--content 0|1]',
15
- ' lattris get memory <website-address|id> [--by <owner-handle>] [--links 0|1] [--depth <n>] [--content 0|1]',
15
+ ' lattris get memory <website-address|id> [--by <owner-handle>] [--links 0|1] [--depth <n>] [--content 0|1] [--engagement]',
16
16
  ' lattris get memory <id-or-prefix> --revision <n> one revision, as history kept it',
17
17
  ' lattris get history <id-or-prefix> [--limit <n>] [--before <operation-id>]',
18
18
  ' lattris get deleted [--limit <n>] [--cursor <token>]',
@@ -55,6 +55,10 @@ export const GET_HELP = [
55
55
  ' field a writer needs (fingerprint, revisionNo, structureHash)',
56
56
  ' --mine (questions) the ones YOU asked, with how each closed',
57
57
  '',
58
+ ' --engagement (a source you own) every dated reading of its numbers,',
59
+ ' latest first. A source you own always shows its latest',
60
+ ' numbers and its text.',
61
+ '',
58
62
  ' --revision <n> the snapshot numbered n: title, words, metadata, its',
59
63
  ' fingerprint and who recorded it. Restore it with',
60
64
  ' `lattris restore memory <id> --revision <n> --base-fingerprint <head>`.',
@@ -2,12 +2,13 @@ import { parseArgs } from "../request/flags.js";
2
2
  import { contactIdFor } from "../memory/access.js";
3
3
  import { getRevision } from "../memory/history.js";
4
4
  import { composeAddress, formatMemoryDetail, formatMemoryPage, formatNodeWalk, leversFor, leversInAddress, ownHandleFor, parseWebsiteMemoryAddress } from "../memory/views.js";
5
+ import { ownerSourceFacts, readingHistory } from "../memory/engagement.js";
5
6
  import { emit } from "../render/output.js";
6
7
  import { ambiguousText } from "../render/rows.js";
7
8
  import { renderRunHint, sanitizeForTerminal } from "../render/text.js";
8
9
  import { optionalAccessToken, signedIn } from "../request/access-token.js";
9
10
  import { refusalOf } from "../request/api-fetch.js";
10
- import { EXIT, refusal } from "../store/exit.js";
11
+ import { EXIT, isRefusal, refusal } from "../store/exit.js";
11
12
  import { loadSession, saveSession } from "../store/session.js";
12
13
  import { isUuidKey } from "../store/write-identity.js";
13
14
  const valuesOf = (value) => (Array.isArray(value) ? value : [value]);
@@ -70,7 +71,7 @@ const sharedAmbiguityText = (matches) => 'That handle names memories shared with
70
71
  .map((m) => ` ${m.id} @${sanitizeForTerminal(m.ownerHandle)} ${sanitizeForTerminal(m.title ?? '(untitled)')}\n`)
71
72
  .join('') +
72
73
  'Use get memory <id> --by <owner-handle>.\n';
73
- const getMemory = async (cfg, io, idOrAddress, flags, by, lookShared) => {
74
+ const getMemory = async (cfg, io, idOrAddress, flags, by, lookShared, withHistory) => {
74
75
  const isAddress = /^https?:\/\//i.test(idOrAddress);
75
76
  const address = isAddress ? parseWebsiteMemoryAddress(cfg.webUrl, idOrAddress) : undefined;
76
77
  if (isAddress && !address) {
@@ -98,9 +99,13 @@ const getMemory = async (cfg, io, idOrAddress, flags, by, lookShared) => {
98
99
  return refusal('A memory id needs its wall: use get memory <website-address> or get memory <id> --by <owner-handle>.\n');
99
100
  }
100
101
  accessToken ??= await optionalAccessToken(io, cfg);
102
+ const session = loadSession(io.store);
103
+ const mine = session !== undefined && session.handle === ownerHandle;
104
+ if (withHistory && (!mine || accessToken === undefined)) {
105
+ return refusal('--engagement reads your own sources: sign in, and read one on your own wall.\n');
106
+ }
101
107
  const levers = address === undefined ? flags : leversFor(flags, leversInAddress(idOrAddress));
102
108
  const url = buildGetMemoryUrl(cfg.webUrl, ownerHandle, address?.ref ?? idOrAddress, levers);
103
- const enveloped = url.search !== '';
104
109
  const result = await io.api(accessToken, url, {
105
110
  headers: { Accept: 'application/json' },
106
111
  retryAnonymousOn401: true
@@ -113,7 +118,7 @@ const getMemory = async (cfg, io, idOrAddress, flags, by, lookShared) => {
113
118
  accessToken !== undefined) {
114
119
  const matches = await sharedMatches(cfg, io, accessToken, idOrAddress);
115
120
  if (matches.length === 1) {
116
- return getMemory(cfg, io, matches[0].id, flags, matches[0].ownerHandle, false);
121
+ return getMemory(cfg, io, matches[0].id, flags, matches[0].ownerHandle, false, withHistory);
117
122
  }
118
123
  if (matches.length > 1) {
119
124
  return refusal(sharedAmbiguityText(matches), EXIT.GENERIC);
@@ -124,13 +129,39 @@ const getMemory = async (cfg, io, idOrAddress, flags, by, lookShared) => {
124
129
  ? 'For another wall, use get memory <website-address> or get memory <id> --by <owner-handle>.\n'
125
130
  : ''));
126
131
  }
127
- const record = enveloped ? result.data.node : result.data;
132
+ const data = result.data;
133
+ const record = 'node' in data ? data.node : data;
128
134
  const displayAddress = io.stdout.isTTY
129
135
  ? composeAddress(cfg.webUrl, ownerHandle, record)
130
136
  : undefined;
131
- emit(io, result.data, result.rawText, () => enveloped
132
- ? formatNodeWalk(result.data, displayAddress)
133
- : formatMemoryDetail(result.data, displayAddress));
137
+ if (withHistory && record.type !== 'source') {
138
+ return refusal('--engagement is for a source; this memory is not one.\n');
139
+ }
140
+ const extras = mine && accessToken !== undefined && record.type === 'source' && 'capturedAt' in record
141
+ ? await sourceExtras(cfg, io, accessToken, record.id, withHistory)
142
+ : undefined;
143
+ if (isRefusal(extras)) {
144
+ return extras;
145
+ }
146
+ const whole = extras === undefined
147
+ ? data
148
+ : 'node' in data
149
+ ? Object.assign({}, data, { node: Object.assign({}, data.node, extras) })
150
+ : Object.assign({}, data, extras);
151
+ emit(io, whole, extras === undefined ? result.rawText : JSON.stringify(whole), () => 'node' in whole
152
+ ? formatNodeWalk(whole, displayAddress)
153
+ : formatMemoryDetail(whole, displayAddress));
154
+ };
155
+ const sourceExtras = async (cfg, io, accessToken, id, withHistory) => {
156
+ const owned = await ownerSourceFacts(cfg, io, accessToken, id);
157
+ if (isRefusal(owned) || !withHistory) {
158
+ return owned;
159
+ }
160
+ const history = await readingHistory(cfg, io, accessToken, id);
161
+ if (!history.ok) {
162
+ return refusalOf(history);
163
+ }
164
+ return Object.assign({}, owned, { engagementHistory: history.data.items });
134
165
  };
135
166
  const GET_FLAG_NAMES = {
136
167
  '--by': 'by',
@@ -251,7 +282,8 @@ export const getMemories = async (cfg, io, rest, noun) => {
251
282
  if (sharedWithMeCount > 1) {
252
283
  return refusal('--shared-with-me was given more than once. Send it once.\n');
253
284
  }
254
- const { flags, positionals, unknown, notAnId } = parseArgs(GET_FLAG_NAMES, rest.filter((arg) => arg !== '--shared-with-me'), [0]);
285
+ const withHistory = rest.includes('--engagement');
286
+ const { flags, positionals, unknown, notAnId } = parseArgs(GET_FLAG_NAMES, rest.filter((arg) => arg !== '--shared-with-me' && arg !== '--engagement'), [0]);
255
287
  if (sharedWithMeCount === 1)
256
288
  flags.sharedWithMe = '1';
257
289
  if (unknown) {
@@ -263,6 +295,9 @@ export const getMemories = async (cfg, io, rest, noun) => {
263
295
  return refusal(`Unexpected argument: ${positionals[1]}\n`);
264
296
  }
265
297
  const id = positionals[0];
298
+ if (withHistory && id === undefined) {
299
+ return refusal('--engagement applies to a single source, not the list.\n');
300
+ }
266
301
  if (id !== undefined) {
267
302
  const inapplicable = LIST_ONLY_FLAGS.find((k) => flags[k] !== undefined);
268
303
  if (inapplicable !== undefined) {
@@ -276,9 +311,12 @@ export const getMemories = async (cfg, io, rest, noun) => {
276
311
  if (walkFlag !== undefined) {
277
312
  return refusal(`--${walkFlag} does not apply to a revision read.\n`);
278
313
  }
314
+ if (withHistory) {
315
+ return refusal('--engagement does not apply to a revision read.\n');
316
+ }
279
317
  return getRevision(cfg, io, id, flags.revision);
280
318
  }
281
- return getMemory(cfg, io, id, { links: flags.links, depth: flags.depth, content: flags.content }, flags.by, true);
319
+ return getMemory(cfg, io, id, { links: flags.links, depth: flags.depth, content: flags.content }, flags.by, true, withHistory);
282
320
  }
283
321
  else if (noun === 'memories') {
284
322
  const walkFlag = WALK_ONLY_FLAGS.find((k) => flags[k] !== undefined);
@@ -1,4 +1,6 @@
1
- import { sourceFacts } from "../memory/views.js";
1
+ import { READING_FLAG_NAMES, buildReading, givesNumbers, postReading } from "../memory/engagement.js";
2
+ import { readTextFile } from "../memory/capture-common.js";
3
+ import { COUNTS, sourceFacts } from "../memory/views.js";
2
4
  import { emit } from "../render/output.js";
3
5
  import { sanitizeForTerminal } from "../render/text.js";
4
6
  import { signedIn } from "../request/access-token.js";
@@ -6,7 +8,7 @@ import { refusalOf } from "../request/api-fetch.js";
6
8
  import { parseArgs } from "../request/flags.js";
7
9
  import { isRefusal, refusal } from "../store/exit.js";
8
10
  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 "…"]';
11
+ const CAPTURE_SOURCE_USAGE = 'Usage: lattris capture source <url> [--title-at-source "…"] [--site "…"] [--author "…"] [--published-at <time>] [--title "…"] [--body-file <path>] [--impressions N] [--likes N] [--comments N] [--shares N] [--as-of <date>]';
10
12
  export const CAPTURE_SOURCE_HELP = `capture source — keep a link: a page, a post, a video.
11
13
 
12
14
  Lattris never visits the page: its title, site, author and date are what you
@@ -23,6 +25,19 @@ ${CAPTURE_SOURCE_USAGE}
23
25
  --author who wrote it, as the page says
24
26
  --published-at when it was published (ISO 8601, with its time and zone)
25
27
  --title your own one line for it
28
+ --body-file a file holding the page's own text, kept with the source
29
+ --impressions how many saw it, as of --as-of
30
+ --likes how many liked it
31
+ --comments how many comments it had
32
+ --shares how many times it was shared
33
+ --as-of the day those numbers were true (2026-11-16, or a full
34
+ time with its zone); default now
35
+
36
+ The text is up to 128KB and only you read it; lattris get memory <id> says it is
37
+ kept, and prints it. Replace or clear it later with lattris update memory.
38
+ Give at least one count to keep the first reading of its numbers with the
39
+ source; each run that gives counts adds one reading. Later readings:
40
+ lattris capture engagement <id>.
26
41
 
27
42
  It is private until you share it (lattris share memory <id> --with <audience>).
28
43
  Your thoughts on it go in a note, linked to it with lattris link, from the
@@ -31,14 +46,20 @@ is refused with the ones it can.
31
46
 
32
47
  saved → prints the id and what the source keeps. lattris get memories --type
33
48
  source lists your sources, and --q finds one by words of its title or address.`;
34
- const SOURCE_FLAG_NAMES = {
49
+ const FACT_FLAG_NAMES = {
35
50
  '--title-at-source': 'titleAtSource',
36
51
  '--site': 'site',
37
52
  '--author': 'author',
38
53
  '--published-at': 'publishedAt',
39
54
  '--title': 'title'
40
55
  };
56
+ const SOURCE_FLAG_NAMES = Object.assign({}, FACT_FLAG_NAMES, READING_FLAG_NAMES, {
57
+ '--body-file': 'bodyFile'
58
+ });
41
59
  const CREATED = 201;
60
+ const countFlags = (r) => COUNTS.filter((name) => r[name] !== undefined)
61
+ .map((name) => `--${name} ${r[name]}`)
62
+ .join(' ');
42
63
  const formatSourceReceipt = (s, created) => {
43
64
  const lines = [
44
65
  created ? `Saved source ${s.id}` : `Already kept source ${s.id}; nothing changed.`
@@ -52,6 +73,13 @@ const formatSourceReceipt = (s, created) => {
52
73
  lines.push(` capturedAt ${s.capturedAt}`);
53
74
  return lines.join('\n');
54
75
  };
76
+ const bodyText = (io, bodyFile) => {
77
+ if (bodyFile === undefined) {
78
+ return {};
79
+ }
80
+ const text = readTextFile(io, bodyFile);
81
+ return isRefusal(text) ? text : { body: text };
82
+ };
55
83
  export const captureSource = async (cfg, io, args) => {
56
84
  if (args.length === 0) {
57
85
  io.stdout.write(`${CAPTURE_SOURCE_HELP}\n`);
@@ -64,6 +92,16 @@ export const captureSource = async (cfg, io, args) => {
64
92
  if (positionals.length !== 1) {
65
93
  return refusal(`${CAPTURE_SOURCE_USAGE}\n`);
66
94
  }
95
+ const text = bodyText(io, flags.bodyFile);
96
+ if (isRefusal(text)) {
97
+ return text;
98
+ }
99
+ const reading = givesNumbers(flags)
100
+ ? buildReading(flags, io.store.now())
101
+ : undefined;
102
+ if (isRefusal(reading)) {
103
+ return reading;
104
+ }
67
105
  const identity = requireWriteIdentity(io.store, io.stdin.isTTY, SOURCE_SESSION_ID_DOOR);
68
106
  if (isRefusal(identity)) {
69
107
  return identity;
@@ -72,14 +110,32 @@ export const captureSource = async (cfg, io, args) => {
72
110
  if (typeof accessToken !== 'string') {
73
111
  return accessToken;
74
112
  }
113
+ const facts = {};
114
+ for (const key of Object.values(FACT_FLAG_NAMES)) {
115
+ const value = flags[key];
116
+ if (value !== undefined) {
117
+ facts[key] = value;
118
+ }
119
+ }
75
120
  const saved = await io.api(accessToken, `${cfg.apiUrl}/memories/sources`, {
76
121
  method: 'POST',
77
122
  headers: Object.assign({ 'Content-Type': 'application/json' }, noteWriteHeaders(identity)),
78
- body: JSON.stringify(Object.assign({ url: positionals[0] }, flags))
123
+ body: JSON.stringify(Object.assign({ url: positionals[0] }, facts, text))
79
124
  });
80
125
  if (!saved.ok) {
81
126
  return refusalOf(saved);
82
127
  }
83
- emit(io, saved.data, saved.rawText, (s) => formatSourceReceipt(s, saved.status === CREATED));
128
+ const created = saved.status === CREATED;
129
+ if (reading === undefined) {
130
+ emit(io, saved.data, saved.rawText, (s) => formatSourceReceipt(s, created));
131
+ return;
132
+ }
133
+ const kept = await postReading(cfg, io, accessToken, saved.data.id, reading);
134
+ if (!kept.ok) {
135
+ emit(io, saved.data, saved.rawText, (s) => formatSourceReceipt(s, created));
136
+ return refusalOf(kept, `The source is kept, but its numbers were not. Add them with: lattris capture engagement ${saved.data.id} ${countFlags(reading)}\n`);
137
+ }
138
+ const whole = Object.assign({}, saved.data, { engagement: kept.data });
139
+ emit(io, whole, JSON.stringify(whole), (s) => formatSourceReceipt(s, created));
84
140
  };
85
141
  //# sourceMappingURL=source.js.map
@@ -18,6 +18,8 @@ export const UPDATE_HELP = [
18
18
  ' lattris update memory <id> --base-fingerprint <fp> --intent <word>',
19
19
  ' lattris update memory <id> --base-fingerprint <fp> --clear-intent',
20
20
  ' echo "..." | lattris update memory <id> --overwrite --reason "..." replace on purpose',
21
+ ' lattris update memory <source-id> --expected-updated-at <time> --source-body-file <path>',
22
+ ' lattris update memory <source-id> --expected-updated-at <time> --clear-source-body',
21
23
  '',
22
24
  ' --base-fingerprint <fp>',
23
25
  ' a NOTE\u2019s guard: the fingerprint the read you built this edit',
@@ -44,6 +46,12 @@ export const UPDATE_HELP = [
44
46
  ' or video carries no intent and says so.',
45
47
  ' --contributor optional; whose expression this is — a contact id, the same',
46
48
  ' flag capture takes (`lattris contact list` shows yours)',
49
+ ' --source-body-file <path>',
50
+ ' a SOURCE\u2019s own text, replaced whole from this file (up to',
51
+ ' 128KB). Only you read it. A source takes the',
52
+ ' --expected-updated-at guard; a note refuses this flag.',
53
+ ' --clear-source-body',
54
+ ' forget the source\u2019s text',
47
55
  ' --clear-intent remove the declared intent (there is no magic value —',
48
56
  ' "none" is not vocabulary and would refuse)',
49
57
  ' --allow-banned-words',
@@ -55,6 +63,9 @@ export const UPDATE_HELP = [
55
63
  ' Content arrives on stdin, like capture — no quoting, up to 128KB. Pipe',
56
64
  ' nothing and the words are left exactly as they were.',
57
65
  '',
66
+ ' To add a video, paste a YouTube link on a line by itself. Put words in',
67
+ ' [brackets](link) to give it a title.',
68
+ '',
58
69
  ' The write carries the fingerprint you read. If another session changed',
59
70
  ' the note in between, the door refuses (memory:stale-write), nothing is',
60
71
  ' written, your draft is kept under drafts/ in the machine dir (0600) and',
@@ -107,7 +118,8 @@ export const UPDATE_FLAG_NAMES = {
107
118
  '--expected-updated-at': 'expectedUpdatedAt',
108
119
  '--reason': 'reason',
109
120
  '--idempotency-key': 'idempotencyKey',
110
- '--contributor': 'contributor'
121
+ '--contributor': 'contributor',
122
+ '--source-body-file': 'sourceBodyFile'
111
123
  };
112
124
  export const FINGERPRINT_SHAPE = /^[0-9a-f]{64}$/;
113
125
  const ISO_INSTANT = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d{1,9})?(Z|[+-]\d{2}:\d{2})$/;
@@ -1,6 +1,6 @@
1
1
  import { randomUUID } from 'node:crypto';
2
2
  import { parseArgs } from "../request/flags.js";
3
- import { retryWords } from "../memory/capture-common.js";
3
+ import { readTextFile, retryWords } from "../memory/capture-common.js";
4
4
  import { FINGERPRINT_SHAPE, UPDATE_FLAG_NAMES, isIsoInstant } from "../memory/update-help.js";
5
5
  import { composeAddressFor, formatBlockLine, formatMemoryDetail } from "../memory/views.js";
6
6
  import { emit } from "../render/output.js";
@@ -15,7 +15,11 @@ export const updateMemory = async (cfg, io, args) => {
15
15
  const clearIntent = args.includes('--clear-intent');
16
16
  const allowBanned = args.includes('--allow-banned-words');
17
17
  const overwrite = args.includes('--overwrite');
18
- const { flags, positionals, unknown, notAnId } = parseArgs(UPDATE_FLAG_NAMES, args.filter((a) => a !== '--clear-intent' && a !== '--allow-banned-words' && a !== '--overwrite'), [0]);
18
+ const clearSourceBody = args.includes('--clear-source-body');
19
+ const { flags, positionals, unknown, notAnId } = parseArgs(UPDATE_FLAG_NAMES, args.filter((a) => a !== '--clear-intent' &&
20
+ a !== '--allow-banned-words' &&
21
+ a !== '--overwrite' &&
22
+ a !== '--clear-source-body'), [0]);
19
23
  if (unknown) {
20
24
  return refusal(`Unknown flag: ${unknown}\n`);
21
25
  }
@@ -61,6 +65,13 @@ export const updateMemory = async (cfg, io, args) => {
61
65
  if (flags.idempotencyKey !== undefined && !isUuidKey(flags.idempotencyKey)) {
62
66
  return refusal(`--idempotency-key must be the UUID a draft printed: ${flags.idempotencyKey}\n`);
63
67
  }
68
+ if (clearSourceBody && flags.sourceBodyFile !== undefined) {
69
+ return refusal('--source-body-file and --clear-source-body contradict each other; pass one.\n');
70
+ }
71
+ const fileText = flags.sourceBodyFile === undefined ? undefined : readTextFile(io, flags.sourceBodyFile);
72
+ if (isRefusal(fileText)) {
73
+ return fileText;
74
+ }
64
75
  const identity = requireWriteIdentity(io.store, io.stdin.isTTY);
65
76
  if (isRefusal(identity))
66
77
  return identity;
@@ -72,6 +83,7 @@ export const updateMemory = async (cfg, io, args) => {
72
83
  const sendContent = content !== undefined;
73
84
  const sendIntent = flags.intent !== undefined;
74
85
  const sendContributor = flags.contributor !== undefined;
86
+ const sendSourceBody = fileText !== undefined || clearSourceBody;
75
87
  if (sendContributor && !isUuidKey(flags.contributor)) {
76
88
  return refusal(`--contributor must be a valid UUID (contact id): ${flags.contributor}\n`);
77
89
  }
@@ -83,8 +95,9 @@ export const updateMemory = async (cfg, io, args) => {
83
95
  !sendContent &&
84
96
  !sendIntent &&
85
97
  !clearIntent &&
86
- !sendContributor) {
87
- return refusal('Nothing to update: pipe new words in, or pass --title, --ai-summary, --intent, --clear-intent or --contributor.\n');
98
+ !sendContributor &&
99
+ !sendSourceBody) {
100
+ return refusal('Nothing to update: pipe new words in, or pass --title, --ai-summary, --intent, --clear-intent, --contributor, --source-body-file or --clear-source-body.\n');
88
101
  }
89
102
  const accessToken = await signedIn(io, cfg);
90
103
  if (typeof accessToken !== 'string')
@@ -102,6 +115,8 @@ export const updateMemory = async (cfg, io, args) => {
102
115
  body.intent = null;
103
116
  if (sendContributor)
104
117
  body.contributor = flags.contributor;
118
+ if (sendSourceBody)
119
+ body.sourceBody = fileText === undefined ? null : fileText;
105
120
  if (allowBanned)
106
121
  body.allowBannedWords = true;
107
122
  if (overwrite)
@@ -125,7 +140,8 @@ export const updateMemory = async (cfg, io, args) => {
125
140
  ...(sendAiSummary ? { aiSummary: body.aiSummary } : {}),
126
141
  ...(sendIntent || clearIntent ? { intent: body.intent } : {}),
127
142
  ...(sendContent ? { content: body.content } : {}),
128
- ...(sendContributor ? { contributor: body.contributor } : {})
143
+ ...(sendContributor ? { contributor: body.contributor } : {}),
144
+ ...(sendSourceBody ? { sourceBody: body.sourceBody } : {})
129
145
  }
130
146
  });
131
147
  const keepWords = () => saveEditDraft(io.store, positionals[0], editDraft());
@@ -207,7 +223,9 @@ export const updateMemory = async (cfg, io, args) => {
207
223
  sendAiSummary ? 'ai summary' : undefined,
208
224
  sendContent ? 'words' : undefined,
209
225
  sendIntent ? 'intent' : undefined,
210
- clearIntent ? 'intent (cleared)' : undefined
226
+ clearIntent ? 'intent (cleared)' : undefined,
227
+ fileText !== undefined ? 'source text' : undefined,
228
+ clearSourceBody ? 'source text (cleared)' : undefined
211
229
  ]
212
230
  .filter((c) => c !== undefined)
213
231
  .join(' and ');
@@ -14,6 +14,11 @@ const rowLabel = (b) => {
14
14
  export const formatBlockLine = (b) => b.ownerHandle === undefined
15
15
  ? `${b.id} ${b.handle} ${b.capturedAt} ${b.intent ?? '-'} ${b.visibility.public ? 'public' : '-'} ${rowLabel(b)}`
16
16
  : `${b.id} ${b.handle} ${b.capturedAt} by ${sanitizeForTerminal(b.ownerDisplayName ?? b.ownerHandle)} (@${b.ownerHandle}) ${graphWord(b)}${rowLabel(b)}`;
17
+ export const COUNTS = ['impressions', 'likes', 'comments', 'shares'];
18
+ export const formatCounts = (r) => COUNTS.flatMap((name) => {
19
+ const count = r[name];
20
+ return count === null ? [] : [`${name} ${count}`];
21
+ }).join(' ');
17
22
  export const sourceFacts = (s) => {
18
23
  if (s.url === undefined) {
19
24
  return [];
@@ -31,6 +36,20 @@ export const sourceFacts = (s) => {
31
36
  if (s.publishedAt) {
32
37
  lines.push(`published ${s.publishedAt}`);
33
38
  }
39
+ if (s.engagement) {
40
+ lines.push(`numbers ${formatCounts(s.engagement)} (as of ${s.engagement.asOf})`);
41
+ }
42
+ if (s.body !== undefined) {
43
+ lines.push(s.body === null || s.body.length === 0 ? 'text kept no' : 'text kept yes');
44
+ }
45
+ if (s.engagementHistory !== undefined) {
46
+ if (s.engagementHistory.length === 0) {
47
+ lines.push('readings none');
48
+ }
49
+ for (const r of s.engagementHistory) {
50
+ lines.push(`reading ${r.asOf} ${formatCounts(r)}`);
51
+ }
52
+ }
34
53
  return lines;
35
54
  };
36
55
  const SLUG_MAX = 60;
@@ -155,6 +174,9 @@ export const formatMemoryDetail = (m, address) => {
155
174
  else if (m.url === undefined) {
156
175
  lines.push('', sanitizeForTerminal(m.content ?? '', Infinity));
157
176
  }
177
+ else if (m.body) {
178
+ lines.push('', sanitizeForTerminal(m.body, Infinity));
179
+ }
158
180
  return lines.join('\n');
159
181
  };
160
182
  export const formatMemoryPage = (page, asked) => {
@@ -23,7 +23,8 @@ 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
+ ' lattris capture source <url> Keep a link \u2014 a page, a post, a video \u2014 with its title, site, author, date, text and numbers',
27
+ ' lattris capture engagement <id> Add a dated reading of a source\u2019s numbers \u2014 impressions, likes, comments, shares',
27
28
  ' lattris get memories List your memories, newest first, with filters (--for <contact> for what they may see)',
28
29
  ' lattris contact create "<name>" Record a person or an AI you work with (--ai, --phone); add, list, get, update, delete, link',
29
30
  ' lattris invite <contact> [--email <address>] Mint an invitation for one of your person contacts, admitting one address',
@@ -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_ENGAGEMENT_HELP, captureEngagement } from "../memory/engagement.js";
16
17
  import { CAPTURE_SOURCE_HELP, captureSource } from "../memory/source.js";
17
18
  import { UPDATE_HELP } from "../memory/update-help.js";
18
19
  import { updateMemory } from "../memory/update.js";
@@ -61,7 +62,10 @@ export const memoryNouns = [
61
62
  name: 'sources',
62
63
  words: { singular: 'source', plural: 'sources' },
63
64
  help: CAPTURE_SOURCE_HELP,
64
- verbs: [{ verb: 'capture', nouns: ['source'], handler: captureSource }]
65
+ verbs: [
66
+ { verb: 'capture', nouns: ['source'], handler: captureSource },
67
+ { verb: 'capture', nouns: ['engagement'], handler: captureEngagement }
68
+ ]
65
69
  }
66
70
  ];
67
71
  const captureHelp = (args) => {
@@ -75,6 +79,8 @@ const captureHelp = (args) => {
75
79
  return CAPTURE_RECORDING_HELP;
76
80
  if (args[0] === 'source')
77
81
  return CAPTURE_SOURCE_HELP;
82
+ if (args[0] === 'engagement')
83
+ return CAPTURE_ENGAGEMENT_HELP;
78
84
  return CAPTURE_INDEX;
79
85
  };
80
86
  export const memoryVerbs = {
@@ -43,6 +43,8 @@ export const alreadySaved = (sent, current) => {
43
43
  return false;
44
44
  if (sent.contributor !== undefined && sent.contributor !== (current.contributor?.id ?? null))
45
45
  return false;
46
+ if (sent.sourceBody !== undefined && sent.sourceBody !== (current.body ?? null))
47
+ return false;
46
48
  return true;
47
49
  };
48
50
  //# sourceMappingURL=drafts.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lattris",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
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": [