dislop 0.9.1 → 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 -63
- 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 -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 +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 +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/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
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { DislopConfigError, getDislopHomeDir, writeJsonFileSecure } from "../kernel/config.mjs";
|
|
4
|
+
import {
|
|
5
|
+
LOCAL_MODEL_CATALOG,
|
|
6
|
+
OLLAMA_INSTALL_HINT,
|
|
7
|
+
detectOllamaBinary,
|
|
8
|
+
readInstalledModelsManifest,
|
|
9
|
+
} from "../runtime/providers/local-model.mjs";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* `dislop model <pull|list|rm> [name] [--endpoint <url>]`
|
|
13
|
+
*/
|
|
14
|
+
export async function runModelCommand(positionals, flags, io = {}) {
|
|
15
|
+
const { env = process.env, stdout = process.stdout, stderr = process.stderr } = io;
|
|
16
|
+
|
|
17
|
+
const action = positionals[0] || "list";
|
|
18
|
+
const modelArg = positionals[1] || "";
|
|
19
|
+
const modelsDir = path.join(getDislopHomeDir(env), "models");
|
|
20
|
+
const manifestPath = path.join(modelsDir, "manifest.json");
|
|
21
|
+
const manifest = readInstalledModelsManifest(modelsDir);
|
|
22
|
+
const ollama = detectOllamaBinary(env);
|
|
23
|
+
|
|
24
|
+
if (action === "list") {
|
|
25
|
+
const installedNames = Object.keys(manifest.installed);
|
|
26
|
+
if (flags.json || flags.format === "json") {
|
|
27
|
+
stdout.write(
|
|
28
|
+
`${JSON.stringify(
|
|
29
|
+
{
|
|
30
|
+
ollamaInstalled: ollama.installed,
|
|
31
|
+
ollamaBinary: ollama.binaryPath,
|
|
32
|
+
activeModel: manifest.activeModel,
|
|
33
|
+
installed: manifest.installed,
|
|
34
|
+
catalog: LOCAL_MODEL_CATALOG,
|
|
35
|
+
},
|
|
36
|
+
null,
|
|
37
|
+
2,
|
|
38
|
+
)}\n`,
|
|
39
|
+
);
|
|
40
|
+
return 0;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
stdout.write("Tier 3 Local Model Catalog (powered by Ollama — https://ollama.com):\n");
|
|
44
|
+
for (const [id, spec] of Object.entries(LOCAL_MODEL_CATALOG)) {
|
|
45
|
+
const isInstalled = Boolean(manifest.installed[id]);
|
|
46
|
+
const isActive = manifest.activeModel === id;
|
|
47
|
+
const badge = isActive ? "[active]" : isInstalled ? "[installed]" : "[available]";
|
|
48
|
+
stdout.write(` - ${id} (${spec.sizeLabel}) ${badge} — ${spec.description}\n`);
|
|
49
|
+
}
|
|
50
|
+
if (!ollama.installed) {
|
|
51
|
+
stdout.write(
|
|
52
|
+
`\nWarning: Ollama is missing on this machine (required for Tier 3 local models).\n ${OLLAMA_INSTALL_HINT}\n`,
|
|
53
|
+
);
|
|
54
|
+
} else if (installedNames.length === 0) {
|
|
55
|
+
stdout.write(
|
|
56
|
+
`\nOllama detected (${ollama.binaryPath}). Start 'ollama serve' and run 'dislop model pull qwen2.5-1.5b-instruct' to enable Tier 3 local semantic checks.\n`,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
return 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (action === "pull") {
|
|
63
|
+
const targetId = modelArg || "qwen2.5-1.5b-instruct";
|
|
64
|
+
const catalogEntry = LOCAL_MODEL_CATALOG[targetId] || {
|
|
65
|
+
name: targetId,
|
|
66
|
+
ollamaTag: targetId,
|
|
67
|
+
sizeLabel: "custom",
|
|
68
|
+
maxInputTokens: 8000,
|
|
69
|
+
description: "Custom local model",
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const customEndpoint = flags.endpoint || env.DISLOP_LOCAL_MODEL_URL || null;
|
|
73
|
+
const baseUrl = customEndpoint || "http://127.0.0.1:11434/v1";
|
|
74
|
+
|
|
75
|
+
// Require Ollama CLI unless running against a custom endpoint or in offline unit test mode
|
|
76
|
+
if (!env.DISLOP_SKIP_OLLAMA_PULL) {
|
|
77
|
+
if (!ollama.installed && !customEndpoint) {
|
|
78
|
+
throw new DislopConfigError(
|
|
79
|
+
`Ollama is missing on this machine (required by 'dislop model pull'). ${OLLAMA_INSTALL_HINT}`,
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
if (ollama.installed) {
|
|
83
|
+
stderr.write(`Pulling '${catalogEntry.ollamaTag}' via local Ollama (${ollama.binaryPath})...\n`);
|
|
84
|
+
const pullRes = spawnSync(ollama.binaryPath, ["pull", catalogEntry.ollamaTag], {
|
|
85
|
+
stdio: "inherit",
|
|
86
|
+
});
|
|
87
|
+
if (pullRes.status !== 0) {
|
|
88
|
+
throw new DislopConfigError(
|
|
89
|
+
`Ollama failed to pull '${catalogEntry.ollamaTag}'. Ensure 'ollama serve' (or the Ollama app) is running, then retry.`,
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
manifest.installed[targetId] = {
|
|
96
|
+
name: targetId,
|
|
97
|
+
ollamaTag: catalogEntry.ollamaTag,
|
|
98
|
+
runtimeModel: catalogEntry.ollamaTag,
|
|
99
|
+
baseUrl,
|
|
100
|
+
maxInputTokens: catalogEntry.maxInputTokens,
|
|
101
|
+
installedAt: new Date().toISOString(),
|
|
102
|
+
};
|
|
103
|
+
manifest.activeModel = targetId;
|
|
104
|
+
|
|
105
|
+
writeJsonFileSecure(manifestPath, manifest, { mode: 0o600 });
|
|
106
|
+
stdout.write(`Registered active Tier 3 local model '${targetId}' -> ${baseUrl}\n`);
|
|
107
|
+
return 0;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (action === "rm" || action === "remove") {
|
|
111
|
+
if (!modelArg) {
|
|
112
|
+
throw new DislopConfigError("Usage: dislop model rm <model-name>");
|
|
113
|
+
}
|
|
114
|
+
if (!manifest.installed[modelArg]) {
|
|
115
|
+
stdout.write(`Model '${modelArg}' is not installed.\n`);
|
|
116
|
+
return 0;
|
|
117
|
+
}
|
|
118
|
+
delete manifest.installed[modelArg];
|
|
119
|
+
if (manifest.activeModel === modelArg) {
|
|
120
|
+
manifest.activeModel = Object.keys(manifest.installed)[0] || null;
|
|
121
|
+
}
|
|
122
|
+
writeJsonFileSecure(manifestPath, manifest, { mode: 0o600 });
|
|
123
|
+
stdout.write(`Removed Tier 3 local model '${modelArg}'.\n`);
|
|
124
|
+
return 0;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
throw new DislopConfigError(
|
|
128
|
+
`Unknown 'dislop model' subcommand '${action}' (expected list, pull, or rm)`,
|
|
129
|
+
);
|
|
130
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { listBuiltinPackIds, loadSinglePack } from "../kernel/pack-loader.mjs";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `dislop packs [--json]` — inspect built-in multi-level Packs via `pack.json` metadata
|
|
5
|
+
* without importing `scripts/` or reading `prompts/`.
|
|
6
|
+
*/
|
|
7
|
+
export async function runPacksCommand(_positionals, flags, io = {}) {
|
|
8
|
+
const { cwd = process.cwd(), stdout = process.stdout } = io;
|
|
9
|
+
|
|
10
|
+
const ids = listBuiltinPackIds();
|
|
11
|
+
const details = [];
|
|
12
|
+
for (const id of ids) {
|
|
13
|
+
const p = await loadSinglePack(id, { cwd });
|
|
14
|
+
details.push({
|
|
15
|
+
name: p.name,
|
|
16
|
+
version: p.version,
|
|
17
|
+
description: p.description,
|
|
18
|
+
languages: p.languages || ["all"],
|
|
19
|
+
formats: p.formats || ["all"],
|
|
20
|
+
hasScripts: Boolean(p.hasScripts),
|
|
21
|
+
hasPrompts: Boolean(p.hasPrompts),
|
|
22
|
+
scriptFileCount: p.loadStats?.scriptFileCount ?? 0,
|
|
23
|
+
promptFileCount: p.loadStats?.promptFileCount ?? 0,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (flags.json || flags.format === "json") {
|
|
28
|
+
stdout.write(`${JSON.stringify({ packs: details }, null, 2)}\n`);
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
stdout.write("Built-in Packs (Layout: packs/<scope-or-lang>/<scenario>/{pack.json,scripts/,prompts/}):\n");
|
|
33
|
+
for (const d of details) {
|
|
34
|
+
const layers = [
|
|
35
|
+
d.hasScripts ? `scripts(${d.scriptFileCount})` : null,
|
|
36
|
+
d.hasPrompts ? `prompts(${d.promptFileCount})` : null,
|
|
37
|
+
]
|
|
38
|
+
.filter(Boolean)
|
|
39
|
+
.join(", ");
|
|
40
|
+
stdout.write(` - ${d.name} (v${d.version}) [${layers}]\n`);
|
|
41
|
+
stdout.write(` ${d.description}\n`);
|
|
42
|
+
}
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import crypto from "node:crypto";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { DislopConfigError } from "../kernel/config.mjs";
|
|
7
|
+
import { detectFormatFromPath, parseDocumentFile, parseDocumentText } from "../kernel/document-model.mjs";
|
|
8
|
+
import { verifyDocumentRevision } from "../kernel/fact-gate.mjs";
|
|
9
|
+
|
|
10
|
+
function extractComparableText(filePath) {
|
|
11
|
+
const doc = parseDocumentFile(filePath);
|
|
12
|
+
if (doc.segments.length > 0) {
|
|
13
|
+
return doc.segments.map((s) => s.text).join("\n");
|
|
14
|
+
}
|
|
15
|
+
return fs.readFileSync(filePath, "utf8");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function extractComparableTextFromBuffer(buf, targetPath) {
|
|
19
|
+
const fmt = detectFormatFromPath(targetPath);
|
|
20
|
+
if (fmt === "docx" || fmt === "pptx" || fmt === "pdf") {
|
|
21
|
+
const tmpFile = path.join(
|
|
22
|
+
os.tmpdir(),
|
|
23
|
+
`dislop-verify-${process.pid}-${crypto.randomBytes(4).toString("hex")}.${fmt}`,
|
|
24
|
+
);
|
|
25
|
+
fs.writeFileSync(tmpFile, buf);
|
|
26
|
+
try {
|
|
27
|
+
return extractComparableText(tmpFile);
|
|
28
|
+
} finally {
|
|
29
|
+
if (fs.existsSync(tmpFile)) fs.unlinkSync(tmpFile);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const text = buf.toString("utf8");
|
|
33
|
+
if (fmt) {
|
|
34
|
+
const doc = parseDocumentText(text, targetPath, fmt);
|
|
35
|
+
if (doc.segments.length > 0) {
|
|
36
|
+
return doc.segments.map((s) => s.text).join("\n");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return text;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* `dislop verify <beforeFile> <afterFile> [--json]`
|
|
44
|
+
* or `dislop verify --git [ref] <file> [--json]`
|
|
45
|
+
*/
|
|
46
|
+
export async function runVerifyCommand(positionals, flags, io = {}) {
|
|
47
|
+
const { cwd = process.cwd(), stdout = process.stdout } = io;
|
|
48
|
+
|
|
49
|
+
let beforeText = "";
|
|
50
|
+
let afterText = "";
|
|
51
|
+
let label = "";
|
|
52
|
+
|
|
53
|
+
if (flags.git !== undefined && flags.git !== false) {
|
|
54
|
+
const gitRef = typeof flags.git === "string" && flags.git.trim() ? flags.git.trim() : "HEAD";
|
|
55
|
+
const targetArg = positionals[0];
|
|
56
|
+
if (!targetArg) {
|
|
57
|
+
throw new DislopConfigError(
|
|
58
|
+
"Usage: dislop verify --git [ref] <file> (missing target file)",
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
const resolvedTarget = path.resolve(cwd, targetArg);
|
|
62
|
+
if (!fs.existsSync(resolvedTarget)) {
|
|
63
|
+
throw new DislopConfigError(`Target file not found: '${targetArg}'`);
|
|
64
|
+
}
|
|
65
|
+
const absTarget = fs.realpathSync(resolvedTarget);
|
|
66
|
+
|
|
67
|
+
let repoRoot;
|
|
68
|
+
try {
|
|
69
|
+
repoRoot = execFileSync("git", ["rev-parse", "--show-toplevel"], {
|
|
70
|
+
cwd: path.dirname(absTarget),
|
|
71
|
+
encoding: "utf8",
|
|
72
|
+
}).trim();
|
|
73
|
+
} catch (err) {
|
|
74
|
+
throw new DislopConfigError(`Unable to locate git repository for --git verify: ${err.message}`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const relGitPath = path.relative(repoRoot, absTarget).replace(/\\/g, "/");
|
|
78
|
+
let beforeBuf;
|
|
79
|
+
try {
|
|
80
|
+
beforeBuf = execFileSync("git", ["show", `${gitRef}:${relGitPath}`], {
|
|
81
|
+
cwd: repoRoot,
|
|
82
|
+
maxBuffer: 32 * 1024 * 1024,
|
|
83
|
+
});
|
|
84
|
+
} catch (err) {
|
|
85
|
+
throw new DislopConfigError(
|
|
86
|
+
`Could not read '${relGitPath}' at git ref '${gitRef}': ${err.message}`,
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
beforeText = extractComparableTextFromBuffer(beforeBuf, absTarget);
|
|
90
|
+
afterText = extractComparableText(absTarget);
|
|
91
|
+
label = `${gitRef}:${relGitPath} -> ${targetArg}`;
|
|
92
|
+
} else {
|
|
93
|
+
if (positionals.length < 2) {
|
|
94
|
+
throw new DislopConfigError(
|
|
95
|
+
"Usage: dislop verify <before-file> <after-file> (or dislop verify --git [ref] <file>)",
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
const beforePath = path.resolve(cwd, positionals[0]);
|
|
99
|
+
const afterPath = path.resolve(cwd, positionals[1]);
|
|
100
|
+
if (!fs.existsSync(beforePath)) {
|
|
101
|
+
throw new DislopConfigError(`Before file not found: '${positionals[0]}'`);
|
|
102
|
+
}
|
|
103
|
+
if (!fs.existsSync(afterPath)) {
|
|
104
|
+
throw new DislopConfigError(`After file not found: '${positionals[1]}'`);
|
|
105
|
+
}
|
|
106
|
+
beforeText = extractComparableText(beforePath);
|
|
107
|
+
afterText = extractComparableText(afterPath);
|
|
108
|
+
label = `${positionals[0]} -> ${positionals[1]}`;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const verification = verifyDocumentRevision(beforeText, afterText);
|
|
112
|
+
const payload = {
|
|
113
|
+
schema: "dislop.verify/1",
|
|
114
|
+
target: label,
|
|
115
|
+
...verification,
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
if (flags.json || flags.format === "json") {
|
|
119
|
+
stdout.write(`${JSON.stringify(payload, null, 2)}\n`);
|
|
120
|
+
} else if (verification.ok) {
|
|
121
|
+
stdout.write(`PASS ${label}: all protected facts preserved; 0 second-order slop regressions.\n`);
|
|
122
|
+
} else {
|
|
123
|
+
stdout.write(`FAIL ${label}:\n`);
|
|
124
|
+
for (const reason of verification.droppedFacts) {
|
|
125
|
+
stdout.write(` - Fact Gate: ${reason}\n`);
|
|
126
|
+
}
|
|
127
|
+
for (const reg of verification.regressions) {
|
|
128
|
+
stdout.write(` - Regression (${reg.id}): ${reg.message}\n`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return verification.ok ? 0 : 1;
|
|
133
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import {
|
|
3
|
+
DislopConfigError,
|
|
4
|
+
isInteractiveHumanTty,
|
|
5
|
+
readJsonFileStrict,
|
|
6
|
+
resolveLayeredConfig,
|
|
7
|
+
writeJsonFileSecure,
|
|
8
|
+
} from "../kernel/config.mjs";
|
|
9
|
+
import { expandTargetInputs } from "../kernel/file-discovery.mjs";
|
|
10
|
+
import { extractVoiceProfile } from "../kernel/voice-profile.mjs";
|
|
11
|
+
import { resolveExecutionRoute } from "../runtime/router.mjs";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* `dislop voice <extract|show|clear> [files/globs...]`
|
|
15
|
+
*/
|
|
16
|
+
export async function runVoiceCommand(positionals, flags, io = {}) {
|
|
17
|
+
const {
|
|
18
|
+
cwd = process.cwd(),
|
|
19
|
+
env = process.env,
|
|
20
|
+
stdin = process.stdin,
|
|
21
|
+
stdout = process.stdout,
|
|
22
|
+
stderr = process.stderr,
|
|
23
|
+
fetchImpl = globalThis.fetch,
|
|
24
|
+
} = io;
|
|
25
|
+
|
|
26
|
+
const action = positionals[0] || "show";
|
|
27
|
+
const targets = positionals.slice(1);
|
|
28
|
+
const config = resolveLayeredConfig({ cwd, env, cliFlags: flags });
|
|
29
|
+
const cachePath = config.voice.cachePath;
|
|
30
|
+
|
|
31
|
+
if (action === "show") {
|
|
32
|
+
if (!fs.existsSync(cachePath)) {
|
|
33
|
+
stdout.write(`No cached voice profile at ${cachePath}. Run 'dislop voice extract <files...>'.\n`);
|
|
34
|
+
return 0;
|
|
35
|
+
}
|
|
36
|
+
const profile = readJsonFileStrict(cachePath);
|
|
37
|
+
if (flags.json || flags.format === "json") {
|
|
38
|
+
stdout.write(`${JSON.stringify(profile, null, 2)}\n`);
|
|
39
|
+
} else {
|
|
40
|
+
stdout.write(`Voice Profile (${cachePath}):\n`);
|
|
41
|
+
stdout.write(` Language : ${profile.language}\n`);
|
|
42
|
+
stdout.write(` Summary : ${profile.summary}\n`);
|
|
43
|
+
stdout.write(` Anchors : ${(profile.voiceAnchors || []).join("; ") || "(none)"}\n`);
|
|
44
|
+
stdout.write(` Connectors : ${(profile.preferredConnectors || []).join(", ") || "(none)"}\n`);
|
|
45
|
+
}
|
|
46
|
+
return 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (action === "clear") {
|
|
50
|
+
if (fs.existsSync(cachePath)) {
|
|
51
|
+
fs.unlinkSync(cachePath);
|
|
52
|
+
stdout.write(`Cleared voice profile at ${cachePath}\n`);
|
|
53
|
+
} else {
|
|
54
|
+
stdout.write("No cached voice profile to clear.\n");
|
|
55
|
+
}
|
|
56
|
+
return 0;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (action === "extract") {
|
|
60
|
+
const fileInputs = targets.length > 0 ? targets : config.voice.referenceFiles;
|
|
61
|
+
if (!fileInputs || fileInputs.length === 0) {
|
|
62
|
+
throw new DislopConfigError(
|
|
63
|
+
"Usage: dislop voice extract <files/globs...> (no reference files provided)",
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
const resolvedFiles = expandTargetInputs(fileInputs, { cwd });
|
|
67
|
+
const isTty = isInteractiveHumanTty({ stdin, stdout, env });
|
|
68
|
+
const route = await resolveExecutionRoute({ config, isTty, env, stdin, stderr, fetchImpl });
|
|
69
|
+
const profile = await extractVoiceProfile(resolvedFiles, { route });
|
|
70
|
+
writeJsonFileSecure(cachePath, profile, { mode: 0o600 });
|
|
71
|
+
|
|
72
|
+
if (flags.json || flags.format === "json") {
|
|
73
|
+
stdout.write(`${JSON.stringify(profile, null, 2)}\n`);
|
|
74
|
+
} else {
|
|
75
|
+
stdout.write(`Saved personal voice profile to ${cachePath} (${resolvedFiles.length} file(s)).\n`);
|
|
76
|
+
stdout.write(` Summary: ${profile.summary}\n`);
|
|
77
|
+
}
|
|
78
|
+
return 0;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
throw new DislopConfigError(
|
|
82
|
+
`Unknown 'dislop voice' subcommand '${action}' (expected extract, show, or clear)`,
|
|
83
|
+
);
|
|
84
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
|
|
6
|
+
export class DislopConfigError extends Error {
|
|
7
|
+
constructor(message) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = "DislopConfigError";
|
|
10
|
+
this.exitCode = 2;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function getDislopHomeDir(env = process.env) {
|
|
15
|
+
if (env.DISLOP_CONFIG_DIR) {
|
|
16
|
+
return path.resolve(env.DISLOP_CONFIG_DIR);
|
|
17
|
+
}
|
|
18
|
+
const xdg = env.XDG_CONFIG_HOME;
|
|
19
|
+
if (xdg) {
|
|
20
|
+
return path.join(xdg, "dislop");
|
|
21
|
+
}
|
|
22
|
+
return path.join(os.homedir(), ".config", "dislop");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function expandTilde(filePath, env = process.env) {
|
|
26
|
+
const s = String(filePath || "");
|
|
27
|
+
if (s === "~") return env.HOME || os.homedir();
|
|
28
|
+
if (s.startsWith("~/") || s.startsWith("~\\")) {
|
|
29
|
+
return path.join(env.HOME || os.homedir(), s.slice(2));
|
|
30
|
+
}
|
|
31
|
+
return s;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Detect whether the current process is attached to an interactive human terminal
|
|
36
|
+
* (false in pipes, CI runners, `TERM=dumb`, and known coding agent sandboxes).
|
|
37
|
+
*/
|
|
38
|
+
export function isInteractiveHumanTty({
|
|
39
|
+
stdin = process.stdin,
|
|
40
|
+
stdout = process.stdout,
|
|
41
|
+
env = process.env,
|
|
42
|
+
} = {}) {
|
|
43
|
+
if (env.DISLOP_FORCE_TTY === "1") return true;
|
|
44
|
+
if (env.DISLOP_FORCE_NON_TTY === "1") return false;
|
|
45
|
+
if (!stdin?.isTTY || !stdout?.isTTY) return false;
|
|
46
|
+
if (env.CI && env.CI !== "0" && env.CI !== "false") return false;
|
|
47
|
+
if (env.TERM === "dumb") return false;
|
|
48
|
+
if (
|
|
49
|
+
env.CLAUDECODE ||
|
|
50
|
+
env.CODEX_SANDBOX ||
|
|
51
|
+
env.CURSOR_AGENT ||
|
|
52
|
+
env.ANTIGRAVITY_AGENT ||
|
|
53
|
+
env.GITHUB_ACTIONS
|
|
54
|
+
) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function readJsonFileStrict(filePath) {
|
|
61
|
+
if (!fs.existsSync(filePath)) return null;
|
|
62
|
+
let raw;
|
|
63
|
+
try {
|
|
64
|
+
raw = fs.readFileSync(filePath, "utf8");
|
|
65
|
+
} catch (err) {
|
|
66
|
+
throw new DislopConfigError(`Unable to read config file '${filePath}': ${err.message}`);
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
const parsed = JSON.parse(raw);
|
|
70
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
71
|
+
throw new Error("root value must be a JSON object");
|
|
72
|
+
}
|
|
73
|
+
return parsed;
|
|
74
|
+
} catch (err) {
|
|
75
|
+
throw new DislopConfigError(`Invalid JSON in '${filePath}': ${err.message}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function writeJsonFileSecure(filePath, data, { mode = 0o600 } = {}) {
|
|
80
|
+
const dir = path.dirname(filePath);
|
|
81
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
82
|
+
const tmp = path.join(dir, `.tmp-${process.pid}-${crypto.randomBytes(4).toString("hex")}`);
|
|
83
|
+
fs.writeFileSync(tmp, `${JSON.stringify(data, null, 2)}\n`, { encoding: "utf8", mode });
|
|
84
|
+
fs.renameSync(tmp, filePath);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const VALID_ROUTING_MODES = new Set(["local", "auto", "cloud", "byok"]);
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Resolve layered configuration:
|
|
91
|
+
* `~/.config/dislop/config.json` <- `<cwd>/.dislop.json` <- `<cwd>/.dislop.local.json` <- CLI flags.
|
|
92
|
+
*/
|
|
93
|
+
export function resolveLayeredConfig({ cwd = process.cwd(), env = process.env, cliFlags = {} } = {}) {
|
|
94
|
+
const homeDir = getDislopHomeDir(env);
|
|
95
|
+
const userConfigPath = path.join(homeDir, "config.json");
|
|
96
|
+
const projectConfigPath = path.join(cwd, ".dislop.json");
|
|
97
|
+
const localConfigPath = path.join(cwd, ".dislop.local.json");
|
|
98
|
+
|
|
99
|
+
const defaults = {
|
|
100
|
+
routing: "local",
|
|
101
|
+
activeProvider: null,
|
|
102
|
+
approvedHosts: [],
|
|
103
|
+
packs: null,
|
|
104
|
+
lang: "auto",
|
|
105
|
+
level: "all",
|
|
106
|
+
voice: {
|
|
107
|
+
referenceFiles: [],
|
|
108
|
+
cachePath: path.join(homeDir, "voice.json"),
|
|
109
|
+
},
|
|
110
|
+
providers: {},
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const layers = [
|
|
114
|
+
{ source: userConfigPath, data: readJsonFileStrict(userConfigPath) },
|
|
115
|
+
{ source: projectConfigPath, data: readJsonFileStrict(projectConfigPath) },
|
|
116
|
+
{ source: localConfigPath, data: readJsonFileStrict(localConfigPath) },
|
|
117
|
+
];
|
|
118
|
+
|
|
119
|
+
const merged = structuredClone(defaults);
|
|
120
|
+
const loadedSources = [];
|
|
121
|
+
|
|
122
|
+
for (const layer of layers) {
|
|
123
|
+
if (!layer.data) continue;
|
|
124
|
+
loadedSources.push(layer.source);
|
|
125
|
+
const d = layer.data;
|
|
126
|
+
|
|
127
|
+
if (d.routing !== undefined) {
|
|
128
|
+
if (!VALID_ROUTING_MODES.has(d.routing)) {
|
|
129
|
+
throw new DislopConfigError(
|
|
130
|
+
`Invalid 'routing' value '${d.routing}' in '${layer.source}' (expected local, auto, cloud, or byok)`,
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
merged.routing = d.routing;
|
|
134
|
+
}
|
|
135
|
+
if (d.activeProvider !== undefined) {
|
|
136
|
+
merged.activeProvider = d.activeProvider ? String(d.activeProvider) : null;
|
|
137
|
+
}
|
|
138
|
+
if (d.approvedHosts !== undefined) {
|
|
139
|
+
if (!Array.isArray(d.approvedHosts)) {
|
|
140
|
+
throw new DislopConfigError(`'approvedHosts' in '${layer.source}' must be an array`);
|
|
141
|
+
}
|
|
142
|
+
merged.approvedHosts = Array.from(new Set([...merged.approvedHosts, ...d.approvedHosts.map(String)]));
|
|
143
|
+
}
|
|
144
|
+
if (d.packs !== undefined) {
|
|
145
|
+
if (!Array.isArray(d.packs)) {
|
|
146
|
+
throw new DislopConfigError(`'packs' in '${layer.source}' must be an array`);
|
|
147
|
+
}
|
|
148
|
+
merged.packs = d.packs.map(String);
|
|
149
|
+
}
|
|
150
|
+
if (d.lang !== undefined) {
|
|
151
|
+
merged.lang = String(d.lang);
|
|
152
|
+
}
|
|
153
|
+
if (d.level !== undefined) {
|
|
154
|
+
merged.level = String(d.level);
|
|
155
|
+
}
|
|
156
|
+
if (d.voice && typeof d.voice === "object" && !Array.isArray(d.voice)) {
|
|
157
|
+
if (Array.isArray(d.voice.referenceFiles)) {
|
|
158
|
+
merged.voice.referenceFiles = d.voice.referenceFiles.map((f) =>
|
|
159
|
+
path.resolve(path.dirname(layer.source), expandTilde(f, env)),
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
if (d.voice.cachePath) {
|
|
163
|
+
merged.voice.cachePath = path.resolve(cwd, expandTilde(d.voice.cachePath, env));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (d.providers && typeof d.providers === "object" && !Array.isArray(d.providers)) {
|
|
167
|
+
for (const [provName, provCfg] of Object.entries(d.providers)) {
|
|
168
|
+
if (!provCfg || typeof provCfg !== "object") continue;
|
|
169
|
+
merged.providers[provName] = { ...merged.providers[provName], ...provCfg };
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Apply CLI flag overrides
|
|
175
|
+
const explicitEngine = Boolean(cliFlags.engine);
|
|
176
|
+
if (cliFlags.engine) {
|
|
177
|
+
if (!VALID_ROUTING_MODES.has(cliFlags.engine)) {
|
|
178
|
+
throw new DislopConfigError(
|
|
179
|
+
`Invalid --engine '${cliFlags.engine}' (expected auto, cloud, byok, or local)`,
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
merged.routing = cliFlags.engine;
|
|
183
|
+
}
|
|
184
|
+
if (cliFlags.provider) {
|
|
185
|
+
merged.activeProvider = String(cliFlags.provider);
|
|
186
|
+
}
|
|
187
|
+
if (cliFlags.packs && cliFlags.packs.length > 0) {
|
|
188
|
+
merged.packs = cliFlags.packs;
|
|
189
|
+
}
|
|
190
|
+
if (cliFlags.lang) {
|
|
191
|
+
if (!["auto", "en", "zh"].includes(cliFlags.lang)) {
|
|
192
|
+
throw new DislopConfigError(`Invalid --lang '${cliFlags.lang}' (expected auto, en, or zh)`);
|
|
193
|
+
}
|
|
194
|
+
merged.lang = cliFlags.lang;
|
|
195
|
+
}
|
|
196
|
+
if (cliFlags.level) {
|
|
197
|
+
if (!["strong", "moderate", "hint", "all"].includes(cliFlags.level)) {
|
|
198
|
+
throw new DislopConfigError(
|
|
199
|
+
`Invalid --level '${cliFlags.level}' (expected strong, moderate, hint, or all)`,
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
merged.level = cliFlags.level;
|
|
203
|
+
}
|
|
204
|
+
if (cliFlags.voiceFiles && cliFlags.voiceFiles.length > 0) {
|
|
205
|
+
merged.voice.referenceFiles = cliFlags.voiceFiles.map((f) => path.resolve(cwd, expandTilde(f, env)));
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return {
|
|
209
|
+
...merged,
|
|
210
|
+
explicitEngine,
|
|
211
|
+
modelOverride: cliFlags.model ? String(cliFlags.model) : null,
|
|
212
|
+
noLlm: Boolean(cliFlags.noLlm),
|
|
213
|
+
homeDir,
|
|
214
|
+
userConfigPath,
|
|
215
|
+
credentialsPath: path.join(homeDir, "credentials.json"),
|
|
216
|
+
modelsDir: path.join(homeDir, "models"),
|
|
217
|
+
loadedSources,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export function computeFilesFingerprint(filePaths) {
|
|
222
|
+
const hash = crypto.createHash("sha256");
|
|
223
|
+
const sorted = [...filePaths].sort();
|
|
224
|
+
for (const fp of sorted) {
|
|
225
|
+
if (!fs.existsSync(fp)) continue;
|
|
226
|
+
hash.update(fp);
|
|
227
|
+
hash.update("\0");
|
|
228
|
+
hash.update(fs.readFileSync(fp));
|
|
229
|
+
hash.update("\0");
|
|
230
|
+
}
|
|
231
|
+
return hash.digest("hex");
|
|
232
|
+
}
|