@plebeiantech/lat.md 0.12.3-fork.1

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 (144) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +97 -0
  3. package/dist/src/cli/check-frontmatter.d.ts +12 -0
  4. package/dist/src/cli/check-frontmatter.js +44 -0
  5. package/dist/src/cli/check-mode.d.ts +6 -0
  6. package/dist/src/cli/check-mode.js +303 -0
  7. package/dist/src/cli/check-status.d.ts +74 -0
  8. package/dist/src/cli/check-status.js +217 -0
  9. package/dist/src/cli/check.d.ts +45 -0
  10. package/dist/src/cli/check.js +777 -0
  11. package/dist/src/cli/checklist-menu.d.ts +12 -0
  12. package/dist/src/cli/checklist-menu.js +111 -0
  13. package/dist/src/cli/comment-guard.d.ts +16 -0
  14. package/dist/src/cli/comment-guard.js +111 -0
  15. package/dist/src/cli/comment-reminder.d.ts +62 -0
  16. package/dist/src/cli/comment-reminder.js +210 -0
  17. package/dist/src/cli/context.d.ts +11 -0
  18. package/dist/src/cli/context.js +58 -0
  19. package/dist/src/cli/expand.d.ts +8 -0
  20. package/dist/src/cli/expand.js +94 -0
  21. package/dist/src/cli/gen-index.d.ts +45 -0
  22. package/dist/src/cli/gen-index.js +235 -0
  23. package/dist/src/cli/gen.d.ts +6 -0
  24. package/dist/src/cli/gen.js +42 -0
  25. package/dist/src/cli/graph.d.ts +7 -0
  26. package/dist/src/cli/graph.js +47 -0
  27. package/dist/src/cli/hook.d.ts +1 -0
  28. package/dist/src/cli/hook.js +432 -0
  29. package/dist/src/cli/index.d.ts +2 -0
  30. package/dist/src/cli/index.js +307 -0
  31. package/dist/src/cli/init.d.ts +9 -0
  32. package/dist/src/cli/init.js +1031 -0
  33. package/dist/src/cli/link-scheme.d.ts +54 -0
  34. package/dist/src/cli/link-scheme.js +101 -0
  35. package/dist/src/cli/locate.d.ts +2 -0
  36. package/dist/src/cli/locate.js +17 -0
  37. package/dist/src/cli/refs.d.ts +22 -0
  38. package/dist/src/cli/refs.js +229 -0
  39. package/dist/src/cli/reindex.d.ts +13 -0
  40. package/dist/src/cli/reindex.js +136 -0
  41. package/dist/src/cli/search.d.ts +36 -0
  42. package/dist/src/cli/search.js +217 -0
  43. package/dist/src/cli/section.d.ts +43 -0
  44. package/dist/src/cli/section.js +252 -0
  45. package/dist/src/cli/select-menu.d.ts +13 -0
  46. package/dist/src/cli/select-menu.js +100 -0
  47. package/dist/src/cli/templates.d.ts +1 -0
  48. package/dist/src/cli/templates.js +15 -0
  49. package/dist/src/cli/ui.d.ts +11 -0
  50. package/dist/src/cli/ui.js +34 -0
  51. package/dist/src/code-refs.d.ts +17 -0
  52. package/dist/src/code-refs.js +277 -0
  53. package/dist/src/config.d.ts +29 -0
  54. package/dist/src/config.js +83 -0
  55. package/dist/src/context.d.ts +23 -0
  56. package/dist/src/context.js +11 -0
  57. package/dist/src/extensions/wiki-link/from-markdown.d.ts +5 -0
  58. package/dist/src/extensions/wiki-link/from-markdown.js +34 -0
  59. package/dist/src/extensions/wiki-link/index.d.ts +4 -0
  60. package/dist/src/extensions/wiki-link/index.js +3 -0
  61. package/dist/src/extensions/wiki-link/syntax.d.ts +14 -0
  62. package/dist/src/extensions/wiki-link/syntax.js +121 -0
  63. package/dist/src/extensions/wiki-link/to-markdown.d.ts +5 -0
  64. package/dist/src/extensions/wiki-link/to-markdown.js +28 -0
  65. package/dist/src/extensions/wiki-link/types.d.ts +34 -0
  66. package/dist/src/extensions/wiki-link/types.js +1 -0
  67. package/dist/src/format.d.ts +8 -0
  68. package/dist/src/format.js +43 -0
  69. package/dist/src/graph-export.d.ts +60 -0
  70. package/dist/src/graph-export.js +309 -0
  71. package/dist/src/init-version.d.ts +10 -0
  72. package/dist/src/init-version.js +49 -0
  73. package/dist/src/knowledge/bd.d.ts +2 -0
  74. package/dist/src/knowledge/bd.js +107 -0
  75. package/dist/src/knowledge/claude-memory.d.ts +13 -0
  76. package/dist/src/knowledge/claude-memory.js +204 -0
  77. package/dist/src/knowledge/cq.d.ts +2 -0
  78. package/dist/src/knowledge/cq.js +74 -0
  79. package/dist/src/knowledge/index.d.ts +49 -0
  80. package/dist/src/knowledge/index.js +271 -0
  81. package/dist/src/knowledge/ranking.d.ts +17 -0
  82. package/dist/src/knowledge/ranking.js +62 -0
  83. package/dist/src/knowledge/session.d.ts +46 -0
  84. package/dist/src/knowledge/session.js +203 -0
  85. package/dist/src/knowledge/types.d.ts +47 -0
  86. package/dist/src/knowledge/types.js +10 -0
  87. package/dist/src/lattice.d.ts +108 -0
  88. package/dist/src/lattice.js +816 -0
  89. package/dist/src/mcp/server.d.ts +1 -0
  90. package/dist/src/mcp/server.js +58 -0
  91. package/dist/src/parser.d.ts +3 -0
  92. package/dist/src/parser.js +18 -0
  93. package/dist/src/search/db.d.ts +16 -0
  94. package/dist/src/search/db.js +54 -0
  95. package/dist/src/search/embedder.d.ts +25 -0
  96. package/dist/src/search/embedder.js +58 -0
  97. package/dist/src/search/index.d.ts +9 -0
  98. package/dist/src/search/index.js +66 -0
  99. package/dist/src/search/search.d.ts +9 -0
  100. package/dist/src/search/search.js +16 -0
  101. package/dist/src/source-parser.d.ts +27 -0
  102. package/dist/src/source-parser.js +916 -0
  103. package/dist/src/untrusted.d.ts +24 -0
  104. package/dist/src/untrusted.js +97 -0
  105. package/dist/src/version.d.ts +7 -0
  106. package/dist/src/version.js +39 -0
  107. package/dist/src/view/client/assets/index-B0n0u03y.css +1 -0
  108. package/dist/src/view/client/assets/index-xm2_px4q.js +23 -0
  109. package/dist/src/view/client/index.html +14 -0
  110. package/dist/src/view/diagnostics.d.ts +5 -0
  111. package/dist/src/view/diagnostics.js +171 -0
  112. package/dist/src/view/git-diff.d.ts +3 -0
  113. package/dist/src/view/git-diff.js +255 -0
  114. package/dist/src/view/git.d.ts +22 -0
  115. package/dist/src/view/git.js +193 -0
  116. package/dist/src/view/highlight.d.ts +2 -0
  117. package/dist/src/view/highlight.js +3767 -0
  118. package/dist/src/view/markdown.d.ts +22 -0
  119. package/dist/src/view/markdown.js +322 -0
  120. package/dist/src/view/protocol.d.ts +89 -0
  121. package/dist/src/view/protocol.js +1 -0
  122. package/dist/src/view/references.d.ts +62 -0
  123. package/dist/src/view/references.js +345 -0
  124. package/dist/src/view/repository.d.ts +12 -0
  125. package/dist/src/view/repository.js +167 -0
  126. package/dist/src/view/search.d.ts +14 -0
  127. package/dist/src/view/search.js +64 -0
  128. package/dist/src/view/server.d.ts +20 -0
  129. package/dist/src/view/server.js +233 -0
  130. package/dist/src/view/store.d.ts +57 -0
  131. package/dist/src/view/store.js +404 -0
  132. package/dist/src/walk.d.ts +18 -0
  133. package/dist/src/walk.js +27 -0
  134. package/package.json +85 -0
  135. package/templates/AGENTS.md +118 -0
  136. package/templates/README +1 -0
  137. package/templates/cursor-rules.md +77 -0
  138. package/templates/init/lat.md +1 -0
  139. package/templates/logo-dark.svg +182 -0
  140. package/templates/logo-light.svg +182 -0
  141. package/templates/logo.txt +7 -0
  142. package/templates/opencode-plugin.ts +180 -0
  143. package/templates/pi-extension.ts +364 -0
  144. package/templates/skill/SKILL.md +189 -0
@@ -0,0 +1,307 @@
1
+ #!/usr/bin/env node
2
+ // Suppress deprecation warnings from transitive dependencies unless --verbose
3
+ if (!process.argv.includes('--verbose')) {
4
+ process.noDeprecation = true;
5
+ }
6
+ import { existsSync, readFileSync } from 'node:fs';
7
+ import { dirname, join } from 'node:path';
8
+ import { fileURLToPath } from 'node:url';
9
+ import { Command } from 'commander';
10
+ import { resolveCheckContext, resolveContext } from './context.js';
11
+ /** Reserve `-- <directory>` for an explicit check target. */
12
+ function splitCheckTarget(args) {
13
+ let commandIndex = -1;
14
+ for (let i = 0; i < args.length; i++) {
15
+ const arg = args[i];
16
+ if (arg === '--dir') {
17
+ i++;
18
+ continue;
19
+ }
20
+ if (arg.startsWith('--dir='))
21
+ continue;
22
+ if (arg.startsWith('-'))
23
+ continue;
24
+ commandIndex = i;
25
+ break;
26
+ }
27
+ if (commandIndex === -1 || args[commandIndex] !== 'check') {
28
+ return { args };
29
+ }
30
+ const separatorIndex = args.indexOf('--', commandIndex + 1);
31
+ if (separatorIndex === -1)
32
+ return { args };
33
+ const targets = args.slice(separatorIndex + 1);
34
+ if (targets.length !== 1 || targets[0] === '') {
35
+ console.error('error: `lat check --` expects exactly one directory after `--`');
36
+ process.exit(1);
37
+ }
38
+ return {
39
+ args: args.slice(0, separatorIndex),
40
+ target: targets[0],
41
+ };
42
+ }
43
+ const checkTargetArgs = splitCheckTarget(process.argv.slice(2));
44
+ function findPackageJson() {
45
+ let dir = dirname(fileURLToPath(import.meta.url));
46
+ while (true) {
47
+ const candidate = join(dir, 'package.json');
48
+ try {
49
+ return JSON.parse(readFileSync(candidate, 'utf-8')).version;
50
+ }
51
+ catch { }
52
+ const parent = dirname(dir);
53
+ if (parent === dir)
54
+ return '0.0.0';
55
+ dir = parent;
56
+ }
57
+ }
58
+ function handleResult(result) {
59
+ if (result.isError) {
60
+ console.error(result.output);
61
+ process.exit(1);
62
+ }
63
+ if (result.output)
64
+ console.log(result.output);
65
+ }
66
+ const version = findPackageJson();
67
+ const program = new Command();
68
+ program
69
+ .name('lat')
70
+ .description('Anchor source code to high-level concepts defined in markdown')
71
+ .version(version)
72
+ .option('--dir <path>', 'project root to look for lat.md in (default: cwd)')
73
+ .option('--no-color', 'disable color output')
74
+ .option('--verbose', 'show deprecation warnings and extra diagnostics');
75
+ program
76
+ .command('locate')
77
+ .description('Find sections by id')
78
+ .argument('<query>', 'section id to search for')
79
+ .action(async (query) => {
80
+ const ctx = resolveContext(program.opts());
81
+ const { locateCommand } = await import('./locate.js');
82
+ handleResult(await locateCommand(ctx, query));
83
+ });
84
+ program
85
+ .command('section')
86
+ .description('Show a section with its content, outgoing refs, and incoming refs')
87
+ .argument('<query>', 'section id to look up')
88
+ .action(async (query) => {
89
+ const ctx = resolveContext(program.opts());
90
+ const { sectionCommand } = await import('./section.js');
91
+ handleResult(await sectionCommand(ctx, query));
92
+ });
93
+ program
94
+ .command('ui')
95
+ .description('Open lat.md in a local browser')
96
+ .action(async () => {
97
+ const ctx = resolveContext(program.opts());
98
+ const { uiCommand } = await import('./ui.js');
99
+ handleResult(await uiCommand(ctx));
100
+ });
101
+ program
102
+ .command('refs')
103
+ .description('Find references to a section')
104
+ .argument('<query>', 'section id to find references for')
105
+ .option('--scope <scope>', 'where to search: md, code, or md+code', 'md+code')
106
+ .action(async (query, opts) => {
107
+ const scope = opts.scope;
108
+ if (scope !== 'md' && scope !== 'code' && scope !== 'md+code') {
109
+ console.error(`Unknown scope: ${scope}. Use md, code, or md+code.`);
110
+ process.exit(1);
111
+ }
112
+ const ctx = resolveContext(program.opts());
113
+ const { refsCommand } = await import('./refs.js');
114
+ handleResult(await refsCommand(ctx, query, scope));
115
+ });
116
+ const check = program
117
+ .command('check')
118
+ .usage('[subcommand] [-- <directory>]')
119
+ .description('Validate markdown, links, code references, and structure')
120
+ .option('--fix', 'generate/update directory index files from frontmatter')
121
+ .action(async (opts) => {
122
+ const ctx = resolveCheckContext(program.opts(), checkTargetArgs.target);
123
+ const { checkAllCommand } = await import('./check.js');
124
+ handleResult(await checkAllCommand(ctx, { fix: opts.fix }));
125
+ });
126
+ check
127
+ .command('md')
128
+ .usage('[-- <directory>]')
129
+ .description('Validate wiki links in markdown files')
130
+ .action(async () => {
131
+ const ctx = resolveCheckContext(program.opts(), checkTargetArgs.target);
132
+ const { checkMdCommand } = await import('./check.js');
133
+ handleResult(await checkMdCommand(ctx));
134
+ });
135
+ check
136
+ .command('links')
137
+ .usage('[-- <directory>]')
138
+ .description('Validate relative markdown links')
139
+ .action(async () => {
140
+ const ctx = resolveCheckContext(program.opts(), checkTargetArgs.target);
141
+ const { checkLinksCommand } = await import('./check.js');
142
+ handleResult(await checkLinksCommand(ctx));
143
+ });
144
+ check
145
+ .command('code-refs')
146
+ .usage('[-- <directory>]')
147
+ .description('Validate @lat code references and coverage')
148
+ .action(async () => {
149
+ const ctx = resolveCheckContext(program.opts(), checkTargetArgs.target);
150
+ const { checkCodeRefsCommand } = await import('./check.js');
151
+ handleResult(await checkCodeRefsCommand(ctx));
152
+ });
153
+ check
154
+ .command('index')
155
+ .usage('[-- <directory>]')
156
+ .description('Validate directory index files')
157
+ // No `.option('--fix', ...)` here: the parent `check` command already
158
+ // declares `--fix` (see line ~133 above), and commander resolves a flag
159
+ // shared by parent and child against the PARENT, leaving this action's
160
+ // own `opts.fix` permanently `undefined`. Re-adding a same-named option
161
+ // on this subcommand silently reintroduces that no-op bug (lat-t1y.31) —
162
+ // read it off `check.opts()` instead.
163
+ .action(async () => {
164
+ const ctx = resolveCheckContext(program.opts(), checkTargetArgs.target);
165
+ const { checkIndexCommand } = await import('./check.js');
166
+ handleResult(await checkIndexCommand(ctx, { fix: check.opts().fix }));
167
+ });
168
+ check
169
+ .command('sections')
170
+ .usage('[-- <directory>]')
171
+ .description('Validate section leading paragraphs')
172
+ .action(async () => {
173
+ const ctx = resolveCheckContext(program.opts(), checkTargetArgs.target);
174
+ const { checkSectionsCommand } = await import('./check.js');
175
+ handleResult(await checkSectionsCommand(ctx));
176
+ });
177
+ check
178
+ .command('mode')
179
+ .usage('[-- <directory>]')
180
+ .description('Validate Diátaxis modes and document shape')
181
+ .action(async () => {
182
+ const ctx = resolveCheckContext(program.opts(), checkTargetArgs.target);
183
+ const { checkModeCommand } = await import('./check.js');
184
+ handleResult(await checkModeCommand(ctx));
185
+ });
186
+ check
187
+ .command('status')
188
+ .usage('[-- <directory>]')
189
+ .description('Validate provenance status and detect stale reviews')
190
+ .action(async () => {
191
+ const ctx = resolveCheckContext(program.opts(), checkTargetArgs.target);
192
+ const { checkStatusCommand } = await import('./check.js');
193
+ handleResult(await checkStatusCommand(ctx));
194
+ });
195
+ async function runExpand(text, opts) {
196
+ if (opts.stdin) {
197
+ const chunks = [];
198
+ for await (const chunk of process.stdin) {
199
+ chunks.push(chunk);
200
+ }
201
+ text = Buffer.concat(chunks).toString('utf-8');
202
+ }
203
+ if (!text) {
204
+ console.error('Provide text as an argument or use --stdin');
205
+ process.exit(1);
206
+ }
207
+ const ctx = resolveContext(program.opts());
208
+ const { expandCommand } = await import('./expand.js');
209
+ const result = await expandCommand(ctx, text);
210
+ if (result.isError) {
211
+ console.error(result.output);
212
+ process.exit(1);
213
+ }
214
+ // Use stdout.write (no trailing newline) for piping
215
+ process.stdout.write(result.output);
216
+ }
217
+ program
218
+ .command('expand')
219
+ .description('Expand [[refs]] in text to lat.md section locations')
220
+ .argument('[text]', 'text containing [[refs]]')
221
+ .option('--stdin', 'read text from stdin')
222
+ .action(runExpand);
223
+ // Deprecated alias — hidden from --help
224
+ program
225
+ .command('prompt', { hidden: true })
226
+ .argument('[text]')
227
+ .option('--stdin')
228
+ .action(async (text, opts) => {
229
+ console.error('Warning: `lat prompt` is deprecated, use `lat expand` instead.');
230
+ await runExpand(text, opts);
231
+ });
232
+ program
233
+ .command('search')
234
+ .description('Semantic search across lat.md sections')
235
+ .argument('[query]', 'search query in plain English')
236
+ .option('--limit <n>', 'max results', '5')
237
+ .action(async (query, opts) => {
238
+ const ctx = resolveContext(program.opts());
239
+ const { searchCommand, cliProgress } = await import('./search.js');
240
+ const progress = cliProgress(ctx.styler);
241
+ const result = await searchCommand(ctx, query, { limit: parseInt(opts.limit) }, progress);
242
+ handleResult(result);
243
+ });
244
+ program
245
+ .command('reindex')
246
+ .description('Rebuild the embedding index; switch backends if needed')
247
+ .option('--local', 'use the local offline model (ignore LAT_LLM_KEY)')
248
+ .option('--remote', 'use the hosted API from LAT_LLM_KEY (override a local pin)')
249
+ .option('--yes', 'assume yes to prompts (non-interactive)')
250
+ .action(async (opts) => {
251
+ const ctx = resolveContext(program.opts());
252
+ const { reindexCommand } = await import('./reindex.js');
253
+ handleResult(await reindexCommand(ctx, opts));
254
+ });
255
+ program
256
+ .command('gen')
257
+ .description('Generate a file to stdout (agents.md, claude.md, cursor-rules.md)')
258
+ .argument('<target>', 'file to generate: agents.md, claude.md, cursor-rules.md')
259
+ .action(async (target) => {
260
+ const { genCmd } = await import('./gen.js');
261
+ await genCmd(target);
262
+ });
263
+ program
264
+ .command('init')
265
+ .description('Initialize a lat.md directory')
266
+ .argument('[dir]', 'target directory (default: cwd)')
267
+ .action(async (dir) => {
268
+ const { initCmd } = await import('./init.js');
269
+ await initCmd(dir);
270
+ });
271
+ program
272
+ .command('hook')
273
+ .description('Handle agent hook events (called by agent hooks, not directly)')
274
+ .argument('<agent>', 'agent name (claude, cursor)')
275
+ .argument('<event>', 'hook event (claude: UserPromptSubmit|Stop, cursor: stop)')
276
+ .action(async (agent, event) => {
277
+ const { hookCmd } = await import('./hook.js');
278
+ await hookCmd(agent, event);
279
+ });
280
+ program
281
+ .command('mcp')
282
+ .description('Start the MCP server (stdio transport)')
283
+ .action(async () => {
284
+ const { startMcpServer } = await import('../mcp/server.js');
285
+ await startMcpServer();
286
+ });
287
+ program
288
+ .command('config')
289
+ .description('Show configuration file path')
290
+ .action(async () => {
291
+ const { getConfigPath } = await import('../config.js');
292
+ const configPath = getConfigPath();
293
+ const exists = existsSync(configPath);
294
+ console.log(`Config file: ${configPath}${exists ? '' : ' (not found)'}`);
295
+ });
296
+ program
297
+ .command('graph')
298
+ .description('Export the knowledge graph, or reconstruct it at a git revision')
299
+ .option('--format <format>', 'output format: json, mermaid, dot', 'json')
300
+ .option('--at <rev>', 'reconstruct the graph at a git revision')
301
+ .option('--since <rev>', 'diff the graph since a git revision')
302
+ .action(async (opts) => {
303
+ const ctx = resolveContext(program.opts());
304
+ const { graphCommand } = await import('./graph.js');
305
+ handleResult(await graphCommand(ctx, opts));
306
+ });
307
+ await program.parseAsync(checkTargetArgs.args, { from: 'user' });
@@ -0,0 +1,9 @@
1
+ type LatCommandStyle = 'global' | 'local' | 'npx';
2
+ /**
3
+ * Remove all lat-owned hook entries from settings, then add fresh ones.
4
+ * Preserves any non-lat hooks the user may have configured.
5
+ */
6
+ export declare function syncLatHooks(settingsPath: string, style: LatCommandStyle, agent?: 'claude' | 'codex'): void;
7
+ export declare function readLogo(): string;
8
+ export declare function initCmd(targetDir?: string): Promise<void>;
9
+ export {};