bmad-plus 0.24.0 → 0.25.1
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/CHANGELOG.md +18 -0
- package/README.md +27 -16
- package/SECURITY.md +3 -3
- package/package.json +90 -2
- package/readme-international/README.de.md +27 -16
- package/readme-international/README.es.md +27 -16
- package/readme-international/README.fr.md +27 -16
- package/src/bmad-plus/data/role-triggers.yaml +26 -0
- package/src/bmad-plus/module.yaml +34 -0
- package/src/bmad-plus/packs/pack-dev-studio/categories/analysis/tech-writer-agent.md +7 -0
- package/src/bmad-plus/packs/pack-ghostwriter/SKILL.md +23 -0
- package/src/bmad-plus/packs/pack-ghostwriter/bmad-skill-manifest.yaml +13 -0
- package/src/bmad-plus/packs/pack-ghostwriter/ghostwriter.md +28 -0
- package/src/bmad-plus/packs/pack-ghostwriter/intake.yaml +73 -0
- package/src/bmad-plus/packs/pack-ghostwriter/languages/en.md +11 -0
- package/src/bmad-plus/packs/pack-ghostwriter/languages/fr-FR.md +15 -0
- package/src/bmad-plus/packs/pack-ghostwriter/languages/glossary.md +14 -0
- package/src/bmad-plus/packs/pack-ghostwriter/languages/pt-BR.md +11 -0
- package/src/bmad-plus/packs/pack-ghostwriter/profiles/README.md +22 -0
- package/src/bmad-plus/packs/pack-ghostwriter/profiles/author-note-fr.yaml +20 -0
- package/src/bmad-plus/packs/pack-ghostwriter/profiles/character-dialogue-fr.yaml +20 -0
- package/src/bmad-plus/packs/pack-ghostwriter/profiles/customer-reply-pt-br.yaml +20 -0
- package/src/bmad-plus/packs/pack-ghostwriter/profiles/service-report-en.yaml +20 -0
- package/src/bmad-plus/packs/pack-ghostwriter/references/evaluation.md +5 -0
- package/src/bmad-plus/packs/pack-ghostwriter/references/provenance.md +32 -0
- package/src/bmad-plus/packs/pack-ghostwriter/schemas/config.schema.json +82 -0
- package/src/bmad-plus/packs/pack-ghostwriter/schemas/review-result.schema.json +212 -0
- package/src/bmad-plus/packs/pack-ghostwriter/schemas/run-manifest.schema.json +197 -0
- package/src/bmad-plus/packs/pack-ghostwriter/schemas/voice-profile.schema.json +55 -0
- package/src/bmad-plus/packs/pack-ghostwriter/shared/catalog.json +14 -0
- package/src/bmad-plus/packs/pack-ghostwriter/shared/editorial-contract.md +38 -0
- package/src/bmad-plus/packs/pack-ghostwriter/shared/execution.md +44 -0
- package/src/bmad-plus/packs/pack-ghostwriter/tools/inspect-typography.cjs +273 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workflows/agent-output-review.md +25 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workflows/draft.md +26 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workflows/humanize.md +52 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workflows/improve.md +26 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workflows/localize.md +24 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workflows/voice-profile.md +24 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workshops/council/README.md +57 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workshops/council/brief.md +23 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workshops/council/check.cjs +128 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workshops/council/jury.json +129 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workshops/council/opening.md +1 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workshops/council/select.cjs +54 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workshops/freytag-pyramid/README.md +32 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workshops/freytag-pyramid/specialist.md +12 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workshops/hero-journey/README.md +44 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workshops/hero-journey/specialist.md +17 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workshops/in-medias-res/README.md +15 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workshops/in-medias-res/specialist.md +15 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workshops/kishotenketsu/README.md +26 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workshops/kishotenketsu/specialist.md +10 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workshops/narrative-arc/README.md +24 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workshops/narrative-arc/specialist.md +9 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workshops/snowflake-method/README.md +15 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workshops/snowflake-method/specialist.md +15 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workshops/story-circle/README.md +28 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workshops/story-circle/specialist.md +10 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workshops/story-spine/README.md +28 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workshops/story-spine/specialist.md +9 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workshops/three-act/README.md +39 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workshops/three-act/briefs/objection.md +27 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workshops/three-act/briefs/proposal.md +15 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workshops/three-act/example.md +11 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workshops/three-act/objections.json +103 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workshops/three-act/proposals.json +79 -0
- package/src/bmad-plus/packs/pack-ghostwriter/workshops/three-act/specialist.md +9 -0
- package/src/bmad-plus/skills/ghostwriter-edit/SKILL.md +16 -0
- package/src/bmad-plus/skills/ghostwriter-humanize/SKILL.md +16 -0
- package/src/bmad-plus/skills/ghostwriter-localize/SKILL.md +16 -0
- package/src/bmad-plus/skills/ghostwriter-verify/SKILL.md +16 -0
- package/src/bmad-plus/skills/ghostwriter-voice/SKILL.md +16 -0
- package/src/bmad-plus/skills/ghostwriter-write/SKILL.md +16 -0
- package/tools/build/adapters.config.js +1 -0
- package/tools/cli/bmad-plus-cli.js +1 -0
- package/tools/cli/commands/ghostwriter.js +76 -0
- package/tools/cli/commands/install.js +4 -0
- package/tools/cli/commands/update-check.js +24 -0
- package/tools/cli/lib/ghostwriter-fidelity.js +352 -0
- package/tools/cli/lib/ghostwriter-manifest.js +238 -0
- package/tools/cli/lib/ghostwriter-nexus.js +542 -0
- package/tools/cli/lib/ghostwriter-project.js +304 -0
- package/tools/cli/lib/ghostwriter-quantities.js +239 -0
- package/tools/cli/lib/ghostwriter-structured.js +154 -0
- package/tools/cli/lib/ghostwriter.js +263 -0
- package/tools/cli/lib/nexus-process.js +44 -1
- package/tools/cli/lib/nexus.js +18 -0
- package/tools/cli/lib/packs.js +141 -6
- package/tools/cli/lib/update-check.js +93 -3
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/** Compare structured documents without serializing their protected bytes through a parser. */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const yaml = require('js-yaml');
|
|
5
|
+
|
|
6
|
+
function childPointer(parent, key) {
|
|
7
|
+
return parent + '/' + String(key).replace(/~/g, '~0').replace(/\//g, '~1');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function jsonStrings(text, editable, capture) {
|
|
11
|
+
// Validate the grammar once. Keep token spans for exact comparison (including large integers,
|
|
12
|
+
// whitespace and escape spelling) and detect duplicate keys that JSON.parse would overwrite.
|
|
13
|
+
JSON.parse(text);
|
|
14
|
+
const token = /[ \t\r\n]*("(?:[^"\\]|\\.)*"|[{}[\],:]|[-+.\deE]+|true|false|null)/y;
|
|
15
|
+
function next() {
|
|
16
|
+
const found = token.exec(text);
|
|
17
|
+
if (!found) throw new Error('Invalid JSON token');
|
|
18
|
+
return found[1];
|
|
19
|
+
}
|
|
20
|
+
function visit(path, value, depth) {
|
|
21
|
+
if (depth > 128) throw new Error('JSON nesting exceeds the supported depth');
|
|
22
|
+
if (value[0] === '"' && editable.has(path)) {
|
|
23
|
+
capture(path, token.lastIndex - value.length + 1, token.lastIndex - 1, JSON.parse(value));
|
|
24
|
+
}
|
|
25
|
+
if (value === '{') {
|
|
26
|
+
const keys = new Set();
|
|
27
|
+
let keyToken = next();
|
|
28
|
+
while (keyToken !== '}') {
|
|
29
|
+
const key = JSON.parse(keyToken);
|
|
30
|
+
if (keys.has(key)) throw new Error('Duplicate JSON key');
|
|
31
|
+
keys.add(key);
|
|
32
|
+
next(); // colon
|
|
33
|
+
visit(childPointer(path, key), next(), depth + 1);
|
|
34
|
+
if (next() === '}') break;
|
|
35
|
+
keyToken = next();
|
|
36
|
+
}
|
|
37
|
+
} else if (value === '[') {
|
|
38
|
+
let item = next();
|
|
39
|
+
let index = 0;
|
|
40
|
+
while (item !== ']') {
|
|
41
|
+
visit(childPointer(path, index++), item, depth + 1);
|
|
42
|
+
if (next() === ']') break;
|
|
43
|
+
item = next();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
visit('', next(), 0);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function yamlScalar(tail) {
|
|
51
|
+
if (tail.startsWith('#') || !tail.trim()) return '';
|
|
52
|
+
if (tail[0] === '"' || tail[0] === "'") {
|
|
53
|
+
const quoted = /^(?:"(?:[^"\\]|\\.)*"|'(?:[^']|'')*')(?=$|[ \t])/.exec(tail);
|
|
54
|
+
if (!quoted || !/^(?:[ \t]+(?:#.*)?|)$/.test(tail.slice(quoted[0].length))) {
|
|
55
|
+
throw new Error('Unsupported YAML quoted scalar');
|
|
56
|
+
}
|
|
57
|
+
return quoted[0];
|
|
58
|
+
}
|
|
59
|
+
if (/^[|>&*!%{}[\],@]/.test(tail) || /^[-?:](?:[ \t]|$)/.test(tail)) {
|
|
60
|
+
throw new Error('Only single-line YAML scalars in block mappings are supported');
|
|
61
|
+
}
|
|
62
|
+
const comment = tail.search(/(?<=[ \t])#/);
|
|
63
|
+
return (comment < 0 ? tail : tail.slice(0, comment)).trimEnd();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function yamlStrings(text, editable, capture) {
|
|
67
|
+
// Only block mappings, simple keys and single-line scalar values. Stop on aliases, complex
|
|
68
|
+
// keys, flow collections, sequences, directives and multi-line scalars instead of guessing
|
|
69
|
+
// editable spans. Keep comments, quoting, indentation, separators and line endings intact.
|
|
70
|
+
const candidates = [];
|
|
71
|
+
const ancestors = [];
|
|
72
|
+
const seen = new Set();
|
|
73
|
+
for (let start = 0; start < text.length;) {
|
|
74
|
+
const newline = text.indexOf('\n', start);
|
|
75
|
+
const end = newline === -1 ? text.length : newline;
|
|
76
|
+
const line = text.slice(start, end).replace(/\r$/, '');
|
|
77
|
+
const offset = start;
|
|
78
|
+
start = end + 1;
|
|
79
|
+
if (/^[ \t]*(?:#.*)?$/.test(line)) continue;
|
|
80
|
+
const match = /^( *)([A-Za-z_][A-Za-z0-9_./~-]*):(?:([ \t]+)(.*)|$)$/.exec(line);
|
|
81
|
+
if (!match) throw new Error('Unsupported YAML mapping or scalar syntax');
|
|
82
|
+
const [, indent, key, separator = '', tail = ''] = match;
|
|
83
|
+
while (ancestors.length && ancestors[ancestors.length - 1].indent >= indent.length) {
|
|
84
|
+
ancestors.pop();
|
|
85
|
+
}
|
|
86
|
+
if (ancestors.length > 128) throw new Error('YAML nesting exceeds the supported depth');
|
|
87
|
+
const path = childPointer(ancestors[ancestors.length - 1]?.path || '', key);
|
|
88
|
+
if (seen.has(path)) throw new Error('Duplicate YAML key');
|
|
89
|
+
seen.add(path);
|
|
90
|
+
const scalar = yamlScalar(tail);
|
|
91
|
+
if (scalar === '') {
|
|
92
|
+
ancestors.push({ key, indent: indent.length, path });
|
|
93
|
+
} else if (editable.has(path)) {
|
|
94
|
+
const pos = offset + indent.length + key.length + 1 + separator.length;
|
|
95
|
+
const quoted = scalar[0] === "'" || scalar[0] === '"' ? 1 : 0;
|
|
96
|
+
candidates.push({
|
|
97
|
+
path,
|
|
98
|
+
keys: [...ancestors.map((node) => node.key), key],
|
|
99
|
+
start: pos + quoted,
|
|
100
|
+
end: pos + scalar.length - quoted,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const document = yaml.load(text, { schema: yaml.JSON_SCHEMA });
|
|
105
|
+
if (!document || typeof document !== 'object' || Array.isArray(document)) {
|
|
106
|
+
throw new Error('Expected a YAML block mapping');
|
|
107
|
+
}
|
|
108
|
+
for (const candidate of candidates) {
|
|
109
|
+
let value = document;
|
|
110
|
+
for (const key of candidate.keys) {
|
|
111
|
+
if (!value || typeof value !== 'object' || !Object.hasOwn(value, key)) {
|
|
112
|
+
throw new Error('YAML path does not resolve to the expected value');
|
|
113
|
+
}
|
|
114
|
+
value = value[key];
|
|
115
|
+
}
|
|
116
|
+
if (typeof value !== 'string') throw new Error('Editable YAML fields must contain strings');
|
|
117
|
+
capture(candidate.path, candidate.start, candidate.end, value);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Units use RFC 6901 pointers. Compare frames for equality before comparing decoded prose. */
|
|
122
|
+
function projectStructured(text, format, allowedFields) {
|
|
123
|
+
if (typeof text !== 'string' || !Array.isArray(allowedFields)) {
|
|
124
|
+
throw new Error('Expected document text and a list of editable field pointers');
|
|
125
|
+
}
|
|
126
|
+
const editable = new Set();
|
|
127
|
+
for (const field of allowedFields) {
|
|
128
|
+
if (
|
|
129
|
+
typeof field !== 'string' ||
|
|
130
|
+
(field !== '' && !field.startsWith('/')) ||
|
|
131
|
+
/~(?:[^01]|$)/.test(field) ||
|
|
132
|
+
editable.has(field)
|
|
133
|
+
) {
|
|
134
|
+
throw new Error('Invalid or duplicate editable field pointer');
|
|
135
|
+
}
|
|
136
|
+
editable.add(field);
|
|
137
|
+
}
|
|
138
|
+
const units = new Map();
|
|
139
|
+
const frame = [];
|
|
140
|
+
let cursor = 0;
|
|
141
|
+
function capture(path, start, end, value) {
|
|
142
|
+
frame.push(text.slice(cursor, start), path);
|
|
143
|
+
cursor = end;
|
|
144
|
+
units.set(path, value);
|
|
145
|
+
}
|
|
146
|
+
if (format === 'json') jsonStrings(text, editable, capture);
|
|
147
|
+
else if (format === 'yaml') yamlStrings(text, editable, capture);
|
|
148
|
+
else throw new Error('Unsupported structured format');
|
|
149
|
+
if (units.size !== editable.size) throw new Error('Missing or non-string editable field');
|
|
150
|
+
frame.push(text.slice(cursor));
|
|
151
|
+
return { frame: JSON.stringify(frame), units };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
module.exports = { projectStructured };
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
const {
|
|
5
|
+
BASE,
|
|
6
|
+
MAX_CONTEXT,
|
|
7
|
+
digest,
|
|
8
|
+
identifier,
|
|
9
|
+
textFile,
|
|
10
|
+
present,
|
|
11
|
+
writeOnce,
|
|
12
|
+
} = require('./ghostwriter-project');
|
|
13
|
+
const { prepare, load, manifestPath } = require('./ghostwriter-manifest');
|
|
14
|
+
const { checkFidelity } = require('./ghostwriter-fidelity');
|
|
15
|
+
const nexus = require('./ghostwriter-nexus');
|
|
16
|
+
|
|
17
|
+
const runDirectory = (id) => BASE + '/runs/' + identifier(id);
|
|
18
|
+
|
|
19
|
+
function describeAttempt(manifest, number) {
|
|
20
|
+
const id = 'attempt-' + number;
|
|
21
|
+
const directory = manifest.expected_outputs.directory + '/' + id;
|
|
22
|
+
const suffix = path.extname(manifest.input_artifacts[0].path).toLowerCase();
|
|
23
|
+
return {
|
|
24
|
+
id,
|
|
25
|
+
number,
|
|
26
|
+
output_path: directory + '/edit/revised' + suffix,
|
|
27
|
+
review_path: directory + '/review/semantic.json',
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function attemptFile(runId, attempt) {
|
|
32
|
+
return runDirectory(runId) + '/' + attempt.id + '.json';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function currentAttempt(root, manifest) {
|
|
36
|
+
let latest = null;
|
|
37
|
+
for (let n = 1; n <= manifest.limits.max_revision_attempts; n++) {
|
|
38
|
+
const attempt = describeAttempt(manifest, n);
|
|
39
|
+
const file = attemptFile(manifest.run_id, attempt);
|
|
40
|
+
if (!present(root, file)) break;
|
|
41
|
+
if (digest(JSON.parse(textFile(root, file).content)) !== digest(attempt))
|
|
42
|
+
throw new Error('Attempt reservation mismatch.');
|
|
43
|
+
latest = attempt;
|
|
44
|
+
}
|
|
45
|
+
return latest;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function incomplete(id, reason, attempt = null) {
|
|
49
|
+
return {
|
|
50
|
+
schema_version: 1,
|
|
51
|
+
run_id: id,
|
|
52
|
+
attempt_id: attempt?.id ?? null,
|
|
53
|
+
execution: { status: 'not_verified', producer_session_id: null, reviewer_session_id: null },
|
|
54
|
+
coverage: { total_units: 0, completed_units: 0, missing_units: [] },
|
|
55
|
+
mechanical_checks: { status: 'not_run', findings: [] },
|
|
56
|
+
semantic_review: { fidelity: 'not_run', facts: 'not_run', quality: 'not_run', findings: [] },
|
|
57
|
+
usage: { tokens: null, cost: null, duration_ms: null },
|
|
58
|
+
gate: { verdict: 'incomplete', reasons: [reason] },
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async function run(root, id, options = {}) {
|
|
63
|
+
const manifest = load(root, id);
|
|
64
|
+
if (manifest.execution_requirements.mode !== 'orchestrated')
|
|
65
|
+
throw new Error('Use a run prepared for orchestrated execution.');
|
|
66
|
+
const previous = currentAttempt(root, manifest);
|
|
67
|
+
if (Boolean(previous) !== Boolean(options.retry))
|
|
68
|
+
throw new Error(
|
|
69
|
+
previous ? 'Use --retry for the next attempt.' : 'No previous attempt to retry.'
|
|
70
|
+
);
|
|
71
|
+
const next = describeAttempt(manifest, (previous?.number ?? 0) + 1);
|
|
72
|
+
if (next.number > manifest.limits.max_revision_attempts)
|
|
73
|
+
throw new Error('Ghostwriter revision attempt limit reached.');
|
|
74
|
+
if (previous) {
|
|
75
|
+
const prior = await nexus.inspectReview(root, manifest, previous);
|
|
76
|
+
if (!prior.retryable) throw new Error('Previous execution is unresolved or cannot be retried.');
|
|
77
|
+
}
|
|
78
|
+
const codex = nexus.resolveCodex(options.codex);
|
|
79
|
+
nexus.preflightReview(root, manifest);
|
|
80
|
+
// A concurrent caller racing for the same ordinal gets EEXIST before spawning any worker.
|
|
81
|
+
writeOnce(root, attemptFile(id, next), next);
|
|
82
|
+
await nexus.executeReview(root, manifest, next, { ...options, codex });
|
|
83
|
+
return evaluate(root, id, 'check');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function evaluate(root, id, action, expectedAttempt) {
|
|
87
|
+
let attempt;
|
|
88
|
+
try {
|
|
89
|
+
const manifest = load(root, id);
|
|
90
|
+
attempt = currentAttempt(root, manifest);
|
|
91
|
+
if (!attempt) {
|
|
92
|
+
const report = incomplete(id, 'No execution attempt was observed.');
|
|
93
|
+
const input = manifest.input_artifacts[0];
|
|
94
|
+
report.coverage = {
|
|
95
|
+
total_units: input.units.length,
|
|
96
|
+
completed_units: 0,
|
|
97
|
+
missing_units: input.units,
|
|
98
|
+
};
|
|
99
|
+
report.input_sha256 = input.sha256;
|
|
100
|
+
return report;
|
|
101
|
+
}
|
|
102
|
+
if (expectedAttempt !== undefined && expectedAttempt !== attempt.id)
|
|
103
|
+
return incomplete(id, 'The requested attempt is not current.', attempt);
|
|
104
|
+
const input = manifest.input_artifacts[0];
|
|
105
|
+
const report = incomplete(id, 'The revision is not yet complete.', attempt);
|
|
106
|
+
Object.assign(report, {
|
|
107
|
+
workflow: manifest.workflow,
|
|
108
|
+
content_type: manifest.content_type,
|
|
109
|
+
locale: manifest.locale,
|
|
110
|
+
manifest_sha256: textFile(root, manifestPath(id)).sha256,
|
|
111
|
+
input_sha256: input.sha256,
|
|
112
|
+
output_sha256: null,
|
|
113
|
+
source_set_sha256: manifest.source_set_sha256,
|
|
114
|
+
profile_sha256: manifest.voice_profile.sha256,
|
|
115
|
+
policy_sha256: manifest.policy.sha256,
|
|
116
|
+
output_path: attempt.output_path,
|
|
117
|
+
review_path: attempt.review_path,
|
|
118
|
+
});
|
|
119
|
+
report.coverage = {
|
|
120
|
+
total_units: input.units.length,
|
|
121
|
+
completed_units: 0,
|
|
122
|
+
missing_units: input.units,
|
|
123
|
+
};
|
|
124
|
+
const evidence = await nexus.inspectReview(root, manifest, attempt);
|
|
125
|
+
if (evidence.usage) {
|
|
126
|
+
report.usage = { ...report.usage, ...evidence.usage };
|
|
127
|
+
}
|
|
128
|
+
report.execution = {
|
|
129
|
+
status: evidence.executed ? 'observed' : 'not_verified',
|
|
130
|
+
producer_session_id: evidence.producer_session_id ?? null,
|
|
131
|
+
reviewer_session_id: evidence.reviewer_session_id ?? null,
|
|
132
|
+
producer_attempt_id: evidence.producer_attempt_id ?? null,
|
|
133
|
+
reviewer_attempt_id: evidence.reviewer_attempt_id ?? null,
|
|
134
|
+
producer_adapter: evidence.producer_session_id ? 'codex-exec' : null,
|
|
135
|
+
reviewer_adapter: evidence.reviewer_session_id ? 'codex-exec' : null,
|
|
136
|
+
};
|
|
137
|
+
const reasons = [];
|
|
138
|
+
const findings = [];
|
|
139
|
+
if (!evidence.complete || !evidence.executed)
|
|
140
|
+
reasons.push(evidence.reason || 'Missing current Nexus evidence.');
|
|
141
|
+
if (
|
|
142
|
+
!report.execution.producer_session_id ||
|
|
143
|
+
!report.execution.reviewer_session_id ||
|
|
144
|
+
report.execution.producer_session_id === report.execution.reviewer_session_id
|
|
145
|
+
) {
|
|
146
|
+
reasons.push('Distinct observed producer and reviewer sessions are required.');
|
|
147
|
+
}
|
|
148
|
+
if (!present(root, attempt.output_path)) {
|
|
149
|
+
reasons.push('The revised text is missing.');
|
|
150
|
+
} else {
|
|
151
|
+
const draft = textFile(root, input.path);
|
|
152
|
+
const output = textFile(root, attempt.output_path, manifest.limits.max_output_bytes);
|
|
153
|
+
report.output_sha256 = output.sha256;
|
|
154
|
+
if (
|
|
155
|
+
evidence.complete &&
|
|
156
|
+
(draft.sha256 !== evidence.input_sha256 || output.sha256 !== evidence.output_sha256)
|
|
157
|
+
) {
|
|
158
|
+
reasons.push('The observed input or output differs from the current artifact.');
|
|
159
|
+
}
|
|
160
|
+
report.mechanical_checks = checkFidelity(draft.content, output.content, {
|
|
161
|
+
format: input.format,
|
|
162
|
+
allowedFields: manifest.policy.editable_fields,
|
|
163
|
+
protectedSpans: manifest.policy.protected_spans,
|
|
164
|
+
protectedTerms: manifest.policy.protected_terms,
|
|
165
|
+
sourceLocale: manifest.policy.source_locale,
|
|
166
|
+
targetLocale: manifest.locale,
|
|
167
|
+
});
|
|
168
|
+
if (report.mechanical_checks.status === 'findings')
|
|
169
|
+
findings.push('Mechanical fidelity checks found differences.');
|
|
170
|
+
else if (
|
|
171
|
+
report.mechanical_checks.status !== 'pass' ||
|
|
172
|
+
report.mechanical_checks.coverage !== 'complete'
|
|
173
|
+
) {
|
|
174
|
+
reasons.push('Mechanical fidelity coverage is incomplete.');
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const semantic = evidence.semantic_review;
|
|
178
|
+
if (evidence.complete && semantic) {
|
|
179
|
+
report.semantic_review = semantic;
|
|
180
|
+
report.review_sha256 = textFile(
|
|
181
|
+
root,
|
|
182
|
+
attempt.review_path,
|
|
183
|
+
manifest.limits.max_output_bytes
|
|
184
|
+
).sha256;
|
|
185
|
+
if (report.review_sha256 !== evidence.review_sha256)
|
|
186
|
+
reasons.push('The current review differs from its execution receipt.');
|
|
187
|
+
const coverage = semantic.coverage;
|
|
188
|
+
if (
|
|
189
|
+
!coverage ||
|
|
190
|
+
!Number.isSafeInteger(coverage.total_units) ||
|
|
191
|
+
coverage.total_units < input.units.length ||
|
|
192
|
+
coverage.completed_units !== coverage.total_units ||
|
|
193
|
+
!Array.isArray(coverage.missing_units) ||
|
|
194
|
+
coverage.missing_units.length
|
|
195
|
+
) {
|
|
196
|
+
reasons.push('Semantic review coverage is partial.');
|
|
197
|
+
} else report.coverage = coverage;
|
|
198
|
+
if (!Array.isArray(semantic.findings)) reasons.push('Missing findings list.');
|
|
199
|
+
else if (semantic.findings.some((f) => f.severity === 'blocking'))
|
|
200
|
+
findings.push('The reviewer identified blocking findings.');
|
|
201
|
+
for (const key of ['fidelity', 'quality']) {
|
|
202
|
+
if (semantic[key] === 'findings')
|
|
203
|
+
findings.push('The reviewer identified ' + key + ' findings.');
|
|
204
|
+
else if (semantic[key] !== 'pass')
|
|
205
|
+
reasons.push('Missing semantic assessment of ' + key + '.');
|
|
206
|
+
}
|
|
207
|
+
if (
|
|
208
|
+
manifest.policy.facts === 'provided-sources' &&
|
|
209
|
+
(!manifest.source_artifacts.length || semantic.facts !== 'supported_by_provided_sources')
|
|
210
|
+
) {
|
|
211
|
+
reasons.push('The required factual support is incomplete.');
|
|
212
|
+
}
|
|
213
|
+
} else {
|
|
214
|
+
reasons.push('A complete current semantic review is required.');
|
|
215
|
+
}
|
|
216
|
+
if (!reasons.length && !findings.length && evidence.passes !== true)
|
|
217
|
+
reasons.push('Nexus did not accept this review.');
|
|
218
|
+
load(root, id);
|
|
219
|
+
if (currentAttempt(root, manifest)?.id !== attempt.id)
|
|
220
|
+
reasons.push('A newer attempt has started.');
|
|
221
|
+
const verdict = reasons.length ? 'incomplete' : findings.length ? 'findings' : 'accepted';
|
|
222
|
+
report.gate = { verdict, reasons: [...reasons, ...findings] };
|
|
223
|
+
// Collection binds current bytes and current observed executions. check cannot mint a delivery decision.
|
|
224
|
+
if (verdict !== 'incomplete') {
|
|
225
|
+
const fingerprint = digest(report);
|
|
226
|
+
const receipt = runDirectory(id) + '/receipts/' + attempt.id + '-' + fingerprint + '.json';
|
|
227
|
+
const record = {
|
|
228
|
+
schema_version: 1,
|
|
229
|
+
run_id: id,
|
|
230
|
+
attempt_id: attempt.id,
|
|
231
|
+
sha256: fingerprint,
|
|
232
|
+
report,
|
|
233
|
+
};
|
|
234
|
+
if (Buffer.byteLength(JSON.stringify(record, null, 2) + '\n') > MAX_CONTEXT) {
|
|
235
|
+
throw new Error('The evidence report exceeds the supported size.');
|
|
236
|
+
}
|
|
237
|
+
if (action === 'collect' && !present(root, receipt)) {
|
|
238
|
+
try {
|
|
239
|
+
writeOnce(root, receipt, record);
|
|
240
|
+
} catch (error) {
|
|
241
|
+
if (error.code !== 'EEXIST') throw error;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (
|
|
245
|
+
!present(root, receipt) ||
|
|
246
|
+
digest(JSON.parse(textFile(root, receipt, MAX_CONTEXT).content)) !== digest(record)
|
|
247
|
+
) {
|
|
248
|
+
report.collection_required = true;
|
|
249
|
+
report.gate = {
|
|
250
|
+
verdict: 'incomplete',
|
|
251
|
+
reasons: ['The current execution evidence has not been collected.'],
|
|
252
|
+
};
|
|
253
|
+
} else {
|
|
254
|
+
report.receipt_path = receipt;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return report;
|
|
258
|
+
} catch (error) {
|
|
259
|
+
return incomplete(id, error.message, attempt);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
module.exports = { prepare, run, evaluate };
|
|
@@ -21,7 +21,9 @@ function normalizeExecution(root, value, helpers) {
|
|
|
21
21
|
'resources',
|
|
22
22
|
'cwd',
|
|
23
23
|
'outputLimitBytes',
|
|
24
|
-
...(value.adapter === 'command'
|
|
24
|
+
...(value.adapter === 'command'
|
|
25
|
+
? ['args', 'blockedExitCodes']
|
|
26
|
+
: ['sandbox', 'model', 'finalMessageFile']),
|
|
25
27
|
];
|
|
26
28
|
if (Object.keys(value).some((key) => !allowed.includes(key)))
|
|
27
29
|
fail('Unknown execution field; shell, environment and arbitrary Codex flags are unsupported.');
|
|
@@ -93,6 +95,10 @@ function normalizeExecution(root, value, helpers) {
|
|
|
93
95
|
if (model) args.push('--model', model);
|
|
94
96
|
args.push('-');
|
|
95
97
|
}
|
|
98
|
+
const finalMessageFile =
|
|
99
|
+
value.finalMessageFile === undefined ? undefined : relative(value.finalMessageFile);
|
|
100
|
+
if (finalMessageFile && sandbox !== 'read-only')
|
|
101
|
+
fail('Capturing a final message requires the read-only Codex sandbox.');
|
|
96
102
|
return {
|
|
97
103
|
adapter: value.adapter,
|
|
98
104
|
...resolved,
|
|
@@ -104,6 +110,7 @@ function normalizeExecution(root, value, helpers) {
|
|
|
104
110
|
outputLimitBytes,
|
|
105
111
|
blockedExitCodes: [...new Set(blockedExitCodes)],
|
|
106
112
|
...(value.adapter === 'codex-exec' ? { sandbox, model } : {}),
|
|
113
|
+
...(finalMessageFile ? { finalMessageFile } : {}),
|
|
107
114
|
};
|
|
108
115
|
}
|
|
109
116
|
|
|
@@ -198,6 +205,41 @@ function interpretOutput(execution, stdout, code) {
|
|
|
198
205
|
};
|
|
199
206
|
}
|
|
200
207
|
|
|
208
|
+
// A captured deliverable is the last assistant message from one completed,
|
|
209
|
+
// tool-free provider turn. The worker never opens the destination path.
|
|
210
|
+
function finalMessage(receipt) {
|
|
211
|
+
if (!receipt.output?.stdout?.complete || !receipt.provider?.threadId)
|
|
212
|
+
throw new Error('No complete Codex output.');
|
|
213
|
+
let text;
|
|
214
|
+
let started = false;
|
|
215
|
+
let completed = false;
|
|
216
|
+
let turnStarted = false;
|
|
217
|
+
for (const line of receipt.output.stdout.text.split(/\r?\n/).filter(Boolean)) {
|
|
218
|
+
const event = JSON.parse(line);
|
|
219
|
+
if (completed) throw new Error('Unexpected event after completion.');
|
|
220
|
+
if (
|
|
221
|
+
event.type === 'thread.started' &&
|
|
222
|
+
!started &&
|
|
223
|
+
event.thread_id === receipt.provider.threadId
|
|
224
|
+
)
|
|
225
|
+
started = true;
|
|
226
|
+
else if (started && !turnStarted && event.type === 'turn.started') turnStarted = true;
|
|
227
|
+
else if (turnStarted && event.type === 'item.completed' && event.item?.type === 'agent_message')
|
|
228
|
+
text = event.item.text;
|
|
229
|
+
else if (
|
|
230
|
+
turnStarted &&
|
|
231
|
+
['item.started', 'item.completed'].includes(event.type) &&
|
|
232
|
+
['reasoning', 'agent_message'].includes(event.item?.type)
|
|
233
|
+
)
|
|
234
|
+
continue;
|
|
235
|
+
else if (turnStarted && event.type === 'turn.completed') completed = true;
|
|
236
|
+
else throw new Error('Unexpected event in a tool-free editorial turn.');
|
|
237
|
+
}
|
|
238
|
+
if (!completed || typeof text !== 'string' || !text.trim() || text.includes('\0'))
|
|
239
|
+
throw new Error('Missing final assistant text.');
|
|
240
|
+
return text;
|
|
241
|
+
}
|
|
242
|
+
|
|
201
243
|
function runOwnedProcess({ root, execution, input, environment, deadline, callbacks }) {
|
|
202
244
|
return new Promise((resolve) => {
|
|
203
245
|
const startedAt = new Date().toISOString();
|
|
@@ -369,6 +411,7 @@ function runOwnedProcess({ root, execution, input, environment, deadline, callba
|
|
|
369
411
|
}
|
|
370
412
|
|
|
371
413
|
module.exports = {
|
|
414
|
+
finalMessage,
|
|
372
415
|
normalizeExecution,
|
|
373
416
|
inputBytes,
|
|
374
417
|
executionEnvironment,
|
package/tools/cli/lib/nexus.js
CHANGED
|
@@ -471,6 +471,8 @@ function normalizePlan(root, plan) {
|
|
|
471
471
|
executable,
|
|
472
472
|
stringList,
|
|
473
473
|
});
|
|
474
|
+
if (execution?.finalMessageFile && !artifacts.includes(execution.finalMessageFile))
|
|
475
|
+
fail('A captured message must be one of the task artifacts.');
|
|
474
476
|
if (execution)
|
|
475
477
|
resources.push(...execution.resources.filter((file) => !resources.includes(file)));
|
|
476
478
|
if (!Array.isArray(task.checks) || !task.checks.length || task.checks.length > 30)
|
|
@@ -859,6 +861,11 @@ function evidenceCurrent(root, run, task, verified = new Set(), ancestors = new
|
|
|
859
861
|
fail('Dependency has not been accepted: ' + dependencyId);
|
|
860
862
|
evidenceCurrent(root, run, dependency, verified, dependencyAncestors);
|
|
861
863
|
}
|
|
864
|
+
if (
|
|
865
|
+
run.plan.config.ghostwriterProtocol === 'bmad-plus/ghostwriter@1' &&
|
|
866
|
+
run.plan.config.ghostwriterStage === 'review'
|
|
867
|
+
)
|
|
868
|
+
require('./ghostwriter-nexus').assertReviewAcceptance(root, run, task);
|
|
862
869
|
verified.add(task.id);
|
|
863
870
|
}
|
|
864
871
|
|
|
@@ -1164,6 +1171,11 @@ async function launchTask(directory, runId, taskId, options = {}) {
|
|
|
1164
1171
|
try {
|
|
1165
1172
|
protectedSnapshot(root, def);
|
|
1166
1173
|
const input = processBackend.inputBytes(root, def.execution, safeTarget);
|
|
1174
|
+
if (
|
|
1175
|
+
def.execution.finalMessageFile &&
|
|
1176
|
+
fs.existsSync(safeTarget(root, def.execution.finalMessageFile))
|
|
1177
|
+
)
|
|
1178
|
+
fail('Captured messages require a fresh destination.');
|
|
1167
1179
|
const environment = processBackend.executionEnvironment(def.execution, checkEnvironment());
|
|
1168
1180
|
receipt = await processBackend.runOwnedProcess({
|
|
1169
1181
|
root,
|
|
@@ -1206,6 +1218,12 @@ async function launchTask(directory, runId, taskId, options = {}) {
|
|
|
1206
1218
|
});
|
|
1207
1219
|
try {
|
|
1208
1220
|
protectedSnapshot(root, def);
|
|
1221
|
+
if (receipt.outcome === 'completed' && def.execution.finalMessageFile) {
|
|
1222
|
+
const file = def.execution.finalMessageFile;
|
|
1223
|
+
const message = processBackend.finalMessage(receipt);
|
|
1224
|
+
fs.mkdirSync(path.dirname(safeTarget(root, file)), { recursive: true });
|
|
1225
|
+
fs.writeFileSync(safeTarget(root, file), message, { flag: 'wx', mode: 0o600 });
|
|
1226
|
+
}
|
|
1209
1227
|
receipt.resultHashes = scopeSnapshot(root, def.scope);
|
|
1210
1228
|
} catch (error) {
|
|
1211
1229
|
receipt.outcome = 'ambiguous';
|