@litfamily/litcodex 1.0.27 → 1.0.28
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-Ko-KR.md +9 -9
- package/README.md +9 -9
- package/dist/cli.d.ts +3 -2
- package/dist/cli.js +72 -3
- package/dist/install/generated-skill-payload-hashes.d.ts +2 -2
- package/dist/install/generated-skill-payload-hashes.js +2 -2
- package/dist/postinstall.js +12 -1
- package/dist/pty-helper.d.ts +7 -0
- package/dist/pty-helper.js +45 -0
- package/dist/run.d.ts +57 -0
- package/dist/run.js +354 -0
- package/marketplace/plugins/litcodex/.codex-plugin/plugin.json +1 -1
- package/marketplace/plugins/litcodex/components/auto-update/package.json +1 -1
- package/marketplace/plugins/litcodex/components/comment-checker/package.json +1 -1
- package/marketplace/plugins/litcodex/components/git-bash/package.json +1 -1
- package/marketplace/plugins/litcodex/components/lit-loop/dist/card-status.d.ts +8 -3
- package/marketplace/plugins/litcodex/components/lit-loop/dist/card-status.js +11 -6
- package/marketplace/plugins/litcodex/components/lit-loop/dist/hook-cli.js +28 -10
- package/marketplace/plugins/litcodex/components/lit-loop/dist/hud-cli.d.ts +38 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/hud-cli.js +155 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/hud.d.ts +42 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/hud.js +297 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/run-filter.d.ts +23 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/run-filter.js +142 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/run-panel.d.ts +29 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/run-panel.js +102 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/screen-card.d.ts +24 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/screen-card.js +104 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/screen-status.d.ts +24 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/screen-status.js +110 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/statusline.d.ts +17 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/statusline.js +113 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/workflow-map.d.ts +7 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/workflow-map.js +58 -10
- package/marketplace/plugins/litcodex/components/lit-loop/package.json +1 -1
- package/marketplace/plugins/litcodex/components/lsp/package.json +1 -1
- package/marketplace/plugins/litcodex/components/rules/bundled-rules/lit-humanizer.md +2 -0
- package/marketplace/plugins/litcodex/components/rules/dist/deliverable-hedge-guard.d.ts +8 -0
- package/marketplace/plugins/litcodex/components/rules/dist/deliverable-hedge-guard.js +381 -39
- package/marketplace/plugins/litcodex/components/rules/package.json +1 -1
- package/marketplace/plugins/litcodex/components/start-work-continuation/package.json +1 -1
- package/marketplace/plugins/litcodex/components/telemetry/package.json +1 -1
- package/marketplace/plugins/litcodex/components/wikify-knowledge/package.json +1 -1
- package/marketplace/plugins/litcodex/skills/lit-humanizer/SKILL.md +4 -0
- package/marketplace/plugins/litcodex/skills/lit-humanizer/scripts/core.mjs +5 -1
- package/marketplace/plugins/litcodex/skills/lit-loop/SKILL.md +2 -1
- package/node_modules/@litcodex/lit-loop/dist/card-status.d.ts +8 -3
- package/node_modules/@litcodex/lit-loop/dist/card-status.js +11 -6
- package/node_modules/@litcodex/lit-loop/dist/hook-cli.js +28 -10
- package/node_modules/@litcodex/lit-loop/dist/hud-cli.d.ts +38 -0
- package/node_modules/@litcodex/lit-loop/dist/hud-cli.js +155 -0
- package/node_modules/@litcodex/lit-loop/dist/hud.d.ts +42 -0
- package/node_modules/@litcodex/lit-loop/dist/hud.js +297 -0
- package/node_modules/@litcodex/lit-loop/dist/run-filter.d.ts +23 -0
- package/node_modules/@litcodex/lit-loop/dist/run-filter.js +142 -0
- package/node_modules/@litcodex/lit-loop/dist/run-panel.d.ts +29 -0
- package/node_modules/@litcodex/lit-loop/dist/run-panel.js +102 -0
- package/node_modules/@litcodex/lit-loop/dist/screen-card.d.ts +24 -0
- package/node_modules/@litcodex/lit-loop/dist/screen-card.js +104 -0
- package/node_modules/@litcodex/lit-loop/dist/screen-status.d.ts +24 -0
- package/node_modules/@litcodex/lit-loop/dist/screen-status.js +110 -0
- package/node_modules/@litcodex/lit-loop/dist/statusline.d.ts +17 -0
- package/node_modules/@litcodex/lit-loop/dist/statusline.js +113 -0
- package/node_modules/@litcodex/lit-loop/dist/workflow-map.d.ts +7 -0
- package/node_modules/@litcodex/lit-loop/dist/workflow-map.js +58 -10
- package/node_modules/@litcodex/lit-loop/package.json +1 -1
- package/node_modules/@litcodex/lit-loop/skills/lit-humanizer/SKILL.md +4 -0
- package/node_modules/@litcodex/lit-loop/skills/lit-humanizer/scripts/core.mjs +5 -1
- package/node_modules/@litcodex/lit-loop/skills/lit-loop/SKILL.md +2 -1
- package/package.json +5 -2
- package/readme-assets/badge-version.svg +1 -1
|
@@ -9,6 +9,8 @@ Pick the skill for the task from the task itself. Do not open `lit-humanizer` fi
|
|
|
9
9
|
|
|
10
10
|
Block only high-confidence drafting residue: label-only evidence/source lines, stacked limitation lists, model disclaimers, and chatbot sign-offs. Warn on vocabulary lists, repeated em dashes, contrast formulas, triads, and rhythm. Warnings are advisory. Never infer authorship from a pattern.
|
|
11
11
|
|
|
12
|
+
Say what a number or thing is first, then add a needed caveat once: write "18,420회는 같은 사람의 반복 방문을 포함한 방문 횟수 합계입니다" in place of `18,420회는 주민 수가 아님`. The write guard refuses a paragraph, list, or table column that stacks two Korean definitional negations, or three in any language, and reworded forms such as `~로 읽을 수 없음`, `~와는 다르다` and `~로 읽으면 안 된다` count too. Exactly two that are English or mixed only warn. Keep any bad example in inline code or a blockquote.
|
|
13
|
+
|
|
12
14
|
Put requested citations in footnotes or a reference list. State a real, material limitation once in the chat reply; keep the deliverable focused on its audience. Keep internal records detailed. For DOCX/PPTX/PDF created by a tool, inspect extracted text after creation and rebuild on a block hit.
|
|
13
15
|
|
|
14
16
|
Preserve facts, numbers, names, quotations, citations, uncertainty, and useful structure. For code, review comments and developer prose; keep validation, error handling, accessibility, and data-integrity checks at trust boundaries.
|
|
@@ -11,6 +11,8 @@ export interface HumanizerFinding {
|
|
|
11
11
|
readonly severity: "block" | "warn";
|
|
12
12
|
readonly rule: string;
|
|
13
13
|
readonly excerpt?: string;
|
|
14
|
+
/** Last line of a multi-line finding, such as a negation-cluster paragraph. */
|
|
15
|
+
readonly endLine?: number;
|
|
14
16
|
}
|
|
15
17
|
type GuardOptions = {
|
|
16
18
|
readonly scan?: (text: string) => readonly HumanizerFinding[];
|
|
@@ -28,4 +30,10 @@ export declare function inspectHumanizerText(text: string, detectorPath?: string
|
|
|
28
30
|
export declare function runHumanizerPreToolUse(input: HumanizerHookInput, options?: GuardOptions): string;
|
|
29
31
|
/** Inspect Office/PDF output after creation; block findings ask the model to fix and rebuild. */
|
|
30
32
|
export declare function runHumanizerPostToolUse(input: HumanizerHookInput, options?: GuardOptions): string;
|
|
33
|
+
/**
|
|
34
|
+
* Check beside the detector: definitional negations, plain or reworded, counted per paragraph or list block,
|
|
35
|
+
* and per column in a Markdown table (short status cells ignored). Code, inline code and quote lines are
|
|
36
|
+
* removed first. A block finding goes through the guard's normal refusal; a warning stays advisory.
|
|
37
|
+
*/
|
|
38
|
+
export declare function negationClusterFindings(text: string): HumanizerFinding[];
|
|
31
39
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
|
-
import { lstatSync, readFileSync, realpathSync } from "node:fs";
|
|
3
|
-
import { dirname, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
2
|
+
import { existsSync, lstatSync, readFileSync, realpathSync } from "node:fs";
|
|
3
|
+
import { basename, dirname, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
const MAX_TEXT_BYTES = 4 * 1024 * 1024;
|
|
6
6
|
const MAX_PATHS = 64;
|
|
@@ -66,14 +66,20 @@ export function runHumanizerPreToolUse(input, options = {}) {
|
|
|
66
66
|
const writes = collectWriteParts(input);
|
|
67
67
|
if (writes === null)
|
|
68
68
|
return contextOutput("PreToolUse", FAIL_OPEN_NOTE);
|
|
69
|
-
const
|
|
69
|
+
const project = projectRoot(input.cwd);
|
|
70
|
+
const units = scanUnits(writes
|
|
70
71
|
.filter((part) => !isInternalPath(part.path) && !isOfficePath(part.path))
|
|
71
|
-
.filter((part) => part.path === undefined ||
|
|
72
|
-
.
|
|
73
|
-
|
|
74
|
-
if (text.length === 0)
|
|
72
|
+
.filter((part) => part.path === undefined || isInside(project, part.path, input.cwd))
|
|
73
|
+
.filter((part) => part.path === undefined || HUMANIZER_PROSE_EXTENSIONS.has(extname(part.path).toLowerCase())), input.cwd).filter((unit) => unit.text.length > 0 && (unit.changed === null || unit.changed.size > 0));
|
|
74
|
+
if (units.length === 0)
|
|
75
75
|
return "";
|
|
76
|
-
|
|
76
|
+
// Each file is scanned whole, so fences, quotes and blank lines around the edit keep their meaning;
|
|
77
|
+
// only findings that touch a changed line count.
|
|
78
|
+
const findings = units.flatMap((unit) => {
|
|
79
|
+
const masked = maskQuotedUserText(unit.text);
|
|
80
|
+
return [...(options.scan ?? inspectHumanizerText)(masked), ...negationClusterFindings(masked)].filter((item) => touchesChangedLine(item, unit.changed));
|
|
81
|
+
});
|
|
82
|
+
return findingsOutput("PreToolUse", findings, writes.length);
|
|
77
83
|
}
|
|
78
84
|
catch {
|
|
79
85
|
return contextOutput("PreToolUse", FAIL_OPEN_NOTE);
|
|
@@ -100,6 +106,99 @@ export function runHumanizerPostToolUse(input, options = {}) {
|
|
|
100
106
|
return contextOutput("PostToolUse", FAIL_OPEN_NOTE);
|
|
101
107
|
}
|
|
102
108
|
}
|
|
109
|
+
const NEGATION_CLUSTER = "negation-cluster";
|
|
110
|
+
const NEGATION_BLOCK_KO = 2;
|
|
111
|
+
const NEGATION_BLOCK_TOTAL = 3;
|
|
112
|
+
const NEGATION_WARN_TOTAL = 2;
|
|
113
|
+
const NEGATION_SHORT_CELL = 12;
|
|
114
|
+
/**
|
|
115
|
+
* Plain Korean negations and the reworded forms that restate them ("~로 읽을 수 없음", "~을 뜻하지 않음",
|
|
116
|
+
* "~와는 다르다", "~로 읽으면 안 된다").
|
|
117
|
+
*/
|
|
118
|
+
const NEGATION_KO_PATTERNS = [
|
|
119
|
+
/아닙니다|아님|아니다|아니며|아니라|아닌/gu,
|
|
120
|
+
/(?:로|으로) (?:읽을|볼|해석할|간주할) 수 없|(?:로|으로) 보지 않|(?:을|를) (?:뜻하지|의미하지|나타내지|가리키지) 않|(?:와|과)는 다(?:릅니다|르다|름|르며|르고|르므로)|(?:로|으로) (?:읽으면|보면|해석하면) 안 /gu,
|
|
121
|
+
];
|
|
122
|
+
const NEGATION_EN_PATTERNS = [
|
|
123
|
+
/(?<![\p{L}\p{N}_])(?:is not|are not|isn't|aren't|not a|rather than)(?![\p{L}\p{N}_])/giu,
|
|
124
|
+
/(?<![\p{L}\p{N}_])(?:(?:should not|cannot|can't|must not) be (?:read|taken|interpreted|treated) as|(?:does|do) not (?:mean|represent|indicate))(?![\p{L}\p{N}_])/giu,
|
|
125
|
+
];
|
|
126
|
+
const NEGATION_NOTE = 'negation-cluster: Several negations sit in one place. Say what the thing is first, then add the caveat once. Example: write "18,420 visits in total, including repeat visits" instead of "18,420 is not the number of residents".';
|
|
127
|
+
function patternCount(patterns, text) {
|
|
128
|
+
return patterns.reduce((total, pattern) => total + (text.match(pattern)?.length ?? 0), 0);
|
|
129
|
+
}
|
|
130
|
+
/** Two Korean negations, or three in any language, block; exactly two otherwise warn. */
|
|
131
|
+
function negationTier(text) {
|
|
132
|
+
const ko = patternCount(NEGATION_KO_PATTERNS, text);
|
|
133
|
+
const total = ko + patternCount(NEGATION_EN_PATTERNS, text);
|
|
134
|
+
if (ko >= NEGATION_BLOCK_KO || total >= NEGATION_BLOCK_TOTAL)
|
|
135
|
+
return "block";
|
|
136
|
+
return total === NEGATION_WARN_TOTAL ? "warn" : null;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Check beside the detector: definitional negations, plain or reworded, counted per paragraph or list block,
|
|
140
|
+
* and per column in a Markdown table (short status cells ignored). Code, inline code and quote lines are
|
|
141
|
+
* removed first. A block finding goes through the guard's normal refusal; a warning stays advisory.
|
|
142
|
+
*/
|
|
143
|
+
export function negationClusterFindings(text) {
|
|
144
|
+
let fence = null;
|
|
145
|
+
const lines = text.split(/\r?\n/u).map((line) => {
|
|
146
|
+
// Same fence rule as the detector: ``` or ~~~ opens, the same character at least as long closes,
|
|
147
|
+
// and an unclosed fence stays code to the end of the text.
|
|
148
|
+
const marker = /^ {0,3}(`{3,}|~{3,})/u.exec(line)?.[1];
|
|
149
|
+
if (fence !== null) {
|
|
150
|
+
if (marker !== undefined && marker[0] === fence.char && marker.length >= fence.length)
|
|
151
|
+
fence = null;
|
|
152
|
+
return "";
|
|
153
|
+
}
|
|
154
|
+
if (marker !== undefined) {
|
|
155
|
+
fence = { char: marker[0] ?? "", length: marker.length };
|
|
156
|
+
return "";
|
|
157
|
+
}
|
|
158
|
+
return line.replace(/`[^`\n]*`/gu, "").replace(/^\s*>.*$/u, "");
|
|
159
|
+
});
|
|
160
|
+
const findings = [];
|
|
161
|
+
let block = [];
|
|
162
|
+
let start = 0;
|
|
163
|
+
const flush = () => {
|
|
164
|
+
const tier = block.length > 0 ? blockNegationTier(block) : null;
|
|
165
|
+
if (tier !== null)
|
|
166
|
+
findings.push({ line: start + 1, endLine: start + block.length, severity: tier, rule: NEGATION_CLUSTER });
|
|
167
|
+
block = [];
|
|
168
|
+
};
|
|
169
|
+
for (const [index, line] of lines.entries()) {
|
|
170
|
+
if (line.trim() === "")
|
|
171
|
+
flush();
|
|
172
|
+
else {
|
|
173
|
+
if (block.length === 0)
|
|
174
|
+
start = index;
|
|
175
|
+
block.push(line);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
flush();
|
|
179
|
+
return findings;
|
|
180
|
+
}
|
|
181
|
+
function blockNegationTier(block) {
|
|
182
|
+
if (!block.every((line) => line.trimStart().startsWith("|")))
|
|
183
|
+
return negationTier(block.join("\n"));
|
|
184
|
+
const rows = block
|
|
185
|
+
.filter((line) => !/^[\s|:-]+$/u.test(line))
|
|
186
|
+
.map((line) => line
|
|
187
|
+
.trim()
|
|
188
|
+
.replace(/^\|+|\|+$/gu, "")
|
|
189
|
+
.split("|")
|
|
190
|
+
.map((cell) => cell.trim()));
|
|
191
|
+
const columns = Math.max(0, ...rows.map((row) => row.length));
|
|
192
|
+
let worst = null;
|
|
193
|
+
for (let column = 0; column < columns; column += 1) {
|
|
194
|
+
const cells = rows.map((row) => row[column] ?? "").filter((cell) => [...cell].length > NEGATION_SHORT_CELL);
|
|
195
|
+
const tier = negationTier(cells.join(" "));
|
|
196
|
+
if (tier === "block")
|
|
197
|
+
return tier;
|
|
198
|
+
worst = tier ?? worst;
|
|
199
|
+
}
|
|
200
|
+
return worst;
|
|
201
|
+
}
|
|
103
202
|
function detectorPathFromEnvironment() {
|
|
104
203
|
const pluginRoot = process.env["PLUGIN_ROOT"];
|
|
105
204
|
return pluginRoot ? join(pluginRoot, "skills", "lit-humanizer", "scripts", "detect.mjs") : DEFAULT_DETECTOR;
|
|
@@ -110,7 +209,7 @@ function collectWriteParts(input) {
|
|
|
110
209
|
const tool = input.tool_name.toLowerCase();
|
|
111
210
|
if (tool === "apply_patch") {
|
|
112
211
|
const patch = firstString(input.tool_input, ["command", "patch", "input"]);
|
|
113
|
-
return patch === undefined ? null :
|
|
212
|
+
return patch === undefined ? null : patchParts(patch);
|
|
114
213
|
}
|
|
115
214
|
if (tool === "bash") {
|
|
116
215
|
const command = firstString(input.tool_input, ["command", "cmd"]);
|
|
@@ -130,9 +229,13 @@ function collectWriteParts(input) {
|
|
|
130
229
|
const candidates = Array.isArray(raw) ? raw.filter(isRecord) : [input.tool_input];
|
|
131
230
|
if (candidates.length > MAX_PATHS)
|
|
132
231
|
throw new Error("humanizer path limit exceeded");
|
|
232
|
+
// An edits list may name its file once, beside the list.
|
|
233
|
+
const sharedPath = Array.isArray(raw)
|
|
234
|
+
? firstString(input.tool_input, ["file_path", "path", "filename", "target"])
|
|
235
|
+
: undefined;
|
|
133
236
|
const parts = [];
|
|
134
237
|
for (const candidate of candidates) {
|
|
135
|
-
const path = firstString(candidate, ["file_path", "path", "filename", "target"]);
|
|
238
|
+
const path = firstString(candidate, ["file_path", "path", "filename", "target"]) ?? sharedPath;
|
|
136
239
|
const oldText = firstString(candidate, ["old_string", "oldString", "old_text", "oldText"]);
|
|
137
240
|
const newText = firstString(candidate, ["new_string", "newString", "new_text", "newText"]);
|
|
138
241
|
const text = newText ?? firstString(candidate, ["content", "contents", "text", "file_text"]);
|
|
@@ -141,6 +244,7 @@ function collectWriteParts(input) {
|
|
|
141
244
|
...(path === undefined ? {} : { path }),
|
|
142
245
|
text,
|
|
143
246
|
...(oldText === undefined ? {} : { before: oldText }),
|
|
247
|
+
...(candidate["replace_all"] === true ? { replaceAll: true } : {}),
|
|
144
248
|
});
|
|
145
249
|
}
|
|
146
250
|
if (parts.length === 0)
|
|
@@ -254,41 +358,233 @@ function readAddedOutputText(path, cwd) {
|
|
|
254
358
|
.map((line) => line.slice(1))
|
|
255
359
|
.join("\n");
|
|
256
360
|
}
|
|
257
|
-
|
|
361
|
+
/** Split an apply_patch (or unified diff) into one part per file. A new file carries its whole text. */
|
|
362
|
+
function patchParts(patch) {
|
|
258
363
|
if (Buffer.byteLength(patch, "utf8") > MAX_TEXT_BYTES)
|
|
259
364
|
throw new Error("humanizer patch limit exceeded");
|
|
260
365
|
const writes = [];
|
|
261
366
|
let path;
|
|
262
|
-
let
|
|
367
|
+
let added = null;
|
|
368
|
+
let hunks = [];
|
|
369
|
+
let hunk = null;
|
|
263
370
|
const flush = () => {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
371
|
+
const where = path === undefined ? {} : { path };
|
|
372
|
+
if (added !== null && added.length > 0)
|
|
373
|
+
writes.push({ ...where, text: added.join("\n") });
|
|
374
|
+
const kept = hunks.filter((lines) => lines.some((line) => line.kind === "+"));
|
|
375
|
+
if (kept.length > 0)
|
|
376
|
+
writes.push({ ...where, text: rebuildFromHunks(kept).text, hunks: kept });
|
|
377
|
+
added = null;
|
|
378
|
+
hunks = [];
|
|
379
|
+
hunk = null;
|
|
267
380
|
};
|
|
268
381
|
for (const line of patch.split(/\r?\n/u)) {
|
|
269
|
-
const codex = /^\*\*\* (
|
|
382
|
+
const codex = /^\*\*\* (Update|Add|Delete) File: (.+)$/u.exec(line);
|
|
270
383
|
const unified = /^\+\+\+ b\/(.+)$/u.exec(line);
|
|
271
384
|
if (codex || unified) {
|
|
272
385
|
flush();
|
|
273
|
-
path = (codex?.[
|
|
386
|
+
path = (codex?.[2] ?? unified?.[1])?.trim();
|
|
387
|
+
if (codex?.[1] === "Add")
|
|
388
|
+
added = [];
|
|
389
|
+
}
|
|
390
|
+
else if (/^(?:\*\*\* |diff --git |--- |\+\+\+ |index )/u.test(line))
|
|
391
|
+
hunk = null;
|
|
392
|
+
else if (added !== null) {
|
|
393
|
+
if (line.startsWith("+"))
|
|
394
|
+
added.push(line.slice(1));
|
|
395
|
+
}
|
|
396
|
+
else if (line.startsWith("@@")) {
|
|
397
|
+
hunk = [];
|
|
398
|
+
hunks.push(hunk);
|
|
399
|
+
}
|
|
400
|
+
else if (/^[ +-]/u.test(line) || line === "") {
|
|
401
|
+
if (hunk === null) {
|
|
402
|
+
hunk = [];
|
|
403
|
+
hunks.push(hunk);
|
|
404
|
+
}
|
|
405
|
+
hunk.push({ kind: (line[0] ?? " "), text: line.slice(1) });
|
|
274
406
|
}
|
|
275
|
-
else if (line.startsWith("+") && !line.startsWith("+++"))
|
|
276
|
-
additions.push(line.slice(1));
|
|
277
407
|
}
|
|
278
408
|
flush();
|
|
279
409
|
if (writes.length > MAX_PATHS)
|
|
280
410
|
throw new Error("humanizer path limit exceeded");
|
|
281
411
|
return writes;
|
|
282
412
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
413
|
+
/** Without the file: each hunk's context and added lines, with a blank line where context was cut. */
|
|
414
|
+
function rebuildFromHunks(hunks) {
|
|
415
|
+
const lines = [];
|
|
416
|
+
const changed = new Set();
|
|
417
|
+
for (const [index, hunk] of hunks.entries()) {
|
|
418
|
+
if (index > 0)
|
|
419
|
+
lines.push("");
|
|
420
|
+
for (const line of hunk) {
|
|
421
|
+
if (line.kind === "-")
|
|
422
|
+
continue;
|
|
423
|
+
lines.push(line.text);
|
|
424
|
+
if (line.kind === "+")
|
|
425
|
+
changed.add(lines.length);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
return { text: lines.join("\n"), changed };
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Apply hunks to the current file; null when a hunk does not match. A hunk with only added lines has no anchor,
|
|
432
|
+
* so it goes at the end of the file, before the final newline, where apply_patch puts it.
|
|
433
|
+
*/
|
|
434
|
+
function applyHunks(before, hunks) {
|
|
435
|
+
const lines = before.replace(/\r\n?/gu, "\n").split("\n");
|
|
436
|
+
const out = [];
|
|
437
|
+
const changed = new Set();
|
|
438
|
+
const appended = [];
|
|
439
|
+
let cursor = 0;
|
|
440
|
+
for (const hunk of hunks) {
|
|
441
|
+
const old = hunk.filter((line) => line.kind !== "+").map((line) => line.text.trimEnd());
|
|
442
|
+
if (old.length === 0) {
|
|
443
|
+
appended.push(hunk);
|
|
444
|
+
continue;
|
|
445
|
+
}
|
|
446
|
+
let at = -1;
|
|
447
|
+
for (let start = cursor; at < 0 && start + old.length <= lines.length; start += 1) {
|
|
448
|
+
if (old.every((text, offset) => (lines[start + offset] ?? "").trimEnd() === text))
|
|
449
|
+
at = start;
|
|
450
|
+
}
|
|
451
|
+
if (at < 0)
|
|
452
|
+
return null;
|
|
453
|
+
out.push(...lines.slice(cursor, at));
|
|
454
|
+
for (const line of hunk) {
|
|
455
|
+
if (line.kind === "-")
|
|
456
|
+
continue;
|
|
457
|
+
out.push(line.text);
|
|
458
|
+
if (line.kind === "+")
|
|
459
|
+
changed.add(out.length);
|
|
460
|
+
}
|
|
461
|
+
cursor = at + old.length;
|
|
462
|
+
}
|
|
463
|
+
out.push(...lines.slice(cursor));
|
|
464
|
+
if (appended.length > 0) {
|
|
465
|
+
const finalNewline = out.length > 1 && out[out.length - 1] === "";
|
|
466
|
+
if (finalNewline)
|
|
467
|
+
out.pop();
|
|
468
|
+
for (const line of appended.flat()) {
|
|
469
|
+
out.push(line.text);
|
|
470
|
+
changed.add(out.length);
|
|
471
|
+
}
|
|
472
|
+
if (finalNewline)
|
|
473
|
+
out.push("");
|
|
474
|
+
}
|
|
475
|
+
return { text: out.join("\n"), changed };
|
|
476
|
+
}
|
|
477
|
+
/** Apply an edit's replacement to the current file; null when the old text is not there. */
|
|
478
|
+
function applyEdit(before, part) {
|
|
479
|
+
const file = before.replace(/\r\n?/gu, "\n");
|
|
480
|
+
const from = part.before.replace(/\r\n?/gu, "\n");
|
|
481
|
+
const to = part.text.replace(/\r\n?/gu, "\n");
|
|
482
|
+
if (from.length === 0 || !file.includes(from))
|
|
483
|
+
return null;
|
|
484
|
+
const added = addedLineIndexes(from, to);
|
|
485
|
+
const changed = new Set();
|
|
486
|
+
let text = "";
|
|
487
|
+
let rest = file;
|
|
488
|
+
let index = rest.indexOf(from);
|
|
489
|
+
while (index >= 0) {
|
|
490
|
+
text += rest.slice(0, index);
|
|
491
|
+
const offset = text.split("\n").length;
|
|
492
|
+
for (const line of added)
|
|
493
|
+
changed.add(offset + line);
|
|
494
|
+
text += to;
|
|
495
|
+
rest = rest.slice(index + from.length);
|
|
496
|
+
index = part.replaceAll === true ? rest.indexOf(from) : -1;
|
|
497
|
+
}
|
|
498
|
+
return { text: text + rest, changed };
|
|
499
|
+
}
|
|
500
|
+
/** Edits to one file are applied one after another, as an edits list is; every other write stands alone. */
|
|
501
|
+
function scanUnits(parts, cwd) {
|
|
502
|
+
const edits = new Map();
|
|
503
|
+
const units = [];
|
|
504
|
+
for (const part of parts) {
|
|
505
|
+
const { path, before } = part;
|
|
506
|
+
if (path === undefined || before === undefined || part.hunks !== undefined)
|
|
507
|
+
units.push(scanUnit(part, cwd));
|
|
508
|
+
else
|
|
509
|
+
edits.set(path, [...(edits.get(path) ?? []), { ...part, path, before }]);
|
|
510
|
+
}
|
|
511
|
+
for (const group of edits.values()) {
|
|
512
|
+
const combined = group.length > 1 ? applyEdits(group, cwd) : null;
|
|
513
|
+
units.push(...(combined === null ? group.map((part) => scanUnit(part, cwd)) : [combined]));
|
|
514
|
+
}
|
|
515
|
+
return units;
|
|
516
|
+
}
|
|
517
|
+
/** Every edit applied in order to the current file; null when the file is unreadable or an edit does not apply. */
|
|
518
|
+
function applyEdits(edits, cwd) {
|
|
519
|
+
const first = edits[0];
|
|
520
|
+
const current = first === undefined ? null : readContextText(first.path, cwd);
|
|
521
|
+
if (current === null)
|
|
522
|
+
return null;
|
|
523
|
+
let text = current;
|
|
524
|
+
for (const edit of edits) {
|
|
525
|
+
const applied = applyEdit(text, edit);
|
|
526
|
+
if (applied === null)
|
|
527
|
+
return null;
|
|
528
|
+
text = applied.text;
|
|
529
|
+
}
|
|
530
|
+
try {
|
|
531
|
+
return { text, changed: oneBased(addedLineIndexes(current, text)) };
|
|
532
|
+
}
|
|
533
|
+
catch {
|
|
534
|
+
return null;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* The proposed text of one write, with the lines it changes. An edit or patch is applied to the current file so
|
|
539
|
+
* fences, quotes and blank lines around it keep their meaning; without the file, the edit or hunks stand alone.
|
|
540
|
+
*/
|
|
541
|
+
function scanUnit(part, cwd) {
|
|
542
|
+
if (part.hunks !== undefined) {
|
|
543
|
+
const current = part.path === undefined ? null : readContextText(part.path, cwd);
|
|
544
|
+
return (current === null ? null : applyHunks(current, part.hunks)) ?? rebuildFromHunks(part.hunks);
|
|
545
|
+
}
|
|
546
|
+
if (part.before !== undefined) {
|
|
547
|
+
const current = part.path === undefined ? null : readContextText(part.path, cwd);
|
|
548
|
+
const applied = current === null ? null : applyEdit(current, { ...part, before: part.before });
|
|
549
|
+
return applied ?? { text: part.text, changed: oneBased(addedLineIndexes(part.before, part.text)) };
|
|
550
|
+
}
|
|
286
551
|
if (part.path === undefined)
|
|
287
|
-
return part.text;
|
|
552
|
+
return { text: part.text, changed: null };
|
|
288
553
|
const before = readSafeExistingText(part.path, cwd);
|
|
289
|
-
return before === null
|
|
554
|
+
return before === null
|
|
555
|
+
? { text: part.text, changed: null }
|
|
556
|
+
: { text: part.text, changed: oneBased(addedLineIndexes(before, part.text)) };
|
|
557
|
+
}
|
|
558
|
+
/** The current file as context for an edit, or null when it cannot be read safely or is too large to scan. */
|
|
559
|
+
function readContextText(path, cwd) {
|
|
560
|
+
try {
|
|
561
|
+
const text = readSafeExistingText(path, cwd);
|
|
562
|
+
return text === null || Buffer.byteLength(text, "utf8") > MAX_TEXT_BYTES ? null : text;
|
|
563
|
+
}
|
|
564
|
+
catch {
|
|
565
|
+
return null;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
function oneBased(indexes) {
|
|
569
|
+
return new Set(indexes.map((index) => index + 1));
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* A negation-cluster finding covers its whole block. A detector finding is its matched occurrences: for a
|
|
573
|
+
* document-scope repeat rule, the first and the last, so an edit between two old occurrences does not count.
|
|
574
|
+
*/
|
|
575
|
+
function touchesChangedLine(finding, changed) {
|
|
576
|
+
if (changed === null)
|
|
577
|
+
return true;
|
|
578
|
+
const end = finding.endLine ?? finding.line;
|
|
579
|
+
if (finding.rule !== NEGATION_CLUSTER)
|
|
580
|
+
return changed.has(finding.line) || changed.has(end);
|
|
581
|
+
for (let line = finding.line; line <= end; line += 1)
|
|
582
|
+
if (changed.has(line))
|
|
583
|
+
return true;
|
|
584
|
+
return false;
|
|
290
585
|
}
|
|
291
|
-
|
|
586
|
+
/** Zero-based indexes of the lines in `after` that a line diff against `before` marks as added. */
|
|
587
|
+
function addedLineIndexes(before, after) {
|
|
292
588
|
if (Buffer.byteLength(before, "utf8") + Buffer.byteLength(after, "utf8") > MAX_TEXT_BYTES)
|
|
293
589
|
throw new Error("humanizer diff limit exceeded");
|
|
294
590
|
const oldLines = before.replace(/\r\n?/gu, "\n").split("\n");
|
|
@@ -316,26 +612,71 @@ function addedLines(before, after) {
|
|
|
316
612
|
else if (valueAt(i + 1, j) >= valueAt(i, j + 1))
|
|
317
613
|
i += 1;
|
|
318
614
|
else {
|
|
319
|
-
|
|
320
|
-
if (added !== undefined)
|
|
321
|
-
additions.push(added);
|
|
615
|
+
additions.push(j);
|
|
322
616
|
j += 1;
|
|
323
617
|
}
|
|
324
618
|
}
|
|
325
619
|
while (j < newLines.length) {
|
|
326
|
-
|
|
327
|
-
if (added !== undefined)
|
|
328
|
-
additions.push(added);
|
|
620
|
+
additions.push(j);
|
|
329
621
|
j += 1;
|
|
330
622
|
}
|
|
331
|
-
return additions
|
|
623
|
+
return additions;
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* The session project. Codex reports the session cwd in the hook payload and sets no project variable for hooks,
|
|
627
|
+
* so the project is the git work tree above that cwd, or the cwd itself outside git.
|
|
628
|
+
*/
|
|
629
|
+
function projectRoot(cwd) {
|
|
630
|
+
const base = realpathSync(cwd);
|
|
631
|
+
for (let dir = base;; dir = dirname(dir)) {
|
|
632
|
+
if (existsSync(join(dir, ".git")))
|
|
633
|
+
return dir;
|
|
634
|
+
if (dirname(dir) === dir)
|
|
635
|
+
return base;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
/** True when the path lies inside the project. Host config, temp notes and other files outside it are not judged. */
|
|
639
|
+
function isInside(project, path, cwd) {
|
|
640
|
+
const full = isAbsolute(path) ? resolve(path) : resolve(realpathSync(cwd), path);
|
|
641
|
+
// Resolve the nearest existing folder, so /tmp and /private/tmp compare as one place. The file itself is not
|
|
642
|
+
// followed: a symlink in the project stays in the project, where the read refuses it.
|
|
643
|
+
const rest = [basename(full)];
|
|
644
|
+
let target = dirname(full);
|
|
645
|
+
for (;;) {
|
|
646
|
+
try {
|
|
647
|
+
target = join(realpathSync(target), ...rest);
|
|
648
|
+
break;
|
|
649
|
+
}
|
|
650
|
+
catch (error) {
|
|
651
|
+
if (error.code !== "ENOENT" || dirname(target) === target)
|
|
652
|
+
throw error;
|
|
653
|
+
rest.unshift(basename(target));
|
|
654
|
+
target = dirname(target);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
const relativePath = relative(project, target);
|
|
658
|
+
return relativePath !== ".." && !relativePath.startsWith(`..${sep}`) && !isAbsolute(relativePath);
|
|
332
659
|
}
|
|
333
660
|
function readSafeExistingText(path, cwd) {
|
|
334
|
-
const
|
|
335
|
-
const target = isAbsolute(path) ? resolve(path) : resolve(
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
661
|
+
const base = realpathSync(cwd);
|
|
662
|
+
const target = isAbsolute(path) ? resolve(path) : resolve(base, path);
|
|
663
|
+
let root = base;
|
|
664
|
+
let relativePath = relative(root, target);
|
|
665
|
+
if (relativePath === "")
|
|
666
|
+
throw new Error("target is the cwd");
|
|
667
|
+
if (relativePath === ".." || relativePath.startsWith(`..${sep}`) || isAbsolute(relativePath)) {
|
|
668
|
+
// The host reports the shell's cwd, which is a subfolder after `cd`. A file above it is still judged:
|
|
669
|
+
// it is read from its own folder, and the file itself is still refused when it is a symlink.
|
|
670
|
+
try {
|
|
671
|
+
root = realpathSync(dirname(target));
|
|
672
|
+
}
|
|
673
|
+
catch (error) {
|
|
674
|
+
if (error.code === "ENOENT")
|
|
675
|
+
return null;
|
|
676
|
+
throw error;
|
|
677
|
+
}
|
|
678
|
+
relativePath = basename(target);
|
|
679
|
+
}
|
|
339
680
|
let current = root;
|
|
340
681
|
const segments = relativePath.split(sep);
|
|
341
682
|
for (const [index, segment] of segments.entries()) {
|
|
@@ -445,12 +786,13 @@ function findingsOutput(event, findings, files) {
|
|
|
445
786
|
.map((item) => `${item.severity} ${item.rule} line ${item.line}`)
|
|
446
787
|
.join("; ");
|
|
447
788
|
const rebuild = event === "PostToolUse" && blocks.length > 0 ? "Fix the changed passages and rebuild the artifact. " : "";
|
|
448
|
-
const
|
|
789
|
+
const negation = findings.some((item) => item.rule === NEGATION_CLUSTER) ? `${NEGATION_NOTE} ` : "";
|
|
790
|
+
const context = `LIT_HUMANIZER findings=${findings.length} files=${files} block=${blocks.length} warn=${warnings.length}. ${rebuild}Warnings are advisory; preserve meaning and voice. ${negation}${detail}`.slice(0, 1800);
|
|
449
791
|
const hookSpecificOutput = { hookEventName: event, additionalContext: context };
|
|
450
792
|
if (event === "PreToolUse" && blocks.length > 0) {
|
|
451
793
|
hookSpecificOutput["permissionDecision"] = "deny";
|
|
452
794
|
hookSpecificOutput["permissionDecisionReason"] =
|
|
453
|
-
`lit-humanizer blocked ${blocks.length} high-confidence drafting residue hit(s): ${blockedRuleSummary(blocks)}. Rewrite those lines and retry
|
|
795
|
+
`lit-humanizer blocked ${blocks.length} high-confidence drafting residue hit(s): ${blockedRuleSummary(blocks)}. Rewrite those lines and retry.${blocks.some((item) => item.rule === NEGATION_CLUSTER) ? ` ${NEGATION_NOTE}` : ""}`;
|
|
454
796
|
}
|
|
455
797
|
return JSON.stringify({ hookSpecificOutput });
|
|
456
798
|
}
|
|
@@ -137,6 +137,10 @@ Load only what the task needs:
|
|
|
137
137
|
|
|
138
138
|
`rules.json` is the source for the dependency-free Node detector and its rule IDs, tiers, exemptions, and caption context. Run `node scripts/test-fixtures.mjs` for rule cases and `node scripts/test-ko-metrics.mjs` for Korean metric goldens. The metric is an optional review aid, not a quality score. Local negative-corpus material is excluded from packages and commits.
|
|
139
139
|
|
|
140
|
+
Write positive-first. Name what a figure or thing is, then attach a needed caveat once. `18,420회는 주민 수가 아님. 고유 방문자 수도 아님.` leaves the reader guessing; "18,420회는 같은 사람의 반복 방문을 포함한 방문 횟수 합계입니다" tells them. A real gap still gets one plain line, such as "고유 이용자 지표는 자료에 없습니다".
|
|
141
|
+
|
|
142
|
+
The Codex write guard runs a `negation-cluster` check beside the detector. It counts definitional negations in each paragraph, list block, or Markdown table column: the plain forms (`아닙니다`, `아님`, `아니다`, `아니며`, `아니라`, `아닌`; `is not`, `are not`, `not a`, `rather than`) and the reworded forms that say the same thing (`~로 읽을 수 없음`, `~로 볼 수 없음`, `~로 보지 않음`, `~을 뜻하지 않음`, `~와는 다르다`, `~로 읽으면 안 된다`; `should not be read as`, `does not mean`). Two Korean hits in one block, or three in any mix of languages, refuse the write, and the refusal carries the rewrite advice. Exactly two hits that are mixed or English warn and let the write through. Trading `아님` for `~로 읽을 수 없음`, `~와는 다르다` or `~로 읽으면 안 된다` still counts, so rewrite the block to state the thing itself. Table cells of 12 characters or fewer, code, inline code, quote lines, and internal records stay exempt; that is why a bad example in this skill sits in inline code or a blockquote.
|
|
143
|
+
|
|
140
144
|
## Korean deep review
|
|
141
145
|
|
|
142
146
|
Use the existing Korean review agents when the host exposes them: `style-analyzer` notes register and cadence; `prose-editor` revises without changing claims; `meaning-preservation-auditor` checks facts, modality, numbers, names, and quotes; `native-flow-reviewer` checks idiom and rhythm; `polish-orchestrator` resolves evidenced findings and runs the final detector. Limit this to two review rounds. If agent surfaces are unavailable, follow the same sequence directly; never invent unsupported agent APIs.
|
|
@@ -200,11 +200,15 @@ export function scanText(text, rules, file = '<stdin>') {
|
|
|
200
200
|
rule.regex.lastIndex = 0;
|
|
201
201
|
const match = rule.regex.exec(segment.text);
|
|
202
202
|
if (!match) continue;
|
|
203
|
+
const line = lineAtOffset(segment, match.index);
|
|
204
|
+
// A match that spans lines (a repeat rule's first and last occurrence) also names its last line.
|
|
205
|
+
const endLine = lineAtOffset(segment, match.index + Math.max(0, match[0].length - 1));
|
|
203
206
|
findings.push({
|
|
204
207
|
file,
|
|
205
208
|
rule: rule.id,
|
|
206
209
|
severity: rule.severity,
|
|
207
|
-
line
|
|
210
|
+
line,
|
|
211
|
+
...(endLine > line ? { endLine } : {}),
|
|
208
212
|
excerpt: segment.text.trim().replace(/\s+/g, ' ').slice(0, 180),
|
|
209
213
|
});
|
|
210
214
|
}
|
|
@@ -265,7 +265,8 @@ After the scope gate selects the durable path:
|
|
|
265
265
|
The bare `lit` trigger (also `lit-loop` / `litcodex` in a prompt) fires the Codex
|
|
266
266
|
`UserPromptSubmit` hook, which injects the `<lit-loop-mode>` directive into the turn. This skill is
|
|
267
267
|
the operational expansion of that directive: once you see `<lit-loop-mode>`, apply the scope gate
|
|
268
|
-
above, then follow the selected path.
|
|
268
|
+
above, then follow the selected path. A user who wants to watch the run from a terminal can keep the LIT card
|
|
269
|
+
live in a second window with `litcodex hud`, which only reads the records these hooks already write.
|
|
269
270
|
|
|
270
271
|
## Codex tool mapping
|
|
271
272
|
|
|
@@ -34,12 +34,17 @@ export interface Usage {
|
|
|
34
34
|
readonly fiveHour: number | null;
|
|
35
35
|
readonly week: number | null;
|
|
36
36
|
}
|
|
37
|
-
/** The workspace a thread runs in: the hook pointer, else the rollout header; null when unknown. */
|
|
38
|
-
export declare function resolveThreadCwd(threadId: string | null, env: NodeJS.ProcessEnv): string | null;
|
|
37
|
+
/** The workspace a thread runs in: the hook pointer, else (when `rollout` allows) the rollout header; null when unknown. */
|
|
38
|
+
export declare function resolveThreadCwd(threadId: string | null, env: NodeJS.ProcessEnv, rollout?: boolean): string | null;
|
|
39
39
|
/** Context and quota use from the newest token count in a rollout tail; null when there is none. */
|
|
40
40
|
export declare function usageFromRollout(text: string): Usage | null;
|
|
41
41
|
/** A tool name as the card shows it: an MCP tool reads `server · tool` rather than its joined id. */
|
|
42
42
|
export declare function toolDisplayName(tool: string): string;
|
|
43
|
-
|
|
43
|
+
/** The card for one thread. `rollout: false` keeps every Codex rollout file unread; the usage row then stays empty. */
|
|
44
|
+
export declare function readCardStatus(threadId: string | null, env: NodeJS.ProcessEnv, now?: number, options?: {
|
|
45
|
+
readonly rollout?: boolean;
|
|
46
|
+
}): CardStatus;
|
|
47
|
+
/** Minutes and seconds, `m:ss`. */
|
|
48
|
+
export declare function clock(ms: number): string;
|
|
44
49
|
/** The card as plain text, for hosts that cannot draw it (the terminal `codex`). */
|
|
45
50
|
export declare function cardStatusText(status: CardStatus): string;
|