dislop 0.9.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/.claude-plugin/marketplace.json +3 -3
  2. package/.claude-plugin/plugin.json +2 -2
  3. package/.codex-plugin/plugin.json +7 -8
  4. package/.cursor-plugin/plugin.json +2 -3
  5. package/.pre-commit-hooks.yaml +5 -12
  6. package/PRODUCT.md +19 -63
  7. package/README.md +358 -249
  8. package/README.zh-CN.md +391 -237
  9. package/action.yml +30 -39
  10. package/bin/dislop-mcp.mjs +3 -4
  11. package/bin/dislop.mjs +4 -4594
  12. package/gemini-extension.json +2 -2
  13. package/llms-install.md +68 -0
  14. package/package.json +17 -63
  15. package/packs/common/artifact-qa/pack.json +5 -0
  16. package/packs/common/artifact-qa/prompts/rules.md +11 -0
  17. package/packs/common/artifact-qa/scripts/index.mjs +235 -0
  18. package/packs/common/slide-deck/pack.json +6 -0
  19. package/packs/common/slide-deck/prompts/rules.md +11 -0
  20. package/packs/common/slide-deck/scripts/index.mjs +62 -0
  21. package/packs/common/web-ui/pack.json +6 -0
  22. package/packs/common/web-ui/prompts/rules.md +11 -0
  23. package/packs/common/web-ui/scripts/index.mjs +80 -0
  24. package/packs/en/artifact-qa/pack.json +6 -0
  25. package/packs/en/artifact-qa/prompts/rules.md +14 -0
  26. package/packs/en/artifact-qa/scripts/index.mjs +90 -0
  27. package/packs/en/prose/pack.json +7 -0
  28. package/packs/en/prose/prompts/rules.md +26 -0
  29. package/packs/en/prose/scripts/index.mjs +293 -0
  30. package/packs/en/slide-deck/pack.json +7 -0
  31. package/packs/en/slide-deck/prompts/rules.md +17 -0
  32. package/packs/en/slide-deck/scripts/index.mjs +81 -0
  33. package/packs/en/web-ui/pack.json +7 -0
  34. package/packs/en/web-ui/prompts/rules.md +20 -0
  35. package/packs/en/web-ui/scripts/index.mjs +103 -0
  36. package/packs/zh/artifact-qa/pack.json +6 -0
  37. package/packs/zh/artifact-qa/prompts/rules.md +14 -0
  38. package/packs/zh/artifact-qa/scripts/index.mjs +89 -0
  39. package/packs/zh/prose/pack.json +7 -0
  40. package/packs/zh/prose/prompts/rules.md +26 -0
  41. package/packs/zh/prose/scripts/index.mjs +305 -0
  42. package/packs/zh/slide-deck/pack.json +7 -0
  43. package/packs/zh/slide-deck/prompts/rules.md +17 -0
  44. package/packs/zh/slide-deck/scripts/index.mjs +75 -0
  45. package/packs/zh/web-ui/pack.json +7 -0
  46. package/packs/zh/web-ui/prompts/rules.md +20 -0
  47. package/packs/zh/web-ui/scripts/index.mjs +98 -0
  48. package/plugin.json +5 -6
  49. package/server.json +2 -2
  50. package/skills/deslop-docs/SKILL.md +10 -8
  51. package/skills/deslop-slides-docx/SKILL.md +7 -8
  52. package/skills/deslop-verify/SKILL.md +7 -8
  53. package/skills/deslop-web-ui/SKILL.md +7 -8
  54. package/skills/dislop/SKILL.md +16 -28
  55. package/skills/dislop/agents/openai.yaml +1 -1
  56. package/skills/dislop/references/essay.md +6 -6
  57. package/skills/dislop/references/essay.zh-CN.md +6 -6
  58. package/skills/dislop/references/office.md +5 -5
  59. package/skills/dislop/references/office.zh-CN.md +5 -5
  60. package/skills/dislop/references/web-ui.md +4 -4
  61. package/skills/dislop/references/web-ui.zh-CN.md +4 -4
  62. package/skills/dislop/references/work-docs.md +7 -7
  63. package/skills/dislop/references/work-docs.zh-CN.md +7 -7
  64. package/src/cli-main.mjs +292 -0
  65. package/src/commands/check-fix.mjs +324 -0
  66. package/src/commands/doctor.mjs +132 -0
  67. package/src/commands/init.mjs +55 -0
  68. package/src/commands/login.mjs +82 -0
  69. package/src/commands/model.mjs +130 -0
  70. package/src/commands/packs.mjs +81 -0
  71. package/src/commands/verify.mjs +165 -0
  72. package/src/commands/voice.mjs +84 -0
  73. package/src/commands/worklog.mjs +424 -0
  74. package/src/kernel/config.mjs +759 -0
  75. package/src/kernel/document-model.mjs +1432 -0
  76. package/src/kernel/fact-gate.mjs +775 -0
  77. package/src/kernel/file-discovery.mjs +296 -0
  78. package/src/{binary-node.mjs → kernel/ooxml-binary.mjs} +615 -890
  79. package/src/kernel/pack-loader.mjs +801 -0
  80. package/src/kernel/pack-validator.mjs +491 -0
  81. package/src/kernel/patcher.mjs +471 -0
  82. package/src/kernel/pipeline.mjs +530 -0
  83. package/src/kernel/prompt-assembler.mjs +336 -0
  84. package/src/kernel/version.mjs +7 -0
  85. package/src/kernel/voice-profile.mjs +180 -0
  86. package/src/mcp/stdio-server.mjs +442 -0
  87. package/src/runners/auto-fix.mjs +74 -0
  88. package/src/runners/interactive-tty.mjs +488 -0
  89. package/src/runners/reporters.mjs +272 -0
  90. package/src/runtime/chunker.mjs +87 -0
  91. package/src/runtime/json-extract.mjs +144 -0
  92. package/src/runtime/privacy-gate.mjs +97 -0
  93. package/src/runtime/providers/anthropic.mjs +65 -0
  94. package/src/runtime/providers/cloud.mjs +138 -0
  95. package/src/runtime/providers/gemini.mjs +91 -0
  96. package/src/runtime/providers/local-model.mjs +147 -0
  97. package/src/runtime/providers/openai-compat.mjs +130 -0
  98. package/src/runtime/router.mjs +324 -0
  99. package/src/runtime/worklog.mjs +904 -0
  100. package/src/sdk/index.mjs +137 -0
  101. package/models/manifest.json +0 -90
  102. package/models/pocket-slop-v1.json +0 -1
  103. package/packs/business-brief/pack.json +0 -937
  104. package/packs/core/pack.json +0 -209
  105. package/packs/deck-and-ui/pack.json +0 -539
  106. package/packs/engineering-spec/pack.json +0 -144
  107. package/packs/executive-deck/pack.json +0 -98
  108. package/packs/literary-essay/pack.json +0 -344
  109. package/packs/regulated-comms/pack.json +0 -99
  110. package/patterns/ai-tic-rubric.json +0 -252
  111. package/patterns/banks/composite-fusion.json +0 -48
  112. package/patterns/banks/discourse-rhythm.json +0 -95
  113. package/patterns/banks/lexical-signals.json +0 -92
  114. package/patterns/banks/syntactic-frames.json +0 -52
  115. package/patterns/banks/visual-deck.json +0 -44
  116. package/patterns/dimensions/artifacts.json +0 -121
  117. package/patterns/dimensions/discourse.json +0 -438
  118. package/patterns/dimensions/lexical.json +0 -198
  119. package/patterns/dimensions/rhythm.json +0 -258
  120. package/patterns/dimensions/syntactic.json +0 -285
  121. package/patterns/dimensions/visual-and-deck.json +0 -530
  122. package/patterns/taxonomy.json +0 -112
  123. package/src/core.mjs +0 -5497
  124. package/src/dislop/review-picker.vim +0 -114
  125. package/src/local-model.mjs +0 -997
  126. package/src/pattern-engine.mjs +0 -1003
  127. package/src/pocket-model.mjs +0 -729
  128. package/src/review-apply.mjs +0 -151
  129. package/src/review-client.mjs +0 -1073
@@ -0,0 +1,324 @@
1
+ import fs from "node:fs";
2
+ import { DislopConfigError, readJsonFileStrict } from "../kernel/config.mjs";
3
+ import { checkPrivacyConsent, isLoopbackHostname, extractHostname } from "./privacy-gate.mjs";
4
+ import { invokeAnthropicProvider } from "./providers/anthropic.mjs";
5
+ import { invokeCloudProvider } from "./providers/cloud.mjs";
6
+ import { invokeGeminiProvider } from "./providers/gemini.mjs";
7
+ import {
8
+ OLLAMA_INSTALL_HINT,
9
+ detectOllamaBinary,
10
+ invokeLocalModelProvider,
11
+ resolveInstalledLocalModel,
12
+ } from "./providers/local-model.mjs";
13
+ import { invokeOpenAiCompatProvider } from "./providers/openai-compat.mjs";
14
+
15
+ const AMBIENT_ENV_CANDIDATES = [
16
+ {
17
+ name: "env-openai",
18
+ protocol: "openai",
19
+ envVarName: "OPENAI_API_KEY",
20
+ baseUrl: "https://api.openai.com/v1",
21
+ model: "gpt-4o-mini",
22
+ structuredOutput: "json_schema",
23
+ maxInputTokens: 16000,
24
+ },
25
+ {
26
+ name: "env-anthropic",
27
+ protocol: "anthropic",
28
+ envVarName: "ANTHROPIC_API_KEY",
29
+ baseUrl: "https://api.anthropic.com/v1",
30
+ model: "claude-3-5-haiku-latest",
31
+ structuredOutput: "json_object",
32
+ maxInputTokens: 16000,
33
+ },
34
+ {
35
+ name: "env-gemini",
36
+ protocol: "gemini",
37
+ envVarName: "GEMINI_API_KEY",
38
+ baseUrl: "https://generativelanguage.googleapis.com/v1beta",
39
+ model: "gemini-3.8-flash",
40
+ structuredOutput: "json_object",
41
+ maxInputTokens: 24000,
42
+ },
43
+ ];
44
+
45
+ const BUILTIN_PROVIDER_ALIASES = new Map([
46
+ ["openai", "env-openai"],
47
+ ["env-openai", "env-openai"],
48
+ ["anthropic", "env-anthropic"],
49
+ ["claude", "env-anthropic"],
50
+ ["env-anthropic", "env-anthropic"],
51
+ ["gemini", "env-gemini"],
52
+ ["google", "env-gemini"],
53
+ ["env-gemini", "env-gemini"],
54
+ ]);
55
+
56
+ function readAmbientCandidate(cand, env, modelOverride) {
57
+ const keyVal = env[cand.envVarName] || (cand.envVarName === "GEMINI_API_KEY" ? env.GOOGLE_API_KEY : "");
58
+ if (!keyVal || !String(keyVal).trim()) return null;
59
+ return {
60
+ ...cand,
61
+ model: modelOverride || cand.model,
62
+ apiKey: String(keyVal).trim(),
63
+ fromAmbientEnv: true,
64
+ envVarName: env[cand.envVarName] ? cand.envVarName : "GOOGLE_API_KEY",
65
+ };
66
+ }
67
+
68
+ export const UPGRADE_TIER_HINT =
69
+ "💡 Running local deterministic checks only. For deeper semantic de-slopping, run 'dislop login' (Cloud), pass '--engine auto' / '--engine byok', or run 'dislop model pull' (requires Ollama: https://ollama.com).";
70
+
71
+ export function loadCloudCredentials(credentialsPath) {
72
+ if (!fs.existsSync(credentialsPath)) return null;
73
+ try {
74
+ const creds = readJsonFileStrict(credentialsPath);
75
+ const token = creds?.accessToken || creds?.token || creds?.apiKey;
76
+ if (!token) return null;
77
+ if (creds.expiresAt && Number(creds.expiresAt) > 0 && Date.now() >= Number(creds.expiresAt)) {
78
+ return null;
79
+ }
80
+ return creds;
81
+ } catch {
82
+ return null;
83
+ }
84
+ }
85
+
86
+ export function resolveTier2ProviderCandidate(config, env = process.env) {
87
+ const configured = config.providers || {};
88
+ const modelOverride = config.modelOverride ? String(config.modelOverride).trim() : "";
89
+
90
+ // 1. Named activeProvider from CLI `--provider` or `config.json`
91
+ if (config.activeProvider) {
92
+ const entry = configured[config.activeProvider];
93
+ if (!entry) {
94
+ const aliasTarget = BUILTIN_PROVIDER_ALIASES.get(String(config.activeProvider).toLowerCase());
95
+ if (aliasTarget) {
96
+ const cand = AMBIENT_ENV_CANDIDATES.find((c) => c.name === aliasTarget);
97
+ return cand ? readAmbientCandidate(cand, env, modelOverride) : null;
98
+ }
99
+ throw new DislopConfigError(
100
+ `Configured provider '${config.activeProvider}' not found in config.json providers.`,
101
+ );
102
+ }
103
+ const apiKey = entry.apiKey || (entry.apiKeyEnv ? env[entry.apiKeyEnv] : "");
104
+ const host = extractHostname(entry.baseUrl || "https://api.openai.com/v1");
105
+ if (!apiKey && !isLoopbackHostname(host)) {
106
+ return null;
107
+ }
108
+ return {
109
+ name: config.activeProvider,
110
+ protocol: entry.protocol || "openai",
111
+ baseUrl: entry.baseUrl || "https://api.openai.com/v1",
112
+ apiKey: apiKey || "",
113
+ model: modelOverride || entry.model || "gpt-4o-mini",
114
+ structuredOutput: entry.structuredOutput || "json_object",
115
+ maxInputTokens: Number(entry.maxInputTokens) || 16000,
116
+ fromAmbientEnv: false,
117
+ envVarName: entry.apiKeyEnv || null,
118
+ };
119
+ }
120
+
121
+ // 2. First usable provider entry in config.json
122
+ for (const [name, entry] of Object.entries(configured)) {
123
+ const apiKey = entry.apiKey || (entry.apiKeyEnv ? env[entry.apiKeyEnv] : "");
124
+ const host = extractHostname(entry.baseUrl || "https://api.openai.com/v1");
125
+ if (!apiKey && !isLoopbackHostname(host)) continue;
126
+ return {
127
+ name,
128
+ protocol: entry.protocol || "openai",
129
+ baseUrl: entry.baseUrl || "https://api.openai.com/v1",
130
+ apiKey: apiKey || "",
131
+ model: modelOverride || entry.model || "gpt-4o-mini",
132
+ structuredOutput: entry.structuredOutput || "json_object",
133
+ maxInputTokens: Number(entry.maxInputTokens) || 16000,
134
+ fromAmbientEnv: false,
135
+ envVarName: entry.apiKeyEnv || null,
136
+ };
137
+ }
138
+
139
+ // 3. Ambient environment variable detection (subject to Privacy Consent Gate)
140
+ for (const cand of AMBIENT_ENV_CANDIDATES) {
141
+ const resolved = readAmbientCandidate(cand, env, modelOverride);
142
+ if (resolved) return resolved;
143
+ }
144
+
145
+ return null;
146
+ }
147
+
148
+ /**
149
+ * Resolve the active LLM execution route according to `config.routing`:
150
+ * - `"local"` (default): Tier 3 local model if installed -> otherwise deterministic-only + upgrade hint (0 uploads).
151
+ * - `"auto"`: Tier 1 Cloud -> Tier 2 BYOK/Loopback (with Privacy Gate) -> Tier 3 Local -> deterministic-only + hint.
152
+ * - `"cloud"`: Tier 1 Cloud strictly (throws Exit Code 2 `DislopConfigError` if missing auth).
153
+ * - `"byok"`: Tier 2 BYOK/Loopback strictly (throws Exit Code 2 `DislopConfigError` if missing provider/key).
154
+ */
155
+ export async function resolveExecutionRoute({
156
+ config,
157
+ isTty,
158
+ env = process.env,
159
+ stdin = process.stdin,
160
+ stderr = process.stderr,
161
+ fetchImpl = globalThis.fetch,
162
+ promptFn = null,
163
+ }) {
164
+ if (config.noLlm || config.routing === "off" || env.DISLOP_TEST_MODE === "1") {
165
+ return { tier: "none", engineLabel: "deterministic", maxInputTokens: 0, execute: null };
166
+ }
167
+
168
+ const mode = config.routing || "local";
169
+
170
+ // Explicit Cloud
171
+ if (mode === "cloud") {
172
+ const creds = loadCloudCredentials(config.credentialsPath);
173
+ if (!creds) {
174
+ throw new DislopConfigError(
175
+ "Engine 'cloud' requires authentication. Run 'dislop login' first.",
176
+ );
177
+ }
178
+ return {
179
+ tier: "cloud",
180
+ engineLabel: "cloud:dislop",
181
+ maxInputTokens: 20000,
182
+ execute: (payload, doc, promptRules) =>
183
+ invokeCloudProvider({ credentials: creds, payload, doc, promptRules, fetchImpl, env }),
184
+ };
185
+ }
186
+
187
+ // Explicit BYOK
188
+ if (mode === "byok") {
189
+ const provider = resolveTier2ProviderCandidate(config, env);
190
+ if (!provider) {
191
+ throw new DislopConfigError(
192
+ "Engine 'byok' requires a configured provider in config.json or an OPENAI_API_KEY / ANTHROPIC_API_KEY / GEMINI_API_KEY environment variable.",
193
+ );
194
+ }
195
+ const consent = await checkPrivacyConsent({
196
+ provider,
197
+ config,
198
+ isTty,
199
+ explicitByokFlag: Boolean(config.explicitEngine),
200
+ stdin,
201
+ stderr,
202
+ promptFn,
203
+ });
204
+ if (!consent || !consent.approved) {
205
+ throw new DislopConfigError(
206
+ consent?.reason || "BYOK external network upload cancelled or missing explicit consent.",
207
+ );
208
+ }
209
+ return buildTier2Route(provider, fetchImpl);
210
+ }
211
+
212
+ // 3-Tier Cascade (`--engine auto` or `routing: "auto"`)
213
+ if (mode === "auto") {
214
+ const creds = loadCloudCredentials(config.credentialsPath);
215
+ if (creds) {
216
+ return {
217
+ tier: "cloud",
218
+ engineLabel: "cloud:dislop",
219
+ maxInputTokens: 20000,
220
+ execute: (payload, doc, promptRules) =>
221
+ invokeCloudProvider({ credentials: creds, payload, doc, promptRules, fetchImpl, env }),
222
+ };
223
+ }
224
+
225
+ const provider = resolveTier2ProviderCandidate(config, env);
226
+ if (provider) {
227
+ const consent = await checkPrivacyConsent({
228
+ provider,
229
+ config,
230
+ isTty,
231
+ explicitByokFlag: false,
232
+ stdin,
233
+ stderr,
234
+ promptFn,
235
+ });
236
+ if (consent.approved) {
237
+ return buildTier2Route(provider, fetchImpl);
238
+ }
239
+ }
240
+ }
241
+
242
+ // Default `"local"` mode (and Tier 3 fallback of `"auto"`): check installed local model
243
+ const localModel = resolveInstalledLocalModel(config, env);
244
+ if (localModel) {
245
+ const resolvedLocal = config.modelOverride
246
+ ? { ...localModel, model: String(config.modelOverride).trim() }
247
+ : localModel;
248
+ return {
249
+ tier: "local",
250
+ engineLabel: `local:${resolvedLocal.model}`,
251
+ maxInputTokens: resolvedLocal.maxInputTokens || 8000,
252
+ fallbackOnConnRefused: !config.explicitEngine,
253
+ execute: (payload) => invokeLocalModelProvider({ localModel: resolvedLocal, payload, fetchImpl, env }),
254
+ };
255
+ }
256
+
257
+ // Also allow loopback provider configured in `config.providers` when routing === "local"
258
+ const maybeLoopback = resolveTier2ProviderCandidate(config, env);
259
+ if (maybeLoopback && isLoopbackHostname(extractHostname(maybeLoopback.baseUrl))) {
260
+ if (String(maybeLoopback.baseUrl).includes(":11434") || /ollama/i.test(maybeLoopback.name)) {
261
+ return {
262
+ tier: "local",
263
+ engineLabel: `local:${maybeLoopback.model}`,
264
+ maxInputTokens: maybeLoopback.maxInputTokens || 8000,
265
+ fallbackOnConnRefused: !config.explicitEngine,
266
+ execute: (payload) =>
267
+ invokeLocalModelProvider({ localModel: maybeLoopback, payload, fetchImpl, env }),
268
+ };
269
+ }
270
+ return buildTier2Route(maybeLoopback, fetchImpl, "local");
271
+ }
272
+
273
+ const ollama = detectOllamaBinary(env);
274
+ let fallbackHint = UPGRADE_TIER_HINT;
275
+ if (config.explicitEngine && mode === "local") {
276
+ fallbackHint = ollama.installed
277
+ ? "💡 No Tier 3 local model installed yet. Running deterministic Script Packs only — start 'ollama serve' and run 'dislop model pull qwen2.5-1.5b-instruct' to enable local LLM checks."
278
+ : `💡 Ollama is missing on this machine (required for Tier 3 '--engine local' LLM checks). Running deterministic Script Packs only — ${OLLAMA_INSTALL_HINT}`;
279
+ } else if (!ollama.installed) {
280
+ fallbackHint =
281
+ "💡 Running local deterministic checks only (Ollama is not installed for Tier 3 local LLM). For deeper semantic de-slopping, run 'dislop login' (Cloud), pass '--engine auto' / '--engine byok', or install Ollama (https://ollama.com) and run 'dislop model pull'.";
282
+ }
283
+
284
+ return {
285
+ tier: "none",
286
+ engineLabel: "deterministic",
287
+ maxInputTokens: 0,
288
+ hint: fallbackHint,
289
+ execute: null,
290
+ };
291
+ }
292
+
293
+ function buildTier2Route(provider, fetchImpl, labelPrefix = "byok") {
294
+ const protocol = String(provider.protocol || "openai").toLowerCase();
295
+ const engineLabel = `${labelPrefix}:${provider.model}`;
296
+ const maxInputTokens = provider.maxInputTokens || 16000;
297
+ const isLoopback = isLoopbackHostname(extractHostname(provider.baseUrl || ""));
298
+
299
+ if (protocol === "anthropic") {
300
+ return {
301
+ tier: labelPrefix,
302
+ isLoopback,
303
+ engineLabel,
304
+ maxInputTokens,
305
+ execute: (payload) => invokeAnthropicProvider({ provider, payload, fetchImpl }),
306
+ };
307
+ }
308
+ if (protocol === "gemini") {
309
+ return {
310
+ tier: labelPrefix,
311
+ isLoopback,
312
+ engineLabel,
313
+ maxInputTokens,
314
+ execute: (payload) => invokeGeminiProvider({ provider, payload, fetchImpl }),
315
+ };
316
+ }
317
+ return {
318
+ tier: labelPrefix,
319
+ isLoopback,
320
+ engineLabel,
321
+ maxInputTokens,
322
+ execute: (payload) => invokeOpenAiCompatProvider({ provider, payload, fetchImpl }),
323
+ };
324
+ }