dislop 0.9.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 -57
- package/README.md +360 -252
- package/README.zh-CN.md +390 -240
- package/action.yml +30 -39
- package/bin/dislop-mcp.mjs +3 -4
- package/bin/dislop.mjs +4 -4582
- package/gemini-extension.json +2 -2
- package/llms-install.md +68 -0
- package/package.json +17 -55
- 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 +173 -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 +290 -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 +8 -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/references/essay.md +1 -1
- package/skills/dislop/references/essay.zh-CN.md +1 -1
- package/skills/dislop/references/office.md +1 -1
- package/skills/dislop/references/office.zh-CN.md +1 -1
- package/skills/dislop/references/web-ui.md +1 -1
- package/skills/dislop/references/web-ui.zh-CN.md +1 -1
- package/skills/dislop/references/work-docs.md +1 -1
- package/skills/dislop/references/work-docs.zh-CN.md +1 -1
- package/src/cli-main.mjs +210 -0
- package/src/commands/check-fix.mjs +169 -0
- package/src/commands/doctor.mjs +110 -0
- package/src/commands/init.mjs +49 -0
- package/src/commands/login.mjs +82 -0
- package/src/commands/model.mjs +130 -0
- package/src/commands/packs.mjs +44 -0
- package/src/commands/verify.mjs +133 -0
- package/src/commands/voice.mjs +84 -0
- package/src/kernel/config.mjs +232 -0
- package/src/kernel/document-model.mjs +1412 -0
- package/src/kernel/fact-gate.mjs +615 -0
- package/src/kernel/file-discovery.mjs +139 -0
- package/src/{binary-node.mjs → kernel/ooxml-binary.mjs} +532 -893
- package/src/kernel/pack-loader.mjs +715 -0
- package/src/kernel/patcher.mjs +341 -0
- package/src/kernel/pipeline.mjs +267 -0
- package/src/kernel/prompt-assembler.mjs +307 -0
- package/src/kernel/voice-profile.mjs +177 -0
- package/src/mcp/stdio-server.mjs +372 -0
- package/src/runners/auto-fix.mjs +59 -0
- package/src/runners/interactive-tty.mjs +461 -0
- package/src/runners/reporters.mjs +256 -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 +136 -0
- package/src/runtime/providers/gemini.mjs +91 -0
- package/src/runtime/providers/local-model.mjs +139 -0
- package/src/runtime/providers/openai-compat.mjs +130 -0
- package/src/runtime/router.mjs +315 -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,210 @@
|
|
|
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 { DislopConfigError } from "./kernel/config.mjs";
|
|
11
|
+
import { startStdioMcpServer } from "./mcp/stdio-server.mjs";
|
|
12
|
+
import { detectOllamaBinary } from "./runtime/providers/local-model.mjs";
|
|
13
|
+
|
|
14
|
+
export const CLI_VERSION = "1.0.1";
|
|
15
|
+
|
|
16
|
+
export function buildHelpText(env = process.env) {
|
|
17
|
+
const ollama = detectOllamaBinary(env);
|
|
18
|
+
const ollamaStatusLine = ollama.installed
|
|
19
|
+
? ` Status: Ollama detected (${ollama.binaryPath}).`
|
|
20
|
+
: " 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'.";
|
|
21
|
+
|
|
22
|
+
return `dislop v${CLI_VERSION} — Pluggable Editorial & Artifact Linter (Node.js Micro-Kernel)
|
|
23
|
+
|
|
24
|
+
Usage:
|
|
25
|
+
dislop check <files/globs...> [options] Read-only Dual-Track audit (Defects & Suggestions)
|
|
26
|
+
dislop fix <files/globs...> [options] Interactive hunk review in TTY, or batch safe fixes (--auto)
|
|
27
|
+
dislop verify <before> <after> [--json] Verify edits preserved facts, units, links, and entities
|
|
28
|
+
dislop verify --git [ref] <file> [--json] Verify working-tree edits against a Git revision
|
|
29
|
+
dislop init [--global] [--voice <glob>] Initialize .dislop.json or ~/.config/dislop/config.json
|
|
30
|
+
dislop login [--token <dslp_*>] Save Official Cloud credentials (~/.config/dislop/credentials.json)
|
|
31
|
+
dislop logout Remove saved Official Cloud credentials
|
|
32
|
+
dislop voice <extract|show|clear> [files] Manage personal voice baseline (voice.json)
|
|
33
|
+
dislop model <list|pull|rm> [name] Manage Tier 3 local models (requires Ollama)
|
|
34
|
+
dislop packs [--json] List built-in multi-level Packs
|
|
35
|
+
dislop doctor [--json] Inspect active routing tier, Ollama status, auth, config, and Packs
|
|
36
|
+
dislop mcp Start local stdio MCP server for coding & office agents
|
|
37
|
+
|
|
38
|
+
Options (check / fix):
|
|
39
|
+
--auto, -y (fix only) Apply verified fixSafety === "safe" items non-interactively
|
|
40
|
+
--json Emit pure dislop.report/1 JSON to stdout (diagnostics to stderr)
|
|
41
|
+
--format <text|diff|json|agent|sarif> Output format ('agent' = token-compact feed for AI agents)
|
|
42
|
+
--pack <names/paths...> Mount specific Packs (comma-separated or repeated)
|
|
43
|
+
--no-llm Run deterministic Script Packs (pack.check) only
|
|
44
|
+
--voice <files/globs...> Align review with hand-written voice reference files
|
|
45
|
+
--level <strong|moderate|hint|all> Filter Suggestion priority threshold (default: all)
|
|
46
|
+
--engine <local|auto|cloud|byok> Routing tier (default: local; Tier 3 local LLM requires Ollama)
|
|
47
|
+
--provider <name> Select named or built-in provider (openai, anthropic, gemini)
|
|
48
|
+
--model <name> Override LLM model identifier for the active provider
|
|
49
|
+
--dry-run Preview unified diff without modifying files on disk
|
|
50
|
+
--backup Create <file>.bak before atomic write
|
|
51
|
+
--lang <auto|en|zh> Diagnostic language ('auto' matches target document language)
|
|
52
|
+
--help, -h Show this help message
|
|
53
|
+
--version, -v Print version
|
|
54
|
+
|
|
55
|
+
Tier 3 Local LLM Prerequisite (Ollama):
|
|
56
|
+
Tier 3 local semantic checks ('--engine local' & 'dislop model pull') require Ollama (https://ollama.com).
|
|
57
|
+
Without Ollama or an installed local model, default 'local' routing runs offline deterministic Packs only.
|
|
58
|
+
Setup: install Ollama ('brew install ollama'), start 'ollama serve', then run 'dislop model pull'.
|
|
59
|
+
${ollamaStatusLine}
|
|
60
|
+
|
|
61
|
+
Exit Codes:
|
|
62
|
+
0 Pass (zero unresolved Defect: error items; prose Suggestions never fail CI)
|
|
63
|
+
1 Unresolved Defect: error found (or Fact Gate failure in 'dislop verify')
|
|
64
|
+
2 CLI usage, configuration, auth, missing Ollama on 'model pull', or unreadable file error
|
|
65
|
+
`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function splitCommaValues(values) {
|
|
69
|
+
if (!values) return [];
|
|
70
|
+
const arr = Array.isArray(values) ? values : [values];
|
|
71
|
+
return arr
|
|
72
|
+
.flatMap((v) => String(v).split(","))
|
|
73
|
+
.map((s) => s.trim())
|
|
74
|
+
.filter(Boolean);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Parse CLI arguments and execute the requested `dislop` subcommand.
|
|
79
|
+
* Returns integer process exit code (`0`, `1`, or `2`).
|
|
80
|
+
*/
|
|
81
|
+
export async function runCli(argv = process.argv.slice(2), io = {}) {
|
|
82
|
+
const stdout = io.stdout || process.stdout;
|
|
83
|
+
const stderr = io.stderr || process.stderr;
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
// Handle `--git` with optional ref value cleanly before `util.parseArgs`
|
|
87
|
+
const normalizedArgv = [];
|
|
88
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
89
|
+
const arg = argv[i];
|
|
90
|
+
if (arg === "--git") {
|
|
91
|
+
const next = argv[i + 1];
|
|
92
|
+
// Heuristic: if only 1 positional remains after `next`, `next` is the git ref; otherwise `HEAD`
|
|
93
|
+
const remainingNonFlags = argv.slice(i + 1).filter((a) => !a.startsWith("-"));
|
|
94
|
+
if (next && !next.startsWith("-") && remainingNonFlags.length >= 2) {
|
|
95
|
+
normalizedArgv.push(`--git=${next}`);
|
|
96
|
+
i += 1;
|
|
97
|
+
} else {
|
|
98
|
+
normalizedArgv.push("--git=HEAD");
|
|
99
|
+
}
|
|
100
|
+
} else {
|
|
101
|
+
normalizedArgv.push(arg);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
let parsed;
|
|
106
|
+
try {
|
|
107
|
+
parsed = parseArgs({
|
|
108
|
+
args: normalizedArgv,
|
|
109
|
+
allowPositionals: true,
|
|
110
|
+
strict: true,
|
|
111
|
+
options: {
|
|
112
|
+
help: { type: "boolean", short: "h" },
|
|
113
|
+
version: { type: "boolean", short: "v" },
|
|
114
|
+
auto: { type: "boolean" },
|
|
115
|
+
yes: { type: "boolean", short: "y" },
|
|
116
|
+
json: { type: "boolean" },
|
|
117
|
+
format: { type: "string" },
|
|
118
|
+
pack: { type: "string", multiple: true },
|
|
119
|
+
"no-llm": { type: "boolean" },
|
|
120
|
+
voice: { type: "string", multiple: true },
|
|
121
|
+
level: { type: "string" },
|
|
122
|
+
engine: { type: "string" },
|
|
123
|
+
provider: { type: "string" },
|
|
124
|
+
model: { type: "string" },
|
|
125
|
+
"dry-run": { type: "boolean" },
|
|
126
|
+
backup: { type: "boolean" },
|
|
127
|
+
lang: { type: "string" },
|
|
128
|
+
global: { type: "boolean" },
|
|
129
|
+
force: { type: "boolean" },
|
|
130
|
+
token: { type: "string" },
|
|
131
|
+
endpoint: { type: "string" },
|
|
132
|
+
git: { type: "string" },
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
} catch (err) {
|
|
136
|
+
throw new DislopConfigError(err.message);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const { values, positionals } = parsed;
|
|
140
|
+
|
|
141
|
+
if (values.version) {
|
|
142
|
+
stdout.write(`${CLI_VERSION}\n`);
|
|
143
|
+
return 0;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (values.help || positionals.length === 0) {
|
|
147
|
+
stdout.write(buildHelpText(io.env || process.env));
|
|
148
|
+
return positionals.length === 0 && !values.help ? 2 : 0;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const subcommand = positionals[0];
|
|
152
|
+
const restPositionals = positionals.slice(1);
|
|
153
|
+
|
|
154
|
+
const flags = {
|
|
155
|
+
auto: Boolean(values.auto),
|
|
156
|
+
yes: Boolean(values.yes),
|
|
157
|
+
json: Boolean(values.json),
|
|
158
|
+
format: values.format || null,
|
|
159
|
+
packs: values.pack ? splitCommaValues(values.pack) : null,
|
|
160
|
+
noLlm: Boolean(values["no-llm"]),
|
|
161
|
+
voiceFiles: values.voice ? splitCommaValues(values.voice) : null,
|
|
162
|
+
level: values.level || null,
|
|
163
|
+
engine: values.engine || null,
|
|
164
|
+
provider: values.provider || null,
|
|
165
|
+
model: values.model || null,
|
|
166
|
+
dryRun: Boolean(values["dry-run"]),
|
|
167
|
+
backup: Boolean(values.backup),
|
|
168
|
+
lang: values.lang || null,
|
|
169
|
+
global: Boolean(values.global),
|
|
170
|
+
force: Boolean(values.force),
|
|
171
|
+
token: values.token || null,
|
|
172
|
+
endpoint: values.endpoint || null,
|
|
173
|
+
git: values.git,
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
switch (subcommand) {
|
|
177
|
+
case "check":
|
|
178
|
+
return await runCheckCommand(restPositionals, flags, io);
|
|
179
|
+
case "fix":
|
|
180
|
+
return await runFixCommand(restPositionals, flags, io);
|
|
181
|
+
case "verify":
|
|
182
|
+
return await runVerifyCommand(restPositionals, flags, io);
|
|
183
|
+
case "init":
|
|
184
|
+
return await runInitCommand(restPositionals, flags, io);
|
|
185
|
+
case "login":
|
|
186
|
+
return await runLoginCommand(restPositionals, flags, io);
|
|
187
|
+
case "logout":
|
|
188
|
+
return await runLogoutCommand(restPositionals, flags, io);
|
|
189
|
+
case "voice":
|
|
190
|
+
return await runVoiceCommand(restPositionals, flags, io);
|
|
191
|
+
case "model":
|
|
192
|
+
return await runModelCommand(restPositionals, flags, io);
|
|
193
|
+
case "packs":
|
|
194
|
+
return await runPacksCommand(restPositionals, flags, io);
|
|
195
|
+
case "doctor":
|
|
196
|
+
return await runDoctorCommand(restPositionals, flags, io);
|
|
197
|
+
case "mcp":
|
|
198
|
+
startStdioMcpServer(io);
|
|
199
|
+
return 0;
|
|
200
|
+
default:
|
|
201
|
+
throw new DislopConfigError(
|
|
202
|
+
`Unknown subcommand '${subcommand}'. Did you mean 'dislop check ${subcommand}' or 'dislop fix ${subcommand}'? Run 'dislop --help' for usage.`,
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
} catch (err) {
|
|
206
|
+
const code = err?.exitCode || 2;
|
|
207
|
+
stderr.write(`dislop error: ${err?.message || String(err)}\n`);
|
|
208
|
+
return code;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { DislopConfigError, isInteractiveHumanTty, resolveLayeredConfig } from "../kernel/config.mjs";
|
|
2
|
+
import { expandTargetInputs } from "../kernel/file-discovery.mjs";
|
|
3
|
+
import { arbitrateExitCode, runDocumentPipeline } from "../kernel/pipeline.mjs";
|
|
4
|
+
import { resolveOrExtractVoiceProfile } from "../kernel/voice-profile.mjs";
|
|
5
|
+
import { runAutoFixOnDocumentResult } from "../runners/auto-fix.mjs";
|
|
6
|
+
import { runInteractiveTtySession } from "../runners/interactive-tty.mjs";
|
|
7
|
+
import { renderReports } from "../runners/reporters.mjs";
|
|
8
|
+
import { resolveExecutionRoute } from "../runtime/router.mjs";
|
|
9
|
+
|
|
10
|
+
const VALID_FORMATS = new Set(["text", "diff", "json", "agent", "sarif"]);
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* `dislop check <files/globs...> [options]` — strictly read-only inspection.
|
|
14
|
+
*/
|
|
15
|
+
export async function runCheckCommand(targets, flags, io = {}) {
|
|
16
|
+
const {
|
|
17
|
+
cwd = process.cwd(),
|
|
18
|
+
env = process.env,
|
|
19
|
+
stdin = process.stdin,
|
|
20
|
+
stdout = process.stdout,
|
|
21
|
+
stderr = process.stderr,
|
|
22
|
+
fetchImpl = globalThis.fetch,
|
|
23
|
+
promptFn = null,
|
|
24
|
+
} = io;
|
|
25
|
+
|
|
26
|
+
const format = flags.json ? "json" : flags.format || "text";
|
|
27
|
+
if (!VALID_FORMATS.has(format)) {
|
|
28
|
+
throw new DislopConfigError(
|
|
29
|
+
`Invalid --format '${format}' (expected text, diff, json, agent, or sarif)`,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const files = expandTargetInputs(targets, { cwd });
|
|
34
|
+
const isTty = isInteractiveHumanTty({ stdin, stdout, env });
|
|
35
|
+
const config = resolveLayeredConfig({ cwd, env, cliFlags: flags });
|
|
36
|
+
const route = await resolveExecutionRoute({
|
|
37
|
+
config,
|
|
38
|
+
isTty,
|
|
39
|
+
env,
|
|
40
|
+
stdin,
|
|
41
|
+
stderr,
|
|
42
|
+
fetchImpl,
|
|
43
|
+
promptFn,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const voiceProfile = await resolveOrExtractVoiceProfile(config, { route });
|
|
47
|
+
|
|
48
|
+
const results = [];
|
|
49
|
+
let emittedHint = false;
|
|
50
|
+
|
|
51
|
+
for (const filePath of files) {
|
|
52
|
+
const res = await runDocumentPipeline({
|
|
53
|
+
filePath,
|
|
54
|
+
config,
|
|
55
|
+
route,
|
|
56
|
+
voiceProfile,
|
|
57
|
+
cwd,
|
|
58
|
+
});
|
|
59
|
+
if (res.routeHint && !emittedHint) {
|
|
60
|
+
stderr.write(`${res.routeHint}\n`);
|
|
61
|
+
emittedHint = true;
|
|
62
|
+
}
|
|
63
|
+
results.push(res);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const uiLang =
|
|
67
|
+
config.lang && config.lang !== "auto"
|
|
68
|
+
? config.lang
|
|
69
|
+
: results[0]?.doc?.language || "en";
|
|
70
|
+
|
|
71
|
+
const rendered = renderReports(results, format, { lang: uiLang });
|
|
72
|
+
if (rendered) {
|
|
73
|
+
stdout.write(rendered);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return arbitrateExitCode(results.map((r) => r.report));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* `dislop fix <files/globs...> [options]`
|
|
81
|
+
* - With `--auto` / `--yes`: non-interactive batch application of `fixSafety === "safe"` items.
|
|
82
|
+
* - Without `--auto`: interactive `git add -p` TTY hunk loop (`y/n/e/p/a/A/s/u/q`).
|
|
83
|
+
*/
|
|
84
|
+
export async function runFixCommand(targets, flags, io = {}) {
|
|
85
|
+
const {
|
|
86
|
+
cwd = process.cwd(),
|
|
87
|
+
env = process.env,
|
|
88
|
+
stdin = process.stdin,
|
|
89
|
+
stdout = process.stdout,
|
|
90
|
+
stderr = process.stderr,
|
|
91
|
+
fetchImpl = globalThis.fetch,
|
|
92
|
+
promptFn = null,
|
|
93
|
+
keyReader = null,
|
|
94
|
+
editorRunner = null,
|
|
95
|
+
clipboardRunner = null,
|
|
96
|
+
} = io;
|
|
97
|
+
|
|
98
|
+
const isAuto = Boolean(flags.auto || flags.yes);
|
|
99
|
+
const isTty = isInteractiveHumanTty({ stdin, stdout, env }) || Boolean(keyReader);
|
|
100
|
+
|
|
101
|
+
if (!isAuto && !isTty) {
|
|
102
|
+
throw new DislopConfigError(
|
|
103
|
+
"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.",
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const files = expandTargetInputs(targets, { cwd });
|
|
108
|
+
const config = resolveLayeredConfig({ cwd, env, cliFlags: flags });
|
|
109
|
+
const route = await resolveExecutionRoute({
|
|
110
|
+
config,
|
|
111
|
+
isTty,
|
|
112
|
+
env,
|
|
113
|
+
stdin,
|
|
114
|
+
stderr,
|
|
115
|
+
fetchImpl,
|
|
116
|
+
promptFn,
|
|
117
|
+
});
|
|
118
|
+
const voiceProfile = await resolveOrExtractVoiceProfile(config, { route });
|
|
119
|
+
|
|
120
|
+
const results = [];
|
|
121
|
+
let emittedHint = false;
|
|
122
|
+
|
|
123
|
+
for (const filePath of files) {
|
|
124
|
+
const docRes = await runDocumentPipeline({
|
|
125
|
+
filePath,
|
|
126
|
+
config,
|
|
127
|
+
route,
|
|
128
|
+
voiceProfile,
|
|
129
|
+
cwd,
|
|
130
|
+
});
|
|
131
|
+
if (docRes.routeHint && !emittedHint) {
|
|
132
|
+
stderr.write(`${docRes.routeHint}\n`);
|
|
133
|
+
emittedHint = true;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (isAuto) {
|
|
137
|
+
const fixRes = runAutoFixOnDocumentResult(docRes, {
|
|
138
|
+
dryRun: Boolean(flags.dryRun),
|
|
139
|
+
backup: Boolean(flags.backup),
|
|
140
|
+
});
|
|
141
|
+
if (flags.dryRun && fixRes.diff && !flags.json) {
|
|
142
|
+
stdout.write(`${fixRes.diff}\n`);
|
|
143
|
+
} else if (!flags.json && flags.format !== "json") {
|
|
144
|
+
stdout.write(
|
|
145
|
+
`${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`,
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
results.push(docRes);
|
|
149
|
+
} else {
|
|
150
|
+
await runInteractiveTtySession(docRes, {
|
|
151
|
+
stdin,
|
|
152
|
+
stdout,
|
|
153
|
+
env,
|
|
154
|
+
dryRun: Boolean(flags.dryRun),
|
|
155
|
+
backup: Boolean(flags.backup),
|
|
156
|
+
keyReader,
|
|
157
|
+
editorRunner,
|
|
158
|
+
clipboardRunner,
|
|
159
|
+
});
|
|
160
|
+
results.push(docRes);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (flags.json || flags.format === "json") {
|
|
165
|
+
stdout.write(renderReports(results, "json"));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return arbitrateExitCode(results.map((r) => r.report));
|
|
169
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { isInteractiveHumanTty, resolveLayeredConfig } from "../kernel/config.mjs";
|
|
3
|
+
import { listBuiltinPackIds } from "../kernel/pack-loader.mjs";
|
|
4
|
+
import {
|
|
5
|
+
detectOllamaBinary,
|
|
6
|
+
readInstalledModelsManifest,
|
|
7
|
+
} from "../runtime/providers/local-model.mjs";
|
|
8
|
+
import {
|
|
9
|
+
loadCloudCredentials,
|
|
10
|
+
resolveExecutionRoute,
|
|
11
|
+
resolveTier2ProviderCandidate,
|
|
12
|
+
} from "../runtime/router.mjs";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* `dislop doctor [--json]` — zero-network diagnostic snapshot of config, active tier, auth, voice, and Packs.
|
|
16
|
+
*/
|
|
17
|
+
export async function runDoctorCommand(_positionals, flags, io = {}) {
|
|
18
|
+
const {
|
|
19
|
+
cwd = process.cwd(),
|
|
20
|
+
env = process.env,
|
|
21
|
+
stdin = process.stdin,
|
|
22
|
+
stdout = process.stdout,
|
|
23
|
+
stderr = process.stderr,
|
|
24
|
+
} = io;
|
|
25
|
+
|
|
26
|
+
const isTty = isInteractiveHumanTty({ stdin, stdout, env });
|
|
27
|
+
const config = resolveLayeredConfig({ cwd, env, cliFlags: flags });
|
|
28
|
+
const cloudCreds = loadCloudCredentials(config.credentialsPath);
|
|
29
|
+
const tier2Candidate = resolveTier2ProviderCandidate(config, env);
|
|
30
|
+
const modelsManifest = readInstalledModelsManifest(config.modelsDir);
|
|
31
|
+
const ollama = detectOllamaBinary(env);
|
|
32
|
+
const builtinPacks = listBuiltinPackIds();
|
|
33
|
+
|
|
34
|
+
// Resolve route non-interactively so `doctor` never triggers consent prompts
|
|
35
|
+
const route = await resolveExecutionRoute({
|
|
36
|
+
config,
|
|
37
|
+
isTty: false,
|
|
38
|
+
env,
|
|
39
|
+
stdin,
|
|
40
|
+
stderr: { write() {} },
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const diagnosis = {
|
|
44
|
+
schema: "dislop.doctor/1",
|
|
45
|
+
nodeVersion: process.version,
|
|
46
|
+
interactiveTty: isTty,
|
|
47
|
+
routingMode: config.routing,
|
|
48
|
+
activeEngine: route.engineLabel,
|
|
49
|
+
activeTier: route.tier,
|
|
50
|
+
configSources: config.loadedSources,
|
|
51
|
+
approvedHosts: config.approvedHosts,
|
|
52
|
+
cloudAuthenticated: Boolean(cloudCreds),
|
|
53
|
+
byokCandidate: tier2Candidate
|
|
54
|
+
? {
|
|
55
|
+
name: tier2Candidate.name,
|
|
56
|
+
protocol: tier2Candidate.protocol,
|
|
57
|
+
model: tier2Candidate.model,
|
|
58
|
+
baseUrl: tier2Candidate.baseUrl,
|
|
59
|
+
fromAmbientEnv: tier2Candidate.fromAmbientEnv,
|
|
60
|
+
}
|
|
61
|
+
: null,
|
|
62
|
+
localModels: {
|
|
63
|
+
ollamaInstalled: ollama.installed,
|
|
64
|
+
ollamaBinary: ollama.binaryPath,
|
|
65
|
+
activeModel: modelsManifest.activeModel,
|
|
66
|
+
installed: Object.keys(modelsManifest.installed),
|
|
67
|
+
},
|
|
68
|
+
voiceCachePresent: Boolean(config.voice?.cachePath && fs.existsSync(config.voice.cachePath)),
|
|
69
|
+
configuredPacks: config.packs || ["(auto by document format & language)"],
|
|
70
|
+
builtinPacks,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
if (flags.json || flags.format === "json") {
|
|
74
|
+
stdout.write(`${JSON.stringify(diagnosis, null, 2)}\n`);
|
|
75
|
+
return 0;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
stdout.write("dislop doctor\n");
|
|
79
|
+
stdout.write(` Node.js : ${diagnosis.nodeVersion}\n`);
|
|
80
|
+
stdout.write(` Interactive TTY : ${diagnosis.interactiveTty ? "yes" : "no (read-only / batch safe)"}\n`);
|
|
81
|
+
stdout.write(` Routing Mode : ${diagnosis.routingMode} -> active engine '${diagnosis.activeEngine}'\n`);
|
|
82
|
+
stdout.write(
|
|
83
|
+
` Config Files : ${diagnosis.configSources.length > 0 ? diagnosis.configSources.join(", ") : "(defaults only)"}\n`,
|
|
84
|
+
);
|
|
85
|
+
stdout.write(` Cloud Tier 1 : ${diagnosis.cloudAuthenticated ? "authenticated" : "not logged in"}\n`);
|
|
86
|
+
stdout.write(
|
|
87
|
+
` BYOK Tier 2 : ${
|
|
88
|
+
diagnosis.byokCandidate
|
|
89
|
+
? `${diagnosis.byokCandidate.name} (${diagnosis.byokCandidate.protocol}:${diagnosis.byokCandidate.model})`
|
|
90
|
+
: "not configured"
|
|
91
|
+
}\n`,
|
|
92
|
+
);
|
|
93
|
+
stdout.write(
|
|
94
|
+
` Approved Hosts : ${diagnosis.approvedHosts.length > 0 ? diagnosis.approvedHosts.join(", ") : "(none)"}\n`,
|
|
95
|
+
);
|
|
96
|
+
const ollamaStatusText = diagnosis.localModels.ollamaInstalled
|
|
97
|
+
? `Ollama: ${diagnosis.localModels.ollamaBinary}`
|
|
98
|
+
: "Ollama: MISSING — install from https://ollama.com";
|
|
99
|
+
stdout.write(
|
|
100
|
+
` Local Tier 3 : ${
|
|
101
|
+
diagnosis.localModels.installed.length > 0
|
|
102
|
+
? diagnosis.localModels.installed.join(", ")
|
|
103
|
+
: "none installed (run 'dislop model pull')"
|
|
104
|
+
} (${ollamaStatusText})\n`,
|
|
105
|
+
);
|
|
106
|
+
stdout.write(` Voice Profile : ${diagnosis.voiceCachePresent ? "cached" : "not configured"}\n`);
|
|
107
|
+
stdout.write(` Built-in Packs : ${diagnosis.builtinPacks.join(", ")}\n`);
|
|
108
|
+
|
|
109
|
+
return 0;
|
|
110
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { getDislopHomeDir, writeJsonFileSecure } from "../kernel/config.mjs";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* `dislop init [--global] [--voice <glob>] [--force]`
|
|
7
|
+
*/
|
|
8
|
+
export async function runInitCommand(_positionals, flags, io = {}) {
|
|
9
|
+
const { cwd = process.cwd(), env = process.env, stdout = process.stdout } = io;
|
|
10
|
+
|
|
11
|
+
const targetPath = flags.global
|
|
12
|
+
? path.join(getDislopHomeDir(env), "config.json")
|
|
13
|
+
: path.join(cwd, ".dislop.json");
|
|
14
|
+
|
|
15
|
+
if (fs.existsSync(targetPath) && !flags.force) {
|
|
16
|
+
stdout.write(`Config already exists at ${targetPath} (pass --force to overwrite).\n`);
|
|
17
|
+
return 0;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const voiceRefs = flags.voiceFiles && flags.voiceFiles.length > 0 ? flags.voiceFiles : [];
|
|
21
|
+
|
|
22
|
+
const template = {
|
|
23
|
+
routing: "local",
|
|
24
|
+
approvedHosts: [],
|
|
25
|
+
packs: ["artifact-qa", "web-ui", "slide-deck", "prose"],
|
|
26
|
+
voice: {
|
|
27
|
+
referenceFiles: voiceRefs,
|
|
28
|
+
},
|
|
29
|
+
providers: {
|
|
30
|
+
"local-ollama": {
|
|
31
|
+
protocol: "openai",
|
|
32
|
+
baseUrl: "http://127.0.0.1:11434/v1",
|
|
33
|
+
apiKey: "ollama",
|
|
34
|
+
model: "qwen2.5:7b",
|
|
35
|
+
structuredOutput: "json_object",
|
|
36
|
+
maxInputTokens: 8000,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
if (flags.global) {
|
|
42
|
+
writeJsonFileSecure(targetPath, template, { mode: 0o600 });
|
|
43
|
+
} else {
|
|
44
|
+
fs.writeFileSync(targetPath, `${JSON.stringify(template, null, 2)}\n`, "utf8");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
stdout.write(`Initialized dislop configuration at ${targetPath}\n`);
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import readline from "node:readline";
|
|
4
|
+
import {
|
|
5
|
+
DislopConfigError,
|
|
6
|
+
getDislopHomeDir,
|
|
7
|
+
isInteractiveHumanTty,
|
|
8
|
+
writeJsonFileSecure,
|
|
9
|
+
} from "../kernel/config.mjs";
|
|
10
|
+
import { DEFAULT_CLOUD_REVIEW_URL } from "../runtime/providers/cloud.mjs";
|
|
11
|
+
|
|
12
|
+
function promptTokenInteractive({ stdin = process.stdin, stderr = process.stderr } = {}) {
|
|
13
|
+
return new Promise((resolve) => {
|
|
14
|
+
const rl = readline.createInterface({ input: stdin, output: stderr });
|
|
15
|
+
rl.question(
|
|
16
|
+
"Sign in at https://dislop.com to generate an API key (dslp_*), then paste token here: ",
|
|
17
|
+
(answer) => {
|
|
18
|
+
rl.close();
|
|
19
|
+
resolve(String(answer || "").trim());
|
|
20
|
+
},
|
|
21
|
+
);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* `dislop login [--token <token>] [--endpoint <url>]`
|
|
27
|
+
*/
|
|
28
|
+
export async function runLoginCommand(_positionals, flags, io = {}) {
|
|
29
|
+
const {
|
|
30
|
+
env = process.env,
|
|
31
|
+
stdin = process.stdin,
|
|
32
|
+
stdout = process.stdout,
|
|
33
|
+
stderr = process.stderr,
|
|
34
|
+
} = io;
|
|
35
|
+
|
|
36
|
+
const homeDir = getDislopHomeDir(env);
|
|
37
|
+
const credentialsPath = path.join(homeDir, "credentials.json");
|
|
38
|
+
|
|
39
|
+
let token = flags.token ? String(flags.token).trim() : "";
|
|
40
|
+
if (!token) {
|
|
41
|
+
if (!isInteractiveHumanTty({ stdin, stdout, env })) {
|
|
42
|
+
throw new DislopConfigError(
|
|
43
|
+
"Non-interactive 'dislop login' requires --token <dslp_token>.",
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
token = await promptTokenInteractive({ stdin, stderr });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (!token) {
|
|
50
|
+
throw new DislopConfigError("No token supplied; login aborted.");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const endpoint = flags.endpoint || DEFAULT_CLOUD_REVIEW_URL;
|
|
54
|
+
writeJsonFileSecure(
|
|
55
|
+
credentialsPath,
|
|
56
|
+
{
|
|
57
|
+
accessToken: token,
|
|
58
|
+
endpoint,
|
|
59
|
+
savedAt: new Date().toISOString(),
|
|
60
|
+
},
|
|
61
|
+
{ mode: 0o600 },
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
stdout.write(`Saved Official Cloud credentials to ${credentialsPath}\n`);
|
|
65
|
+
return 0;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* `dislop logout`
|
|
70
|
+
*/
|
|
71
|
+
export async function runLogoutCommand(_positionals, _flags, io = {}) {
|
|
72
|
+
const { env = process.env, stdout = process.stdout } = io;
|
|
73
|
+
const credentialsPath = path.join(getDislopHomeDir(env), "credentials.json");
|
|
74
|
+
|
|
75
|
+
if (fs.existsSync(credentialsPath)) {
|
|
76
|
+
fs.unlinkSync(credentialsPath);
|
|
77
|
+
stdout.write(`Removed credentials at ${credentialsPath}\n`);
|
|
78
|
+
} else {
|
|
79
|
+
stdout.write("No active Official Cloud credentials found.\n");
|
|
80
|
+
}
|
|
81
|
+
return 0;
|
|
82
|
+
}
|