opencode-self-improvement 0.15.16 → 0.15.18
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/identity/session-context.ts +39 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-self-improvement",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.18",
|
|
4
4
|
"description": "Durable memory for opencode: remember facts, decisions, and commands across sessions, plus a one-command per-repo setup (/repo-init).",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"exports": {
|
|
@@ -96,18 +96,27 @@ export function createSessionContext(
|
|
|
96
96
|
// so this path is a legacy-shape best-effort; the session-row fallback
|
|
97
97
|
// below is what actually resolves serve-host sessions.
|
|
98
98
|
// One-shot: never overwrites an event-bound entry.
|
|
99
|
-
const
|
|
99
|
+
const messageBindings = new Map<string, Promise<void>>();
|
|
100
100
|
async function bindSessionFromMessages(sid: string | undefined): Promise<void> {
|
|
101
|
-
if (!sid || sid === "?" || sessionDirFirm(sid)
|
|
102
|
-
|
|
101
|
+
if (!sid || sid === "?" || sessionDirFirm(sid)) return;
|
|
102
|
+
const pending = messageBindings.get(sid);
|
|
103
|
+
if (pending) return pending;
|
|
104
|
+
// Publish the promise before invoking the host: concurrent callers must
|
|
105
|
+
// await this identity source rather than fall through to a provisional one.
|
|
106
|
+
const binding = Promise.resolve().then(async () => {
|
|
107
|
+
try {
|
|
108
|
+
const msgs = await ctx.session?.context?.({ sessionID: sid });
|
|
109
|
+
const dir = sessionDirectoryFromMessages(msgs);
|
|
110
|
+
if (dir !== undefined) rememberSessionDir(sid, dir);
|
|
111
|
+
} catch {
|
|
112
|
+
// no context access or host error: the event stream still binds later
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
messageBindings.set(sid, binding);
|
|
103
116
|
try {
|
|
104
|
-
|
|
105
|
-
const dir = sessionDirectoryFromMessages(msgs);
|
|
106
|
-
if (dir !== undefined) rememberSessionDir(sid, dir);
|
|
107
|
-
} catch {
|
|
108
|
-
// no context access or host error: the event stream still binds later
|
|
117
|
+
await binding;
|
|
109
118
|
} finally {
|
|
110
|
-
|
|
119
|
+
messageBindings.delete(sid);
|
|
111
120
|
}
|
|
112
121
|
}
|
|
113
122
|
|
|
@@ -120,16 +129,30 @@ export function createSessionContext(
|
|
|
120
129
|
// not re-asked on every turn (bounded LRU, same cap as the scope cache).
|
|
121
130
|
const apiBindTried = new Set<string>();
|
|
122
131
|
const apiBindOrder = new SessionLru(SESSION_CAP, (evicted) => apiBindTried.delete(evicted));
|
|
132
|
+
const apiBindings = new Map<string, Promise<void>>();
|
|
123
133
|
async function bindSessionFromApi(sid: string | undefined): Promise<void> {
|
|
124
|
-
if (!sid || sid === "?" || sessionDirFirm(sid)
|
|
134
|
+
if (!sid || sid === "?" || sessionDirFirm(sid)) return;
|
|
135
|
+
// An event may already be fetching this row. Join it before consulting
|
|
136
|
+
// the completed-attempt cache, which also records attempts still in flight.
|
|
137
|
+
const pending = apiBindings.get(sid);
|
|
138
|
+
if (pending) return pending;
|
|
139
|
+
if (apiBindTried.has(sid)) return;
|
|
125
140
|
apiBindTried.add(sid);
|
|
126
141
|
apiBindOrder.touch(sid);
|
|
142
|
+
const binding = Promise.resolve().then(async () => {
|
|
143
|
+
try {
|
|
144
|
+
const got = await ctx.session?.get?.({ sessionID: sid });
|
|
145
|
+
const dir = sessionDirectoryFromRow(got);
|
|
146
|
+
if (dir !== undefined) rememberSessionDir(sid, dir);
|
|
147
|
+
} catch {
|
|
148
|
+
// no session.get on this host (or unknown session): stay unbound
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
apiBindings.set(sid, binding);
|
|
127
152
|
try {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
} catch {
|
|
132
|
-
// no session.get on this host (or unknown session): stay unbound
|
|
153
|
+
await binding;
|
|
154
|
+
} finally {
|
|
155
|
+
apiBindings.delete(sid);
|
|
133
156
|
}
|
|
134
157
|
}
|
|
135
158
|
|
|
@@ -147,4 +170,4 @@ export function createSessionContext(
|
|
|
147
170
|
}
|
|
148
171
|
|
|
149
172
|
return { gateContext, ownerlessWriter, refuseOwnerlessWrite, toolIds, bindSessionFromApi, bindSessionIdentity };
|
|
150
|
-
}
|
|
173
|
+
}
|