dislop 0.9.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +3 -3
- package/.claude-plugin/plugin.json +2 -2
- package/.codex-plugin/plugin.json +7 -8
- package/.cursor-plugin/plugin.json +2 -3
- package/.pre-commit-hooks.yaml +5 -12
- package/PRODUCT.md +19 -63
- package/README.md +358 -249
- package/README.zh-CN.md +391 -237
- package/action.yml +30 -39
- package/bin/dislop-mcp.mjs +3 -4
- package/bin/dislop.mjs +4 -4594
- package/gemini-extension.json +2 -2
- package/llms-install.md +68 -0
- package/package.json +17 -63
- package/packs/common/artifact-qa/pack.json +5 -0
- package/packs/common/artifact-qa/prompts/rules.md +11 -0
- package/packs/common/artifact-qa/scripts/index.mjs +235 -0
- package/packs/common/slide-deck/pack.json +6 -0
- package/packs/common/slide-deck/prompts/rules.md +11 -0
- package/packs/common/slide-deck/scripts/index.mjs +62 -0
- package/packs/common/web-ui/pack.json +6 -0
- package/packs/common/web-ui/prompts/rules.md +11 -0
- package/packs/common/web-ui/scripts/index.mjs +80 -0
- package/packs/en/artifact-qa/pack.json +6 -0
- package/packs/en/artifact-qa/prompts/rules.md +14 -0
- package/packs/en/artifact-qa/scripts/index.mjs +90 -0
- package/packs/en/prose/pack.json +7 -0
- package/packs/en/prose/prompts/rules.md +26 -0
- package/packs/en/prose/scripts/index.mjs +293 -0
- package/packs/en/slide-deck/pack.json +7 -0
- package/packs/en/slide-deck/prompts/rules.md +17 -0
- package/packs/en/slide-deck/scripts/index.mjs +81 -0
- package/packs/en/web-ui/pack.json +7 -0
- package/packs/en/web-ui/prompts/rules.md +20 -0
- package/packs/en/web-ui/scripts/index.mjs +103 -0
- package/packs/zh/artifact-qa/pack.json +6 -0
- package/packs/zh/artifact-qa/prompts/rules.md +14 -0
- package/packs/zh/artifact-qa/scripts/index.mjs +89 -0
- package/packs/zh/prose/pack.json +7 -0
- package/packs/zh/prose/prompts/rules.md +26 -0
- package/packs/zh/prose/scripts/index.mjs +305 -0
- package/packs/zh/slide-deck/pack.json +7 -0
- package/packs/zh/slide-deck/prompts/rules.md +17 -0
- package/packs/zh/slide-deck/scripts/index.mjs +75 -0
- package/packs/zh/web-ui/pack.json +7 -0
- package/packs/zh/web-ui/prompts/rules.md +20 -0
- package/packs/zh/web-ui/scripts/index.mjs +98 -0
- package/plugin.json +5 -6
- package/server.json +2 -2
- package/skills/deslop-docs/SKILL.md +10 -8
- package/skills/deslop-slides-docx/SKILL.md +7 -8
- package/skills/deslop-verify/SKILL.md +7 -8
- package/skills/deslop-web-ui/SKILL.md +7 -8
- package/skills/dislop/SKILL.md +16 -28
- package/skills/dislop/agents/openai.yaml +1 -1
- package/skills/dislop/references/essay.md +6 -6
- package/skills/dislop/references/essay.zh-CN.md +6 -6
- package/skills/dislop/references/office.md +5 -5
- package/skills/dislop/references/office.zh-CN.md +5 -5
- package/skills/dislop/references/web-ui.md +4 -4
- package/skills/dislop/references/web-ui.zh-CN.md +4 -4
- package/skills/dislop/references/work-docs.md +7 -7
- package/skills/dislop/references/work-docs.zh-CN.md +7 -7
- package/src/cli-main.mjs +292 -0
- package/src/commands/check-fix.mjs +324 -0
- package/src/commands/doctor.mjs +132 -0
- package/src/commands/init.mjs +55 -0
- package/src/commands/login.mjs +82 -0
- package/src/commands/model.mjs +130 -0
- package/src/commands/packs.mjs +81 -0
- package/src/commands/verify.mjs +165 -0
- package/src/commands/voice.mjs +84 -0
- package/src/commands/worklog.mjs +424 -0
- package/src/kernel/config.mjs +759 -0
- package/src/kernel/document-model.mjs +1432 -0
- package/src/kernel/fact-gate.mjs +775 -0
- package/src/kernel/file-discovery.mjs +296 -0
- package/src/{binary-node.mjs → kernel/ooxml-binary.mjs} +615 -890
- package/src/kernel/pack-loader.mjs +801 -0
- package/src/kernel/pack-validator.mjs +491 -0
- package/src/kernel/patcher.mjs +471 -0
- package/src/kernel/pipeline.mjs +530 -0
- package/src/kernel/prompt-assembler.mjs +336 -0
- package/src/kernel/version.mjs +7 -0
- package/src/kernel/voice-profile.mjs +180 -0
- package/src/mcp/stdio-server.mjs +442 -0
- package/src/runners/auto-fix.mjs +74 -0
- package/src/runners/interactive-tty.mjs +488 -0
- package/src/runners/reporters.mjs +272 -0
- package/src/runtime/chunker.mjs +87 -0
- package/src/runtime/json-extract.mjs +144 -0
- package/src/runtime/privacy-gate.mjs +97 -0
- package/src/runtime/providers/anthropic.mjs +65 -0
- package/src/runtime/providers/cloud.mjs +138 -0
- package/src/runtime/providers/gemini.mjs +91 -0
- package/src/runtime/providers/local-model.mjs +147 -0
- package/src/runtime/providers/openai-compat.mjs +130 -0
- package/src/runtime/router.mjs +324 -0
- package/src/runtime/worklog.mjs +904 -0
- package/src/sdk/index.mjs +137 -0
- package/models/manifest.json +0 -90
- package/models/pocket-slop-v1.json +0 -1
- package/packs/business-brief/pack.json +0 -937
- package/packs/core/pack.json +0 -209
- package/packs/deck-and-ui/pack.json +0 -539
- package/packs/engineering-spec/pack.json +0 -144
- package/packs/executive-deck/pack.json +0 -98
- package/packs/literary-essay/pack.json +0 -344
- package/packs/regulated-comms/pack.json +0 -99
- package/patterns/ai-tic-rubric.json +0 -252
- package/patterns/banks/composite-fusion.json +0 -48
- package/patterns/banks/discourse-rhythm.json +0 -95
- package/patterns/banks/lexical-signals.json +0 -92
- package/patterns/banks/syntactic-frames.json +0 -52
- package/patterns/banks/visual-deck.json +0 -44
- package/patterns/dimensions/artifacts.json +0 -121
- package/patterns/dimensions/discourse.json +0 -438
- package/patterns/dimensions/lexical.json +0 -198
- package/patterns/dimensions/rhythm.json +0 -258
- package/patterns/dimensions/syntactic.json +0 -285
- package/patterns/dimensions/visual-and-deck.json +0 -530
- package/patterns/taxonomy.json +0 -112
- package/src/core.mjs +0 -5497
- package/src/dislop/review-picker.vim +0 -114
- package/src/local-model.mjs +0 -997
- package/src/pattern-engine.mjs +0 -1003
- package/src/pocket-model.mjs +0 -729
- package/src/review-apply.mjs +0 -151
- package/src/review-client.mjs +0 -1073
package/src/cli-main.mjs
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import { runCheckCommand, runFixCommand } from "./commands/check-fix.mjs";
|
|
3
|
+
import { runDoctorCommand } from "./commands/doctor.mjs";
|
|
4
|
+
import { runInitCommand } from "./commands/init.mjs";
|
|
5
|
+
import { runLoginCommand, runLogoutCommand } from "./commands/login.mjs";
|
|
6
|
+
import { runModelCommand } from "./commands/model.mjs";
|
|
7
|
+
import { runPacksCommand } from "./commands/packs.mjs";
|
|
8
|
+
import { runVerifyCommand } from "./commands/verify.mjs";
|
|
9
|
+
import { runVoiceCommand } from "./commands/voice.mjs";
|
|
10
|
+
import { runWorklogCommand } from "./commands/worklog.mjs";
|
|
11
|
+
import { DislopConfigError } from "./kernel/config.mjs";
|
|
12
|
+
import { DISLOP_VERSION } from "./kernel/version.mjs";
|
|
13
|
+
import { startStdioMcpServer } from "./mcp/stdio-server.mjs";
|
|
14
|
+
import { detectOllamaBinary } from "./runtime/providers/local-model.mjs";
|
|
15
|
+
|
|
16
|
+
export const CLI_VERSION = DISLOP_VERSION;
|
|
17
|
+
|
|
18
|
+
export function buildHelpText(env = process.env) {
|
|
19
|
+
const ollama = detectOllamaBinary(env);
|
|
20
|
+
const ollamaStatusLine = ollama.installed
|
|
21
|
+
? ` Status: Ollama detected (${ollama.binaryPath}).`
|
|
22
|
+
: " Status: Ollama is MISSING on this machine — install from https://ollama.com (e.g., 'brew install ollama') before using Tier 3 local LLM checks or 'dislop model pull'.";
|
|
23
|
+
|
|
24
|
+
return `dislop v${CLI_VERSION} — Pluggable Editorial & Artifact Linter (Node.js Micro-Kernel)
|
|
25
|
+
|
|
26
|
+
Usage:
|
|
27
|
+
dislop check <files/globs...> [options] Read-only Dual-Track audit (Defects & Suggestions)
|
|
28
|
+
dislop fix <files/globs...> [options] Interactive hunk review in TTY, or batch safe fixes (--auto)
|
|
29
|
+
dislop verify <before> <after> [--json] Verify edits preserved facts, units, links, and entities
|
|
30
|
+
dislop verify --git [ref] <file> [--json] Verify working-tree edits against a Git revision
|
|
31
|
+
dislop init [--global] [--voice <glob>] Initialize .dislop.json or ~/.config/dislop/config.json
|
|
32
|
+
dislop login [--token <dslp_*>] Save Official Cloud credentials (~/.config/dislop/credentials.json)
|
|
33
|
+
dislop logout Remove saved Official Cloud credentials
|
|
34
|
+
dislop voice <extract|show|clear> [files] Manage personal voice baseline (voice.json)
|
|
35
|
+
dislop model <list|pull|rm> [name] Manage Tier 3 local models (requires Ollama)
|
|
36
|
+
dislop packs [list|lint <path>] [--json] List built-in Packs or lint external .pack.md / Pack dirs
|
|
37
|
+
dislop doctor [--json] Inspect active routing tier, Ollama status, auth, config, and Packs
|
|
38
|
+
dislop worklog <status|list|show|stats|reflect|clear> Inspect local dev worklog & reflection summaries
|
|
39
|
+
dislop mcp Start local stdio MCP server for coding & office agents
|
|
40
|
+
|
|
41
|
+
Options (check / fix):
|
|
42
|
+
--auto, -y (fix only) Apply verified fixSafety === "safe" items non-interactively
|
|
43
|
+
--json Emit pure dislop.report/1 JSON to stdout (diagnostics to stderr)
|
|
44
|
+
--format <text|diff|json|agent|sarif> Output format ('agent' = token-compact feed for AI agents)
|
|
45
|
+
--stdin-filename <name> Filename/extension hint when reading document from stdin ('-')
|
|
46
|
+
--changed Inspect git-modified, staged, and untracked deliverable files
|
|
47
|
+
--since <ref> Inspect deliverable files changed since git <ref>
|
|
48
|
+
--fail-on <none|error|warning> Minimum Defect severity to fail with Exit 1 (default: error; Suggestions always Exit 0)
|
|
49
|
+
--pack <names/paths...> Mount specific Packs (comma-separated or repeated)
|
|
50
|
+
--no-llm Run deterministic Script Packs (pack.check) only
|
|
51
|
+
--voice <files/globs...> Align review with hand-written voice reference files
|
|
52
|
+
--level <strong|moderate|hint|all> Filter Suggestion priority threshold (default: all)
|
|
53
|
+
--engine <off|local|auto|cloud|byok> Routing tier (default: local; Tier 3 local LLM requires Ollama)
|
|
54
|
+
--provider <name> Select named or built-in provider (openai, anthropic, gemini)
|
|
55
|
+
--model <name> Override LLM model identifier for the active provider
|
|
56
|
+
--concurrency <n> Max parallel files during 'check' (1-16; default 4 for LLM)
|
|
57
|
+
--dry-run Preview unified diff without modifying files on disk
|
|
58
|
+
--backup Create <file>.bak before atomic write
|
|
59
|
+
--lang <auto|en|zh> Diagnostic language ('auto' matches target document language)
|
|
60
|
+
--help, -h Show this help message
|
|
61
|
+
--version, -v Print version
|
|
62
|
+
|
|
63
|
+
Tier 3 Local LLM Prerequisite (Ollama):
|
|
64
|
+
Tier 3 local semantic checks ('--engine local' & 'dislop model pull') require Ollama (https://ollama.com).
|
|
65
|
+
Without Ollama or an installed local model, default 'local' routing runs offline deterministic Packs only.
|
|
66
|
+
Setup: install Ollama ('brew install ollama'), start 'ollama serve', then run 'dislop model pull'.
|
|
67
|
+
${ollamaStatusLine}
|
|
68
|
+
|
|
69
|
+
Exit Codes:
|
|
70
|
+
0 Pass (zero unresolved Defect: error items; prose Suggestions never fail CI)
|
|
71
|
+
1 Unresolved Defect: error found (or Fact Gate failure in 'dislop verify')
|
|
72
|
+
2 CLI usage, configuration, auth, missing Ollama on 'model pull', or unreadable file error
|
|
73
|
+
`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function splitCommaValues(values) {
|
|
77
|
+
if (!values) return [];
|
|
78
|
+
const arr = Array.isArray(values) ? values : [values];
|
|
79
|
+
return arr
|
|
80
|
+
.flatMap((v) => String(v).split(","))
|
|
81
|
+
.map((s) => s.trim())
|
|
82
|
+
.filter(Boolean);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const OPTIONS_WITH_VALUE = new Set([
|
|
86
|
+
"--format",
|
|
87
|
+
"--pack",
|
|
88
|
+
"--voice",
|
|
89
|
+
"--level",
|
|
90
|
+
"--engine",
|
|
91
|
+
"--provider",
|
|
92
|
+
"--model",
|
|
93
|
+
"--concurrency",
|
|
94
|
+
"--lang",
|
|
95
|
+
"--token",
|
|
96
|
+
"--endpoint",
|
|
97
|
+
"--since",
|
|
98
|
+
"--fail-on",
|
|
99
|
+
"--stdin-filename",
|
|
100
|
+
"--days",
|
|
101
|
+
"--limit",
|
|
102
|
+
"--command",
|
|
103
|
+
"--older-than",
|
|
104
|
+
]);
|
|
105
|
+
|
|
106
|
+
function countRemainingPositionals(tokens, startIndex) {
|
|
107
|
+
let count = 0;
|
|
108
|
+
for (let j = startIndex; j < tokens.length; j += 1) {
|
|
109
|
+
const tok = tokens[j];
|
|
110
|
+
if (tok === "--") {
|
|
111
|
+
count += tokens.length - j - 1;
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
if (tok.startsWith("-")) {
|
|
115
|
+
if (OPTIONS_WITH_VALUE.has(tok) && !tok.includes("=")) {
|
|
116
|
+
j += 1;
|
|
117
|
+
}
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
count += 1;
|
|
121
|
+
}
|
|
122
|
+
return count;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Parse CLI arguments and execute the requested `dislop` subcommand.
|
|
127
|
+
* Returns integer process exit code (`0`, `1`, or `2`).
|
|
128
|
+
*/
|
|
129
|
+
export async function runCli(argv = process.argv.slice(2), io = {}) {
|
|
130
|
+
const stdout = io.stdout || process.stdout;
|
|
131
|
+
const stderr = io.stderr || process.stderr;
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
// Handle `--git` with optional ref value cleanly before `util.parseArgs`
|
|
135
|
+
const normalizedArgv = [];
|
|
136
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
137
|
+
const arg = argv[i];
|
|
138
|
+
if (arg === "--git") {
|
|
139
|
+
const next = argv[i + 1];
|
|
140
|
+
// If another positional target follows `next`, `next` is the git ref; otherwise default to `HEAD`
|
|
141
|
+
const remainingAfterNext = next ? countRemainingPositionals(argv, i + 2) : 0;
|
|
142
|
+
if (next && !next.startsWith("-") && remainingAfterNext >= 1) {
|
|
143
|
+
normalizedArgv.push(`--git=${next}`);
|
|
144
|
+
i += 1;
|
|
145
|
+
} else {
|
|
146
|
+
normalizedArgv.push("--git=HEAD");
|
|
147
|
+
}
|
|
148
|
+
} else {
|
|
149
|
+
normalizedArgv.push(arg);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
let parsed;
|
|
154
|
+
try {
|
|
155
|
+
parsed = parseArgs({
|
|
156
|
+
args: normalizedArgv,
|
|
157
|
+
allowPositionals: true,
|
|
158
|
+
strict: true,
|
|
159
|
+
options: {
|
|
160
|
+
help: { type: "boolean", short: "h" },
|
|
161
|
+
version: { type: "boolean", short: "v" },
|
|
162
|
+
auto: { type: "boolean" },
|
|
163
|
+
yes: { type: "boolean", short: "y" },
|
|
164
|
+
json: { type: "boolean" },
|
|
165
|
+
format: { type: "string" },
|
|
166
|
+
"stdin-filename": { type: "string" },
|
|
167
|
+
changed: { type: "boolean" },
|
|
168
|
+
since: { type: "string" },
|
|
169
|
+
"fail-on": { type: "string" },
|
|
170
|
+
patterns: { type: "boolean" },
|
|
171
|
+
ml: { type: "boolean" },
|
|
172
|
+
deep: { type: "boolean" },
|
|
173
|
+
pack: { type: "string", multiple: true },
|
|
174
|
+
"no-llm": { type: "boolean" },
|
|
175
|
+
voice: { type: "string", multiple: true },
|
|
176
|
+
level: { type: "string" },
|
|
177
|
+
engine: { type: "string" },
|
|
178
|
+
provider: { type: "string" },
|
|
179
|
+
model: { type: "string" },
|
|
180
|
+
concurrency: { type: "string" },
|
|
181
|
+
"dry-run": { type: "boolean" },
|
|
182
|
+
backup: { type: "boolean" },
|
|
183
|
+
lang: { type: "string" },
|
|
184
|
+
global: { type: "boolean" },
|
|
185
|
+
force: { type: "boolean" },
|
|
186
|
+
token: { type: "string" },
|
|
187
|
+
endpoint: { type: "string" },
|
|
188
|
+
git: { type: "string" },
|
|
189
|
+
days: { type: "string" },
|
|
190
|
+
limit: { type: "string" },
|
|
191
|
+
command: { type: "string" },
|
|
192
|
+
"older-than": { type: "string" },
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
} catch (err) {
|
|
196
|
+
throw new DislopConfigError(err.message);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const { values, positionals } = parsed;
|
|
200
|
+
|
|
201
|
+
if (values.patterns) {
|
|
202
|
+
throw new DislopConfigError(
|
|
203
|
+
"Flag '--patterns' was removed in dislop v1.x. Use '--pack <names>' (for example '--pack en/prose' or '--pack common/artifact-qa').",
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
if (values.ml || values.deep) {
|
|
207
|
+
throw new DislopConfigError(
|
|
208
|
+
"Flags '--ml' and '--deep' were removed in dislop v1.x. Use '--engine <auto|local|cloud|byok>' or '--no-llm'.",
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (values.version) {
|
|
213
|
+
stdout.write(`${CLI_VERSION}\n`);
|
|
214
|
+
return 0;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (values.help || positionals.length === 0) {
|
|
218
|
+
stdout.write(buildHelpText(io.env || process.env));
|
|
219
|
+
return positionals.length === 0 && !values.help ? 2 : 0;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const subcommand = positionals[0];
|
|
223
|
+
const restPositionals = positionals.slice(1);
|
|
224
|
+
|
|
225
|
+
const flags = {
|
|
226
|
+
auto: Boolean(values.auto),
|
|
227
|
+
yes: Boolean(values.yes),
|
|
228
|
+
json: Boolean(values.json),
|
|
229
|
+
format: values.format || null,
|
|
230
|
+
packs: values.pack ? splitCommaValues(values.pack) : null,
|
|
231
|
+
noLlm: Boolean(values["no-llm"]),
|
|
232
|
+
voiceFiles: values.voice ? splitCommaValues(values.voice) : null,
|
|
233
|
+
level: values.level || null,
|
|
234
|
+
engine: values.engine || null,
|
|
235
|
+
provider: values.provider || null,
|
|
236
|
+
model: values.model || null,
|
|
237
|
+
concurrency: values.concurrency || null,
|
|
238
|
+
dryRun: Boolean(values["dry-run"]),
|
|
239
|
+
backup: Boolean(values.backup),
|
|
240
|
+
lang: values.lang || null,
|
|
241
|
+
stdinFilename: values["stdin-filename"] || null,
|
|
242
|
+
changed: Boolean(values.changed),
|
|
243
|
+
since: values.since || null,
|
|
244
|
+
failOn: values["fail-on"] || null,
|
|
245
|
+
global: Boolean(values.global),
|
|
246
|
+
force: Boolean(values.force),
|
|
247
|
+
token: values.token || null,
|
|
248
|
+
endpoint: values.endpoint || null,
|
|
249
|
+
git: values.git,
|
|
250
|
+
days: values.days || null,
|
|
251
|
+
limit: values.limit || null,
|
|
252
|
+
command: values.command || null,
|
|
253
|
+
olderThan: values["older-than"] || null,
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
switch (subcommand) {
|
|
257
|
+
case "check":
|
|
258
|
+
return await runCheckCommand(restPositionals, flags, io);
|
|
259
|
+
case "fix":
|
|
260
|
+
return await runFixCommand(restPositionals, flags, io);
|
|
261
|
+
case "verify":
|
|
262
|
+
return await runVerifyCommand(restPositionals, flags, io);
|
|
263
|
+
case "init":
|
|
264
|
+
return await runInitCommand(restPositionals, flags, io);
|
|
265
|
+
case "login":
|
|
266
|
+
return await runLoginCommand(restPositionals, flags, io);
|
|
267
|
+
case "logout":
|
|
268
|
+
return await runLogoutCommand(restPositionals, flags, io);
|
|
269
|
+
case "voice":
|
|
270
|
+
return await runVoiceCommand(restPositionals, flags, io);
|
|
271
|
+
case "model":
|
|
272
|
+
return await runModelCommand(restPositionals, flags, io);
|
|
273
|
+
case "packs":
|
|
274
|
+
return await runPacksCommand(restPositionals, flags, io);
|
|
275
|
+
case "doctor":
|
|
276
|
+
return await runDoctorCommand(restPositionals, flags, io);
|
|
277
|
+
case "worklog":
|
|
278
|
+
return await runWorklogCommand(restPositionals, flags, io);
|
|
279
|
+
case "mcp":
|
|
280
|
+
startStdioMcpServer(io);
|
|
281
|
+
return 0;
|
|
282
|
+
default:
|
|
283
|
+
throw new DislopConfigError(
|
|
284
|
+
`Unknown subcommand '${subcommand}'. Did you mean 'dislop check ${subcommand}' or 'dislop fix ${subcommand}'? Run 'dislop --help' for usage.`,
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
} catch (err) {
|
|
288
|
+
const code = err?.exitCode || 2;
|
|
289
|
+
stderr.write(`dislop error: ${err?.message || String(err)}\n`);
|
|
290
|
+
return code;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { DislopConfigError, isInteractiveHumanTty, resolveLayeredConfig } from "../kernel/config.mjs";
|
|
4
|
+
import { discoverChangedFiles, expandTargetInputs } from "../kernel/file-discovery.mjs";
|
|
5
|
+
import { arbitrateExitCode, runDocumentPipeline } from "../kernel/pipeline.mjs";
|
|
6
|
+
import { resolveOrExtractVoiceProfile } from "../kernel/voice-profile.mjs";
|
|
7
|
+
import { runAutoFixOnDocumentResult } from "../runners/auto-fix.mjs";
|
|
8
|
+
import { runInteractiveTtySession } from "../runners/interactive-tty.mjs";
|
|
9
|
+
import { renderReports } from "../runners/reporters.mjs";
|
|
10
|
+
import { resolveExecutionRoute } from "../runtime/router.mjs";
|
|
11
|
+
import { buildCheckOrFixWorklogEntry, recordWorklogEntry } from "../runtime/worklog.mjs";
|
|
12
|
+
|
|
13
|
+
const VALID_FORMATS = new Set(["text", "diff", "json", "agent", "sarif"]);
|
|
14
|
+
|
|
15
|
+
async function readStreamBuffer(stream, preloaded = null) {
|
|
16
|
+
if (Buffer.isBuffer(preloaded)) return preloaded;
|
|
17
|
+
if (typeof preloaded === "string") return Buffer.from(preloaded, "utf8");
|
|
18
|
+
if (!stream) return Buffer.alloc(0);
|
|
19
|
+
const chunks = [];
|
|
20
|
+
for await (const chunk of stream) {
|
|
21
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk), "utf8"));
|
|
22
|
+
}
|
|
23
|
+
return Buffer.concat(chunks);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function mapWithConcurrency(items, concurrency, worker) {
|
|
27
|
+
const limit = Math.max(1, Math.min(concurrency || 1, items.length || 1));
|
|
28
|
+
const results = new Array(items.length);
|
|
29
|
+
let nextIdx = 0;
|
|
30
|
+
|
|
31
|
+
async function runWorker() {
|
|
32
|
+
while (nextIdx < items.length) {
|
|
33
|
+
const idx = nextIdx;
|
|
34
|
+
nextIdx += 1;
|
|
35
|
+
results[idx] = await worker(items[idx], idx);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
await Promise.all(Array.from({ length: limit }, () => runWorker()));
|
|
40
|
+
return results;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* `dislop check <files/globs...> [options]` — strictly read-only inspection.
|
|
45
|
+
*/
|
|
46
|
+
export async function runCheckCommand(targets, flags, io = {}) {
|
|
47
|
+
const {
|
|
48
|
+
cwd = process.cwd(),
|
|
49
|
+
env = process.env,
|
|
50
|
+
stdin = process.stdin,
|
|
51
|
+
stdout = process.stdout,
|
|
52
|
+
stderr = process.stderr,
|
|
53
|
+
fetchImpl = globalThis.fetch,
|
|
54
|
+
promptFn = null,
|
|
55
|
+
} = io;
|
|
56
|
+
|
|
57
|
+
const startedAt = Date.now();
|
|
58
|
+
const format = flags.json ? "json" : flags.format || "text";
|
|
59
|
+
if (!VALID_FORMATS.has(format)) {
|
|
60
|
+
throw new DislopConfigError(
|
|
61
|
+
`Invalid --format '${format}' (expected text, diff, json, agent, or sarif)`,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const isTty = isInteractiveHumanTty({ stdin, stdout, env });
|
|
66
|
+
const config = resolveLayeredConfig({ cwd, env, cliFlags: flags });
|
|
67
|
+
|
|
68
|
+
const hasStdinTarget = Array.isArray(targets) && targets.includes("-");
|
|
69
|
+
if (hasStdinTarget && targets.length > 1) {
|
|
70
|
+
throw new DislopConfigError("Cannot mix '-' (stdin) with additional file paths.");
|
|
71
|
+
}
|
|
72
|
+
if ((flags.changed || flags.since) && targets && targets.length > 0) {
|
|
73
|
+
throw new DislopConfigError("Cannot combine '--changed' / '--since' with explicit file targets.");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let files = [];
|
|
77
|
+
let stdinBufferContent = null;
|
|
78
|
+
if (hasStdinTarget) {
|
|
79
|
+
stdinBufferContent = await readStreamBuffer(stdin, io.stdinText ?? null);
|
|
80
|
+
const virtualName = flags.stdinFilename || "stdin.md";
|
|
81
|
+
files = [path.resolve(cwd, virtualName)];
|
|
82
|
+
} else if (flags.changed || flags.since) {
|
|
83
|
+
files = discoverChangedFiles({
|
|
84
|
+
cwd,
|
|
85
|
+
since: flags.since || null,
|
|
86
|
+
ignorePatterns: config.ignore,
|
|
87
|
+
projectRoot: config.projectDir || cwd,
|
|
88
|
+
});
|
|
89
|
+
} else {
|
|
90
|
+
files = expandTargetInputs(targets, {
|
|
91
|
+
cwd,
|
|
92
|
+
ignorePatterns: config.ignore,
|
|
93
|
+
projectRoot: config.projectDir || cwd,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (files.length === 0) {
|
|
98
|
+
const emptyMsg = flags.changed || flags.since
|
|
99
|
+
? "No changed deliverable files to check.\n"
|
|
100
|
+
: "No matching deliverable files to check.\n";
|
|
101
|
+
if (format === "json") {
|
|
102
|
+
stdout.write("[]\n");
|
|
103
|
+
} else {
|
|
104
|
+
stdout.write(emptyMsg);
|
|
105
|
+
}
|
|
106
|
+
return 0;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const route = await resolveExecutionRoute({
|
|
110
|
+
config,
|
|
111
|
+
isTty,
|
|
112
|
+
env,
|
|
113
|
+
stdin,
|
|
114
|
+
stderr,
|
|
115
|
+
fetchImpl,
|
|
116
|
+
promptFn,
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const voiceProfile = config.noLlm ? null : await resolveOrExtractVoiceProfile(config, { route });
|
|
120
|
+
const workerCount = config.concurrency || (route?.execute ? Math.min(4, files.length) : 1);
|
|
121
|
+
|
|
122
|
+
const rawResults = await mapWithConcurrency(files, workerCount, (filePath) =>
|
|
123
|
+
runDocumentPipeline({
|
|
124
|
+
filePath,
|
|
125
|
+
bufferContent: hasStdinTarget ? stdinBufferContent : null,
|
|
126
|
+
config,
|
|
127
|
+
route,
|
|
128
|
+
voiceProfile,
|
|
129
|
+
cwd,
|
|
130
|
+
}),
|
|
131
|
+
);
|
|
132
|
+
const results = rawResults.filter((r) => !r.skippedByIgnore);
|
|
133
|
+
|
|
134
|
+
if (results.length === 0) {
|
|
135
|
+
stdout.write(format === "json" ? "[]\n" : "No matching deliverable files to check.\n");
|
|
136
|
+
return 0;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
let emittedHint = false;
|
|
140
|
+
for (const res of results) {
|
|
141
|
+
if (res.routeHint && !emittedHint) {
|
|
142
|
+
stderr.write(`${res.routeHint}\n`);
|
|
143
|
+
emittedHint = true;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const uiLang =
|
|
148
|
+
config.lang && config.lang !== "auto"
|
|
149
|
+
? config.lang
|
|
150
|
+
: results[0]?.doc?.language || "en";
|
|
151
|
+
|
|
152
|
+
const rendered = renderReports(results, format, { lang: uiLang });
|
|
153
|
+
if (rendered) {
|
|
154
|
+
stdout.write(rendered);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const exitCode = arbitrateExitCode(results, {
|
|
158
|
+
failOn: config.failOn,
|
|
159
|
+
explicitFailOn: config.explicitFailOn,
|
|
160
|
+
});
|
|
161
|
+
recordWorklogEntry(
|
|
162
|
+
buildCheckOrFixWorklogEntry({
|
|
163
|
+
source: "cli",
|
|
164
|
+
command: "check",
|
|
165
|
+
mode: format,
|
|
166
|
+
cwd,
|
|
167
|
+
config,
|
|
168
|
+
route,
|
|
169
|
+
results,
|
|
170
|
+
durationMs: Date.now() - startedAt,
|
|
171
|
+
exitCode,
|
|
172
|
+
}),
|
|
173
|
+
config,
|
|
174
|
+
env,
|
|
175
|
+
);
|
|
176
|
+
return exitCode;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* `dislop fix <files/globs...> [options]`
|
|
181
|
+
* - With `--auto` / `--yes`: non-interactive batch application of `fixSafety === "safe"` items.
|
|
182
|
+
* - Without `--auto`: interactive `git add -p` TTY hunk loop (`y/n/e/p/a/A/s/u/q`).
|
|
183
|
+
*/
|
|
184
|
+
export async function runFixCommand(targets, flags, io = {}) {
|
|
185
|
+
const {
|
|
186
|
+
cwd = process.cwd(),
|
|
187
|
+
env = process.env,
|
|
188
|
+
stdin = process.stdin,
|
|
189
|
+
stdout = process.stdout,
|
|
190
|
+
stderr = process.stderr,
|
|
191
|
+
fetchImpl = globalThis.fetch,
|
|
192
|
+
promptFn = null,
|
|
193
|
+
keyReader = null,
|
|
194
|
+
editorRunner = null,
|
|
195
|
+
clipboardRunner = null,
|
|
196
|
+
} = io;
|
|
197
|
+
|
|
198
|
+
const startedAt = Date.now();
|
|
199
|
+
const isAuto = Boolean(flags.auto || flags.yes);
|
|
200
|
+
const isTty = isInteractiveHumanTty({ stdin, stdout, env }) || Boolean(keyReader);
|
|
201
|
+
|
|
202
|
+
if (!isAuto && !isTty) {
|
|
203
|
+
throw new DislopConfigError(
|
|
204
|
+
"Interactive 'dislop fix' requires an interactive terminal. Pass '--auto' to apply verified safe fixes in batch/CI/agent mode, or run 'dislop check' for read-only reports.",
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const config = resolveLayeredConfig({ cwd, env, cliFlags: flags });
|
|
209
|
+
if (Array.isArray(targets) && targets.includes("-")) {
|
|
210
|
+
throw new DislopConfigError("'dislop fix' does not modify '-' (stdin). Pass file paths or run 'dislop check - --format diff'.");
|
|
211
|
+
}
|
|
212
|
+
const files =
|
|
213
|
+
flags.changed || flags.since
|
|
214
|
+
? discoverChangedFiles({
|
|
215
|
+
cwd,
|
|
216
|
+
since: flags.since || null,
|
|
217
|
+
ignorePatterns: config.ignore,
|
|
218
|
+
projectRoot: config.projectDir || cwd,
|
|
219
|
+
})
|
|
220
|
+
: expandTargetInputs(targets, {
|
|
221
|
+
cwd,
|
|
222
|
+
ignorePatterns: config.ignore,
|
|
223
|
+
projectRoot: config.projectDir || cwd,
|
|
224
|
+
});
|
|
225
|
+
if (files.length === 0) {
|
|
226
|
+
stdout.write("No matching deliverable files to fix.\n");
|
|
227
|
+
return 0;
|
|
228
|
+
}
|
|
229
|
+
const route = await resolveExecutionRoute({
|
|
230
|
+
config,
|
|
231
|
+
isTty,
|
|
232
|
+
env,
|
|
233
|
+
stdin,
|
|
234
|
+
stderr,
|
|
235
|
+
fetchImpl,
|
|
236
|
+
promptFn,
|
|
237
|
+
});
|
|
238
|
+
const voiceProfile = config.noLlm ? null : await resolveOrExtractVoiceProfile(config, { route });
|
|
239
|
+
|
|
240
|
+
const results = [];
|
|
241
|
+
const decisionsByFile = [];
|
|
242
|
+
let aborted = false;
|
|
243
|
+
let emittedHint = false;
|
|
244
|
+
|
|
245
|
+
for (const filePath of files) {
|
|
246
|
+
const docRes = await runDocumentPipeline({
|
|
247
|
+
filePath,
|
|
248
|
+
config,
|
|
249
|
+
route,
|
|
250
|
+
voiceProfile,
|
|
251
|
+
cwd,
|
|
252
|
+
});
|
|
253
|
+
if (docRes.skippedByIgnore) continue;
|
|
254
|
+
if (docRes.routeHint && !emittedHint) {
|
|
255
|
+
stderr.write(`${docRes.routeHint}\n`);
|
|
256
|
+
emittedHint = true;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (isAuto) {
|
|
260
|
+
const fixRes = runAutoFixOnDocumentResult(docRes, {
|
|
261
|
+
dryRun: Boolean(flags.dryRun),
|
|
262
|
+
backup: Boolean(flags.backup),
|
|
263
|
+
});
|
|
264
|
+
if (flags.dryRun && fixRes.diff && !flags.json) {
|
|
265
|
+
stdout.write(`${fixRes.diff}\n`);
|
|
266
|
+
} else if (!flags.json && flags.format !== "json") {
|
|
267
|
+
stdout.write(
|
|
268
|
+
`${docRes.report.file}: applied ${fixRes.appliedCount} safe fix(es); remaining defects=${docRes.report.summary.defects.error + docRes.report.summary.defects.warning}, suggestions=${docRes.report.summary.suggestions.strong + docRes.report.summary.suggestions.moderate + docRes.report.summary.suggestions.hint}\n`,
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
results.push(docRes);
|
|
272
|
+
decisionsByFile.push({
|
|
273
|
+
decisions: fixRes.decisions || {},
|
|
274
|
+
undoCount: 0,
|
|
275
|
+
aborted: false,
|
|
276
|
+
});
|
|
277
|
+
} else {
|
|
278
|
+
const ttyRes = await runInteractiveTtySession(docRes, {
|
|
279
|
+
stdin,
|
|
280
|
+
stdout,
|
|
281
|
+
env,
|
|
282
|
+
dryRun: Boolean(flags.dryRun),
|
|
283
|
+
backup: Boolean(flags.backup),
|
|
284
|
+
keyReader,
|
|
285
|
+
editorRunner,
|
|
286
|
+
clipboardRunner,
|
|
287
|
+
});
|
|
288
|
+
if (ttyRes.aborted) aborted = true;
|
|
289
|
+
results.push(docRes);
|
|
290
|
+
decisionsByFile.push({
|
|
291
|
+
decisions: ttyRes.decisions || {},
|
|
292
|
+
undoCount: ttyRes.undoCount || 0,
|
|
293
|
+
aborted: Boolean(ttyRes.aborted),
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (flags.json || flags.format === "json") {
|
|
299
|
+
stdout.write(renderReports(results, "json"));
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const exitCode = arbitrateExitCode(results, {
|
|
303
|
+
failOn: config.failOn,
|
|
304
|
+
explicitFailOn: config.explicitFailOn,
|
|
305
|
+
});
|
|
306
|
+
recordWorklogEntry(
|
|
307
|
+
buildCheckOrFixWorklogEntry({
|
|
308
|
+
source: "cli",
|
|
309
|
+
command: "fix",
|
|
310
|
+
mode: isAuto ? (flags.dryRun ? "auto-dry-run" : "auto") : (flags.dryRun ? "tty-dry-run" : "tty"),
|
|
311
|
+
cwd,
|
|
312
|
+
config,
|
|
313
|
+
route,
|
|
314
|
+
results,
|
|
315
|
+
decisionsByFile,
|
|
316
|
+
durationMs: Date.now() - startedAt,
|
|
317
|
+
exitCode,
|
|
318
|
+
aborted,
|
|
319
|
+
}),
|
|
320
|
+
config,
|
|
321
|
+
env,
|
|
322
|
+
);
|
|
323
|
+
return exitCode;
|
|
324
|
+
}
|