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,132 @@
1
+ import fs from "node:fs";
2
+ import {
3
+ isCiEnvironment,
4
+ isInteractiveHumanTty,
5
+ resolveLayeredConfig,
6
+ } from "../kernel/config.mjs";
7
+ import { listBuiltinPackIds } from "../kernel/pack-loader.mjs";
8
+ import {
9
+ detectOllamaBinary,
10
+ readInstalledModelsManifest,
11
+ } from "../runtime/providers/local-model.mjs";
12
+ import {
13
+ loadCloudCredentials,
14
+ resolveExecutionRoute,
15
+ resolveTier2ProviderCandidate,
16
+ } from "../runtime/router.mjs";
17
+ import { isWorklogActive } from "../runtime/worklog.mjs";
18
+
19
+ /**
20
+ * `dislop doctor [--json]` — zero-network diagnostic snapshot of config, active tier, auth, voice, and Packs.
21
+ */
22
+ export async function runDoctorCommand(_positionals, flags, io = {}) {
23
+ const {
24
+ cwd = process.cwd(),
25
+ env = process.env,
26
+ stdin = process.stdin,
27
+ stdout = process.stdout,
28
+ stderr = process.stderr,
29
+ } = io;
30
+
31
+ const isTty = isInteractiveHumanTty({ stdin, stdout, env });
32
+ const config = resolveLayeredConfig({ cwd, env, cliFlags: flags });
33
+ const cloudCreds = loadCloudCredentials(config.credentialsPath);
34
+ const tier2Candidate = resolveTier2ProviderCandidate(config, env);
35
+ const modelsManifest = readInstalledModelsManifest(config.modelsDir);
36
+ const ollama = detectOllamaBinary(env);
37
+ const builtinPacks = listBuiltinPackIds();
38
+
39
+ // Resolve route non-interactively so `doctor` never triggers consent prompts
40
+ const route = await resolveExecutionRoute({
41
+ config,
42
+ isTty: false,
43
+ env,
44
+ stdin,
45
+ stderr: { write() {} },
46
+ });
47
+
48
+ const diagnosis = {
49
+ schema: "dislop.doctor/1",
50
+ nodeVersion: process.version,
51
+ interactiveTty: isTty,
52
+ routingMode: config.routing,
53
+ activeEngine: route.engineLabel,
54
+ activeTier: route.tier,
55
+ configSources: config.loadedSources,
56
+ approvedHosts: config.approvedHosts,
57
+ cloudAuthenticated: Boolean(cloudCreds),
58
+ byokCandidate: tier2Candidate
59
+ ? {
60
+ name: tier2Candidate.name,
61
+ protocol: tier2Candidate.protocol,
62
+ model: tier2Candidate.model,
63
+ baseUrl: tier2Candidate.baseUrl,
64
+ fromAmbientEnv: tier2Candidate.fromAmbientEnv,
65
+ }
66
+ : null,
67
+ localModels: {
68
+ ollamaInstalled: ollama.installed,
69
+ ollamaBinary: ollama.binaryPath,
70
+ activeModel: modelsManifest.activeModel,
71
+ installed: Object.keys(modelsManifest.installed),
72
+ },
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
+ },
82
+ configuredPacks: config.packs || ["(auto by document format & language)"],
83
+ builtinPacks,
84
+ };
85
+
86
+ if (flags.json || flags.format === "json") {
87
+ stdout.write(`${JSON.stringify(diagnosis, null, 2)}\n`);
88
+ return 0;
89
+ }
90
+
91
+ stdout.write("dislop doctor\n");
92
+ stdout.write(` Node.js : ${diagnosis.nodeVersion}\n`);
93
+ stdout.write(` Interactive TTY : ${diagnosis.interactiveTty ? "yes" : "no (read-only / batch safe)"}\n`);
94
+ stdout.write(` Routing Mode : ${diagnosis.routingMode} -> active engine '${diagnosis.activeEngine}'\n`);
95
+ stdout.write(
96
+ ` Config Files : ${diagnosis.configSources.length > 0 ? diagnosis.configSources.join(", ") : "(defaults only)"}\n`,
97
+ );
98
+ stdout.write(` Cloud Tier 1 : ${diagnosis.cloudAuthenticated ? "authenticated" : "not logged in"}\n`);
99
+ stdout.write(
100
+ ` BYOK Tier 2 : ${
101
+ diagnosis.byokCandidate
102
+ ? `${diagnosis.byokCandidate.name} (${diagnosis.byokCandidate.protocol}:${diagnosis.byokCandidate.model})`
103
+ : "not configured"
104
+ }\n`,
105
+ );
106
+ stdout.write(
107
+ ` Approved Hosts : ${diagnosis.approvedHosts.length > 0 ? diagnosis.approvedHosts.join(", ") : "(none)"}\n`,
108
+ );
109
+ const ollamaStatusText = diagnosis.localModels.ollamaInstalled
110
+ ? `Ollama: ${diagnosis.localModels.ollamaBinary}`
111
+ : "Ollama: MISSING — install from https://ollama.com";
112
+ stdout.write(
113
+ ` Local Tier 3 : ${
114
+ diagnosis.localModels.installed.length > 0
115
+ ? diagnosis.localModels.installed.join(", ")
116
+ : "none installed (run 'dislop model pull')"
117
+ } (${ollamaStatusText})\n`,
118
+ );
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
+ );
129
+ stdout.write(` Built-in Packs : ${diagnosis.builtinPacks.join(", ")}\n`);
130
+
131
+ return 0;
132
+ }
@@ -0,0 +1,55 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { getDislopHomeDir, writeJsonFileSecure } from "../kernel/config.mjs";
4
+
5
+ /**
6
+ * `dislop init [--global] [--voice <glob>] [--force]`
7
+ */
8
+ export async function runInitCommand(_positionals, flags, io = {}) {
9
+ const { cwd = process.cwd(), env = process.env, stdout = process.stdout } = io;
10
+
11
+ const targetPath = flags.global
12
+ ? path.join(getDislopHomeDir(env), "config.json")
13
+ : path.join(cwd, ".dislop.json");
14
+
15
+ if (fs.existsSync(targetPath) && !flags.force) {
16
+ stdout.write(`Config already exists at ${targetPath} (pass --force to overwrite).\n`);
17
+ return 0;
18
+ }
19
+
20
+ const voiceRefs = flags.voiceFiles && flags.voiceFiles.length > 0 ? flags.voiceFiles : [];
21
+
22
+ const template = 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
+ };
46
+
47
+ if (flags.global) {
48
+ writeJsonFileSecure(targetPath, template, { mode: 0o600 });
49
+ } else {
50
+ fs.writeFileSync(targetPath, `${JSON.stringify(template, null, 2)}\n`, "utf8");
51
+ }
52
+
53
+ stdout.write(`Initialized dislop configuration at ${targetPath}\n`);
54
+ return 0;
55
+ }
@@ -0,0 +1,82 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import readline from "node:readline";
4
+ import {
5
+ DislopConfigError,
6
+ getDislopHomeDir,
7
+ isInteractiveHumanTty,
8
+ writeJsonFileSecure,
9
+ } from "../kernel/config.mjs";
10
+ import { DEFAULT_CLOUD_REVIEW_URL } from "../runtime/providers/cloud.mjs";
11
+
12
+ function promptTokenInteractive({ stdin = process.stdin, stderr = process.stderr } = {}) {
13
+ return new Promise((resolve) => {
14
+ const rl = readline.createInterface({ input: stdin, output: stderr });
15
+ rl.question(
16
+ "Sign in at https://dislop.com to generate an API key (dslp_*), then paste token here: ",
17
+ (answer) => {
18
+ rl.close();
19
+ resolve(String(answer || "").trim());
20
+ },
21
+ );
22
+ });
23
+ }
24
+
25
+ /**
26
+ * `dislop login [--token <token>] [--endpoint <url>]`
27
+ */
28
+ export async function runLoginCommand(_positionals, flags, io = {}) {
29
+ const {
30
+ env = process.env,
31
+ stdin = process.stdin,
32
+ stdout = process.stdout,
33
+ stderr = process.stderr,
34
+ } = io;
35
+
36
+ const homeDir = getDislopHomeDir(env);
37
+ const credentialsPath = path.join(homeDir, "credentials.json");
38
+
39
+ let token = flags.token ? String(flags.token).trim() : "";
40
+ if (!token) {
41
+ if (!isInteractiveHumanTty({ stdin, stdout, env })) {
42
+ throw new DislopConfigError(
43
+ "Non-interactive 'dislop login' requires --token <dslp_token>.",
44
+ );
45
+ }
46
+ token = await promptTokenInteractive({ stdin, stderr });
47
+ }
48
+
49
+ if (!token) {
50
+ throw new DislopConfigError("No token supplied; login aborted.");
51
+ }
52
+
53
+ const endpoint = flags.endpoint || DEFAULT_CLOUD_REVIEW_URL;
54
+ writeJsonFileSecure(
55
+ credentialsPath,
56
+ {
57
+ accessToken: token,
58
+ endpoint,
59
+ savedAt: new Date().toISOString(),
60
+ },
61
+ { mode: 0o600 },
62
+ );
63
+
64
+ stdout.write(`Saved Official Cloud credentials to ${credentialsPath}\n`);
65
+ return 0;
66
+ }
67
+
68
+ /**
69
+ * `dislop logout`
70
+ */
71
+ export async function runLogoutCommand(_positionals, _flags, io = {}) {
72
+ const { env = process.env, stdout = process.stdout } = io;
73
+ const credentialsPath = path.join(getDislopHomeDir(env), "credentials.json");
74
+
75
+ if (fs.existsSync(credentialsPath)) {
76
+ fs.unlinkSync(credentialsPath);
77
+ stdout.write(`Removed credentials at ${credentialsPath}\n`);
78
+ } else {
79
+ stdout.write("No active Official Cloud credentials found.\n");
80
+ }
81
+ return 0;
82
+ }
@@ -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,81 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { DislopConfigError } from "../kernel/config.mjs";
4
+ import { listBuiltinPackIds, loadSinglePack } from "../kernel/pack-loader.mjs";
5
+ import { validatePackPath } from "../kernel/pack-validator.mjs";
6
+
7
+ /**
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.
10
+ */
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
+ }
46
+
47
+ const ids = listBuiltinPackIds();
48
+ const details = [];
49
+ for (const id of ids) {
50
+ const p = await loadSinglePack(id, { cwd });
51
+ details.push({
52
+ name: p.name,
53
+ version: p.version,
54
+ description: p.description,
55
+ languages: p.languages || ["all"],
56
+ formats: p.formats || ["all"],
57
+ hasScripts: Boolean(p.hasScripts),
58
+ hasPrompts: Boolean(p.hasPrompts),
59
+ scriptFileCount: p.loadStats?.scriptFileCount ?? 0,
60
+ promptFileCount: p.loadStats?.promptFileCount ?? 0,
61
+ });
62
+ }
63
+
64
+ if (flags.json || flags.format === "json") {
65
+ stdout.write(`${JSON.stringify({ packs: details }, null, 2)}\n`);
66
+ return 0;
67
+ }
68
+
69
+ stdout.write("Built-in Packs (Layout: packs/<scope-or-lang>/<scenario>/{pack.json,scripts/,prompts/}):\n");
70
+ for (const d of details) {
71
+ const layers = [
72
+ d.hasScripts ? `scripts(${d.scriptFileCount})` : null,
73
+ d.hasPrompts ? `prompts(${d.promptFileCount})` : null,
74
+ ]
75
+ .filter(Boolean)
76
+ .join(", ");
77
+ stdout.write(` - ${d.name} (v${d.version}) [${layers}]\n`);
78
+ stdout.write(` ${d.description}\n`);
79
+ }
80
+ return 0;
81
+ }
@@ -0,0 +1,165 @@
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, resolveLayeredConfig } from "../kernel/config.mjs";
7
+ import { detectFormatFromPath, parseDocumentFile, parseDocumentText } from "../kernel/document-model.mjs";
8
+ import { verifyDocumentRevision } from "../kernel/fact-gate.mjs";
9
+ import { buildVerifyWorklogEntry, recordWorklogEntry } from "../runtime/worklog.mjs";
10
+
11
+ function extractComparableText(filePath) {
12
+ const doc = parseDocumentFile(filePath);
13
+ if (doc.segments.length > 0) {
14
+ return doc.segments.map((s) => s.text).join("\n");
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
+ }
22
+ return fs.readFileSync(filePath, "utf8");
23
+ }
24
+
25
+ function extractComparableTextFromBuffer(buf, targetPath) {
26
+ const fmt = detectFormatFromPath(targetPath);
27
+ if (fmt === "docx" || fmt === "pptx" || fmt === "pdf") {
28
+ const tmpFile = path.join(
29
+ os.tmpdir(),
30
+ `dislop-verify-${process.pid}-${crypto.randomBytes(4).toString("hex")}.${fmt}`,
31
+ );
32
+ fs.writeFileSync(tmpFile, buf);
33
+ try {
34
+ return extractComparableText(tmpFile);
35
+ } finally {
36
+ if (fs.existsSync(tmpFile)) fs.unlinkSync(tmpFile);
37
+ }
38
+ }
39
+ const text = buf.toString("utf8");
40
+ if (fmt) {
41
+ const doc = parseDocumentText(text, targetPath, fmt);
42
+ if (doc.segments.length > 0) {
43
+ return doc.segments.map((s) => s.text).join("\n");
44
+ }
45
+ }
46
+ return text;
47
+ }
48
+
49
+ /**
50
+ * `dislop verify <beforeFile> <afterFile> [--json]`
51
+ * or `dislop verify --git [ref] <file> [--json]`
52
+ */
53
+ export async function runVerifyCommand(positionals, flags, io = {}) {
54
+ const { cwd = process.cwd(), env = process.env, stdout = process.stdout } = io;
55
+ const startedAt = Date.now();
56
+
57
+ let beforeText = "";
58
+ let afterText = "";
59
+ let label = "";
60
+
61
+ if (flags.git !== undefined && flags.git !== false) {
62
+ const gitRef = typeof flags.git === "string" && flags.git.trim() ? flags.git.trim() : "HEAD";
63
+ const targetArg = positionals[0];
64
+ if (!targetArg) {
65
+ throw new DislopConfigError(
66
+ "Usage: dislop verify --git [ref] <file> (missing target file)",
67
+ );
68
+ }
69
+ const resolvedTarget = path.resolve(cwd, targetArg);
70
+ if (!fs.existsSync(resolvedTarget)) {
71
+ throw new DislopConfigError(`Target file not found: '${targetArg}'`);
72
+ }
73
+ const absTarget = fs.realpathSync(resolvedTarget);
74
+
75
+ let repoRoot;
76
+ try {
77
+ repoRoot = execFileSync("git", ["rev-parse", "--show-toplevel"], {
78
+ cwd: path.dirname(absTarget),
79
+ encoding: "utf8",
80
+ }).trim();
81
+ } catch (err) {
82
+ throw new DislopConfigError(`Unable to locate git repository for --git verify: ${err.message}`);
83
+ }
84
+
85
+ const relGitPath = path.relative(repoRoot, absTarget).replace(/\\/g, "/");
86
+ let beforeBuf;
87
+ try {
88
+ beforeBuf = execFileSync("git", ["show", `${gitRef}:${relGitPath}`], {
89
+ cwd: repoRoot,
90
+ maxBuffer: 32 * 1024 * 1024,
91
+ });
92
+ } catch (err) {
93
+ throw new DislopConfigError(
94
+ `Could not read '${relGitPath}' at git ref '${gitRef}': ${err.message}`,
95
+ );
96
+ }
97
+ beforeText = extractComparableTextFromBuffer(beforeBuf, absTarget);
98
+ afterText = extractComparableText(absTarget);
99
+ label = `${gitRef}:${relGitPath} -> ${targetArg}`;
100
+ } else {
101
+ if (positionals.length < 2) {
102
+ throw new DislopConfigError(
103
+ "Usage: dislop verify <before-file> <after-file> (or dislop verify --git [ref] <file>)",
104
+ );
105
+ }
106
+ const beforePath = path.resolve(cwd, positionals[0]);
107
+ const afterPath = path.resolve(cwd, positionals[1]);
108
+ if (!fs.existsSync(beforePath)) {
109
+ throw new DislopConfigError(`Before file not found: '${positionals[0]}'`);
110
+ }
111
+ if (!fs.existsSync(afterPath)) {
112
+ throw new DislopConfigError(`After file not found: '${positionals[1]}'`);
113
+ }
114
+ beforeText = extractComparableText(beforePath);
115
+ afterText = extractComparableText(afterPath);
116
+ label = `${positionals[0]} -> ${positionals[1]}`;
117
+ }
118
+
119
+ const verification = verifyDocumentRevision(beforeText, afterText);
120
+ const payload = {
121
+ schema: "dislop.verify/1",
122
+ target: label,
123
+ ...verification,
124
+ };
125
+
126
+ if (flags.json || flags.format === "json") {
127
+ stdout.write(`${JSON.stringify(payload, null, 2)}\n`);
128
+ } else if (verification.ok) {
129
+ stdout.write(
130
+ `PASS ${label}: anchored tokens & qualifiers preserved; 0 detected slop/polarity regressions.\n`,
131
+ );
132
+ } else {
133
+ stdout.write(`FAIL ${label}:\n`);
134
+ for (const reason of verification.droppedFacts) {
135
+ stdout.write(` - Fact Gate: ${reason}\n`);
136
+ }
137
+ for (const reg of verification.regressions) {
138
+ stdout.write(` - Regression (${reg.id}): ${reg.message}\n`);
139
+ }
140
+ }
141
+
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;
165
+ }