@aiwg/cli 2026.11.6 → 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/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/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/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/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/providers/deployment-input-session.d.mts +2 -0
- package/dist/src/providers/deployment-input-session.mjs +38 -0
- 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/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 +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/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/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
|
@@ -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
|
|
@@ -17,6 +17,9 @@ import { existsSync } from 'fs';
|
|
|
17
17
|
import { ValidationRuleLoader } from './validation-rules.js';
|
|
18
18
|
import { loadScoringConfig, getScoringConfig } from './scoring-config-loader.js';
|
|
19
19
|
import { diagnoseWriting } from './contextual-diagnostics.js';
|
|
20
|
+
import { currentPatternIssues, rhetoricalTriad } from './current-patterns.js';
|
|
21
|
+
import { validateCampaign } from './validation-campaign.js';
|
|
22
|
+
import { maskProse } from './prose-mask.js';
|
|
20
23
|
/**
|
|
21
24
|
* Core Writing Validation Engine
|
|
22
25
|
*/
|
|
@@ -59,13 +62,14 @@ export class WritingValidationEngine {
|
|
|
59
62
|
/**
|
|
60
63
|
* Validate content and return comprehensive results
|
|
61
64
|
*/
|
|
62
|
-
async validate(content, context) {
|
|
65
|
+
async validate(content, context, campaign = []) {
|
|
63
66
|
await this.initialize();
|
|
64
67
|
const issues = [];
|
|
65
68
|
// Run all detections
|
|
66
69
|
issues.push(...this.detectBannedPhrases(content, context));
|
|
67
70
|
issues.push(...this.detectAIPatterns(content, context));
|
|
68
71
|
issues.push(...this.detectFormulicStructures(content));
|
|
72
|
+
issues.push(...currentPatternIssues(content, campaign));
|
|
69
73
|
// Analyze authenticity
|
|
70
74
|
const authenticityAnalysis = this.analyzeAuthenticity(content);
|
|
71
75
|
// Check for missing authenticity markers
|
|
@@ -109,7 +113,9 @@ export class WritingValidationEngine {
|
|
|
109
113
|
/**
|
|
110
114
|
* Validate multiple files in batch
|
|
111
115
|
*/
|
|
112
|
-
async validateBatch(files, context) {
|
|
116
|
+
async validateBatch(files, context, options = {}) {
|
|
117
|
+
if (options.cross)
|
|
118
|
+
return validateCampaign(this, files, context);
|
|
113
119
|
const results = new Map();
|
|
114
120
|
// Process in parallel
|
|
115
121
|
await Promise.all(files.map(async (file) => {
|
|
@@ -207,6 +213,7 @@ export class WritingValidationEngine {
|
|
|
207
213
|
* Analyze content for authenticity markers
|
|
208
214
|
*/
|
|
209
215
|
analyzeAuthenticity(content) {
|
|
216
|
+
content = maskProse(content);
|
|
210
217
|
const humanMarkers = [];
|
|
211
218
|
const aiTells = [];
|
|
212
219
|
const missingMarkers = [];
|
|
@@ -232,7 +239,7 @@ export class WritingValidationEngine {
|
|
|
232
239
|
{ pattern: /\b(comprehensive|robust|innovative|optimal|best-in-class)\b/gi, name: 'vague intensifiers' },
|
|
233
240
|
{ pattern: /\b(it is important to note|it is worth noting|it should be mentioned)\b/gi, name: 'throat-clearing phrases' },
|
|
234
241
|
{ pattern: /\b(may help to|can serve to|has the potential to)\b/gi, name: 'excessive hedging' },
|
|
235
|
-
{ pattern:
|
|
242
|
+
{ pattern: rhetoricalTriad, name: 'three-item lists' }
|
|
236
243
|
];
|
|
237
244
|
for (const { pattern, name } of aiTellPatterns) {
|
|
238
245
|
const matches = content.match(pattern);
|
|
@@ -324,7 +331,7 @@ export class WritingValidationEngine {
|
|
|
324
331
|
findPatternMatches(content, pattern) {
|
|
325
332
|
const matches = [];
|
|
326
333
|
const regex = typeof pattern === 'string' ? new RegExp(pattern, 'gi') : pattern;
|
|
327
|
-
const lines = content.split('\n');
|
|
334
|
+
const lines = maskProse(content).split('\n');
|
|
328
335
|
let absolutePos = 0;
|
|
329
336
|
for (let lineIdx = 0; lineIdx < lines.length; lineIdx++) {
|
|
330
337
|
const line = lines[lineIdx];
|
|
@@ -335,7 +342,7 @@ export class WritingValidationEngine {
|
|
|
335
342
|
// Extract context (surrounding text)
|
|
336
343
|
const contextStart = Math.max(0, (match.index || 0) - 30);
|
|
337
344
|
const contextEnd = Math.min(line.length, (match.index || 0) + match[0].length + 30);
|
|
338
|
-
const context =
|
|
345
|
+
const context = content.slice(absolutePos + contextStart, absolutePos + contextEnd);
|
|
339
346
|
matches.push({
|
|
340
347
|
match: match[0],
|
|
341
348
|
location: {
|
|
@@ -356,12 +363,12 @@ export class WritingValidationEngine {
|
|
|
356
363
|
const warningCount = issues.filter(i => i.severity === 'warning').length;
|
|
357
364
|
const infoCount = issues.filter(i => i.severity === 'info').length;
|
|
358
365
|
// Count words and sentences
|
|
359
|
-
const words = content.split(/\s+/).filter(w => w.length > 0);
|
|
360
|
-
const sentences = content.split(/[.!?]+/).filter(s => s.trim().length > 0);
|
|
366
|
+
const words = maskProse(content).replace(/\u0001/g, ' ').split(/\s+/).filter(w => w.length > 0);
|
|
367
|
+
const sentences = maskProse(content).replace(/\u0001/g, ' ').split(/[.!?]+/).filter(s => s.trim().length > 0);
|
|
361
368
|
// Calculate AI pattern score (0-100, higher = more AI-like)
|
|
362
369
|
const config = getScoringConfig();
|
|
363
370
|
const aiPatternCount = issues.filter(i => i.type === 'ai_pattern' || i.type === 'banned_phrase').length;
|
|
364
|
-
const aiPatternScore = Math.min(100, (aiPatternCount / Math.max(1, words.length
|
|
371
|
+
const aiPatternScore = Math.min(100, (aiPatternCount * 50 / Math.max(1, words.length)) * config.issueScoring.aiPatternNormalizer);
|
|
365
372
|
return {
|
|
366
373
|
totalIssues: issues.length,
|
|
367
374
|
criticalCount,
|
|
@@ -378,9 +385,9 @@ export class WritingValidationEngine {
|
|
|
378
385
|
// Start with authenticity score
|
|
379
386
|
let score = authenticityAnalysis.score;
|
|
380
387
|
// Deduct for critical issues (heavy penalty)
|
|
381
|
-
score -= summary.criticalCount * config.issueScoring.criticalPenalty;
|
|
388
|
+
score -= summary.criticalCount * 50 / Math.max(1, summary.wordCount) * config.issueScoring.criticalPenalty;
|
|
382
389
|
// Deduct for warnings (moderate penalty)
|
|
383
|
-
score -= summary.warningCount * config.issueScoring.warningPenalty;
|
|
390
|
+
score -= summary.warningCount * 50 / Math.max(1, summary.wordCount) * config.issueScoring.warningPenalty;
|
|
384
391
|
// Deduct for high AI pattern score
|
|
385
392
|
score -= summary.aiPatternScore * config.issueScoring.aiPatternMultiplier;
|
|
386
393
|
// Clamp to 0-100
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { readFile } from 'fs/promises';
|
|
8
8
|
import { existsSync } from 'fs';
|
|
9
9
|
import { join } from 'path';
|
|
10
|
+
import { rhetoricalTriad } from './current-patterns.js';
|
|
10
11
|
/**
|
|
11
12
|
* Loads validation rules from AIWG markdown files
|
|
12
13
|
*/
|
|
@@ -368,10 +369,10 @@ export class ValidationRuleLoader {
|
|
|
368
369
|
{
|
|
369
370
|
id: 'struct_three_items',
|
|
370
371
|
type: 'formulaic_structure',
|
|
371
|
-
pattern:
|
|
372
|
+
pattern: rhetoricalTriad,
|
|
372
373
|
severity: 'info',
|
|
373
|
-
message: '
|
|
374
|
-
suggestion: '
|
|
374
|
+
message: 'Rhetorical three-item predicate detected',
|
|
375
|
+
suggestion: 'Replace generic claims with supported details; retain real inventories',
|
|
375
376
|
category: 'Lists'
|
|
376
377
|
}
|
|
377
378
|
];
|
package/package.json
CHANGED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://aiwg.io/schemas/dataset/service-binding.v1.schema.json",
|
|
4
|
+
"title": "Qualified dataset service binding v1",
|
|
5
|
+
"oneOf": [
|
|
6
|
+
{ "$ref": "#/$defs/selection" },
|
|
7
|
+
{ "$ref": "#/$defs/descriptor" }
|
|
8
|
+
],
|
|
9
|
+
"$defs": {
|
|
10
|
+
"contract": { "const": "aiwg.dataset.service-binding/v1" },
|
|
11
|
+
"id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9._-]{1,127}$" },
|
|
12
|
+
"version": { "type": "string", "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$" },
|
|
13
|
+
"digest": {
|
|
14
|
+
"type": "object", "additionalProperties": false, "required": ["algorithm", "value"],
|
|
15
|
+
"properties": { "algorithm": { "const": "sha256" }, "value": { "type": "string", "pattern": "^[a-f0-9]{64}$" } }
|
|
16
|
+
},
|
|
17
|
+
"component": {
|
|
18
|
+
"type": "object", "additionalProperties": false, "required": ["id", "version", "packageDigest"],
|
|
19
|
+
"properties": { "id": { "$ref": "#/$defs/id" }, "version": { "$ref": "#/$defs/version" }, "packageDigest": { "$ref": "#/$defs/digest" } }
|
|
20
|
+
},
|
|
21
|
+
"capability": {
|
|
22
|
+
"type": "object", "additionalProperties": false, "required": ["name", "version"],
|
|
23
|
+
"properties": { "name": { "$ref": "#/$defs/id" }, "version": { "$ref": "#/$defs/version" } }
|
|
24
|
+
},
|
|
25
|
+
"selection": {
|
|
26
|
+
"type": "object", "additionalProperties": false, "required": ["contractVersion", "kind", "id", "version", "descriptorDigest"],
|
|
27
|
+
"properties": {
|
|
28
|
+
"contractVersion": { "$ref": "#/$defs/contract" }, "kind": { "const": "DatasetBindingSelection" },
|
|
29
|
+
"id": { "$ref": "#/$defs/id" }, "version": { "$ref": "#/$defs/version" }, "descriptorDigest": { "$ref": "#/$defs/digest" }
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"descriptor": {
|
|
33
|
+
"type": "object", "additionalProperties": false,
|
|
34
|
+
"required": ["contractVersion", "kind", "id", "version", "datasetContractVersion", "adapterContractVersion", "adapter", "adapterManifestDigest", "backend", "capabilities", "limits", "qualification"],
|
|
35
|
+
"properties": {
|
|
36
|
+
"contractVersion": { "$ref": "#/$defs/contract" }, "kind": { "const": "DatasetServiceBinding" },
|
|
37
|
+
"id": { "$ref": "#/$defs/id" }, "version": { "$ref": "#/$defs/version" },
|
|
38
|
+
"datasetContractVersion": { "const": "aiwg.dataset/v1" }, "adapterContractVersion": { "const": "aiwg.dataset.adapter/v1" },
|
|
39
|
+
"adapter": { "$ref": "#/$defs/component" }, "adapterManifestDigest": { "$ref": "#/$defs/digest" }, "backend": { "$ref": "#/$defs/component" },
|
|
40
|
+
"capabilities": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "$ref": "#/$defs/capability" } },
|
|
41
|
+
"limits": {
|
|
42
|
+
"type": "object", "additionalProperties": false, "required": ["maxRecords", "maxBytes", "maxRecordBytes", "timeoutMs"],
|
|
43
|
+
"properties": {
|
|
44
|
+
"maxRecords": { "type": "integer", "minimum": 1, "maximum": 10000 },
|
|
45
|
+
"maxBytes": { "type": "integer", "minimum": 1, "maximum": 16777216 },
|
|
46
|
+
"maxRecordBytes": { "type": "integer", "minimum": 1, "maximum": 1048576 },
|
|
47
|
+
"timeoutMs": { "type": "integer", "minimum": 1, "maximum": 30000 }
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"qualification": {
|
|
51
|
+
"type": "object", "additionalProperties": false, "required": ["fixtureRevision", "cells"],
|
|
52
|
+
"properties": {
|
|
53
|
+
"fixtureRevision": { "type": "string", "minLength": 1, "maxLength": 128 },
|
|
54
|
+
"cells": {
|
|
55
|
+
"type": "array", "minItems": 5, "maxItems": 5,
|
|
56
|
+
"items": {
|
|
57
|
+
"type": "object", "additionalProperties": false, "required": ["name", "passed", "evidence"],
|
|
58
|
+
"properties": {
|
|
59
|
+
"name": { "enum": ["admission", "capability-version", "cancellation-resume", "replay", "receipt-mismatch"] },
|
|
60
|
+
"passed": { "type": "boolean" },
|
|
61
|
+
"evidence": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 1, "maxLength": 1024 } }
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -1,68 +1,107 @@
|
|
|
1
1
|
// Shared provider models platforms utilities.
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
2
3
|
import { resolveAiwgRoot } from './base-inventory.mjs';
|
|
3
|
-
import { fs, os, path, yaml } from './base-runtime.mjs';
|
|
4
|
+
import { createRequire, fs, os, path, yaml } from './base-runtime.mjs';
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
// ============================================================================
|
|
7
8
|
// Model Configuration
|
|
8
9
|
// ============================================================================
|
|
9
10
|
|
|
11
|
+
const isPlainObject = value => value !== null && typeof value === 'object'
|
|
12
|
+
&& Object.getPrototypeOf(value) === Object.prototype;
|
|
13
|
+
|
|
14
|
+
/** Merge plain objects; malformed overrides cannot erase inherited object fields. */
|
|
15
|
+
function mergeModelConfig(base, layer, source, prefix = '') {
|
|
16
|
+
const merged = { ...base };
|
|
17
|
+
for (const [key, value] of Object.entries(layer)) {
|
|
18
|
+
if (['_source', '__proto__', 'constructor', 'prototype'].includes(key)) continue;
|
|
19
|
+
const field = prefix ? `${prefix}.${key}` : key;
|
|
20
|
+
if (isPlainObject(base[key]) && !isPlainObject(value)) {
|
|
21
|
+
console.warn(`Warning: Ignoring non-object models.json key "${field}" at ${source}; keeping inherited object`);
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
merged[key] = isPlainObject(value)
|
|
25
|
+
? mergeModelConfig(isPlainObject(base[key]) ? base[key] : {}, value, source, field)
|
|
26
|
+
: value;
|
|
27
|
+
}
|
|
28
|
+
return merged;
|
|
29
|
+
}
|
|
30
|
+
|
|
10
31
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
32
|
+
* Merge model configuration: AIWG defaults ← user ← project.
|
|
33
|
+
* Omitted fields inherit; object fields require object overrides. _source lists applied layers.
|
|
13
34
|
*/
|
|
14
35
|
export function loadModelConfig(srcRoot) {
|
|
15
|
-
//
|
|
16
|
-
// shipped
|
|
17
|
-
// through to the hardcoded fallback and deployed bare aliases (#2563).
|
|
36
|
+
// Bundle sources are not corpus roots. If no corpus can be found, read the
|
|
37
|
+
// defaults shipped beside this loader before falling back to the catalog.
|
|
18
38
|
const aiwgRoot = (srcRoot && resolveAiwgRoot(srcRoot)) || srcRoot;
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (fs.existsSync(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
} catch (err) {
|
|
32
|
-
console.warn(`Warning: Could not parse models.json at ${loc.path}: ${err.message}`);
|
|
39
|
+
const shippedPath = 'agentic/code/frameworks/sdlc-complete/config/models.json';
|
|
40
|
+
const bundledPath = new URL(`../../../${shippedPath}`, import.meta.url);
|
|
41
|
+
const defaultPaths = [...new Set([
|
|
42
|
+
...(aiwgRoot ? [path.join(aiwgRoot, shippedPath)] : []),
|
|
43
|
+
fileURLToPath(bundledPath),
|
|
44
|
+
])];
|
|
45
|
+
function readConfig(file) {
|
|
46
|
+
if (!fs.existsSync(file)) return null;
|
|
47
|
+
try {
|
|
48
|
+
const config = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
49
|
+
if (!config || typeof config !== 'object' || Array.isArray(config)) {
|
|
50
|
+
throw new Error('expected a JSON object');
|
|
33
51
|
}
|
|
52
|
+
return config;
|
|
53
|
+
} catch (err) {
|
|
54
|
+
console.warn(`Warning: Could not parse models.json at ${file}: ${err.message}`);
|
|
55
|
+
return null;
|
|
34
56
|
}
|
|
35
57
|
}
|
|
36
58
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
'haiku': 'claude-haiku-4-5',
|
|
53
|
-
'inherit': 'inherit'
|
|
54
|
-
},
|
|
55
|
-
claude_shorthand: {
|
|
56
|
-
'opus': 'opus',
|
|
57
|
-
'opus-1m': 'opus[1m]',
|
|
58
|
-
'opus[1m]': 'opus[1m]',
|
|
59
|
-
'sonnet': 'sonnet',
|
|
60
|
-
'sonnet-1m': 'sonnet[1m]',
|
|
61
|
-
'sonnet[1m]': 'sonnet[1m]',
|
|
62
|
-
'haiku': 'haiku',
|
|
63
|
-
'inherit': 'inherit'
|
|
59
|
+
let config;
|
|
60
|
+
const sources = [];
|
|
61
|
+
for (const file of defaultPaths) {
|
|
62
|
+
config = readConfig(file);
|
|
63
|
+
if (config) {
|
|
64
|
+
sources.push(`AIWG defaults (${file})`);
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (!config) {
|
|
69
|
+
const catalog = createRequire(import.meta.url)('../../../agentic/code/providers/model-catalog.v1.json');
|
|
70
|
+
config = {};
|
|
71
|
+
for (const provider of ['claude', 'factory']) {
|
|
72
|
+
config[provider] = Object.fromEntries(Object.entries(catalog.providers[provider].roles)
|
|
73
|
+
.map(([role, entry]) => [role, { model: entry.id }]));
|
|
64
74
|
}
|
|
65
|
-
|
|
75
|
+
// Windsurf's catalog currently has only "inherited" placeholders. Until it
|
|
76
|
+
// supplies concrete IDs, use Factory's API pins, matching shipped Windsurf.
|
|
77
|
+
config.windsurf = Object.fromEntries(Object.entries(config.factory).map(([role, entry]) => {
|
|
78
|
+
const id = catalog.providers.windsurf?.roles?.[role]?.id;
|
|
79
|
+
return [role, { model: typeof id === 'string' && id.trim() && id !== 'inherited' ? id : entry.model }];
|
|
80
|
+
}));
|
|
81
|
+
config.shorthand = { inherit: 'inherit' };
|
|
82
|
+
config.claude_shorthand = { inherit: 'inherit' };
|
|
83
|
+
for (const [alias, role] of Object.entries({ opus: 'reasoning', sonnet: 'coding', haiku: 'efficiency' })) {
|
|
84
|
+
config.shorthand[alias] = config.claude[role].model;
|
|
85
|
+
config.claude_shorthand[alias] = alias;
|
|
86
|
+
if (alias !== 'haiku') {
|
|
87
|
+
config.claude_shorthand[`${alias}-1m`] = `${alias}[1m]`;
|
|
88
|
+
config.claude_shorthand[`${alias}[1m]`] = `${alias}[1m]`;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
sources.push('model catalog (fallback)');
|
|
92
|
+
}
|
|
93
|
+
const homeDir = process.env.HOME || process.env.USERPROFILE || os.homedir();
|
|
94
|
+
for (const loc of [
|
|
95
|
+
{ path: path.join(homeDir, '.config', 'aiwg', 'models.json'), label: 'user' },
|
|
96
|
+
{ path: path.join(process.cwd(), 'models.json'), label: 'project' },
|
|
97
|
+
]) {
|
|
98
|
+
const layer = readConfig(loc.path);
|
|
99
|
+
if (layer) {
|
|
100
|
+
config = mergeModelConfig(config, layer, loc.path);
|
|
101
|
+
sources.push(`${loc.label} (${loc.path})`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return { ...config, _source: sources.join(' ← ') };
|
|
66
105
|
}
|
|
67
106
|
|
|
68
107
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Preview live corpus inputs without copying or sealing a never-committed source snapshot.
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { snapshotPreimages, within } from './rule-deployment-state.mjs';
|
|
4
|
+
|
|
5
|
+
export function corpusInputPlan(original, corpusRoot, sourceTree, pool) {
|
|
6
|
+
const preview = original.dryRun === true;
|
|
7
|
+
return {
|
|
8
|
+
preimages: preview ? [] : pool?.preimages ?? snapshotPreimages([
|
|
9
|
+
sourceTree, path.join(corpusRoot, 'prebuilt', 'framework-relations'),
|
|
10
|
+
path.join(corpusRoot, 'package.json'), path.join(corpusRoot, 'schemas'),
|
|
11
|
+
]),
|
|
12
|
+
snapshotRequired: !preview && !pool,
|
|
13
|
+
snapshotRoot: temp => preview ? corpusRoot : pool?.snapshotRoot ?? path.join(temp, 'input'),
|
|
14
|
+
// Binding discovery may return absolute corpus paths. These are already
|
|
15
|
+
// readable in a preview; copying each selected target would rebuild the
|
|
16
|
+
// snapshot piecemeal. Output still renders in the isolated project stage.
|
|
17
|
+
isLiveInput: file => preview && within(corpusRoot, file),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Reuse the existing immutable input pool within an update and measure staging.
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { channel } from 'node:diagnostics_channel';
|
|
4
|
+
import { importImpl } from '../../_resolve-impl.mjs';
|
|
5
|
+
import { resolveAiwgRoot } from './base.mjs';
|
|
6
|
+
import { createRuleDeploymentInputPool, disposeRuleDeploymentInputPool } from './rule-deployment-state.mjs';
|
|
7
|
+
|
|
8
|
+
const { deploymentSessionInput } = await importImpl(import.meta.url, 'providers/deployment-input-session.mjs');
|
|
9
|
+
const timings = channel('aiwg.provider-staging');
|
|
10
|
+
const sourceRoot = srcRoot => path.resolve(resolveAiwgRoot(srcRoot) || srcRoot);
|
|
11
|
+
|
|
12
|
+
export function sessionInputPool(srcRoot) {
|
|
13
|
+
const root = sourceRoot(srcRoot);
|
|
14
|
+
return deploymentSessionInput(root, () => {
|
|
15
|
+
const start = performance.now();
|
|
16
|
+
let status = 'failed';
|
|
17
|
+
try {
|
|
18
|
+
const pool = createRuleDeploymentInputPool(srcRoot);
|
|
19
|
+
status = 'succeeded';
|
|
20
|
+
return pool;
|
|
21
|
+
}
|
|
22
|
+
finally {
|
|
23
|
+
timings.publish({ phase: 'snapshot-provider-inputs', source: root, durationMs: performance.now() - start, status });
|
|
24
|
+
}
|
|
25
|
+
}, disposeRuleDeploymentInputPool);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function measureProviderStaging(original, provider, prepare) {
|
|
29
|
+
const source = sourceRoot(original.srcRoot);
|
|
30
|
+
const start = performance.now();
|
|
31
|
+
let status = 'failed';
|
|
32
|
+
try {
|
|
33
|
+
const plan = await prepare();
|
|
34
|
+
status = 'prepared';
|
|
35
|
+
return plan;
|
|
36
|
+
} finally {
|
|
37
|
+
timings.publish({ phase: 'prepare-provider-staging', source, provider: provider.name,
|
|
38
|
+
durationMs: performance.now() - start, status });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -49,10 +49,18 @@ const { captureDeploymentOutputs, recordDeploymentOutputs } = await importImpl(i
|
|
|
49
49
|
const { preserveDeploymentOutputs } = await importImpl(import.meta.url, 'providers/deployment-preservation.mjs');
|
|
50
50
|
import { retireInlineStartup } from './rule-startup.mjs';
|
|
51
51
|
import { createStagedDirectoryReference } from './staged-directory-reference.mjs';
|
|
52
|
+
import { measureProviderStaging, sessionInputPool } from './rule-deployment-input-session.mjs';
|
|
53
|
+
import { corpusInputPlan } from './rule-deployment-corpus-inputs.mjs';
|
|
52
54
|
|
|
53
55
|
/** Stage only provider/context output, never the user's source tree. On failure
|
|
54
56
|
* no staged output (including skills and behaviors) reaches the prior deployment. */
|
|
55
57
|
export async function prepareRuleDeployment(original, provider, deploy) {
|
|
58
|
+
return measureProviderStaging(original, provider, () => prepareWithInputs({
|
|
59
|
+
...original, inputPool: original.dryRun ? undefined : original.inputPool || sessionInputPool(original.srcRoot),
|
|
60
|
+
}, provider, deploy));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function prepareWithInputs(original, provider, deploy) {
|
|
56
64
|
const budgetEnv = { ...process.env };
|
|
57
65
|
const ruleDir = path.isAbsolute(provider.paths.rules || '') ? provider.paths.rules : path.join(original.target, provider.paths.rules || `.${provider.name}/rules`);
|
|
58
66
|
const manifestFile = path.join(ruleDir, '.aiwg-manifest.json');
|
|
@@ -78,7 +86,8 @@ export async function prepareRuleDeployment(original, provider, deploy) {
|
|
|
78
86
|
const localSources = Object.values(projectConfig.installed || {}).filter(entry => entry?.localPath)
|
|
79
87
|
.map(entry => path.resolve(original.target, entry.localPath));
|
|
80
88
|
const selectedRules = collectDeploymentRuleSources({ ...original, previousRuleSources: previous.ruleSources || [] });
|
|
81
|
-
const
|
|
89
|
+
const corpusInputs = corpusInputPlan(original, corpusRoot, sourceTree, pool);
|
|
90
|
+
const initialPreimages = [...corpusInputs.preimages, ...snapshotPreimages([path.join(corpusRoot, '.aiwg', '.index'),
|
|
82
91
|
manifestFile, path.join(original.target, '.aiwg', 'aiwg.config'), path.join(original.target, '.aiwg', 'AIWG.md'), path.join(original.target, '.aiwg', 'skills'), path.join(original.target, '.aiwg-location'), ...projectGraphFiles, ...userGraphFiles, ...localSources,
|
|
83
92
|
...(path.resolve(original.srcRoot) === path.resolve(corpusRoot) ? [] : [original.srcRoot]), ...(original.additionalSources || []), ...selectedRules, ...selectedRules.map(file => path.dirname(file)),
|
|
84
93
|
userConfigFile('aiwg.config'), process.env.AIWG_USER_REGISTRY_PATH || userConfigFile('installed.json'),
|
|
@@ -114,14 +123,14 @@ export async function prepareRuleDeployment(original, provider, deploy) {
|
|
|
114
123
|
const priorArtifacts = process.env.AIWG_ARTIFACTS_PATH;
|
|
115
124
|
const priorXdgData = process.env.XDG_DATA_HOME;
|
|
116
125
|
try {
|
|
117
|
-
const snapshotRoot =
|
|
126
|
+
const snapshotRoot = corpusInputs.snapshotRoot(temp);
|
|
118
127
|
const treeRelative = path.relative(corpusRoot, sourceTree);
|
|
119
128
|
const isCorpusTree = treeRelative === path.join('agentic', 'code');
|
|
120
129
|
const snapshotTree = isCorpusTree ? path.join(snapshotRoot, 'agentic', 'code') : snapshotRoot;
|
|
121
|
-
if (
|
|
130
|
+
if (corpusInputs.snapshotRequired) { fs.mkdirSync(path.dirname(snapshotTree), { recursive: true }); materializeInput(sourceTree, snapshotTree); }
|
|
122
131
|
const expectedTree = initialPreimages.find(item => item.path === path.resolve(sourceTree));
|
|
123
|
-
if (
|
|
124
|
-
if (isCorpusTree &&
|
|
132
|
+
if (corpusInputs.snapshotRequired && JSON.stringify(capturePreimage(snapshotTree)) !== JSON.stringify(materializedPreimage(expectedTree.state))) throw new Error('Source changed while preparing immutable snapshot');
|
|
133
|
+
if (isCorpusTree && corpusInputs.snapshotRequired) {
|
|
125
134
|
for (const rel of ['package.json', 'prebuilt', 'schemas']) {
|
|
126
135
|
const from = path.join(corpusRoot, rel), to = path.join(snapshotRoot, rel);
|
|
127
136
|
if (fs.existsSync(from)) materializeInput(from, to);
|
|
@@ -323,7 +332,7 @@ export async function prepareRuleDeployment(original, provider, deploy) {
|
|
|
323
332
|
const remappedBindings = new Map();
|
|
324
333
|
for (const entry of delivery.targets) {
|
|
325
334
|
const source = path.resolve(entry.source);
|
|
326
|
-
const alreadyFrozen = source.startsWith(`${temp}${path.sep}`);
|
|
335
|
+
const alreadyFrozen = corpusInputs.isLiveInput(source) || source.startsWith(`${temp}${path.sep}`) || Boolean(pool && source.startsWith(`${pool.snapshotRoot}${path.sep}`));
|
|
327
336
|
if (!alreadyFrozen) {
|
|
328
337
|
const state = capturePreimage(source);
|
|
329
338
|
const to = path.join(temp, 'discovered-input', String(sourceMappings.length), path.basename(source));
|
|
@@ -246,6 +246,8 @@ Writing quality validation and AI pattern detection.
|
|
|
246
246
|
...['artifact-output-policy', 'artifact-output-policy-guidance'].map(name =>
|
|
247
247
|
({ from: `agentic/code/addons/aiwg-utils/rules/${name}.md`, to: `rules/${name}.md` })),
|
|
248
248
|
{ from: 'agentic/code/addons/aiwg-utils/templates/subagent-brief.md', to: 'templates/subagent-brief.md' },
|
|
249
|
+
...['checkpoint-handoff', 'commit-message', 'agent-handoff', 'stakeholder-status-report', 'security-finding', 'code-review-findings'].map(name =>
|
|
250
|
+
({ from: `agentic/code/addons/aiwg-utils/templates/${name}.md`, to: `templates/${name}.md` })),
|
|
249
251
|
{ from: 'agentic/code/addons/aiwg-utils/templates/issues', to: 'templates/issues' },
|
|
250
252
|
{ from: 'agentic/code/addons/aiwg-utils/templates/pull-requests', to: 'templates/pull-requests' }
|
|
251
253
|
],
|