@plebeiantech/lat.md 0.12.3-fork.3 → 0.12.3-fork.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/README.md +2 -0
- package/dist/src/cli/check-mode.js +5 -1
- package/dist/src/cli/comment-guard.d.ts +14 -0
- package/dist/src/cli/comment-guard.js +10 -33
- package/dist/src/cli/comment-reminder.d.ts +65 -6
- package/dist/src/cli/comment-reminder.js +164 -28
- package/dist/src/cli/index.js +29 -4
- package/dist/src/cli/search.js +6 -4
- package/dist/src/cli/ui-build.d.ts +4 -0
- package/dist/src/cli/ui-build.js +13 -0
- package/dist/src/cli/ui.js +18 -2
- package/dist/src/code-refs.js +25 -4
- package/dist/src/fork/upstream-drift-cli.d.ts +1 -0
- package/dist/src/fork/upstream-drift-cli.js +2 -0
- package/dist/src/fork/upstream-drift.d.ts +26 -0
- package/dist/src/fork/upstream-drift.js +185 -0
- package/dist/src/fork/upstream-guard-cli.d.ts +1 -0
- package/dist/src/fork/upstream-guard-cli.js +2 -0
- package/dist/src/fork/upstream-guard.d.ts +72 -0
- package/dist/src/fork/upstream-guard.js +445 -0
- package/dist/src/graph-export.d.ts +2 -0
- package/dist/src/graph-export.js +31 -12
- package/dist/src/knowledge/claude-memory.d.ts +1 -0
- package/dist/src/knowledge/claude-memory.js +33 -4
- package/dist/src/lattice.d.ts +1 -0
- package/dist/src/search/search.d.ts +1 -0
- package/dist/src/search/search.js +15 -9
- package/dist/src/untrusted.d.ts +0 -6
- package/dist/src/untrusted.js +7 -11
- package/dist/src/view/client/assets/index-VZwPPiFE.js +334 -0
- package/dist/src/view/client/assets/index-W8ktvNj9.css +1 -0
- package/dist/src/view/client/assets/logo-CNF8zs47.svg +182 -0
- package/dist/src/view/client/index.html +2 -2
- package/dist/src/view/git-diff.js +17 -0
- package/dist/src/view/graph.d.ts +6 -0
- package/dist/src/view/graph.js +176 -0
- package/dist/src/view/markdown.d.ts +5 -1
- package/dist/src/view/markdown.js +112 -25
- package/dist/src/view/protocol.d.ts +43 -0
- package/dist/src/view/protocol.js +1 -1
- package/dist/src/view/references.d.ts +2 -0
- package/dist/src/view/references.js +30 -8
- package/dist/src/view/repository.d.ts +5 -2
- package/dist/src/view/repository.js +13 -12
- package/dist/src/view/search.js +1 -0
- package/dist/src/view/server.d.ts +3 -0
- package/dist/src/view/server.js +42 -9
- package/dist/src/view/source-target.d.ts +8 -0
- package/dist/src/view/source-target.js +22 -0
- package/dist/src/view/static-build.d.ts +16 -0
- package/dist/src/view/static-build.js +408 -0
- package/dist/src/view/static-protocol.d.ts +23 -0
- package/dist/src/view/static-protocol.js +10 -0
- package/dist/src/view/store.d.ts +9 -1
- package/dist/src/view/store.js +82 -15
- package/dist/src/view/table-of-contents.d.ts +9 -0
- package/dist/src/view/table-of-contents.js +103 -0
- package/package.json +3 -1
- package/templates/AGENTS.md +2 -0
- package/templates/skill/SKILL.md +2 -0
- package/dist/src/view/client/assets/index-B0n0u03y.css +0 -1
- package/dist/src/view/client/assets/index-xm2_px4q.js +0 -23
package/README.md
CHANGED
|
@@ -62,6 +62,8 @@ npm i -g --prefix ~/.local/lat https://github.com/PlebeianTech/lat.md/releases/l
|
|
|
62
62
|
|
|
63
63
|
That last one wants `~/.local/lat/bin` on your `PATH`. A fixed prefix keeps the install independent of whichever Node version is active.
|
|
64
64
|
|
|
65
|
+
Pick one route and stay on it. A Release-route install left on `PATH` shadows a mise-managed one — `mise upgrade` then reports a new version while the shell keeps running the old binary.
|
|
66
|
+
|
|
65
67
|
Then run `lat init` in the repo you want to use lat in.
|
|
66
68
|
|
|
67
69
|
### As a Claude Code plugin
|
|
@@ -18,7 +18,11 @@ export const MODE_DIRS = {
|
|
|
18
18
|
explanation: 'explanation',
|
|
19
19
|
};
|
|
20
20
|
/** Reverse lookup: first path segment -> mode. Built once, not per file. */
|
|
21
|
-
|
|
21
|
+
// Null-prototype: the key is a directory name read off disk.
|
|
22
|
+
const DIR_TO_MODE = Object.create(null);
|
|
23
|
+
for (const mode of DIATAXIS_MODES) {
|
|
24
|
+
DIR_TO_MODE[MODE_DIRS[mode]] = mode;
|
|
25
|
+
}
|
|
22
26
|
const OUTCOME_RE = /\b(outcome|by the end|you will (build|learn|have|create)|what you (will )?(build|learn|have|create))\b/i;
|
|
23
27
|
/**
|
|
24
28
|
* Imperative verbs that flag a command inside an explanation document.
|
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
import { type ToolInput } from './comment-reminder.js';
|
|
2
|
+
/**
|
|
3
|
+
* The blocking half of the comment convention. `computeCommentReminder` runs
|
|
4
|
+
* at PostToolUse and only advises: by then the prose is already on disk, and
|
|
5
|
+
* it is deduped to once per file per session, so the second rationale block
|
|
6
|
+
* in a file draws no signal at all.
|
|
7
|
+
*
|
|
8
|
+
* This runs at PreToolUse instead, where `tool_input` is visible before the
|
|
9
|
+
* edit is applied and the hook can answer `deny`. A multi-line comment is
|
|
10
|
+
* refused outright and the agent is told to put the reasoning in `lat.md/`
|
|
11
|
+
* and leave a `@lat:` pointer behind.
|
|
12
|
+
*
|
|
13
|
+
* There is deliberately no per-session dedup here. A gate that fires once is
|
|
14
|
+
* not a gate.
|
|
15
|
+
*/
|
|
2
16
|
export type PreToolUseInput = {
|
|
3
17
|
hook_event_name?: string;
|
|
4
18
|
session_id?: string;
|
|
@@ -1,28 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
/**
|
|
3
|
-
* The blocking half of the comment convention. `computeCommentReminder` runs
|
|
4
|
-
* at PostToolUse and only advises: by then the prose is already on disk, and
|
|
5
|
-
* it is deduped to once per file per session, so the second rationale block
|
|
6
|
-
* in a file draws no signal at all.
|
|
7
|
-
*
|
|
8
|
-
* This runs at PreToolUse instead, where `tool_input` is visible before the
|
|
9
|
-
* edit is applied and the hook can answer `deny`. A multi-line comment is
|
|
10
|
-
* refused outright and the agent is told to put the reasoning in `lat.md/`
|
|
11
|
-
* and leave a `@lat:` pointer behind.
|
|
12
|
-
*
|
|
13
|
-
* There is deliberately no per-session dedup here. A gate that fires once is
|
|
14
|
-
* not a gate.
|
|
15
|
-
*/
|
|
16
|
-
/** Minimum candidate comment lines in one write before the edit is refused.
|
|
17
|
-
* A single line ("// bytes, not chars") is the bare-fact case the convention
|
|
18
|
-
* explicitly allows; two or more is a block of prose. */
|
|
19
|
-
const BLOCK_THRESHOLD = 2;
|
|
20
|
-
/** Explicit, reviewable opt-out. Spelled the same as the `lat:ignore` token
|
|
21
|
-
* [[src/code-refs.ts]] already honours, so a project has one escape hatch to
|
|
22
|
-
* learn rather than two. It suppresses only the line it appears on, which
|
|
23
|
-
* keeps a deliberate exception visible in the diff instead of silently
|
|
24
|
-
* disarming the gate for a whole file. */
|
|
25
|
-
const LAT_IGNORE_RE = /(?<![\w])lat:ignore(?![-\w])/;
|
|
1
|
+
import { hasLatTree, judgeWrittenComments, matchFamily, resolveProjectRoot, } from './comment-reminder.js';
|
|
26
2
|
function buildReason(opts) {
|
|
27
3
|
const where = opts.hasTree
|
|
28
4
|
? ' 1. Put the reasoning in a lat.md/ section. Verbatim is fine — it does\n' +
|
|
@@ -43,8 +19,12 @@ function buildReason(opts) {
|
|
|
43
19
|
' 3. Re-apply the edit with the prose replaced by that one pointer line.\n\n' +
|
|
44
20
|
'If a comment only narrates what the code does, delete it rather than ' +
|
|
45
21
|
'moving it — a reader could reconstruct it from the code.\n\n' +
|
|
46
|
-
|
|
47
|
-
'
|
|
22
|
+
'Two exits, if neither applies:\n' +
|
|
23
|
+
' - Put `lat:ignore` on a specific line to keep it. An explicit, ' +
|
|
24
|
+
'reviewable exception, not a way to silence the gate.\n' +
|
|
25
|
+
' - Use `Edit` rather than a whole-file `Write`. Re-emitting a comment ' +
|
|
26
|
+
'the file already holds is free in either shape, but an `Edit` puts far ' +
|
|
27
|
+
'less text in front of the count.');
|
|
48
28
|
}
|
|
49
29
|
/**
|
|
50
30
|
* Returns the denial reason for a single Edit/Write/MultiEdit call, or `null`
|
|
@@ -93,18 +73,15 @@ export function computeCommentBlock(input) {
|
|
|
93
73
|
const family = matchFamily(filePath);
|
|
94
74
|
if (!family)
|
|
95
75
|
return null;
|
|
96
|
-
const
|
|
97
|
-
if (!
|
|
98
|
-
return null;
|
|
99
|
-
const candidates = candidateCommentLines(written, family).filter((line) => !LAT_IGNORE_RE.test(line));
|
|
100
|
-
if (candidates.length < BLOCK_THRESHOLD)
|
|
76
|
+
const verdict = judgeWrittenComments(toolInput, family, 'before-write');
|
|
77
|
+
if (!verdict.flagged)
|
|
101
78
|
return null;
|
|
102
79
|
const projectRoot = resolveProjectRoot(filePath, input.cwd);
|
|
103
80
|
if (!projectRoot)
|
|
104
81
|
return null;
|
|
105
82
|
return buildReason({
|
|
106
83
|
base: filePath.split('/').pop() ?? filePath,
|
|
107
|
-
count:
|
|
84
|
+
count: verdict.count,
|
|
108
85
|
marker: family.marker,
|
|
109
86
|
hasTree: hasLatTree(projectRoot),
|
|
110
87
|
});
|
|
@@ -27,20 +27,79 @@ export declare function matchFamily(filePath: string): CommentFamily | null;
|
|
|
27
27
|
export type ToolInput = {
|
|
28
28
|
file_path?: string;
|
|
29
29
|
content?: string;
|
|
30
|
+
old_string?: string;
|
|
30
31
|
new_string?: string;
|
|
31
32
|
edits?: {
|
|
33
|
+
old_string?: string;
|
|
32
34
|
new_string?: string;
|
|
33
35
|
}[];
|
|
34
36
|
};
|
|
35
|
-
/**
|
|
36
|
-
*
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Which side of the tool call the caller is on.
|
|
39
|
+
*
|
|
40
|
+
* `'before-write'` — PreToolUse. The file on disk is still the pre-edit state,
|
|
41
|
+
* so it is usable as a baseline for a whole-file `Write`, which carries no
|
|
42
|
+
* other record of what it replaced.
|
|
43
|
+
*
|
|
44
|
+
* `'after-write'` — PostToolUse. The write has landed, so the file contains
|
|
45
|
+
* every line of `content` by construction. Diffing against it there cancels
|
|
46
|
+
* the whole payload and the caller sees nothing at all.
|
|
47
|
+
*
|
|
48
|
+
* An `Edit` carries its own `old_string` and needs neither reading: its
|
|
49
|
+
* baseline is phase-independent, which is the shape to prefer.
|
|
50
|
+
*
|
|
51
|
+
* The parameter is required so a third call site has to answer the question
|
|
52
|
+
* rather than inherit whichever default happened to suit the first two.
|
|
53
|
+
*/
|
|
54
|
+
export type WritePhase = 'before-write' | 'after-write';
|
|
55
|
+
/** Explicit, reviewable per-line opt-out, spelled the same as the token
|
|
56
|
+
* [[src/code-refs.ts]] already honours so a project has one escape hatch to
|
|
57
|
+
* learn rather than two. It lives here, not in the guard, because the
|
|
58
|
+
* advisory and blocking halves have to agree on it: an exemption that the
|
|
59
|
+
* gate honours but the reminder does not just relocates the nag.
|
|
60
|
+
* It suppresses only the line it appears on, keeping a deliberate exception
|
|
61
|
+
* visible in the diff instead of silently disarming the convention for a
|
|
62
|
+
* whole file. */
|
|
63
|
+
export declare const LAT_IGNORE_RE: RegExp;
|
|
64
|
+
/** Whether one line is a comment worth counting. Not counted:
|
|
39
65
|
* - a line that already carries a `@lat:` pointer (the compliant state)
|
|
66
|
+
* - a line carrying the explicit opt-out token
|
|
40
67
|
* - machine directives: shebangs, magic comments, linter/type pragmas
|
|
41
68
|
* - decoration with no alphanumeric character (`# ----`, `//////`, a bare
|
|
42
|
-
* `*/` closing a block)
|
|
43
|
-
|
|
69
|
+
* `*/` closing a block)
|
|
70
|
+
*
|
|
71
|
+
* Both halves of the convention call this and nothing else, so the gate and
|
|
72
|
+
* the reminder cannot drift apart on what counts as prose. */
|
|
73
|
+
export declare function isCandidateCommentLine(line: string, family: CommentFamily): boolean;
|
|
74
|
+
export type CommentVerdict = {
|
|
75
|
+
/** Candidate comment lines this call is answerable for. Names the number
|
|
76
|
+
* printed in the denial or the reminder. */
|
|
77
|
+
count: number;
|
|
78
|
+
/** Whether the call warrants a denial from the gate or a reminder from its
|
|
79
|
+
* advisory half. */
|
|
80
|
+
flagged: boolean;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* What one Edit/Write/MultiEdit call did to the comments in a file.
|
|
84
|
+
*
|
|
85
|
+
* Two rules, because neither alone survives contact with an agent:
|
|
86
|
+
*
|
|
87
|
+
* A run of `PROSE_THRESHOLD` or more *adjacent* comment lines is flagged as
|
|
88
|
+
* soon as any one of them is new. Counting only the new lines lets a block be
|
|
89
|
+
* grown one line per `Edit` and never reach the threshold — and the denial
|
|
90
|
+
* text itself recommends `Edit` over `Write`, so the technique is advertised.
|
|
91
|
+
* What matters is the block the edit leaves behind, not the increment.
|
|
92
|
+
*
|
|
93
|
+
* Isolated new comment lines are flagged once `PROSE_THRESHOLD` of them
|
|
94
|
+
* accumulate anywhere in the call. Two one-line comments in different places
|
|
95
|
+
* are still two lines of prose; without this a scattered write walks past the
|
|
96
|
+
* adjacency rule.
|
|
97
|
+
*
|
|
98
|
+
* Neither rule counts a line that was already there, so re-emitting a
|
|
99
|
+
* comment — the whole of a `Write`'s payload, or the lines bracketing an
|
|
100
|
+
* `Edit` — stays free.
|
|
101
|
+
*/
|
|
102
|
+
export declare function judgeWrittenComments(toolInput: ToolInput, family: CommentFamily, phase: WritePhase): CommentVerdict;
|
|
44
103
|
/** Resolvable project root, required so a scratch file in /tmp is not treated
|
|
45
104
|
* as a project. `cwd` is preferred (matches CLAUDE_PROJECT_DIR / payload cwd
|
|
46
105
|
* conventions); falls back to `git rev-parse --show-toplevel`. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { execSync } from 'node:child_process';
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
|
-
import { existsSync, mkdirSync, writeFileSync, statSync, lstatSync, } from 'node:fs';
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync, statSync, lstatSync, } from 'node:fs';
|
|
4
4
|
import { tmpdir } from 'node:os';
|
|
5
5
|
import { basename, dirname, join } from 'node:path';
|
|
6
6
|
const FAMILIES = [
|
|
@@ -41,35 +41,174 @@ export function matchFamily(filePath) {
|
|
|
41
41
|
}
|
|
42
42
|
return null;
|
|
43
43
|
}
|
|
44
|
-
/**
|
|
45
|
-
*
|
|
46
|
-
|
|
47
|
-
const
|
|
44
|
+
/** Line multiset of `text`, used as the baseline a written fragment is new
|
|
45
|
+
* against. */
|
|
46
|
+
function lineCounts(text) {
|
|
47
|
+
const counts = new Map();
|
|
48
|
+
for (const line of text.split('\n')) {
|
|
49
|
+
counts.set(line, (counts.get(line) ?? 0) + 1);
|
|
50
|
+
}
|
|
51
|
+
return counts;
|
|
52
|
+
}
|
|
53
|
+
/** Baseline taken from the file itself, or `null` when there is no readable
|
|
54
|
+
* file — a brand-new path, a directory, a permission error, a payload naming
|
|
55
|
+
* no file. `null` means every line counts as new, which is what makes an
|
|
56
|
+
* unreadable file fail closed: the gate denies rather than waving the write
|
|
57
|
+
* through on evidence it could not gather. */
|
|
58
|
+
function fileBaseline(filePath) {
|
|
59
|
+
if (!filePath)
|
|
60
|
+
return null;
|
|
61
|
+
try {
|
|
62
|
+
return lineCounts(readFileSync(filePath, 'utf-8'));
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The fragments one tool call writes, each against the narrowest baseline
|
|
70
|
+
* available for it.
|
|
71
|
+
*
|
|
72
|
+
* `old_string` is preferred over the file wherever the payload carries one,
|
|
73
|
+
* because the file is the wrong scope: matching a written line against
|
|
74
|
+
* *anywhere* in the file forgives a genuinely new block whenever one of its
|
|
75
|
+
* lines happens to duplicate an unrelated line elsewhere. `old_string` is the
|
|
76
|
+
* exact text being replaced, so the difference is the real delta.
|
|
77
|
+
*
|
|
78
|
+
* Baselines are per fragment rather than shared across a `MultiEdit`: two
|
|
79
|
+
* hunks that each re-emit the same surrounding comment are both re-emitting
|
|
80
|
+
* it, and charging the second one for it would deny exactly the edit this is
|
|
81
|
+
* here to allow.
|
|
82
|
+
*/
|
|
83
|
+
function writtenFragments(toolInput, phase) {
|
|
84
|
+
let diskRead = false;
|
|
85
|
+
let disk = null;
|
|
86
|
+
const fromFile = () => {
|
|
87
|
+
if (phase !== 'before-write')
|
|
88
|
+
return null;
|
|
89
|
+
if (!diskRead) {
|
|
90
|
+
disk = fileBaseline(toolInput.file_path);
|
|
91
|
+
diskRead = true;
|
|
92
|
+
}
|
|
93
|
+
return disk;
|
|
94
|
+
};
|
|
95
|
+
const baselineFor = (oldString) => typeof oldString === 'string' ? lineCounts(oldString) : fromFile();
|
|
96
|
+
const fragments = [];
|
|
48
97
|
if (typeof toolInput.content === 'string')
|
|
49
|
-
|
|
98
|
+
fragments.push({ text: toolInput.content, baseline: fromFile() });
|
|
50
99
|
if (typeof toolInput.new_string === 'string')
|
|
51
|
-
|
|
100
|
+
fragments.push({
|
|
101
|
+
text: toolInput.new_string,
|
|
102
|
+
baseline: baselineFor(toolInput.old_string),
|
|
103
|
+
});
|
|
52
104
|
if (Array.isArray(toolInput.edits)) {
|
|
53
105
|
for (const edit of toolInput.edits) {
|
|
54
106
|
if (typeof edit?.new_string === 'string')
|
|
55
|
-
|
|
107
|
+
fragments.push({
|
|
108
|
+
text: edit.new_string,
|
|
109
|
+
baseline: baselineFor(edit.old_string),
|
|
110
|
+
});
|
|
56
111
|
}
|
|
57
112
|
}
|
|
58
|
-
return
|
|
113
|
+
return fragments;
|
|
59
114
|
}
|
|
60
|
-
/**
|
|
115
|
+
/** Explicit, reviewable per-line opt-out, spelled the same as the token
|
|
116
|
+
* [[src/code-refs.ts]] already honours so a project has one escape hatch to
|
|
117
|
+
* learn rather than two. It lives here, not in the guard, because the
|
|
118
|
+
* advisory and blocking halves have to agree on it: an exemption that the
|
|
119
|
+
* gate honours but the reminder does not just relocates the nag.
|
|
120
|
+
* It suppresses only the line it appears on, keeping a deliberate exception
|
|
121
|
+
* visible in the diff instead of silently disarming the convention for a
|
|
122
|
+
* whole file. */
|
|
123
|
+
export const LAT_IGNORE_RE = /(?<![\w])lat:ignore(?![-\w])/;
|
|
124
|
+
/** Whether one line is a comment worth counting. Not counted:
|
|
61
125
|
* - a line that already carries a `@lat:` pointer (the compliant state)
|
|
126
|
+
* - a line carrying the explicit opt-out token
|
|
62
127
|
* - machine directives: shebangs, magic comments, linter/type pragmas
|
|
63
128
|
* - decoration with no alphanumeric character (`# ----`, `//////`, a bare
|
|
64
|
-
* `*/` closing a block)
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
.
|
|
71
|
-
|
|
72
|
-
|
|
129
|
+
* `*/` closing a block)
|
|
130
|
+
*
|
|
131
|
+
* Both halves of the convention call this and nothing else, so the gate and
|
|
132
|
+
* the reminder cannot drift apart on what counts as prose. */
|
|
133
|
+
export function isCandidateCommentLine(line, family) {
|
|
134
|
+
return (family.commentRe.test(line) &&
|
|
135
|
+
!line.includes('@lat:') &&
|
|
136
|
+
!LAT_IGNORE_RE.test(line) &&
|
|
137
|
+
!/^\s*#!/.test(line) &&
|
|
138
|
+
!family.pragmaRe.test(line) &&
|
|
139
|
+
/[a-zA-Z0-9]/.test(line));
|
|
140
|
+
}
|
|
141
|
+
/** Candidate comment lines in one write before either half reacts. A single
|
|
142
|
+
* line ("// bytes, not chars") is the bare-fact case the convention allows;
|
|
143
|
+
* two is a block of prose. */
|
|
144
|
+
const PROSE_THRESHOLD = 2;
|
|
145
|
+
/**
|
|
146
|
+
* What one Edit/Write/MultiEdit call did to the comments in a file.
|
|
147
|
+
*
|
|
148
|
+
* Two rules, because neither alone survives contact with an agent:
|
|
149
|
+
*
|
|
150
|
+
* A run of `PROSE_THRESHOLD` or more *adjacent* comment lines is flagged as
|
|
151
|
+
* soon as any one of them is new. Counting only the new lines lets a block be
|
|
152
|
+
* grown one line per `Edit` and never reach the threshold — and the denial
|
|
153
|
+
* text itself recommends `Edit` over `Write`, so the technique is advertised.
|
|
154
|
+
* What matters is the block the edit leaves behind, not the increment.
|
|
155
|
+
*
|
|
156
|
+
* Isolated new comment lines are flagged once `PROSE_THRESHOLD` of them
|
|
157
|
+
* accumulate anywhere in the call. Two one-line comments in different places
|
|
158
|
+
* are still two lines of prose; without this a scattered write walks past the
|
|
159
|
+
* adjacency rule.
|
|
160
|
+
*
|
|
161
|
+
* Neither rule counts a line that was already there, so re-emitting a
|
|
162
|
+
* comment — the whole of a `Write`'s payload, or the lines bracketing an
|
|
163
|
+
* `Edit` — stays free.
|
|
164
|
+
*/
|
|
165
|
+
export function judgeWrittenComments(toolInput, family, phase) {
|
|
166
|
+
const fragments = writtenFragments(toolInput, phase);
|
|
167
|
+
if (!fragments.some((fragment) => fragment.text !== ''))
|
|
168
|
+
return { count: 0, flagged: false };
|
|
169
|
+
let inFlaggedRuns = 0;
|
|
170
|
+
let isolatedNew = 0;
|
|
171
|
+
for (const fragment of fragments) {
|
|
172
|
+
const lines = fragment.text.split('\n');
|
|
173
|
+
const unclaimed = fragment.baseline ? new Map(fragment.baseline) : null;
|
|
174
|
+
const isNew = [];
|
|
175
|
+
const isComment = [];
|
|
176
|
+
for (const line of lines) {
|
|
177
|
+
let fresh = true;
|
|
178
|
+
if (unclaimed) {
|
|
179
|
+
const left = unclaimed.get(line) ?? 0;
|
|
180
|
+
if (left > 0) {
|
|
181
|
+
unclaimed.set(line, left - 1);
|
|
182
|
+
fresh = false;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
isNew.push(fresh);
|
|
186
|
+
isComment.push(isCandidateCommentLine(line, family));
|
|
187
|
+
}
|
|
188
|
+
let i = 0;
|
|
189
|
+
while (i < lines.length) {
|
|
190
|
+
if (!isComment[i]) {
|
|
191
|
+
i += 1;
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
let end = i;
|
|
195
|
+
while (end < lines.length && isComment[end])
|
|
196
|
+
end += 1;
|
|
197
|
+
let fresh = 0;
|
|
198
|
+
for (let k = i; k < end; k += 1)
|
|
199
|
+
if (isNew[k])
|
|
200
|
+
fresh += 1;
|
|
201
|
+
if (end - i >= PROSE_THRESHOLD && fresh > 0)
|
|
202
|
+
inFlaggedRuns += end - i;
|
|
203
|
+
else
|
|
204
|
+
isolatedNew += fresh;
|
|
205
|
+
i = end;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return {
|
|
209
|
+
count: inFlaggedRuns + isolatedNew,
|
|
210
|
+
flagged: inFlaggedRuns > 0 || isolatedNew >= PROSE_THRESHOLD,
|
|
211
|
+
};
|
|
73
212
|
}
|
|
74
213
|
/** Resolvable project root, required so a scratch file in /tmp is not treated
|
|
75
214
|
* as a project. `cwd` is preferred (matches CLAUDE_PROJECT_DIR / payload cwd
|
|
@@ -176,16 +315,13 @@ export function computeCommentReminder(input) {
|
|
|
176
315
|
const family = matchFamily(filePath);
|
|
177
316
|
if (!family)
|
|
178
317
|
return null;
|
|
179
|
-
const written = extractWrittenText(toolInput);
|
|
180
|
-
if (!written)
|
|
181
|
-
return null;
|
|
182
318
|
// A single-line comment ("// increment the counter") almost always states
|
|
183
319
|
// a bare fact, not a rationale — the acceptance case for this hook. Only a
|
|
184
|
-
//
|
|
185
|
-
//
|
|
186
|
-
//
|
|
187
|
-
const
|
|
188
|
-
if (
|
|
320
|
+
// block is treated as prose worth a reminder; the model still makes the
|
|
321
|
+
// real judgment call, this just filters the overwhelmingly common one-liner
|
|
322
|
+
// before it ever reaches that question.
|
|
323
|
+
const verdict = judgeWrittenComments(toolInput, family, 'after-write');
|
|
324
|
+
if (!verdict.flagged)
|
|
189
325
|
return null;
|
|
190
326
|
const sessionId = input.session_id;
|
|
191
327
|
let dedup = null;
|
|
@@ -201,7 +337,7 @@ export function computeCommentReminder(input) {
|
|
|
201
337
|
const base = basename(filePath);
|
|
202
338
|
const message = buildMessage({
|
|
203
339
|
base,
|
|
204
|
-
count:
|
|
340
|
+
count: verdict.count,
|
|
205
341
|
marker: family.marker,
|
|
206
342
|
hasTree,
|
|
207
343
|
});
|
package/dist/src/cli/index.js
CHANGED
|
@@ -6,8 +6,18 @@ if (!process.argv.includes('--verbose')) {
|
|
|
6
6
|
import { existsSync, readFileSync } from 'node:fs';
|
|
7
7
|
import { dirname, join } from 'node:path';
|
|
8
8
|
import { fileURLToPath } from 'node:url';
|
|
9
|
-
import { Command } from 'commander';
|
|
9
|
+
import { Command, InvalidArgumentError } from 'commander';
|
|
10
10
|
import { resolveCheckContext, resolveContext } from './context.js';
|
|
11
|
+
function parsePort(value) {
|
|
12
|
+
if (!/^\d+$/.test(value)) {
|
|
13
|
+
throw new InvalidArgumentError('port must be an integer from 1 to 65535');
|
|
14
|
+
}
|
|
15
|
+
const port = Number(value);
|
|
16
|
+
if (port < 1 || port > 65_535) {
|
|
17
|
+
throw new InvalidArgumentError('port must be an integer from 1 to 65535');
|
|
18
|
+
}
|
|
19
|
+
return port;
|
|
20
|
+
}
|
|
11
21
|
/** Reserve `-- <directory>` for an explicit check target. */
|
|
12
22
|
function splitCheckTarget(args) {
|
|
13
23
|
let commandIndex = -1;
|
|
@@ -90,13 +100,28 @@ program
|
|
|
90
100
|
const { sectionCommand } = await import('./section.js');
|
|
91
101
|
handleResult(await sectionCommand(ctx, query));
|
|
92
102
|
});
|
|
93
|
-
program
|
|
103
|
+
const ui = program
|
|
94
104
|
.command('ui')
|
|
95
105
|
.description('Open lat.md in a local browser')
|
|
96
|
-
.
|
|
106
|
+
.option('--logo-text <text>', 'top-left logo text')
|
|
107
|
+
.option('--port <number>', 'server port (default: 4242; explicit ports are strict)', parsePort)
|
|
108
|
+
.action(async (opts) => {
|
|
97
109
|
const ctx = resolveContext(program.opts());
|
|
98
110
|
const { uiCommand } = await import('./ui.js');
|
|
99
|
-
handleResult(await uiCommand(ctx));
|
|
111
|
+
handleResult(await uiCommand(ctx, { logoText: opts.logoText, port: opts.port }));
|
|
112
|
+
});
|
|
113
|
+
ui.command('build')
|
|
114
|
+
.description('Export lat.md as a static website')
|
|
115
|
+
.argument('[output]', 'output directory relative to the project', 'lat-ui')
|
|
116
|
+
.option('--base <path>', 'deployment base path', '/')
|
|
117
|
+
.option('--logo-text <text>', 'top-left logo text')
|
|
118
|
+
.action(async (output, opts) => {
|
|
119
|
+
const ctx = resolveContext(program.opts());
|
|
120
|
+
const { uiBuildCommand } = await import('./ui-build.js');
|
|
121
|
+
handleResult(await uiBuildCommand(ctx, output, {
|
|
122
|
+
basePath: opts.base,
|
|
123
|
+
logoText: opts.logoText ?? ui.opts().logoText,
|
|
124
|
+
}));
|
|
100
125
|
});
|
|
101
126
|
program
|
|
102
127
|
.command('refs')
|
package/dist/src/cli/search.js
CHANGED
|
@@ -73,10 +73,12 @@ async function resolveMatches(latDir, results, preloadedSections) {
|
|
|
73
73
|
const allSections = preloadedSections ?? (await loadAllSections(latDir));
|
|
74
74
|
const flat = flattenSections(allSections);
|
|
75
75
|
const byId = new Map(flat.map((s) => [s.id, s]));
|
|
76
|
-
return results
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
return results.flatMap((result) => {
|
|
77
|
+
const section = byId.get(result.id);
|
|
78
|
+
return section
|
|
79
|
+
? [{ section, reason: 'semantic match', score: result.score }]
|
|
80
|
+
: [];
|
|
81
|
+
});
|
|
80
82
|
}
|
|
81
83
|
/**
|
|
82
84
|
* Run a semantic search across lat.md sections.
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CmdContext, CmdResult } from '../context.js';
|
|
2
|
+
import { type StaticViewBuildOptions } from '../view/static-build.js';
|
|
3
|
+
/** Export the current vault as a serverless, read-only Lat UI. */
|
|
4
|
+
export declare function uiBuildCommand(ctx: CmdContext, output?: string, options?: StaticViewBuildOptions): Promise<CmdResult>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { buildStaticView, } from '../view/static-build.js';
|
|
2
|
+
/** Export the current vault as a serverless, read-only Lat UI. */
|
|
3
|
+
export async function uiBuildCommand(ctx, output = 'lat-ui', options = {}) {
|
|
4
|
+
try {
|
|
5
|
+
const result = await buildStaticView(ctx, output, options);
|
|
6
|
+
return {
|
|
7
|
+
output: `Built ${result.documents} documents and ${result.sources} source views at ${result.outputDir}`,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
return { output: error.message, isError: true };
|
|
12
|
+
}
|
|
13
|
+
}
|
package/dist/src/cli/ui.js
CHANGED
|
@@ -21,9 +21,25 @@ export function openBrowser(url) {
|
|
|
21
21
|
}
|
|
22
22
|
/** Start `lat ui`, report its URL, and launch the default browser. */
|
|
23
23
|
export async function uiCommand(ctx, options = {}) {
|
|
24
|
-
|
|
24
|
+
let server;
|
|
25
|
+
try {
|
|
26
|
+
server = await startViewServer(ctx, options);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
if (options.port !== undefined &&
|
|
30
|
+
error.code === 'EADDRINUSE') {
|
|
31
|
+
return {
|
|
32
|
+
isError: true,
|
|
33
|
+
output: `Port ${options.port} is already in use. Choose another with --port <number>.`,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
25
38
|
options.onStarted?.(server);
|
|
26
|
-
const lines = [
|
|
39
|
+
const lines = [
|
|
40
|
+
`Viewing lat.md at ${server.url}`,
|
|
41
|
+
'Note: you can use `lat ui build` to build a static version of the UI',
|
|
42
|
+
];
|
|
27
43
|
try {
|
|
28
44
|
await (options.openBrowser ?? openBrowser)(server.url);
|
|
29
45
|
}
|
package/dist/src/code-refs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import { execFile } from 'node:child_process';
|
|
3
|
-
import { join, relative } from 'node:path';
|
|
3
|
+
import { join, posix, relative } from 'node:path';
|
|
4
4
|
import { toPosix, walkEntries } from './walk.js';
|
|
5
5
|
/** Glob patterns used to exclude directories/files from code-ref scanning.
|
|
6
6
|
* Shared between rg args and the TS fallback's walkFiles filter. */
|
|
@@ -9,7 +9,10 @@ const EXCLUDE_GLOBS = ['*.md'];
|
|
|
9
9
|
/** Walk project files for code-ref scanning. Uses walkEntries for .gitignore
|
|
10
10
|
* support, then additionally skips .md files, lat.md/, .claude/, and sub-projects. */
|
|
11
11
|
export async function walkFiles(dir) {
|
|
12
|
-
const entries = await walkEntries(dir);
|
|
12
|
+
const entries = (await walkEntries(dir)).map(toPosix);
|
|
13
|
+
const generatedOutputs = new Set(entries
|
|
14
|
+
.filter((entry) => entry.endsWith('/.lat-ui-build'))
|
|
15
|
+
.map((entry) => `${posix.dirname(entry)}/`));
|
|
13
16
|
// Collect directories that contain their own lat.md/ (sub-projects)
|
|
14
17
|
const subProjects = new Set();
|
|
15
18
|
for (const e of entries) {
|
|
@@ -21,6 +24,7 @@ export async function walkFiles(dir) {
|
|
|
21
24
|
.filter((e) => !e.endsWith('.md') &&
|
|
22
25
|
!e.startsWith('lat.md/') &&
|
|
23
26
|
!e.startsWith('.claude/') &&
|
|
27
|
+
![...generatedOutputs].some((prefix) => e.startsWith(prefix)) &&
|
|
24
28
|
![...subProjects].some((prefix) => e.startsWith(prefix)))
|
|
25
29
|
.map((e) => join(dir, e));
|
|
26
30
|
}
|
|
@@ -148,8 +152,22 @@ async function findSubProjects(projectRoot) {
|
|
|
148
152
|
}
|
|
149
153
|
return [...subProjects];
|
|
150
154
|
}
|
|
155
|
+
/** Find static UI exports so generated JSON and bundles never become code refs. */
|
|
156
|
+
async function findGeneratedOutputs(projectRoot) {
|
|
157
|
+
const out = await tryExec('rg', ['--files', '--hidden', '--glob', '**/.lat-ui-build', '.'], projectRoot);
|
|
158
|
+
if (!out)
|
|
159
|
+
return [];
|
|
160
|
+
return [
|
|
161
|
+
...new Set(out
|
|
162
|
+
.split('\n')
|
|
163
|
+
.filter(Boolean)
|
|
164
|
+
.map((line) => toPosix(line).replace(/^\.\//, ''))
|
|
165
|
+
.filter((line) => line.endsWith('/.lat-ui-build'))
|
|
166
|
+
.map((line) => posix.dirname(line))),
|
|
167
|
+
];
|
|
168
|
+
}
|
|
151
169
|
/** Build rg glob exclusion args. */
|
|
152
|
-
function rgExcludeArgs(subProjects) {
|
|
170
|
+
function rgExcludeArgs(subProjects, generatedOutputs) {
|
|
153
171
|
const args = [];
|
|
154
172
|
for (const dir of EXCLUDE_DIRS)
|
|
155
173
|
args.push('--glob', `!${dir}/`);
|
|
@@ -157,6 +175,8 @@ function rgExcludeArgs(subProjects) {
|
|
|
157
175
|
args.push('--glob', `!${glob}`);
|
|
158
176
|
for (const sp of subProjects)
|
|
159
177
|
args.push('--glob', `!${sp}/`);
|
|
178
|
+
for (const output of generatedOutputs)
|
|
179
|
+
args.push('--glob', `!${output}/`);
|
|
160
180
|
return args;
|
|
161
181
|
}
|
|
162
182
|
/**
|
|
@@ -167,7 +187,8 @@ function rgExcludeArgs(subProjects) {
|
|
|
167
187
|
async function tryRipgrep(projectRoot) {
|
|
168
188
|
// Detect sub-projects first so we can exclude them from all rg calls
|
|
169
189
|
const subProjects = await findSubProjects(projectRoot);
|
|
170
|
-
const
|
|
190
|
+
const generatedOutputs = await findGeneratedOutputs(projectRoot);
|
|
191
|
+
const excludes = rgExcludeArgs(subProjects, generatedOutputs);
|
|
171
192
|
// Search for @lat refs
|
|
172
193
|
const searchArgs = [
|
|
173
194
|
'--no-heading',
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare const UPSTREAM_URL = "https://github.com/vercel-labs/lat.md.git";
|
|
2
|
+
export declare const UPSTREAM_REF = "refs/remotes/upstream/main";
|
|
3
|
+
export type Drift = {
|
|
4
|
+
upstream: string;
|
|
5
|
+
ahead: number;
|
|
6
|
+
behind: number;
|
|
7
|
+
upstreamFiles: string[];
|
|
8
|
+
forkFiles: string[];
|
|
9
|
+
overlap: string[];
|
|
10
|
+
conflicts: string[];
|
|
11
|
+
mergesCleanly: boolean;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Conflicting paths from `git merge-tree --write-tree --name-only`, whose
|
|
15
|
+
* output is the written tree id, then one path per line, then a blank line
|
|
16
|
+
* and the human-readable log. Everything after that blank line is prose.
|
|
17
|
+
*/
|
|
18
|
+
export declare function parseMergeTree(stdout: string): string[];
|
|
19
|
+
export declare function fetchUpstream(repo: string, url: string, ref: string): void;
|
|
20
|
+
export declare function analyzeDrift(opts: {
|
|
21
|
+
repo: string;
|
|
22
|
+
syncPoint: string;
|
|
23
|
+
upstreamRef: string;
|
|
24
|
+
}): Drift;
|
|
25
|
+
export declare function formatDrift(drift: Drift): string;
|
|
26
|
+
export declare function main(argv: string[]): number;
|