@adhdev/daemon-standalone 0.9.82-rc.36 → 0.9.82-rc.37
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/index.js +192 -18
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -46541,12 +46541,89 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
46541
46541
|
var REFINE_VALIDATION_OUTPUT_LIMIT_BYTES = 128 * 1024;
|
|
46542
46542
|
var REFINE_VALIDATION_SUMMARY_CHARS = 2e3;
|
|
46543
46543
|
var REFINE_VALIDATION_MAX_COMMANDS = 4;
|
|
46544
|
+
var REFINE_PATCH_EQUIVALENCE_OUTPUT_LIMIT_BYTES = 4 * 1024 * 1024;
|
|
46544
46545
|
function truncateValidationOutput(value) {
|
|
46545
46546
|
const text = typeof value === "string" ? value : value == null ? "" : String(value);
|
|
46546
46547
|
if (text.length <= REFINE_VALIDATION_SUMMARY_CHARS) return text;
|
|
46547
46548
|
return `${text.slice(0, REFINE_VALIDATION_SUMMARY_CHARS)}
|
|
46548
46549
|
[truncated ${text.length - REFINE_VALIDATION_SUMMARY_CHARS} chars]`;
|
|
46549
46550
|
}
|
|
46551
|
+
function recordMeshRefineStage(stages, stage, status, startedAt, details) {
|
|
46552
|
+
stages.push({
|
|
46553
|
+
stage,
|
|
46554
|
+
status,
|
|
46555
|
+
durationMs: Date.now() - startedAt,
|
|
46556
|
+
...details || {}
|
|
46557
|
+
});
|
|
46558
|
+
}
|
|
46559
|
+
async function computeGitPatchId(cwd, fromRef, toRef) {
|
|
46560
|
+
const { execFileSync: execFileSync4 } = await import("child_process");
|
|
46561
|
+
const diff = execFileSync4("git", ["diff", "--patch", "--full-index", fromRef, toRef], {
|
|
46562
|
+
cwd,
|
|
46563
|
+
encoding: "utf8",
|
|
46564
|
+
maxBuffer: REFINE_PATCH_EQUIVALENCE_OUTPUT_LIMIT_BYTES
|
|
46565
|
+
});
|
|
46566
|
+
if (!diff.trim()) return "";
|
|
46567
|
+
const patchId = execFileSync4("git", ["patch-id", "--stable"], {
|
|
46568
|
+
cwd,
|
|
46569
|
+
input: diff,
|
|
46570
|
+
encoding: "utf8",
|
|
46571
|
+
maxBuffer: REFINE_PATCH_EQUIVALENCE_OUTPUT_LIMIT_BYTES
|
|
46572
|
+
}).trim();
|
|
46573
|
+
return patchId.split(/\s+/)[0] || "";
|
|
46574
|
+
}
|
|
46575
|
+
async function runMeshRefinePatchEquivalenceGate(repoRoot, baseHead, branchHead) {
|
|
46576
|
+
const startedAt = Date.now();
|
|
46577
|
+
try {
|
|
46578
|
+
const { execFileSync: execFileSync4 } = await import("child_process");
|
|
46579
|
+
const git = (args) => execFileSync4("git", args, {
|
|
46580
|
+
cwd: repoRoot,
|
|
46581
|
+
encoding: "utf8",
|
|
46582
|
+
maxBuffer: REFINE_PATCH_EQUIVALENCE_OUTPUT_LIMIT_BYTES
|
|
46583
|
+
});
|
|
46584
|
+
const mergeBase = git(["merge-base", baseHead, branchHead]).trim();
|
|
46585
|
+
const mergeTreeStdout = git(["merge-tree", "--write-tree", baseHead, branchHead]);
|
|
46586
|
+
const mergedTree = mergeTreeStdout.trim().split(/\s+/)[0] || "";
|
|
46587
|
+
if (!mergeBase || !mergedTree) {
|
|
46588
|
+
return {
|
|
46589
|
+
status: "failed",
|
|
46590
|
+
equivalent: false,
|
|
46591
|
+
baseHead,
|
|
46592
|
+
branchHead,
|
|
46593
|
+
mergeBase: mergeBase || void 0,
|
|
46594
|
+
mergedTree: mergedTree || void 0,
|
|
46595
|
+
durationMs: Date.now() - startedAt,
|
|
46596
|
+
error: "patch equivalence preflight could not resolve merge-base or synthetic merge tree",
|
|
46597
|
+
stdout: truncateValidationOutput(mergeTreeStdout)
|
|
46598
|
+
};
|
|
46599
|
+
}
|
|
46600
|
+
const expectedPatchId = await computeGitPatchId(repoRoot, mergeBase, branchHead);
|
|
46601
|
+
const actualPatchId = await computeGitPatchId(repoRoot, baseHead, mergedTree);
|
|
46602
|
+
const equivalent = expectedPatchId === actualPatchId;
|
|
46603
|
+
return {
|
|
46604
|
+
status: equivalent ? "passed" : "failed",
|
|
46605
|
+
equivalent,
|
|
46606
|
+
baseHead,
|
|
46607
|
+
branchHead,
|
|
46608
|
+
mergeBase,
|
|
46609
|
+
mergedTree,
|
|
46610
|
+
expectedPatchId,
|
|
46611
|
+
actualPatchId,
|
|
46612
|
+
durationMs: Date.now() - startedAt
|
|
46613
|
+
};
|
|
46614
|
+
} catch (e) {
|
|
46615
|
+
return {
|
|
46616
|
+
status: "failed",
|
|
46617
|
+
equivalent: false,
|
|
46618
|
+
baseHead,
|
|
46619
|
+
branchHead,
|
|
46620
|
+
durationMs: Date.now() - startedAt,
|
|
46621
|
+
error: e?.message || String(e),
|
|
46622
|
+
stdout: truncateValidationOutput(e?.stdout),
|
|
46623
|
+
stderr: truncateValidationOutput(e?.stderr)
|
|
46624
|
+
};
|
|
46625
|
+
}
|
|
46626
|
+
}
|
|
46550
46627
|
function readPackageScripts(workspace) {
|
|
46551
46628
|
try {
|
|
46552
46629
|
const packageJsonPath = (0, import_path7.join)(workspace, "package.json");
|
|
@@ -48191,26 +48268,41 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
48191
48268
|
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
48192
48269
|
const nodeId = typeof args?.nodeId === "string" ? args.nodeId.trim() : "";
|
|
48193
48270
|
if (!meshId || !nodeId) return { success: false, error: "meshId and nodeId required" };
|
|
48271
|
+
const refineStages = [];
|
|
48194
48272
|
try {
|
|
48195
48273
|
const meshRecord = await this.getMeshForCommand(meshId, args?.inlineMesh);
|
|
48196
48274
|
const mesh = meshRecord?.mesh;
|
|
48197
48275
|
const node = mesh?.nodes?.find((n) => n.id === nodeId || n.nodeId === nodeId);
|
|
48198
|
-
if (!node) return { success: false, error: `Node '${nodeId}' not found in mesh
|
|
48276
|
+
if (!node) return { success: false, error: `Node '${nodeId}' not found in mesh`, refineStages };
|
|
48199
48277
|
if (!node.isLocalWorktree || !node.workspace) {
|
|
48200
|
-
return { success: false, error: `Refinery requires a local worktree node
|
|
48278
|
+
return { success: false, error: `Refinery requires a local worktree node`, refineStages };
|
|
48201
48279
|
}
|
|
48202
48280
|
const sourceNode = node.clonedFromNodeId ? mesh?.nodes.find((n) => n.id === node.clonedFromNodeId || n.nodeId === node.clonedFromNodeId) : mesh?.nodes.find((n) => !n.isLocalWorktree);
|
|
48203
48281
|
const repoRoot = sourceNode?.repoRoot || sourceNode?.workspace;
|
|
48204
|
-
if (!repoRoot) return { success: false, error: "Source node repoRoot not found" };
|
|
48282
|
+
if (!repoRoot) return { success: false, error: "Source node repoRoot not found", refineStages };
|
|
48205
48283
|
const { execFile: execFile3 } = await import("child_process");
|
|
48206
48284
|
const { promisify: promisify3 } = await import("util");
|
|
48207
48285
|
const execFileAsync3 = promisify3(execFile3);
|
|
48286
|
+
const resolveStarted = Date.now();
|
|
48208
48287
|
const { stdout: branchStdout } = await execFileAsync3("git", ["branch", "--show-current"], { cwd: node.workspace, encoding: "utf8" });
|
|
48209
48288
|
const branch = branchStdout.trim();
|
|
48210
|
-
if (!branch) return { success: false, error: "Could not determine branch of the worktree node" };
|
|
48289
|
+
if (!branch) return { success: false, error: "Could not determine branch of the worktree node", refineStages };
|
|
48211
48290
|
const { stdout: baseBranchStdout } = await execFileAsync3("git", ["branch", "--show-current"], { cwd: repoRoot, encoding: "utf8" });
|
|
48212
48291
|
const baseBranch = baseBranchStdout.trim();
|
|
48292
|
+
const { stdout: baseHeadStdout } = await execFileAsync3("git", ["rev-parse", "HEAD"], { cwd: repoRoot, encoding: "utf8" });
|
|
48293
|
+
const { stdout: branchHeadStdout } = await execFileAsync3("git", ["rev-parse", branch], { cwd: node.workspace, encoding: "utf8" });
|
|
48294
|
+
const baseHead = baseHeadStdout.trim();
|
|
48295
|
+
const branchHead = branchHeadStdout.trim();
|
|
48296
|
+
recordMeshRefineStage(refineStages, "resolve_refs", "passed", resolveStarted, { branch, baseBranch, baseHead, branchHead });
|
|
48297
|
+
const validationStarted = Date.now();
|
|
48213
48298
|
const validationSummary = await runMeshRefineValidationGate(mesh, node.workspace);
|
|
48299
|
+
recordMeshRefineStage(
|
|
48300
|
+
refineStages,
|
|
48301
|
+
"validation",
|
|
48302
|
+
validationSummary.status === "passed" ? "passed" : validationSummary.status === "failed" ? "failed" : "skipped",
|
|
48303
|
+
validationStarted,
|
|
48304
|
+
{ validationStatus: validationSummary.status, commandsRun: validationSummary.commandsRun.length }
|
|
48305
|
+
);
|
|
48214
48306
|
if (validationSummary.status === "failed") {
|
|
48215
48307
|
return {
|
|
48216
48308
|
success: false,
|
|
@@ -48220,6 +48312,7 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
48220
48312
|
branch,
|
|
48221
48313
|
into: baseBranch,
|
|
48222
48314
|
validationSummary,
|
|
48315
|
+
refineStages,
|
|
48223
48316
|
finalBranchConvergenceState: {
|
|
48224
48317
|
branch,
|
|
48225
48318
|
baseBranch,
|
|
@@ -48239,6 +48332,7 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
48239
48332
|
branch,
|
|
48240
48333
|
into: baseBranch,
|
|
48241
48334
|
validationSummary,
|
|
48335
|
+
refineStages,
|
|
48242
48336
|
finalBranchConvergenceState: {
|
|
48243
48337
|
branch,
|
|
48244
48338
|
baseBranch,
|
|
@@ -48249,37 +48343,121 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
48249
48343
|
}
|
|
48250
48344
|
};
|
|
48251
48345
|
}
|
|
48346
|
+
const patchEquivalenceStarted = Date.now();
|
|
48347
|
+
const patchEquivalence = await runMeshRefinePatchEquivalenceGate(repoRoot, baseHead, branchHead);
|
|
48348
|
+
recordMeshRefineStage(refineStages, "patch_equivalence", patchEquivalence.status, patchEquivalenceStarted, {
|
|
48349
|
+
equivalent: patchEquivalence.equivalent,
|
|
48350
|
+
expectedPatchId: patchEquivalence.expectedPatchId,
|
|
48351
|
+
actualPatchId: patchEquivalence.actualPatchId,
|
|
48352
|
+
error: patchEquivalence.error
|
|
48353
|
+
});
|
|
48354
|
+
if (!patchEquivalence.equivalent) {
|
|
48355
|
+
return {
|
|
48356
|
+
success: false,
|
|
48357
|
+
code: "patch_equivalence_failed",
|
|
48358
|
+
convergenceStatus: "blocked_review",
|
|
48359
|
+
error: "Refinery patch-equivalence preflight failed; merge/refine was not attempted.",
|
|
48360
|
+
branch,
|
|
48361
|
+
into: baseBranch,
|
|
48362
|
+
validationSummary,
|
|
48363
|
+
patchEquivalence,
|
|
48364
|
+
refineStages,
|
|
48365
|
+
finalBranchConvergenceState: {
|
|
48366
|
+
branch,
|
|
48367
|
+
baseBranch,
|
|
48368
|
+
merged: false,
|
|
48369
|
+
removed: false,
|
|
48370
|
+
validation: "passed",
|
|
48371
|
+
patchEquivalence: "failed",
|
|
48372
|
+
status: "blocked_review"
|
|
48373
|
+
}
|
|
48374
|
+
};
|
|
48375
|
+
}
|
|
48376
|
+
let mergeResult;
|
|
48377
|
+
const mergeStarted = Date.now();
|
|
48252
48378
|
try {
|
|
48253
|
-
await execFileAsync3("git", ["merge", "--no-ff", branch, "-m", `Auto-merge branch '${branch}' via Refinery`], { cwd: repoRoot, encoding: "utf8" });
|
|
48379
|
+
const result = await execFileAsync3("git", ["merge", "--no-ff", branch, "-m", `Auto-merge branch '${branch}' via Refinery`], { cwd: repoRoot, encoding: "utf8" });
|
|
48380
|
+
mergeResult = {
|
|
48381
|
+
stdout: truncateValidationOutput(result.stdout),
|
|
48382
|
+
stderr: truncateValidationOutput(result.stderr),
|
|
48383
|
+
durationMs: Date.now() - mergeStarted
|
|
48384
|
+
};
|
|
48385
|
+
recordMeshRefineStage(refineStages, "merge", "passed", mergeStarted, mergeResult);
|
|
48254
48386
|
} catch (e) {
|
|
48387
|
+
recordMeshRefineStage(refineStages, "merge", "failed", mergeStarted, {
|
|
48388
|
+
error: e?.message || String(e),
|
|
48389
|
+
stdout: truncateValidationOutput(e?.stdout),
|
|
48390
|
+
stderr: truncateValidationOutput(e?.stderr)
|
|
48391
|
+
});
|
|
48255
48392
|
return {
|
|
48256
48393
|
success: false,
|
|
48257
48394
|
error: `Merge failed (conflicts?): ${e.message}`,
|
|
48258
48395
|
validationSummary,
|
|
48396
|
+
patchEquivalence,
|
|
48397
|
+
refineStages,
|
|
48259
48398
|
finalBranchConvergenceState: {
|
|
48260
48399
|
branch,
|
|
48261
48400
|
baseBranch,
|
|
48262
48401
|
merged: false,
|
|
48263
48402
|
removed: false,
|
|
48264
48403
|
validation: "passed",
|
|
48404
|
+
patchEquivalence: "passed",
|
|
48265
48405
|
status: "not_mergeable"
|
|
48266
48406
|
}
|
|
48267
48407
|
};
|
|
48268
48408
|
}
|
|
48409
|
+
const cleanupStarted = Date.now();
|
|
48269
48410
|
const removeResult = await this.execute("remove_mesh_node", {
|
|
48270
48411
|
meshId,
|
|
48271
48412
|
nodeId,
|
|
48272
|
-
sessionCleanupMode: "
|
|
48413
|
+
sessionCleanupMode: "preserve",
|
|
48273
48414
|
inlineMesh: args?.inlineMesh
|
|
48274
48415
|
});
|
|
48416
|
+
recordMeshRefineStage(refineStages, "cleanup", removeResult?.success === false ? "failed" : "passed", cleanupStarted, {
|
|
48417
|
+
removed: removeResult?.removed,
|
|
48418
|
+
code: removeResult?.code,
|
|
48419
|
+
error: removeResult?.error
|
|
48420
|
+
});
|
|
48421
|
+
let ledgerError;
|
|
48422
|
+
const ledgerStarted = Date.now();
|
|
48275
48423
|
try {
|
|
48276
48424
|
const { appendLedgerEntry: appendLedgerEntry2 } = await Promise.resolve().then(() => (init_mesh_ledger(), mesh_ledger_exports));
|
|
48277
48425
|
appendLedgerEntry2(meshId, {
|
|
48278
48426
|
kind: "node_removed",
|
|
48279
48427
|
nodeId,
|
|
48280
|
-
payload: { refined: true, mergedBranch: branch, into: baseBranch, validationSummary }
|
|
48428
|
+
payload: { refined: true, mergedBranch: branch, into: baseBranch, validationSummary, patchEquivalence }
|
|
48281
48429
|
});
|
|
48282
|
-
|
|
48430
|
+
recordMeshRefineStage(refineStages, "ledger", "passed", ledgerStarted);
|
|
48431
|
+
} catch (e) {
|
|
48432
|
+
ledgerError = e?.message || String(e);
|
|
48433
|
+
recordMeshRefineStage(refineStages, "ledger", "failed", ledgerStarted, { error: ledgerError });
|
|
48434
|
+
}
|
|
48435
|
+
const finalBranchConvergenceState = {
|
|
48436
|
+
branch: baseBranch,
|
|
48437
|
+
mergedBranch: branch,
|
|
48438
|
+
baseBranch,
|
|
48439
|
+
merged: true,
|
|
48440
|
+
removed: removeResult?.success !== false,
|
|
48441
|
+
validation: "passed",
|
|
48442
|
+
patchEquivalence: "passed",
|
|
48443
|
+
status: removeResult?.success === false ? "merged_cleanup_failed" : "merged"
|
|
48444
|
+
};
|
|
48445
|
+
if (removeResult?.success === false) {
|
|
48446
|
+
return {
|
|
48447
|
+
success: false,
|
|
48448
|
+
code: "cleanup_failed",
|
|
48449
|
+
error: "Refinery merge completed but worktree cleanup failed; manual cleanup/retry is required.",
|
|
48450
|
+
merged: true,
|
|
48451
|
+
branch,
|
|
48452
|
+
into: baseBranch,
|
|
48453
|
+
removeResult,
|
|
48454
|
+
validationSummary,
|
|
48455
|
+
patchEquivalence,
|
|
48456
|
+
mergeResult,
|
|
48457
|
+
refineStages,
|
|
48458
|
+
...ledgerError ? { ledgerError } : {},
|
|
48459
|
+
finalBranchConvergenceState
|
|
48460
|
+
};
|
|
48283
48461
|
}
|
|
48284
48462
|
return {
|
|
48285
48463
|
success: true,
|
|
@@ -48288,18 +48466,14 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
48288
48466
|
into: baseBranch,
|
|
48289
48467
|
removeResult,
|
|
48290
48468
|
validationSummary,
|
|
48291
|
-
|
|
48292
|
-
|
|
48293
|
-
|
|
48294
|
-
|
|
48295
|
-
|
|
48296
|
-
removed: removeResult?.success !== false,
|
|
48297
|
-
validation: "passed",
|
|
48298
|
-
status: removeResult?.success === false ? "merged_cleanup_failed" : "merged"
|
|
48299
|
-
}
|
|
48469
|
+
patchEquivalence,
|
|
48470
|
+
mergeResult,
|
|
48471
|
+
refineStages,
|
|
48472
|
+
...ledgerError ? { ledgerError } : {},
|
|
48473
|
+
finalBranchConvergenceState
|
|
48300
48474
|
};
|
|
48301
48475
|
} catch (e) {
|
|
48302
|
-
return { success: false, error: e.message };
|
|
48476
|
+
return { success: false, error: e.message, refineStages };
|
|
48303
48477
|
}
|
|
48304
48478
|
}
|
|
48305
48479
|
case "remove_mesh_node": {
|