@adhdev/daemon-standalone 0.9.82-rc.369 → 0.9.82-rc.370
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 +98 -547
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/public/assets/index-DZWOjMlg.js +113 -0
- package/public/index.html +1 -1
- package/vendor/mcp-server/index.js +7 -7
- package/vendor/mcp-server/index.js.map +1 -1
package/dist/index.js
CHANGED
|
@@ -30036,10 +30036,10 @@ var require_dist3 = __commonJS({
|
|
|
30036
30036
|
}
|
|
30037
30037
|
function getDaemonBuildInfo() {
|
|
30038
30038
|
if (cached2) return cached2;
|
|
30039
|
-
const commit = readInjected(true ? "
|
|
30040
|
-
const commitShort = readInjected(true ? "
|
|
30041
|
-
const version2 = readInjected(true ? "0.9.82-rc.
|
|
30042
|
-
const builtAt = readInjected(true ? "2026-06-
|
|
30039
|
+
const commit = readInjected(true ? "84d52e533859a9dd3c3bc8bc11a2541911f7bd0c" : void 0) ?? "unknown";
|
|
30040
|
+
const commitShort = readInjected(true ? "84d52e53" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
|
|
30041
|
+
const version2 = readInjected(true ? "0.9.82-rc.370" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
|
|
30042
|
+
const builtAt = readInjected(true ? "2026-06-24T10:08:19.248Z" : void 0);
|
|
30043
30043
|
cached2 = builtAt ? { commit, commitShort, version: version2, builtAt } : { commit, commitShort, version: version2 };
|
|
30044
30044
|
return cached2;
|
|
30045
30045
|
}
|
|
@@ -43493,54 +43493,8 @@ ${cleanBody}`;
|
|
|
43493
43493
|
function shouldForceInjectMeshEvent(eventName) {
|
|
43494
43494
|
return typeof eventName === "string" && MESH_FORCE_INJECT_EVENTS.has(eventName);
|
|
43495
43495
|
}
|
|
43496
|
-
function
|
|
43497
|
-
const eventSessionId
|
|
43498
|
-
const eventNodeId = readNonEmptyString2(args.nodeId) || readNonEmptyString2(args.metadataEvent.meshNodeId);
|
|
43499
|
-
const traceCtx = {
|
|
43500
|
-
taskId: args.metadataEvent.taskId,
|
|
43501
|
-
sessionId: eventSessionId,
|
|
43502
|
-
nodeId: eventNodeId,
|
|
43503
|
-
meshId: args.meshId,
|
|
43504
|
-
event: args.event
|
|
43505
|
-
};
|
|
43506
|
-
const sourceSession = args.sourceInstanceId ? components.instanceManager.getInstance(args.sourceInstanceId) : void 0;
|
|
43507
|
-
const workerCoordinatorDaemonId = readNonEmptyString2(
|
|
43508
|
-
sourceSession?.getState()?.settings?.meshCoordinatorDaemonId
|
|
43509
|
-
);
|
|
43510
|
-
const workerCoordinatorSessionId = readNonEmptyString2(
|
|
43511
|
-
sourceSession?.getState()?.settings?.meshCoordinatorSessionId
|
|
43512
|
-
) || readNonEmptyString2(args.metadataEvent.meshCoordinatorSessionId);
|
|
43513
|
-
const enrichedMetadataEvent = (() => {
|
|
43514
|
-
const last = sourceSession ? getLastDisplayMessage(sourceSession.getState()) : null;
|
|
43515
|
-
if (!last || !last.preview) return args.metadataEvent;
|
|
43516
|
-
return {
|
|
43517
|
-
...args.metadataEvent,
|
|
43518
|
-
lastMessagePreview: last.preview,
|
|
43519
|
-
lastMessageRole: last.role,
|
|
43520
|
-
...last.receivedAt > 0 ? { lastMessageAt: last.receivedAt } : {}
|
|
43521
|
-
};
|
|
43522
|
-
})();
|
|
43523
|
-
if (components.onMeshCoordinatorEventForwarded) {
|
|
43524
|
-
try {
|
|
43525
|
-
const surfacedPreview = resolveMeshSurfacedSessionPreview(enrichedMetadataEvent);
|
|
43526
|
-
components.onMeshCoordinatorEventForwarded({
|
|
43527
|
-
event: args.event,
|
|
43528
|
-
meshId: args.meshId,
|
|
43529
|
-
nodeId: eventNodeId || void 0,
|
|
43530
|
-
...enrichedMetadataEvent,
|
|
43531
|
-
// Ensure a `workspace` field reaches updateMeshOwnedSession even when the
|
|
43532
|
-
// worker provider event only carried `workspaceName`. The merge spread of
|
|
43533
|
-
// metadataEvent above wins when it already has a non-empty `workspace`.
|
|
43534
|
-
workspace: readNonEmptyString2(args.metadataEvent.workspace) || readNonEmptyString2(args.metadataEvent.workspaceName) || void 0,
|
|
43535
|
-
...surfacedPreview ? {
|
|
43536
|
-
meshSessionLastMessagePreview: surfacedPreview.preview,
|
|
43537
|
-
meshSessionLastMessageRole: surfacedPreview.role,
|
|
43538
|
-
meshSessionLastMessageAt: surfacedPreview.receivedAt || void 0
|
|
43539
|
-
} : {}
|
|
43540
|
-
});
|
|
43541
|
-
} catch {
|
|
43542
|
-
}
|
|
43543
|
-
}
|
|
43496
|
+
function evaluateMeshEventSuppression(args, ctx) {
|
|
43497
|
+
const { traceCtx, eventSessionId, eventNodeId, eventTimestamp, workerCoordinatorDaemonId } = ctx;
|
|
43544
43498
|
const intentionalCleanupStop = shouldSuppressIntentionalCleanupStop({
|
|
43545
43499
|
event: args.event,
|
|
43546
43500
|
meshId: args.meshId,
|
|
@@ -43557,7 +43511,7 @@ ${cleanBody}`;
|
|
|
43557
43511
|
}
|
|
43558
43512
|
LOG2.info("MeshEvents", `Suppressed ${args.event} for intentionally cleanup-stopped session ${eventSessionId || "(unknown session)"}`);
|
|
43559
43513
|
traceMeshEventDrop("intentional_cleanup_stop", traceCtx);
|
|
43560
|
-
return { success: true, forwarded: 0, suppressed: true, intentionalCleanupStop: true };
|
|
43514
|
+
return { kind: "suppress", result: { success: true, forwarded: 0, suppressed: true, intentionalCleanupStop: true } };
|
|
43561
43515
|
}
|
|
43562
43516
|
if (args.event === "monitor:no_progress") {
|
|
43563
43517
|
const reconciledCompletion = buildNoProgressCompletionReconciliation({
|
|
@@ -43569,30 +43523,28 @@ ${cleanBody}`;
|
|
|
43569
43523
|
});
|
|
43570
43524
|
if (reconciledCompletion?.source === "no_progress_reconciliation") {
|
|
43571
43525
|
LOG2.info("MeshEvents", `Reconciled no-progress monitor to completion for session ${eventSessionId || "(unknown session)"}`);
|
|
43572
|
-
return
|
|
43573
|
-
...args,
|
|
43574
|
-
event: "agent:generating_completed",
|
|
43575
|
-
metadataEvent: reconciledCompletion
|
|
43576
|
-
});
|
|
43526
|
+
return { kind: "reconcile", metadataEvent: reconciledCompletion };
|
|
43577
43527
|
}
|
|
43578
43528
|
if (reconciledCompletion?.source === "no_progress_terminal_ledger_suppression") {
|
|
43579
43529
|
LOG2.info("MeshEvents", `Suppressed no-progress monitor because terminal ledger evidence already exists for session ${eventSessionId || "(unknown session)"}`);
|
|
43580
43530
|
traceMeshEventDrop("no_progress_terminal_ledger_suppression", traceCtx, `terminalKind=${reconciledCompletion.terminalLedgerKind}`);
|
|
43581
43531
|
return {
|
|
43582
|
-
|
|
43583
|
-
|
|
43584
|
-
|
|
43585
|
-
|
|
43586
|
-
|
|
43532
|
+
kind: "suppress",
|
|
43533
|
+
result: {
|
|
43534
|
+
success: true,
|
|
43535
|
+
forwarded: 0,
|
|
43536
|
+
suppressed: true,
|
|
43537
|
+
terminalLedgerEvidence: true,
|
|
43538
|
+
terminalLedgerKind: reconciledCompletion.terminalLedgerKind
|
|
43539
|
+
}
|
|
43587
43540
|
};
|
|
43588
43541
|
}
|
|
43589
43542
|
}
|
|
43590
43543
|
if (isDuplicateRefineTerminalEvent(args.meshId, args.event, args.metadataEvent)) {
|
|
43591
43544
|
LOG2.info("MeshEvents", `Suppressed duplicate ${args.event} for refine job ${readRefineJobId({ metadataEvent: args.metadataEvent })}`);
|
|
43592
43545
|
traceMeshEventDrop("duplicate_refine_terminal", traceCtx);
|
|
43593
|
-
return { success: true, forwarded: 0, suppressed: true, duplicateRefineTerminalEvent: true };
|
|
43546
|
+
return { kind: "suppress", result: { success: true, forwarded: 0, suppressed: true, duplicateRefineTerminalEvent: true } };
|
|
43594
43547
|
}
|
|
43595
|
-
const eventTimestamp = readEventTimestamp(args.metadataEvent.timestamp);
|
|
43596
43548
|
if (args.event === "agent:waiting_approval" && eventSessionId) {
|
|
43597
43549
|
const duplicateApproval = isDuplicateMeshApprovalEvent({
|
|
43598
43550
|
meshId: args.meshId,
|
|
@@ -43605,7 +43557,7 @@ ${cleanBody}`;
|
|
|
43605
43557
|
if (duplicateApproval) {
|
|
43606
43558
|
LOG2.info("MeshEvents", `Suppressed duplicate approval event for mesh ${args.meshId} session ${eventSessionId}`);
|
|
43607
43559
|
traceMeshEventDrop("duplicate_approval", traceCtx);
|
|
43608
|
-
return { success: true, forwarded: 0, suppressed: true, duplicateApproval: true };
|
|
43560
|
+
return { kind: "suppress", result: { success: true, forwarded: 0, suppressed: true, duplicateApproval: true } };
|
|
43609
43561
|
}
|
|
43610
43562
|
}
|
|
43611
43563
|
if (args.event === "agent:generating_completed" && eventSessionId) {
|
|
@@ -43628,7 +43580,7 @@ ${cleanBody}`;
|
|
|
43628
43580
|
if (terminalProviderSessionId && terminalProviderSessionId === eventProviderSessionId || terminalFinalSummary && terminalFinalSummary === eventFinalSummary || args.metadataEvent.source === "no_progress_reconciliation") {
|
|
43629
43581
|
LOG2.info("MeshEvents", `Suppressed duplicate completion with existing terminal ledger evidence for mesh ${args.meshId} session ${eventSessionId}`);
|
|
43630
43582
|
traceMeshEventDrop("duplicate_completion_terminal_ledger", traceCtx);
|
|
43631
|
-
return { success: true, forwarded: 0, suppressed: true, duplicateCompletion: true, terminalLedgerEvidence: true };
|
|
43583
|
+
return { kind: "suppress", result: { success: true, forwarded: 0, suppressed: true, duplicateCompletion: true, terminalLedgerEvidence: true } };
|
|
43632
43584
|
}
|
|
43633
43585
|
}
|
|
43634
43586
|
}
|
|
@@ -43647,7 +43599,7 @@ ${cleanBody}`;
|
|
|
43647
43599
|
if (duplicateCompletion) {
|
|
43648
43600
|
LOG2.info("MeshEvents", `Suppressed duplicate completion for mesh ${args.meshId} session ${eventSessionId}`);
|
|
43649
43601
|
traceMeshEventDrop("duplicate_completion", traceCtx);
|
|
43650
|
-
return { success: true, forwarded: 0, suppressed: true, duplicateCompletion: true };
|
|
43602
|
+
return { kind: "suppress", result: { success: true, forwarded: 0, suppressed: true, duplicateCompletion: true } };
|
|
43651
43603
|
}
|
|
43652
43604
|
}
|
|
43653
43605
|
if (args.event === "agent:stopped" && eventSessionId) {
|
|
@@ -43666,8 +43618,76 @@ ${cleanBody}`;
|
|
|
43666
43618
|
if (duplicateStopped) {
|
|
43667
43619
|
LOG2.info("MeshEvents", `Suppressed duplicate stopped event for mesh ${args.meshId} session ${eventSessionId}`);
|
|
43668
43620
|
traceMeshEventDrop("duplicate_stopped", traceCtx);
|
|
43669
|
-
return { success: true, forwarded: 0, suppressed: true, duplicateStopped: true };
|
|
43621
|
+
return { kind: "suppress", result: { success: true, forwarded: 0, suppressed: true, duplicateStopped: true } };
|
|
43622
|
+
}
|
|
43623
|
+
}
|
|
43624
|
+
return null;
|
|
43625
|
+
}
|
|
43626
|
+
function injectMeshSystemMessage(components, args) {
|
|
43627
|
+
const eventSessionId = resolveEventSessionId(args.metadataEvent, args.sourceInstanceId);
|
|
43628
|
+
const eventNodeId = readNonEmptyString2(args.nodeId) || readNonEmptyString2(args.metadataEvent.meshNodeId);
|
|
43629
|
+
const traceCtx = {
|
|
43630
|
+
taskId: args.metadataEvent.taskId,
|
|
43631
|
+
sessionId: eventSessionId,
|
|
43632
|
+
nodeId: eventNodeId,
|
|
43633
|
+
meshId: args.meshId,
|
|
43634
|
+
event: args.event
|
|
43635
|
+
};
|
|
43636
|
+
const sourceSession = args.sourceInstanceId ? components.instanceManager.getInstance(args.sourceInstanceId) : void 0;
|
|
43637
|
+
const workerCoordinatorDaemonId = readNonEmptyString2(
|
|
43638
|
+
sourceSession?.getState()?.settings?.meshCoordinatorDaemonId
|
|
43639
|
+
);
|
|
43640
|
+
const workerCoordinatorSessionId = readNonEmptyString2(
|
|
43641
|
+
sourceSession?.getState()?.settings?.meshCoordinatorSessionId
|
|
43642
|
+
) || readNonEmptyString2(args.metadataEvent.meshCoordinatorSessionId);
|
|
43643
|
+
const enrichedMetadataEvent = (() => {
|
|
43644
|
+
const last = sourceSession ? getLastDisplayMessage(sourceSession.getState()) : null;
|
|
43645
|
+
if (!last || !last.preview) return args.metadataEvent;
|
|
43646
|
+
return {
|
|
43647
|
+
...args.metadataEvent,
|
|
43648
|
+
lastMessagePreview: last.preview,
|
|
43649
|
+
lastMessageRole: last.role,
|
|
43650
|
+
...last.receivedAt > 0 ? { lastMessageAt: last.receivedAt } : {}
|
|
43651
|
+
};
|
|
43652
|
+
})();
|
|
43653
|
+
if (components.onMeshCoordinatorEventForwarded) {
|
|
43654
|
+
try {
|
|
43655
|
+
const surfacedPreview = resolveMeshSurfacedSessionPreview(enrichedMetadataEvent);
|
|
43656
|
+
components.onMeshCoordinatorEventForwarded({
|
|
43657
|
+
event: args.event,
|
|
43658
|
+
meshId: args.meshId,
|
|
43659
|
+
nodeId: eventNodeId || void 0,
|
|
43660
|
+
...enrichedMetadataEvent,
|
|
43661
|
+
// Ensure a `workspace` field reaches updateMeshOwnedSession even when the
|
|
43662
|
+
// worker provider event only carried `workspaceName`. The merge spread of
|
|
43663
|
+
// metadataEvent above wins when it already has a non-empty `workspace`.
|
|
43664
|
+
workspace: readNonEmptyString2(args.metadataEvent.workspace) || readNonEmptyString2(args.metadataEvent.workspaceName) || void 0,
|
|
43665
|
+
...surfacedPreview ? {
|
|
43666
|
+
meshSessionLastMessagePreview: surfacedPreview.preview,
|
|
43667
|
+
meshSessionLastMessageRole: surfacedPreview.role,
|
|
43668
|
+
meshSessionLastMessageAt: surfacedPreview.receivedAt || void 0
|
|
43669
|
+
} : {}
|
|
43670
|
+
});
|
|
43671
|
+
} catch {
|
|
43672
|
+
}
|
|
43673
|
+
}
|
|
43674
|
+
const eventTimestamp = readEventTimestamp(args.metadataEvent.timestamp);
|
|
43675
|
+
const suppression = evaluateMeshEventSuppression(args, {
|
|
43676
|
+
traceCtx,
|
|
43677
|
+
eventSessionId,
|
|
43678
|
+
eventNodeId,
|
|
43679
|
+
eventTimestamp,
|
|
43680
|
+
workerCoordinatorDaemonId
|
|
43681
|
+
});
|
|
43682
|
+
if (suppression) {
|
|
43683
|
+
if (suppression.kind === "reconcile") {
|
|
43684
|
+
return injectMeshSystemMessage(components, {
|
|
43685
|
+
...args,
|
|
43686
|
+
event: "agent:generating_completed",
|
|
43687
|
+
metadataEvent: suppression.metadataEvent
|
|
43688
|
+
});
|
|
43670
43689
|
}
|
|
43690
|
+
return suppression.result;
|
|
43671
43691
|
}
|
|
43672
43692
|
function markSessionTerminal(sessionId, outcome, occurredAtMs, opts) {
|
|
43673
43693
|
const eventTaskId = readNonEmptyString2(args.metadataEvent.taskId) || void 0;
|
|
@@ -50692,6 +50712,7 @@ ${lastSnapshot}`;
|
|
|
50692
50712
|
markSetupComplete: () => markSetupComplete,
|
|
50693
50713
|
markStaleDirectDispatches: () => markStaleDirectDispatches,
|
|
50694
50714
|
maybeRunDaemonUpgradeHelperFromEnv: () => maybeRunDaemonUpgradeHelperFromEnv2,
|
|
50715
|
+
meshNodeIdMatches: () => meshNodeIdMatches,
|
|
50695
50716
|
namedKeyToAnsi: () => namedKeyToAnsi,
|
|
50696
50717
|
namedKeysToAnsi: () => namedKeysToAnsi,
|
|
50697
50718
|
nodeSatisfiesRequiredTags: () => nodeSatisfiesRequiredTags,
|
|
@@ -50708,6 +50729,7 @@ ${lastSnapshot}`;
|
|
|
50708
50729
|
normalizeManagedStatus: () => normalizeManagedStatus,
|
|
50709
50730
|
normalizeMeshCapabilityTags: () => normalizeMeshCapabilityTags,
|
|
50710
50731
|
normalizeMeshDaemonRole: () => normalizeMeshDaemonRole,
|
|
50732
|
+
normalizeMeshNodeId: () => normalizeMeshNodeId,
|
|
50711
50733
|
normalizeMeshSchedulingStrategy: () => normalizeMeshSchedulingStrategy,
|
|
50712
50734
|
normalizeMeshTaskMode: () => normalizeMeshTaskMode,
|
|
50713
50735
|
normalizeMeshWorkerResult: () => normalizeMeshWorkerResult,
|
|
@@ -52023,6 +52045,7 @@ ${lastSnapshot}`;
|
|
|
52023
52045
|
}
|
|
52024
52046
|
init_mesh_config();
|
|
52025
52047
|
init_dist();
|
|
52048
|
+
init_dist();
|
|
52026
52049
|
init_coordinator_prompt();
|
|
52027
52050
|
init_mesh_missions();
|
|
52028
52051
|
init_mesh_task_stats();
|
|
@@ -57582,6 +57605,7 @@ ${effect.notification.body || ""}`.trim();
|
|
|
57582
57605
|
}
|
|
57583
57606
|
return fn() || null;
|
|
57584
57607
|
}
|
|
57608
|
+
init_hash();
|
|
57585
57609
|
var AUTO_APPROVE_MANUAL_ATTENDANCE_SUPPRESS_MS = 6e4;
|
|
57586
57610
|
var ManualAttendanceTracker = class {
|
|
57587
57611
|
constructor(suppressMs = AUTO_APPROVE_MANUAL_ATTENDANCE_SUPPRESS_MS) {
|
|
@@ -62289,7 +62313,6 @@ ${effect.notification.body || ""}`.trim();
|
|
|
62289
62313
|
const https = require("https");
|
|
62290
62314
|
const fs35 = require("fs");
|
|
62291
62315
|
const path422 = require("path");
|
|
62292
|
-
const crypto6 = require("crypto");
|
|
62293
62316
|
const REGISTRY = "https://api.adhf.dev/api/v1/registry";
|
|
62294
62317
|
function fetchText(url2, timeoutMs) {
|
|
62295
62318
|
return new Promise((resolve24, reject) => {
|
|
@@ -62321,7 +62344,7 @@ ${effect.notification.body || ""}`.trim();
|
|
|
62321
62344
|
`${REGISTRY}/providers/${encodeURIComponent(type)}/${encodeURIComponent(version2)}/download`,
|
|
62322
62345
|
3e4
|
|
62323
62346
|
);
|
|
62324
|
-
const actualChecksum =
|
|
62347
|
+
const actualChecksum = sha256Hex(manifestBody);
|
|
62325
62348
|
if (actualChecksum !== meta3.checksum) {
|
|
62326
62349
|
return { success: false, error: `checksum mismatch: expected ${meta3.checksum}, got ${actualChecksum}` };
|
|
62327
62350
|
}
|
|
@@ -64632,6 +64655,7 @@ ${body}
|
|
|
64632
64655
|
var import_node_module = require("module");
|
|
64633
64656
|
init_contracts();
|
|
64634
64657
|
init_provider_input_support();
|
|
64658
|
+
init_hash();
|
|
64635
64659
|
var fs18 = __toESM2(require("fs"));
|
|
64636
64660
|
var path24 = __toESM2(require("path"));
|
|
64637
64661
|
init_provider_cli_adapter();
|
|
@@ -68288,7 +68312,7 @@ ${body}
|
|
|
68288
68312
|
if (!content) return;
|
|
68289
68313
|
const receivedAt = Date.now();
|
|
68290
68314
|
this.lastAcknowledgedUserInputAt = receivedAt;
|
|
68291
|
-
const dedupKey = `user_input_ack:${
|
|
68315
|
+
const dedupKey = `user_input_ack:${shortHash(`${this.instanceId}:${content}:${receivedAt}`, 24)}`;
|
|
68292
68316
|
this.appendRuntimeMessage(buildChatMessage({
|
|
68293
68317
|
role: "user",
|
|
68294
68318
|
senderName: "User",
|
|
@@ -72139,6 +72163,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
72139
72163
|
var path34 = __toESM2(require("path"));
|
|
72140
72164
|
var os25 = __toESM2(require("os"));
|
|
72141
72165
|
var chokidar = __toESM2(require_chokidar());
|
|
72166
|
+
init_hash();
|
|
72142
72167
|
init_logger();
|
|
72143
72168
|
init_open_panel_support();
|
|
72144
72169
|
var VALID_CAPABILITY_MEDIA_TYPES = /* @__PURE__ */ new Set(["text", "image", "audio", "video", "resource"]);
|
|
@@ -74778,10 +74803,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
74778
74803
|
reject(new Error(`download timeout for ${type}`));
|
|
74779
74804
|
});
|
|
74780
74805
|
});
|
|
74781
|
-
const actualChecksum =
|
|
74782
|
-
const crypto6 = require("crypto");
|
|
74783
|
-
resolve24(crypto6.createHash("sha256").update(manifestBody, "utf-8").digest("hex"));
|
|
74784
|
-
});
|
|
74806
|
+
const actualChecksum = sha256Hex(manifestBody);
|
|
74785
74807
|
if (actualChecksum !== checksum) {
|
|
74786
74808
|
this.log(`\u26A0 Registry checksum mismatch for ${type}@${version2} \u2014 skipping`);
|
|
74787
74809
|
continue;
|
|
@@ -89708,477 +89730,6 @@ data: ${JSON.stringify(msg.data)}
|
|
|
89708
89730
|
async handleAutoImplement(type, req, res) {
|
|
89709
89731
|
return handleAutoImplement(this, type, req, res);
|
|
89710
89732
|
}
|
|
89711
|
-
buildAutoImplPrompt(type, provider, providerDir, functions, domContext, referenceScripts, userComment, referenceType) {
|
|
89712
|
-
if (provider.category === "cli") {
|
|
89713
|
-
return this.buildCliAutoImplPrompt(type, provider, providerDir, functions, referenceScripts, userComment, referenceType);
|
|
89714
|
-
}
|
|
89715
|
-
const lines = [];
|
|
89716
|
-
lines.push("You are implementing browser automation scripts for an IDE provider.");
|
|
89717
|
-
lines.push("Be concise. Do NOT explain your reasoning. Just edit files directly.");
|
|
89718
|
-
lines.push("");
|
|
89719
|
-
lines.push(`# Target: ${provider.name || type} (${type})`);
|
|
89720
|
-
lines.push(`Provider directory: \`${providerDir}\``);
|
|
89721
|
-
lines.push("");
|
|
89722
|
-
const funcToFile = {
|
|
89723
|
-
readChat: "read_chat.js",
|
|
89724
|
-
sendMessage: "send_message.js",
|
|
89725
|
-
resolveAction: "resolve_action.js",
|
|
89726
|
-
listSessions: "list_sessions.js",
|
|
89727
|
-
listChats: "list_chats.js",
|
|
89728
|
-
switchSession: "switch_session.js",
|
|
89729
|
-
newSession: "new_session.js",
|
|
89730
|
-
focusEditor: "focus_editor.js",
|
|
89731
|
-
openPanel: "open_panel.js",
|
|
89732
|
-
listModels: "list_models.js",
|
|
89733
|
-
listModes: "list_modes.js",
|
|
89734
|
-
setModel: "set_model.js",
|
|
89735
|
-
setMode: "set_mode.js"
|
|
89736
|
-
};
|
|
89737
|
-
const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
|
|
89738
|
-
const scriptsDir = path41.join(providerDir, "scripts");
|
|
89739
|
-
const latestScriptsDir = this.getLatestScriptVersionDir(scriptsDir);
|
|
89740
|
-
if (latestScriptsDir) {
|
|
89741
|
-
lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
|
|
89742
|
-
lines.push("");
|
|
89743
|
-
lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
|
|
89744
|
-
lines.push("These are the ONLY files you are allowed to modify. Replace the TODO stubs with working implementations.");
|
|
89745
|
-
lines.push("");
|
|
89746
|
-
for (const file2 of fs34.readdirSync(latestScriptsDir)) {
|
|
89747
|
-
if (file2.endsWith(".js") && targetFileNames.has(file2)) {
|
|
89748
|
-
try {
|
|
89749
|
-
const content = fs34.readFileSync(path41.join(latestScriptsDir, file2), "utf-8");
|
|
89750
|
-
lines.push(`### \`${file2}\` \u270F\uFE0F EDIT`);
|
|
89751
|
-
lines.push("```javascript");
|
|
89752
|
-
lines.push(content);
|
|
89753
|
-
lines.push("```");
|
|
89754
|
-
lines.push("");
|
|
89755
|
-
} catch {
|
|
89756
|
-
}
|
|
89757
|
-
}
|
|
89758
|
-
}
|
|
89759
|
-
const refFiles = fs34.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
|
|
89760
|
-
if (refFiles.length > 0) {
|
|
89761
|
-
lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
|
|
89762
|
-
lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
|
|
89763
|
-
lines.push("");
|
|
89764
|
-
for (const file2 of refFiles) {
|
|
89765
|
-
try {
|
|
89766
|
-
const content = fs34.readFileSync(path41.join(latestScriptsDir, file2), "utf-8");
|
|
89767
|
-
lines.push(`### \`${file2}\` \u{1F512}`);
|
|
89768
|
-
lines.push("```javascript");
|
|
89769
|
-
lines.push(content);
|
|
89770
|
-
lines.push("```");
|
|
89771
|
-
lines.push("");
|
|
89772
|
-
} catch {
|
|
89773
|
-
}
|
|
89774
|
-
}
|
|
89775
|
-
}
|
|
89776
|
-
}
|
|
89777
|
-
if (domContext) {
|
|
89778
|
-
lines.push("## Live DOM Analysis (from CDP)");
|
|
89779
|
-
lines.push("Use these selectors in your implementations:");
|
|
89780
|
-
lines.push("```json");
|
|
89781
|
-
lines.push(JSON.stringify(domContext, null, 2));
|
|
89782
|
-
lines.push("```");
|
|
89783
|
-
lines.push("");
|
|
89784
|
-
}
|
|
89785
|
-
if (Object.keys(referenceScripts).length > 0) {
|
|
89786
|
-
lines.push(`## Reference Implementation (from ${referenceType || "antigravity"} provider)`);
|
|
89787
|
-
lines.push("These are WORKING scripts from another IDE. Adapt the PATTERNS (not selectors) for the target IDE.");
|
|
89788
|
-
lines.push("");
|
|
89789
|
-
for (const fn of functions) {
|
|
89790
|
-
const fileName = funcToFile[fn];
|
|
89791
|
-
if (fileName && referenceScripts[fileName]) {
|
|
89792
|
-
lines.push(`### ${fn} \u2192 \`${fileName}\``);
|
|
89793
|
-
lines.push("```javascript");
|
|
89794
|
-
lines.push(referenceScripts[fileName]);
|
|
89795
|
-
lines.push("```");
|
|
89796
|
-
lines.push("");
|
|
89797
|
-
}
|
|
89798
|
-
}
|
|
89799
|
-
if (referenceScripts["scripts.js"]) {
|
|
89800
|
-
lines.push("### Router \u2192 `scripts.js`");
|
|
89801
|
-
lines.push("```javascript");
|
|
89802
|
-
lines.push(referenceScripts["scripts.js"]);
|
|
89803
|
-
lines.push("```");
|
|
89804
|
-
lines.push("");
|
|
89805
|
-
}
|
|
89806
|
-
}
|
|
89807
|
-
const docsDir = path41.join(providerDir, "../../docs");
|
|
89808
|
-
const loadGuide = (name) => {
|
|
89809
|
-
try {
|
|
89810
|
-
const p = path41.join(docsDir, name);
|
|
89811
|
-
if (fs34.existsSync(p)) return fs34.readFileSync(p, "utf-8");
|
|
89812
|
-
} catch {
|
|
89813
|
-
}
|
|
89814
|
-
return null;
|
|
89815
|
-
};
|
|
89816
|
-
const providerGuide = loadGuide("PROVIDER_GUIDE.md");
|
|
89817
|
-
if (providerGuide) {
|
|
89818
|
-
lines.push("## Documentation: PROVIDER_GUIDE.md");
|
|
89819
|
-
lines.push("```markdown");
|
|
89820
|
-
lines.push(providerGuide);
|
|
89821
|
-
lines.push("```");
|
|
89822
|
-
lines.push("");
|
|
89823
|
-
}
|
|
89824
|
-
const cdpGuide = loadGuide("CDP_SELECTOR_GUIDE.md");
|
|
89825
|
-
if (cdpGuide) {
|
|
89826
|
-
lines.push("## Documentation: CDP_SELECTOR_GUIDE.md");
|
|
89827
|
-
lines.push("```markdown");
|
|
89828
|
-
lines.push(cdpGuide);
|
|
89829
|
-
lines.push("```");
|
|
89830
|
-
lines.push("");
|
|
89831
|
-
}
|
|
89832
|
-
lines.push("## Task");
|
|
89833
|
-
lines.push(`Edit files in \`${providerDir}\` to implement: **${functions.join(", ")}**`);
|
|
89834
|
-
lines.push("");
|
|
89835
|
-
lines.push("## Rules");
|
|
89836
|
-
lines.push('0. **\u{1F6AB} SCOPE CONSTRAINT**: You may ONLY edit files marked \u270F\uFE0F EDIT above. ALL other files are READ-ONLY. Do NOT modify, rewrite, refactor, or "improve" any file not explicitly marked as editable \u2014 even if you notice bugs or improvements. No exceptions.');
|
|
89837
|
-
lines.push("1. **Scripts WITHOUT params** \u2192 IIFE: `(() => { ... })()`");
|
|
89838
|
-
lines.push("2. **Scripts WITH params** \u2192 arrow: `(params) => { ... }` \u2014 router calls `(${script})(${JSON.stringify(params)})`");
|
|
89839
|
-
lines.push("3. If live DOM analysis is included above, use it. Otherwise, discover selectors yourself via CDP before coding.");
|
|
89840
|
-
lines.push("4. Always wrap in try-catch, return `JSON.stringify(result)`");
|
|
89841
|
-
lines.push("5. Do NOT modify `scripts.js` router \u2014 only edit individual `*.js` files");
|
|
89842
|
-
lines.push("6. All scripts run in the browser (CDP evaluate) \u2014 use DOM APIs only");
|
|
89843
|
-
lines.push('7. **Cross-Platform Compatibility**: If you use ARIA labels that contain keyboard shortcuts (e.g., `Cascade (\u2318L)`), you MUST use substring matches (`aria-label*="Cascade"`) or handle both macOS (`\u2318`, `Cmd`) and Windows (`Ctrl`) so the script does not break on other operating systems.');
|
|
89844
|
-
lines.push("8. **CRITICAL: DO NOT explore the filesystem or read other providers.** The reference implementation pattern is already provided below. Do not run `find`, `rg`, or `cat` on upstream providers. Doing so wastes context tokens and will crash the agent session. Focus entirely on modifying the target files.");
|
|
89845
|
-
lines.push("9. Do NOT delete any files. Implement the logic by replacing the empty stubs.");
|
|
89846
|
-
lines.push("");
|
|
89847
|
-
lines.push("## Required Return Format");
|
|
89848
|
-
lines.push("| Function | Return JSON |");
|
|
89849
|
-
lines.push("|---|---|");
|
|
89850
|
-
lines.push("| readChat | `{ id, status, title, messages: [{role, content, index, kind?, meta?}], inputContent, activeModal, controlValues?, summaryMetadata? }` \u2014 optional `kind`: standard, thought, tool, terminal; prefer explicit `controlValues` for current selections and `summaryMetadata` for compact always-visible UI metadata |");
|
|
89851
|
-
lines.push("| sendMessage | `{ sent: false, needsTypeAndSend: true, selector }` |");
|
|
89852
|
-
lines.push("| resolveAction | `{ resolved: true/false, clicked? }` |");
|
|
89853
|
-
lines.push("| listSessions | `{ sessions: [{ id, title, active, index }] }` |");
|
|
89854
|
-
lines.push("| switchSession | `{ switched: true/false }` |");
|
|
89855
|
-
lines.push("| newSession | `{ created: true/false }` |");
|
|
89856
|
-
lines.push("| listModels | `{ models: [{ name, id }], current }` |");
|
|
89857
|
-
lines.push("| setModel | `{ success: true/false }` |");
|
|
89858
|
-
lines.push("| listModes | `{ modes: [{ name, id }], current }` |");
|
|
89859
|
-
lines.push("| setMode | `{ success: true/false }` |");
|
|
89860
|
-
lines.push("| focusEditor | `{ focused: true/false, error? }` |");
|
|
89861
|
-
lines.push("| openPanel | `{ opened: true/false, visible: true/false, focused?: true, error? }` |");
|
|
89862
|
-
lines.push("");
|
|
89863
|
-
lines.push("## \u{1F534} CRITICAL: readChat `status` Lifecycle");
|
|
89864
|
-
lines.push("The `status` field in readChat controls how the dashboard and daemon auto-approve-loop behave.");
|
|
89865
|
-
lines.push("Getting this wrong will break the entire automation pipeline. The status MUST reflect the ACTUAL current state:");
|
|
89866
|
-
lines.push("");
|
|
89867
|
-
lines.push("| Status | When to use | How to detect |");
|
|
89868
|
-
lines.push("|---|---|---|");
|
|
89869
|
-
lines.push("| `idle` | AI is NOT generating, no approval needed | Default state. No stop button, no spinners, no approval pills/buttons |");
|
|
89870
|
-
lines.push('| `generating` | AI is actively streaming/thinking | ANY of: (1) Submit button icon SVG changes (e.g. arrow\u2192stop square, fill="none"\u2192fill="currentColor"), (2) Stop/Cancel button visible, (3) CSS animation, (4) Structural markers (aria-labels that only appear during generation) |');
|
|
89871
|
-
lines.push("| `waiting_approval` | AI stopped and needs user action | Actionable buttons like Run/Skip/Accept/Reject are visible AND clickable |");
|
|
89872
|
-
lines.push("");
|
|
89873
|
-
lines.push("### \u26A0\uFE0F Status Detection Gotchas (MUST READ!)");
|
|
89874
|
-
lines.push(`1. **DO NOT rely on button text/labels in the user's language.** OS locale may be Korean, Japanese, etc. Button text like "Cancel" or "Stop" will be localized. Instead, detect STRUCTURAL indicators: SVG icon changes, CSS classes, aria-labels from the extension's own React/Radix UI (which stay in English regardless of OS locale).`);
|
|
89875
|
-
lines.push('2. **Use sendMessage to CREATE a generating state, then CAPTURE the DOM.** Send a LONG prompt (e.g. "Write an extremely detailed 5000-word essay...") so the AI takes 10+ seconds. Then periodically capture the DOM during generation to find which elements appear/change. Compare idle vs generating DOM snapshots to find reliable structural markers.');
|
|
89876
|
-
lines.push("3. **Look for SVG icon changes in the submit button.** Many IDEs change the submit button icon from an arrow (send) to a square (stop) during generation. Check the SVG `fill` attribute or path data.");
|
|
89877
|
-
lines.push('4. **FALSE POSITIVES from old messages**: Chat history may contain text like "Command Awaiting Approval" from PAST turns. ONLY match small leaf elements (under 80 chars) or use explicit button/pill selectors.');
|
|
89878
|
-
lines.push("5. **Awaiting Approval pill without actions**: Some IDEs show a floating pill/banner that is just a scroll-to indicator. If NO actionable buttons exist, the status should be `idle`, NOT `waiting_approval`.");
|
|
89879
|
-
lines.push("6. **activeModal must include actions**: When `status` is `waiting_approval`, the `activeModal` object MUST include a non-empty `actions` array.");
|
|
89880
|
-
lines.push("");
|
|
89881
|
-
lines.push("## Action");
|
|
89882
|
-
lines.push("1. Edit the script files to implement working code");
|
|
89883
|
-
lines.push("2. After editing, TEST each function using the DevConsole API (see below)");
|
|
89884
|
-
lines.push("3. If a test fails, fix the implementation and re-test");
|
|
89885
|
-
lines.push("4. **IMPORTANT VERIFICATION LOGIC**: When verifying your implementation, beware of state contamination! You MUST perform strict Integration Testing:");
|
|
89886
|
-
lines.push(" - `openPanel`: Toggle buttons are usually located in the top header, sidebar, or activity bar. Prefer finding and clicking these native UI buttons over extreme CSS injection hacks if possible.");
|
|
89887
|
-
lines.push(" - `listSessions`: If sessions are unmounted when the panel is closed, try to explicitly interact with the UI to open the history/sessions view (e.g., clicking a history icon usually found near the chat header) BEFORE scraping.");
|
|
89888
|
-
lines.push(" - `switchSession`: Prove your switch was successful by subsequently calling `readChat` and explicitly checking that the chat context has actually changed.");
|
|
89889
|
-
lines.push("");
|
|
89890
|
-
lines.push("## DOM Exploration");
|
|
89891
|
-
if (domContext) {
|
|
89892
|
-
lines.push("A lightweight DOM snapshot is included above, but you MUST still verify selectors yourself before finalizing the scripts.");
|
|
89893
|
-
} else {
|
|
89894
|
-
lines.push("No DOM snapshot is included here. You MUST use your command-line tools to discover the IDE structure dynamically.");
|
|
89895
|
-
}
|
|
89896
|
-
lines.push("");
|
|
89897
|
-
lines.push("### 1. Evaluate JS to explore IDE DOM");
|
|
89898
|
-
lines.push("Use cURL to run JavaScript inside the IDE:");
|
|
89899
|
-
lines.push("```bash");
|
|
89900
|
-
lines.push(`curl -sS -X POST http://127.0.0.1:${DEV_SERVER_PORT}/api/cdp/evaluate \\`);
|
|
89901
|
-
lines.push(` -H "Content-Type: application/json" \\`);
|
|
89902
|
-
lines.push(` -d '{"expression": "document.body.innerHTML.substring(0, 1000)", "ideType": "${type}"}'`);
|
|
89903
|
-
lines.push("```");
|
|
89904
|
-
lines.push("");
|
|
89905
|
-
lines.push("### 2. Test your generated function");
|
|
89906
|
-
lines.push("Once you save the file, test it by running:");
|
|
89907
|
-
lines.push("```bash");
|
|
89908
|
-
lines.push(`curl -X POST http://127.0.0.1:${DEV_SERVER_PORT}/api/providers/reload`);
|
|
89909
|
-
lines.push(`curl -sS -X POST http://127.0.0.1:${DEV_SERVER_PORT}/api/scripts/run -H "Content-Type: application/json" -d '{"script": "readChat", "type": "${type}", "ideType": "${type}"}'`);
|
|
89910
|
-
lines.push("```");
|
|
89911
|
-
lines.push("");
|
|
89912
|
-
lines.push("### Task Workflow");
|
|
89913
|
-
lines.push("1. Write bash scripts to `curl` the CDP evaluate API above to find exactly where `.chat-message`, etc., are located.");
|
|
89914
|
-
lines.push("2. Iteratively explore until you are confident in your selectors.");
|
|
89915
|
-
lines.push("3. Edit the `.js` files using the selectors you discovered.");
|
|
89916
|
-
lines.push("4. Reload providers and TEST your script via the API.");
|
|
89917
|
-
lines.push("");
|
|
89918
|
-
lines.push("### \u{1F525} Advanced UI Parsing (CRUCIAL for `readChat`)");
|
|
89919
|
-
lines.push("Your `readChat` must flawlessly parse complex UI elements (tables, code blocks, tool calls, and AI thoughts). The quality must match the `antigravity` reference.");
|
|
89920
|
-
lines.push("To achieve this, you MUST generate a live test scenario:");
|
|
89921
|
-
lines.push(`1. Early in your process, send a rich prompt to the IDE using the API:`);
|
|
89922
|
-
lines.push(` \`curl -sS -X POST http://127.0.0.1:${DEV_SERVER_PORT}/api/scripts/run -H "Content-Type: application/json" -d '{"script": "sendMessage", "type": "${type}", "ideType": "${type}", "args": {"message": "Write a python script, draw a markdown table, use a tool, and show your reasoning/thought process"}}'\``);
|
|
89923
|
-
lines.push("2. Wait a few seconds for the IDE AI to generate these elements in the UI.");
|
|
89924
|
-
lines.push("3. Use CDP evaluate to deeply inspect the DOM structure of the newly generated tables, code blocks, thought blocks, and tool calls.");
|
|
89925
|
-
lines.push("4. Ensure `readChat` extracts `content` with precise markdown formatting (especially for tables/code) and assigns correct `kind` tags (`thought`, `tool`, `terminal`).");
|
|
89926
|
-
lines.push("");
|
|
89927
|
-
lines.push("## \u{1F9EA} MANDATORY: Status Integration Test");
|
|
89928
|
-
lines.push("Before finishing, you MUST run this end-to-end test to verify readChat status transitions work:");
|
|
89929
|
-
lines.push("");
|
|
89930
|
-
lines.push("### Step 1: Baseline \u2014 confirm idle");
|
|
89931
|
-
lines.push("```bash");
|
|
89932
|
-
lines.push(`curl -X POST http://127.0.0.1:${DEV_SERVER_PORT}/api/providers/reload`);
|
|
89933
|
-
lines.push(`RESULT=$(curl -sS -X POST http://127.0.0.1:${DEV_SERVER_PORT}/api/scripts/run -H "Content-Type: application/json" -d '{"script": "readChat", "type": "${type}", "ideType": "${type}"}')`);
|
|
89934
|
-
lines.push(`echo "$RESULT" | python3 -c "import sys,json; d=json.load(sys.stdin); r=d.get('result',d); r=json.loads(r) if isinstance(r,str) else r; assert r.get('status')=='idle', f'Expected idle, got {r.get(chr(34)+chr(115)+chr(116)+chr(97)+chr(116)+chr(117)+chr(115)+chr(34))}'; print('Step 1 PASS: status=idle')"`);
|
|
89935
|
-
lines.push("```");
|
|
89936
|
-
lines.push("");
|
|
89937
|
-
lines.push("### Step 2: Send a LONG message that triggers extended generation (10+ seconds)");
|
|
89938
|
-
lines.push("```bash");
|
|
89939
|
-
lines.push(`curl -sS -X POST http://127.0.0.1:${DEV_SERVER_PORT}/api/scripts/run -H "Content-Type: application/json" -d '{"script": "sendMessage", "type": "${type}", "ideType": "${type}", "args": {"message": "Write an extremely detailed 5000-word essay about the history of artificial intelligence from Alan Turing to 2025. Be very thorough and verbose."}}'`);
|
|
89940
|
-
lines.push("sleep 3");
|
|
89941
|
-
lines.push("```");
|
|
89942
|
-
lines.push("");
|
|
89943
|
-
lines.push("### Step 3: Check generating OR completed");
|
|
89944
|
-
lines.push("The AI may still be generating OR may have finished already. Either generating or idle is acceptable:");
|
|
89945
|
-
lines.push("```bash");
|
|
89946
|
-
lines.push(`RESULT=$(curl -sS -X POST http://127.0.0.1:${DEV_SERVER_PORT}/api/scripts/run -H "Content-Type: application/json" -d '{"script": "readChat", "type": "${type}", "ideType": "${type}"}')`);
|
|
89947
|
-
lines.push(`echo "$RESULT" | python3 -c "import sys,json; d=json.load(sys.stdin); r=d.get('result',d); r=json.loads(r) if isinstance(r,str) else r; s=r.get('status'); assert s in ('generating','idle','waiting_approval'), f'Unexpected: {s}'; print(f'Step 3 PASS: status={s}')"`);
|
|
89948
|
-
lines.push("```");
|
|
89949
|
-
lines.push("");
|
|
89950
|
-
lines.push("### Step 4: Wait for completion and verify new message");
|
|
89951
|
-
lines.push("```bash");
|
|
89952
|
-
lines.push("sleep 10");
|
|
89953
|
-
lines.push(`RESULT=$(curl -sS -X POST http://127.0.0.1:${DEV_SERVER_PORT}/api/scripts/run -H "Content-Type: application/json" -d '{"script": "readChat", "type": "${type}", "ideType": "${type}"}')`);
|
|
89954
|
-
lines.push(`echo "$RESULT" | python3 -c "import sys,json; d=json.load(sys.stdin); r=d.get('result',d); r=json.loads(r) if isinstance(r,str) else r; s=r.get('status'); msgs=r.get('messages',[]); assert s=='idle', f'Expected idle, got {s}'; assert len(msgs)>0, 'No messages'; print(f'Step 4 PASS: status={s}, messages={len(msgs)}')"`);
|
|
89955
|
-
lines.push("```");
|
|
89956
|
-
lines.push("");
|
|
89957
|
-
lines.push("If ANY step fails, fix your implementation and re-run the test. Do NOT finish until all 4 steps pass.");
|
|
89958
|
-
lines.push("");
|
|
89959
|
-
if (userComment) {
|
|
89960
|
-
lines.push("## \u26A0\uFE0F User Instructions (HIGH PRIORITY)");
|
|
89961
|
-
lines.push("The user has provided the following additional instructions. Follow them strictly:");
|
|
89962
|
-
lines.push("");
|
|
89963
|
-
lines.push(userComment);
|
|
89964
|
-
lines.push("");
|
|
89965
|
-
}
|
|
89966
|
-
lines.push("Start NOW. Do not ask for permission. Explore the DOM -> Code -> Test.");
|
|
89967
|
-
return lines.join("\n");
|
|
89968
|
-
}
|
|
89969
|
-
buildCliAutoImplPrompt(type, provider, providerDir, functions, referenceScripts, userComment, referenceType) {
|
|
89970
|
-
const lines = [];
|
|
89971
|
-
lines.push("You are implementing PTY parsing scripts for a CLI provider.");
|
|
89972
|
-
lines.push("Be concise. Do NOT explain your reasoning. Edit files directly and verify with the local DevServer.");
|
|
89973
|
-
lines.push("");
|
|
89974
|
-
lines.push(`# Target: ${provider.name || type} (${type})`);
|
|
89975
|
-
lines.push(`Provider directory: \`${providerDir}\``);
|
|
89976
|
-
lines.push("Provider category: `cli`");
|
|
89977
|
-
lines.push("");
|
|
89978
|
-
const funcToFile = {
|
|
89979
|
-
parseSession: "parse_session.js",
|
|
89980
|
-
detectStatus: "detect_status.js",
|
|
89981
|
-
parseApproval: "parse_approval.js"
|
|
89982
|
-
};
|
|
89983
|
-
const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
|
|
89984
|
-
const scriptsDir = path41.join(providerDir, "scripts");
|
|
89985
|
-
const latestScriptsDir = this.getLatestScriptVersionDir(scriptsDir);
|
|
89986
|
-
if (latestScriptsDir) {
|
|
89987
|
-
lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
|
|
89988
|
-
lines.push("");
|
|
89989
|
-
lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
|
|
89990
|
-
lines.push("These are the ONLY files you are allowed to modify. Replace TODO or heuristic-only logic with working PTY-aware implementations.");
|
|
89991
|
-
lines.push("");
|
|
89992
|
-
for (const file2 of fs34.readdirSync(latestScriptsDir)) {
|
|
89993
|
-
if (!file2.endsWith(".js")) continue;
|
|
89994
|
-
if (!targetFileNames.has(file2)) continue;
|
|
89995
|
-
try {
|
|
89996
|
-
const content = fs34.readFileSync(path41.join(latestScriptsDir, file2), "utf-8");
|
|
89997
|
-
lines.push(`### \`${file2}\` \u270F\uFE0F EDIT`);
|
|
89998
|
-
lines.push("```javascript");
|
|
89999
|
-
lines.push(content);
|
|
90000
|
-
lines.push("```");
|
|
90001
|
-
lines.push("");
|
|
90002
|
-
} catch {
|
|
90003
|
-
}
|
|
90004
|
-
}
|
|
90005
|
-
const refFiles = fs34.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
|
|
90006
|
-
if (refFiles.length > 0) {
|
|
90007
|
-
lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
|
|
90008
|
-
lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
|
|
90009
|
-
lines.push("");
|
|
90010
|
-
for (const file2 of refFiles) {
|
|
90011
|
-
try {
|
|
90012
|
-
const content = fs34.readFileSync(path41.join(latestScriptsDir, file2), "utf-8");
|
|
90013
|
-
lines.push(`### \`${file2}\` \u{1F512}`);
|
|
90014
|
-
lines.push("```javascript");
|
|
90015
|
-
lines.push(content);
|
|
90016
|
-
lines.push("```");
|
|
90017
|
-
lines.push("");
|
|
90018
|
-
} catch {
|
|
90019
|
-
}
|
|
90020
|
-
}
|
|
90021
|
-
}
|
|
90022
|
-
}
|
|
90023
|
-
if (Object.keys(referenceScripts).length > 0) {
|
|
90024
|
-
lines.push(`## Reference Implementation (from ${referenceType || "another CLI"} provider)`);
|
|
90025
|
-
lines.push("These are working CLI PTY parser scripts. Reuse the parsing shape and runtime contract, but adapt to the target CLI screen.");
|
|
90026
|
-
lines.push("");
|
|
90027
|
-
for (const fn of functions) {
|
|
90028
|
-
const fileName = funcToFile[fn];
|
|
90029
|
-
if (fileName && referenceScripts[fileName]) {
|
|
90030
|
-
lines.push(`### ${fn} \u2192 \`${fileName}\``);
|
|
90031
|
-
lines.push("```javascript");
|
|
90032
|
-
lines.push(referenceScripts[fileName]);
|
|
90033
|
-
lines.push("```");
|
|
90034
|
-
lines.push("");
|
|
90035
|
-
}
|
|
90036
|
-
}
|
|
90037
|
-
if (referenceScripts["scripts.js"]) {
|
|
90038
|
-
lines.push("### Router \u2192 `scripts.js`");
|
|
90039
|
-
lines.push("```javascript");
|
|
90040
|
-
lines.push(referenceScripts["scripts.js"]);
|
|
90041
|
-
lines.push("```");
|
|
90042
|
-
lines.push("");
|
|
90043
|
-
}
|
|
90044
|
-
}
|
|
90045
|
-
const docsDir = path41.join(providerDir, "../../docs");
|
|
90046
|
-
const loadGuide = (name) => {
|
|
90047
|
-
try {
|
|
90048
|
-
const p = path41.join(docsDir, name);
|
|
90049
|
-
if (fs34.existsSync(p)) return fs34.readFileSync(p, "utf-8");
|
|
90050
|
-
} catch {
|
|
90051
|
-
}
|
|
90052
|
-
return null;
|
|
90053
|
-
};
|
|
90054
|
-
const providerGuide = loadGuide("PROVIDER_GUIDE.md");
|
|
90055
|
-
if (providerGuide) {
|
|
90056
|
-
lines.push("## Documentation: PROVIDER_GUIDE.md");
|
|
90057
|
-
lines.push("```markdown");
|
|
90058
|
-
lines.push(providerGuide);
|
|
90059
|
-
lines.push("```");
|
|
90060
|
-
lines.push("");
|
|
90061
|
-
}
|
|
90062
|
-
lines.push("## Runtime Contract");
|
|
90063
|
-
lines.push("The daemon runtime is already implemented in `packages/daemon-core/src/cli-adapters/provider-cli-adapter.ts`.");
|
|
90064
|
-
lines.push("Your scripts receive PTY-derived input and must return plain JS objects.");
|
|
90065
|
-
lines.push("");
|
|
90066
|
-
lines.push("| Function | Input | Return |");
|
|
90067
|
-
lines.push("|---|---|---|");
|
|
90068
|
-
lines.push("| `parseSession` | `{ buffer, rawBuffer, recentBuffer, screenText, messages, partialResponse }` | `{ id, status, title, messages, activeModal }` |");
|
|
90069
|
-
lines.push("| `detectStatus` | `{ tail, screenText, rawBuffer }` | `idle`, `generating`, `waiting_approval`, or `error` |");
|
|
90070
|
-
lines.push("| `parseApproval` | `{ buffer, rawBuffer, tail }` | `{ message, buttons }` or `null` |");
|
|
90071
|
-
lines.push("");
|
|
90072
|
-
lines.push("## Primary Source of Truth");
|
|
90073
|
-
lines.push("The runtime now provides a reliable current-screen snapshot. Treat `screenText` as the primary source of truth for the LIVE visible UI.");
|
|
90074
|
-
lines.push("That means:");
|
|
90075
|
-
lines.push("- Use `screenText` first for prompt detection, approval UI, status, and visible assistant content.");
|
|
90076
|
-
lines.push("- Use `rawBuffer` only as supporting evidence when ANSI/style/cursor cues matter.");
|
|
90077
|
-
lines.push("- Use `buffer` only when the visible screen does not contain enough text to recover the latest assistant answer.");
|
|
90078
|
-
lines.push("- Do NOT build the parser around stale transcript noise if the current screen already gives the answer.");
|
|
90079
|
-
lines.push("");
|
|
90080
|
-
lines.push("## Rules");
|
|
90081
|
-
lines.push('0. **\u{1F6AB} SCOPE CONSTRAINT**: You may ONLY edit files marked \u270F\uFE0F EDIT above. ALL other files are READ-ONLY. Do NOT modify, rewrite, refactor, or "improve" any file not explicitly marked as editable \u2014 even if you notice bugs or improvements. No exceptions.');
|
|
90082
|
-
lines.push("1. These scripts run in Node.js CommonJS, not in the browser. Do NOT use DOM APIs.");
|
|
90083
|
-
lines.push("2. Prefer `screenText` for current visible UI state. It is now the PTY equivalent of a trustworthy live DOM snapshot.");
|
|
90084
|
-
lines.push("3. Use `messages` as prior transcript state so redraws do not duplicate old turns on every parse.");
|
|
90085
|
-
lines.push("4. Use `partialResponse` for the actively streaming assistant text when status is `generating`.");
|
|
90086
|
-
lines.push("5. `detectStatus` must stay lightweight and current-screen-oriented. Prefer the active bottom-of-screen region over stale history.");
|
|
90087
|
-
lines.push("6. `parseApproval` should understand the live approval area and return clean button labels from the CURRENT visible modal.");
|
|
90088
|
-
lines.push("7. Use `rawBuffer` only when ANSI/control-sequence artifacts or style cues matter. Do not depend on raw escape noise unless necessary.");
|
|
90089
|
-
lines.push("8. Keep exports compatible with the existing `scripts.js` router (`module.exports = function ...`).");
|
|
90090
|
-
lines.push('9. Do NOT modify ANY file not explicitly marked \u270F\uFE0F EDIT above. No exceptions \u2014 no "tiny supporting changes" to other files.');
|
|
90091
|
-
lines.push("10. When the verification API returns `instanceId`, keep using that exact instance for follow-up `send`, `resolve`, `raw`, and `stop` calls. Do not assume type-only routing is safe if multiple sessions exist.");
|
|
90092
|
-
lines.push("11. Do NOT repeatedly dump the same target files. Read the target scripts once, reproduce the bug, then move directly to patching.");
|
|
90093
|
-
lines.push("12. If the user instructions include concrete screen text, raw PTY snippets, or a specific repro, treat that as the primary acceptance criteria.");
|
|
90094
|
-
lines.push("13. After the first successful live repro, stop broad diagnosis. Edit the scripts, reload, and verify. Do not burn tokens on repeated re-inspection without code changes.");
|
|
90095
|
-
lines.push("14. If the visible current screen is clean and sufficient, do NOT fall back to complex buffer heuristics. Simpler current-screen parsing is preferred.");
|
|
90096
|
-
lines.push("15. Before changing parser logic, verify whether `provider.json` submit/approval behavior (`sendDelayMs`, `approvalKeys`, submit strategy) is the simpler and more correct fix.");
|
|
90097
|
-
lines.push("");
|
|
90098
|
-
lines.push("## Task");
|
|
90099
|
-
lines.push(`Edit files in \`${providerDir}\` to implement: **${functions.join(", ")}**`);
|
|
90100
|
-
lines.push("");
|
|
90101
|
-
lines.push("## Verification API");
|
|
90102
|
-
lines.push("Use the DevServer CLI debug endpoints, not DOM/CDP routes.");
|
|
90103
|
-
lines.push("");
|
|
90104
|
-
lines.push("### 1. Launch the target CLI");
|
|
90105
|
-
lines.push("```bash");
|
|
90106
|
-
lines.push(`curl -sS -X POST http://127.0.0.1:${DEV_SERVER_PORT}/api/cli/launch \\`);
|
|
90107
|
-
lines.push(' -H "Content-Type: application/json" \\');
|
|
90108
|
-
lines.push(` -d '{"type":"${type}","workingDir":"${providerDir.replace(/\\/g, "\\\\")}"}'`);
|
|
90109
|
-
lines.push("```");
|
|
90110
|
-
lines.push("");
|
|
90111
|
-
lines.push("### 2. Inspect parsed + raw adapter state");
|
|
90112
|
-
lines.push("```bash");
|
|
90113
|
-
lines.push(`curl -sS http://127.0.0.1:${DEV_SERVER_PORT}/api/cli/debug/${type}`);
|
|
90114
|
-
lines.push(`curl -sS http://127.0.0.1:${DEV_SERVER_PORT}/api/cli/trace/${type}`);
|
|
90115
|
-
lines.push(`curl -sS http://127.0.0.1:${DEV_SERVER_PORT}/api/cli/status`);
|
|
90116
|
-
lines.push("```");
|
|
90117
|
-
lines.push("");
|
|
90118
|
-
lines.push("The debug payload should be read in this priority order:");
|
|
90119
|
-
lines.push("1. `screenText` / current visible state");
|
|
90120
|
-
lines.push("2. parsed `status`, `messages`, `activeModal`");
|
|
90121
|
-
lines.push("3. `rawBuffer` only for style/control-sequence cues");
|
|
90122
|
-
lines.push("4. `buffer` only when the current screen is insufficient");
|
|
90123
|
-
lines.push("");
|
|
90124
|
-
lines.push("Extract the current `instanceId` from the launch or status response and keep using it below.");
|
|
90125
|
-
lines.push("");
|
|
90126
|
-
lines.push("### 3. Send a realistic approval-triggering prompt");
|
|
90127
|
-
lines.push("```bash");
|
|
90128
|
-
lines.push(`curl -sS -X POST http://127.0.0.1:${DEV_SERVER_PORT}/api/cli/send \\`);
|
|
90129
|
-
lines.push(' -H "Content-Type: application/json" \\');
|
|
90130
|
-
lines.push(` -d '{"type":"${type}","instanceId":"<INSTANCE_ID>","text":"Create a file at tmp/adhdev_provider_fix_test.py that prints the current working directory and the squares of 1 through 5, then run python3 tmp/adhdev_provider_fix_test.py and tell me the exact output."}'`);
|
|
90131
|
-
lines.push("```");
|
|
90132
|
-
lines.push("");
|
|
90133
|
-
lines.push("### 4. If approval appears, resolve it until the CLI reaches idle");
|
|
90134
|
-
lines.push("```bash");
|
|
90135
|
-
lines.push(`curl -sS -X POST http://127.0.0.1:${DEV_SERVER_PORT}/api/cli/resolve \\`);
|
|
90136
|
-
lines.push(' -H "Content-Type: application/json" \\');
|
|
90137
|
-
lines.push(` -d '{"type":"${type}","instanceId":"<INSTANCE_ID>","buttonIndex":0}'`);
|
|
90138
|
-
lines.push(`curl -sS -X POST http://127.0.0.1:${DEV_SERVER_PORT}/api/cli/raw \\`);
|
|
90139
|
-
lines.push(' -H "Content-Type: application/json" \\');
|
|
90140
|
-
lines.push(` -d '{"type":"${type}","instanceId":"<INSTANCE_ID>","keys":"1"}'`);
|
|
90141
|
-
lines.push("```");
|
|
90142
|
-
lines.push("");
|
|
90143
|
-
lines.push("Use `resolve` when the parsed modal buttons are correct. Use `raw` when the CLI expects a literal keystroke like `1`, `y`, or Enter. Repeat until idle.");
|
|
90144
|
-
lines.push("");
|
|
90145
|
-
lines.push("### Patch Discipline");
|
|
90146
|
-
lines.push("Once the repro is confirmed, immediately edit the target files. Avoid loops where you keep re-reading long files or re-running the same debug commands without changing code.");
|
|
90147
|
-
lines.push("");
|
|
90148
|
-
lines.push("### 5. Verify the side effects outside the CLI");
|
|
90149
|
-
lines.push("```bash");
|
|
90150
|
-
lines.push("test -f tmp/adhdev_provider_fix_test.py");
|
|
90151
|
-
lines.push("python3 tmp/adhdev_provider_fix_test.py");
|
|
90152
|
-
lines.push("```");
|
|
90153
|
-
lines.push("");
|
|
90154
|
-
lines.push("### 6. Stop the CLI when finished");
|
|
90155
|
-
lines.push("```bash");
|
|
90156
|
-
lines.push(`curl -sS -X POST http://127.0.0.1:${DEV_SERVER_PORT}/api/cli/stop \\`);
|
|
90157
|
-
lines.push(' -H "Content-Type: application/json" \\');
|
|
90158
|
-
lines.push(` -d '{"type":"${type}","instanceId":"<INSTANCE_ID>"}'`);
|
|
90159
|
-
lines.push("```");
|
|
90160
|
-
lines.push("");
|
|
90161
|
-
lines.push("## Required Validation");
|
|
90162
|
-
lines.push("1. Confirm `detectStatus` changes sensibly between startup, generating, approval, and idle.");
|
|
90163
|
-
lines.push("2. Confirm `parseSession` produces a stable transcript without duplicating past turns when the PTY redraws.");
|
|
90164
|
-
lines.push("3. Confirm the latest assistant message streams through `partialResponse` while generation is in progress.");
|
|
90165
|
-
lines.push("4. Confirm approval parsing returns meaningful button labels when the CLI requests permission.");
|
|
90166
|
-
lines.push("5. Confirm the Python file was actually created and executed, not just described in chat text.");
|
|
90167
|
-
lines.push("6. Confirm the final assistant transcript includes the exact Python output, including the working directory line and the five square numbers.");
|
|
90168
|
-
lines.push("7. Re-run the debug endpoints after edits. Do NOT finish until the parsed result looks correct.");
|
|
90169
|
-
lines.push("8. Confirm the parser still works after a redraw or scroll change without duplicating transcript history.");
|
|
90170
|
-
lines.push("9. Confirm the implementation prefers current-screen signals over stale history when both are present.");
|
|
90171
|
-
lines.push("");
|
|
90172
|
-
if (userComment) {
|
|
90173
|
-
lines.push("## \u26A0\uFE0F User Instructions (HIGH PRIORITY)");
|
|
90174
|
-
lines.push("The user has provided the following additional instructions. Follow them strictly:");
|
|
90175
|
-
lines.push("");
|
|
90176
|
-
lines.push(userComment);
|
|
90177
|
-
lines.push("");
|
|
90178
|
-
}
|
|
90179
|
-
lines.push("Start NOW. Launch the CLI, inspect PTY state, edit the scripts, and verify via the CLI debug endpoints.");
|
|
90180
|
-
return lines.join("\n");
|
|
90181
|
-
}
|
|
90182
89733
|
handleAutoImplSSE(type, req, res) {
|
|
90183
89734
|
handleAutoImplSSE(this, type, req, res);
|
|
90184
89735
|
}
|