opencode-codex-memory 0.10.0 → 0.10.2
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/README.md +10 -12
- package/dist/src/agent-health.js +10 -7
- package/dist/src/capture.js +7 -7
- package/dist/src/citation.js +12 -3
- package/dist/src/claude-import.js +1 -3
- package/dist/src/codex-interop.js +51 -17
- package/dist/src/db.d.ts +0 -2
- package/dist/src/db.js +0 -4
- package/dist/src/git-baseline.d.ts +10 -11
- package/dist/src/git-baseline.js +167 -97
- package/dist/src/host-client.d.ts +5 -0
- package/dist/src/host-client.js +24 -0
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +56 -99
- package/dist/src/llm.d.ts +4 -1
- package/dist/src/llm.js +43 -15
- package/dist/src/options.d.ts +7 -0
- package/dist/src/options.js +20 -2
- package/dist/src/paths.d.ts +1 -0
- package/dist/src/paths.js +5 -2
- package/dist/src/phase1.js +12 -21
- package/dist/src/phase2.js +7 -6
- package/dist/src/reasoning-variant.d.ts +7 -0
- package/dist/src/reasoning-variant.js +11 -2
- package/dist/src/rollout-input.js +3 -5
- package/dist/src/session-version.js +4 -5
- package/dist/src/source.js +6 -2
- package/dist/src/store.d.ts +3 -2
- package/dist/src/store.js +72 -47
- package/dist/src/v2/agents.js +11 -14
- package/dist/src/v2/model-readiness.js +3 -1
- package/dist/src/v2/plugin.js +81 -109
- package/dist/src/v2/search-sandbox.js +1 -1
- package/dist/src/v2/service.js +5 -0
- package/dist/src/v2/shim.d.ts +3 -0
- package/dist/src/v2/shim.js +144 -90
- package/dist/src/v2/status-rpc.js +40 -14
- package/dist/src/v2/status.js +4 -7
- package/dist/src/v2/tools.d.ts +15 -9
- package/dist/src/v2/tools.js +9 -9
- package/dist/src/v2/tui.js +14 -4
- package/dist/src/workspace.js +13 -4
- package/dist/tools/control.js +29 -28
- package/dist/tools/memory.js +163 -89
- package/package.json +22 -9
package/dist/src/v2/shim.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { memoryRoot } from "../paths.js";
|
|
2
2
|
import { consolidationPermissions } from "./agents.js";
|
|
3
3
|
import { retryModelSelection } from "./model-readiness.js";
|
|
4
|
-
import { invalidateOwnService, lastServiceFailure, ownServiceClient, serviceRequest } from "./service.js";
|
|
4
|
+
import { invalidateOwnService, lastServiceFailure, ownServiceClient, serviceRequest, } from "./service.js";
|
|
5
5
|
let v2ctx = null;
|
|
6
6
|
let discoveryStatus = null;
|
|
7
7
|
/** Last completed list's scope; inspect/status must not initiate discovery. */
|
|
@@ -36,16 +36,10 @@ function isNotFoundError(e) {
|
|
|
36
36
|
}
|
|
37
37
|
return false;
|
|
38
38
|
}
|
|
39
|
-
async function
|
|
40
|
-
if (typeof client.session.get !== "function")
|
|
41
|
-
return false;
|
|
39
|
+
async function confirmRemoval(get) {
|
|
42
40
|
try {
|
|
43
|
-
const info = await
|
|
44
|
-
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
const data = und(info);
|
|
48
|
-
return !data || typeof data !== "object";
|
|
41
|
+
const info = await get();
|
|
42
|
+
return isNotFoundError(info?.error);
|
|
49
43
|
}
|
|
50
44
|
catch (e) {
|
|
51
45
|
return isNotFoundError(e);
|
|
@@ -53,8 +47,10 @@ async function sessionGoneOnService(client, sessionID) {
|
|
|
53
47
|
}
|
|
54
48
|
/** Sub-session ids released via delete(): report 404 from get(). */
|
|
55
49
|
const releasedSubSessions = new Set();
|
|
50
|
+
const helperOwners = new Map();
|
|
56
51
|
const RELEASED_CAP = 500;
|
|
57
52
|
function markReleased(id) {
|
|
53
|
+
helperOwners.delete(id);
|
|
58
54
|
releasedSubSessions.add(id);
|
|
59
55
|
if (releasedSubSessions.size > RELEASED_CAP) {
|
|
60
56
|
const oldest = releasedSubSessions.values().next().value;
|
|
@@ -117,6 +113,7 @@ function listObservedSessions(limit, cursor, search) {
|
|
|
117
113
|
}
|
|
118
114
|
/** Test seam. */
|
|
119
115
|
export function resetV2ShimStateForTest() {
|
|
116
|
+
helperOwners.clear();
|
|
120
117
|
releasedSubSessions.clear();
|
|
121
118
|
observedSessions.clear();
|
|
122
119
|
discoveryStatus = null;
|
|
@@ -130,7 +127,10 @@ function joinTextParts(content) {
|
|
|
130
127
|
return "";
|
|
131
128
|
const out = [];
|
|
132
129
|
for (const p of content) {
|
|
133
|
-
if (p &&
|
|
130
|
+
if (p &&
|
|
131
|
+
typeof p === "object" &&
|
|
132
|
+
p.type === "text" &&
|
|
133
|
+
typeof p.text === "string") {
|
|
134
134
|
out.push(p.text);
|
|
135
135
|
}
|
|
136
136
|
else if (typeof p === "string") {
|
|
@@ -168,36 +168,25 @@ export function adaptV2Messages(msgs) {
|
|
|
168
168
|
else if (p.type === "reasoning")
|
|
169
169
|
parts.push({ type: "reasoning" });
|
|
170
170
|
else if (p.type === "tool") {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
//
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
const outputText = joinTextParts(st.content);
|
|
191
|
-
parts.push({
|
|
192
|
-
type: "tool",
|
|
193
|
-
tool: p.name ?? "unknown",
|
|
194
|
-
state: {
|
|
195
|
-
...(st.input !== undefined ? { input: st.input } : {}),
|
|
196
|
-
...(outputText ? { output: outputText } : {}),
|
|
197
|
-
...(typeof st.error === "string" ? { error: st.error } : {}),
|
|
198
|
-
},
|
|
199
|
-
});
|
|
200
|
-
}
|
|
171
|
+
const st = p.state ?? {};
|
|
172
|
+
const calls = st.metadata?.toolCalls ?? p.metadata?.toolCalls;
|
|
173
|
+
// Code Mode stores one program result. Nested calls only have a
|
|
174
|
+
// name, inputs and status; the result cannot be attributed to them.
|
|
175
|
+
const input = p.name === "execute" && Array.isArray(calls) && calls.length
|
|
176
|
+
? { program: st.input, nestedCalls: calls.map(({ tool, input, status }) => ({ tool, input, status })) }
|
|
177
|
+
: st.input;
|
|
178
|
+
const message = typeof st.error === "string" ? st.error : st.error?.message;
|
|
179
|
+
const error = typeof message === "string" ? message.slice(0, 4000) : undefined;
|
|
180
|
+
const content = joinTextParts(st.content);
|
|
181
|
+
parts.push({
|
|
182
|
+
type: "tool",
|
|
183
|
+
tool: p.name ?? "unknown",
|
|
184
|
+
state: {
|
|
185
|
+
...(input !== undefined ? { input } : {}),
|
|
186
|
+
...(content ? { output: error ? `${content}\n[error] ${error}` : content } : {}),
|
|
187
|
+
...(error ? { error } : {}),
|
|
188
|
+
},
|
|
189
|
+
});
|
|
201
190
|
}
|
|
202
191
|
}
|
|
203
192
|
rows.push({ info: { role: "assistant" }, parts });
|
|
@@ -216,7 +205,7 @@ export function adaptV2Messages(msgs) {
|
|
|
216
205
|
/** V2 model.list (legacy catalog.model.list) → V1 provider-list shape. */
|
|
217
206
|
export function adaptProviderCatalog(v2) {
|
|
218
207
|
const items = und(v2);
|
|
219
|
-
const list = Array.isArray(items) ? items : items?.data ?? [];
|
|
208
|
+
const list = Array.isArray(items) ? items : (items?.data ?? []);
|
|
220
209
|
const providers = new Map();
|
|
221
210
|
for (const m of list) {
|
|
222
211
|
if (!m || typeof m !== "object")
|
|
@@ -232,11 +221,16 @@ export function adaptProviderCatalog(v2) {
|
|
|
232
221
|
const variants = {};
|
|
233
222
|
for (const v of m.variants ?? []) {
|
|
234
223
|
if (v && typeof v === "object" && typeof v.id === "string") {
|
|
235
|
-
variants[v.id] = {
|
|
224
|
+
variants[v.id] = {
|
|
225
|
+
...(typeof v.disabled === "boolean" ? { disabled: v.disabled } : {}),
|
|
226
|
+
};
|
|
236
227
|
}
|
|
237
228
|
}
|
|
238
229
|
;
|
|
239
|
-
providers.get(providerID)[modelID] = {
|
|
230
|
+
providers.get(providerID)[modelID] = {
|
|
231
|
+
...(m.limit ? { limit: m.limit } : {}),
|
|
232
|
+
...(m.variants !== undefined ? { variants } : {}),
|
|
233
|
+
};
|
|
240
234
|
}
|
|
241
235
|
return { all: [...providers.entries()].map(([id, models]) => ({ id, models })) };
|
|
242
236
|
}
|
|
@@ -274,14 +268,39 @@ function responseNextCursor(response) {
|
|
|
274
268
|
const next = direct ?? payload?.cursor?.next;
|
|
275
269
|
return typeof next === "string" && next.length > 0 ? next : undefined;
|
|
276
270
|
}
|
|
271
|
+
// Some host context methods don't accept request options. Share identical
|
|
272
|
+
// reads and keep the slot until the actual call settles, even if its caller
|
|
273
|
+
// has timed out. Retries can't grow an unbounded queue on a stalled host.
|
|
274
|
+
const localReads = new WeakMap();
|
|
275
|
+
function localRead(owner, key, signal, read) {
|
|
276
|
+
signal?.throwIfAborted();
|
|
277
|
+
let reads = localReads.get(owner);
|
|
278
|
+
if (!reads)
|
|
279
|
+
localReads.set(owner, (reads = new Map()));
|
|
280
|
+
let request = reads.get(key);
|
|
281
|
+
if (!request) {
|
|
282
|
+
if (reads.size >= 32)
|
|
283
|
+
throw new Error("OpenCode context read limit reached");
|
|
284
|
+
request = Promise.resolve()
|
|
285
|
+
.then(read)
|
|
286
|
+
.finally(() => reads.delete(key));
|
|
287
|
+
reads.set(key, request);
|
|
288
|
+
}
|
|
289
|
+
return signal ? raceAbort(request, signal) : request;
|
|
290
|
+
}
|
|
291
|
+
export async function localMcpStatus(owner, signal) {
|
|
292
|
+
return { data: adaptMcpStatus(await localRead(owner, "mcp", signal, () => owner.mcp.list())) };
|
|
293
|
+
}
|
|
277
294
|
/** Read durable messages in source order, including terminal errors/idle rows. */
|
|
278
295
|
async function loadV2Messages(sessionID, context, signal) {
|
|
296
|
+
signal?.throwIfAborted();
|
|
279
297
|
const client = await ownServiceClient();
|
|
280
298
|
if (typeof client?.message?.list === "function") {
|
|
281
299
|
const messages = [];
|
|
282
300
|
const seenCursors = new Set();
|
|
283
301
|
let cursor;
|
|
284
302
|
while (true) {
|
|
303
|
+
signal?.throwIfAborted();
|
|
285
304
|
const response = await serviceRequest(client, () => client.message.list(cursor ? { sessionID, cursor } : { sessionID, order: "asc" }, signal ? { signal } : undefined));
|
|
286
305
|
const rows = responseRows(response);
|
|
287
306
|
if (!rows)
|
|
@@ -300,7 +319,8 @@ async function loadV2Messages(sessionID, context, signal) {
|
|
|
300
319
|
// on, not the full transcript: the originals before it are gone here, so
|
|
301
320
|
// the compaction summary is the only record of them. (message.list above
|
|
302
321
|
// keeps the originals; there the summary would duplicate them.)
|
|
303
|
-
const
|
|
322
|
+
const owner = context ?? ctx();
|
|
323
|
+
const raw = await localRead(owner, `messages:${sessionID}`, signal, () => owner.session.context({ sessionID }));
|
|
304
324
|
const rows = responseRows(raw);
|
|
305
325
|
if (!rows)
|
|
306
326
|
throw new Error("session context returned an invalid message list");
|
|
@@ -321,10 +341,20 @@ function completedPromptResponse(rows, promptID) {
|
|
|
321
341
|
if (assistant.error) {
|
|
322
342
|
// V1 runPrompt recognizes info.error, including its quota status code.
|
|
323
343
|
const error = assistant.error;
|
|
324
|
-
return {
|
|
344
|
+
return {
|
|
345
|
+
data: {
|
|
346
|
+
info: {
|
|
347
|
+
error: {
|
|
325
348
|
name: error.type ?? error.name,
|
|
326
|
-
data: {
|
|
327
|
-
|
|
349
|
+
data: {
|
|
350
|
+
message: error.message ?? error.data?.message,
|
|
351
|
+
statusCode: error.status ?? error.statusCode ?? error.data?.statusCode,
|
|
352
|
+
},
|
|
353
|
+
},
|
|
354
|
+
},
|
|
355
|
+
parts: [],
|
|
356
|
+
},
|
|
357
|
+
};
|
|
328
358
|
}
|
|
329
359
|
const idle = messages.findLast((m) => m?.type === "idle");
|
|
330
360
|
if (idle && idle.outcome !== "succeeded")
|
|
@@ -365,7 +395,7 @@ function raceAbort(promise, signal) {
|
|
|
365
395
|
});
|
|
366
396
|
}
|
|
367
397
|
async function v2promptWithWait(sessionID, body, signal) {
|
|
368
|
-
const c = ctx();
|
|
398
|
+
const c = helperOwners.get(sessionID) ?? ctx();
|
|
369
399
|
const text = body.parts.map((p) => p.text ?? "").join("\n");
|
|
370
400
|
// Structured-output extraction: V2 prompts carry text only, so run the
|
|
371
401
|
// turn through generate.text (inherently tool-less, like the V1
|
|
@@ -387,11 +417,15 @@ async function v2promptWithWait(sessionID, body, signal) {
|
|
|
387
417
|
// that complete reference; never emit a variant-only model object.
|
|
388
418
|
const payload = {
|
|
389
419
|
prompt,
|
|
390
|
-
...(parsed
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
420
|
+
...(parsed
|
|
421
|
+
? {
|
|
422
|
+
model: {
|
|
423
|
+
providerID: parsed.providerID,
|
|
424
|
+
id: parsed.modelID,
|
|
425
|
+
...(body.variant ? { variant: body.variant } : {}),
|
|
426
|
+
},
|
|
427
|
+
}
|
|
428
|
+
: {}),
|
|
395
429
|
};
|
|
396
430
|
if (signal?.aborted)
|
|
397
431
|
throw new Error("sub-agent prompt cancelled");
|
|
@@ -408,7 +442,8 @@ async function v2promptWithWait(sessionID, body, signal) {
|
|
|
408
442
|
}
|
|
409
443
|
// ctx.generate.text ignores request-option signals. Race AbortSignal.
|
|
410
444
|
const gen = und(await retryModelSelection(async () => {
|
|
411
|
-
const
|
|
445
|
+
const generation = c.experimental?.generate ?? c.generate;
|
|
446
|
+
const genP = generation.text(payload);
|
|
412
447
|
const result = signal ? await raceAbort(genP, signal) : await genP;
|
|
413
448
|
if (result?.error)
|
|
414
449
|
throw result.error;
|
|
@@ -463,13 +498,14 @@ export function buildV1ClientShim() {
|
|
|
463
498
|
}
|
|
464
499
|
return client;
|
|
465
500
|
}
|
|
466
|
-
async function paginateSessionList(listFn, limit, cursor, search) {
|
|
501
|
+
async function paginateSessionList(listFn, limit, cursor, search, signal) {
|
|
467
502
|
const pageSize = Math.min(Math.max(limit, 1), 5000);
|
|
468
503
|
const out = [];
|
|
469
504
|
const seenCursors = new Set();
|
|
470
505
|
const timestampCursor = typeof cursor === "number" ? cursor : undefined;
|
|
471
506
|
let next = typeof cursor === "string" ? cursor : undefined;
|
|
472
507
|
while (out.length < limit) {
|
|
508
|
+
signal?.throwIfAborted();
|
|
473
509
|
const response = (await listFn({
|
|
474
510
|
limit: pageSize,
|
|
475
511
|
order: "desc",
|
|
@@ -480,9 +516,7 @@ export function buildV1ClientShim() {
|
|
|
480
516
|
const rawRows = responseRows(response);
|
|
481
517
|
if (!rawRows)
|
|
482
518
|
throw new Error("registered service returned an invalid session list");
|
|
483
|
-
const rows = rawRows
|
|
484
|
-
.map(adaptV2SessionRow)
|
|
485
|
-
.filter((row) => {
|
|
519
|
+
const rows = rawRows.map(adaptV2SessionRow).filter((row) => {
|
|
486
520
|
if (!row || typeof row !== "object")
|
|
487
521
|
return false;
|
|
488
522
|
const record = row;
|
|
@@ -505,16 +539,18 @@ export function buildV1ClientShim() {
|
|
|
505
539
|
}
|
|
506
540
|
return { data: out.slice(0, limit) };
|
|
507
541
|
}
|
|
508
|
-
async function listGlobalSessions(limit, cursor, search) {
|
|
509
|
-
|
|
542
|
+
async function listGlobalSessions(limit, cursor, search, signal) {
|
|
543
|
+
signal?.throwIfAborted();
|
|
544
|
+
const owner = v2ctx;
|
|
545
|
+
const localList = owner ? owner.session.list : undefined;
|
|
510
546
|
if (typeof localList === "function") {
|
|
511
|
-
const result = await paginateSessionList((input) => localList(input), limit, cursor, search);
|
|
547
|
+
const result = await paginateSessionList((input) => localRead(owner, `list:${JSON.stringify(input)}`, signal, () => localList(input)), limit, cursor, search, signal);
|
|
512
548
|
discoveryStatus = { source: "context", warning: null };
|
|
513
549
|
return result;
|
|
514
550
|
}
|
|
515
551
|
const client = await ownServiceClient();
|
|
516
552
|
if (client && typeof client.session.list === "function") {
|
|
517
|
-
const result = await paginateSessionList((input) => serviceRequest(client, () => client.session.list(input)), limit, cursor, search);
|
|
553
|
+
const result = await paginateSessionList((input) => serviceRequest(client, () => client.session.list(input, { signal })), limit, cursor, search, signal);
|
|
518
554
|
discoveryStatus = { source: "service", warning: null };
|
|
519
555
|
return result;
|
|
520
556
|
}
|
|
@@ -540,7 +576,8 @@ export function buildV1ClientShim() {
|
|
|
540
576
|
return { data: { id: EXTRACT_STUB_SESSION_ID } };
|
|
541
577
|
}
|
|
542
578
|
const directory = opts?.query?.directory ?? memoryRoot();
|
|
543
|
-
const
|
|
579
|
+
const owner = ctx();
|
|
580
|
+
const res = await owner.session.create({
|
|
544
581
|
...(opts?.body?.title ? { title: opts.body.title } : {}),
|
|
545
582
|
...(opts?.body?.metadata ? { metadata: opts.body.metadata } : {}),
|
|
546
583
|
...(opts?.body?.title === "codex-memory-consolidate"
|
|
@@ -548,7 +585,10 @@ export function buildV1ClientShim() {
|
|
|
548
585
|
: {}),
|
|
549
586
|
location: { directory },
|
|
550
587
|
});
|
|
551
|
-
|
|
588
|
+
const id = und(res)?.id;
|
|
589
|
+
if (typeof id === "string")
|
|
590
|
+
helperOwners.set(id, owner);
|
|
591
|
+
return { data: { id } };
|
|
552
592
|
}
|
|
553
593
|
catch (e) {
|
|
554
594
|
return { error: e };
|
|
@@ -563,8 +603,8 @@ export function buildV1ClientShim() {
|
|
|
563
603
|
// "UnexpectedStatus" whose message alone misses the capacity breaker.
|
|
564
604
|
if (!(e instanceof Error))
|
|
565
605
|
return { error: e };
|
|
566
|
-
const status = e.status
|
|
567
|
-
|
|
606
|
+
const status = e.status ??
|
|
607
|
+
e.cause?.status;
|
|
568
608
|
return { error: { message: e.message, ...(typeof status === "number" ? { statusCode: status } : {}) } };
|
|
569
609
|
}
|
|
570
610
|
},
|
|
@@ -572,7 +612,7 @@ export function buildV1ClientShim() {
|
|
|
572
612
|
try {
|
|
573
613
|
if (isReleasedSubSession(opts.path.id))
|
|
574
614
|
throw Object.assign(new Error("SessionNotFound"), { _tag: "SessionNotFoundError" });
|
|
575
|
-
return { data: adaptV2Messages(await loadV2Messages(opts.path.id)) };
|
|
615
|
+
return { data: adaptV2Messages(await loadV2Messages(opts.path.id, undefined, opts.signal)) };
|
|
576
616
|
}
|
|
577
617
|
catch (e) {
|
|
578
618
|
return { error: e };
|
|
@@ -589,17 +629,27 @@ export function buildV1ClientShim() {
|
|
|
589
629
|
// Interrupt where the helper runs first. With a loopback PID mismatch the
|
|
590
630
|
// service is another process: removing the row there alone would leave
|
|
591
631
|
// this process's consolidator editing after the lease is released.
|
|
592
|
-
let interruptError;
|
|
593
632
|
try {
|
|
594
|
-
const
|
|
595
|
-
const interrupt = await
|
|
633
|
+
const local = (helperOwners.get(id) ?? ctx()).session;
|
|
634
|
+
const interrupt = await local.interrupt({ sessionID: id });
|
|
596
635
|
if (interrupt?.error)
|
|
597
636
|
throw interrupt.error;
|
|
598
|
-
|
|
599
|
-
|
|
637
|
+
const idle = await local.wait({ sessionID: id });
|
|
638
|
+
if (idle?.error)
|
|
639
|
+
throw idle.error;
|
|
640
|
+
opts.signal?.throwIfAborted();
|
|
641
|
+
if (typeof local.remove === "function") {
|
|
642
|
+
const result = await local.remove({ sessionID: id });
|
|
643
|
+
if (result?.error)
|
|
644
|
+
throw result.error;
|
|
645
|
+
if (!(await confirmRemoval(() => local.get({ sessionID: id }))))
|
|
646
|
+
throw new Error("local session still exists after remove");
|
|
647
|
+
markReleased(id);
|
|
648
|
+
return {};
|
|
649
|
+
}
|
|
600
650
|
}
|
|
601
651
|
catch (error) {
|
|
602
|
-
|
|
652
|
+
return { error: error ?? new Error("local session shutdown failed") };
|
|
603
653
|
}
|
|
604
654
|
let client = null;
|
|
605
655
|
let removeError;
|
|
@@ -618,14 +668,15 @@ export function buildV1ClientShim() {
|
|
|
618
668
|
removeError = error;
|
|
619
669
|
}
|
|
620
670
|
if (client && typeof client.session.get === "function") {
|
|
621
|
-
|
|
671
|
+
const service = client;
|
|
672
|
+
if (await confirmRemoval(() => serviceRequest(service, () => service.session.get({ sessionID: id }, { signal: opts.signal })))) {
|
|
622
673
|
markReleased(id);
|
|
623
674
|
return {};
|
|
624
675
|
}
|
|
625
|
-
return { error: removeError ??
|
|
676
|
+
return { error: removeError ?? new Error("session still exists after remove") };
|
|
626
677
|
}
|
|
627
|
-
if (
|
|
628
|
-
return { error: removeError
|
|
678
|
+
if (removeError !== undefined)
|
|
679
|
+
return { error: removeError };
|
|
629
680
|
// Isolated serve: no session.remove on plugin ctx. interrupt+wait already
|
|
630
681
|
// finished, so the helper is idle. Holding the phase-2 lease until it
|
|
631
682
|
// expires would block consolidation for an hour.
|
|
@@ -640,7 +691,8 @@ export function buildV1ClientShim() {
|
|
|
640
691
|
const client = await ownServiceClient();
|
|
641
692
|
if (client?.session?.get) {
|
|
642
693
|
try {
|
|
643
|
-
|
|
694
|
+
opts.signal?.throwIfAborted();
|
|
695
|
+
const info = und(await serviceRequest(client, () => client.session.get({ sessionID: opts.path.id }, { signal: opts.signal })));
|
|
644
696
|
return { data: info };
|
|
645
697
|
}
|
|
646
698
|
catch (e) {
|
|
@@ -649,7 +701,8 @@ export function buildV1ClientShim() {
|
|
|
649
701
|
return { error: e };
|
|
650
702
|
}
|
|
651
703
|
}
|
|
652
|
-
const
|
|
704
|
+
const owner = ctx();
|
|
705
|
+
const info = und(await localRead(owner, `get:${opts.path.id}`, opts.signal, () => owner.session.get({ sessionID: opts.path.id })));
|
|
653
706
|
return { data: info };
|
|
654
707
|
}
|
|
655
708
|
catch (e) {
|
|
@@ -663,7 +716,9 @@ export function buildV1ClientShim() {
|
|
|
663
716
|
return {};
|
|
664
717
|
// Local first: the helper runs in this process (see delete above).
|
|
665
718
|
try {
|
|
666
|
-
const result = await
|
|
719
|
+
const result = await (helperOwners.get(opts.path.id) ?? ctx()).session.interrupt({
|
|
720
|
+
sessionID: opts.path.id,
|
|
721
|
+
});
|
|
667
722
|
if (!result?.error)
|
|
668
723
|
return {};
|
|
669
724
|
}
|
|
@@ -683,10 +738,10 @@ export function buildV1ClientShim() {
|
|
|
683
738
|
},
|
|
684
739
|
};
|
|
685
740
|
const config = {
|
|
686
|
-
get: async () => {
|
|
741
|
+
get: async (opts) => {
|
|
687
742
|
try {
|
|
688
743
|
const client = await serviceOrThrow();
|
|
689
|
-
const response = await serviceRequest(client, async () => client.config?.get({ location: { directory: ctx().location.directory } }));
|
|
744
|
+
const response = await serviceRequest(client, async () => client.config?.get({ location: { directory: ctx().location.directory } }, opts));
|
|
690
745
|
const documents = und(response);
|
|
691
746
|
const candidates = Array.isArray(documents) ? documents : documents?.type === "document" ? [documents] : [];
|
|
692
747
|
let info = {};
|
|
@@ -715,13 +770,13 @@ export function buildV1ClientShim() {
|
|
|
715
770
|
},
|
|
716
771
|
};
|
|
717
772
|
const provider = {
|
|
718
|
-
list: async () => {
|
|
773
|
+
list: async (opts) => {
|
|
719
774
|
try {
|
|
720
775
|
const c = ctx();
|
|
721
776
|
const models = c.model ?? c.catalog?.model;
|
|
722
777
|
if (typeof models?.list !== "function")
|
|
723
778
|
throw new Error("host does not support model.list");
|
|
724
|
-
const res = await models.list();
|
|
779
|
+
const res = await localRead(c, "models", opts?.signal, () => models.list());
|
|
725
780
|
return { data: adaptProviderCatalog(res) };
|
|
726
781
|
}
|
|
727
782
|
catch (e) {
|
|
@@ -730,10 +785,9 @@ export function buildV1ClientShim() {
|
|
|
730
785
|
},
|
|
731
786
|
};
|
|
732
787
|
const mcp = {
|
|
733
|
-
status: async () => {
|
|
788
|
+
status: async (opts) => {
|
|
734
789
|
try {
|
|
735
|
-
|
|
736
|
-
return { data: adaptMcpStatus(res) };
|
|
790
|
+
return await localMcpStatus(ctx(), opts?.signal);
|
|
737
791
|
}
|
|
738
792
|
catch (e) {
|
|
739
793
|
return { error: e };
|
|
@@ -745,10 +799,10 @@ export function buildV1ClientShim() {
|
|
|
745
799
|
if (opts.url === "/experimental/session") {
|
|
746
800
|
const q = opts.query ?? {};
|
|
747
801
|
const cursor = typeof q.cursor === "number" || typeof q.cursor === "string" ? q.cursor : undefined;
|
|
748
|
-
return listGlobalSessions(typeof q.limit === "number" ? q.limit : 5000, cursor, typeof q.search === "string" ? q.search : undefined);
|
|
802
|
+
return listGlobalSessions(typeof q.limit === "number" ? q.limit : 5000, cursor, typeof q.search === "string" ? q.search : undefined, opts.signal);
|
|
749
803
|
}
|
|
750
804
|
if (opts.url === "/provider") {
|
|
751
|
-
return provider.list();
|
|
805
|
+
return provider.list(opts);
|
|
752
806
|
}
|
|
753
807
|
return { error: { message: `unsupported shim route ${opts.url}` } };
|
|
754
808
|
},
|
|
@@ -84,7 +84,13 @@ export const MemoryStatusRpc = {
|
|
|
84
84
|
},
|
|
85
85
|
required: [
|
|
86
86
|
"activity",
|
|
87
|
-
"version",
|
|
87
|
+
"version",
|
|
88
|
+
"sessionVersion",
|
|
89
|
+
"dualWrite",
|
|
90
|
+
"v2ConsolidatedThreads",
|
|
91
|
+
"v2Ready",
|
|
92
|
+
"minConsolidatedThreads",
|
|
93
|
+
"pipelines",
|
|
88
94
|
"useMemories",
|
|
89
95
|
"generateMemories",
|
|
90
96
|
"extractModel",
|
|
@@ -111,7 +117,12 @@ export const MemoryStatusRpc = {
|
|
|
111
117
|
required: ["key", "value"],
|
|
112
118
|
additionalProperties: false,
|
|
113
119
|
},
|
|
114
|
-
output: {
|
|
120
|
+
output: {
|
|
121
|
+
type: "object",
|
|
122
|
+
properties: { ok: { type: "boolean" } },
|
|
123
|
+
required: ["ok"],
|
|
124
|
+
additionalProperties: false,
|
|
125
|
+
},
|
|
115
126
|
},
|
|
116
127
|
/** Same effect as the memory_mode tool. */
|
|
117
128
|
setSessionMode: {
|
|
@@ -124,7 +135,12 @@ export const MemoryStatusRpc = {
|
|
|
124
135
|
required: ["sessionID", "mode"],
|
|
125
136
|
additionalProperties: false,
|
|
126
137
|
},
|
|
127
|
-
output: {
|
|
138
|
+
output: {
|
|
139
|
+
type: "object",
|
|
140
|
+
properties: { ok: { type: "boolean" } },
|
|
141
|
+
required: ["ok"],
|
|
142
|
+
additionalProperties: false,
|
|
143
|
+
},
|
|
128
144
|
},
|
|
129
145
|
/** Run extraction + consolidation now, bypassing the success cooldown (not the lease). */
|
|
130
146
|
consolidateNow: {
|
|
@@ -163,8 +179,7 @@ function isRecord(value) {
|
|
|
163
179
|
export function isMemoryStatus(value) {
|
|
164
180
|
if (!isRecord(value))
|
|
165
181
|
return false;
|
|
166
|
-
if (typeof value.activity !== "string" ||
|
|
167
|
-
!MEMORY_STATUS_ACTIVITIES.includes(value.activity)) {
|
|
182
|
+
if (typeof value.activity !== "string" || !MEMORY_STATUS_ACTIVITIES.includes(value.activity)) {
|
|
168
183
|
return false;
|
|
169
184
|
}
|
|
170
185
|
for (const key of ["useMemories", "generateMemories", "codexImport", "dualWrite", "v2Ready"]) {
|
|
@@ -177,23 +192,34 @@ export function isMemoryStatus(value) {
|
|
|
177
192
|
}
|
|
178
193
|
if (!Number.isInteger(value.v2ConsolidatedThreads) || value.v2ConsolidatedThreads < 0)
|
|
179
194
|
return false;
|
|
180
|
-
if (value.v2NotReadyReason !== undefined &&
|
|
195
|
+
if (value.v2NotReadyReason !== undefined &&
|
|
196
|
+
value.v2NotReadyReason !== null &&
|
|
197
|
+
typeof value.v2NotReadyReason !== "string")
|
|
181
198
|
return false;
|
|
182
199
|
for (const key of ["v2SummaryBytes", "v2InjectedSummaryBytes"]) {
|
|
183
|
-
if (value[key] !== undefined &&
|
|
200
|
+
if (value[key] !== undefined &&
|
|
201
|
+
value[key] !== null &&
|
|
184
202
|
(!Number.isInteger(value[key]) || value[key] < 0))
|
|
185
203
|
return false;
|
|
186
204
|
}
|
|
187
205
|
if (typeof value.v2InjectedSummaryBytes === "number" && value.v2InjectedSummaryBytes > 9999)
|
|
188
206
|
return false;
|
|
189
|
-
if (!Number.isInteger(value.minConsolidatedThreads) ||
|
|
207
|
+
if (!Number.isInteger(value.minConsolidatedThreads) ||
|
|
208
|
+
value.minConsolidatedThreads < 1 ||
|
|
209
|
+
value.minConsolidatedThreads > 4096)
|
|
190
210
|
return false;
|
|
191
|
-
if (!Array.isArray(value.pipelines) ||
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
211
|
+
if (!Array.isArray(value.pipelines) ||
|
|
212
|
+
!value.pipelines.every((pipeline) => isRecord(pipeline) &&
|
|
213
|
+
(pipeline.version === "v1" || pipeline.version === "v2") &&
|
|
214
|
+
Number.isInteger(pipeline.stage1Count) &&
|
|
215
|
+
pipeline.stage1Count >= 0 &&
|
|
216
|
+
Number.isInteger(pipeline.extracting) &&
|
|
217
|
+
pipeline.extracting >= 0 &&
|
|
218
|
+
(pipeline.phase2Status === null || typeof pipeline.phase2Status === "string") &&
|
|
219
|
+
(pipeline.lastError === null || typeof pipeline.lastError === "string") &&
|
|
220
|
+
["phase2CooldownUntil", "phase1RetryAt", "phase2RetryAt"].every((key) => pipeline[key] === undefined ||
|
|
221
|
+
pipeline[key] === null ||
|
|
222
|
+
(typeof pipeline[key] === "number" && Number.isFinite(pipeline[key])))))
|
|
197
223
|
return false;
|
|
198
224
|
for (const key of ["extractModel", "consolidationModel", "lastSuccessAt", "retryAt"]) {
|
|
199
225
|
const v = value[key];
|
package/dist/src/v2/status.js
CHANGED
|
@@ -30,7 +30,8 @@ export function readMemoryStatus(sessionID, minConsolidatedThreads) {
|
|
|
30
30
|
};
|
|
31
31
|
const pipelines = snapshots.map((pipeline) => {
|
|
32
32
|
const cooldown = pipeline.phase2?.success_finished_at == null
|
|
33
|
-
? null
|
|
33
|
+
? null
|
|
34
|
+
: pipeline.phase2.success_finished_at * 1000 + PHASE2_COOLDOWN_MS;
|
|
34
35
|
return {
|
|
35
36
|
version: pipeline.version,
|
|
36
37
|
stage1Count: pipeline.stage1Count,
|
|
@@ -50,8 +51,7 @@ export function readMemoryStatus(sessionID, minConsolidatedThreads) {
|
|
|
50
51
|
const total = injectionTotals();
|
|
51
52
|
const retryAt = nextRetry([
|
|
52
53
|
...activeProviderCapacityBackoffs().map((backoff) => backoff.retry_at),
|
|
53
|
-
...active.flatMap((pipeline) => [pipeline.phase1RetryAt, pipeline.phase2RetryAt]
|
|
54
|
-
.map((time) => time === null ? null : time / 1000)),
|
|
54
|
+
...active.flatMap((pipeline) => [pipeline.phase1RetryAt, pipeline.phase2RetryAt].map((time) => (time === null ? null : time / 1000))),
|
|
55
55
|
]);
|
|
56
56
|
const warnings = [...getConfigWarnings()];
|
|
57
57
|
const discoveryWarning = getV2DiscoveryStatus()?.warning;
|
|
@@ -97,10 +97,7 @@ export function readMemoryStatus(sessionID, minConsolidatedThreads) {
|
|
|
97
97
|
// A `running` row this process does not own is either another opencode
|
|
98
98
|
// instance's live job or an orphaned lease (e.g. a server restart killed the
|
|
99
99
|
// owner mid-run). Neither is "consolidating" here; surface it instead.
|
|
100
|
-
const foreignLease = !isPhase2InFlight() &&
|
|
101
|
-
phase2?.status === "running" &&
|
|
102
|
-
phase2.lease_until != null &&
|
|
103
|
-
phase2.lease_until * 1000 > now;
|
|
100
|
+
const foreignLease = !isPhase2InFlight() && phase2?.status === "running" && phase2.lease_until != null && phase2.lease_until * 1000 > now;
|
|
104
101
|
if (foreignLease) {
|
|
105
102
|
warnings.push(`Consolidation lease held by another process until ${new Date(phase2.lease_until * 1000).toLocaleTimeString()}.`);
|
|
106
103
|
}
|
package/dist/src/v2/tools.d.ts
CHANGED
|
@@ -10,6 +10,18 @@
|
|
|
10
10
|
* Inspect additionally reports the V2 host discovery scope and fallback reason.
|
|
11
11
|
*/
|
|
12
12
|
import { z } from "zod";
|
|
13
|
+
type CallContext = {
|
|
14
|
+
sessionID: string;
|
|
15
|
+
messageID: string;
|
|
16
|
+
agent: string;
|
|
17
|
+
id?: string;
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
abort?: AbortSignal;
|
|
20
|
+
};
|
|
21
|
+
type Ask = (ctx: CallContext, request: {
|
|
22
|
+
patterns: string[];
|
|
23
|
+
metadata: unknown;
|
|
24
|
+
}) => Promise<void>;
|
|
13
25
|
interface V2ToolDefinition {
|
|
14
26
|
name: string;
|
|
15
27
|
description: string;
|
|
@@ -23,12 +35,7 @@ interface V2ToolDefinition {
|
|
|
23
35
|
options: {
|
|
24
36
|
codemode: false;
|
|
25
37
|
};
|
|
26
|
-
execute: (input: any, ctx: {
|
|
27
|
-
sessionID: string;
|
|
28
|
-
messageID: string;
|
|
29
|
-
agent: string;
|
|
30
|
-
abort?: AbortSignal;
|
|
31
|
-
}) => Promise<{
|
|
38
|
+
execute: (input: any, ctx: CallContext) => Promise<{
|
|
32
39
|
content: string | unknown[];
|
|
33
40
|
metadata?: unknown;
|
|
34
41
|
}>;
|
|
@@ -36,8 +43,7 @@ interface V2ToolDefinition {
|
|
|
36
43
|
/**
|
|
37
44
|
* Same gating as the V1 entry: the read/search/list/add-note tools require
|
|
38
45
|
* BOTH use_memories and dedicated_tools (codex MemoriesExtension); the
|
|
39
|
-
* control tools are always available.
|
|
40
|
-
* which V2 plugin tools cannot request: reset lives in the memory panel.
|
|
46
|
+
* control tools are always available. Destructive reset lives in the panel.
|
|
41
47
|
*/
|
|
42
|
-
export declare function buildV2Tools(): V2ToolDefinition[];
|
|
48
|
+
export declare function buildV2Tools(ask?: Ask): V2ToolDefinition[];
|
|
43
49
|
export {};
|