@litfamily/litcodex 1.0.27 → 1.0.29
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 +10 -10
- package/README.md +10 -10
- package/dist/cli.d.ts +3 -2
- package/dist/cli.js +73 -4
- package/dist/config-migration/cli.js +11 -3
- package/dist/install/generated-skill-payload-hashes.d.ts +58 -30
- package/dist/install/generated-skill-payload-hashes.js +58 -30
- package/dist/install/index.js +1 -1
- package/dist/install/motion-runtime.d.ts +4 -1
- package/dist/install/motion-runtime.js +15 -4
- package/dist/install/office-runtime.d.ts +10 -11
- package/dist/install/office-runtime.js +8 -3
- package/dist/install/skill-catalog.d.ts +1 -1
- package/dist/install/skill-catalog.js +1 -0
- package/dist/postinstall.js +16 -3
- 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/dist/auto-update.d.ts +12 -0
- package/marketplace/plugins/litcodex/components/auto-update/dist/auto-update.js +31 -2
- 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/directive.md +2 -1
- package/marketplace/plugins/litcodex/components/lit-loop/directives/deep-interview.md +2 -0
- package/marketplace/plugins/litcodex/components/lit-loop/directives/lit-brainstorm.md +216 -0
- package/marketplace/plugins/litcodex/components/lit-loop/directives/litgoal.md +8 -1
- package/marketplace/plugins/litcodex/components/lit-loop/directives/review-work.md +12 -4
- 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/codex-hook.d.ts +6 -1
- package/marketplace/plugins/litcodex/components/lit-loop/dist/codex-hook.js +16 -5
- package/marketplace/plugins/litcodex/components/lit-loop/dist/guards.d.ts +3 -1
- package/marketplace/plugins/litcodex/components/lit-loop/dist/guards.js +5 -2
- package/marketplace/plugins/litcodex/components/lit-loop/dist/hook-cli.d.ts +2 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/hook-cli.js +53 -17
- 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/markers.d.ts +2 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/markers.js +2 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/modes.d.ts +1 -1
- package/marketplace/plugins/litcodex/components/lit-loop/dist/modes.js +9 -1
- package/marketplace/plugins/litcodex/components/lit-loop/dist/motion-route.js +2 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/plan-persistence.d.ts +2 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/plan-persistence.js +8 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/reentry.d.ts +56 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/reentry.js +171 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/route-context.js +5 -2
- package/marketplace/plugins/litcodex/components/lit-loop/dist/route-heads.js +35 -15
- 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/skill-mention-scope.js +2 -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/trigger.d.ts +2 -2
- package/marketplace/plugins/litcodex/components/lit-loop/dist/trigger.js +15 -5
- 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 +59 -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/dist/model-metadata.d.ts +16 -0
- package/marketplace/plugins/litcodex/components/rules/dist/model-metadata.js +37 -1
- 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/browser-drive/scripts/capability-probe.mjs +24 -4
- package/marketplace/plugins/litcodex/skills/deep-interview/SKILL.md +3 -1
- package/marketplace/plugins/litcodex/skills/lit-brainstorm/SKILL.md +271 -0
- package/marketplace/plugins/litcodex/skills/lit-brainstorm/agents/openai.yaml +6 -0
- package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/scripts/doctor.mjs +4 -3
- package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/scripts/export.mjs +6 -5
- package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/scripts/runtime-probes.mjs +25 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/scripts/convert_md_to_pdf.py +31 -1
- package/marketplace/plugins/litcodex/skills/lit-docx/templates/latex/acs/template.tex +2 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/templates/latex/elsevier/template.tex +2 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/templates/latex/ieee/template.tex +2 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/templates/latex/korean-generic/template.tex +2 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/templates/latex/nature/template.tex +2 -0
- 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 +10 -2
- package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/office-run.mjs +42 -10
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/SKILL.md +11 -9
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/agents/openai.yaml +3 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/THIRD_PARTY_NOTICES +4 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/constants.mjs +38 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-assets.mjs +113 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-capture.mjs +161 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-gate.mjs +327 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-image.mjs +136 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-init.js +43 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-sheet.mjs +69 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-treatment.mjs +102 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-worker.mjs +21 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover.mjs +352 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/driver.mjs +19 -1
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/fonts.mjs +11 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/look.mjs +128 -2
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/loop-kit.js +104 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/runtime.mjs +92 -18
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/stage.mjs +2 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/treatment.mjs +3 -2
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/webp.mjs +140 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/fonts/jetbrains-mono/JetBrainsMono-wght-latin.woff2 +0 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/fonts/jetbrains-mono/OFL.txt +93 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/card-scenes/expected.json +16 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/card-scenes/index.html +42 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/reset-sweep/expected.json +16 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/reset-sweep/index.html +27 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/still-glow/expected.json +17 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/still-glow/index.html +29 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/title-slam/expected.json +17 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/title-slam/index.html +44 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/orbit-loop/expected.json +67 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/orbit-loop/index.html +182 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/painted-light/expected.json +95 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/painted-light/index.html +231 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/weight-tide/expected.json +67 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/weight-tide/index.html +103 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/cover.md +389 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/quality-gate.md +4 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/runtime.md +7 -6
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/stage.md +3 -1
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/treatment.md +2 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/scripts/render.mjs +37 -5
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/scripts/runtime.mjs +1 -1
- package/marketplace/plugins/litcodex/skills/litgoal/SKILL.md +8 -3
- package/marketplace/plugins/litcodex/skills/lsp-setup/scripts/verify-lsp.ts +43 -7
- package/marketplace/plugins/litcodex/skills/review-work/SKILL.md +21 -4
- package/node_modules/@litcodex/lit-loop/CHANGELOG.md +7 -0
- package/node_modules/@litcodex/lit-loop/README.md +6 -0
- package/node_modules/@litcodex/lit-loop/directive.md +2 -1
- package/node_modules/@litcodex/lit-loop/directives/deep-interview.md +2 -0
- package/node_modules/@litcodex/lit-loop/directives/lit-brainstorm.md +216 -0
- package/node_modules/@litcodex/lit-loop/directives/litgoal.md +8 -1
- package/node_modules/@litcodex/lit-loop/directives/review-work.md +12 -4
- 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/codex-hook.d.ts +6 -1
- package/node_modules/@litcodex/lit-loop/dist/codex-hook.js +16 -5
- package/node_modules/@litcodex/lit-loop/dist/guards.d.ts +3 -1
- package/node_modules/@litcodex/lit-loop/dist/guards.js +5 -2
- package/node_modules/@litcodex/lit-loop/dist/hook-cli.d.ts +2 -0
- package/node_modules/@litcodex/lit-loop/dist/hook-cli.js +53 -17
- 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/markers.d.ts +2 -0
- package/node_modules/@litcodex/lit-loop/dist/markers.js +2 -0
- package/node_modules/@litcodex/lit-loop/dist/modes.d.ts +1 -1
- package/node_modules/@litcodex/lit-loop/dist/modes.js +9 -1
- package/node_modules/@litcodex/lit-loop/dist/motion-route.js +2 -0
- package/node_modules/@litcodex/lit-loop/dist/plan-persistence.d.ts +2 -0
- package/node_modules/@litcodex/lit-loop/dist/plan-persistence.js +8 -0
- package/node_modules/@litcodex/lit-loop/dist/reentry.d.ts +56 -0
- package/node_modules/@litcodex/lit-loop/dist/reentry.js +171 -0
- package/node_modules/@litcodex/lit-loop/dist/route-context.js +5 -2
- package/node_modules/@litcodex/lit-loop/dist/route-heads.js +35 -15
- 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/skill-mention-scope.js +2 -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/trigger.d.ts +2 -2
- package/node_modules/@litcodex/lit-loop/dist/trigger.js +15 -5
- package/node_modules/@litcodex/lit-loop/dist/workflow-map.d.ts +7 -0
- package/node_modules/@litcodex/lit-loop/dist/workflow-map.js +59 -10
- package/node_modules/@litcodex/lit-loop/package.json +1 -1
- package/node_modules/@litcodex/lit-loop/skills/browser-drive/scripts/capability-probe.mjs +24 -4
- package/node_modules/@litcodex/lit-loop/skills/deep-interview/SKILL.md +3 -1
- package/node_modules/@litcodex/lit-loop/skills/lit-brainstorm/SKILL.md +271 -0
- 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 +10 -2
- package/node_modules/@litcodex/lit-loop/skills/litgoal/SKILL.md +8 -3
- package/node_modules/@litcodex/lit-loop/skills/review-work/SKILL.md +21 -4
- package/package.json +5 -2
- package/readme-assets/badge-version.svg +1 -1
- package/readme-assets/cover-motion-still.webp +0 -0
- package/readme-assets/cover-motion.webp +0 -0
- package/readme-assets/cover.webp +0 -0
- package/readme-assets/litfamily-machines.png +0 -0
- package/readme-assets/skills/lit-brainstorm.webp +0 -0
|
@@ -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
|
}
|
|
@@ -13,3 +13,19 @@ export declare function resetModelMetadataCacheForTests(): void;
|
|
|
13
13
|
export declare function resolveModelMetadata(model: string, structuredCatalog?: string): ModelMetadataResult;
|
|
14
14
|
export type ManagedModelSlug = "gpt-6-astra" | "gpt-6.1-sol" | "gpt-6-sol" | "gpt-6-luna" | "gpt-5.6" | "gpt-5.6-sol" | "gpt-5.6-terra" | "gpt-5.6-luna";
|
|
15
15
|
export declare function managedGpt56Slug(model: string): ManagedModelSlug | null;
|
|
16
|
+
export interface ShellFreeCommand {
|
|
17
|
+
readonly command: string;
|
|
18
|
+
readonly args: readonly string[];
|
|
19
|
+
}
|
|
20
|
+
export interface ShellFreeOptions {
|
|
21
|
+
readonly env?: NodeJS.ProcessEnv;
|
|
22
|
+
readonly platform?: NodeJS.Platform;
|
|
23
|
+
readonly exists?: (file: string) => boolean;
|
|
24
|
+
readonly read?: (file: string) => string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* How to spawn a user-installed CLI without a shell. On Windows npm installs Codex as a codex.cmd
|
|
28
|
+
* shim, which Node refuses to spawn without a shell (CVE-2024-27980) and a bare "codex" never finds,
|
|
29
|
+
* so the shim is unwrapped to the script or binary it launches; no argument passes through cmd.exe.
|
|
30
|
+
*/
|
|
31
|
+
export declare function shellFreeCommand(name: string, args: readonly string[], { env, platform, exists, read, }?: ShellFreeOptions): ShellFreeCommand;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { win32 } from "node:path";
|
|
2
4
|
let memoizedCatalog;
|
|
3
5
|
export function resetModelMetadataCacheForTests() {
|
|
4
6
|
memoizedCatalog = undefined;
|
|
@@ -96,7 +98,15 @@ function readCatalogOnce() {
|
|
|
96
98
|
if (memoizedCatalog !== undefined) {
|
|
97
99
|
return memoizedCatalog;
|
|
98
100
|
}
|
|
99
|
-
|
|
101
|
+
let codex;
|
|
102
|
+
try {
|
|
103
|
+
codex = shellFreeCommand("codex", ["debug", "models"]);
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
memoizedCatalog = null;
|
|
107
|
+
return memoizedCatalog;
|
|
108
|
+
}
|
|
109
|
+
const result = spawnSync(codex.command, [...codex.args], {
|
|
100
110
|
encoding: "utf8",
|
|
101
111
|
timeout: 750,
|
|
102
112
|
maxBuffer: 2 * 1024 * 1024,
|
|
@@ -105,6 +115,32 @@ function readCatalogOnce() {
|
|
|
105
115
|
memoizedCatalog = result.status === 0 && result.error === undefined ? result.stdout : null;
|
|
106
116
|
return memoizedCatalog;
|
|
107
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* How to spawn a user-installed CLI without a shell. On Windows npm installs Codex as a codex.cmd
|
|
120
|
+
* shim, which Node refuses to spawn without a shell (CVE-2024-27980) and a bare "codex" never finds,
|
|
121
|
+
* so the shim is unwrapped to the script or binary it launches; no argument passes through cmd.exe.
|
|
122
|
+
*/
|
|
123
|
+
export function shellFreeCommand(name, args, { env = process.env, platform = process.platform, exists = existsSync, read = (file) => readFileSync(file, "utf8"), } = {}) {
|
|
124
|
+
if (platform !== "win32")
|
|
125
|
+
return { command: name, args };
|
|
126
|
+
const extensions = (env["PATHEXT"] || ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean);
|
|
127
|
+
const found = (env["PATH"] ?? env["Path"] ?? "")
|
|
128
|
+
.split(";")
|
|
129
|
+
.filter(Boolean)
|
|
130
|
+
.flatMap((dir) => extensions.map((ext) => win32.join(dir, name + ext)))
|
|
131
|
+
.find((file) => exists(file));
|
|
132
|
+
if (found === undefined)
|
|
133
|
+
return { command: name, args };
|
|
134
|
+
if (!/\.(?:cmd|bat)$/iu.test(found))
|
|
135
|
+
return { command: found, args };
|
|
136
|
+
const target = [...read(found).matchAll(/"%~?dp0%?\\([^"\r\n]+)"\s+%\*/gu)].at(-1)?.[1];
|
|
137
|
+
if (target === undefined)
|
|
138
|
+
throw new Error(`${found} is not an npm shim; it cannot be run without a shell`);
|
|
139
|
+
const resolved = win32.join(win32.dirname(found), target);
|
|
140
|
+
return /\.[cm]?js$/iu.test(resolved)
|
|
141
|
+
? { command: process.execPath, args: [resolved, ...args] }
|
|
142
|
+
: { command: resolved, args };
|
|
143
|
+
}
|
|
108
144
|
function isRecord(value) {
|
|
109
145
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
110
146
|
}
|