@engineeros/connector 0.15.0 → 0.15.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.
@@ -13,6 +13,7 @@ import {
13
13
  } from "../src/config.mjs";
14
14
  import {
15
15
  ASSESSMENT_RESULT_TIMEOUT_MS,
16
+ attachAssessmentRejectionCorrection,
16
17
  assessmentWorkerSnapshots,
17
18
  assessmentInactivityFailure,
18
19
  assessmentProgressMessage,
@@ -735,6 +736,41 @@ async function executeAssessment(assignment, assessmentState) {
735
736
  stage,
736
737
  );
737
738
  if (result) {
739
+ attachAssessmentRejectionCorrection(
740
+ result,
741
+ preparedAssignment,
742
+ config,
743
+ {
744
+ onController: (controller) => {
745
+ if (isActiveAssessment()) assessmentState.controller = controller;
746
+ },
747
+ onProcess: (child) => {
748
+ if (isActiveAssessment()) {
749
+ assessmentState.child = child;
750
+ agentProcessStarted = true;
751
+ assessmentState.phase = "correcting";
752
+ assessmentState.lastActivityAt = Date.now();
753
+ }
754
+ },
755
+ onEvent: (event) => {
756
+ assessmentState.lastActivityAt = Date.now();
757
+ assessmentState.eventCount += 1;
758
+ const message = assessmentProgressMessage(event);
759
+ if (message) reportProgress(message);
760
+ },
761
+ },
762
+ {
763
+ draftPath: path
764
+ .join(
765
+ ".engineeros",
766
+ "assessments",
767
+ String(assessmentId),
768
+ result.report_file,
769
+ )
770
+ .split(path.sep)
771
+ .join("/"),
772
+ },
773
+ );
738
774
  reportProgress("Recovered completed stage report from connector storage");
739
775
  } else {
740
776
  result = await executeWorkspaceAssessment(preparedAssignment, config, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@engineeros/connector",
3
- "version": "0.15.0",
3
+ "version": "0.15.1",
4
4
  "description": "Connect a local coding agent to EngineerOS, using ACP when supported.",
5
5
  "private": false,
6
6
  "type": "module",
@@ -43,6 +43,7 @@ export async function persistAssessmentStageResult(
43
43
  change_impact_markdown: result.change_impact_markdown ?? null,
44
44
  model: result.model ?? null,
45
45
  usage: result.usage ?? null,
46
+ agent_session_id: result.agent_session_id ?? null,
46
47
  };
47
48
  await atomicWrite(path.join(directory, reportName), `${report}\n`);
48
49
  await atomicWrite(
package/src/runner.mjs CHANGED
@@ -462,39 +462,101 @@ export async function executeWorkspaceAssessment(
462
462
  change_impact_markdown: changeImpact.markdown,
463
463
  model: turn.model ?? config.agent_protocol ?? "coding-agent",
464
464
  usage: turn.usage ?? null,
465
+ agent_session_id: turn.sessionId ?? null,
465
466
  };
466
467
  };
467
468
  const result = await buildResult(completed, recovered.report);
468
469
  if (!recovered.correctionUsed) {
469
- Object.defineProperty(result, "correctAfterRejection", {
470
- enumerable: false,
471
- value: async (validationMessage) => {
472
- callbacks.onEvent?.({
473
- type: "assessment.output_correction",
474
- message: "The Agent is correcting the rejected stage report",
475
- });
476
- const correction = launchAssessmentAgent(
477
- assessmentRejectionCorrectionPrompt(
478
- validationMessage,
479
- execution.requiredOutputHeading,
480
- ),
481
- completed.sessionId,
482
- );
483
- const corrected = await correction.completed;
484
- const correctedReport = normalizeAgentStructuredOutput(
485
- corrected.finalMessage,
486
- execution.requiredOutputHeading,
487
- );
470
+ attachAssessmentRejectionCorrection(result, assignment, config, callbacks, {
471
+ previousSessionId: completed.sessionId,
472
+ buildResult,
473
+ });
474
+ }
475
+ return result;
476
+ }
477
+
478
+ export function attachAssessmentRejectionCorrection(
479
+ result,
480
+ assignment,
481
+ config,
482
+ callbacks,
483
+ { previousSessionId = result.agent_session_id, draftPath, buildResult } = {},
484
+ ) {
485
+ const execution = workspaceAssessmentExecution(assignment);
486
+ const assessmentAcpContext =
487
+ config.agent_protocol === "acp"
488
+ ? {
489
+ persistentAcp: true,
490
+ sessionKey: `assessment:${assignment.assessment_id}:${assignment.stage}`,
491
+ }
492
+ : undefined;
493
+ Object.defineProperty(result, "correctAfterRejection", {
494
+ enumerable: false,
495
+ value: async (validationMessage) => {
496
+ callbacks.onEvent?.({
497
+ type: "assessment.output_correction",
498
+ message: "The Agent is correcting the rejected stage report",
499
+ });
500
+ const draftInstruction = draftPath
501
+ ? [
502
+ "",
503
+ `The authoritative draft is stored at \`${draftPath}\`. Read that file before making the requested correction.`,
504
+ ].join("\n")
505
+ : "";
506
+ const controller = launchAgentProcess(
507
+ config.workspace,
508
+ `${assessmentRejectionCorrectionPrompt(validationMessage, execution.requiredOutputHeading)}${draftInstruction}`,
509
+ execution.sandboxMode,
510
+ config,
511
+ callbacks,
512
+ execution.profile,
513
+ previousSessionId,
514
+ assessmentAcpContext,
515
+ );
516
+ callbacks.onController?.(controller);
517
+ callbacks.onProcess?.(controller.child);
518
+ const corrected = await controller.completed;
519
+ const correctedReport = normalizeAgentStructuredOutput(
520
+ corrected.finalMessage,
521
+ execution.requiredOutputHeading,
522
+ );
523
+ if (buildResult) {
488
524
  return buildResult(
489
525
  {
490
526
  ...corrected,
491
- usage: mergeTokenUsage(completed.usage, corrected.usage),
527
+ usage: mergeTokenUsage(result.usage, corrected.usage),
492
528
  },
493
529
  correctedReport,
494
530
  );
495
- },
496
- });
497
- }
531
+ }
532
+ const endingRevision = await run(
533
+ "git",
534
+ ["rev-parse", "HEAD"],
535
+ config.workspace,
536
+ { allowFailure: true },
537
+ );
538
+ const endingHead =
539
+ endingRevision.code === 0
540
+ ? endingRevision.stdout.trim().slice(0, 128)
541
+ : null;
542
+ if (
543
+ assignment.target_head_revision &&
544
+ endingHead !== assignment.target_head_revision
545
+ ) {
546
+ throw new Error(
547
+ "The Git commit changed before assessment correction. Refresh the workspace inventory and assess the new commit.",
548
+ );
549
+ }
550
+ return {
551
+ ...result,
552
+ report_markdown: correctedReport,
553
+ observed_head_revision: endingHead,
554
+ model: corrected.model ?? result.model,
555
+ usage: mergeTokenUsage(result.usage, corrected.usage),
556
+ agent_session_id: corrected.sessionId ?? previousSessionId ?? null,
557
+ };
558
+ },
559
+ });
498
560
  return result;
499
561
  }
500
562