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/llm.js
CHANGED
|
@@ -2,7 +2,8 @@ import fs from "fs";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { memoryRoot } from "./paths.js";
|
|
4
4
|
import { hostListSessionsGlobal, hostProviderList, hostSessionCreate, hostSessionDeletionConfirmed, hostSessionPrompt, hostStructuredOutput, ignoreLateRejection, pluginHttpGet, withHostTimeout, } from "./host-client.js";
|
|
5
|
-
import { catalogVariantKeys, nearestReasoningVariant } from "./reasoning-variant.js";
|
|
5
|
+
import { catalogModel, catalogVariantKeys, nearestReasoningVariant } from "./reasoning-variant.js";
|
|
6
|
+
import { truncateToBytes } from "./token.js";
|
|
6
7
|
import { isPluginShuttingDown, pluginShutdownSignal } from "./lifecycle.js";
|
|
7
8
|
import { modelList } from "./options.js";
|
|
8
9
|
import { currentMemoryVersion } from "./memory-version.js";
|
|
@@ -10,6 +11,7 @@ import { SCAN_LIMIT, STAGE1_LEASE_SECONDS } from "./store.js";
|
|
|
10
11
|
import { isProviderCapacityBlocked, isProviderCapacityError, noteProviderCapacityExhausted, ProviderCapacityError, providerCapacityMessage, } from "./ratelimit.js";
|
|
11
12
|
import { recordDiagnostic } from "./diagnostics.js";
|
|
12
13
|
const EXTRACTION_TIMEOUT_MS = (STAGE1_LEASE_SECONDS - 600) * 1000;
|
|
14
|
+
export const MAX_TRANSCRIPT_BYTES = 600_000;
|
|
13
15
|
let inputRef = null;
|
|
14
16
|
let inputGeneration = 0;
|
|
15
17
|
let subSessionDirectoryOverride = null;
|
|
@@ -97,10 +99,14 @@ async function createSession(title) {
|
|
|
97
99
|
body: {
|
|
98
100
|
title,
|
|
99
101
|
metadata: { [SUBSESSION_METADATA_KEY]: true },
|
|
100
|
-
...(title === "codex-memory-consolidate"
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
...(title === "codex-memory-consolidate"
|
|
103
|
+
? {
|
|
104
|
+
permission: [
|
|
105
|
+
{ permission: "external_directory", pattern: "*", action: "deny" },
|
|
106
|
+
{ permission: "external_directory", pattern: path.join(memoryRoot(), "*"), action: "allow" },
|
|
107
|
+
],
|
|
108
|
+
}
|
|
109
|
+
: {}),
|
|
104
110
|
},
|
|
105
111
|
signal: controller.signal,
|
|
106
112
|
}), createTimeoutMs, "session.create", controller);
|
|
@@ -116,8 +122,8 @@ async function createSession(title) {
|
|
|
116
122
|
/**
|
|
117
123
|
* opencode's config carries the same split codex expresses with provider
|
|
118
124
|
* model preferences: `small_model` for cheap background work (codex:
|
|
119
|
-
* memory_extraction_preferred_model = gpt-
|
|
120
|
-
* work (codex: memory_consolidation_preferred_model = gpt-
|
|
125
|
+
* memory_extraction_preferred_model = gpt-6-luna) and `model` for capable
|
|
126
|
+
* work (codex: memory_consolidation_preferred_model = gpt-6.1-terra). Cached per
|
|
121
127
|
* plugin instance — opencode reloads plugins on config change.
|
|
122
128
|
*/
|
|
123
129
|
let configModels = null;
|
|
@@ -134,7 +140,7 @@ async function getConfigModels() {
|
|
|
134
140
|
const request = (async () => {
|
|
135
141
|
const controller = new AbortController();
|
|
136
142
|
try {
|
|
137
|
-
const res = await withHostTimeout(input.client.config.get({ signal: controller.signal }), configGetTimeoutMs, "config.get", controller);
|
|
143
|
+
const res = (await withHostTimeout(input.client.config.get({ signal: controller.signal }), configGetTimeoutMs, "config.get", controller));
|
|
138
144
|
if (res.error || !res.data || generation !== inputGeneration)
|
|
139
145
|
return {};
|
|
140
146
|
const resolved = { model: res.data.model, smallModel: res.data.small_model };
|
|
@@ -361,7 +367,10 @@ function extractAssistantText(body) {
|
|
|
361
367
|
if (typeof body.text === "string")
|
|
362
368
|
return body.text;
|
|
363
369
|
if (body.parts && Array.isArray(body.parts))
|
|
364
|
-
return body.parts
|
|
370
|
+
return body.parts
|
|
371
|
+
.map((p) => p?.text ?? "")
|
|
372
|
+
.filter(Boolean)
|
|
373
|
+
.join("\n");
|
|
365
374
|
if (body.messages && Array.isArray(body.messages)) {
|
|
366
375
|
return body.messages
|
|
367
376
|
.filter((m) => m?.info?.role === "assistant")
|
|
@@ -471,18 +480,32 @@ async function extractOnce(sessionId, transcript, cwd, configuredModel, timeoutM
|
|
|
471
480
|
const subId = await createSession(`codex-memory-extract-${sessionId}`);
|
|
472
481
|
try {
|
|
473
482
|
const version = currentMemoryVersion();
|
|
474
|
-
const prompt = buildExtractionInput(sessionId, cwd ?? "unknown", transcript, version);
|
|
475
483
|
// extract_model chain entry > opencode small_model > session default.
|
|
476
484
|
const model = await resolveExtractionModel(configuredModel);
|
|
485
|
+
const system = readTemplate(version === "v2" ? "stage_one_system_v2.md" : "stage_one_system.md");
|
|
486
|
+
const schema = version === "v2" ? EXTRACTION_SCHEMA_V2 : EXTRACTION_SCHEMA;
|
|
487
|
+
const ref = model && parseModelRef(model);
|
|
488
|
+
const limit = ref ? catalogModel(await getProviderCatalog(), ref.providerID, ref.modelID)?.limit : undefined;
|
|
489
|
+
const windows = [limit?.context, limit?.input].filter((n) => typeof n === "number" && Number.isSafeInteger(n) && n > 0);
|
|
490
|
+
// 70% of the effective input window (Codex), reserving template/schema
|
|
491
|
+
// bytes plus host framing. Token counts are estimates, not provider billing.
|
|
492
|
+
const overhead = Buffer.byteLength(system + buildExtractionInput(sessionId, cwd ?? "unknown", "", version) + JSON.stringify(schema)) + 1024;
|
|
493
|
+
const budget = windows.length
|
|
494
|
+
? Math.min(MAX_TRANSCRIPT_BYTES, Math.floor(Math.min(...windows) * 0.7) * 4 - overhead)
|
|
495
|
+
: MAX_TRANSCRIPT_BYTES;
|
|
496
|
+
if (budget < 256)
|
|
497
|
+
throw new Error(`Model ${model} has insufficient input space for the extraction instructions`);
|
|
498
|
+
const content = typeof transcript === "string" ? truncateToBytes(transcript, budget) : transcript(budget);
|
|
499
|
+
const prompt = buildExtractionInput(sessionId, cwd ?? "unknown", content, version);
|
|
477
500
|
const data = await runPrompt(subId, prompt, agent, {
|
|
478
501
|
timeoutMs,
|
|
479
|
-
system
|
|
502
|
+
system,
|
|
480
503
|
model,
|
|
481
504
|
signal,
|
|
482
505
|
// opencode enforces json_schema output via a forced StructuredOutput tool
|
|
483
506
|
// call (toolChoice: required) — which is why memorize-extract must allow
|
|
484
507
|
// that one otherwise-denied tool.
|
|
485
|
-
format: { type: "json_schema", schema
|
|
508
|
+
format: { type: "json_schema", schema },
|
|
486
509
|
// Codex extraction ReasoningEffort::Low. Host maps variant → reasoningEffort.
|
|
487
510
|
// If the model has no `low`, pick the nearest listed effort (host-only).
|
|
488
511
|
variant: await resolveReasoningVariant(EXTRACT_VARIANT, model),
|
|
@@ -599,7 +622,9 @@ export async function cleanupOldSubSessions(maxAgeMinutes = 90, timeoutMs = SUBS
|
|
|
599
622
|
}
|
|
600
623
|
if (list.length < pageLimit)
|
|
601
624
|
return;
|
|
602
|
-
const updates = list
|
|
625
|
+
const updates = list
|
|
626
|
+
.map((s) => s.time?.updated)
|
|
627
|
+
.filter((updated) => typeof updated === "number" && Number.isFinite(updated) && updated >= 0);
|
|
603
628
|
if (updates.length === 0)
|
|
604
629
|
return;
|
|
605
630
|
// listGlobal uses `updated < cursor`. Add one millisecond so sessions
|
|
@@ -680,7 +705,7 @@ async function deleteSession(id, input = getPluginInput(), timeoutMs = SUBSESSIO
|
|
|
680
705
|
// after shutdown succeeded. Hosts without session.get cannot confirm;
|
|
681
706
|
// the successful delete is all the evidence there is.
|
|
682
707
|
const canConfirm = typeof input.client.session?.get === "function";
|
|
683
|
-
if (!canConfirm || await hostSessionDeletionConfirmed(input.client, id, SUBSESSION_CONFIRM_TIMEOUT_MS)) {
|
|
708
|
+
if (!canConfirm || (await hostSessionDeletionConfirmed(input.client, id, SUBSESSION_CONFIRM_TIMEOUT_MS))) {
|
|
684
709
|
activeSubSessions.delete(id);
|
|
685
710
|
}
|
|
686
711
|
return true;
|
|
@@ -813,7 +838,10 @@ export function validateExtraction(obj, version = currentMemoryVersion()) {
|
|
|
813
838
|
* is unavailable; the primary path reads AssistantMessage.structured directly.
|
|
814
839
|
*/
|
|
815
840
|
export function parseExtraction(raw, version = currentMemoryVersion()) {
|
|
816
|
-
const cleaned = raw
|
|
841
|
+
const cleaned = raw
|
|
842
|
+
.replace(/^```(?:json)?/gim, "")
|
|
843
|
+
.replace(/```$/gim, "")
|
|
844
|
+
.trim();
|
|
817
845
|
const start = cleaned.indexOf("{");
|
|
818
846
|
const end = cleaned.lastIndexOf("}");
|
|
819
847
|
if (start === -1 || end === -1 || end <= start) {
|
package/dist/src/options.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import type { CodexInteropOptions } from "./codex-interop.js";
|
|
2
2
|
import type { ClaudeImportOptions } from "./claude-import.js";
|
|
3
|
+
type SharedConfig = {
|
|
4
|
+
home: string;
|
|
5
|
+
options: Record<string, unknown>;
|
|
6
|
+
};
|
|
7
|
+
/** Check the effective home before applying options or touching DB handles. */
|
|
8
|
+
export declare function reserveMemoryConfig(active: SharedConfig | undefined, raw: Record<string, unknown> | undefined, directory: string): SharedConfig;
|
|
3
9
|
/**
|
|
4
10
|
* Effective plugin options + configuration diagnostics, owned by a leaf
|
|
5
11
|
* module so both the plugin entry (writes) and the control tools (read for
|
|
@@ -50,3 +56,4 @@ export declare function getConfigWarnings(): readonly string[];
|
|
|
50
56
|
export declare function clearConfigWarnings(): void;
|
|
51
57
|
/** Test seam: options/warnings are module state, tests need a clean slate. */
|
|
52
58
|
export declare function resetConfigWarningsForTest(): void;
|
|
59
|
+
export {};
|
package/dist/src/options.js
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
|
-
import { setConfiguredHome } from "./paths.js";
|
|
1
|
+
import { resolveDataRoot, resolveHomePath, setConfiguredHome } from "./paths.js";
|
|
2
|
+
import { isDeepStrictEqual } from "node:util";
|
|
3
|
+
/** Check the effective home before applying options or touching DB handles. */
|
|
4
|
+
export function reserveMemoryConfig(active, raw, directory) {
|
|
5
|
+
const { home, ...options } = raw ?? {};
|
|
6
|
+
const config = {
|
|
7
|
+
home: resolveDataRoot(typeof home === "string" ? (resolveHomePath(home) ?? undefined) : undefined),
|
|
8
|
+
options,
|
|
9
|
+
};
|
|
10
|
+
if (active && !isDeepStrictEqual(active, config)) {
|
|
11
|
+
throw new Error(`Conflicting memory configuration for ${directory}. Configure one memory home and options for all locations in this OpenCode process.`);
|
|
12
|
+
}
|
|
13
|
+
return active ?? config;
|
|
14
|
+
}
|
|
2
15
|
const DEFAULT_PLUGIN_OPTIONS = {
|
|
3
16
|
generate_memories: true,
|
|
4
17
|
use_memories: true,
|
|
@@ -22,7 +35,12 @@ export const pluginOptions = {
|
|
|
22
35
|
};
|
|
23
36
|
/** Splits an extract_model / consolidation_model value into its fallback chain. */
|
|
24
37
|
export function modelList(value) {
|
|
25
|
-
return [
|
|
38
|
+
return [
|
|
39
|
+
...new Set((value ?? "")
|
|
40
|
+
.split(",")
|
|
41
|
+
.map((model) => model.trim())
|
|
42
|
+
.filter(Boolean)),
|
|
43
|
+
];
|
|
26
44
|
}
|
|
27
45
|
export function resetPluginOptions() {
|
|
28
46
|
delete pluginOptions.extract_model;
|
package/dist/src/paths.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export type MemoryHomeSource = "test" | "option" | "env" | "default";
|
|
|
25
25
|
export declare function resolveHomePath(raw: string): string | null;
|
|
26
26
|
export declare function setConfiguredHome(home: string | undefined): void;
|
|
27
27
|
export declare function dataRoot(): string;
|
|
28
|
+
export declare function resolveDataRoot(home: string | undefined): string;
|
|
28
29
|
export declare function memoryHomeSource(): MemoryHomeSource;
|
|
29
30
|
export declare function memoryRoot(version?: MemoryVersion): string;
|
|
30
31
|
/** Jobs/outputs DB for the selected version. Session mode/pollution lives in sessionMetaDbPath. */
|
package/dist/src/paths.js
CHANGED
|
@@ -51,11 +51,14 @@ export function setConfiguredHome(home) {
|
|
|
51
51
|
configuredHome = home;
|
|
52
52
|
}
|
|
53
53
|
export function dataRoot() {
|
|
54
|
+
return resolveDataRoot(configuredHome);
|
|
55
|
+
}
|
|
56
|
+
export function resolveDataRoot(home) {
|
|
54
57
|
const testRoot = process.env[TEST_ROOT_ENV];
|
|
55
58
|
if (testRoot)
|
|
56
59
|
return testRoot;
|
|
57
|
-
if (
|
|
58
|
-
return
|
|
60
|
+
if (home)
|
|
61
|
+
return home;
|
|
59
62
|
const envHome = process.env[HOME_ENV];
|
|
60
63
|
if (envHome) {
|
|
61
64
|
const resolved = resolveHomePath(envHome);
|
package/dist/src/phase1.js
CHANGED
|
@@ -3,8 +3,8 @@ import { loadTranscript, selectEligibleSessions } from "./capture.js";
|
|
|
3
3
|
import { serializeTieredInput } from "./rollout-input.js";
|
|
4
4
|
import { redact, isMemoryExcludedFragment } from "./redact.js";
|
|
5
5
|
import { stripCitations } from "./citation.js";
|
|
6
|
-
import { extractViaSubagent, SubagentCancelledError } from "./llm.js";
|
|
7
|
-
import { checkRateLimit, isProviderCapacityBlocked, markRateLimitUsed, ProviderCapacityError
|
|
6
|
+
import { extractViaSubagent, MAX_TRANSCRIPT_BYTES, SubagentCancelledError } from "./llm.js";
|
|
7
|
+
import { checkRateLimit, isProviderCapacityBlocked, markRateLimitUsed, ProviderCapacityError } from "./ratelimit.js";
|
|
8
8
|
import { isPluginShuttingDown } from "./lifecycle.js";
|
|
9
9
|
import { recordDiagnostic } from "./diagnostics.js";
|
|
10
10
|
import { currentMemoryVersion, withMemoryVersion } from "./memory-version.js";
|
|
@@ -16,15 +16,6 @@ export const DEFAULT_PHASE1_OPTIONS = {
|
|
|
16
16
|
maxClaimed: 2,
|
|
17
17
|
maxUnusedDays: 30,
|
|
18
18
|
};
|
|
19
|
-
// codex serializes the full transcript and truncates at 70% of the model
|
|
20
|
-
// context window, falling back to 150k tokens; ~4 chars/token puts the
|
|
21
|
-
// char-estimate equivalent at 600k.
|
|
22
|
-
const TRANSCRIPT_MAX_CHARS = 600_000;
|
|
23
|
-
// When truncating, keep the head and the tail: the start carries the user's
|
|
24
|
-
// framing, the end carries the final outcome and feedback. codex splits the
|
|
25
|
-
// budget 50/50 between head and tail (truncate.rs split_budget).
|
|
26
|
-
const TRANSCRIPT_HEAD_CHARS = 300_000;
|
|
27
|
-
const TRANSCRIPT_TAIL_CHARS = 300_000;
|
|
28
19
|
export async function runPhase1(store, opts = DEFAULT_PHASE1_OPTIONS, rateLimitCheck = checkRateLimit) {
|
|
29
20
|
return withMemoryVersion(store.version, () => runVersionPhase1(store, opts, rateLimitCheck));
|
|
30
21
|
}
|
|
@@ -77,12 +68,12 @@ async function runVersionPhase1(store, opts, rateLimitCheck) {
|
|
|
77
68
|
try {
|
|
78
69
|
const session = sessionById.get(sid);
|
|
79
70
|
const sourceUpdatedAt = session?.updated_at ?? Date.now();
|
|
80
|
-
const transcript = await
|
|
71
|
+
const transcript = await prepareTranscript(sid);
|
|
81
72
|
if (isPluginShuttingDown()) {
|
|
82
73
|
store.releaseStage1OnShutdown(sid, claim.ownershipToken);
|
|
83
74
|
return;
|
|
84
75
|
}
|
|
85
|
-
if (!transcript
|
|
76
|
+
if (!transcript) {
|
|
86
77
|
// A newly empty chat is a legitimate no-output result. An existing
|
|
87
78
|
// extraction plus an empty API success is anomalous: retry instead of
|
|
88
79
|
// permanently forgetting memory because of a transient host glitch.
|
|
@@ -133,12 +124,16 @@ async function runVersionPhase1(store, opts, rateLimitCheck) {
|
|
|
133
124
|
});
|
|
134
125
|
}
|
|
135
126
|
export async function buildTranscript(sessionId) {
|
|
127
|
+
return (await prepareTranscript(sessionId))?.(MAX_TRANSCRIPT_BYTES) ?? "";
|
|
128
|
+
}
|
|
129
|
+
async function prepareTranscript(sessionId) {
|
|
136
130
|
const msgs = await loadTranscript(sessionId);
|
|
137
131
|
if (msgs.length === 0)
|
|
138
|
-
return
|
|
132
|
+
return null;
|
|
139
133
|
if (currentMemoryVersion() === "v2") {
|
|
140
|
-
const
|
|
141
|
-
|
|
134
|
+
const render = (limit) => redact(stripCitations(serializeTieredInput(msgs, limit)));
|
|
135
|
+
const initial = render(MAX_TRANSCRIPT_BYTES);
|
|
136
|
+
return initial.trim() ? (limit) => (Buffer.byteLength(initial) <= limit ? initial : render(limit)) : null;
|
|
142
137
|
}
|
|
143
138
|
const lines = [];
|
|
144
139
|
for (const m of msgs) {
|
|
@@ -160,11 +155,7 @@ export async function buildTranscript(sessionId) {
|
|
|
160
155
|
lines.push(`### ${role}\n${redact(stripCitations(text))}`);
|
|
161
156
|
}
|
|
162
157
|
const full = lines.join("\n\n");
|
|
163
|
-
|
|
164
|
-
return full;
|
|
165
|
-
return (full.slice(0, TRANSCRIPT_HEAD_CHARS) +
|
|
166
|
-
"\n\n[... transcript truncated ...]\n\n" +
|
|
167
|
-
full.slice(full.length - TRANSCRIPT_TAIL_CHARS));
|
|
158
|
+
return full ? (limit) => truncateToBytes(full, limit) : null;
|
|
168
159
|
}
|
|
169
160
|
async function runPool(items, concurrency, fn) {
|
|
170
161
|
let cursor = 0;
|
package/dist/src/phase2.js
CHANGED
|
@@ -2,7 +2,7 @@ import { PHASE2_HEARTBEAT_SECONDS } from "./store.js";
|
|
|
2
2
|
import { checkRateLimit } from "./ratelimit.js";
|
|
3
3
|
import { ensureLayout, rebuildRawMemories, writeRolloutSummaries, pruneExtensionResources, EXTENSION_RESOURCE_RETENTION_DAYS, writeWorkspaceDiff, validateConsolidationArtifactsForVersion, removeMemorySymlinks, } from "./workspace.js";
|
|
4
4
|
import { ensureBaseline, captureWorkspaceDiff, resetBaseline, DIFF_ARTIFACT } from "./git-baseline.js";
|
|
5
|
-
import { consolidateViaSubagent, getPluginInput, SubagentCancelledError, SubagentShutdownError
|
|
5
|
+
import { consolidateViaSubagent, getPluginInput, SubagentCancelledError, SubagentShutdownError } from "./llm.js";
|
|
6
6
|
import { hostSessionLiveness, withHostTimeout } from "./host-client.js";
|
|
7
7
|
import { invalidateCache } from "./source.js";
|
|
8
8
|
import { withMemoryVersion } from "./memory-version.js";
|
|
@@ -145,12 +145,13 @@ async function runVersionPhase2(store, opts) {
|
|
|
145
145
|
// the lease instead of leaving the row running until it expires.
|
|
146
146
|
const interop = opts.codexInterop ? resolveCodexInterop(opts.codexInterop) : null;
|
|
147
147
|
ensureLayout();
|
|
148
|
-
// Preserves
|
|
149
|
-
//
|
|
150
|
-
//
|
|
148
|
+
// Preserves a current-version baseline; missing/outdated/unusable
|
|
149
|
+
// metadata becomes an empty baseline (codex ensure_git_baseline_repository),
|
|
150
|
+
// so the diff below spans last-successful-run -> now and existing memory
|
|
151
|
+
// files stay visible as additions. Stale stage-1
|
|
151
152
|
// output pruning happens in phase 1, before the rate gate (codex
|
|
152
153
|
// start.rs ordering).
|
|
153
|
-
if (!await withHostTimeout(ensureBaseline(), GIT_TIMEOUT_MS, "ensureBaseline")) {
|
|
154
|
+
if (!(await withHostTimeout(ensureBaseline(), GIT_TIMEOUT_MS, "ensureBaseline"))) {
|
|
154
155
|
store.markPhase2Failed(claim.ownershipToken, "git baseline failed");
|
|
155
156
|
return { status: "baseline_failed" };
|
|
156
157
|
}
|
|
@@ -292,7 +293,7 @@ async function runVersionPhase2(store, opts) {
|
|
|
292
293
|
store.markPhase2Failed(claim.ownershipToken, `failed_invalid_artifacts: ${artifacts.reason}`);
|
|
293
294
|
return { status: "failed_invalid_artifacts" };
|
|
294
295
|
}
|
|
295
|
-
if (!await withHostTimeout(resetBaseline(diff.extensionSnapshot), GIT_TIMEOUT_MS, "resetBaseline")) {
|
|
296
|
+
if (!(await withHostTimeout(resetBaseline(diff.extensionSnapshot), GIT_TIMEOUT_MS, "resetBaseline"))) {
|
|
296
297
|
store.markPhase2Failed(claim.ownershipToken, "baseline reset failed");
|
|
297
298
|
return { status: "baseline_reset_failed" };
|
|
298
299
|
}
|
|
@@ -2,4 +2,11 @@ export declare const REASONING_VARIANT_LADDER: readonly ["none", "minimal", "low
|
|
|
2
2
|
export type ReasoningVariant = (typeof REASONING_VARIANT_LADDER)[number];
|
|
3
3
|
export declare function nearestReasoningVariant(preferred: string, available: Iterable<string>): string | undefined;
|
|
4
4
|
export declare function enabledVariantKeys(variants: unknown): string[];
|
|
5
|
+
export declare function catalogModel(data: unknown, providerID: string, modelID: string): {
|
|
6
|
+
variants?: unknown;
|
|
7
|
+
limit?: {
|
|
8
|
+
context?: number;
|
|
9
|
+
input?: number;
|
|
10
|
+
};
|
|
11
|
+
} | undefined;
|
|
5
12
|
export declare function catalogVariantKeys(data: unknown, providerID: string, modelID: string): string[] | undefined;
|
|
@@ -27,14 +27,17 @@ export function enabledVariantKeys(variants) {
|
|
|
27
27
|
return [];
|
|
28
28
|
const out = [];
|
|
29
29
|
for (const [name, value] of Object.entries(variants)) {
|
|
30
|
-
if (value &&
|
|
30
|
+
if (value &&
|
|
31
|
+
typeof value === "object" &&
|
|
32
|
+
!Array.isArray(value) &&
|
|
33
|
+
value.disabled === true) {
|
|
31
34
|
continue;
|
|
32
35
|
}
|
|
33
36
|
out.push(name);
|
|
34
37
|
}
|
|
35
38
|
return out;
|
|
36
39
|
}
|
|
37
|
-
export function
|
|
40
|
+
export function catalogModel(data, providerID, modelID) {
|
|
38
41
|
if (!data || typeof data !== "object")
|
|
39
42
|
return undefined;
|
|
40
43
|
const root = data;
|
|
@@ -47,6 +50,12 @@ export function catalogVariantKeys(data, providerID, modelID) {
|
|
|
47
50
|
const model = provider.models[modelID];
|
|
48
51
|
if (!model || typeof model !== "object" || Array.isArray(model))
|
|
49
52
|
return undefined;
|
|
53
|
+
return model;
|
|
54
|
+
}
|
|
55
|
+
export function catalogVariantKeys(data, providerID, modelID) {
|
|
56
|
+
const model = catalogModel(data, providerID, modelID);
|
|
57
|
+
if (!model)
|
|
58
|
+
return undefined;
|
|
50
59
|
if (!Object.prototype.hasOwnProperty.call(model, "variants"))
|
|
51
60
|
return undefined;
|
|
52
61
|
return enabledVariantKeys(model.variants);
|
|
@@ -21,10 +21,8 @@ function isEnvContext(text) {
|
|
|
21
21
|
}
|
|
22
22
|
function isOtherAgent(text) {
|
|
23
23
|
const trimmed = text.trimStart();
|
|
24
|
-
return (trimmed.startsWith("<subagent_notification>")
|
|
25
|
-
|
|
26
|
-
&& trimmed.includes("\nTask name:")
|
|
27
|
-
&& trimmed.includes("\nSender:")));
|
|
24
|
+
return (trimmed.startsWith("<subagent_notification>") ||
|
|
25
|
+
(trimmed.startsWith("Message Type:") && trimmed.includes("\nTask name:") && trimmed.includes("\nSender:")));
|
|
28
26
|
}
|
|
29
27
|
function classify(msg) {
|
|
30
28
|
if (msg.type === "reasoning" || msg.type === "step-start" || msg.type === "step-finish")
|
|
@@ -65,7 +63,7 @@ function rowText(msg, tier) {
|
|
|
65
63
|
return "[file omitted]";
|
|
66
64
|
let text = redact(stripCitations(msg.userReply
|
|
67
65
|
? `Assistant question: ${msg.userReply.question}\nHuman reply: ${msg.userReply.answer}`
|
|
68
|
-
: msg.text ?? ""));
|
|
66
|
+
: (msg.text ?? "")));
|
|
69
67
|
if (tier === "tool")
|
|
70
68
|
text = truncateToBytes(text, TOOL_ROW_BYTES - TRUNCATION_RESERVE_BYTES);
|
|
71
69
|
text = truncateToBytes(text, MAX_ROW_BYTES - TRUNCATION_RESERVE_BYTES);
|
|
@@ -9,10 +9,8 @@ export function sessionMemoryVersion(sessionId) {
|
|
|
9
9
|
if (!sessionId)
|
|
10
10
|
return pluginOptions.version;
|
|
11
11
|
const db = openSessionMetaDb();
|
|
12
|
-
db.prepare("INSERT OR IGNORE INTO memory_session_versions (session_id, version) VALUES (?, ?)")
|
|
13
|
-
|
|
14
|
-
return db.prepare("SELECT version FROM memory_session_versions WHERE session_id = ?")
|
|
15
|
-
.get(sessionId).version;
|
|
12
|
+
db.prepare("INSERT OR IGNORE INTO memory_session_versions (session_id, version) VALUES (?, ?)").run(sessionId, pluginOptions.version);
|
|
13
|
+
return db.prepare("SELECT version FROM memory_session_versions WHERE session_id = ?").get(sessionId).version;
|
|
16
14
|
}
|
|
17
15
|
export function withSessionMemoryVersion(sessionId, run) {
|
|
18
16
|
return withMemoryVersion(sessionMemoryVersion(sessionId), run);
|
|
@@ -21,7 +19,8 @@ export function withSessionMemoryVersion(sessionId, run) {
|
|
|
21
19
|
export function peekSessionMemoryVersion(sessionId) {
|
|
22
20
|
if (!sessionId)
|
|
23
21
|
return pluginOptions.version;
|
|
24
|
-
const row = openSessionMetaDb()
|
|
22
|
+
const row = openSessionMetaDb()
|
|
23
|
+
.prepare("SELECT version FROM memory_session_versions WHERE session_id = ?")
|
|
25
24
|
.get(sessionId);
|
|
26
25
|
return row?.version ?? pluginOptions.version;
|
|
27
26
|
}
|
package/dist/src/source.js
CHANGED
|
@@ -91,8 +91,12 @@ export function buildMemorySystemPrompt(dedicatedTools) {
|
|
|
91
91
|
const template = readTemplate();
|
|
92
92
|
const v2 = currentMemoryVersion() === "v2";
|
|
93
93
|
const searchStep = dedicatedTools
|
|
94
|
-
?
|
|
95
|
-
|
|
94
|
+
? v2
|
|
95
|
+
? SEARCH_STEP_TOOLS_V2
|
|
96
|
+
: SEARCH_STEP_TOOLS
|
|
97
|
+
: v2
|
|
98
|
+
? SEARCH_STEP_FILES_V2
|
|
99
|
+
: SEARCH_STEP_FILES;
|
|
96
100
|
return fillTemplate(template, {
|
|
97
101
|
search_step: searchStep,
|
|
98
102
|
skill_step: dedicatedTools ? SKILL_STEP_TOOLS : SKILL_STEP_FILES,
|
package/dist/src/store.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ export type Phase2ClaimResult = {
|
|
|
41
41
|
type: "skipped_retry_unavailable";
|
|
42
42
|
};
|
|
43
43
|
/** Wipe jobs/outputs in every versioned DB. Leaves memory_session_meta on memory.db. */
|
|
44
|
-
export declare function clearAllVersionMemoryData(): void;
|
|
44
|
+
export declare function clearAllVersionMemoryData(wipeWorkspace: () => void): void;
|
|
45
45
|
/** Include inactive existing stores for deletion, reset guards and diagnostics. */
|
|
46
46
|
export declare function existingMemoryStores(): MemoryStore[];
|
|
47
47
|
export declare const PHASE2_HEARTBEAT_SECONDS = 90;
|
|
@@ -92,6 +92,7 @@ export declare class MemoryStore {
|
|
|
92
92
|
claimGlobalPhase2Job(opts?: {
|
|
93
93
|
bypassCooldown?: boolean;
|
|
94
94
|
}): Phase2ClaimResult;
|
|
95
|
+
private claimPhase2;
|
|
95
96
|
heartbeatPhase2Job(ownershipToken: string): boolean;
|
|
96
97
|
/**
|
|
97
98
|
* Marks the phase-2 job done and records exactly which stage-1 snapshots the
|
|
@@ -165,7 +166,7 @@ export declare class MemoryStore {
|
|
|
165
166
|
* surface is model-invoked mid-session, so hooks can race the wipe.
|
|
166
167
|
*/
|
|
167
168
|
clearMemoryData(): void;
|
|
168
|
-
setMemoryMode(sessionId: string, mode: "enabled" | "disabled" | "polluted"): void;
|
|
169
|
+
setMemoryMode(sessionId: string, mode: "enabled" | "disabled" | "polluted", approvedRestore?: boolean): void;
|
|
169
170
|
/**
|
|
170
171
|
* Stamp a mode only when the session has no meta row yet — used to mark
|
|
171
172
|
* sessions seen while generate_memories=false as permanently 'disabled'
|