dislop 1.0.1 → 1.1.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 +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/action.yml +17 -2
- 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 +4 -4
- package/skills/dislop/references/web-ui.zh-CN.md +4 -4
- 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
|
@@ -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
|
+
}
|