om-memory-system 3.2.0-next.8 → 3.3.0-next.17
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 +4 -1
- package/dist/adapters/opencode/auto-capture-summary.js +50 -8
- package/dist/adapters/opencode/import-command.d.ts +3 -7
- package/dist/adapters/opencode/import-command.js +3 -54
- package/dist/adapters/pi/extension.js +3 -0
- package/dist/adapters/pi/profile.js +2 -1
- package/dist/adapters/pi/provider.js +41 -14
- package/dist/config.d.ts +18 -1
- package/dist/config.js +103 -9
- package/dist/core/capture-context.js +1 -1
- package/dist/core/capture.d.ts +4 -0
- package/dist/core/capture.js +30 -0
- package/dist/core/extraction.d.ts +23 -1
- package/dist/core/extraction.js +41 -0
- package/dist/core/host.d.ts +23 -0
- package/dist/core/host.js +9 -1
- package/dist/core/profile-analysis.js +9 -1
- package/dist/importer/discovery.d.ts +32 -5
- package/dist/importer/discovery.js +88 -36
- package/dist/importer/import-args.d.ts +23 -1
- package/dist/importer/import-args.js +29 -1
- package/dist/importer/import-project.d.ts +16 -0
- package/dist/importer/import-project.js +35 -0
- package/dist/importer/import-readiness.d.ts +47 -0
- package/dist/importer/import-readiness.js +54 -0
- package/dist/importer/import-sessions.d.ts +98 -0
- package/dist/importer/import-sessions.js +222 -0
- package/dist/importer/import-sources.d.ts +47 -0
- package/dist/importer/import-sources.js +147 -0
- package/dist/importer/importer.d.ts +31 -1
- package/dist/importer/importer.js +82 -24
- package/dist/importer/opencode-import.d.ts +11 -1
- package/dist/importer/opencode-import.js +133 -69
- package/dist/importer/opencode-project.d.ts +1 -4
- package/dist/importer/opencode-project.js +3 -36
- package/dist/importer/opencode-reader.d.ts +25 -5
- package/dist/importer/opencode-reader.js +92 -106
- package/dist/importer/opencode-snapshot.d.ts +82 -0
- package/dist/importer/opencode-snapshot.js +276 -0
- package/dist/importer/profile-import.d.ts +1 -0
- package/dist/importer/profile-import.js +7 -1
- package/dist/importer/run-import.d.ts +10 -0
- package/dist/importer/run-import.js +21 -0
- package/dist/importer/settings-health.d.ts +25 -0
- package/dist/importer/settings-health.js +136 -0
- package/dist/importer/web-import-api.d.ts +8 -0
- package/dist/importer/web-import-api.js +8 -0
- package/dist/importer/web-import-jobs.d.ts +53 -0
- package/dist/importer/web-import-jobs.js +227 -0
- package/dist/index.js +4 -0
- package/dist/services/ai/live-model-choice.js +6 -3
- package/dist/services/ai/opencode-import-models.d.ts +11 -0
- package/dist/services/ai/opencode-import-models.js +55 -0
- package/dist/services/ai/opencode-provider.d.ts +9 -0
- package/dist/services/ai/opencode-provider.js +31 -4
- package/dist/services/ai/providers/anthropic-messages.js +14 -6
- package/dist/services/ai/providers/base-provider.d.ts +8 -0
- package/dist/services/ai/providers/base-provider.js +12 -0
- package/dist/services/ai/providers/google-gemini.js +21 -7
- package/dist/services/ai/providers/openai-chat-completion.js +20 -7
- package/dist/services/ai/providers/openai-responses.js +11 -0
- package/dist/services/capture-attempt-store.d.ts +21 -0
- package/dist/services/capture-attempt-store.js +108 -0
- package/dist/services/capture-diagnostics.d.ts +66 -0
- package/dist/services/capture-diagnostics.js +175 -0
- package/dist/services/cleanup-service.js +9 -0
- package/dist/services/global-config-writer.d.ts +10 -0
- package/dist/services/global-config-writer.js +106 -0
- package/dist/services/log-path.d.ts +2 -0
- package/dist/services/log-path.js +15 -0
- package/dist/services/logger.js +1 -12
- package/dist/services/settings-log.d.ts +5 -0
- package/dist/services/settings-log.js +36 -0
- package/dist/services/settings-models.d.ts +35 -0
- package/dist/services/settings-models.js +39 -0
- package/dist/services/settings-snapshot.d.ts +24 -0
- package/dist/services/settings-snapshot.js +71 -0
- package/dist/services/settings-traces.d.ts +7 -0
- package/dist/services/settings-traces.js +39 -0
- package/dist/services/user-memory-learning.js +2 -1
- package/dist/services/web-server.d.ts +5 -0
- package/dist/services/web-server.js +176 -3
- package/dist/v2/legacy-client.js +19 -2
- package/dist/web/assets/index-BMkPht7g.js +124 -0
- package/dist/web/assets/index-D5ak5KsI.css +2 -0
- package/dist/web/index.html +2 -2
- package/package.json +2 -1
- package/dist/web/assets/index-DPjEpD1h.css +0 -2
- package/dist/web/assets/index-do26c4JJ.js +0 -122
package/README.md
CHANGED
|
@@ -122,7 +122,10 @@ import guides, and the [CLI reference](docs/cli.md).
|
|
|
122
122
|
Pi shows a notice when a new version is out; update with
|
|
123
123
|
`pi update npm:om-memory-system`. On OpenCode v2, run `opencode plugin check`
|
|
124
124
|
and `opencode plugin update om-memory-system`. Restart the agent afterwards.
|
|
125
|
-
|
|
125
|
+
To stay on one version, install it with the number, for example
|
|
126
|
+
`pi install npm:om-memory-system@3.1.1` or
|
|
127
|
+
`opencode plugin add om-memory-system@3.1.1`; a pinned install is never
|
|
128
|
+
updated. Coming from `opencode-mem`? Your memories move over automatically, with a
|
|
126
129
|
backup first. See [Updating and upgrading](docs/upgrading.md) and
|
|
127
130
|
[CHANGELOG.md](CHANGELOG.md).
|
|
128
131
|
|
|
@@ -2,7 +2,7 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import { CONFIG } from "../../config.js";
|
|
3
3
|
import { resolveOpencodeHostModel } from "../../services/ai/live-model-choice.js";
|
|
4
4
|
import { buildBoundedSummaryPrompt } from "../../core/capture-context.js";
|
|
5
|
-
import { parseCaptureSummary } from "../../core/extraction.js";
|
|
5
|
+
import { classifyCaptureReply, normalizeStopReason, parseCaptureSummary, } from "../../core/extraction.js";
|
|
6
6
|
import { log } from "../../services/logger.js";
|
|
7
7
|
import { loadOpencodeProvider } from "../../services/ai/opencode-provider-loader.js";
|
|
8
8
|
function buildSystemPrompt(languageName) {
|
|
@@ -26,8 +26,19 @@ FORMAT:
|
|
|
26
26
|
SKIP if: greetings, casual chat, no code/decisions made
|
|
27
27
|
CAPTURE if: code changed, bug fixed, feature added, decision made`;
|
|
28
28
|
}
|
|
29
|
+
/** Reason code for an error thrown on the OpenCode host-model path. */
|
|
30
|
+
function hostModelFailureReason(error) {
|
|
31
|
+
if (error instanceof Error && error.name === "ZodError")
|
|
32
|
+
return "schema-mismatch";
|
|
33
|
+
if (String(error).includes("returned no structured output"))
|
|
34
|
+
return "empty-text";
|
|
35
|
+
return "call-error";
|
|
36
|
+
}
|
|
29
37
|
export async function generateOpenCodeAutoCaptureSummary(request, notify) {
|
|
30
38
|
let opencodeProviderError;
|
|
39
|
+
// Filled per path; when the host model falls back, the external API attempt
|
|
40
|
+
// overwrites it, so the record describes the call that decided the outcome.
|
|
41
|
+
const diagnostics = request.diagnostics ?? {};
|
|
31
42
|
const hostModel = resolveOpencodeHostModel(CONFIG);
|
|
32
43
|
if (hostModel) {
|
|
33
44
|
try {
|
|
@@ -40,6 +51,9 @@ export async function generateOpenCodeAutoCaptureSummary(request, notify) {
|
|
|
40
51
|
...hostModel,
|
|
41
52
|
prompt: request.prompt,
|
|
42
53
|
});
|
|
54
|
+
diagnostics.path = "host-model";
|
|
55
|
+
diagnostics.provider = providerID;
|
|
56
|
+
diagnostics.model = modelID;
|
|
43
57
|
if (!isProviderConnected(providerID)) {
|
|
44
58
|
throw new Error(`opencode provider '${providerID}' is not connected. Check your opencode provider configuration.`);
|
|
45
59
|
}
|
|
@@ -59,6 +73,8 @@ export async function generateOpenCodeAutoCaptureSummary(request, notify) {
|
|
|
59
73
|
tags: z.array(z.string()),
|
|
60
74
|
});
|
|
61
75
|
const aiPrompt = buildBoundedSummaryPrompt(request.context, systemPrompt, z.toJSONSchema(schema));
|
|
76
|
+
diagnostics.systemPrompt = systemPrompt;
|
|
77
|
+
diagnostics.userPrompt = aiPrompt;
|
|
62
78
|
const result = await generateStructuredOutput({
|
|
63
79
|
client: v2Client,
|
|
64
80
|
providerID,
|
|
@@ -66,6 +82,12 @@ export async function generateOpenCodeAutoCaptureSummary(request, notify) {
|
|
|
66
82
|
systemPrompt,
|
|
67
83
|
userPrompt: aiPrompt,
|
|
68
84
|
schema,
|
|
85
|
+
onReply: (reply) => {
|
|
86
|
+
diagnostics.stopReason = normalizeStopReason(reply.finish);
|
|
87
|
+
diagnostics.blockTypes = reply.partTypes;
|
|
88
|
+
diagnostics.rawReply =
|
|
89
|
+
reply.structuredOutput === undefined ? "" : JSON.stringify(reply.structuredOutput);
|
|
90
|
+
},
|
|
69
91
|
});
|
|
70
92
|
return {
|
|
71
93
|
summary: result.summary,
|
|
@@ -75,6 +97,7 @@ export async function generateOpenCodeAutoCaptureSummary(request, notify) {
|
|
|
75
97
|
}
|
|
76
98
|
catch (error) {
|
|
77
99
|
opencodeProviderError = error;
|
|
100
|
+
diagnostics.failureReason = hostModelFailureReason(error);
|
|
78
101
|
log("auto-capture: opencode provider failed, falling back to external API", {
|
|
79
102
|
error: String(error),
|
|
80
103
|
});
|
|
@@ -134,19 +157,38 @@ export async function generateOpenCodeAutoCaptureSummary(request, notify) {
|
|
|
134
157
|
};
|
|
135
158
|
const aiPrompt = buildBoundedSummaryPrompt(request.context, systemPrompt, toolSchema);
|
|
136
159
|
const captureSessionID = `auto-capture-${request.prompt?.id ?? request.sessionId}-${randomUUID()}`;
|
|
137
|
-
|
|
160
|
+
// Replace whatever the failed host-model attempt recorded.
|
|
161
|
+
Object.assign(diagnostics, {
|
|
162
|
+
path: "external-api",
|
|
163
|
+
provider: CONFIG.memoryProvider,
|
|
164
|
+
model: CONFIG.memoryModel,
|
|
165
|
+
systemPrompt,
|
|
166
|
+
userPrompt: aiPrompt,
|
|
167
|
+
stopReason: undefined,
|
|
168
|
+
blockTypes: undefined,
|
|
169
|
+
rawReply: undefined,
|
|
170
|
+
failureReason: undefined,
|
|
171
|
+
});
|
|
172
|
+
let result;
|
|
173
|
+
try {
|
|
174
|
+
result = await provider.executeToolCall(systemPrompt, aiPrompt, toolSchema, captureSessionID);
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
diagnostics.failureReason = "call-error";
|
|
178
|
+
throw error;
|
|
179
|
+
}
|
|
180
|
+
diagnostics.stopReason = normalizeStopReason(result.stopReason);
|
|
138
181
|
if (!result.success || !result.data) {
|
|
182
|
+
diagnostics.failureReason = diagnostics.stopReason === "length" ? "truncated" : "call-error";
|
|
139
183
|
throw new Error(result.error || "Failed to generate summary");
|
|
140
184
|
}
|
|
141
185
|
const rawReply = JSON.stringify(result.data);
|
|
186
|
+
diagnostics.rawReply = rawReply;
|
|
142
187
|
const summary = parseCaptureSummary(rawReply);
|
|
143
188
|
if (!summary) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
// The reply can carry conversation content, so log only its size.
|
|
148
|
-
replyLength: rawReply.length,
|
|
149
|
-
});
|
|
189
|
+
// The capture pipeline logs the attempt's metadata; never the reply.
|
|
190
|
+
diagnostics.failureReason =
|
|
191
|
+
classifyCaptureReply({ text: rawReply, stopReason: result.stopReason }) ?? "schema-mismatch";
|
|
150
192
|
throw new Error("omms: OpenCode extraction returned an invalid summary payload");
|
|
151
193
|
}
|
|
152
194
|
return summary;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type OpencodeModelRef } from "../../services/ai/opencode-import-models.js";
|
|
2
|
+
export { createOpencodeImportModels } from "../../services/ai/opencode-import-models.js";
|
|
3
|
+
export type { OpencodeModelRef } from "../../services/ai/opencode-import-models.js";
|
|
2
4
|
/**
|
|
3
5
|
* OpenCode command surface for the historical-session importer:
|
|
4
6
|
*
|
|
@@ -12,10 +14,6 @@ import { type HistoryImportModels } from "../../importer/run-import.js";
|
|
|
12
14
|
export declare const OPENCODE_IMPORT_COMMAND = "memory-import-opencode-history";
|
|
13
15
|
export declare const OPENCODE_IMPORT_DESCRIPTION = "Import historical OpenCode sessions into the shared memory store (try --dry-run first)";
|
|
14
16
|
export declare const OPENCODE_IMPORT_USAGE: string;
|
|
15
|
-
export interface OpencodeModelRef {
|
|
16
|
-
providerID: string;
|
|
17
|
-
modelID: string;
|
|
18
|
-
}
|
|
19
17
|
export interface OpencodeImportCommandInput {
|
|
20
18
|
argsText: string;
|
|
21
19
|
/** Session directory; relative paths and the default project resolve here. */
|
|
@@ -24,8 +22,6 @@ export interface OpencodeImportCommandInput {
|
|
|
24
22
|
sessionModel: () => Promise<OpencodeModelRef | null>;
|
|
25
23
|
notify?: (message: string) => void;
|
|
26
24
|
}
|
|
27
|
-
/** Capture and profile calls routed through OpenCode's structured-output sessions. */
|
|
28
|
-
export declare function createOpencodeImportModels(ref: OpencodeModelRef, directory: string): Promise<Required<HistoryImportModels>>;
|
|
29
25
|
/** Parse, run, and describe one import; always resolves to text for the session. */
|
|
30
26
|
export declare function runOpencodeImportCommand(input: OpencodeImportCommandInput): Promise<string>;
|
|
31
27
|
/** The model of the session's latest user message, from the V1 message list. */
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { buildBoundedSummaryPrompt } from "../../core/capture-context.js";
|
|
1
|
+
import { isConfigured } from "../../config.js";
|
|
3
2
|
import { historyImportUsage, importNeedsModel, parseHistoryImportArgs, tokenizeImportArgs, } from "../../importer/import-args.js";
|
|
4
3
|
import { formatHistoryImportReport, summarizeHistoryImportReport, runHistoryImport, } from "../../importer/run-import.js";
|
|
4
|
+
import { createOpencodeImportModels, } from "../../services/ai/opencode-import-models.js";
|
|
5
|
+
export { createOpencodeImportModels } from "../../services/ai/opencode-import-models.js";
|
|
5
6
|
import { loadOpencodeProvider } from "../../services/ai/opencode-provider-loader.js";
|
|
6
7
|
import { memoryClient } from "../../services/client.js";
|
|
7
8
|
import { log } from "../../services/logger.js";
|
|
@@ -23,58 +24,6 @@ function splitModel(value) {
|
|
|
23
24
|
const separator = value.indexOf("/");
|
|
24
25
|
return { providerID: value.slice(0, separator), modelID: value.slice(separator + 1) };
|
|
25
26
|
}
|
|
26
|
-
/** Capture and profile calls routed through OpenCode's structured-output sessions. */
|
|
27
|
-
export async function createOpencodeImportModels(ref, directory) {
|
|
28
|
-
const { getV2Client, generateStructuredOutput } = await loadOpencodeProvider();
|
|
29
|
-
const client = getV2Client();
|
|
30
|
-
if (!client)
|
|
31
|
-
throw new Error("the OpenCode client is not ready; retry in a moment");
|
|
32
|
-
const { z } = await import("zod");
|
|
33
|
-
const { buildCaptureSystemPrompt, createUserProfileAnalysisSchema, parseCaptureSummary } = await import("../../core/extraction.js");
|
|
34
|
-
const { detectLanguage, getLanguageName } = await import("../../services/language-detector.js");
|
|
35
|
-
const captureSchema = z.object({
|
|
36
|
-
summary: z.string().optional(),
|
|
37
|
-
type: z.string(),
|
|
38
|
-
tags: z.array(z.string()).optional(),
|
|
39
|
-
});
|
|
40
|
-
const capture = {
|
|
41
|
-
async summarize(request) {
|
|
42
|
-
const target = CONFIG.autoCaptureLanguage && CONFIG.autoCaptureLanguage !== "auto"
|
|
43
|
-
? CONFIG.autoCaptureLanguage
|
|
44
|
-
: detectLanguage(request.userPrompt);
|
|
45
|
-
const systemPrompt = buildCaptureSystemPrompt(getLanguageName(target));
|
|
46
|
-
const result = await generateStructuredOutput({
|
|
47
|
-
client,
|
|
48
|
-
...ref,
|
|
49
|
-
systemPrompt,
|
|
50
|
-
userPrompt: buildBoundedSummaryPrompt(request.context, systemPrompt, z.toJSONSchema(captureSchema)),
|
|
51
|
-
schema: captureSchema,
|
|
52
|
-
directory,
|
|
53
|
-
});
|
|
54
|
-
const parsed = parseCaptureSummary(JSON.stringify(result));
|
|
55
|
-
if (!parsed)
|
|
56
|
-
throw new Error("History capture returned an invalid summary");
|
|
57
|
-
return parsed;
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
const profileSchema = createUserProfileAnalysisSchema(z);
|
|
61
|
-
const profile = {
|
|
62
|
-
provider: ref.providerID,
|
|
63
|
-
modelId: ref.modelID,
|
|
64
|
-
async complete(systemPrompt, userPrompt) {
|
|
65
|
-
const result = await generateStructuredOutput({
|
|
66
|
-
client,
|
|
67
|
-
...ref,
|
|
68
|
-
systemPrompt,
|
|
69
|
-
userPrompt,
|
|
70
|
-
schema: profileSchema,
|
|
71
|
-
directory,
|
|
72
|
-
});
|
|
73
|
-
return JSON.stringify(result);
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
return { capture, profile };
|
|
77
|
-
}
|
|
78
27
|
/** Parse, run, and describe one import; always resolves to text for the session. */
|
|
79
28
|
export async function runOpencodeImportCommand(input) {
|
|
80
29
|
const name = OPENCODE_IMPORT_COMMAND;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
2
|
import { CONFIG, initConfigWithLegacyMigration, isConfigured } from "../../config.js";
|
|
3
|
+
import { pruneTraces } from "../../services/capture-diagnostics.js";
|
|
3
4
|
import { executeMemoryOperation } from "../../core/memory-operations.js";
|
|
4
5
|
import { getLanguageName } from "../../services/language-detector.js";
|
|
5
6
|
import { log } from "../../services/logger.js";
|
|
@@ -97,6 +98,8 @@ export default function ommsPiExtension(pi) {
|
|
|
97
98
|
try {
|
|
98
99
|
latestCtx = ctx;
|
|
99
100
|
initConfigWithLegacyMigration(ctx.cwd);
|
|
101
|
+
// Runs even with tracing off, so turning it off does not leave old traces behind.
|
|
102
|
+
pruneTraces(CONFIG);
|
|
100
103
|
captureState = createPiCaptureState();
|
|
101
104
|
const globalScope = globalThis;
|
|
102
105
|
if (!globalScope[GLOBAL_PLUGIN_WARMUP_KEY] && isConfigured()) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CONFIG } from "../../config.js";
|
|
1
|
+
import { CONFIG, refreshConfigIfChanged } from "../../config.js";
|
|
2
2
|
import { analyzeProfile, } from "../../core/profile-analysis.js";
|
|
3
3
|
import { log } from "../../services/logger.js";
|
|
4
4
|
import { getTags } from "../../services/tags.js";
|
|
@@ -47,6 +47,7 @@ export async function performPiProfileLearning(input) {
|
|
|
47
47
|
if (input.prompts.length === 0)
|
|
48
48
|
return;
|
|
49
49
|
try {
|
|
50
|
+
refreshConfigIfChanged(input.directory);
|
|
50
51
|
const tags = getTags(input.directory);
|
|
51
52
|
if (!tags.user.userEmail) {
|
|
52
53
|
log("pi profile learning: skipped (no user email resolved)", {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { CONFIG } from "../../config.js";
|
|
2
2
|
import { buildBoundedSummaryPrompt } from "../../core/capture-context.js";
|
|
3
|
-
import { buildCaptureSystemPrompt, captureSummaryToolSchema, parseCaptureSummary, } from "../../core/extraction.js";
|
|
3
|
+
import { buildCaptureReplyInstruction, buildCaptureSystemPrompt, captureSummaryToolSchema, classifyCaptureReply, normalizeStopReason, parseCaptureSummary, } from "../../core/extraction.js";
|
|
4
4
|
import { detectLanguage, getLanguageName } from "../../services/language-detector.js";
|
|
5
|
-
import { log } from "../../services/logger.js";
|
|
6
5
|
/**
|
|
7
6
|
* Active-model-first resolution: the explicit `piProvider`/`piModel`
|
|
8
7
|
* configuration when both are set, otherwise the active `ctx.model`.
|
|
@@ -80,23 +79,51 @@ export function createPiCaptureProvider(resolveModel) {
|
|
|
80
79
|
? detectLanguage(request.userPrompt)
|
|
81
80
|
: CONFIG.autoCaptureLanguage;
|
|
82
81
|
const systemPrompt = buildCaptureSystemPrompt(getLanguageName(targetLang));
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
82
|
+
const replyInstruction = buildCaptureReplyInstruction();
|
|
83
|
+
// The instruction is counted as schema bytes so the context budget leaves room for it.
|
|
84
|
+
const userPrompt = `${buildBoundedSummaryPrompt(request.context, systemPrompt, {
|
|
85
|
+
schema: captureSummaryToolSchema,
|
|
86
|
+
replyInstruction,
|
|
87
|
+
})}\n\n${replyInstruction}`;
|
|
88
|
+
const diagnostics = request.diagnostics;
|
|
89
|
+
if (diagnostics) {
|
|
90
|
+
diagnostics.path = "host-model";
|
|
91
|
+
diagnostics.provider = model.provider;
|
|
92
|
+
diagnostics.model = model.modelId;
|
|
93
|
+
diagnostics.systemPrompt = systemPrompt;
|
|
94
|
+
diagnostics.userPrompt = userPrompt;
|
|
95
|
+
}
|
|
96
|
+
let reply;
|
|
97
|
+
try {
|
|
98
|
+
reply = await model.complete({
|
|
99
|
+
systemPrompt,
|
|
100
|
+
messages: [{ role: "user", content: userPrompt, timestamp: Date.now() }],
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
if (diagnostics)
|
|
105
|
+
diagnostics.failureReason = "call-error";
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
const rawReply = replyText(reply);
|
|
109
|
+
if (diagnostics) {
|
|
110
|
+
diagnostics.stopReason = normalizeStopReason(reply.stopReason);
|
|
111
|
+
diagnostics.blockTypes = reply.content.map((block) => block.type);
|
|
112
|
+
diagnostics.rawReply = rawReply;
|
|
113
|
+
}
|
|
88
114
|
if (reply.stopReason === "error") {
|
|
115
|
+
if (diagnostics)
|
|
116
|
+
diagnostics.failureReason = "call-error";
|
|
89
117
|
throw new Error(`omms: Pi extraction call failed: ${reply.errorMessage || "unknown error"}`);
|
|
90
118
|
}
|
|
91
|
-
const rawReply = replyText(reply);
|
|
92
119
|
const summary = parseCaptureSummary(rawReply);
|
|
93
120
|
if (!summary) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
121
|
+
// The capture pipeline logs the attempt's metadata; never the reply.
|
|
122
|
+
if (diagnostics) {
|
|
123
|
+
diagnostics.failureReason =
|
|
124
|
+
classifyCaptureReply({ text: rawReply, stopReason: reply.stopReason }) ??
|
|
125
|
+
"schema-mismatch";
|
|
126
|
+
}
|
|
100
127
|
throw new Error("omms: Pi extraction returned an invalid summary payload");
|
|
101
128
|
}
|
|
102
129
|
return summary;
|
package/dist/config.d.ts
CHANGED
|
@@ -38,6 +38,10 @@ interface OmmsConfig {
|
|
|
38
38
|
piProvider?: string;
|
|
39
39
|
piModel?: string;
|
|
40
40
|
aiSessionRetentionDays?: number;
|
|
41
|
+
/** Write full capture prompts and replies to ~/.omms/traces. Global config only. */
|
|
42
|
+
captureTrace?: boolean;
|
|
43
|
+
captureTraceRetentionDays?: number;
|
|
44
|
+
captureAttemptRetentionDays?: number;
|
|
41
45
|
webServerEnabled?: boolean;
|
|
42
46
|
webServerPort?: number;
|
|
43
47
|
webServerHost?: string;
|
|
@@ -85,6 +89,7 @@ interface OmmsConfig {
|
|
|
85
89
|
injectOn?: "first" | "always";
|
|
86
90
|
};
|
|
87
91
|
}
|
|
92
|
+
export declare const CONFIG_TEMPLATE = "{\n // ============================================\n // omms (Opinionated Modular Memory System) Configuration\n // ============================================\n \n // Storage location for the vector database. Leave unset to use the\n // default ~/.omms/data (a legacy ~/.opencode-mem/data store is migrated\n // there automatically on first start; see docs/omms-migration.md).\n // \"storagePath\": \"~/.omms/data\",\n\n \"userEmailOverride\": \"\",\n \"userNameOverride\": \"\",\n \n // ============================================\n // Embedding Model (for similarity search)\n // ============================================\n // Local = Hugging Face / ONNX via @huggingface/transformers (not Apple MLX).\n // Remote = set BOTH embeddingApiUrl and embeddingApiKey (OpenAI-compatible /embeddings).\n \n // Default: Nomic Embed v1 (768 dimensions, 8192 context, multilingual)\n \"embeddingModel\": \"Xenova/nomic-embed-text-v1\",\n\n // Opt-in Nomic task prefixes (search_document: / search_query:). After enabling,\n // re-index existing memories so store and query vectors stay aligned.\n // \"embeddingUseTaskPrefixes\": true,\n \n // Auto-detected dimensions (no need to set manually)\n // \"embeddingDimensions\": 768,\n \n // Other recommended local models:\n // \"embeddingModel\": \"Xenova/jina-embeddings-v2-base-en\", // 768 dims, English-only, 8192 context\n // \"embeddingModel\": \"Xenova/jina-embeddings-v2-small-en\", // 512 dims, faster, 8192 context\n // \"embeddingModel\": \"Xenova/all-MiniLM-L6-v2\", // 384 dims, very fast, 512 context\n // \"embeddingModel\": \"Xenova/all-mpnet-base-v2\", // 768 dims, good quality, 512 context\n \n // Optional: OpenAI-compatible API for embeddings (both URL and key required)\n // \"embeddingApiUrl\": \"https://api.openai.com/v1\",\n // \"embeddingApiKey\": \"env://OPENAI_API_KEY\", // or \"sk-...\" / \"file:///path/to/key\"\n // \"embeddingModel\": \"text-embedding-3-small\", // 1536 dims, auto-detected\n \n // ============================================\n // Web Server Settings\n // ============================================\n \n // Enable web UI for managing memories (accessible at http://localhost:4747)\n \"webServerEnabled\": true,\n \n // Port for web UI server\n \"webServerPort\": 4747,\n \n // Host address for web UI (use 127.0.0.1 for local only, 0.0.0.0 for network access)\n \"webServerHost\": \"127.0.0.1\",\n\n // Optional HTTP Basic Auth for the web UI. Accepts literal, env://, or file:// secrets.\n // \"webServerAuthPassword\": \"\",\n // \"webServerAuthUsername\": \"\",\n\n // Required when webServerHost is not loopback. Protects /api/* with Bearer / X-Opencode-Mem-Token.\n // \"webServerApiToken\": \"env://OMMS_WEB_TOKEN\",\n \n // ============================================\n // Database Settings\n // ============================================\n \n // Maximum vectors per database shard (auto-creates new shard when limit reached)\n \"maxVectorsPerShard\": 50000,\n \n // Automatically delete old memories based on retention period\n \"autoCleanupEnabled\": true,\n \n // Days to keep memories before auto-cleanup (only if autoCleanupEnabled is true)\n \"autoCleanupRetentionDays\": 30,\n \n // Automatically detect and remove duplicate memories\n \"deduplicationEnabled\": true,\n \n // Similarity threshold (0-1) for detecting duplicates (higher = stricter)\n \"deduplicationSimilarityThreshold\": 0.90,\n \n // ============================================\n // Memory Scope Settings\n // ============================================\n\n // Default scope for memory list/search queries\n // \"project\" keeps queries within the current project, \"all-projects\" searches across all project shards\n \"memory\": {\n \"defaultScope\": \"project\"\n },\n\n // ============================================\n // Model for auto-capture and profile learning (same rule in OpenCode and Pi)\n // ============================================\n\n // Which model summarises your work, in this order:\n // 1. The host model below: opencodeProvider/opencodeModel in OpenCode,\n // piProvider/piModel in Pi. Set the model to \"inherit\" to follow\n // whatever model the session is using.\n // 2. If no host model is set: the external API (memoryModel/memoryApiUrl/\n // memoryApiKey further down).\n // 3. If neither is set: the session's own model.\n // If the host model fails and the external API is configured, the external\n // API is used instead.\n //\n // Host models go through OpenCode's or Pi's own sign-in (OAuth like Claude\n // Pro/Max, GitHub Copilot, ChatGPT, or your own key there), so no separate API\n // key is needed here.\n //\n // Examples (OpenCode names from 'opencode providers list'; Pi names from its model list):\n // \"opencodeProvider\": \"anthropic\", \"opencodeModel\": \"claude-haiku-4-5-20251001\"\n // \"opencodeProvider\": \"openai\", \"opencodeModel\": \"inherit\"\n // \"piProvider\": \"openai-codex\", \"piModel\": \"gpt-5.6-luna\"\n //\n // \"opencodeProvider\": \"anthropic\",\n // \"opencodeModel\": \"claude-haiku-4-5-20251001\",\n // \"piProvider\": \"openai-codex\",\n // \"piModel\": \"gpt-5.6-luna\",\n\n // ============================================\n // Auto-Capture Settings\n // ============================================\n \n // Auto-capture runs in the background without blocking your main session.\n // Note: Ollama may not support tool calling. Use OpenAI, Anthropic, or Groq for best results.\n \n \"autoCaptureEnabled\": true,\n \n // Provider type: \"openai-chat\" | \"openai-responses\" | \"anthropic\" | \"minimax\" | \"orcarouter\"\n // Note: \"openai-chat\" is a generic OpenAI API-compatible mode.\n // Any service that follows the OpenAI Chat Completions API can use it via custom \"memoryApiUrl\".\n \"memoryProvider\": \"openai-chat\",\n \n // External API (step 2 above, and the fallback when a host model fails).\n // Uncomment all 3 lines and replace memoryApiKey before use:\n // \"memoryModel\": \"gpt-4o-mini\",\n // \"memoryApiUrl\": \"https://api.openai.com/v1\",\n // \"memoryApiKey\": \"sk-...\",\n\n // API Key Formats:\n // Direct value: \"sk-...\"\n // From file: \"file://~/.config/litellm-key.txt\"\n // From env variable: \"env://LITELLM_API_KEY\"\n \n // Examples for different providers:\n // Any OpenAI-compatible endpoint can use the \"openai-chat\" provider pattern below.\n // Common examples: DeepSeek, Qwen (via Alibaba Cloud ModelStudio),\n // Zhipu GLM (BigModel platform), and Kimi (Moonshot AI platform).\n\n // OpenAI Chat Completion (default, backward compatible):\n // \"memoryProvider\": \"openai-chat\"\n // \"memoryModel\": \"gpt-4o-mini\"\n // \"memoryApiUrl\": \"https://api.openai.com/v1\"\n // \"memoryApiKey\": \"sk-...\"\n\n // DeepSeek (OpenAI-compatible example):\n // \"memoryProvider\": \"openai-chat\"\n // \"memoryModel\": \"deepseek-chat\"\n // \"memoryApiUrl\": \"https://api.deepseek.com/v1\"\n // \"memoryApiKey\": \"sk-...\"\n \n // OpenAI Responses API (recommended, with session support):\n // \"memoryProvider\": \"openai-responses\"\n // \"memoryModel\": \"gpt-4o\"\n // \"memoryApiUrl\": \"https://api.openai.com/v1\"\n // \"memoryApiKey\": \"sk-...\"\n \n // Anthropic (with session support):\n // \"memoryProvider\": \"anthropic\"\n // \"memoryModel\": \"claude-3-5-haiku-20241022\"\n // \"memoryApiUrl\": \"https://api.anthropic.com/v1\"\n // \"memoryApiKey\": \"sk-ant-...\"\n\n // MiniMax (Anthropic Messages-compatible endpoint, with session support):\n // \"memoryProvider\": \"minimax\"\n // \"memoryModel\": \"MiniMax-M3\"\n // \"memoryApiUrl\": \"https://api.minimax.io\" // global endpoint\n // \"memoryApiKey\": \"<MiniMax API key>\"\n // // China endpoint: \"memoryApiUrl\": \"https://api.minimaxi.com\"\n // // Optional adaptive thinking for MiniMax-M3:\n // \"memoryExtraParams\": { \"thinking\": { \"type\": \"adaptive\" } }\n\n // OrcaRouter (OpenAI-compatible gateway, namespaced model IDs, with session support):\n // \"memoryProvider\": \"orcarouter\"\n // \"memoryApiKey\": \"<OrcaRouter API key>\"\n // // memoryApiUrl and memoryModel are optional \u2014 they default to\n // // https://api.orcarouter.ai/v1 and \"orcarouter/auto\" (a routing alias).\n // // OrcaRouter rejects bare model names, so if you set memoryModel, use a\n // // namespaced ID such as \"openai/gpt-5.5\" or \"deepseek/deepseek-v4-flash\".\n // \"memoryModel\": \"openai/gpt-5.5\"\n\n // Groq (OpenAI-compatible, use openai-chat provider):\n // \"memoryProvider\": \"openai-chat\"\n // \"memoryModel\": \"llama-3.3-70b-versatile\"\n // \"memoryApiUrl\": \"https://api.groq.com/openai/v1\"\n // \"memoryApiKey\": \"gsk_...\"\n \n // Maximum iterations for multi-turn AI analysis (for openai-responses, anthropic, and minimax)\n \"autoCaptureMaxIterations\": 5,\n \n // Timeout per iteration in milliseconds (30 seconds default)\n \"autoCaptureIterationTimeout\": 30000,\n\n // Maximum number of times to retry capturing a prompt if it fails (due to network, API errors, etc.)\n \"autoCaptureMaxRetries\": 3,\n\n // Maximum UTF-8 bytes for the auto-capture markdown context sent to the summary model.\n // Prevents HTTP 400 context overflows on models with ~131K token windows (e.g. Groq Llama).\n // Rough guide: tokens \u2248 bytes / 4 for mixed code/prose.\n \"autoCaptureMaxContextBytes\": 131072,\n \n // Days to keep AI session history before cleanup\n \"aiSessionRetentionDays\": 7,\n\n // Capture diagnostics: every capture attempt always writes one metadata line\n // (model, stop reason, sizes, outcome) to ~/.omms/omms.log, with no\n // conversation text. Set captureTrace to true to also write each attempt's\n // prompt and raw reply to ~/.omms/traces/ for debugging. Traces can contain\n // conversation content: <private> text and common API key formats are\n // redacted, files are readable only by you, and they are deleted after\n // captureTraceRetentionDays. Only this global file can turn tracing on.\n // \"captureTrace\": false,\n // \"captureTraceRetentionDays\": 7,\n // \"captureAttemptRetentionDays\": 30,\n\n // Temperature for AI API requests (set to false to omit parameter for models that don't support it)\n // Some reasoning models (like o1, o3, gpt-5) don't support temperature parameter\n // Set to false and add \"memoryTemperature\": false in config when using such models\n \"memoryTemperature\": 0.3,\n\n // Extra parameters to include in API request body\n // Useful for local inference servers (e.g. llama-server with --jinja) that support\n // additional parameters like disabling thinking/reasoning mode\n // Example for Qwen3 models: { \"enable_thinking\": false }\n // \"memoryExtraParams\": {},\n\n // Language for auto-capture summaries (default: \"auto\" for auto-detection)\n // Options: \"auto\", \"en\", \"id\", \"zh\", \"ja\", \"es\", \"fr\", \"de\", \"ru\", \"pt\", \"ar\", \"ko\"\n // \"autoCaptureLanguage\": \"auto\",\n\n // ============================================\n // Toast Notifications\n // ============================================\n\n // Show toast when memory is auto-captured\n \"showAutoCaptureToasts\": true,\n\n // Show toast when user profile is updated\n \"showUserProfileToasts\": true,\n\n // Show toast for error messages\n \"showErrorToasts\": true,\n\n // ============================================\n // User Profile System\n // ============================================\n\n // Analyze user prompts every N prompts to build/update your user profile\n // When N uncaptured prompts accumulate, AI will analyze them to identify:\n // - User preferences (code style, communication style, tool preferences)\n // - User patterns (recurring topics, problem domains, technical interests)\n // - User workflows (development habits, sequences, learning style)\n // - Skill level (overall and per-domain assessment)\n \"userProfileAnalysisInterval\": 10,\n\n // Days before inactive items (all types) are eligible for removal\n \"userProfileStaleDays\": 2,\n\n // Number of preferences shown in UI\n \"userProfileDisplayPreferences\": 20,\n \n // Number of patterns shown in UI\n \"userProfileDisplayPatterns\": 15,\n \n // Number of workflows shown in UI\n \"userProfileDisplayWorkflows\": 10,\n \n // Number of preferences injected into LLM conversation context\n // Keep this small \u2014 the strongest signals are enough; more dilute LLM attention\n \"userProfileInjectPreferences\": 5,\n \n // Number of patterns injected into LLM conversation context\n \"userProfileInjectPatterns\": 5,\n \n // Number of workflows injected into LLM conversation context\n \"userProfileInjectWorkflows\": 3,\n \n // Days before preference confidence starts to decay (if not reinforced)\n // Preferences that aren't seen again will gradually lose confidence and be removed\n \"userProfileConfidenceDecayDays\": 30,\n \n // Number of profile versions to keep in changelog (for rollback/debugging)\n // Older versions are automatically cleaned up\n \"userProfileChangelogRetentionCount\": 5,\n\n // Minimum evidence count for a preference/pattern to survive confidence decay\n // Items confirmed fewer times are more likely to be pruned when confidence decays\n \"userProfileMinEvidenceForRetention\": 3,\n\n // Periodically merge duplicate or irrelevant profile items with the configured AI provider\n \"userProfileAutoCleanupEnabled\": true,\n // Number of analyzed user prompts between automatic AI cleanup runs\n \"userProfileAutoCleanupInterval\": 100,\n\n // Enable LLM validation of existing preferences against recent behavior.\n // When enabled, each analysis round checks if top-5 preferences still match recent prompts.\n // Experimental \u2014 disabled by default.\n \"userProfileValidationEnabled\": false,\n\n // ============================================\n // Search Settings\n // ============================================\n \n // Minimum similarity score (0-1) for memory search results\n \"similarityThreshold\": 0.6,\n\n // Maximum number of memories to return in search results\n \"maxMemories\": 10,\n\n // ============================================\n // Advanced Settings\n // ============================================\n \n // Inject user profile into AI context (preferences, patterns, workflows)\n \"injectProfile\": true\n}\n";
|
|
88
93
|
export declare function normalizeAutoCaptureMaxContextBytes(value: number): number;
|
|
89
94
|
export declare function normalizeAutoCleanupRetentionDays(value: number): number;
|
|
90
95
|
declare function buildConfig(fileConfig: OmmsConfig): {
|
|
@@ -119,6 +124,9 @@ declare function buildConfig(fileConfig: OmmsConfig): {
|
|
|
119
124
|
piModel: string | undefined;
|
|
120
125
|
autoCaptureProviderStatus: import("./config.js").AutoCaptureProviderStatus;
|
|
121
126
|
aiSessionRetentionDays: number;
|
|
127
|
+
captureTrace: boolean;
|
|
128
|
+
captureTraceRetentionDays: number;
|
|
129
|
+
captureAttemptRetentionDays: number;
|
|
122
130
|
webServerEnabled: boolean;
|
|
123
131
|
webServerPort: number;
|
|
124
132
|
webServerHost: string;
|
|
@@ -169,6 +177,9 @@ declare function buildConfig(fileConfig: OmmsConfig): {
|
|
|
169
177
|
injectOn: "first" | "always";
|
|
170
178
|
};
|
|
171
179
|
};
|
|
180
|
+
export declare function getGlobalConfigSourcePath(): string | undefined;
|
|
181
|
+
export declare function getGlobalConfigWritePath(): string;
|
|
182
|
+
export declare function validateGlobalConfig(value: unknown): void;
|
|
172
183
|
export declare let CONFIG: {
|
|
173
184
|
storagePath: string;
|
|
174
185
|
userEmailOverride: string | undefined;
|
|
@@ -201,6 +212,9 @@ export declare let CONFIG: {
|
|
|
201
212
|
piModel: string | undefined;
|
|
202
213
|
autoCaptureProviderStatus: import("./config.js").AutoCaptureProviderStatus;
|
|
203
214
|
aiSessionRetentionDays: number;
|
|
215
|
+
captureTrace: boolean;
|
|
216
|
+
captureTraceRetentionDays: number;
|
|
217
|
+
captureAttemptRetentionDays: number;
|
|
204
218
|
webServerEnabled: boolean;
|
|
205
219
|
webServerPort: number;
|
|
206
220
|
webServerHost: string;
|
|
@@ -255,7 +269,10 @@ type RuntimeConfig = ReturnType<typeof buildConfig>;
|
|
|
255
269
|
export { getAutoCaptureProviderStatus, type AutoCaptureProviderStatus, } from "./services/ai/live-model-choice.js";
|
|
256
270
|
export { isPlaceholderApiKey };
|
|
257
271
|
export declare function hasAutoCaptureProviderConfig(config?: RuntimeConfig): boolean;
|
|
258
|
-
export declare function
|
|
272
|
+
export declare function refreshConfigIfChanged(directory: string): void;
|
|
273
|
+
export declare function initConfig(directory: string, options?: {
|
|
274
|
+
strict?: boolean;
|
|
275
|
+
}): void;
|
|
259
276
|
/**
|
|
260
277
|
* initConfig plus the one-time legacy store migration (decision D13).
|
|
261
278
|
*
|
package/dist/config.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync, readFileSync, mkdirSync, writeFileSync } from "node:fs";
|
|
1
|
+
import { existsSync, readFileSync, mkdirSync, writeFileSync, statSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { stripJsoncComments } from "./services/jsonc.js";
|
|
@@ -48,6 +48,9 @@ const DEFAULTS = {
|
|
|
48
48
|
autoCaptureMaxRetries: 3,
|
|
49
49
|
autoCaptureMaxContextBytes: 131072,
|
|
50
50
|
aiSessionRetentionDays: 7,
|
|
51
|
+
captureTrace: false,
|
|
52
|
+
captureTraceRetentionDays: 7,
|
|
53
|
+
captureAttemptRetentionDays: 30,
|
|
51
54
|
webServerEnabled: true,
|
|
52
55
|
webServerPort: 4747,
|
|
53
56
|
webServerHost: "127.0.0.1",
|
|
@@ -108,8 +111,9 @@ function expandPath(path) {
|
|
|
108
111
|
* Load the first config file that exists, in priority order. A file that
|
|
109
112
|
* exists but cannot be read or parsed is not skipped: falling through would let
|
|
110
113
|
* a lower-priority (legacy) file silently supply settings such as storagePath.
|
|
114
|
+
* `strict` (live reload) throws instead, so running hosts keep their settings.
|
|
111
115
|
*/
|
|
112
|
-
function loadConfigFromPaths(paths) {
|
|
116
|
+
function loadConfigFromPaths(paths, strict = false) {
|
|
113
117
|
const path = paths.find((candidate) => existsSync(candidate));
|
|
114
118
|
if (!path)
|
|
115
119
|
return {};
|
|
@@ -119,6 +123,9 @@ function loadConfigFromPaths(paths) {
|
|
|
119
123
|
return JSON.parse(json);
|
|
120
124
|
}
|
|
121
125
|
catch (error) {
|
|
126
|
+
// The parser's message can quote file content, so a reload names the file only.
|
|
127
|
+
if (strict)
|
|
128
|
+
throw new Error(`Config file cannot be parsed: ${path}`, { cause: error });
|
|
122
129
|
log("Config file is invalid; using defaults instead of lower-priority files", {
|
|
123
130
|
path,
|
|
124
131
|
error: String(error),
|
|
@@ -140,7 +147,7 @@ function assertProjectRemoteProviderConfigIsSafe(projectConfig) {
|
|
|
140
147
|
`Move them to the global config at ${CONFIG_FILES[0]}.`);
|
|
141
148
|
}
|
|
142
149
|
}
|
|
143
|
-
const CONFIG_TEMPLATE = `{
|
|
150
|
+
export const CONFIG_TEMPLATE = `{
|
|
144
151
|
// ============================================
|
|
145
152
|
// omms (Opinionated Modular Memory System) Configuration
|
|
146
153
|
// ============================================
|
|
@@ -352,6 +359,17 @@ const CONFIG_TEMPLATE = `{
|
|
|
352
359
|
// Days to keep AI session history before cleanup
|
|
353
360
|
"aiSessionRetentionDays": 7,
|
|
354
361
|
|
|
362
|
+
// Capture diagnostics: every capture attempt always writes one metadata line
|
|
363
|
+
// (model, stop reason, sizes, outcome) to ~/.omms/omms.log, with no
|
|
364
|
+
// conversation text. Set captureTrace to true to also write each attempt's
|
|
365
|
+
// prompt and raw reply to ~/.omms/traces/ for debugging. Traces can contain
|
|
366
|
+
// conversation content: <private> text and common API key formats are
|
|
367
|
+
// redacted, files are readable only by you, and they are deleted after
|
|
368
|
+
// captureTraceRetentionDays. Only this global file can turn tracing on.
|
|
369
|
+
// "captureTrace": false,
|
|
370
|
+
// "captureTraceRetentionDays": 7,
|
|
371
|
+
// "captureAttemptRetentionDays": 30,
|
|
372
|
+
|
|
355
373
|
// Temperature for AI API requests (set to false to omit parameter for models that don't support it)
|
|
356
374
|
// Some reasoning models (like o1, o3, gpt-5) don't support temperature parameter
|
|
357
375
|
// Set to false and add "memoryTemperature": false in config when using such models
|
|
@@ -580,6 +598,9 @@ function buildConfig(fileConfig) {
|
|
|
580
598
|
memoryApiKey,
|
|
581
599
|
}),
|
|
582
600
|
aiSessionRetentionDays: fileConfig.aiSessionRetentionDays ?? DEFAULTS.aiSessionRetentionDays,
|
|
601
|
+
captureTrace: fileConfig.captureTrace === true,
|
|
602
|
+
captureTraceRetentionDays: Math.max(1, Math.floor(fileConfig.captureTraceRetentionDays ?? DEFAULTS.captureTraceRetentionDays)),
|
|
603
|
+
captureAttemptRetentionDays: normalizeAutoCleanupRetentionDays(fileConfig.captureAttemptRetentionDays ?? DEFAULTS.captureAttemptRetentionDays),
|
|
583
604
|
webServerEnabled: fileConfig.webServerEnabled ?? DEFAULTS.webServerEnabled,
|
|
584
605
|
webServerPort: fileConfig.webServerPort ?? DEFAULTS.webServerPort,
|
|
585
606
|
webServerHost: fileConfig.webServerHost ?? DEFAULTS.webServerHost,
|
|
@@ -638,6 +659,21 @@ function buildConfig(fileConfig) {
|
|
|
638
659
|
},
|
|
639
660
|
};
|
|
640
661
|
}
|
|
662
|
+
export function getGlobalConfigSourcePath() {
|
|
663
|
+
return CONFIG_FILES.find((candidate) => existsSync(candidate));
|
|
664
|
+
}
|
|
665
|
+
export function getGlobalConfigWritePath() {
|
|
666
|
+
const source = getGlobalConfigSourcePath();
|
|
667
|
+
return source && !LEGACY_CONFIG_FILES.includes(source)
|
|
668
|
+
? source
|
|
669
|
+
: join(OMMS_CONFIG_DIR, "omms.jsonc");
|
|
670
|
+
}
|
|
671
|
+
export function validateGlobalConfig(value) {
|
|
672
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
673
|
+
throw new Error("Global config must be an object");
|
|
674
|
+
}
|
|
675
|
+
buildConfig(value);
|
|
676
|
+
}
|
|
641
677
|
const _globalFileConfig = loadConfigFromPaths(CONFIG_FILES);
|
|
642
678
|
let lastFileConfig = _globalFileConfig;
|
|
643
679
|
export let CONFIG = buildConfig(_globalFileConfig);
|
|
@@ -646,23 +682,81 @@ export { isPlaceholderApiKey };
|
|
|
646
682
|
export function hasAutoCaptureProviderConfig(config = CONFIG) {
|
|
647
683
|
return getAutoCaptureProviderStatus(config).ready;
|
|
648
684
|
}
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
const projectPaths = [
|
|
685
|
+
function projectConfigPaths(directory) {
|
|
686
|
+
return [
|
|
652
687
|
join(directory, ".opencode", "omms.jsonc"),
|
|
653
688
|
join(directory, ".opencode", "omms.json"),
|
|
654
689
|
join(directory, ".opencode", "opencode-mem.jsonc"),
|
|
655
690
|
join(directory, ".opencode", "opencode-mem.json"),
|
|
656
691
|
];
|
|
657
|
-
|
|
658
|
-
|
|
692
|
+
}
|
|
693
|
+
function configSignature(directory) {
|
|
694
|
+
return [...CONFIG_FILES, ...projectConfigPaths(directory)]
|
|
695
|
+
.filter((path) => existsSync(path))
|
|
696
|
+
.map((path) => {
|
|
697
|
+
try {
|
|
698
|
+
const stat = statSync(path);
|
|
699
|
+
return `${path}:${stat.mtimeMs}:${stat.size}`;
|
|
700
|
+
}
|
|
701
|
+
catch (error) {
|
|
702
|
+
if (error.code === "ENOENT")
|
|
703
|
+
return `${path}:missing`;
|
|
704
|
+
throw error;
|
|
705
|
+
}
|
|
706
|
+
})
|
|
707
|
+
.join("|");
|
|
708
|
+
}
|
|
709
|
+
let lastConfigDirectory;
|
|
710
|
+
let lastConfigSignature;
|
|
711
|
+
/** Directory and signature of the last reload that failed. */
|
|
712
|
+
let lastFailedConfig;
|
|
713
|
+
export function refreshConfigIfChanged(directory) {
|
|
714
|
+
// Both hosts initialise their config at startup. Direct callers that have
|
|
715
|
+
// not initialised it keep their in-memory settings untouched.
|
|
716
|
+
if (lastConfigDirectory === undefined)
|
|
717
|
+
return;
|
|
718
|
+
let attempt;
|
|
719
|
+
try {
|
|
720
|
+
const signature = configSignature(directory);
|
|
721
|
+
if (directory === lastConfigDirectory && signature === lastConfigSignature)
|
|
722
|
+
return;
|
|
723
|
+
attempt = `${directory}\0${signature}`;
|
|
724
|
+
if (attempt === lastFailedConfig)
|
|
725
|
+
return;
|
|
726
|
+
initConfig(directory, { strict: true });
|
|
727
|
+
lastFailedConfig = undefined;
|
|
728
|
+
}
|
|
729
|
+
catch (error) {
|
|
730
|
+
// A bad hand edit must not stop capture: keep the last good settings, and
|
|
731
|
+
// skip this exact file state until it changes, instead of re-reading it on
|
|
732
|
+
// every unit. The last good directory and signature stay as they were.
|
|
733
|
+
log("Config reload failed; keeping the previous settings", {
|
|
734
|
+
error: error instanceof Error ? error.message : String(error),
|
|
735
|
+
});
|
|
736
|
+
lastFailedConfig = attempt;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
export function initConfig(directory, options = {}) {
|
|
740
|
+
// omms project overrides win; the legacy opencode-mem file is still read.
|
|
741
|
+
const globalConfig = loadConfigFromPaths(CONFIG_FILES, options.strict);
|
|
742
|
+
const projectConfig = loadConfigFromPaths(projectConfigPaths(directory), options.strict);
|
|
659
743
|
assertProjectRemoteProviderConfigIsSafe(projectConfig);
|
|
660
744
|
const projectOverrides = { ...projectConfig };
|
|
661
745
|
delete projectOverrides.autoCleanupEnabled;
|
|
662
746
|
delete projectOverrides.autoCleanupRetentionDays;
|
|
747
|
+
// A checked-in project file must not start recording conversations; it may
|
|
748
|
+
// only turn tracing off for its project.
|
|
749
|
+
if (projectOverrides.captureTrace === true) {
|
|
750
|
+
log("Project config cannot turn on captureTrace; the value was ignored", { directory });
|
|
751
|
+
delete projectOverrides.captureTrace;
|
|
752
|
+
}
|
|
753
|
+
delete projectOverrides.captureTraceRetentionDays;
|
|
663
754
|
const merged = { ...globalConfig, ...projectOverrides };
|
|
755
|
+
const nextConfig = buildConfig(merged);
|
|
664
756
|
lastFileConfig = merged;
|
|
665
|
-
CONFIG =
|
|
757
|
+
CONFIG = nextConfig;
|
|
758
|
+
lastConfigDirectory = directory;
|
|
759
|
+
lastConfigSignature = configSignature(directory);
|
|
666
760
|
}
|
|
667
761
|
/**
|
|
668
762
|
* Rebuild CONFIG from the last loaded file config. Used after the legacy
|
|
@@ -4,7 +4,7 @@ const DEFAULT_AUTO_CAPTURE_MAX_CONTEXT_BYTES = 131072;
|
|
|
4
4
|
const CONTEXT_TRUNCATION_MARKER = "\n[... truncated to autoCaptureMaxContextBytes ...]\n";
|
|
5
5
|
const SUMMARY_REQUEST_OVERHEAD_BYTES = 1024;
|
|
6
6
|
const SUMMARY_OUTPUT_RESERVE_BYTES = 16384;
|
|
7
|
-
const SUMMARY_ANALYSIS_SUFFIX = 'Analyze this conversation. If it contains technical work (code, bugs, features, decisions), create a concise summary and relevant tags. If it\'s non-technical (greetings, casual chat, incomplete requests),
|
|
7
|
+
const SUMMARY_ANALYSIS_SUFFIX = 'Analyze this conversation. If it contains technical work (code, bugs, features, decisions), create a concise summary and relevant tags. If it\'s non-technical (greetings, casual chat, incomplete requests), set "type" to "skip" with an empty "summary".';
|
|
8
8
|
function fitTextResponses(textResponses, maxBytes) {
|
|
9
9
|
if (textResponses.length === 0 || maxBytes <= 0)
|
|
10
10
|
return "";
|
package/dist/core/capture.d.ts
CHANGED
|
@@ -12,4 +12,8 @@ export type CaptureResult = {
|
|
|
12
12
|
status: "skipped";
|
|
13
13
|
type?: string;
|
|
14
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* Run one capture attempt and write exactly one diagnostics record for it,
|
|
17
|
+
* whether it is saved, skipped, or fails.
|
|
18
|
+
*/
|
|
15
19
|
export declare function captureConversation(workUnit: CaptureWorkUnit, provider: CaptureSummaryProvider): Promise<CaptureResult>;
|