@xqli02/mneme 0.1.12 → 0.1.13
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/auto.mjs +17 -4
- package/src/opencode-client.mjs +9 -5
package/package.json
CHANGED
package/src/commands/auto.mjs
CHANGED
|
@@ -516,6 +516,7 @@ function createEventDisplay(client) {
|
|
|
516
516
|
let currentRole = null;
|
|
517
517
|
let lastOutputTime = 0;
|
|
518
518
|
let hasReceivedAny = false;
|
|
519
|
+
let abortController = null;
|
|
519
520
|
|
|
520
521
|
const printedTextLengths = new Map();
|
|
521
522
|
const displayedToolStates = new Map();
|
|
@@ -523,8 +524,9 @@ function createEventDisplay(client) {
|
|
|
523
524
|
|
|
524
525
|
async function start() {
|
|
525
526
|
running = true;
|
|
527
|
+
abortController = new AbortController();
|
|
526
528
|
try {
|
|
527
|
-
const iterator = await client.events.subscribe();
|
|
529
|
+
const iterator = await client.events.subscribe({ signal: abortController.signal });
|
|
528
530
|
connected = true;
|
|
529
531
|
hasReceivedAny = false;
|
|
530
532
|
log.ok("SSE event stream connected");
|
|
@@ -535,7 +537,7 @@ function createEventDisplay(client) {
|
|
|
535
537
|
}
|
|
536
538
|
} catch (err) {
|
|
537
539
|
connected = false;
|
|
538
|
-
if (running) {
|
|
540
|
+
if (running && err.name !== "AbortError") {
|
|
539
541
|
console.error(
|
|
540
542
|
color.dim(`\n [events] Stream error: ${err.message}`),
|
|
541
543
|
);
|
|
@@ -687,6 +689,10 @@ function createEventDisplay(client) {
|
|
|
687
689
|
|
|
688
690
|
function stop() {
|
|
689
691
|
running = false;
|
|
692
|
+
if (abortController) {
|
|
693
|
+
abortController.abort();
|
|
694
|
+
abortController = null;
|
|
695
|
+
}
|
|
690
696
|
if (turnResolve) {
|
|
691
697
|
turnResolve("stopped");
|
|
692
698
|
turnResolve = null;
|
|
@@ -717,6 +723,7 @@ function createDaemonEventMonitor(client, dlog) {
|
|
|
717
723
|
let turnResolve = null;
|
|
718
724
|
let lastOutputTime = 0;
|
|
719
725
|
let hasReceivedAny = false;
|
|
726
|
+
let abortController = null;
|
|
720
727
|
|
|
721
728
|
// Track known prompt texts we sent — to distinguish user messages
|
|
722
729
|
const knownPromptTexts = new Set();
|
|
@@ -726,8 +733,9 @@ function createDaemonEventMonitor(client, dlog) {
|
|
|
726
733
|
|
|
727
734
|
async function start() {
|
|
728
735
|
running = true;
|
|
736
|
+
abortController = new AbortController();
|
|
729
737
|
try {
|
|
730
|
-
const iterator = await client.events.subscribe();
|
|
738
|
+
const iterator = await client.events.subscribe({ signal: abortController.signal });
|
|
731
739
|
connected = true;
|
|
732
740
|
hasReceivedAny = false;
|
|
733
741
|
dlog.ok("SSE event stream connected (daemon)");
|
|
@@ -738,7 +746,7 @@ function createDaemonEventMonitor(client, dlog) {
|
|
|
738
746
|
}
|
|
739
747
|
} catch (err) {
|
|
740
748
|
connected = false;
|
|
741
|
-
if (running) {
|
|
749
|
+
if (running && err.name !== "AbortError") {
|
|
742
750
|
dlog.warn(`SSE stream error: ${err.message}`);
|
|
743
751
|
await sleep(2000);
|
|
744
752
|
if (running) {
|
|
@@ -835,6 +843,10 @@ function createDaemonEventMonitor(client, dlog) {
|
|
|
835
843
|
|
|
836
844
|
function stop() {
|
|
837
845
|
running = false;
|
|
846
|
+
if (abortController) {
|
|
847
|
+
abortController.abort();
|
|
848
|
+
abortController = null;
|
|
849
|
+
}
|
|
838
850
|
if (turnResolve) {
|
|
839
851
|
turnResolve("stopped");
|
|
840
852
|
turnResolve = null;
|
|
@@ -1892,6 +1904,7 @@ async function runHeadlessMode(opts) {
|
|
|
1892
1904
|
serverCtx.serverProcess.kill("SIGTERM");
|
|
1893
1905
|
}
|
|
1894
1906
|
log.ok("mneme auto finished.");
|
|
1907
|
+
process.exit(0);
|
|
1895
1908
|
}
|
|
1896
1909
|
}
|
|
1897
1910
|
|
package/src/opencode-client.mjs
CHANGED
|
@@ -37,12 +37,16 @@ export function createClient(baseUrl) {
|
|
|
37
37
|
/**
|
|
38
38
|
* Subscribe to SSE event stream.
|
|
39
39
|
* Returns an async iterator of parsed events: { type, properties }.
|
|
40
|
+
* @param {string} path
|
|
41
|
+
* @param {{ signal?: AbortSignal }} [opts]
|
|
40
42
|
*/
|
|
41
|
-
async function* subscribeEvents(path = "/event") {
|
|
43
|
+
async function* subscribeEvents(path = "/event", opts = {}) {
|
|
42
44
|
const url = `${base}${path}`;
|
|
43
|
-
const
|
|
45
|
+
const fetchOpts = {
|
|
44
46
|
headers: { Accept: "text/event-stream" },
|
|
45
|
-
}
|
|
47
|
+
};
|
|
48
|
+
if (opts.signal) fetchOpts.signal = opts.signal;
|
|
49
|
+
const res = await fetch(url, fetchOpts);
|
|
46
50
|
if (!res.ok) {
|
|
47
51
|
throw new Error(`SSE connect failed: ${res.status}`);
|
|
48
52
|
}
|
|
@@ -126,8 +130,8 @@ export function createClient(baseUrl) {
|
|
|
126
130
|
|
|
127
131
|
/** Events */
|
|
128
132
|
events: {
|
|
129
|
-
subscribe: () => subscribeEvents("/event"),
|
|
130
|
-
subscribeGlobal: () => subscribeEvents("/global/event"),
|
|
133
|
+
subscribe: (opts) => subscribeEvents("/event", opts),
|
|
134
|
+
subscribeGlobal: (opts) => subscribeEvents("/global/event", opts),
|
|
131
135
|
},
|
|
132
136
|
|
|
133
137
|
/** Raw request for anything else */
|