agentxchain 2.155.37 → 2.155.39
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/package.json +1 -1
- package/src/commands/run.js +31 -5
- package/src/lib/dispatch-bundle.js +1 -0
- package/src/lib/export-verifier.js +29 -21
- package/src/lib/export.js +41 -1
- package/src/lib/governed-state.js +88 -30
package/package.json
CHANGED
package/src/commands/run.js
CHANGED
|
@@ -673,26 +673,52 @@ export async function executeGovernedRun(context, opts = {}) {
|
|
|
673
673
|
const reportsDir = join(root, '.agentxchain', 'reports');
|
|
674
674
|
mkdirSync(reportsDir, { recursive: true });
|
|
675
675
|
|
|
676
|
-
|
|
676
|
+
// BUG-88: two-attempt export with fallback to tighter bounds on string-length overflow
|
|
677
|
+
const defaultExportOpts = { maxJsonlEntries: 1000, maxBase64Bytes: 1024 * 1024, maxExportFiles: 500, maxTextDataBytes: 131072 };
|
|
678
|
+
const tightExportOpts = { maxJsonlEntries: 500, maxBase64Bytes: 65536, maxExportFiles: 200, maxTextDataBytes: 32768 };
|
|
679
|
+
|
|
680
|
+
let exportResult = buildRunExport(root, defaultExportOpts);
|
|
677
681
|
if (exportResult.ok) {
|
|
678
682
|
const runId = result.state.run_id || 'unknown';
|
|
679
683
|
const exportPath = join(reportsDir, `export-${runId}.json`);
|
|
684
|
+
let exportWriteOk = false;
|
|
685
|
+
let usedExport = exportResult.export;
|
|
680
686
|
|
|
681
|
-
// Write export JSON — compact format to avoid string-length overflow (BUG-84)
|
|
687
|
+
// Write export JSON — compact format to avoid string-length overflow (BUG-84/88)
|
|
682
688
|
try {
|
|
683
689
|
writeFileSync(exportPath, JSON.stringify(exportResult.export));
|
|
690
|
+
exportWriteOk = true;
|
|
684
691
|
} catch (exportWriteErr) {
|
|
685
|
-
|
|
692
|
+
// BUG-88: retry with tighter bounds on Invalid string length
|
|
693
|
+
if (/Invalid string length/i.test(exportWriteErr.message)) {
|
|
694
|
+
log(chalk.dim(` Export write exceeded string limit; retrying with tighter bounds...`));
|
|
695
|
+
const tightResult = buildRunExport(root, tightExportOpts);
|
|
696
|
+
if (tightResult.ok) {
|
|
697
|
+
try {
|
|
698
|
+
writeFileSync(exportPath, JSON.stringify(tightResult.export));
|
|
699
|
+
exportWriteOk = true;
|
|
700
|
+
usedExport = tightResult.export;
|
|
701
|
+
} catch (retryErr) {
|
|
702
|
+
log(chalk.dim(` Governance export write failed (tight bounds): ${retryErr.message}`));
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
} else {
|
|
706
|
+
log(chalk.dim(` Governance export write failed: ${exportWriteErr.message}`));
|
|
707
|
+
}
|
|
686
708
|
}
|
|
687
709
|
|
|
688
|
-
// Generate markdown report
|
|
710
|
+
// Generate markdown report from whichever export succeeded
|
|
689
711
|
try {
|
|
690
|
-
const
|
|
712
|
+
const reportInput = exportWriteOk ? exportPath : '(in-memory)';
|
|
713
|
+
const reportResult = buildGovernanceReport(usedExport, { input: reportInput });
|
|
691
714
|
const reportPath = join(reportsDir, `report-${runId}.md`);
|
|
692
715
|
writeFileSync(reportPath, formatGovernanceReportMarkdown(reportResult.report));
|
|
693
716
|
|
|
694
717
|
log('');
|
|
695
718
|
log(chalk.dim(` Governance report: .agentxchain/reports/report-${runId}.md`));
|
|
719
|
+
if (!exportWriteOk) {
|
|
720
|
+
log(chalk.dim(` Note: report generated from in-memory bounded export (disk write failed).`));
|
|
721
|
+
}
|
|
696
722
|
} catch (reportErr) {
|
|
697
723
|
log(chalk.dim(` Governance report failed: ${reportErr.message}`));
|
|
698
724
|
}
|
|
@@ -499,6 +499,7 @@ function renderPrompt(role, roleId, turn, state, config, root) {
|
|
|
499
499
|
lines.push('- `verification.status`: one of `pass`, `fail`, `skipped`');
|
|
500
500
|
lines.push('- `verification.status: "pass"` is valid only when every `verification.machine_evidence[].exit_code` is `0`');
|
|
501
501
|
lines.push('- Expected-failure checks must be wrapped in a verifier that exits `0` when the failure occurs as expected; do not list raw non-zero negative-case commands on a passing turn');
|
|
502
|
+
lines.push('- If verification commands produce side-effect files (e.g., `.tusq/plan.json`, `coverage/`, `.cache/`), declare each in `verification.produced_files` with `disposition: "ignore"` (temporary output to clean up) or `disposition: "artifact"` (output to checkpoint as a turn deliverable). Undeclared dirty files with declared verification will be auto-cleaned but declaring them is preferred.');
|
|
502
503
|
lines.push('- `artifact.type`: one of `workspace`, `patch`, `commit`, `review`');
|
|
503
504
|
lines.push('- If you make zero repo file edits, set `artifact.type` to `"review"` and `files_changed` to `[]`.');
|
|
504
505
|
lines.push('- Only set `artifact.type` to `"workspace"` when you actually modified repo files and listed every changed path in `files_changed`.');
|
|
@@ -106,27 +106,35 @@ function verifyFileEntry(relPath, entry, errors) {
|
|
|
106
106
|
return;
|
|
107
107
|
}
|
|
108
108
|
if (isTruncated) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
109
|
+
// BUG-88: truncated entries may be JSONL (windowed) or text (size-capped)
|
|
110
|
+
if (entry.format === 'jsonl') {
|
|
111
|
+
if (!Array.isArray(entry.data)) {
|
|
112
|
+
addError(errors, path, 'truncated JSONL data must be an array');
|
|
113
|
+
}
|
|
114
|
+
if (!Number.isInteger(entry.total_entries) || entry.total_entries < 0) {
|
|
115
|
+
addError(errors, path, 'total_entries must be a non-negative integer when truncated');
|
|
116
|
+
}
|
|
117
|
+
if (!Number.isInteger(entry.retained_entries) || entry.retained_entries < 0) {
|
|
118
|
+
addError(errors, path, 'retained_entries must be a non-negative integer when truncated');
|
|
119
|
+
}
|
|
120
|
+
if (Array.isArray(entry.data) && entry.retained_entries !== entry.data.length) {
|
|
121
|
+
addError(errors, path, 'retained_entries must match truncated data length');
|
|
122
|
+
}
|
|
123
|
+
if (
|
|
124
|
+
Number.isInteger(entry.total_entries)
|
|
125
|
+
&& Number.isInteger(entry.retained_entries)
|
|
126
|
+
&& entry.retained_entries > entry.total_entries
|
|
127
|
+
) {
|
|
128
|
+
addError(errors, path, 'retained_entries must not exceed total_entries');
|
|
129
|
+
}
|
|
130
|
+
} else if (entry.format === 'text') {
|
|
131
|
+
if (typeof entry.data !== 'string') {
|
|
132
|
+
addError(errors, path, 'truncated text data must be a string');
|
|
133
|
+
}
|
|
134
|
+
} else if (entry.format === 'json') {
|
|
135
|
+
// Truncated JSON: data may be partial or null
|
|
136
|
+
} else {
|
|
137
|
+
addError(errors, path, `truncated file entries must use jsonl, text, or json format, got: ${entry.format}`);
|
|
130
138
|
}
|
|
131
139
|
return;
|
|
132
140
|
}
|
package/src/lib/export.js
CHANGED
|
@@ -182,6 +182,10 @@ function parseFile(root, relPath, opts = {}) {
|
|
|
182
182
|
totalEntries = parsed.totalEntries;
|
|
183
183
|
} else {
|
|
184
184
|
data = buffer.toString('utf8');
|
|
185
|
+
if (opts.maxTextDataBytes && typeof data === 'string' && data.length > opts.maxTextDataBytes) {
|
|
186
|
+
data = data.slice(0, opts.maxTextDataBytes);
|
|
187
|
+
truncated = true;
|
|
188
|
+
}
|
|
185
189
|
}
|
|
186
190
|
|
|
187
191
|
const skipBase64 = truncated || (opts.maxBase64Bytes && buffer.byteLength > opts.maxBase64Bytes);
|
|
@@ -464,9 +468,42 @@ export function buildRunExport(startDir = process.cwd(), exportOpts = {}) {
|
|
|
464
468
|
if (exportOpts.maxBase64Bytes) {
|
|
465
469
|
parseOpts.maxBase64Bytes = exportOpts.maxBase64Bytes;
|
|
466
470
|
}
|
|
471
|
+
if (exportOpts.maxTextDataBytes) {
|
|
472
|
+
parseOpts.maxTextDataBytes = exportOpts.maxTextDataBytes;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// BUG-88: apply maxExportFiles cap with priority ordering.
|
|
476
|
+
// Core governance files first, then dispatch/staging, then .planning/ last.
|
|
477
|
+
let boundedPaths = collectedPaths;
|
|
478
|
+
let exportFilesTruncated = false;
|
|
479
|
+
if (exportOpts.maxExportFiles && collectedPaths.length > exportOpts.maxExportFiles) {
|
|
480
|
+
const corePaths = [];
|
|
481
|
+
const runtimePaths = [];
|
|
482
|
+
const planningPaths = [];
|
|
483
|
+
for (const p of collectedPaths) {
|
|
484
|
+
if (p.startsWith('.planning/')) {
|
|
485
|
+
planningPaths.push(p);
|
|
486
|
+
} else if (p.startsWith('.agentxchain/dispatch/') || p.startsWith('.agentxchain/staging/') || p.startsWith('.agentxchain/transactions/')) {
|
|
487
|
+
runtimePaths.push(p);
|
|
488
|
+
} else {
|
|
489
|
+
corePaths.push(p);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
const budget = exportOpts.maxExportFiles;
|
|
493
|
+
boundedPaths = corePaths.slice(0, budget);
|
|
494
|
+
const remaining = budget - boundedPaths.length;
|
|
495
|
+
if (remaining > 0) {
|
|
496
|
+
boundedPaths.push(...runtimePaths.slice(0, remaining));
|
|
497
|
+
const remaining2 = remaining - Math.min(runtimePaths.length, remaining);
|
|
498
|
+
if (remaining2 > 0) {
|
|
499
|
+
boundedPaths.push(...planningPaths.slice(0, remaining2));
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
exportFilesTruncated = true;
|
|
503
|
+
}
|
|
467
504
|
|
|
468
505
|
const files = {};
|
|
469
|
-
for (const relPath of
|
|
506
|
+
for (const relPath of boundedPaths) {
|
|
470
507
|
files[relPath] = parseFile(root, relPath, parseOpts);
|
|
471
508
|
}
|
|
472
509
|
|
|
@@ -511,6 +548,9 @@ export function buildRunExport(startDir = process.cwd(), exportOpts = {}) {
|
|
|
511
548
|
dashboard_session: buildDashboardSessionSummary(root),
|
|
512
549
|
delegation_summary: buildDelegationSummary(files),
|
|
513
550
|
repo_decisions: buildRepoDecisionsSummary(root, rawConfig),
|
|
551
|
+
export_files_truncated: exportFilesTruncated || false,
|
|
552
|
+
total_collected_files: collectedPaths.length,
|
|
553
|
+
included_files: Object.keys(files).length,
|
|
514
554
|
},
|
|
515
555
|
workspace: buildRunWorkspaceMetadata(root),
|
|
516
556
|
files,
|
|
@@ -4531,39 +4531,97 @@ function _acceptGovernedTurnLocked(root, config, opts) {
|
|
|
4531
4531
|
&& verification.machine_evidence.some((e) => e && typeof e === 'object' && typeof e.command === 'string' && e.command.trim().length > 0);
|
|
4532
4532
|
const verificationWasDeclared = declaredVerificationCommands || declaredMachineEvidence;
|
|
4533
4533
|
|
|
4534
|
-
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4534
|
+
// ── BUG-87: Auto-normalize undeclared verification outputs ──────────
|
|
4535
|
+
// When verification was declared and unexpected dirty files exist,
|
|
4536
|
+
// attempt to clean them up as ignored verification outputs before
|
|
4537
|
+
// hard-erroring. This covers tool-generated side-effect files (e.g.,
|
|
4538
|
+
// .tusq/plan.json, coverage/) that the agent failed to declare in
|
|
4539
|
+
// verification.produced_files. cleanupIgnoredVerificationFiles already
|
|
4540
|
+
// respects the dispatch baseline: only files NOT dirty at dispatch
|
|
4541
|
+
// time are cleaned; pre-existing dirty files are left untouched.
|
|
4542
|
+
if (verificationWasDeclared && Array.isArray(dirtyParity.unexpected_dirty_files) && dirtyParity.unexpected_dirty_files.length > 0) {
|
|
4543
|
+
const autoClassifyAttempt = cleanupIgnoredVerificationFiles({
|
|
4544
|
+
root,
|
|
4545
|
+
baseline,
|
|
4546
|
+
ignoredFiles: dirtyParity.unexpected_dirty_files,
|
|
4547
|
+
});
|
|
4548
|
+
if (autoClassifyAttempt.ok) {
|
|
4549
|
+
// Re-check dirty parity after cleanup
|
|
4550
|
+
const recheckParity = detectDirtyFilesOutsideAllowed(
|
|
4551
|
+
root,
|
|
4552
|
+
writeAuthority,
|
|
4553
|
+
[
|
|
4554
|
+
...(turnResult.files_changed || []),
|
|
4555
|
+
...concurrentAllowedDirtyFiles,
|
|
4556
|
+
...uncheckpointedPriorFiles,
|
|
4557
|
+
],
|
|
4558
|
+
);
|
|
4559
|
+
if (recheckParity.clean) {
|
|
4560
|
+
const autoClassifiedFiles = dirtyParity.unexpected_dirty_files;
|
|
4561
|
+
// Auto-normalization succeeded — emit audit event and continue
|
|
4562
|
+
emitRunEvent(root, 'verification_output_auto_normalized', {
|
|
4563
|
+
run_id: state.run_id,
|
|
4564
|
+
phase: state.phase,
|
|
4565
|
+
status: state.status,
|
|
4566
|
+
turn: { turn_id: currentTurn.turn_id, role_id: currentTurn.assigned_role },
|
|
4567
|
+
intent_id: currentTurn.intake_context?.intent_id || null,
|
|
4568
|
+
payload: {
|
|
4569
|
+
auto_classified_files: autoClassifiedFiles,
|
|
4570
|
+
restored_files: autoClassifyAttempt.restored_files || [],
|
|
4571
|
+
disposition: 'ignore',
|
|
4572
|
+
rationale: 'undeclared_verification_output_auto_normalized',
|
|
4573
|
+
},
|
|
4574
|
+
});
|
|
4575
|
+
// Remove auto-classified files from the observation so
|
|
4576
|
+
// compareDeclaredVsObserved does not re-flag them as undeclared.
|
|
4577
|
+
const autoSet = new Set(autoClassifiedFiles);
|
|
4578
|
+
if (Array.isArray(observation.files_changed)) {
|
|
4579
|
+
observation.files_changed = observation.files_changed.filter(
|
|
4580
|
+
(f) => !autoSet.has(f),
|
|
4581
|
+
);
|
|
4582
|
+
}
|
|
4583
|
+
// Fall through to the rest of acceptance (skip the error block)
|
|
4584
|
+
dirtyParity.clean = true;
|
|
4585
|
+
}
|
|
4586
|
+
}
|
|
4544
4587
|
}
|
|
4588
|
+
// ── End BUG-87 ──────────────────────────────────────────────────────
|
|
4589
|
+
|
|
4590
|
+
if (!dirtyParity.clean) {
|
|
4591
|
+
let failureReason = dirtyParity.reason;
|
|
4592
|
+
let failureErrorCode = 'artifact_dirty_tree_mismatch';
|
|
4593
|
+
if (verificationWasDeclared) {
|
|
4594
|
+
failureErrorCode = 'undeclared_verification_outputs';
|
|
4595
|
+
const undeclared = Array.isArray(dirtyParity.unexpected_dirty_files)
|
|
4596
|
+
? dirtyParity.unexpected_dirty_files
|
|
4597
|
+
: [];
|
|
4598
|
+
const listForMessage = undeclared.slice(0, 5).join(', ')
|
|
4599
|
+
+ (undeclared.length > 5 ? '...' : '');
|
|
4600
|
+
failureReason = `Verification was declared (commands or machine_evidence), but these files are dirty and not classified: ${listForMessage}. Classify each under verification.produced_files with disposition "ignore" (the file should be cleaned up after replay) or "artifact" (the file should be checkpointed as part of the turn), OR add it to files_changed if it is a core turn mutation. Acceptance cannot proceed until the declared contract matches the working tree.`;
|
|
4601
|
+
}
|
|
4545
4602
|
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
stage: 'artifact_observation',
|
|
4549
|
-
extra: {
|
|
4550
|
-
unexpected_dirty_files: dirtyParity.unexpected_dirty_files,
|
|
4551
|
-
dirty_files: dirtyParity.dirty_files,
|
|
4552
|
-
},
|
|
4553
|
-
});
|
|
4554
|
-
return {
|
|
4555
|
-
ok: false,
|
|
4556
|
-
error: failureReason,
|
|
4557
|
-
error_code: failureErrorCode,
|
|
4558
|
-
validation: {
|
|
4559
|
-
...validation,
|
|
4560
|
-
ok: false,
|
|
4603
|
+
transitionToFailedAcceptance(root, state, currentTurn, failureReason, {
|
|
4604
|
+
error_code: failureErrorCode,
|
|
4561
4605
|
stage: 'artifact_observation',
|
|
4562
|
-
|
|
4563
|
-
|
|
4564
|
-
|
|
4565
|
-
|
|
4566
|
-
|
|
4606
|
+
extra: {
|
|
4607
|
+
unexpected_dirty_files: dirtyParity.unexpected_dirty_files,
|
|
4608
|
+
dirty_files: dirtyParity.dirty_files,
|
|
4609
|
+
},
|
|
4610
|
+
});
|
|
4611
|
+
return {
|
|
4612
|
+
ok: false,
|
|
4613
|
+
error: failureReason,
|
|
4614
|
+
error_code: failureErrorCode,
|
|
4615
|
+
validation: {
|
|
4616
|
+
...validation,
|
|
4617
|
+
ok: false,
|
|
4618
|
+
stage: 'artifact_observation',
|
|
4619
|
+
error_class: 'artifact_error',
|
|
4620
|
+
errors: [failureReason],
|
|
4621
|
+
warnings: validation.warnings,
|
|
4622
|
+
},
|
|
4623
|
+
};
|
|
4624
|
+
}
|
|
4567
4625
|
}
|
|
4568
4626
|
|
|
4569
4627
|
const diffComparison = compareDeclaredVsObserved(
|