@aiwg/cli 2026.11.5 → 2026.11.7
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/agentic/code/providers/model-capabilities.v1.json +9 -9
- package/bin/aiwg.mjs +6 -4
- package/dist/src/activity-log/cli.js +1 -1
- package/dist/src/agents/agent-deployer.js +1 -1
- package/dist/src/artifacts/audit/types.js +1 -1
- package/dist/src/artifacts/browser-export.js +1 -0
- package/dist/src/artifacts/discover-facets.js +1 -1
- package/dist/src/artifacts/enrichment/prompt.js +1 -1
- package/dist/src/artifacts/enrichment/types.js +1 -1
- package/dist/src/artifacts/fortemi-core-query-adapter.js +2 -0
- package/dist/src/artifacts/index-builder.js +1 -0
- package/dist/src/artifacts/query-engine-discover-output.js +1 -0
- package/dist/src/artifacts/query-engine-discover.js +2 -2
- package/dist/src/artifacts/query-engine-scoring.js +7 -0
- package/dist/src/artifacts/template-output-kind.js +10 -0
- package/dist/src/artifacts/types.js +1 -1
- package/dist/src/artifacts/views/definition.js +1 -1
- package/dist/src/artifacts/views/types.js +1 -1
- package/dist/src/catalog/cli.js +1 -1
- package/dist/src/catalog/cli.mjs +1 -1
- package/dist/src/catalog/loader.js +1 -1
- package/dist/src/catalog/loader.mjs +1 -1
- package/dist/src/catalog/types.js +1 -1
- package/dist/src/cli/cli-extension-loader.js +19 -5
- package/dist/src/cli/cli-extension-paths.js +65 -0
- package/dist/src/cli/handlers/best-practices-audit.js +1 -1
- package/dist/src/cli/handlers/dataset.js +11 -2
- package/dist/src/cli/handlers/help.js +3 -4
- package/dist/src/cli/handlers/index.js +1 -1
- package/dist/src/cli/handlers/marketplace-plugin-search.js +37 -0
- package/dist/src/cli/handlers/marketplace.js +3 -1
- package/dist/src/cli/handlers/models.js +1 -1
- package/dist/src/cli/handlers/ralph-launcher.js +8 -2
- package/dist/src/cli/handlers/ralph.js +1 -1
- package/dist/src/cli/handlers/runtime-info.js +1 -1
- package/dist/src/cli/handlers/scaffolding.js +2 -2
- package/dist/src/cli/handlers/script-runner.js +1 -1
- package/dist/src/cli/handlers/sdlc-accelerate.js +1 -1
- package/dist/src/cli/handlers/subcommands-bundles.js +1 -1
- package/dist/src/cli/handlers/subcommands-list-format.js +19 -1
- package/dist/src/cli/handlers/types.js +1 -1
- package/dist/src/cli/handlers/update.js +26 -12
- package/dist/src/cli/handlers/use.js +6 -5
- package/dist/src/cli/handlers/utilities.js +1 -1
- package/dist/src/cli/handlers/version.js +1 -1
- package/dist/src/cli/handlers/workspace.js +1 -1
- package/dist/src/cli/handlers/writing.js +7 -1
- package/dist/src/cli/help-generator.js +9 -11
- package/dist/src/cli/hooks/builtin/activity-log-hook.js +1 -1
- package/dist/src/cli/router.js +1 -1
- package/dist/src/cli/workflow-orchestrator.js +1 -1
- package/dist/src/config/worker-context.js +37 -7
- package/dist/src/config/worker-parallelism.js +11 -0
- package/dist/src/contributors/detect.js +1 -1
- package/dist/src/contributors/discover.js +1 -1
- package/dist/src/contributors/heuristic.js +1 -1
- package/dist/src/contributors/index.js +1 -1
- package/dist/src/contributors/types.js +1 -1
- package/dist/src/contributors/validation.js +1 -1
- package/dist/src/dataset/backend-selection.d.ts +3 -0
- package/dist/src/dataset/backend-selection.js +11 -0
- package/dist/src/dataset/contract-range.d.ts +7 -0
- package/dist/src/dataset/contract-range.js +55 -0
- package/dist/src/dataset/fortemi-execution-bridge.d.ts +2 -0
- package/dist/src/dataset/fortemi-execution-bridge.js +12 -1
- package/dist/src/dataset/index.d.ts +2 -0
- package/dist/src/dataset/index.js +2 -0
- package/dist/src/dataset/orchestration-service.d.ts +1 -1
- package/dist/src/dataset/orchestration-service.js +7 -8
- package/dist/src/dataset/orchestration-types.d.ts +2 -0
- package/dist/src/dataset/service-binding-checkpoints.d.ts +10 -0
- package/dist/src/dataset/service-binding-checkpoints.js +26 -0
- package/dist/src/dataset/service-binding-contract.d.ts +46 -0
- package/dist/src/dataset/service-binding-contract.js +25 -0
- package/dist/src/dataset/service-binding-registry.d.ts +12 -0
- package/dist/src/dataset/service-binding-registry.js +118 -0
- package/dist/src/effects/worker-delivery.js +83 -0
- package/dist/src/extensions/capability-index.js +1 -1
- package/dist/src/extensions/commands/definitions.js +2 -2
- package/dist/src/extensions/deployment-registration.js +1 -1
- package/dist/src/extensions/index.js +1 -1
- package/dist/src/extensions/loader.js +1 -1
- package/dist/src/extensions/manifest.js +27 -9
- package/dist/src/extensions/project-local-activity.js +1 -1
- package/dist/src/extensions/project-local-discovery.js +2 -2
- package/dist/src/extensions/project-local-doctor.js +9 -4
- package/dist/src/extensions/project-local-promote.js +3 -3
- package/dist/src/extensions/project-local-remove.js +3 -3
- package/dist/src/extensions/project-local-scaffold.js +1 -1
- package/dist/src/extensions/project-quickref-discovery.js +11 -0
- package/dist/src/extensions/project-quickref.js +4 -7
- package/dist/src/extensions/registry.js +1 -1
- package/dist/src/extensions/shadow-resolver.js +1 -1
- package/dist/src/extensions/types.js +1 -1
- package/dist/src/extensions/upstream-registry.js +1 -1
- package/dist/src/extensions/validation.js +1 -1
- package/dist/src/intake/git-history-analyzer.js +1 -1
- package/dist/src/kb/cli.js +1 -1
- package/dist/src/marketplace/plugin-directory.js +36 -0
- package/dist/src/marketplace/plugin-search.js +180 -0
- package/dist/src/mcp/cli.mjs +2 -2
- package/dist/src/mcp/helpers.mjs +1 -1
- package/dist/src/mcp/http-tools.mjs +8 -6
- package/dist/src/mcp/http-transport.mjs +3 -1
- package/dist/src/mcp/server.mjs +1 -1
- package/dist/src/mcp/tools/command-run.mjs +1 -1
- package/dist/src/mcp/tools/discovery.mjs +1 -1
- package/dist/src/mcp/tools/subsystems.mjs +1 -1
- package/dist/src/mcp/tools/worker-invoke.mjs +71 -23
- package/dist/src/mcp/tools/worker-launch-ledger.mjs +33 -0
- package/dist/src/mcp/tools/worker-local-only-preflight.mjs +79 -0
- package/dist/src/mcp/tools/worker-recorded-launch.mjs +26 -0
- package/dist/src/mcp/tools/worker-stdin-runtime.mjs +33 -6
- package/dist/src/mcp/tools/worker-verify-deliver-schema.mjs +49 -0
- package/dist/src/mcp/tools/worker-verify-deliver.mjs +25 -0
- package/dist/src/models/catalog-policy.js +2 -2
- package/dist/src/models/conductor-data-policy.mjs +83 -14
- package/dist/src/models/config-loader.js +2 -2
- package/dist/src/models/index.js +2 -2
- package/dist/src/models/local-endpoint-models.js +155 -0
- package/dist/src/models/model-capabilities.v1.json +9 -9
- package/dist/src/models/model-discovery.js +9 -5
- package/dist/src/models/opencode-worker-model.mjs +16 -0
- package/dist/src/models/resolver.js +2 -2
- package/dist/src/models/worker-installation.mjs +5 -3
- package/dist/src/models/worker-plan.js +1 -1
- package/dist/src/plugin/plugin-installer.js +2 -2
- package/dist/src/plugin/registry-validator.js +2 -2
- package/dist/src/plugin/skill-command-translator.js +1 -1
- package/dist/src/providers/deployment-input-session.d.mts +2 -0
- package/dist/src/providers/deployment-input-session.mjs +38 -0
- package/dist/src/rlm/cache/hash.js +1 -1
- package/dist/src/rlm/cache/store.js +1 -1
- package/dist/src/rlm/cache/types.js +1 -1
- package/dist/src/serve/worker-invocation-preparation.js +54 -22
- package/dist/src/serve/worker-invocation.js +25 -8
- package/dist/src/serve/worker-shell-prompt.d.mts +6 -0
- package/dist/src/serve/worker-shell-prompt.mjs +78 -0
- package/dist/src/skills/run.js +0 -11
- package/dist/src/smiths/agentsmith/generator.js +1 -1
- package/dist/src/smiths/context-pipeline/index.js +1 -1
- package/dist/src/smiths/context-pipeline/provider-policy.js +1 -1
- package/dist/src/smiths/context-pipeline/types.js +1 -1
- package/dist/src/smiths/mcpsmith/analyzers/cli-analyzer.js +2 -2
- package/dist/src/smiths/mcpsmith/generator.js +2 -2
- package/dist/src/smiths/mcpsmith/index.js +2 -2
- package/dist/src/smiths/mcpsmith/types.js +2 -2
- package/dist/src/smiths/skillsmith/collision-detector.js +1 -1
- package/dist/src/smiths/skillsmith/namespace-adapter.js +1 -1
- package/dist/src/smiths/toolsmith/runtime-discovery.mjs +2 -2
- package/dist/src/smiths/toolsmith/types.js +2 -2
- package/dist/src/storage/backends/fortemi.js +1 -1
- package/dist/src/storage/backends/fs.js +1 -1
- package/dist/src/storage/backends/logseq.js +1 -1
- package/dist/src/storage/backends/obsidian.js +1 -1
- package/dist/src/storage/cli.js +2 -2
- package/dist/src/storage/config.js +1 -1
- package/dist/src/storage/index.js +1 -1
- package/dist/src/storage/subsystem-cli.js +1 -1
- package/dist/src/storage/types.js +1 -1
- package/dist/src/testing/generators/test-case-generator.js +1 -1
- package/dist/src/writing/campaign-patterns.js +96 -0
- package/dist/src/writing/campaign-report.js +41 -0
- package/dist/src/writing/contextual-diagnostics.js +29 -5
- package/dist/src/writing/current-patterns.catalogue.json +87 -0
- package/dist/src/writing/current-patterns.js +99 -0
- package/dist/src/writing/prose-mask.js +80 -0
- package/dist/src/writing/structural-patterns.js +109 -0
- package/dist/src/writing/validation-campaign.js +19 -0
- package/dist/src/writing/validation-engine.js +18 -11
- package/dist/src/writing/validation-rules.js +4 -3
- package/package.json +11 -1
- package/schemas/dataset/service-binding.v1.schema.json +70 -0
- package/schemas/models/model-catalog.v1.schema.json +6 -3
- package/tools/agents/providers/base-models-platforms.mjs +87 -48
- package/tools/agents/providers/conductor-data-guard.mjs +1 -1
- package/tools/agents/providers/rule-deployment-corpus-inputs.mjs +19 -0
- package/tools/agents/providers/rule-deployment-input-session.mjs +40 -0
- package/tools/agents/providers/rule-deployment-prepare.mjs +15 -6
- package/tools/plugin/package-plugins.mjs +2 -0
- package/tools/ralph-external/lib/mcp-worker-launch.mjs +67 -0
- package/tools/ralph-external/lib/opencode-adapter.mjs +9 -7
- package/tools/ralph-external/lib/trusted-verification.mjs +1021 -0
- package/tools/ralph-external/lib/typed-stop-delivery.mjs +55 -0
- package/tools/ralph-external/lib/verification-isolation.mjs +509 -0
- package/tools/ralph-external/lib/worker-context.mjs +3 -3
- package/tools/ralph-external/lib/worker-delivery-guards.mjs +141 -0
- package/tools/ralph-external/lib/worker-delivery-record.mjs +15 -0
- package/tools/ralph-external/lib/worker-final.mjs +4 -1
- package/tools/ralph-external/lib/worker-isolation-status.mjs +3 -0
- package/tools/ralph-external/lib/worker-launch-cli.mjs +8 -0
- package/tools/ralph-external/lib/worker-local-only-paths.mjs +45 -0
- package/tools/ralph-external/lib/worker-prompt.mjs +4 -1
- package/tools/ralph-external/lib/worker-retry-evidence.mjs +2 -1
- package/tools/ralph-external/lib/worker-run-directory-refusal.mjs +2 -1
- package/tools/ralph-external/lib/worker-run-directory.mjs +45 -0
- package/tools/ralph-external/lib/worker-unit-cleanup.mjs +10 -2
- package/tools/ralph-external/lib/worker-verification-cli.mjs +164 -0
- package/tools/ralph-external/lib/worktree-preparation.mjs +417 -0
- package/tools/ralph-external/session-launcher.mjs +8 -15
- package/vscode-extension/schemas/aiwg.config.v1.json +27 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// Compare prose sentences and opening/closing forms within one explicit campaign set.
|
|
2
|
+
import { maskProse } from './prose-mask.js';
|
|
3
|
+
import { proseParagraphs, stopWords, words } from './structural-patterns.js';
|
|
4
|
+
export const MAX_CAMPAIGN_DOCUMENTS = 200;
|
|
5
|
+
export function checkCampaignSize(count) {
|
|
6
|
+
if (count > MAX_CAMPAIGN_DOCUMENTS)
|
|
7
|
+
throw new RangeError(`Campaign exceeds ${MAX_CAMPAIGN_DOCUMENTS} documents; split it into smaller campaign sets.`);
|
|
8
|
+
}
|
|
9
|
+
export function scanCampaignPatterns(documents) {
|
|
10
|
+
checkCampaignSize(documents.length);
|
|
11
|
+
const byDocument = new Map();
|
|
12
|
+
const out = new Map();
|
|
13
|
+
const records = documents.flatMap(d => {
|
|
14
|
+
if (out.has(d.id))
|
|
15
|
+
throw new Error(`Duplicate document ID: ${d.id}`);
|
|
16
|
+
out.set(d.id, []);
|
|
17
|
+
const own = proseParagraphs(maskProse(d.content)).flatMap(p => p.sentences);
|
|
18
|
+
const indexed = own.map(s => ({ ...s, document: d, key: s.tokens.join(' '), line: d.content.slice(0, s.start).split('\n').length }));
|
|
19
|
+
byDocument.set(d.id, indexed);
|
|
20
|
+
return indexed;
|
|
21
|
+
});
|
|
22
|
+
const emit = (id, tier, r, related, explanation, suggestion) => {
|
|
23
|
+
// A one-sentence post can share both boundaries; keep one diagnostic per span/rule.
|
|
24
|
+
if (out.get(r.document.id).some(f => f.ruleId === id && f.start === r.start && f.end === r.end))
|
|
25
|
+
return;
|
|
26
|
+
out.get(r.document.id).push({ ruleId: id, tier, start: r.start, end: r.end, scope: 'cross', explanation, suggestion,
|
|
27
|
+
related: related.filter(o => o !== r).map(o => ({ documentId: o.document.id, line: o.line })).sort((a, b) => a.documentId.localeCompare(b.documentId) || a.line - b.line) });
|
|
28
|
+
};
|
|
29
|
+
const group = (pairs) => {
|
|
30
|
+
const map = new Map();
|
|
31
|
+
for (const [key, record] of pairs) {
|
|
32
|
+
let occurrences = map.get(key);
|
|
33
|
+
if (!occurrences) {
|
|
34
|
+
occurrences = [];
|
|
35
|
+
map.set(key, occurrences);
|
|
36
|
+
}
|
|
37
|
+
occurrences.push(record);
|
|
38
|
+
}
|
|
39
|
+
return map;
|
|
40
|
+
};
|
|
41
|
+
const repeated = new Set();
|
|
42
|
+
for (const [key, occurrences] of group(records.filter(r => r.tokens.length >= 6).map(r => [r.key, r]))) {
|
|
43
|
+
if (occurrences.length < 2)
|
|
44
|
+
continue;
|
|
45
|
+
repeated.add(key);
|
|
46
|
+
for (const r of occurrences)
|
|
47
|
+
emit('repeated-sentence', 'cut', r, occurrences, 'This sentence repeats within the campaign set.', 'Write each channel from its relevant facts; retain required repetition with a reason.');
|
|
48
|
+
}
|
|
49
|
+
const shingles = group(records.flatMap(r => r.tokens.slice(0, -7).map((_, i) => [r.tokens.slice(i, i + 8).join(' '), r])));
|
|
50
|
+
const shingleDocuments = new Map([...shingles].map(([key, occurrences]) => [key, new Set(occurrences.map(r => r.document.id)).size]));
|
|
51
|
+
for (const r of records) {
|
|
52
|
+
if (repeated.has(r.key))
|
|
53
|
+
continue;
|
|
54
|
+
const covered = new Set();
|
|
55
|
+
const related = new Set();
|
|
56
|
+
for (let i = 0; i + 8 <= r.tokens.length; i++) {
|
|
57
|
+
const key = r.tokens.slice(i, i + 8).join(' ');
|
|
58
|
+
if (shingleDocuments.get(key) < 3)
|
|
59
|
+
continue;
|
|
60
|
+
const occurrences = shingles.get(key);
|
|
61
|
+
for (let j = i; j < i + 8; j++)
|
|
62
|
+
covered.add(j);
|
|
63
|
+
for (const o of occurrences)
|
|
64
|
+
related.add(o);
|
|
65
|
+
}
|
|
66
|
+
// Shingles identify shared runs; each affected sentence receives one phrase finding.
|
|
67
|
+
for (const index of covered)
|
|
68
|
+
if (!covered.has(index - 1))
|
|
69
|
+
emit('repeated-phrase', 'check', r, [...related], 'An eight-word or longer run is shared by at least three documents.', 'Rewrite the shared run for the reader and channel.');
|
|
70
|
+
}
|
|
71
|
+
for (const edge of ['opening', 'closing']) {
|
|
72
|
+
const pairs = [];
|
|
73
|
+
for (const d of documents) {
|
|
74
|
+
const own = byDocument.get(d.id);
|
|
75
|
+
const r = edge === 'opening' ? own[0] : own.at(-1);
|
|
76
|
+
if (!r)
|
|
77
|
+
continue;
|
|
78
|
+
const normalized = words(r.text.replace(/\d+(?:[.-]\d+)*/g, ' num '));
|
|
79
|
+
if (normalized.length < 3)
|
|
80
|
+
continue;
|
|
81
|
+
const key = (edge === 'opening' ? normalized.slice(0, 3) : normalized.slice(-3)).join(' ');
|
|
82
|
+
if (key.split(' ').some(w => !stopWords.has(w)))
|
|
83
|
+
pairs.push([key, r]);
|
|
84
|
+
}
|
|
85
|
+
for (const occurrences of group(pairs).values()) {
|
|
86
|
+
if (new Set(occurrences.map(r => r.document.id)).size < 3)
|
|
87
|
+
continue;
|
|
88
|
+
for (const r of occurrences)
|
|
89
|
+
emit('shared-skeleton', 'check', r, occurrences, `The ${edge} shares three boundary words across at least three documents; numbers and versions are normalized.`, 'Lead or close with the useful change for this channel instead of a recurring template.');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
for (const findings of out.values())
|
|
93
|
+
findings.sort((a, b) => a.start - b.start || a.ruleId.localeCompare(b.ruleId));
|
|
94
|
+
return out;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=campaign-patterns.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Render read-only campaign checks for the existing writing CLI entry point.
|
|
2
|
+
import { readFile, readdir } from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { checkCampaignSize } from './campaign-patterns.js';
|
|
5
|
+
import { diagnoseWritingBatch } from './contextual-diagnostics.js';
|
|
6
|
+
export async function campaignReport(cwd, args) {
|
|
7
|
+
const files = new Set();
|
|
8
|
+
const json = args.includes('--json');
|
|
9
|
+
const inputs = args.filter(a => !['--cross', '--json'].includes(a));
|
|
10
|
+
if (!inputs.length || inputs.some(a => a.startsWith('-')))
|
|
11
|
+
throw new Error('Expected campaign files or directories');
|
|
12
|
+
const visit = async (file) => {
|
|
13
|
+
try {
|
|
14
|
+
const entries = await readdir(file, { withFileTypes: true });
|
|
15
|
+
for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
16
|
+
if (entry.isDirectory() || (entry.isFile() && /\.md$/i.test(entry.name)))
|
|
17
|
+
await visit(path.join(file, entry.name));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
if (error.code !== 'ENOTDIR')
|
|
22
|
+
throw error;
|
|
23
|
+
files.add(file);
|
|
24
|
+
checkCampaignSize(files.size);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
for (const input of inputs)
|
|
28
|
+
await visit(path.resolve(cwd, input));
|
|
29
|
+
const documents = await Promise.all([...files].sort().map(async (id) => ({ id, content: await readFile(id, 'utf8') })));
|
|
30
|
+
const results = diagnoseWritingBatch(documents, { cross: true });
|
|
31
|
+
if (json)
|
|
32
|
+
return JSON.stringify(Object.fromEntries(results), null, 2);
|
|
33
|
+
const lines = [];
|
|
34
|
+
for (const d of documents)
|
|
35
|
+
for (const f of results.get(d.id).diagnostics) {
|
|
36
|
+
const line = d.content.slice(0, f.start).split('\n').length;
|
|
37
|
+
lines.push(`${d.id}:${line}:${f.start - d.content.lastIndexOf('\n', f.start - 1)} [${f.tier ?? 'check'}] ${f.ruleId}: ${f.suggestion}`);
|
|
38
|
+
}
|
|
39
|
+
return lines.join('\n') || 'No editorial pattern findings in this campaign.';
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=campaign-report.js.map
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
+
import { scanCurrentPatterns } from './current-patterns.js';
|
|
3
|
+
import { maskProse, protectedRegions } from './prose-mask.js';
|
|
4
|
+
import { scanCampaignPatterns } from './campaign-patterns.js';
|
|
2
5
|
const DEFAULT_RULES = [
|
|
3
6
|
{ id: 'phrase:delve', phrase: 'delve', authority: 'advisory', explanation: 'This phrase can be formulaic in general introductions; inspect what the reader needs.', suggestion: 'Retain deliberate usage or state the concrete action.' },
|
|
4
7
|
{ id: 'phrase:rich-tapestry', phrase: 'rich tapestry', authority: 'advisory', explanation: 'This metaphor can obscure the subject; literal textile descriptions are valid.', suggestion: 'Retain literal or intentional use, or describe the subject specifically.' },
|
|
@@ -50,12 +53,12 @@ function contextAt(span, contexts, whole = false) {
|
|
|
50
53
|
export function diagnoseWriting(content, options = {}) {
|
|
51
54
|
return diagnoseDocument(content, options);
|
|
52
55
|
}
|
|
53
|
-
function diagnoseDocument(content, options, priorParagraphs = new Map(), documentId = '') {
|
|
56
|
+
function diagnoseDocument(content, options, priorParagraphs = new Map(), documentId = '', campaign = []) {
|
|
54
57
|
const contentHash = writingContentHash(content);
|
|
55
58
|
const language = options.language ?? 'en';
|
|
56
59
|
const notices = [];
|
|
57
60
|
const diagnostics = [];
|
|
58
|
-
const contexts = [...(options.contexts ?? []), ...protectedContexts(content)];
|
|
61
|
+
const contexts = [...(options.contexts ?? []), ...protectedContexts(content), ...protectedRegions(content)];
|
|
59
62
|
if (contexts.some(s => !validSpan(s, content.length)))
|
|
60
63
|
throw new Error('Invalid context span');
|
|
61
64
|
const rules = new Map();
|
|
@@ -82,8 +85,17 @@ function diagnoseDocument(content, options, priorParagraphs = new Map(), documen
|
|
|
82
85
|
const exception = exceptions.find(e => e.contentHash === contentHash && e.ruleId === rule.id && e.start === span.start && e.end === span.end);
|
|
83
86
|
diagnostics.push({ ...span, id: `${rule.id}:${span.start}:${span.end}`, ruleId: rule.id, text: content.slice(span.start, span.end), context,
|
|
84
87
|
explanation: rule.explanation, suggestion: rule.suggestion, authority: rule.authority,
|
|
85
|
-
confidence: { kind: 'heuristic', calibrated: false }, resolution: exception ? 'retained' : 'review', ...(exception ? { reason: exception.reason } : {}) });
|
|
88
|
+
confidence: { kind: 'heuristic', calibrated: false }, resolution: exception ? 'retained' : 'review', ...(exception ? { reason: exception.reason } : {}), ...(rule.tier ? { tier: rule.tier } : {}) });
|
|
86
89
|
};
|
|
90
|
+
const current = language.split('-')[0] === 'en' ? scanCurrentPatterns(maskProse(content, contexts.filter(c => c.context !== 'prose').map(c => ({ ...c, context: 'code' })))) : [];
|
|
91
|
+
for (const f of [...current, ...campaign]) {
|
|
92
|
+
const override = rules.get(f.ruleId);
|
|
93
|
+
if (override?.enabled === false)
|
|
94
|
+
continue;
|
|
95
|
+
emit(f, override ?? { id: f.ruleId, phrase: '', authority: 'advisory', explanation: f.explanation, suggestion: f.suggestion, tier: f.tier }, 'prose');
|
|
96
|
+
if ('scope' in f)
|
|
97
|
+
Object.assign(diagnostics.at(-1), { scope: f.scope, related: f.related });
|
|
98
|
+
}
|
|
87
99
|
for (const rule of rules.values()) {
|
|
88
100
|
if (rule.enabled === false || rule.id.startsWith('repetition:'))
|
|
89
101
|
continue;
|
|
@@ -92,10 +104,20 @@ function diagnoseDocument(content, options, priorParagraphs = new Map(), documen
|
|
|
92
104
|
for (const match of content.matchAll(pattern)) {
|
|
93
105
|
const span = { start: match.index, end: match.index + match[0].length };
|
|
94
106
|
const context = contextAt(span, contexts);
|
|
107
|
+
if (current.some(f => f.ruleId === rule.id && span.start < f.end && span.end > f.start))
|
|
108
|
+
continue;
|
|
95
109
|
if (context === 'code' || context === 'quote')
|
|
96
110
|
continue;
|
|
97
111
|
if (rule.authority === 'advisory' && (context !== 'prose' || options.terminology?.some(t => t.toLocaleLowerCase() === match[0].toLocaleLowerCase())))
|
|
98
112
|
continue;
|
|
113
|
+
if (rule.authority === 'advisory' && ['phrase:delve', 'phrase:rich-tapestry'].includes(rule.id)) {
|
|
114
|
+
const paragraphStart = content.lastIndexOf('\n\n', span.start);
|
|
115
|
+
if (current.some(f => f.ruleId === 'lexical-cluster' && content.lastIndexOf('\n\n', f.start) === paragraphStart))
|
|
116
|
+
continue;
|
|
117
|
+
const paragraph = content.slice(paragraphStart < 0 ? 0 : paragraphStart + 2, content.indexOf('\n\n', span.end) < 0 ? content.length : content.indexOf('\n\n', span.end));
|
|
118
|
+
if (rule.id === 'phrase:rich-tapestry' && /\b(?:textile|woven|weaving|cloth|fabric|border)\b/i.test(paragraph))
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
99
121
|
emit(span, rule, context);
|
|
100
122
|
}
|
|
101
123
|
}
|
|
@@ -110,7 +132,8 @@ function diagnoseDocument(content, options, priorParagraphs = new Map(), documen
|
|
|
110
132
|
if (contextAt(span, contexts, true) !== 'prose')
|
|
111
133
|
continue;
|
|
112
134
|
const priorDocument = priorParagraphs.get(text);
|
|
113
|
-
|
|
135
|
+
const coveredByCampaign = campaign.some(f => f.ruleId === 'repeated-sentence' && f.start >= span.start && f.end <= span.end);
|
|
136
|
+
if (!coveredByCampaign && (seen.has(text) || priorDocument !== undefined))
|
|
114
137
|
emit(span, repetitionOverride ?? { ...repetitionRule, explanation: priorDocument !== undefined && priorDocument !== documentId ? `This paragraph also occurs in document ${priorDocument}; repetition may be intentional.` : repetitionRule.explanation }, 'prose');
|
|
115
138
|
seen.add(text);
|
|
116
139
|
if (priorDocument === undefined)
|
|
@@ -131,10 +154,11 @@ function diagnoseDocument(content, options, priorParagraphs = new Map(), documen
|
|
|
131
154
|
export function diagnoseWritingBatch(documents, options = {}) {
|
|
132
155
|
const results = new Map();
|
|
133
156
|
const seen = new Map();
|
|
157
|
+
const campaign = options.cross ? scanCampaignPatterns(documents.map(d => ({ ...d, content: maskProse(d.content, (options.contexts ?? []).filter(c => c.context !== 'prose').map(c => ({ ...c, context: 'code' }))) }))) : undefined;
|
|
134
158
|
for (const document of documents) {
|
|
135
159
|
if (results.has(document.id))
|
|
136
160
|
throw new Error(`Duplicate document ID: ${document.id}`);
|
|
137
|
-
const result = diagnoseDocument(document.content, options, seen, document.id);
|
|
161
|
+
const result = diagnoseDocument(document.content, options, seen, document.id, campaign?.get(document.id));
|
|
138
162
|
results.set(document.id, result);
|
|
139
163
|
}
|
|
140
164
|
return results;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
{
|
|
2
|
+
"reviewed": "2026-11-12",
|
|
3
|
+
"nextReview": "2027-02-12",
|
|
4
|
+
"note": "Editorial heuristics for #4138 and #4140, based on the November voice-quality catalogue. Not authorship evidence. Sequence and campaign rules supplement local clauses.",
|
|
5
|
+
"rules": [
|
|
6
|
+
{
|
|
7
|
+
"id": "contrast-not-but",
|
|
8
|
+
"tier": "cut",
|
|
9
|
+
"pattern": "\\bnot\\s+[^.!?;:\\n]{1,100}?,?\\s+but\\b",
|
|
10
|
+
"message": "Negated alternative before but.",
|
|
11
|
+
"fix": "State the positive claim; retain a negated alternative when it corrects a stated belief."
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"id": "contrast-x-not-y",
|
|
15
|
+
"tier": "cut",
|
|
16
|
+
"pattern": ",\\s+not\\s+(?!(?:yet|now|sure|necessarily|really|enough|all|in|if|when|because|until|any|clear|certain|true|quite|going|at all|be|do|need)\\b)[\\w'-]+(?:\\s+[\\w'-]+){0,4}",
|
|
17
|
+
"message": "A clause ends with a negated alternative.",
|
|
18
|
+
"fix": "Keep the useful claim; retain the alternative only when the reader needs the correction."
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"id": "rather-than",
|
|
22
|
+
"tier": "check",
|
|
23
|
+
"pattern": "\\brather\\s+than\\b",
|
|
24
|
+
"message": "Comparison without a stated reason.",
|
|
25
|
+
"fix": "Name the action, or explain why the alternative was a real option."
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"id": "negate-then-assert",
|
|
29
|
+
"tier": "check",
|
|
30
|
+
"pattern": "\\b(?:(?:is|are|was|were)\\s+not|isn't|aren't)\\s+(?:evidence|proof|a substitute|a replacement|the same|enough|just|only|about)\\b|\\b(?:it|this|that)\\s+does\\s+not\\s+(?:mean|prove|imply)\\b",
|
|
31
|
+
"message": "Negated assertion frames the claim.",
|
|
32
|
+
"fix": "State the positive claim, retaining negation when it corrects a misconception."
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"id": "labelled-significance",
|
|
36
|
+
"tier": "cut",
|
|
37
|
+
"pattern": "(?:^|[.!?]\\s+|\\n)\\s*(?:why (?:it|this|that) (?:matters|helps)|why you should care|what (?:changed|this means(?: for you)?|that means|you get)|the (?:bug|takeaway|point|lesson|catch|upshot|real (?:question|point|story))|bottom line|the short version)\\s*:|\\b(?:(?:which|that) is the (?:part|thing|bit|point|half) (?:i'd|i would) (?:keep|say|add)(?: too)?|(?:that|this) is the (?:other|real|whole|hard) (?:half|part|point|story|thing))\\b",
|
|
38
|
+
"message": "A label or aside announces significance.",
|
|
39
|
+
"fix": "Explain the circumstance and consequence together; deleting only the label is insufficient."
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"id": "throat-clearing",
|
|
43
|
+
"tier": "cut",
|
|
44
|
+
"pattern": "\\b(?:here'?s the (?:thing|deal|kicker|catch|twist)|here'?s why|let'?s (?:dive|dig|jump) (?:in|into)|let'?s (?:be|get) (?:honest|real|clear)|without further ado|buckle up|picture this|spoiler alert|let me explain)\\b|\\bfull stop\\.",
|
|
45
|
+
"message": "Empty opener delays the content.",
|
|
46
|
+
"fix": "Start with the useful information."
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"id": "engagement-bait",
|
|
50
|
+
"tier": "cut",
|
|
51
|
+
"pattern": "\\b(?:what do you think|agree|thoughts|am i wrong|what'?s your take)\\?|\\b(?:drop a comment|comment below|tag someone who|let me know (?:in the comments|what you think))\\b",
|
|
52
|
+
"message": "Generic engagement prompt.",
|
|
53
|
+
"fix": "Ask a concrete question with something to answer, or end with the information."
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
"structuralRules": [
|
|
57
|
+
{ "id": "mirrored-sentences", "tier": "cut", "scope": "file", "trigger": "Adjacent sentences share the first two tokens and aligned predicates; exactly one polarity flip or listed antonym supplies a real contrast. Different verbs with a negated opener are insufficient.", "fix": "Combine the useful claim; retain deliberate parallelism with a reason." },
|
|
58
|
+
{ "id": "aphorism-ending", "tier": "cut", "scope": "file", "trigger": "Paragraph-final explicit moral/lesson opener of 3–10 words; exclude numbers, identifiers and protected spans. Generic closers are not detected.", "fix": "End on the last useful fact or support the claim." },
|
|
59
|
+
{ "id": "colon-reveal", "tier": "watch", "scope": "file", "trigger": "Setup of 4–12 words ending in a withheld complement, then a sentence-final punchline of 2–10 words. Frequency never triggers a finding. Exclude lists/definitions, digits/citations and protected material.", "fix": "State the subject and consequence directly." },
|
|
60
|
+
{ "id": "fragment-run", "tier": "check", "scope": "file", "trigger": "At least four consecutive statements with 1–4 words in one prose paragraph; questions break runs and identical-sentence-only runs are excluded.", "fix": "Join fragments to explain the reason or result." },
|
|
61
|
+
{ "id": "repeated-sentence", "tier": "cut", "scope": "cross", "trigger": "At least six words repeated within an explicit campaign; case and punctuation are ignored, numbers are retained.", "fix": "Write each channel from its relevant facts." },
|
|
62
|
+
{ "id": "repeated-phrase", "tier": "check", "scope": "cross", "trigger": "An eight-word run inside one sentence shared by at least three distinct documents; overlapping runs merge, affected sentences receive one phrase finding, repeated sentences are excluded.", "fix": "Rewrite the shared run for the reader and channel." },
|
|
63
|
+
{ "id": "shared-skeleton", "tier": "check", "scope": "cross", "trigger": "First or last three words of the first or last prose sentence shared by three distinct documents, including a content word; numbers and versions normalize to num.", "fix": "Lead or close with the useful change for this channel." }
|
|
64
|
+
],
|
|
65
|
+
"antonyms": [
|
|
66
|
+
["quiet", "loud"], ["fast", "slow"], ["cheap", "expensive"],
|
|
67
|
+
["simple", "complex"], ["easy", "hard"], ["safe", "unsafe"],
|
|
68
|
+
["big", "small"], ["large", "small"], ["new", "old"],
|
|
69
|
+
["public", "private"], ["local", "remote"], ["manual", "automatic"],
|
|
70
|
+
["short", "long"], ["early", "late"], ["good", "bad"],
|
|
71
|
+
["real", "fake"], ["open", "closed"], ["visible", "hidden"],
|
|
72
|
+
["cold", "hot"], ["dark", "bright"], ["strong", "weak"],
|
|
73
|
+
["clean", "dirty"], ["working", "broken"], ["fixed", "broken"]
|
|
74
|
+
],
|
|
75
|
+
"lexicon": {
|
|
76
|
+
"paragraphMinHits": 2,
|
|
77
|
+
"fileMinHits": 4,
|
|
78
|
+
"sets": [
|
|
79
|
+
{ "name": "2023", "tier": "check", "words": ["delve", "delves", "delved", "delving", "tapestry", "testament", "pivotal", "crucial", "meticulous"] },
|
|
80
|
+
{ "name": "2024-25", "tier": "check", "words": ["enhance", "enhances", "enhanced", "enhancing", "fostering", "showcasing", "highlighting", "valuable insights"] },
|
|
81
|
+
{ "name": "2026", "tier": "check", "words": ["leverage", "leverages", "leveraged", "leveraging", "multifaceted"] },
|
|
82
|
+
{ "name": "copula-avoidance", "tier": "check", "words": ["serves as", "stands as", "boasts", "acts as", "functions as"] },
|
|
83
|
+
{ "name": "spectral-technical", "tier": "watch", "words": ["quiet", "hum", "echo"] }
|
|
84
|
+
]
|
|
85
|
+
},
|
|
86
|
+
"triadPattern": "\\b(?:is|are|was|were)\\s+(?:fast|reliable|secure|efficient|scalable|robust|innovative|flexible|powerful),\\s+(?:fast|reliable|secure|efficient|scalable|robust|innovative|flexible|powerful),?\\s+and\\s+(?:fast|reliable|secure|efficient|scalable|robust|innovative|flexible|powerful)(?![\\w-]|\\s*,)"
|
|
87
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Local editorial pattern matching shared by validation and contextual diagnostics.
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { maskProse } from './prose-mask.js';
|
|
4
|
+
import { structuralPatterns } from './structural-patterns.js';
|
|
5
|
+
const require = createRequire(import.meta.url);
|
|
6
|
+
// Package-local copy of the writing-quality addon catalogue (the addon file stays canonical for the
|
|
7
|
+
// Python scanner; test/unit/writing/catalogue-sync.test.ts keeps the two identical). Every package
|
|
8
|
+
// built from dist/src ships it, so no install needs agentic/code at import time.
|
|
9
|
+
const catalogue = require('./current-patterns.catalogue.json');
|
|
10
|
+
const compiled = catalogue.rules.map(rule => ({ ...rule, regex: new RegExp(rule.pattern, 'gim') }));
|
|
11
|
+
const escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
12
|
+
const lexicon = catalogue.lexicon.sets.map(set => ({ ...set,
|
|
13
|
+
regex: new RegExp(`\\b(?:${set.words.map(escape).join('|')})\\b`, 'gi') }));
|
|
14
|
+
export const rhetoricalTriad = new RegExp(catalogue.triadPattern, 'gi');
|
|
15
|
+
const tokens = (s) => s.toLowerCase().match(/[a-z]+(?:['-][a-z]+)*/g) ?? [];
|
|
16
|
+
/** Grounding must be near this comparison, rather than anywhere in its sentence. */
|
|
17
|
+
function groundedComparison(text, start, end) {
|
|
18
|
+
const words = (s) => s.match(/[a-z0-9]+(?:['.-][a-z0-9]+)*/gi) ?? [];
|
|
19
|
+
for (const cue of text.matchAll(/\b(?:because|while|correction|earlier|previously|misconception|you said)\b/gi)) {
|
|
20
|
+
const gap = cue.index >= end ? text.slice(end, cue.index) : cue.index + cue[0].length <= start ? text.slice(cue.index + cue[0].length, start) : '';
|
|
21
|
+
if (!/[;:]/.test(gap) && words(gap).length <= 4)
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
const divider = /\brather\s+than\b|\bbut\b|,\s+not\b|^,$/i.exec(text.slice(start, end));
|
|
25
|
+
if (!divider)
|
|
26
|
+
return false;
|
|
27
|
+
const pivot = start + divider.index;
|
|
28
|
+
const left = words(text.slice(0, pivot).split(/[;:]/).at(-1)).slice(-6);
|
|
29
|
+
const right = words(text.slice(pivot + divider[0].length).split(/[;:]/)[0]).slice(0, 6);
|
|
30
|
+
return left.some(w => /\d/.test(w)) && right.some(w => /\d/.test(w));
|
|
31
|
+
}
|
|
32
|
+
export function scanCurrentPatterns(content) {
|
|
33
|
+
const prose = maskProse(content).replace(/[‘’]/g, "'");
|
|
34
|
+
const findings = [];
|
|
35
|
+
const paragraphs = [...prose.matchAll(/\S[^\n]*(?:\n(?!\s*\n)[^\n]+)*/g)];
|
|
36
|
+
const lexical = [];
|
|
37
|
+
const emit = (ruleId, tier, start, end, explanation, suggestion) => {
|
|
38
|
+
findings.push({ ruleId, tier, start, end, explanation, suggestion });
|
|
39
|
+
};
|
|
40
|
+
for (const m of prose.matchAll(rhetoricalTriad)) {
|
|
41
|
+
emit('struct_three_items', 'watch', m.index, m.index + m[0].length, 'Rhetorical three-item predicate detected.', 'Replace generic claims with supported details; retain real inventories.');
|
|
42
|
+
}
|
|
43
|
+
for (const p of paragraphs) {
|
|
44
|
+
const hits = lexicon.flatMap(set => [...p[0].matchAll(set.regex)].map(m => ({ start: p.index + m.index, end: p.index + m.index + m[0].length, tier: set.tier })));
|
|
45
|
+
hits.sort((a, b) => a.start - b.start);
|
|
46
|
+
if (hits.length)
|
|
47
|
+
lexical.push({ ...hits[0], tier: hits.some(h => h.tier === 'check') ? 'check' : 'watch', hits: hits.length });
|
|
48
|
+
}
|
|
49
|
+
const total = lexical.reduce((n, p) => n + p.hits, 0);
|
|
50
|
+
for (const p of lexical)
|
|
51
|
+
if (p.hits >= catalogue.lexicon.paragraphMinHits || total >= catalogue.lexicon.fileMinHits) {
|
|
52
|
+
emit('lexical-cluster', p.tier, p.start, p.end, 'Dated lexical markers cluster in this prose.', 'Replace vague markers with the specific action or fact.');
|
|
53
|
+
}
|
|
54
|
+
// Clause checks retain the existing protected-region boundaries.
|
|
55
|
+
for (const sentence of prose.matchAll(/[^.!?\n\u0001]+(?:[.!?]+|(?=[\n\u0001]|$))/g)) {
|
|
56
|
+
const text = sentence[0];
|
|
57
|
+
const contrast = /\bnot\s+[^.!?;:\n]{1,100}?,?\s+but\b/i.test(text);
|
|
58
|
+
for (const rule of compiled) {
|
|
59
|
+
if (rule.id === 'negate-then-assert' && contrast)
|
|
60
|
+
continue;
|
|
61
|
+
for (const m of text.matchAll(rule.regex)) {
|
|
62
|
+
if (['contrast-not-but', 'contrast-x-not-y', 'rather-than', 'negate-then-assert'].includes(rule.id) && groundedComparison(text, m.index, m.index + m[0].length))
|
|
63
|
+
continue;
|
|
64
|
+
const start = sentence.index + m.index + m[0].length - m[0].trimStart().length;
|
|
65
|
+
emit(rule.id, rule.tier, start, sentence.index + m.index + m[0].length, rule.message, rule.fix);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
for (const comma of text.matchAll(/,/g)) {
|
|
69
|
+
if (groundedComparison(text, comma.index, comma.index + 1))
|
|
70
|
+
continue;
|
|
71
|
+
const left = tokens(text.slice(0, comma.index)).slice(-3);
|
|
72
|
+
const right = tokens(text.slice(comma.index + 1)).slice(0, 2);
|
|
73
|
+
if (left.length < 2 || right.length < 2)
|
|
74
|
+
continue;
|
|
75
|
+
if (catalogue.antonyms.some(([a, b]) => (left.includes(a) && right.includes(b)) || (left.includes(b) && right.includes(a)))) {
|
|
76
|
+
const start = sentence.index + text.length - text.trimStart().length;
|
|
77
|
+
emit('antithesis-pair', 'cut', start, sentence.index + text.length, 'Mirrored antonyms across a comma.', 'Keep the fact and drop the mirrored half.');
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
findings.push(...structuralPatterns(prose, catalogue.antonyms));
|
|
83
|
+
return findings.sort((a, b) => a.start - b.start || a.ruleId.localeCompare(b.ruleId));
|
|
84
|
+
}
|
|
85
|
+
/** Adapt local findings to the existing validation issue contract. */
|
|
86
|
+
export function currentPatternIssues(content, campaign = []) {
|
|
87
|
+
const severity = { cut: 'critical', check: 'warning', watch: 'info' };
|
|
88
|
+
// Validation already emits triads through its existing structural rule loader.
|
|
89
|
+
return [...scanCurrentPatterns(content), ...campaign].filter(f => f.ruleId !== 'struct_three_items').map(f => ({
|
|
90
|
+
type: 'formulaic_structure', severity: severity[f.tier], ruleId: f.ruleId,
|
|
91
|
+
tier: f.tier,
|
|
92
|
+
message: f.explanation, suggestion: f.suggestion,
|
|
93
|
+
location: { start: f.start, end: f.end, line: content.slice(0, f.start).split('\n').length,
|
|
94
|
+
column: f.start - content.lastIndexOf('\n', f.start - 1) },
|
|
95
|
+
context: content.slice(f.start, f.end),
|
|
96
|
+
...(f.scope === 'cross' ? { scope: f.scope, related: f.related } : {}),
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=current-patterns.js.map
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export function protectedRegions(content) {
|
|
2
|
+
const spans = [];
|
|
3
|
+
const add = (start, end, context = 'code') => {
|
|
4
|
+
if (end > start)
|
|
5
|
+
spans.push({ start, end, context });
|
|
6
|
+
};
|
|
7
|
+
const lines = [...content.matchAll(/[^\n]+(?:\n|$)|\n/g)];
|
|
8
|
+
let fence;
|
|
9
|
+
let frontMatter = /^(?:\uFEFF)?---\s*$/.test(lines[0]?.[0].trimEnd() ?? '');
|
|
10
|
+
let comment = false;
|
|
11
|
+
let indented = false;
|
|
12
|
+
for (let i = 0; i < lines.length; i++) {
|
|
13
|
+
const line = lines[i][0];
|
|
14
|
+
const start = lines[i].index;
|
|
15
|
+
const marker = /^ {0,3}(`{3,}|~{3,})(.*)/.exec(line);
|
|
16
|
+
if (frontMatter) {
|
|
17
|
+
add(start, start + line.length);
|
|
18
|
+
if (i > 0 && /^(?:---|\.\.\.)\s*$/.test(line))
|
|
19
|
+
frontMatter = false;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (fence) {
|
|
23
|
+
add(start, start + line.length);
|
|
24
|
+
if (marker && marker[1][0] === fence[0] && marker[1].length >= fence.length && !marker[2].trim())
|
|
25
|
+
fence = undefined;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (marker) {
|
|
29
|
+
fence = marker[1];
|
|
30
|
+
add(start, start + line.length);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (comment) {
|
|
34
|
+
const end = line.indexOf('-->');
|
|
35
|
+
add(start, start + (end < 0 ? line.length : end + 3));
|
|
36
|
+
comment = end < 0;
|
|
37
|
+
if (comment)
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
for (const m of line.matchAll(/<!--[\s\S]*?(?:-->|$)/g)) {
|
|
41
|
+
add(start + m.index, start + m.index + m[0].length);
|
|
42
|
+
if (!m[0].endsWith('-->'))
|
|
43
|
+
comment = true;
|
|
44
|
+
}
|
|
45
|
+
const setext = i + 1 < lines.length && /^ {0,3}(?:=+|-+)\s*$/.test(lines[i + 1][0]);
|
|
46
|
+
if (/^ {0,3}(?:#{1,6}(?:\s|$)|>|\|)/.test(line) || setext || /^ {0,3}(?:=+|-+)\s*$/.test(line)) {
|
|
47
|
+
add(start, start + line.length);
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (/^(?: {4}|\t)/.test(line) && (indented || i === 0 || !lines[i - 1][0].trim())) {
|
|
51
|
+
add(start, start + line.length);
|
|
52
|
+
indented = true;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (line.trim())
|
|
56
|
+
indented = false;
|
|
57
|
+
if (/^\s*(?:[-*+] |\d+[.)] )/.test(line))
|
|
58
|
+
add(start, start + line.length, 'inventory');
|
|
59
|
+
}
|
|
60
|
+
const patterns = [
|
|
61
|
+
['code', /(`+)(?!`)([^`]|(?!\1)`)*?\1(?!`)/g],
|
|
62
|
+
['code', /!\[[^\]\n]*\](?:\([^\n]*?\)|\[[^\]\n]*\])/g],
|
|
63
|
+
['code', /(?:!?\[[^\]\n]*\])?\((?:https?:\/\/)[^\s)]*\)|https?:\/\/[^\s<>]+/g],
|
|
64
|
+
['quote', /“[^”]*”|"[^"\n]+"|«[^»]*»/g],
|
|
65
|
+
];
|
|
66
|
+
for (const [context, pattern] of patterns)
|
|
67
|
+
for (const m of content.matchAll(pattern))
|
|
68
|
+
add(m.index, m.index + m[0].length, context);
|
|
69
|
+
return spans;
|
|
70
|
+
}
|
|
71
|
+
/** UTF-16 length is preserved, including astral characters in protected regions. */
|
|
72
|
+
export function maskProse(content, regions = protectedRegions(content)) {
|
|
73
|
+
const chars = content.split('');
|
|
74
|
+
for (const span of regions)
|
|
75
|
+
for (let i = span.start; i < span.end; i++)
|
|
76
|
+
if (chars[i] !== '\n' && chars[i] !== '\r')
|
|
77
|
+
chars[i] = '\u0001';
|
|
78
|
+
return chars.join('');
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=prose-mask.js.map
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
export const words = (s) => s.toLowerCase().match(/[a-z0-9]+(?:['’-][a-z0-9]+)*/g) ?? [];
|
|
2
|
+
export const stopWords = new Set(('a an the of to in on for and or but is are was were be it its this that these those with as at by from not no so if we you i they he she our your their there here than then also about into over under out up down can will would should could has have had do does did just only more most very all any each some which who what when where how why num them his her me my').split(' '));
|
|
3
|
+
const abbreviations = new Set('e.g i.e vs etc approx cf eg ie dr mr mrs ms st no fig al'.split(' '));
|
|
4
|
+
export function proseParagraphs(prose) {
|
|
5
|
+
const paragraphs = [];
|
|
6
|
+
// A wholly masked line is a boundary, including a heading between two prose lines.
|
|
7
|
+
for (const block of prose.matchAll(/[^\n]*(?:\n|$)/g)) {
|
|
8
|
+
if (!block[0])
|
|
9
|
+
continue;
|
|
10
|
+
if (!block[0].replace(/[\s\u0001]/g, ''))
|
|
11
|
+
continue;
|
|
12
|
+
const previous = paragraphs.at(-1);
|
|
13
|
+
if (previous && previous.end === block.index)
|
|
14
|
+
previous.end += block[0].length;
|
|
15
|
+
else
|
|
16
|
+
paragraphs.push({ start: block.index, end: block.index + block[0].length, sentences: [] });
|
|
17
|
+
}
|
|
18
|
+
for (const p of paragraphs) {
|
|
19
|
+
const text = prose.slice(p.start, p.end);
|
|
20
|
+
let from = 0;
|
|
21
|
+
const push = (end) => {
|
|
22
|
+
const raw = text.slice(from, end);
|
|
23
|
+
const trimmed = raw.replace(/^[\s\u0001]+|[\s\u0001]+$/g, '');
|
|
24
|
+
if (words(trimmed).length) {
|
|
25
|
+
const start = p.start + from + raw.search(/[^\s\u0001]/);
|
|
26
|
+
p.sentences.push({ start, end: start + trimmed.length, text: trimmed, tokens: words(trimmed) });
|
|
27
|
+
}
|
|
28
|
+
from = end;
|
|
29
|
+
};
|
|
30
|
+
for (const m of text.matchAll(/[.!?]+/g)) {
|
|
31
|
+
const end = m.index + m[0].length;
|
|
32
|
+
if (end < text.length && !/\s/.test(text[end]))
|
|
33
|
+
continue;
|
|
34
|
+
const word = text.slice(from, m.index).match(/([a-z][a-z.]*)$/i)?.[1].toLowerCase();
|
|
35
|
+
if (m[0] === '.' && word && (abbreviations.has(word) || /^(?:[a-z]\.)+[a-z]$/.test(word)))
|
|
36
|
+
continue;
|
|
37
|
+
push(end);
|
|
38
|
+
}
|
|
39
|
+
push(text.length);
|
|
40
|
+
}
|
|
41
|
+
return paragraphs;
|
|
42
|
+
}
|
|
43
|
+
export function structuralPatterns(prose, antonyms) {
|
|
44
|
+
const out = [];
|
|
45
|
+
const emit = (ruleId, tier, s, explanation, suggestion) => {
|
|
46
|
+
out.push({ ruleId, tier, start: s.start, end: s.end, explanation, suggestion });
|
|
47
|
+
};
|
|
48
|
+
for (const p of proseParagraphs(prose)) {
|
|
49
|
+
const sentences = p.sentences;
|
|
50
|
+
for (let i = 1; i < sentences.length; i++) {
|
|
51
|
+
const a = sentences[i - 1], b = sentences[i];
|
|
52
|
+
// A shared subject alone is insufficient: predicates must align after removing
|
|
53
|
+
// a single negation, or differ by exactly one catalogued antonym.
|
|
54
|
+
const normalize = (s) => words(s.text.replace(/n['’]t\b/gi, ' not'));
|
|
55
|
+
const left = normalize(a), right = normalize(b);
|
|
56
|
+
const negated = (tokens) => tokens.includes('not') || tokens.includes('never');
|
|
57
|
+
const positive = (tokens) => tokens.filter(t => t !== 'not' && t !== 'never');
|
|
58
|
+
const x = positive(left), y = positive(right);
|
|
59
|
+
const differences = x.map((token, index) => token === y[index] ? -1 : index).filter(index => index >= 0);
|
|
60
|
+
const polarityFlip = negated(left) !== negated(right) && differences.length === 0;
|
|
61
|
+
const antonymFlip = negated(left) === negated(right) && differences.length === 1 && differences[0] >= 2
|
|
62
|
+
&& antonyms.some(pair => pair.includes(x[differences[0]]) && pair.includes(y[differences[0]]));
|
|
63
|
+
if (x.length >= 3 && x.length === y.length && x[0] === y[0] && x[1] === y[1] && (polarityFlip || antonymFlip)) {
|
|
64
|
+
emit('mirrored-sentences', 'cut', b, 'Parallel predicates contrast through a polarity flip or a listed antonym.', 'Combine the useful claim into one sentence; retain deliberate parallelism with a reason.');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
let run = [];
|
|
68
|
+
const flush = () => {
|
|
69
|
+
if (run.length >= 4 && new Set(run.map(s => s.tokens.join(' '))).size > 1)
|
|
70
|
+
emit('fragment-run', 'check', { start: run[0].start, end: run.at(-1).end }, 'Four or more consecutive statements contain fewer than five words.', 'Join fragments to explain the reason or result.');
|
|
71
|
+
run = [];
|
|
72
|
+
};
|
|
73
|
+
for (const s of sentences) {
|
|
74
|
+
const label = s.text.match(/^([^:]+):/);
|
|
75
|
+
if (s.tokens.length <= 4 && !/\?$/.test(s.text) && !(label && words(label[1]).length <= 3))
|
|
76
|
+
run.push(s);
|
|
77
|
+
else
|
|
78
|
+
flush();
|
|
79
|
+
// A reveal withholds its complement, then supplies a short final punchline.
|
|
80
|
+
// Mere colon frequency, another diagnostic, or a technical definition is insufficient.
|
|
81
|
+
const colon = s.text.indexOf(':');
|
|
82
|
+
if (colon < 0 || colon !== s.text.lastIndexOf(':') || /[\d\u0001`\[\]{};,]/.test(s.text) || !/[.!]$/.test(s.text))
|
|
83
|
+
continue;
|
|
84
|
+
const before = s.text.slice(0, colon), after = s.text.slice(colon + 1).trim();
|
|
85
|
+
const setup = words(before), punchline = words(after);
|
|
86
|
+
const withheld = /\b(?:is|are|was|were)$/.test(before.trim())
|
|
87
|
+
|| /\b(?:has|had|have|makes|made|holds|held|offers|offered|reveals|revealed|leaves|left) (?:a|an|one|this|that) (?:[a-z]+ ){0,2}[a-z]+$/i.test(before.trim());
|
|
88
|
+
// Require a simple subject/predicate shape, protecting nominal definitions
|
|
89
|
+
// such as 'request identifier' or 'shared memory' after the colon.
|
|
90
|
+
const subject = /^(?:the|a|an)$/.test(punchline[0]) ? 1 : 0;
|
|
91
|
+
const predicate = punchline[subject + 1] ?? '';
|
|
92
|
+
const clause = (subject === 1 || /^(?:it|this|that|we|you|they|he|she|nothing|everything)$/.test(punchline[0]))
|
|
93
|
+
&& /^(?:is|are|was|were|can|will|must|has|had|does|[a-z]+(?:s|ed))$/.test(predicate);
|
|
94
|
+
if (clause && setup.length >= 4 && setup.length <= 12 && punchline.length >= 2 && punchline.length <= 10
|
|
95
|
+
&& withheld && !/^(?:["“]|[-*+]|\u0001)/.test(after) && !/\b(?:and|or)\b|:|[?!]/i.test(after)) {
|
|
96
|
+
emit('colon-reveal', 'watch', { start: s.start + colon, end: s.start + colon + 1 }, 'A short setup withholds a complement until a sentence-final punchline.', 'State the subject and consequence directly; retain real lists, labels and code introductions.');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
flush();
|
|
100
|
+
const last = sentences.at(-1);
|
|
101
|
+
if (!last || last.tokens.length < 3 || last.tokens.length > 10 || /[\d\u0001@/]|[?:]$/.test(last.text))
|
|
102
|
+
continue;
|
|
103
|
+
const moral = /^(?:(?:always|never|remember)\b|the (?:point|lesson|moral)\b|(?:that's|that is|it's|it is|this is) the (?:point|lesson|moral)\b)/i.test(last.text);
|
|
104
|
+
if (moral)
|
|
105
|
+
emit('aphorism-ending', 'cut', last, 'A short paragraph-final sentence opens with an explicit moral or lesson.', 'End on the last useful fact, or develop the claim with supported detail.');
|
|
106
|
+
}
|
|
107
|
+
return out;
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=structural-patterns.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Extend validation's existing batch entry point with explicit campaign comparisons.
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { maskProse } from './prose-mask.js';
|
|
4
|
+
import { checkCampaignSize, scanCampaignPatterns } from './campaign-patterns.js';
|
|
5
|
+
import { diagnoseWritingBatch } from './contextual-diagnostics.js';
|
|
6
|
+
export async function validateCampaign(engine, files, context) {
|
|
7
|
+
checkCampaignSize(files.length);
|
|
8
|
+
const documents = await Promise.all(files.map(async (id) => ({ id, content: await readFile(id, 'utf8') })));
|
|
9
|
+
const campaign = scanCampaignPatterns(documents.map(d => ({ ...d, content: maskProse(d.content) })));
|
|
10
|
+
const diagnostics = diagnoseWritingBatch(documents, { cross: true });
|
|
11
|
+
const results = new Map();
|
|
12
|
+
for (const d of documents) {
|
|
13
|
+
const result = await engine.validate(d.content, context, campaign.get(d.id));
|
|
14
|
+
result.contextualDiagnostics = diagnostics.get(d.id);
|
|
15
|
+
results.set(d.id, result);
|
|
16
|
+
}
|
|
17
|
+
return results;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=validation-campaign.js.map
|