lattris 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +2 -2
  2. package/dist/build.json +4 -1
  3. package/dist/datasets/capture.js +118 -0
  4. package/dist/datasets/page.js +64 -0
  5. package/dist/datasets/pieces.js +78 -0
  6. package/dist/dispatch-form.js +181 -0
  7. package/dist/dispatch-words.js +137 -0
  8. package/dist/dispatch.js +67 -0
  9. package/dist/entry/session.js +219 -0
  10. package/dist/entry/set.js +130 -0
  11. package/dist/entry/setup-boot.js +151 -0
  12. package/dist/entry/setup.js +145 -0
  13. package/dist/entry/use.js +127 -0
  14. package/dist/help.js +65 -0
  15. package/dist/main.js +143 -6877
  16. package/dist/memory/capture-common.js +67 -0
  17. package/dist/memory/capture-help.js +186 -0
  18. package/dist/memory/capture-note.js +190 -0
  19. package/dist/memory/capture-session.js +166 -0
  20. package/dist/memory/delete.js +88 -0
  21. package/dist/memory/erase.js +67 -0
  22. package/dist/{extract-claude-jsonl.js → memory/extract-claude-jsonl.js} +5 -94
  23. package/dist/memory/get-help.js +63 -0
  24. package/dist/memory/get.js +213 -0
  25. package/dist/memory/history.js +134 -0
  26. package/dist/memory/recording-update.js +128 -0
  27. package/dist/memory/recording.js +249 -0
  28. package/dist/memory/resend.js +82 -0
  29. package/dist/memory/restore.js +73 -0
  30. package/dist/memory/save-session-chain.js +59 -0
  31. package/dist/memory/transcript.js +85 -0
  32. package/dist/memory/update-help.js +126 -0
  33. package/dist/memory/update.js +220 -0
  34. package/dist/memory/views.js +138 -0
  35. package/dist/nouns/consent.js +29 -0
  36. package/dist/nouns/contact.js +142 -0
  37. package/dist/nouns/datasets.js +109 -0
  38. package/dist/nouns/edges.js +106 -0
  39. package/dist/nouns/form.js +2 -0
  40. package/dist/nouns/index.js +34 -0
  41. package/dist/nouns/invite.js +98 -0
  42. package/dist/nouns/questions.js +116 -0
  43. package/dist/nouns/share.js +105 -0
  44. package/dist/nouns/words.js +76 -0
  45. package/dist/registry/datasets.js +15 -0
  46. package/dist/registry/entry.js +51 -0
  47. package/dist/registry/index.js +17 -0
  48. package/dist/registry/memory.js +110 -0
  49. package/dist/render/datasets.js +77 -0
  50. package/dist/render/door.js +39 -0
  51. package/dist/render/output.js +19 -0
  52. package/dist/render/prompt.js +4 -0
  53. package/dist/render/rows.js +49 -0
  54. package/dist/render/text.js +21 -0
  55. package/dist/request/access-token.js +67 -0
  56. package/dist/request/api-fetch.js +76 -0
  57. package/dist/request/callback.js +86 -0
  58. package/dist/request/door.js +74 -0
  59. package/dist/request/flags.js +38 -0
  60. package/dist/request/io.js +2 -0
  61. package/dist/request/paste-and-device.js +99 -0
  62. package/dist/request/stdin.js +22 -0
  63. package/dist/request/token.js +66 -0
  64. package/dist/request/upload.js +6 -0
  65. package/dist/request/version-check.js +79 -0
  66. package/dist/store/chains.js +25 -0
  67. package/dist/store/drafts.js +48 -0
  68. package/dist/store/environment.js +57 -0
  69. package/dist/store/exit.js +13 -0
  70. package/dist/store/io.js +2 -0
  71. package/dist/store/json-file.js +9 -0
  72. package/dist/store/session-home.js +189 -0
  73. package/dist/store/session-lock.js +169 -0
  74. package/dist/store/session.js +70 -0
  75. package/dist/store/write-identity.js +153 -0
  76. package/dist/version.js +16 -0
  77. package/package.json +4 -5
  78. package/dist/save-session-chain.js +0 -136
@@ -0,0 +1,127 @@
1
+ import { dirname, join, resolve, sep } from 'node:path';
2
+ import { formatPerson } from "../entry/session.js";
3
+ import { HELP_TOKENS } from "../request/flags.js";
4
+ import { sanitizeForTerminal } from "../render/text.js";
5
+ import { BINDING_FILE, clearBinding, findBinding, machinesRoot, resolveActorDir, resolveSessionHome, sessionDir, writeBinding } from "../store/session-home.js";
6
+ import { refusal } from "../store/exit.js";
7
+ const USE_HELP = [
8
+ 'use — bind this directory to an actor.',
9
+ '',
10
+ 'Usage:',
11
+ ' lattris use <name|path> Bind: an email or short name resolves inside ~/lattris-machines',
12
+ ' (canonical dir = the account email; short names match too);',
13
+ ' a path (contains / or starts with . or ~) is used as-is.',
14
+ ' lattris use Show the effective binding and who it acts as.',
15
+ ' lattris use --clear Remove THIS directory’s binding (never an ancestor’s).',
16
+ '',
17
+ 'Resolution order for every command: --as or LATTRIS_HOME, then the nearest',
18
+ '.lattris walking up from the current directory (stopping below $HOME), then the',
19
+ 'default state home. The binding file is personal, machine-local state — gitignore it.',
20
+ '',
21
+ 'A .lattris is honoured only when it is a plain file naming a directory under',
22
+ '~/lattris-machines, or one lattris use made on this machine. Every command',
23
+ 'refuses any other; if you wrote it, run lattris use there to trust it.'
24
+ ].join('\n');
25
+ const UNVERIFIED = 'session present, identity unverified (not signed in, or API unreachable)';
26
+ const describeIdentity = async (cfg, io) => {
27
+ try {
28
+ const accessToken = await io.token(cfg);
29
+ const result = await io.api(accessToken, `${cfg.apiUrl}/person/me`);
30
+ if (!result.ok) {
31
+ return result.answer.kind === 'page'
32
+ ? UNVERIFIED
33
+ : 'session present, identity unverified (API refused)';
34
+ }
35
+ return `acts as ${formatPerson(result.data)}`;
36
+ }
37
+ catch {
38
+ return UNVERIFIED;
39
+ }
40
+ };
41
+ const insideGitRepo = (machine) => {
42
+ let dir = machine.cwd;
43
+ while (dir.startsWith(machine.home + sep)) {
44
+ if (machine.files.existsSync(join(dir, '.git')))
45
+ return true;
46
+ const parent = dirname(dir);
47
+ if (parent === dir)
48
+ break;
49
+ dir = parent;
50
+ }
51
+ return false;
52
+ };
53
+ export const use = async (cfg, io, args) => {
54
+ if (args.some((a) => HELP_TOKENS.has(a))) {
55
+ io.stdout.write(`${USE_HELP}\n`);
56
+ return;
57
+ }
58
+ if (args.length > 1 || (args[0]?.startsWith('--') && args[0] !== '--clear')) {
59
+ return refusal(`Usage: lattris use <name|path> | lattris use | lattris use --clear\n`);
60
+ }
61
+ const machine = io.store;
62
+ const { existsSync } = machine.files;
63
+ const cwd = machine.cwd;
64
+ if (args.length === 0) {
65
+ const home = resolveSessionHome(machine);
66
+ const rung = home.bindingFile
67
+ ? `bound via ${home.bindingFile}`
68
+ : machine.env.LATTRIS_HOME
69
+ ? 'LATTRIS_HOME'
70
+ : 'the default state home';
71
+ const sDir = sessionDir(io.store);
72
+ const hasSession = existsSync(join(sDir, 'session.json'));
73
+ io.stdout.write(`session home: ${sDir} (${rung}, env=${io.store.envName})\n`);
74
+ if (!hasSession) {
75
+ io.stdout.write(home.bindingFile
76
+ ? `no session there — run lattris login here, or lattris use --clear.\n`
77
+ : `no session — run lattris login.\n`);
78
+ return;
79
+ }
80
+ io.stdout.write(`${await describeIdentity(cfg, io)}\n`);
81
+ return;
82
+ }
83
+ if (args[0] === '--clear') {
84
+ const ancestor = findBinding(machine, dirname(cwd));
85
+ io.stdout.write(clearBinding(machine, cwd) ? 'Binding cleared.\n' : 'No binding in this directory.\n');
86
+ if (ancestor?.trusted) {
87
+ io.stdout.write(`Note: an ancestor binding is still in effect — ${ancestor.bindingFile} → ${ancestor.machineDir}. Clear it there if you mean to.\n`);
88
+ }
89
+ else if (ancestor) {
90
+ io.stdout.write(`Note: an ancestor binding, ${sanitizeForTerminal(ancestor.bindingFile, Infinity)}, is not trusted, so commands here are refused until it is cleared or made there with lattris use.\n`);
91
+ }
92
+ return;
93
+ }
94
+ const ref = args[0];
95
+ let target;
96
+ if (ref.includes(sep) || ref.startsWith('.') || ref.startsWith('~')) {
97
+ target = resolve(cwd, ref.replace(/^~(?=\/|$)/, machine.home));
98
+ }
99
+ else {
100
+ const resolved = resolveActorDir(machine.files, ref, machinesRoot(machine));
101
+ if (resolved.ambiguous) {
102
+ return refusal(`'${ref}' is ambiguous: ${resolved.ambiguous.join(', ')}. Use the full email.\n`);
103
+ }
104
+ target = resolved.dir ?? join(machinesRoot(machine), ref);
105
+ }
106
+ if (!existsSync(target)) {
107
+ return refusal(`No machine dir at ${target}. Provision the actor first (provision-actor.sh), or pass an explicit path.\n`);
108
+ }
109
+ const bindEnv = io.store.envExplicit ? io.store.envName : undefined;
110
+ writeBinding(machine, cwd, target, bindEnv);
111
+ io.stdout.write(`Bound: ${cwd} → ${target}${bindEnv ? ` (env=${bindEnv})` : ''}\n`);
112
+ const envSubdir = bindEnv ?? 'local';
113
+ const sessionCheck = existsSync(join(target, envSubdir, 'session.json')) || existsSync(join(target, 'session.json'));
114
+ if (!sessionCheck) {
115
+ io.stdout.write('No session there yet — run lattris login from this directory.\n');
116
+ }
117
+ else {
118
+ io.stdout.write(`${await describeIdentity(cfg, io)}\n`);
119
+ }
120
+ if (insideGitRepo(machine)) {
121
+ const ignored = machine.run('git', ['check-ignore', '-q', BINDING_FILE], cwd);
122
+ if (ignored.status !== 0) {
123
+ io.stdout.write('Tip: add .lattris to .gitignore — the binding is personal, machine-local state.\n');
124
+ }
125
+ }
126
+ };
127
+ //# sourceMappingURL=use.js.map
package/dist/help.js ADDED
@@ -0,0 +1,65 @@
1
+ import { USAGE_LINES } from "./nouns/words.js";
2
+ import { renderRunHint } from "./render/text.js";
3
+ export const commandHelpText = (registry, command, args) => {
4
+ if (command === undefined)
5
+ return null;
6
+ const nounFirst = registry.nouns.find((n) => n.grammar === 'noun-first' &&
7
+ n.helpBeforeAuth &&
8
+ [n.words.singular, ...(n.words.aliases ?? [])].includes(command));
9
+ if (nounFirst)
10
+ return nounFirst.help;
11
+ const verb = registry.verbs[command];
12
+ if (!verb?.helpBeforeAuth || verb.help === undefined)
13
+ return null;
14
+ return typeof verb.help === 'string' ? verb.help : verb.help(args);
15
+ };
16
+ export const missingActorDirVerdict = (actor, dirExists, command) => {
17
+ if (dirExists)
18
+ return null;
19
+ if (command === 'login' || command === 'use' || command === 'setup')
20
+ return null;
21
+ return (`No machine dir for ${actor} — check the spelling, or log in as them first: ` +
22
+ `${renderRunHint(['--as', actor, 'login'])}\n`);
23
+ };
24
+ export const usage = (term) => {
25
+ term.stdout.write([
26
+ 'lattris — first-party CLI for the Lattris platform',
27
+ '',
28
+ 'Usage:',
29
+ ...USAGE_LINES,
30
+ '',
31
+ 'Exit codes:',
32
+ ' 0 success',
33
+ ' 1 unexpected or transport failure',
34
+ ' 2 usage — bad or missing flag, unknown command',
35
+ ' 3 not authenticated — no session, refresh failed, or a 401',
36
+ ' 4 a door must be walked first',
37
+ '',
38
+ 'Config (env overrides; localdev defaults shown):',
39
+ ' LATTRIS_ISSUER Hydra public base (http://localhost:4444)',
40
+ ' LATTRIS_API lattris-api base (http://localhost:54301)',
41
+ ' LATTRIS_CLIENT_ID OAuth client id (lattris-cli)',
42
+ ' LATTRIS_REDIRECT_PORT loopback callback (4577)',
43
+ ' LATTRIS_SESSION_ID names this session on every note write (required off a terminal)',
44
+ ' LATTRIS_AGENT a readable label for it (optional)',
45
+ '',
46
+ 'Session resolution (which identity a command acts as), in order:',
47
+ ' 0. --as <email|name> per-invocation: resolves inside ~/lattris-machines',
48
+ ' (email exact; a short name matches its <name>@* dir)',
49
+ ' 1. LATTRIS_HOME a session home named outright',
50
+ ' 2. nearest .lattris binding walking up from cwd, stopping below $HOME',
51
+ ' 3. ~/.local/state/lattris the default ($XDG_STATE_HOME honoured)',
52
+ '',
53
+ 'Environment resolution (which API endpoints to use), in order:',
54
+ ' 0. --env <name> per-invocation (e.g. --env prod)',
55
+ ' 1. .lattris env= field default for this workspace',
56
+ ' 2. LATTRIS_ENV explicit env var',
57
+ ' 3. "local" the default',
58
+ '',
59
+ 'Per-env sessions live in subdirectories: ~/lattris-machines/<actor>/<env>/session.json.',
60
+ 'Environments are configured in ~/.config/lattris/environments.json; built-in',
61
+ 'local + prod work with no file. Env vars (LATTRIS_API etc.) still override.',
62
+ ''
63
+ ].join('\n'));
64
+ };
65
+ //# sourceMappingURL=help.js.map