dislop 1.0.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 +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/.cursor-plugin/plugin.json +1 -1
- package/PRODUCT.md +2 -2
- package/README.md +34 -33
- package/README.zh-CN.md +65 -61
- package/gemini-extension.json +1 -1
- package/package.json +2 -2
- package/packs/common/artifact-qa/scripts/index.mjs +64 -2
- package/packs/en/artifact-qa/scripts/index.mjs +1 -1
- package/packs/en/prose/scripts/index.mjs +3 -0
- package/plugin.json +1 -1
- package/server.json +2 -2
- package/skills/dislop/SKILL.md +1 -1
- package/skills/dislop/agents/openai.yaml +1 -1
- package/skills/dislop/references/essay.md +5 -5
- package/skills/dislop/references/essay.zh-CN.md +5 -5
- package/skills/dislop/references/office.md +4 -4
- package/skills/dislop/references/office.zh-CN.md +4 -4
- package/skills/dislop/references/web-ui.md +3 -3
- package/skills/dislop/references/web-ui.zh-CN.md +3 -3
- package/skills/dislop/references/work-docs.md +6 -6
- package/skills/dislop/references/work-docs.zh-CN.md +6 -6
- package/src/cli-main.mjs +88 -6
- package/src/commands/check-fix.mjs +170 -15
- package/src/commands/doctor.mjs +23 -1
- package/src/commands/init.mjs +24 -18
- package/src/commands/packs.mjs +41 -4
- package/src/commands/verify.mjs +36 -4
- package/src/commands/voice.mjs +1 -1
- package/src/commands/worklog.mjs +424 -0
- package/src/kernel/config.mjs +546 -19
- package/src/kernel/document-model.mjs +30 -10
- package/src/kernel/fact-gate.mjs +160 -0
- package/src/kernel/file-discovery.mjs +168 -11
- package/src/kernel/ooxml-binary.mjs +86 -0
- package/src/kernel/pack-loader.mjs +107 -21
- package/src/kernel/pack-validator.mjs +491 -0
- package/src/kernel/patcher.mjs +177 -47
- package/src/kernel/pipeline.mjs +284 -21
- package/src/kernel/prompt-assembler.mjs +37 -8
- package/src/kernel/version.mjs +7 -0
- package/src/kernel/voice-profile.mjs +3 -0
- package/src/mcp/stdio-server.mjs +71 -1
- package/src/runners/auto-fix.mjs +17 -2
- package/src/runners/interactive-tty.mjs +32 -5
- package/src/runners/reporters.mjs +18 -2
- package/src/runtime/providers/cloud.mjs +4 -2
- package/src/runtime/providers/local-model.mjs +8 -0
- package/src/runtime/router.mjs +11 -2
- package/src/runtime/worklog.mjs +904 -0
package/src/commands/doctor.mjs
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
isCiEnvironment,
|
|
4
|
+
isInteractiveHumanTty,
|
|
5
|
+
resolveLayeredConfig,
|
|
6
|
+
} from "../kernel/config.mjs";
|
|
3
7
|
import { listBuiltinPackIds } from "../kernel/pack-loader.mjs";
|
|
4
8
|
import {
|
|
5
9
|
detectOllamaBinary,
|
|
@@ -10,6 +14,7 @@ import {
|
|
|
10
14
|
resolveExecutionRoute,
|
|
11
15
|
resolveTier2ProviderCandidate,
|
|
12
16
|
} from "../runtime/router.mjs";
|
|
17
|
+
import { isWorklogActive } from "../runtime/worklog.mjs";
|
|
13
18
|
|
|
14
19
|
/**
|
|
15
20
|
* `dislop doctor [--json]` — zero-network diagnostic snapshot of config, active tier, auth, voice, and Packs.
|
|
@@ -66,6 +71,14 @@ export async function runDoctorCommand(_positionals, flags, io = {}) {
|
|
|
66
71
|
installed: Object.keys(modelsManifest.installed),
|
|
67
72
|
},
|
|
68
73
|
voiceCachePresent: Boolean(config.voice?.cachePath && fs.existsSync(config.voice.cachePath)),
|
|
74
|
+
worklog: {
|
|
75
|
+
enabled: config.worklog.enabled,
|
|
76
|
+
active: isWorklogActive(config, env),
|
|
77
|
+
ciDisabled: isCiEnvironment(env),
|
|
78
|
+
privacy: config.worklog.privacy,
|
|
79
|
+
dir: config.worklog.dir,
|
|
80
|
+
retentionDays: config.worklog.retentionDays,
|
|
81
|
+
},
|
|
69
82
|
configuredPacks: config.packs || ["(auto by document format & language)"],
|
|
70
83
|
builtinPacks,
|
|
71
84
|
};
|
|
@@ -104,6 +117,15 @@ export async function runDoctorCommand(_positionals, flags, io = {}) {
|
|
|
104
117
|
} (${ollamaStatusText})\n`,
|
|
105
118
|
);
|
|
106
119
|
stdout.write(` Voice Profile : ${diagnosis.voiceCachePresent ? "cached" : "not configured"}\n`);
|
|
120
|
+
stdout.write(
|
|
121
|
+
` Worklog : ${
|
|
122
|
+
diagnosis.worklog.active
|
|
123
|
+
? `active (privacy=${diagnosis.worklog.privacy}, dir=${diagnosis.worklog.dir})`
|
|
124
|
+
: diagnosis.worklog.ciDisabled
|
|
125
|
+
? "disabled in CI"
|
|
126
|
+
: "disabled (local opt-in only)"
|
|
127
|
+
}\n`,
|
|
128
|
+
);
|
|
107
129
|
stdout.write(` Built-in Packs : ${diagnosis.builtinPacks.join(", ")}\n`);
|
|
108
130
|
|
|
109
131
|
return 0;
|
package/src/commands/init.mjs
CHANGED
|
@@ -19,24 +19,30 @@ export async function runInitCommand(_positionals, flags, io = {}) {
|
|
|
19
19
|
|
|
20
20
|
const voiceRefs = flags.voiceFiles && flags.voiceFiles.length > 0 ? flags.voiceFiles : [];
|
|
21
21
|
|
|
22
|
-
const template =
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
22
|
+
const template = flags.global
|
|
23
|
+
? {
|
|
24
|
+
routing: "local",
|
|
25
|
+
approvedHosts: [],
|
|
26
|
+
packs: ["artifact-qa", "web-ui", "slide-deck", "prose"],
|
|
27
|
+
voice: {
|
|
28
|
+
referenceFiles: voiceRefs,
|
|
29
|
+
},
|
|
30
|
+
providers: {
|
|
31
|
+
"local-ollama": {
|
|
32
|
+
protocol: "openai",
|
|
33
|
+
baseUrl: "http://127.0.0.1:11434/v1",
|
|
34
|
+
apiKey: "ollama",
|
|
35
|
+
model: "qwen2.5:7b",
|
|
36
|
+
structuredOutput: "json_object",
|
|
37
|
+
maxInputTokens: 8000,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
: {
|
|
42
|
+
routing: "local",
|
|
43
|
+
ignore: [".private/**"],
|
|
44
|
+
...(voiceRefs.length > 0 ? { voice: { referenceFiles: voiceRefs } } : {}),
|
|
45
|
+
};
|
|
40
46
|
|
|
41
47
|
if (flags.global) {
|
|
42
48
|
writeJsonFileSecure(targetPath, template, { mode: 0o600 });
|
package/src/commands/packs.mjs
CHANGED
|
@@ -1,11 +1,48 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { DislopConfigError } from "../kernel/config.mjs";
|
|
1
4
|
import { listBuiltinPackIds, loadSinglePack } from "../kernel/pack-loader.mjs";
|
|
5
|
+
import { validatePackPath } from "../kernel/pack-validator.mjs";
|
|
2
6
|
|
|
3
7
|
/**
|
|
4
|
-
* `dislop packs [--json]` — inspect built-in
|
|
5
|
-
*
|
|
8
|
+
* `dislop packs [list | lint <path>] [--json]` — inspect built-in Packs via `pack.json` metadata
|
|
9
|
+
* or validate external `.pack.md` / Pack directories against security & schema checks.
|
|
6
10
|
*/
|
|
7
|
-
export async function runPacksCommand(
|
|
8
|
-
const { cwd = process.cwd(), stdout = process.stdout } = io;
|
|
11
|
+
export async function runPacksCommand(positionals = [], flags = {}, io = {}) {
|
|
12
|
+
const { cwd = process.cwd(), stdout = process.stdout, stderr = process.stderr } = io;
|
|
13
|
+
const subcommand = (positionals[0] || "list").trim();
|
|
14
|
+
|
|
15
|
+
if (subcommand === "lint" || subcommand === "validate") {
|
|
16
|
+
const target = positionals[1];
|
|
17
|
+
if (!target) {
|
|
18
|
+
throw new DislopConfigError("Usage: dislop packs lint <pack-dir|file.pack.md>");
|
|
19
|
+
}
|
|
20
|
+
const result = validatePackPath(target, { cwd });
|
|
21
|
+
if (!result.exists) {
|
|
22
|
+
throw new DislopConfigError(`Pack path does not exist: ${target}`);
|
|
23
|
+
}
|
|
24
|
+
if (flags.json || flags.format === "json") {
|
|
25
|
+
stdout.write(`${JSON.stringify(result, null, 2)}\n`);
|
|
26
|
+
} else if (result.ok) {
|
|
27
|
+
const relTarget = path.relative(cwd, result.targetPath) || ".";
|
|
28
|
+
stdout.write(
|
|
29
|
+
`OK ${relTarget}: ${result.checkedFiles} file(s) validated with 0 violations.\n`,
|
|
30
|
+
);
|
|
31
|
+
} else {
|
|
32
|
+
for (const v of result.violations) {
|
|
33
|
+
const rel = path.relative(cwd, v.file) || v.file;
|
|
34
|
+
const loc = v.line ? `:${v.line}` : "";
|
|
35
|
+
stderr.write(`FAIL [${v.ruleId}] ${rel}${loc}: ${v.message}\n`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return result.ok ? 0 : 1;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (subcommand !== "list") {
|
|
42
|
+
throw new DislopConfigError(
|
|
43
|
+
`Unknown packs subcommand '${subcommand}'. Expected 'list', 'lint', or 'validate'.`,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
9
46
|
|
|
10
47
|
const ids = listBuiltinPackIds();
|
|
11
48
|
const details = [];
|
package/src/commands/verify.mjs
CHANGED
|
@@ -3,15 +3,22 @@ import crypto from "node:crypto";
|
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import os from "node:os";
|
|
5
5
|
import path from "node:path";
|
|
6
|
-
import { DislopConfigError } from "../kernel/config.mjs";
|
|
6
|
+
import { DislopConfigError, resolveLayeredConfig } from "../kernel/config.mjs";
|
|
7
7
|
import { detectFormatFromPath, parseDocumentFile, parseDocumentText } from "../kernel/document-model.mjs";
|
|
8
8
|
import { verifyDocumentRevision } from "../kernel/fact-gate.mjs";
|
|
9
|
+
import { buildVerifyWorklogEntry, recordWorklogEntry } from "../runtime/worklog.mjs";
|
|
9
10
|
|
|
10
11
|
function extractComparableText(filePath) {
|
|
11
12
|
const doc = parseDocumentFile(filePath);
|
|
12
13
|
if (doc.segments.length > 0) {
|
|
13
14
|
return doc.segments.map((s) => s.text).join("\n");
|
|
14
15
|
}
|
|
16
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
17
|
+
if ([".pdf", ".docx", ".pptx", ".png", ".jpg", ".jpeg", ".webp", ".gif"].includes(ext)) {
|
|
18
|
+
throw new DislopConfigError(
|
|
19
|
+
`Unable to extract inspectable text segments from binary file '${filePath}'. Cannot verify unextractable binary artifacts.`,
|
|
20
|
+
);
|
|
21
|
+
}
|
|
15
22
|
return fs.readFileSync(filePath, "utf8");
|
|
16
23
|
}
|
|
17
24
|
|
|
@@ -44,7 +51,8 @@ function extractComparableTextFromBuffer(buf, targetPath) {
|
|
|
44
51
|
* or `dislop verify --git [ref] <file> [--json]`
|
|
45
52
|
*/
|
|
46
53
|
export async function runVerifyCommand(positionals, flags, io = {}) {
|
|
47
|
-
const { cwd = process.cwd(), stdout = process.stdout } = io;
|
|
54
|
+
const { cwd = process.cwd(), env = process.env, stdout = process.stdout } = io;
|
|
55
|
+
const startedAt = Date.now();
|
|
48
56
|
|
|
49
57
|
let beforeText = "";
|
|
50
58
|
let afterText = "";
|
|
@@ -118,7 +126,9 @@ export async function runVerifyCommand(positionals, flags, io = {}) {
|
|
|
118
126
|
if (flags.json || flags.format === "json") {
|
|
119
127
|
stdout.write(`${JSON.stringify(payload, null, 2)}\n`);
|
|
120
128
|
} else if (verification.ok) {
|
|
121
|
-
stdout.write(
|
|
129
|
+
stdout.write(
|
|
130
|
+
`PASS ${label}: anchored tokens & qualifiers preserved; 0 detected slop/polarity regressions.\n`,
|
|
131
|
+
);
|
|
122
132
|
} else {
|
|
123
133
|
stdout.write(`FAIL ${label}:\n`);
|
|
124
134
|
for (const reason of verification.droppedFacts) {
|
|
@@ -129,5 +139,27 @@ export async function runVerifyCommand(positionals, flags, io = {}) {
|
|
|
129
139
|
}
|
|
130
140
|
}
|
|
131
141
|
|
|
132
|
-
|
|
142
|
+
const exitCode = verification.ok ? 0 : 1;
|
|
143
|
+
try {
|
|
144
|
+
const config = resolveLayeredConfig({ cwd, env, cliFlags: flags });
|
|
145
|
+
recordWorklogEntry(
|
|
146
|
+
buildVerifyWorklogEntry({
|
|
147
|
+
source: "cli",
|
|
148
|
+
command: "verify",
|
|
149
|
+
mode: flags.git !== undefined && flags.git !== false ? "verify-git" : "verify-files",
|
|
150
|
+
cwd,
|
|
151
|
+
config,
|
|
152
|
+
targetLabel: label,
|
|
153
|
+
verification,
|
|
154
|
+
durationMs: Date.now() - startedAt,
|
|
155
|
+
exitCode,
|
|
156
|
+
}),
|
|
157
|
+
config,
|
|
158
|
+
env,
|
|
159
|
+
);
|
|
160
|
+
} catch {
|
|
161
|
+
// Worklog recording must never break verify
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return exitCode;
|
|
133
165
|
}
|
package/src/commands/voice.mjs
CHANGED
|
@@ -63,7 +63,7 @@ export async function runVoiceCommand(positionals, flags, io = {}) {
|
|
|
63
63
|
"Usage: dislop voice extract <files/globs...> (no reference files provided)",
|
|
64
64
|
);
|
|
65
65
|
}
|
|
66
|
-
const resolvedFiles = expandTargetInputs(fileInputs, { cwd });
|
|
66
|
+
const resolvedFiles = expandTargetInputs(fileInputs, { cwd, ignorePatterns: config.ignore });
|
|
67
67
|
const isTty = isInteractiveHumanTty({ stdin, stdout, env });
|
|
68
68
|
const route = await resolveExecutionRoute({ config, isTty, env, stdin, stderr, fetchImpl });
|
|
69
69
|
const profile = await extractVoiceProfile(resolvedFiles, { route });
|
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
import { DislopConfigError, isCiEnvironment, resolveLayeredConfig } from "../kernel/config.mjs";
|
|
2
|
+
import {
|
|
3
|
+
buildReflectionReport,
|
|
4
|
+
clearWorklogEntries,
|
|
5
|
+
computeWorklogStats,
|
|
6
|
+
findWorklogEntryById,
|
|
7
|
+
getWorklogStorageStats,
|
|
8
|
+
isWorklogActive,
|
|
9
|
+
readWorklogEntries,
|
|
10
|
+
} from "../runtime/worklog.mjs";
|
|
11
|
+
|
|
12
|
+
function parseBoundedInt(raw, label, min, max) {
|
|
13
|
+
const num = Number(raw);
|
|
14
|
+
if (!Number.isInteger(num) || num < min || num > max) {
|
|
15
|
+
throw new DislopConfigError(`Invalid ${label} '${raw}' (expected integer ${min}..${max})`);
|
|
16
|
+
}
|
|
17
|
+
return num;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function formatBytes(bytes) {
|
|
21
|
+
if (!Number.isFinite(bytes) || bytes < 1024) return `${bytes || 0} B`;
|
|
22
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
23
|
+
return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function renderStatusText(status) {
|
|
27
|
+
const stateLabel = status.active
|
|
28
|
+
? "active"
|
|
29
|
+
: status.ciDisabled
|
|
30
|
+
? "disabled (suppressed in CI environment)"
|
|
31
|
+
: "disabled (off by default)";
|
|
32
|
+
|
|
33
|
+
const lines = [
|
|
34
|
+
"dislop worklog",
|
|
35
|
+
` State : ${stateLabel}`,
|
|
36
|
+
` Privacy Tier : ${status.privacy}`,
|
|
37
|
+
` Storage Dir : ${status.dir}`,
|
|
38
|
+
` Retention Days : ${status.retentionDays}`,
|
|
39
|
+
` Stored Files : ${status.fileCount} daily file(s), ${status.entryCount} entry(ies), ${formatBytes(status.totalBytes)}`,
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
if (!status.enabled) {
|
|
43
|
+
lines.push(
|
|
44
|
+
" Enable Locally : set DISLOP_WORKLOG=1 or add {\"worklog\":{\"enabled\":true}} in .dislop.local.json or ~/.config/dislop/config.json",
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
return `${lines.join("\n")}\n`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function renderListText(entries, windowDays) {
|
|
51
|
+
if (entries.length === 0) {
|
|
52
|
+
return `No worklog entries found in the last ${windowDays} day(s).\n`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const lines = [`Recent worklog entries (${entries.length}, window=${windowDays}d):`];
|
|
56
|
+
for (const e of entries) {
|
|
57
|
+
const shortId = String(e.id || "").slice(0, 8);
|
|
58
|
+
const ts = String(e.timestamp || "").replace("T", " ").slice(0, 19);
|
|
59
|
+
const cmdLabel = e.mode ? `${e.source || "cli"}:${e.command}/${e.mode}` : `${e.source || "cli"}:${e.command}`;
|
|
60
|
+
if (e.verify) {
|
|
61
|
+
lines.push(
|
|
62
|
+
` ${shortId} ${ts} ${cmdLabel} verify=${e.verify.ok ? "PASS" : "FAIL"} dropped=${e.verify.droppedFactsCount || 0} regressions=${(e.verify.regressionIds || []).length} ${e.durationMs || 0}ms exit=${e.exitCode ?? 0}`,
|
|
63
|
+
);
|
|
64
|
+
} else {
|
|
65
|
+
const s = e.summary || {};
|
|
66
|
+
const defects = (s.defects?.error || 0) + (s.defects?.warning || 0);
|
|
67
|
+
const suggestions =
|
|
68
|
+
(s.suggestions?.strong || 0) + (s.suggestions?.moderate || 0) + (s.suggestions?.hint || 0);
|
|
69
|
+
lines.push(
|
|
70
|
+
` ${shortId} ${ts} ${cmdLabel} engine=${e.engine || "deterministic"} files=${e.fileCount || 0} defects=${defects} suggestions=${suggestions} applied=${s.applied || 0} skipped=${s.skipped || 0} ${e.durationMs || 0}ms exit=${e.exitCode ?? 0}`,
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return `${lines.join("\n")}\n`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function renderEntryDetailText(entry) {
|
|
78
|
+
const lines = [
|
|
79
|
+
`Worklog Entry ${entry.id}`,
|
|
80
|
+
` Timestamp : ${entry.timestamp}`,
|
|
81
|
+
` Source/Command : ${entry.source || "cli"}:${entry.command}${entry.mode ? ` (${entry.mode})` : ""}`,
|
|
82
|
+
` Version : ${entry.version || "unknown"}`,
|
|
83
|
+
` Privacy Tier : ${entry.privacy}`,
|
|
84
|
+
` Workspace : ${entry.workspaceName ? `${entry.workspaceName} (${entry.workspaceHash})` : entry.workspaceHash}`,
|
|
85
|
+
` Engine/Routing : ${entry.engine} (routing=${entry.routing}${entry.routeFallback ? ", fallback=yes" : ""})`,
|
|
86
|
+
` Duration/Exit : ${entry.durationMs}ms (exit=${entry.exitCode})`,
|
|
87
|
+
];
|
|
88
|
+
|
|
89
|
+
if (entry.verify) {
|
|
90
|
+
lines.push(
|
|
91
|
+
` Verify : ${entry.verify.ok ? "PASS" : "FAIL"} (droppedFacts=${entry.verify.droppedFactsCount || 0}, regressions=${(entry.verify.regressionIds || []).join(", ") || "none"})`,
|
|
92
|
+
);
|
|
93
|
+
if ((entry.verify.droppedFactTypes || []).length > 0) {
|
|
94
|
+
lines.push(` Dropped Types : ${entry.verify.droppedFactTypes.join(", ")}`);
|
|
95
|
+
}
|
|
96
|
+
if (Array.isArray(entry.verify.droppedFacts) && entry.verify.droppedFacts.length > 0) {
|
|
97
|
+
lines.push(` Dropped Detail : ${entry.verify.droppedFacts.join(" | ")}`);
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
const s = entry.summary || {};
|
|
101
|
+
lines.push(
|
|
102
|
+
` Summary : defects(err=${s.defects?.error || 0}, warn=${s.defects?.warning || 0}) suggestions(strong=${s.suggestions?.strong || 0}, mod=${s.suggestions?.moderate || 0}, hint=${s.suggestions?.hint || 0}) applied=${s.applied || 0} edited=${s.edited || 0} skipped=${s.skipped || 0} factGateDowngraded=${s.factGateDowngraded || 0}`,
|
|
103
|
+
);
|
|
104
|
+
for (const fileRec of entry.files || []) {
|
|
105
|
+
const label = fileRec.fileRef || `${fileRec.fileHash}.${fileRec.ext}`;
|
|
106
|
+
lines.push(
|
|
107
|
+
` File : ${label} (${fileRec.language}/${fileRec.modality}, segments=${fileRec.segmentCount}, ${fileRec.durationMs ?? "-"}ms, findings=${(fileRec.findings || []).length})`,
|
|
108
|
+
);
|
|
109
|
+
for (const f of fileRec.findings || []) {
|
|
110
|
+
const extra = [
|
|
111
|
+
f.origin,
|
|
112
|
+
f.fixSafety,
|
|
113
|
+
f.decision ? `decision=${f.decision}` : null,
|
|
114
|
+
f.factGateDowngraded ? `factGate=[${(f.factGateCategories || []).join(",")}]` : null,
|
|
115
|
+
]
|
|
116
|
+
.filter(Boolean)
|
|
117
|
+
.join(", ");
|
|
118
|
+
lines.push(` - [${f.kind}:${f.severityOrPriority}] ${f.ruleId} (${extra})`);
|
|
119
|
+
if (f.quotePreview || f.originalQuote) {
|
|
120
|
+
lines.push(` quote: ${f.quotePreview || f.originalQuote}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return `${lines.join("\n")}\n`;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function renderStatsText(stats, windowDays) {
|
|
130
|
+
const lines = [
|
|
131
|
+
`dislop worklog stats (window=${windowDays}d)`,
|
|
132
|
+
` Total Runs : ${stats.totalRuns} (${stats.totalFiles} file inspections)`,
|
|
133
|
+
` By Command : ${Object.entries(stats.byCommand).map(([k, v]) => `${k}=${v}`).join(", ") || "none"}`,
|
|
134
|
+
` By Source : ${Object.entries(stats.bySource).map(([k, v]) => `${k}=${v}`).join(", ") || "none"}`,
|
|
135
|
+
` By Engine : ${Object.entries(stats.byEngine).map(([k, v]) => `${k}=${v}`).join(", ") || "none"}`,
|
|
136
|
+
` Route Fallback : ${stats.fallbackRuns} (${Math.round(stats.fallbackRate * 100)}%)`,
|
|
137
|
+
` Latency : p50=${stats.latency.p50Ms}ms, p95=${stats.latency.p95Ms}ms, max=${stats.latency.maxMs}ms`,
|
|
138
|
+
` Findings : defects(err=${stats.findingsSummary.defects.error}, warn=${stats.findingsSummary.defects.warning}) suggestions(strong=${stats.findingsSummary.suggestions.strong}, mod=${stats.findingsSummary.suggestions.moderate}, hint=${stats.findingsSummary.suggestions.hint})`,
|
|
139
|
+
` Fix Decisions : applied=${stats.findingsSummary.applied}, edited=${stats.findingsSummary.edited}, skipped=${stats.findingsSummary.skipped}, promptCopied=${stats.findingsSummary.promptCopied}, factGateDowngraded=${stats.findingsSummary.factGateDowngraded}`,
|
|
140
|
+
` Verify : total=${stats.verify.total}, passed=${stats.verify.passed}, failed=${stats.verify.failed}`,
|
|
141
|
+
];
|
|
142
|
+
|
|
143
|
+
if (stats.rules.length > 0) {
|
|
144
|
+
lines.push(" Top Rules:");
|
|
145
|
+
for (const r of stats.rules.slice(0, 15)) {
|
|
146
|
+
const skipStr = r.skipRate !== null ? ` skipRate=${Math.round(r.skipRate * 100)}%` : "";
|
|
147
|
+
const fgStr = r.factGateDowngrades > 0 ? ` fgDowngrades=${r.factGateDowngrades}` : "";
|
|
148
|
+
lines.push(
|
|
149
|
+
` - ${r.ruleId} [${r.kind}] hits=${r.hits} (det=${r.deterministicHits}, llm=${r.llmHits}) applied=${r.accepted + r.autoApplied} edited=${r.edited} skipped=${r.skipped}${skipStr}${fgStr}`,
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return `${lines.join("\n")}\n`;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function renderReflectMarkdown(report) {
|
|
157
|
+
const { stats, signals, windowDays } = report;
|
|
158
|
+
const lines = [
|
|
159
|
+
`# dislop Worklog Reflection (${windowDays}d)`,
|
|
160
|
+
"",
|
|
161
|
+
`- Total runs: **${stats.totalRuns}** (${stats.totalFiles} file inspections)`,
|
|
162
|
+
`- Latency: p50 **${stats.latency.p50Ms}ms**, p95 **${stats.latency.p95Ms}ms**, max **${stats.latency.maxMs}ms**`,
|
|
163
|
+
`- Routing fallbacks: **${stats.fallbackRuns}** (${Math.round(stats.fallbackRate * 100)}%)`,
|
|
164
|
+
`- Fact Gate downgrades: **${stats.findingsSummary.factGateDowngraded}**`,
|
|
165
|
+
`- Verify checks: **${stats.verify.total}** (failed: **${stats.verify.failed}**)`,
|
|
166
|
+
"",
|
|
167
|
+
"## 1. High-Skip Rules (Possible False Positives / Noise)",
|
|
168
|
+
];
|
|
169
|
+
|
|
170
|
+
if (signals.highSkipRules.length === 0) {
|
|
171
|
+
lines.push("- None observed (requires >=3 interactive fix decisions and >=50% skip rate).");
|
|
172
|
+
} else {
|
|
173
|
+
for (const r of signals.highSkipRules) {
|
|
174
|
+
lines.push(
|
|
175
|
+
`- \`${r.ruleId}\` (${r.pack}): skipped **${r.skipped}/${r.interactiveDecisions}** (${Math.round(r.skipRate * 100)}%) — ${r.recommendation}`,
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
lines.push("", "## 2. Frequently Edited Rules (Improve Suggested Fix / Prompt)");
|
|
181
|
+
if (signals.highEditRules.length === 0) {
|
|
182
|
+
lines.push("- None observed (requires >=2 manual `[e]` edits).");
|
|
183
|
+
} else {
|
|
184
|
+
for (const r of signals.highEditRules) {
|
|
185
|
+
lines.push(
|
|
186
|
+
`- \`${r.ruleId}\` (${r.pack}): manually edited **${r.edited}** time(s) across ${r.hits} hits — ${r.recommendation}`,
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
lines.push("", "## 3. Fact Gate Downgrade Hotspots");
|
|
192
|
+
if (signals.factGateHotspots.length === 0) {
|
|
193
|
+
lines.push("- None observed.");
|
|
194
|
+
} else {
|
|
195
|
+
for (const r of signals.factGateHotspots) {
|
|
196
|
+
const cats = Object.entries(r.categories)
|
|
197
|
+
.map(([k, v]) => `${k}:${v}`)
|
|
198
|
+
.join(", ");
|
|
199
|
+
lines.push(
|
|
200
|
+
`- \`${r.ruleId}\` (${r.pack}): **${r.downgrades}** downgrade(s) [${cats || "other"}] — ${r.recommendation}`,
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
lines.push("", "## 4. Verify Regressions & Dropped Fact Categories");
|
|
206
|
+
if (signals.verifyHotspots.total === 0) {
|
|
207
|
+
lines.push("- No `verify` runs recorded in window.");
|
|
208
|
+
} else {
|
|
209
|
+
lines.push(
|
|
210
|
+
`- Pass rate: **${signals.verifyHotspots.total - signals.verifyHotspots.failed}/${signals.verifyHotspots.total}** (failRate=${Math.round(signals.verifyHotspots.failRate * 100)}%)`,
|
|
211
|
+
);
|
|
212
|
+
if (signals.verifyHotspots.droppedFactTypes.length > 0) {
|
|
213
|
+
lines.push(
|
|
214
|
+
`- Dropped fact categories: ${signals.verifyHotspots.droppedFactTypes.map((d) => `\`${d.type}\` (${d.count})`).join(", ")}`,
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
if (signals.verifyHotspots.regressionIds.length > 0) {
|
|
218
|
+
lines.push(
|
|
219
|
+
`- Second-order regressions: ${signals.verifyHotspots.regressionIds.map((r) => `\`${r.id}\` (${r.count})`).join(", ")}`,
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
lines.push("", "## 5. Slow Files & Routing Friction");
|
|
225
|
+
if (signals.slowFiles.length === 0) {
|
|
226
|
+
lines.push("- No slow files exceeded latency thresholds (>500ms deterministic, >5000ms LLM).");
|
|
227
|
+
} else {
|
|
228
|
+
for (const sf of signals.slowFiles.slice(0, 10)) {
|
|
229
|
+
lines.push(
|
|
230
|
+
`- \`${sf.file}\` (${sf.ext}/${sf.modality}, ${sf.engine}): **${sf.durationMs}ms** across ${sf.segmentCount} segments`,
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (signals.routingFriction.recommendation) {
|
|
235
|
+
lines.push(`- Routing friction: ${signals.routingFriction.recommendation}`);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return `${lines.join("\n")}\n`;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function renderReflectText(report) {
|
|
242
|
+
const { stats, signals, windowDays } = report;
|
|
243
|
+
const lines = [
|
|
244
|
+
`dislop worklog reflect (window=${windowDays}d)`,
|
|
245
|
+
` Runs=${stats.totalRuns}, Files=${stats.totalFiles}, p50=${stats.latency.p50Ms}ms, p95=${stats.latency.p95Ms}ms, Fallbacks=${stats.fallbackRuns}, FactGateDowngrades=${stats.findingsSummary.factGateDowngraded}, VerifyFailed=${stats.verify.failed}/${stats.verify.total}`,
|
|
246
|
+
"",
|
|
247
|
+
"Signals:",
|
|
248
|
+
];
|
|
249
|
+
|
|
250
|
+
let anySignal = false;
|
|
251
|
+
for (const r of signals.highSkipRules) {
|
|
252
|
+
anySignal = true;
|
|
253
|
+
lines.push(` [HIGH-SKIP] ${r.ruleId}: ${r.skipped}/${r.interactiveDecisions} (${Math.round(r.skipRate * 100)}%)`);
|
|
254
|
+
}
|
|
255
|
+
for (const r of signals.highEditRules) {
|
|
256
|
+
anySignal = true;
|
|
257
|
+
lines.push(` [HIGH-EDIT] ${r.ruleId}: edited ${r.edited} time(s)`);
|
|
258
|
+
}
|
|
259
|
+
for (const r of signals.factGateHotspots) {
|
|
260
|
+
anySignal = true;
|
|
261
|
+
const cats = Object.entries(r.categories).map(([k, v]) => `${k}:${v}`).join(", ");
|
|
262
|
+
lines.push(` [FACT-GATE] ${r.ruleId}: ${r.downgrades} downgrade(s) (${cats || "other"})`);
|
|
263
|
+
}
|
|
264
|
+
for (const dt of signals.verifyHotspots.droppedFactTypes) {
|
|
265
|
+
anySignal = true;
|
|
266
|
+
lines.push(` [VERIFY-DROP] ${dt.type}: ${dt.count}`);
|
|
267
|
+
}
|
|
268
|
+
for (const reg of signals.verifyHotspots.regressionIds) {
|
|
269
|
+
anySignal = true;
|
|
270
|
+
lines.push(` [VERIFY-REG] ${reg.id}: ${reg.count}`);
|
|
271
|
+
}
|
|
272
|
+
for (const sf of signals.slowFiles.slice(0, 5)) {
|
|
273
|
+
anySignal = true;
|
|
274
|
+
lines.push(` [SLOW-FILE] ${sf.file} (${sf.ext}, ${sf.engine}): ${sf.durationMs}ms`);
|
|
275
|
+
}
|
|
276
|
+
if (signals.routingFriction.recommendation) {
|
|
277
|
+
anySignal = true;
|
|
278
|
+
lines.push(` [ROUTING] ${signals.routingFriction.recommendation}`);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (!anySignal) {
|
|
282
|
+
lines.push(" (No optimization anomalies detected in the current window.)");
|
|
283
|
+
}
|
|
284
|
+
return `${lines.join("\n")}\n`;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* `dislop worklog <status|list|show|stats|reflect|clear> [options]`
|
|
289
|
+
*/
|
|
290
|
+
export async function runWorklogCommand(positionals, flags, io = {}) {
|
|
291
|
+
const { cwd = process.cwd(), env = process.env, stdout = process.stdout } = io;
|
|
292
|
+
const config = resolveLayeredConfig({ cwd, env, cliFlags: flags });
|
|
293
|
+
const subcommand = positionals[0] || "status";
|
|
294
|
+
const dir = config.worklog.dir;
|
|
295
|
+
const wantJson = Boolean(flags.json || flags.format === "json");
|
|
296
|
+
|
|
297
|
+
if (subcommand === "status") {
|
|
298
|
+
const storage = getWorklogStorageStats(dir);
|
|
299
|
+
const payload = {
|
|
300
|
+
schema: "dislop.worklog.status/1",
|
|
301
|
+
enabled: config.worklog.enabled,
|
|
302
|
+
active: isWorklogActive(config, env),
|
|
303
|
+
ciDisabled: isCiEnvironment(env),
|
|
304
|
+
privacy: config.worklog.privacy,
|
|
305
|
+
dir,
|
|
306
|
+
retentionDays: config.worklog.retentionDays,
|
|
307
|
+
fileCount: storage.fileCount,
|
|
308
|
+
entryCount: storage.entryCount,
|
|
309
|
+
totalBytes: storage.totalBytes,
|
|
310
|
+
};
|
|
311
|
+
stdout.write(wantJson ? `${JSON.stringify(payload, null, 2)}\n` : renderStatusText(payload));
|
|
312
|
+
return 0;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (subcommand === "list") {
|
|
316
|
+
const days =
|
|
317
|
+
flags.days !== null && flags.days !== undefined
|
|
318
|
+
? parseBoundedInt(flags.days, "--days", 1, 3650)
|
|
319
|
+
: 14;
|
|
320
|
+
const limit =
|
|
321
|
+
flags.limit !== null && flags.limit !== undefined
|
|
322
|
+
? parseBoundedInt(flags.limit, "--limit", 1, 1000)
|
|
323
|
+
: 20;
|
|
324
|
+
const command = flags.command ? String(flags.command).trim() : null;
|
|
325
|
+
const entries = readWorklogEntries(dir, { days, command, limit });
|
|
326
|
+
if (wantJson) {
|
|
327
|
+
stdout.write(
|
|
328
|
+
`${JSON.stringify({ schema: "dislop.worklog.list/1", windowDays: days, count: entries.length, entries }, null, 2)}\n`,
|
|
329
|
+
);
|
|
330
|
+
} else {
|
|
331
|
+
stdout.write(renderListText(entries, days));
|
|
332
|
+
}
|
|
333
|
+
return 0;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if (subcommand === "show") {
|
|
337
|
+
const targetId = positionals[1];
|
|
338
|
+
if (!targetId) {
|
|
339
|
+
throw new DislopConfigError("Usage: dislop worklog show <id>");
|
|
340
|
+
}
|
|
341
|
+
const found = findWorklogEntryById(dir, targetId);
|
|
342
|
+
if (found.ambiguous) {
|
|
343
|
+
throw new DislopConfigError(
|
|
344
|
+
`Worklog id prefix '${targetId}' matched ${found.count} entries; provide a longer prefix.`,
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
if (!found.entry) {
|
|
348
|
+
throw new DislopConfigError(`Worklog entry not found: '${targetId}'`);
|
|
349
|
+
}
|
|
350
|
+
stdout.write(
|
|
351
|
+
wantJson ? `${JSON.stringify(found.entry, null, 2)}\n` : renderEntryDetailText(found.entry),
|
|
352
|
+
);
|
|
353
|
+
return 0;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
if (subcommand === "stats") {
|
|
357
|
+
const days =
|
|
358
|
+
flags.days !== null && flags.days !== undefined
|
|
359
|
+
? parseBoundedInt(flags.days, "--days", 1, 3650)
|
|
360
|
+
: 30;
|
|
361
|
+
const command = flags.command ? String(flags.command).trim() : null;
|
|
362
|
+
const entries = readWorklogEntries(dir, { days, command });
|
|
363
|
+
const stats = computeWorklogStats(entries);
|
|
364
|
+
if (wantJson) {
|
|
365
|
+
stdout.write(
|
|
366
|
+
`${JSON.stringify({ schema: "dislop.worklog.stats/1", windowDays: days, ...stats }, null, 2)}\n`,
|
|
367
|
+
);
|
|
368
|
+
} else {
|
|
369
|
+
stdout.write(renderStatsText(stats, days));
|
|
370
|
+
}
|
|
371
|
+
return 0;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
if (subcommand === "reflect") {
|
|
375
|
+
const days =
|
|
376
|
+
flags.days !== null && flags.days !== undefined
|
|
377
|
+
? parseBoundedInt(flags.days, "--days", 1, 3650)
|
|
378
|
+
: 30;
|
|
379
|
+
const format = flags.json ? "json" : flags.format || "text";
|
|
380
|
+
if (!["text", "markdown", "json"].includes(format)) {
|
|
381
|
+
throw new DislopConfigError(
|
|
382
|
+
`Invalid --format '${format}' for worklog reflect (expected text, markdown, or json)`,
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
const command = flags.command ? String(flags.command).trim() : null;
|
|
386
|
+
const entries = readWorklogEntries(dir, { days, command });
|
|
387
|
+
const report = buildReflectionReport(entries, { days });
|
|
388
|
+
if (format === "json") {
|
|
389
|
+
stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
390
|
+
} else if (format === "markdown") {
|
|
391
|
+
stdout.write(renderReflectMarkdown(report));
|
|
392
|
+
} else {
|
|
393
|
+
stdout.write(renderReflectText(report));
|
|
394
|
+
}
|
|
395
|
+
return 0;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
if (subcommand === "clear") {
|
|
399
|
+
const olderThan =
|
|
400
|
+
flags.olderThan !== null && flags.olderThan !== undefined
|
|
401
|
+
? parseBoundedInt(flags.olderThan, "--older-than", 1, 3650)
|
|
402
|
+
: null;
|
|
403
|
+
if (olderThan === null && !flags.yes && !flags.auto && !flags.force) {
|
|
404
|
+
throw new DislopConfigError(
|
|
405
|
+
"Refusing to delete all worklog entries without confirmation. Pass '--yes' (or '--older-than <days>') to proceed.",
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
const cleared = clearWorklogEntries(dir, { olderThanDays: olderThan });
|
|
409
|
+
if (wantJson) {
|
|
410
|
+
stdout.write(
|
|
411
|
+
`${JSON.stringify({ schema: "dislop.worklog.clear/1", olderThanDays: olderThan, ...cleared }, null, 2)}\n`,
|
|
412
|
+
);
|
|
413
|
+
} else {
|
|
414
|
+
stdout.write(
|
|
415
|
+
`Cleared ${cleared.removedEntries} entry(ies) across ${cleared.removedFiles} file(s) from ${dir}.\n`,
|
|
416
|
+
);
|
|
417
|
+
}
|
|
418
|
+
return 0;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
throw new DislopConfigError(
|
|
422
|
+
`Unknown worklog subcommand '${subcommand}' (expected status, list, show, stats, reflect, or clear).`,
|
|
423
|
+
);
|
|
424
|
+
}
|