@aiwg/cli 2026.11.6 → 2026.11.8
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/addons/aiwg-hooks/hooks/aiwg-prompt-discovery.cjs +3 -2
- package/agentic/code/providers/model-capabilities.v1.json +22 -21
- package/agentic/code/providers/model-catalog.v1.json +11 -10
- package/dist/src/artifacts/browser-export.js +1 -0
- 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/cli/handlers/dataset.js +11 -2
- package/dist/src/cli/handlers/refresh-managed-deployment.js +13 -3
- package/dist/src/cli/handlers/refresh-user-hooks.js +102 -0
- package/dist/src/cli/handlers/refresh.js +2 -0
- package/dist/src/cli/handlers/update.js +26 -12
- package/dist/src/cli/handlers/use.js +4 -3
- package/dist/src/cli/handlers/writing.js +7 -1
- package/dist/src/config/worker-guidance-warning.js +8 -0
- 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/extensions/manifest.js +23 -7
- package/dist/src/extensions/project-local-doctor.js +2 -1
- package/dist/src/extensions/project-quickref-discovery.js +11 -0
- package/dist/src/extensions/project-quickref.js +4 -7
- package/dist/src/extensions/user-hook-diagnostics.js +16 -1
- package/dist/src/extensions/verified-hook-command.js +7 -0
- package/dist/src/mcp/tools/worker-invoke.mjs +6 -4
- package/dist/src/mcp/tools/worker-launch-ledger.mjs +33 -0
- package/dist/src/mcp/tools/worker-verify-deliver-schema.mjs +22 -6
- package/dist/src/mcp/tools/worker-verify-deliver.mjs +4 -6
- package/dist/src/models/cursor-models.js +92 -0
- package/dist/src/models/model-capabilities.v1.json +22 -21
- package/dist/src/models/model-catalog.v1.json +11 -10
- package/dist/src/models/model-discovery.js +4 -3
- package/dist/src/models/provider-policy.js +1 -1
- package/dist/src/models/worker-health-readiness.js +4 -0
- package/dist/src/models/worker-installation.d.mts +2 -0
- package/dist/src/models/worker-installation.mjs +8 -2
- package/dist/src/models/worker-invocation-policy.js +21 -1
- package/dist/src/models/worker-plan.js +3 -1
- package/dist/src/models/worker-wiring-diagnostics.js +25 -0
- package/dist/src/providers/deployment-input-session.d.mts +2 -0
- package/dist/src/providers/deployment-input-session.mjs +38 -0
- package/dist/src/providers/provider-context-contracts.js +3 -0
- package/dist/src/providers/provider-seeds-1.js +1 -1
- package/dist/src/serve/worker-invocation-preparation.js +52 -33
- package/dist/src/serve/worker-invocation.js +4 -2
- package/dist/src/serve/worker-shell-prompt.d.mts +6 -0
- package/dist/src/serve/worker-shell-prompt.mjs +78 -0
- package/dist/src/smiths/context-pipeline/muse-bridge.js +7 -4
- package/dist/src/smiths/context-pipeline/workspace-audit.js +37 -6
- package/dist/src/smiths/context-pipeline/workspace-bootstrap.js +3 -1
- package/dist/src/smiths/context-pipeline/workspace-doctor.js +16 -4
- package/dist/src/smiths/context-pipeline/workspace-document.js +4 -2
- package/dist/src/smiths/hook-bridge/codex-trust.js +56 -7
- package/dist/src/smiths/hook-bridge/cursor-translator.js +89 -0
- package/dist/src/smiths/hook-bridge/index.js +4 -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 +30 -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 +126 -0
- package/dist/src/writing/validation-campaign.js +19 -0
- package/dist/src/writing/validation-engine.js +17 -10
- package/dist/src/writing/validation-rules.js +4 -3
- package/package.json +1 -1
- package/schemas/dataset/service-binding.v1.schema.json +70 -0
- package/tools/agents/providers/base-models-platforms.mjs +87 -48
- package/tools/agents/providers/cursor-prompt-discovery.mjs +13 -0
- package/tools/agents/providers/cursor.mjs +2 -0
- package/tools/agents/providers/openclaw-context.mjs +6 -0
- package/tools/agents/providers/openclaw.mjs +14 -12
- package/tools/agents/providers/rule-delivery-surface.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 +16 -6
- package/tools/agents/providers/rule-presentation.mjs +1 -1
- package/tools/agents/providers/rule-startup.mjs +3 -1
- package/tools/plugin/package-plugins.mjs +2 -0
- package/tools/ralph-external/lib/typed-stop-delivery.mjs +10 -1
- package/tools/ralph-external/lib/worker-delivery-guards.mjs +47 -1
- package/tools/ralph-external/lib/worker-run-directory-refusal.mjs +2 -1
- package/tools/ralph-external/lib/worker-verification-cli.mjs +1 -1
- package/vscode-extension/schemas/aiwg.config.v1.json +13 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Deploy canonical prompt discovery through Cursor's flat beforeSubmitPrompt command array.
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { randomUUID } from 'node:crypto';
|
|
5
|
+
import { loadHookSources } from './loader.js';
|
|
6
|
+
import { verifiedHookCommand } from '../../extensions/verified-hook-command.js';
|
|
7
|
+
import { managedHookScriptState } from '../../extensions/managed-hook-script-state.js';
|
|
8
|
+
import { captureDeploymentOutputs, recordDeploymentOutputs } from '../../providers/deployment-ownership.mjs';
|
|
9
|
+
export const CURSOR_PROMPT_SCRIPT = '.cursor/hooks/aiwg-prompt-discovery.cjs';
|
|
10
|
+
export function managedCursorPromptHook(root, bytes) {
|
|
11
|
+
return { type: 'command', command: verifiedHookCommand(root, CURSOR_PROMPT_SCRIPT, bytes), timeout: 2,
|
|
12
|
+
_aiwg_managed: true, _aiwg_id: 'aiwg-prompt-discovery' };
|
|
13
|
+
}
|
|
14
|
+
export async function translateForCursor(source, options) {
|
|
15
|
+
const result = { provider: 'cursor', emittedPaths: [], warnings: [], skipped: false };
|
|
16
|
+
if (source.degradeOn?.includes('cursor'))
|
|
17
|
+
return { ...result, skipped: true, skipReason: 'degrade-on declared cursor' };
|
|
18
|
+
if (source.id !== 'aiwg-prompt-discovery' || !source.events.includes('UserPromptSubmit')) {
|
|
19
|
+
return { ...result, skipped: true, skipReason: 'no Cursor-mapped prompt discovery event' };
|
|
20
|
+
}
|
|
21
|
+
if (!source.args?.[0])
|
|
22
|
+
throw new Error('Missing shared prompt discovery script');
|
|
23
|
+
const directory = path.join(options.projectPath, '.cursor');
|
|
24
|
+
const script = path.join(options.projectPath, CURSOR_PROMPT_SCRIPT);
|
|
25
|
+
const config = path.join(directory, 'hooks.json');
|
|
26
|
+
if (options.dryRun)
|
|
27
|
+
return { ...result, emittedPaths: [config, script].map(file => file + ' (dry-run)') };
|
|
28
|
+
for (const file of [directory, config, path.dirname(script), script]) {
|
|
29
|
+
try {
|
|
30
|
+
if ((await fs.lstat(file)).isSymbolicLink())
|
|
31
|
+
throw new Error(`Refusing symlinked Cursor hook target: ${file}`);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
if (error.code !== 'ENOENT')
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
let existing = '';
|
|
39
|
+
try {
|
|
40
|
+
existing = await fs.readFile(config, 'utf8');
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (error.code !== 'ENOENT')
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
const doc = existing ? JSON.parse(existing) : { version: 1, hooks: {} };
|
|
47
|
+
if (!doc || typeof doc !== 'object' || Array.isArray(doc) || !Number.isInteger(doc.version) || doc.version < 1
|
|
48
|
+
|| !doc.hooks || typeof doc.hooks !== 'object' || Array.isArray(doc.hooks)
|
|
49
|
+
|| Object.values(doc.hooks).some(entries => !Array.isArray(entries)
|
|
50
|
+
|| entries.some(entry => !entry || typeof entry !== 'object' || Array.isArray(entry)))) {
|
|
51
|
+
throw new Error(`Invalid Cursor hooks object: ${config}`);
|
|
52
|
+
}
|
|
53
|
+
const before = captureDeploymentOutputs([directory]);
|
|
54
|
+
const bytes = await fs.readFile(source.args[0]);
|
|
55
|
+
const state = await managedHookScriptState(options.projectPath, CURSOR_PROMPT_SCRIPT, bytes);
|
|
56
|
+
if (state === 'operator-edited' || state === 'unreadable')
|
|
57
|
+
result.warnings.push(`${script}: kept (${state})`);
|
|
58
|
+
else {
|
|
59
|
+
await fs.mkdir(path.dirname(script), { recursive: true });
|
|
60
|
+
await fs.writeFile(script, bytes, { mode: 0o755 });
|
|
61
|
+
result.emittedPaths.push(script);
|
|
62
|
+
}
|
|
63
|
+
// Replace only our registration; flat operator entries and other events retain their order.
|
|
64
|
+
const hooks = doc.hooks.beforeSubmitPrompt ?? [];
|
|
65
|
+
doc.hooks.beforeSubmitPrompt = [...hooks.filter((hook) => !(hook._aiwg_managed === true && hook._aiwg_id === source.id)),
|
|
66
|
+
managedCursorPromptHook(options.commandRoot ?? options.projectPath, bytes)];
|
|
67
|
+
await fs.mkdir(directory, { recursive: true });
|
|
68
|
+
const temporary = `${config}.tmp.${randomUUID()}`;
|
|
69
|
+
try {
|
|
70
|
+
await fs.writeFile(temporary, JSON.stringify(doc, null, 2) + '\n', { flag: 'wx' });
|
|
71
|
+
await fs.rename(temporary, config);
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
await fs.rm(temporary, { force: true });
|
|
75
|
+
}
|
|
76
|
+
result.emittedPaths.push(config);
|
|
77
|
+
recordDeploymentOutputs(before, [directory], { frameworkSlug: 'aiwg-hooks', claimUnchangedSettings: false, writtenFiles: result.emittedPaths });
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
export async function installCursorPromptDiscovery(options) {
|
|
81
|
+
const { sources, errors } = await loadHookSources(options.frameworkRoot);
|
|
82
|
+
if (errors.length)
|
|
83
|
+
throw new Error(errors.join('\n'));
|
|
84
|
+
const source = sources.find(hook => hook.id === 'aiwg-prompt-discovery');
|
|
85
|
+
if (!source)
|
|
86
|
+
throw new Error('Missing canonical aiwg-prompt-discovery source');
|
|
87
|
+
return translateForCursor(source, options);
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=cursor-translator.js.map
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
import path from 'node:path';
|
|
13
13
|
import { homedir } from 'node:os';
|
|
14
14
|
import { captureDeploymentOutputs, recordDeploymentOutputs } from '../../providers/deployment-ownership.mjs';
|
|
15
|
+
import { translateForCursor } from './cursor-translator.js';
|
|
15
16
|
import { translateForCodex } from './codex-translator.js';
|
|
16
17
|
import { translateForCopilot } from './copilot-translator.js';
|
|
17
18
|
import { translateForFactory } from './factory-translator.js';
|
|
@@ -22,6 +23,7 @@ import { resolveHermesHomePath } from '../../providers/hermes-home.js';
|
|
|
22
23
|
export { AIWG_ENV_VARS, NATIVE_ENV_VAR_MAP } from './types.js';
|
|
23
24
|
export { substituteEnvVars, generateShimBash, EXIT_CODE_MAP } from './shim.js';
|
|
24
25
|
export { translateForCodex, renderCodexHookToml, injectHookBlock as injectCodexHookBlock } from './codex-translator.js';
|
|
26
|
+
export { translateForCursor, installCursorPromptDiscovery } from './cursor-translator.js';
|
|
25
27
|
export { translateForCopilot } from './copilot-translator.js';
|
|
26
28
|
export { translateForFactory, installFactoryPromptDiscovery } from './factory-translator.js';
|
|
27
29
|
export { translateForHermes } from './hermes-translator.js';
|
|
@@ -37,6 +39,7 @@ export { loadHookSources } from './loader.js';
|
|
|
37
39
|
*/
|
|
38
40
|
export const TRANSLATORS = {
|
|
39
41
|
codex: translateForCodex,
|
|
42
|
+
cursor: translateForCursor,
|
|
40
43
|
copilot: translateForCopilot,
|
|
41
44
|
factory: translateForFactory,
|
|
42
45
|
hermes: translateForHermes,
|
|
@@ -67,7 +70,7 @@ export async function bridgeAll(sources, providers, options) {
|
|
|
67
70
|
continue;
|
|
68
71
|
}
|
|
69
72
|
try {
|
|
70
|
-
const roots = [path.join(options.projectPath, '.factory/hooks'), path.join(options.projectPath, '.factory/hooks.json'), path.join(options.projectPath, '.github/hooks'),
|
|
73
|
+
const roots = [path.join(options.projectPath, '.cursor/hooks.json'), path.join(options.projectPath, '.cursor/hooks'), path.join(options.projectPath, '.factory/hooks'), path.join(options.projectPath, '.factory/hooks.json'), path.join(options.projectPath, '.github/hooks'),
|
|
71
74
|
path.join(options.projectPath, '.grok/hooks'), path.join(options.projectPath, '.codex/hooks.json'), path.join(options.projectPath, '.codex/hooks'),
|
|
72
75
|
path.join(homedir(), '.hermes/plugins'), resolveHermesHomePath('config.yaml'), resolveHermesHomePath('agent-hooks'),
|
|
73
76
|
resolveHermesHomePath('.aiwg-manifest.json')];
|
|
@@ -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,18 @@ 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
|
+
// The shared scanner masks automatic quotations; explicit caller contexts stay protected.
|
|
91
|
+
const current = language.split('-')[0] === 'en' ? scanCurrentPatterns(maskProse(content, contexts.filter(c => c.context !== 'prose' && (c.context !== 'quote' || options.contexts?.includes(c))).map(c => ({ ...c, context: 'code' })))) : [];
|
|
92
|
+
for (const f of [...current, ...campaign]) {
|
|
93
|
+
const override = rules.get(f.ruleId);
|
|
94
|
+
if (override?.enabled === false)
|
|
95
|
+
continue;
|
|
96
|
+
emit(f, override ?? { id: f.ruleId, phrase: '', authority: 'advisory', explanation: f.explanation, suggestion: f.suggestion, tier: f.tier }, 'prose');
|
|
97
|
+
if ('scope' in f)
|
|
98
|
+
Object.assign(diagnostics.at(-1), { scope: f.scope, related: f.related });
|
|
99
|
+
}
|
|
87
100
|
for (const rule of rules.values()) {
|
|
88
101
|
if (rule.enabled === false || rule.id.startsWith('repetition:'))
|
|
89
102
|
continue;
|
|
@@ -92,10 +105,20 @@ function diagnoseDocument(content, options, priorParagraphs = new Map(), documen
|
|
|
92
105
|
for (const match of content.matchAll(pattern)) {
|
|
93
106
|
const span = { start: match.index, end: match.index + match[0].length };
|
|
94
107
|
const context = contextAt(span, contexts);
|
|
108
|
+
if (current.some(f => f.ruleId === rule.id && span.start < f.end && span.end > f.start))
|
|
109
|
+
continue;
|
|
95
110
|
if (context === 'code' || context === 'quote')
|
|
96
111
|
continue;
|
|
97
112
|
if (rule.authority === 'advisory' && (context !== 'prose' || options.terminology?.some(t => t.toLocaleLowerCase() === match[0].toLocaleLowerCase())))
|
|
98
113
|
continue;
|
|
114
|
+
if (rule.authority === 'advisory' && ['phrase:delve', 'phrase:rich-tapestry'].includes(rule.id)) {
|
|
115
|
+
const paragraphStart = content.lastIndexOf('\n\n', span.start);
|
|
116
|
+
if (current.some(f => f.ruleId === 'lexical-cluster' && content.lastIndexOf('\n\n', f.start) === paragraphStart))
|
|
117
|
+
continue;
|
|
118
|
+
const paragraph = content.slice(paragraphStart < 0 ? 0 : paragraphStart + 2, content.indexOf('\n\n', span.end) < 0 ? content.length : content.indexOf('\n\n', span.end));
|
|
119
|
+
if (rule.id === 'phrase:rich-tapestry' && /\b(?:textile|woven|weaving|cloth|fabric|border)\b/i.test(paragraph))
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
99
122
|
emit(span, rule, context);
|
|
100
123
|
}
|
|
101
124
|
}
|
|
@@ -110,7 +133,8 @@ function diagnoseDocument(content, options, priorParagraphs = new Map(), documen
|
|
|
110
133
|
if (contextAt(span, contexts, true) !== 'prose')
|
|
111
134
|
continue;
|
|
112
135
|
const priorDocument = priorParagraphs.get(text);
|
|
113
|
-
|
|
136
|
+
const coveredByCampaign = campaign.some(f => f.ruleId === 'repeated-sentence' && f.start >= span.start && f.end <= span.end);
|
|
137
|
+
if (!coveredByCampaign && (seen.has(text) || priorDocument !== undefined))
|
|
114
138
|
emit(span, repetitionOverride ?? { ...repetitionRule, explanation: priorDocument !== undefined && priorDocument !== documentId ? `This paragraph also occurs in document ${priorDocument}; repetition may be intentional.` : repetitionRule.explanation }, 'prose');
|
|
115
139
|
seen.add(text);
|
|
116
140
|
if (priorDocument === undefined)
|
|
@@ -131,10 +155,11 @@ function diagnoseDocument(content, options, priorParagraphs = new Map(), documen
|
|
|
131
155
|
export function diagnoseWritingBatch(documents, options = {}) {
|
|
132
156
|
const results = new Map();
|
|
133
157
|
const seen = new Map();
|
|
158
|
+
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
159
|
for (const document of documents) {
|
|
135
160
|
if (results.has(document.id))
|
|
136
161
|
throw new Error(`Duplicate document ID: ${document.id}`);
|
|
137
|
-
const result = diagnoseDocument(document.content, options, seen, document.id);
|
|
162
|
+
const result = diagnoseDocument(document.content, options, seen, document.id, campaign?.get(document.id));
|
|
138
163
|
results.set(document.id, result);
|
|
139
164
|
}
|
|
140
165
|
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|\\bit\\s+(?:doesn't|does not)\\s+anymore\\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; allow quoted scenario names inside authored prose but exclude numbers, identifiers, code and wholly quoted statements. 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. Also detect a withheld defect followed by an if-clause and a short consequence (at most 16 words after the colon). 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. Also detect a short consequence, a one-word repair and a final explicit moral; the consequence may follow a conditional comma.", "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, protectedRegions } 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, maskProse(content, protectedRegions(content).filter(r => r.context !== 'quote'))));
|
|
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
|