@herbertgao/pi-extensions 2026.8.12 → 2026.8.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -3
- package/THIRD_PARTY_NOTICES.md +4 -0
- package/node_modules/@luxusai/pi-hindsight/CHANGELOG.md +376 -0
- package/node_modules/@luxusai/pi-hindsight/README.md +92 -0
- package/node_modules/@luxusai/pi-hindsight/docs/adr/001-memory-lifecycle-and-scope.md +56 -0
- package/node_modules/@luxusai/pi-hindsight/docs/adr/002-explicit-routing-strategy-seam.md +169 -0
- package/node_modules/@luxusai/pi-hindsight/docs/adr/003-tui-memory-mode-vocabulary.md +107 -0
- package/node_modules/@luxusai/pi-hindsight/docs/adr/004-lifeos-dual-bank-design.md +89 -0
- package/node_modules/@luxusai/pi-hindsight/docs/adr/005-domain-banks-and-agent-first-surface.md +189 -0
- package/node_modules/@luxusai/pi-hindsight/docs/assets/logos/pi-hindsight-logo-dark.webp +0 -0
- package/node_modules/@luxusai/pi-hindsight/docs/assets/logos/pi-hindsight-logo-dark@2x.webp +0 -0
- package/node_modules/@luxusai/pi-hindsight/docs/coding-memory-evaluation.md +54 -0
- package/node_modules/@luxusai/pi-hindsight/docs/compatibility.md +75 -0
- package/node_modules/@luxusai/pi-hindsight/docs/hindsight-core-functions.md +300 -0
- package/node_modules/@luxusai/pi-hindsight/docs/mission-and-mental-model-quality.md +158 -0
- package/node_modules/@luxusai/pi-hindsight/docs/next-opt-out-design.md +164 -0
- package/node_modules/@luxusai/pi-hindsight/docs/risky-memory-modes.md +139 -0
- package/node_modules/@luxusai/pi-hindsight/docs/starter-mental-model-suggestions.md +74 -0
- package/node_modules/@luxusai/pi-hindsight/docs/surface-reference.md +261 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/banks/bank-operations.ts +151 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/banks/bank-selection.ts +18 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/banks/bank-settings-presenter.ts +46 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/banks/bank-templates.ts +383 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/banks/banking.ts +240 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/banks/knowledge-page-seed.ts +176 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/banks/retain-strategies.ts +178 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/client/client-retry.ts +41 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/client/client.ts +386 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/client/fetch-compat.ts +39 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/client/timeout.ts +34 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/config/config-defaults.ts +140 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/config/config-editing-model.ts +61 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/config/config-editing-registry.ts +925 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/config/config-field-paths.ts +247 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/config/config-normalize.ts +547 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/config/config-writer.ts +480 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/config/config.ts +182 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/config/setup-gate.ts +86 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/imports/import-execute.ts +1010 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/imports/import-parse.ts +175 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/imports/import-plan.ts +425 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/imports/import-presentation.ts +210 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/imports/import-sessions.ts +817 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/index.ts +25 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/git-seed.ts +319 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/memory-lifecycle-recall.ts +196 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/memory-lifecycle-retain.ts +189 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/memory-lifecycle-runtime.ts +65 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/memory-lifecycle.ts +260 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/mental-models.ts +244 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/observation-scopes.ts +59 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/recall-cleanup.ts +82 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/recall-visibility.ts +45 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/recall.ts +331 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/retain-cursor.ts +354 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/retain-job-builder.ts +66 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/retain-receipts.ts +132 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/retain.ts +228 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-bank-template-operations.ts +74 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-config-operations.ts +16 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-control-operations.ts +648 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-diagnostics-operations.ts +105 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-identity.ts +68 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-operation-service.ts +71 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-operation-types.ts +13 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-recall-operations.ts +162 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-retain-operations.ts +131 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-scope.ts +104 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-session-operations.ts +37 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/operation-catalog.ts +893 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/reflect-presenter.ts +35 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/scope-migrate.ts +177 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/tools.ts +7 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/queue/flush-presenter.ts +21 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/queue/jsonl-queue-store.ts +112 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/queue/queue-delivery.ts +111 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/queue/queue-lock.ts +214 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/queue/queue-operations.ts +70 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/queue/queue.ts +392 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/bank-template-presentation.ts +45 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/commands.ts +9 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/guided-setup.ts +860 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/prefill-input.ts +105 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/setup-flow.ts +189 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/setup-server-probe.ts +299 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/setup-tui-actions.ts +201 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/setup-tui-facts.ts +47 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/setup-tui-render.ts +239 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/setup-tui-types.ts +50 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/setup-tui.ts +259 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/tool-presenters.ts +77 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/types.ts +534 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/utils/diagnostics.ts +319 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/utils/messages.ts +325 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/utils/sanitize.ts +42 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/utils/session-memory-meta.ts +244 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/utils/session-operations.ts +56 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/utils/session.ts +50 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/utils/status-fields.ts +167 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/utils/status-health.ts +207 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/utils/status.ts +120 -0
- package/node_modules/@luxusai/pi-hindsight/extensions/version.ts +8 -0
- package/node_modules/@luxusai/pi-hindsight/package.json +118 -0
- package/node_modules/@luxusai/pi-hindsight/skills/hindsight-memory-doctor/SKILL.md +75 -0
- package/node_modules/@narumitw/pi-btw/package.json +2 -2
- package/node_modules/pi-mcp-adapter/CHANGELOG.md +13 -0
- package/node_modules/pi-mcp-adapter/config.ts +10 -0
- package/node_modules/pi-mcp-adapter/dist/config.js +10 -0
- package/node_modules/pi-mcp-adapter/dist/config.js.map +1 -1
- package/node_modules/pi-mcp-adapter/init.ts +5 -1
- package/node_modules/pi-mcp-adapter/package.json +1 -1
- package/package.json +10 -4
|
@@ -0,0 +1,547 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RECALL_SCORE_FIELDS,
|
|
3
|
+
type HindsightEntityInput,
|
|
4
|
+
type RecallMinScores,
|
|
5
|
+
type ResolvedConfig,
|
|
6
|
+
} from "../types.js";
|
|
7
|
+
import { DEFAULT_CONFIG } from "./config-defaults.js";
|
|
8
|
+
|
|
9
|
+
export function isRecord(value: unknown): value is Record<string, unknown> {
|
|
10
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function merge<T>(base: T, patch: unknown): T {
|
|
14
|
+
if (!isRecord(base) || !isRecord(patch)) return (patch ?? base) as T;
|
|
15
|
+
const out: Record<string, unknown> = { ...base };
|
|
16
|
+
for (const [key, value] of Object.entries(patch)) {
|
|
17
|
+
out[key] = isRecord(value) && isRecord(out[key]) ? merge(out[key], value) : value;
|
|
18
|
+
}
|
|
19
|
+
return out as T;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function envBool(env: NodeJS.ProcessEnv, name: string): boolean | undefined {
|
|
23
|
+
const value = env[name];
|
|
24
|
+
if (value === undefined) return undefined;
|
|
25
|
+
return ["1", "true", "yes", "on"].includes(value.toLowerCase());
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function bool(value: unknown, fallback: boolean): boolean {
|
|
29
|
+
return typeof value === "boolean" ? value : fallback;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function positiveInt(value: unknown, fallback: number): number {
|
|
33
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : fallback;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function stringValue(value: unknown, fallback: string): string {
|
|
37
|
+
return typeof value === "string" && value.length > 0 ? value : fallback;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function optionalString(value: unknown, fallback?: string): string | undefined {
|
|
41
|
+
return typeof value === "string" && value.length > 0 ? value : fallback;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function validEnvVarName(value: string): boolean {
|
|
45
|
+
return /^[A-Za-z_][A-Za-z0-9_]*$/.test(value);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function enumValue<T extends string>(value: unknown, allowed: readonly T[], fallback: T): T {
|
|
49
|
+
return typeof value === "string" && (allowed as readonly string[]).includes(value)
|
|
50
|
+
? (value as T)
|
|
51
|
+
: fallback;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function stringArray(value: unknown, fallback: string[]): string[] {
|
|
55
|
+
return Array.isArray(value) && value.every((item) => typeof item === "string") ? value : fallback;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function stringMatrix(value: unknown, fallback: string[][]): string[][] {
|
|
59
|
+
return Array.isArray(value) &&
|
|
60
|
+
value.every(
|
|
61
|
+
(scope) =>
|
|
62
|
+
Array.isArray(scope) && scope.length > 0 && scope.every((item) => typeof item === "string"),
|
|
63
|
+
)
|
|
64
|
+
? value
|
|
65
|
+
: fallback;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function enumArray<T extends string>(
|
|
69
|
+
value: unknown,
|
|
70
|
+
allowed: readonly T[],
|
|
71
|
+
fallback: T[],
|
|
72
|
+
): T[] {
|
|
73
|
+
return Array.isArray(value) && value.every((item) => allowed.includes(item as T))
|
|
74
|
+
? (value as T[])
|
|
75
|
+
: fallback;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function optionalStringArray(value: unknown): string[] | undefined {
|
|
79
|
+
return Array.isArray(value) && value.every((item) => typeof item === "string")
|
|
80
|
+
? value
|
|
81
|
+
: undefined;
|
|
82
|
+
}
|
|
83
|
+
function normalizeApiKeyRefString(value: unknown): string | undefined {
|
|
84
|
+
if (typeof value !== "string" || !value.startsWith("env:")) return undefined;
|
|
85
|
+
const name = value.slice("env:".length);
|
|
86
|
+
return validEnvVarName(name) ? value : undefined;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function normalizeApiKeyRef(value: unknown): string | undefined {
|
|
90
|
+
if (!isRecord(value)) return undefined;
|
|
91
|
+
if (value.source !== "env" || typeof value.name !== "string" || !validEnvVarName(value.name))
|
|
92
|
+
return undefined;
|
|
93
|
+
return `env:${value.name}`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function resolveApiKeyRef(ref: string | undefined, env: NodeJS.ProcessEnv): string | undefined {
|
|
97
|
+
if (!ref) return undefined;
|
|
98
|
+
if (!ref.startsWith("env:")) return undefined;
|
|
99
|
+
const name = ref.slice("env:".length);
|
|
100
|
+
return name ? optionalString(env[name]) : undefined;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function directApiKey(value: unknown, fallback?: string): string | undefined {
|
|
104
|
+
return typeof value === "string" && value.length > 0 ? value : fallback;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function entityArray(value: unknown, fallback: HindsightEntityInput[]): HindsightEntityInput[] {
|
|
108
|
+
if (!Array.isArray(value)) return fallback;
|
|
109
|
+
const entities = value
|
|
110
|
+
.map((item) => {
|
|
111
|
+
if (!isRecord(item) || typeof item.text !== "string" || item.text.length === 0)
|
|
112
|
+
return undefined;
|
|
113
|
+
return {
|
|
114
|
+
text: item.text,
|
|
115
|
+
...(typeof item.type === "string" && item.type.length > 0 ? { type: item.type } : {}),
|
|
116
|
+
} satisfies HindsightEntityInput;
|
|
117
|
+
})
|
|
118
|
+
.filter((item): item is HindsightEntityInput => Boolean(item));
|
|
119
|
+
return entities.length === value.length ? entities : fallback;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function toolNameFilter(
|
|
123
|
+
value: unknown,
|
|
124
|
+
fallback: { include?: string[]; exclude?: string[] },
|
|
125
|
+
): { include?: string[]; exclude?: string[] } {
|
|
126
|
+
if (!isRecord(value)) return fallback;
|
|
127
|
+
const hasInclude = "include" in value;
|
|
128
|
+
const hasExclude = "exclude" in value;
|
|
129
|
+
const include = optionalStringArray(value.include);
|
|
130
|
+
const exclude = optionalStringArray(value.exclude);
|
|
131
|
+
if ((hasInclude && !include) || (hasExclude && !exclude) || (!hasInclude && !hasExclude)) {
|
|
132
|
+
return fallback;
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
...(include ? { include } : {}),
|
|
136
|
+
...(exclude ? { exclude } : {}),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function scoreFloors(value: unknown): RecallMinScores | undefined {
|
|
141
|
+
if (!isRecord(value)) return undefined;
|
|
142
|
+
const floors: RecallMinScores = {};
|
|
143
|
+
for (const field of RECALL_SCORE_FIELDS) {
|
|
144
|
+
const valueForField = value[field];
|
|
145
|
+
if (typeof valueForField === "number" && Number.isFinite(valueForField)) {
|
|
146
|
+
floors[field] = valueForField;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return Object.keys(floors).length ? floors : undefined;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function hasConfiguredRecallField(rawConfig: unknown, field: string): boolean {
|
|
153
|
+
return isRecord(rawConfig) && isRecord(rawConfig.recall) && field in rawConfig.recall;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function missionFields(bankConfig: unknown) {
|
|
157
|
+
if (!isRecord(bankConfig)) return {};
|
|
158
|
+
return {
|
|
159
|
+
...(typeof bankConfig.retainMission === "string"
|
|
160
|
+
? { retainMission: bankConfig.retainMission }
|
|
161
|
+
: {}),
|
|
162
|
+
...(typeof bankConfig.reflectMission === "string"
|
|
163
|
+
? { reflectMission: bankConfig.reflectMission }
|
|
164
|
+
: {}),
|
|
165
|
+
...(typeof bankConfig.observationsMission === "string"
|
|
166
|
+
? { observationsMission: bankConfig.observationsMission }
|
|
167
|
+
: {}),
|
|
168
|
+
...(typeof bankConfig.retainStructuredChunkSize === "number" &&
|
|
169
|
+
Number.isInteger(bankConfig.retainStructuredChunkSize) &&
|
|
170
|
+
bankConfig.retainStructuredChunkSize > 0
|
|
171
|
+
? { retainStructuredChunkSize: bankConfig.retainStructuredChunkSize }
|
|
172
|
+
: {}),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function normalizeConfig(
|
|
177
|
+
config: ResolvedConfig,
|
|
178
|
+
rawConfig?: unknown,
|
|
179
|
+
env: NodeJS.ProcessEnv = process.env,
|
|
180
|
+
): ResolvedConfig {
|
|
181
|
+
const apiKeyRef =
|
|
182
|
+
normalizeApiKeyRef(config.hindsight?.apiKey) ??
|
|
183
|
+
normalizeApiKeyRefString(config.hindsight?.apiKeyRef) ??
|
|
184
|
+
normalizeApiKeyRefString(DEFAULT_CONFIG.hindsight.apiKeyRef);
|
|
185
|
+
const apiKey =
|
|
186
|
+
directApiKey(config.hindsight?.apiKey, DEFAULT_CONFIG.hindsight.apiKey) ??
|
|
187
|
+
resolveApiKeyRef(apiKeyRef, env);
|
|
188
|
+
// banks.coding → project; banks.life → user (ADR-005 role names).
|
|
189
|
+
const banksRaw = config.banks as
|
|
190
|
+
| {
|
|
191
|
+
project?: unknown;
|
|
192
|
+
coding?: unknown;
|
|
193
|
+
user?: unknown;
|
|
194
|
+
global?: unknown;
|
|
195
|
+
life?: unknown;
|
|
196
|
+
}
|
|
197
|
+
| undefined;
|
|
198
|
+
if (banksRaw && isRecord(banksRaw.coding) && !isRecord(banksRaw.project)) {
|
|
199
|
+
banksRaw.project = banksRaw.coding;
|
|
200
|
+
} else if (banksRaw && isRecord(banksRaw.coding) && isRecord(banksRaw.project)) {
|
|
201
|
+
banksRaw.project = { ...banksRaw.coding, ...banksRaw.project };
|
|
202
|
+
}
|
|
203
|
+
if (banksRaw && isRecord(banksRaw.life)) {
|
|
204
|
+
// life overlays user so alias fields win over defaults merged earlier.
|
|
205
|
+
if (isRecord(banksRaw.user)) banksRaw.user = { ...banksRaw.user, ...banksRaw.life };
|
|
206
|
+
else banksRaw.user = banksRaw.life;
|
|
207
|
+
}
|
|
208
|
+
const projectBankId = optionalString(
|
|
209
|
+
config.banks?.project?.bankId,
|
|
210
|
+
DEFAULT_CONFIG.banks.project.bankId,
|
|
211
|
+
);
|
|
212
|
+
const userBankConfig = config.banks?.user ?? config.banks?.global;
|
|
213
|
+
const defaultUserBankConfig = DEFAULT_CONFIG.banks.user;
|
|
214
|
+
const globalBankId = optionalString(userBankConfig?.bankId, defaultUserBankConfig.bankId);
|
|
215
|
+
const minScores = scoreFloors(config.recall?.minScores);
|
|
216
|
+
const scopeRaw = (
|
|
217
|
+
config as {
|
|
218
|
+
scope?: {
|
|
219
|
+
mode?: unknown;
|
|
220
|
+
projectId?: unknown;
|
|
221
|
+
projectIdStrategy?: unknown;
|
|
222
|
+
includeSharedObservations?: unknown;
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
).scope;
|
|
226
|
+
const projectIdPin = optionalString(scopeRaw?.projectId, DEFAULT_CONFIG.scope.projectId);
|
|
227
|
+
return {
|
|
228
|
+
enabled: bool(config.enabled, DEFAULT_CONFIG.enabled),
|
|
229
|
+
setupComplete: bool(
|
|
230
|
+
(config as { setupComplete?: unknown }).setupComplete,
|
|
231
|
+
DEFAULT_CONFIG.setupComplete,
|
|
232
|
+
),
|
|
233
|
+
scope: {
|
|
234
|
+
mode: enumValue(
|
|
235
|
+
scopeRaw?.mode,
|
|
236
|
+
["domain-tagged", "isolated-bank"] as const,
|
|
237
|
+
DEFAULT_CONFIG.scope.mode,
|
|
238
|
+
),
|
|
239
|
+
...(projectIdPin ? { projectId: projectIdPin } : {}),
|
|
240
|
+
projectIdStrategy: enumValue(
|
|
241
|
+
scopeRaw?.projectIdStrategy,
|
|
242
|
+
["remote", "basename"] as const,
|
|
243
|
+
DEFAULT_CONFIG.scope.projectIdStrategy,
|
|
244
|
+
),
|
|
245
|
+
includeSharedObservations: bool(
|
|
246
|
+
scopeRaw?.includeSharedObservations,
|
|
247
|
+
DEFAULT_CONFIG.scope.includeSharedObservations,
|
|
248
|
+
),
|
|
249
|
+
},
|
|
250
|
+
hindsight: {
|
|
251
|
+
baseUrl: stringValue(config.hindsight?.baseUrl, DEFAULT_CONFIG.hindsight.baseUrl),
|
|
252
|
+
...(apiKey ? { apiKey } : {}),
|
|
253
|
+
...(apiKeyRef ? { apiKeyRef } : {}),
|
|
254
|
+
timeoutMs: positiveInt(config.hindsight?.timeoutMs, DEFAULT_CONFIG.hindsight.timeoutMs),
|
|
255
|
+
},
|
|
256
|
+
agentUse: enumValue(
|
|
257
|
+
(config as { agentUse?: unknown }).agentUse,
|
|
258
|
+
["coding", "conversation"],
|
|
259
|
+
DEFAULT_CONFIG.agentUse,
|
|
260
|
+
),
|
|
261
|
+
mentalModels: {
|
|
262
|
+
inject: bool(
|
|
263
|
+
(config as { mentalModels?: { inject?: unknown } }).mentalModels?.inject,
|
|
264
|
+
DEFAULT_CONFIG.mentalModels.inject,
|
|
265
|
+
),
|
|
266
|
+
maxChars: positiveInt(
|
|
267
|
+
(config as { mentalModels?: { maxChars?: unknown } }).mentalModels?.maxChars,
|
|
268
|
+
DEFAULT_CONFIG.mentalModels.maxChars,
|
|
269
|
+
),
|
|
270
|
+
cacheTtlMs: positiveInt(
|
|
271
|
+
(config as { mentalModels?: { cacheTtlMs?: unknown } }).mentalModels?.cacheTtlMs,
|
|
272
|
+
DEFAULT_CONFIG.mentalModels.cacheTtlMs,
|
|
273
|
+
),
|
|
274
|
+
},
|
|
275
|
+
banks: {
|
|
276
|
+
project: {
|
|
277
|
+
enabled: bool(config.banks?.project?.enabled, DEFAULT_CONFIG.banks.project.enabled),
|
|
278
|
+
...(projectBankId ? { bankId: projectBankId } : {}),
|
|
279
|
+
derive: enumValue(
|
|
280
|
+
config.banks?.project?.derive,
|
|
281
|
+
["repo", "cwd", "manual"],
|
|
282
|
+
DEFAULT_CONFIG.banks.project.derive,
|
|
283
|
+
),
|
|
284
|
+
...missionFields(config.banks?.project),
|
|
285
|
+
},
|
|
286
|
+
user: {
|
|
287
|
+
enabled: bool(userBankConfig?.enabled, defaultUserBankConfig.enabled),
|
|
288
|
+
...(globalBankId ? { bankId: globalBankId } : {}),
|
|
289
|
+
...missionFields(userBankConfig),
|
|
290
|
+
},
|
|
291
|
+
global: {
|
|
292
|
+
enabled: bool(userBankConfig?.enabled, defaultUserBankConfig.enabled),
|
|
293
|
+
...(globalBankId ? { bankId: globalBankId } : {}),
|
|
294
|
+
...missionFields(userBankConfig),
|
|
295
|
+
},
|
|
296
|
+
},
|
|
297
|
+
observations: {
|
|
298
|
+
enabled: bool(config.observations?.enabled, DEFAULT_CONFIG.observations.enabled),
|
|
299
|
+
scopes: stringMatrix(config.observations?.scopes, DEFAULT_CONFIG.observations.scopes),
|
|
300
|
+
},
|
|
301
|
+
userRetain: {
|
|
302
|
+
mode: enumValue(
|
|
303
|
+
config.userRetain?.mode ?? config.globalRetain?.mode,
|
|
304
|
+
["explicit-only"],
|
|
305
|
+
DEFAULT_CONFIG.userRetain.mode,
|
|
306
|
+
),
|
|
307
|
+
},
|
|
308
|
+
globalRetain: {
|
|
309
|
+
mode: enumValue(
|
|
310
|
+
config.userRetain?.mode ?? config.globalRetain?.mode,
|
|
311
|
+
["explicit-only"],
|
|
312
|
+
DEFAULT_CONFIG.userRetain.mode,
|
|
313
|
+
),
|
|
314
|
+
},
|
|
315
|
+
recall: {
|
|
316
|
+
enabled: bool(config.recall?.enabled, DEFAULT_CONFIG.recall.enabled),
|
|
317
|
+
budget: enumValue(
|
|
318
|
+
config.recall?.budget,
|
|
319
|
+
["low", "mid", "high"],
|
|
320
|
+
DEFAULT_CONFIG.recall.budget,
|
|
321
|
+
),
|
|
322
|
+
maxTokens: positiveInt(config.recall?.maxTokens, DEFAULT_CONFIG.recall.maxTokens),
|
|
323
|
+
userMaxTokens: positiveInt(config.recall?.userMaxTokens, DEFAULT_CONFIG.recall.userMaxTokens),
|
|
324
|
+
types: stringArray(config.recall?.types, DEFAULT_CONFIG.recall.types),
|
|
325
|
+
includeSourceFacts: bool(
|
|
326
|
+
config.recall?.includeSourceFacts,
|
|
327
|
+
DEFAULT_CONFIG.recall.includeSourceFacts,
|
|
328
|
+
),
|
|
329
|
+
maxSourceFactsTokens: positiveInt(
|
|
330
|
+
config.recall?.maxSourceFactsTokens,
|
|
331
|
+
DEFAULT_CONFIG.recall.maxSourceFactsTokens,
|
|
332
|
+
),
|
|
333
|
+
contextTurns: positiveInt(config.recall?.contextTurns, DEFAULT_CONFIG.recall.contextTurns),
|
|
334
|
+
roles: enumArray(
|
|
335
|
+
config.recall?.roles,
|
|
336
|
+
["user", "assistant", "tool", "system"],
|
|
337
|
+
DEFAULT_CONFIG.recall.roles,
|
|
338
|
+
),
|
|
339
|
+
maxQueryChars: positiveInt(config.recall?.maxQueryChars, DEFAULT_CONFIG.recall.maxQueryChars),
|
|
340
|
+
queryPreamble:
|
|
341
|
+
typeof config.recall?.queryPreamble === "string"
|
|
342
|
+
? config.recall.queryPreamble
|
|
343
|
+
: DEFAULT_CONFIG.recall.queryPreamble,
|
|
344
|
+
projectQueryPreamble:
|
|
345
|
+
hasConfiguredRecallField(rawConfig, "projectQueryPreamble") &&
|
|
346
|
+
typeof config.recall?.projectQueryPreamble === "string"
|
|
347
|
+
? config.recall.projectQueryPreamble
|
|
348
|
+
: hasConfiguredRecallField(rawConfig, "queryPreamble") &&
|
|
349
|
+
typeof config.recall?.queryPreamble === "string"
|
|
350
|
+
? config.recall.queryPreamble
|
|
351
|
+
: DEFAULT_CONFIG.recall.projectQueryPreamble,
|
|
352
|
+
globalQueryPreamble:
|
|
353
|
+
hasConfiguredRecallField(rawConfig, "userQueryPreamble") &&
|
|
354
|
+
typeof config.recall?.userQueryPreamble === "string"
|
|
355
|
+
? config.recall.userQueryPreamble
|
|
356
|
+
: hasConfiguredRecallField(rawConfig, "globalQueryPreamble") &&
|
|
357
|
+
typeof config.recall?.globalQueryPreamble === "string"
|
|
358
|
+
? config.recall.globalQueryPreamble
|
|
359
|
+
: hasConfiguredRecallField(rawConfig, "queryPreamble") &&
|
|
360
|
+
typeof config.recall?.queryPreamble === "string"
|
|
361
|
+
? config.recall.queryPreamble
|
|
362
|
+
: (DEFAULT_CONFIG.recall.userQueryPreamble ??
|
|
363
|
+
DEFAULT_CONFIG.recall.globalQueryPreamble),
|
|
364
|
+
includeDateInQuery: bool(
|
|
365
|
+
config.recall?.includeDateInQuery,
|
|
366
|
+
DEFAULT_CONFIG.recall.includeDateInQuery,
|
|
367
|
+
),
|
|
368
|
+
includeRepoHintsInQuery: bool(
|
|
369
|
+
config.recall?.includeRepoHintsInQuery,
|
|
370
|
+
DEFAULT_CONFIG.recall.includeRepoHintsInQuery,
|
|
371
|
+
),
|
|
372
|
+
storeLastRecall: bool(config.recall?.storeLastRecall, DEFAULT_CONFIG.recall.storeLastRecall),
|
|
373
|
+
storeLastRecallFailures: bool(
|
|
374
|
+
config.recall?.storeLastRecallFailures,
|
|
375
|
+
DEFAULT_CONFIG.recall.storeLastRecallFailures,
|
|
376
|
+
),
|
|
377
|
+
lastRecallPath:
|
|
378
|
+
typeof config.recall?.lastRecallPath === "string" && config.recall.lastRecallPath.trim()
|
|
379
|
+
? config.recall.lastRecallPath
|
|
380
|
+
: DEFAULT_CONFIG.recall.lastRecallPath,
|
|
381
|
+
topK: positiveInt(config.recall?.topK, DEFAULT_CONFIG.recall.topK),
|
|
382
|
+
timeoutMs: positiveInt(config.recall?.timeoutMs, DEFAULT_CONFIG.recall.timeoutMs),
|
|
383
|
+
cacheTtlMs: positiveInt(config.recall?.cacheTtlMs, DEFAULT_CONFIG.recall.cacheTtlMs),
|
|
384
|
+
injectionMode: "context",
|
|
385
|
+
injectionPosition: enumValue(
|
|
386
|
+
config.recall?.injectionPosition,
|
|
387
|
+
["prepend", "append"],
|
|
388
|
+
DEFAULT_CONFIG.recall.injectionPosition,
|
|
389
|
+
),
|
|
390
|
+
includeFactsInDebug: bool(
|
|
391
|
+
config.recall?.includeFactsInDebug,
|
|
392
|
+
DEFAULT_CONFIG.recall.includeFactsInDebug,
|
|
393
|
+
),
|
|
394
|
+
preferObservations: bool(
|
|
395
|
+
config.recall?.preferObservations,
|
|
396
|
+
DEFAULT_CONFIG.recall.preferObservations,
|
|
397
|
+
),
|
|
398
|
+
...(minScores ? { minScores } : {}),
|
|
399
|
+
...(optionalString(config.recall?.queryTimestamp, DEFAULT_CONFIG.recall.queryTimestamp)
|
|
400
|
+
? {
|
|
401
|
+
queryTimestamp: stringValue(
|
|
402
|
+
config.recall?.queryTimestamp,
|
|
403
|
+
DEFAULT_CONFIG.recall.queryTimestamp ?? "",
|
|
404
|
+
),
|
|
405
|
+
}
|
|
406
|
+
: {}),
|
|
407
|
+
},
|
|
408
|
+
retain: {
|
|
409
|
+
enabled: bool(config.retain?.enabled, DEFAULT_CONFIG.retain.enabled),
|
|
410
|
+
async: bool(config.retain?.async, DEFAULT_CONFIG.retain.async),
|
|
411
|
+
delivery: enumValue(
|
|
412
|
+
config.retain?.delivery,
|
|
413
|
+
["immediate", "coalesced"],
|
|
414
|
+
DEFAULT_CONFIG.retain.delivery,
|
|
415
|
+
),
|
|
416
|
+
updateMode: enumValue(
|
|
417
|
+
config.retain?.updateMode,
|
|
418
|
+
["append", "replace"],
|
|
419
|
+
DEFAULT_CONFIG.retain.updateMode,
|
|
420
|
+
),
|
|
421
|
+
content: {
|
|
422
|
+
user: enumArray(config.retain?.content?.user, ["text"], DEFAULT_CONFIG.retain.content.user),
|
|
423
|
+
assistant: enumArray(
|
|
424
|
+
config.retain?.content?.assistant,
|
|
425
|
+
["text", "toolCall", "thinking"],
|
|
426
|
+
DEFAULT_CONFIG.retain.content.assistant,
|
|
427
|
+
),
|
|
428
|
+
toolResult: enumArray(
|
|
429
|
+
config.retain?.content?.toolResult,
|
|
430
|
+
["error", "summary", "content"],
|
|
431
|
+
DEFAULT_CONFIG.retain.content.toolResult,
|
|
432
|
+
),
|
|
433
|
+
},
|
|
434
|
+
toolFilter: {
|
|
435
|
+
toolCall: toolNameFilter(
|
|
436
|
+
config.retain?.toolFilter?.toolCall,
|
|
437
|
+
DEFAULT_CONFIG.retain.toolFilter.toolCall,
|
|
438
|
+
),
|
|
439
|
+
toolResult: toolNameFilter(
|
|
440
|
+
config.retain?.toolFilter?.toolResult,
|
|
441
|
+
DEFAULT_CONFIG.retain.toolFilter.toolResult,
|
|
442
|
+
),
|
|
443
|
+
},
|
|
444
|
+
compactToolCalls: bool(
|
|
445
|
+
config.retain?.compactToolCalls,
|
|
446
|
+
DEFAULT_CONFIG.retain.compactToolCalls,
|
|
447
|
+
),
|
|
448
|
+
strip: {
|
|
449
|
+
message: stringArray(config.retain?.strip?.message, DEFAULT_CONFIG.retain.strip.message),
|
|
450
|
+
topLevel: stringArray(config.retain?.strip?.topLevel, DEFAULT_CONFIG.retain.strip.topLevel),
|
|
451
|
+
},
|
|
452
|
+
redactSecrets: bool(config.retain?.redactSecrets, DEFAULT_CONFIG.retain.redactSecrets),
|
|
453
|
+
entities: entityArray(config.retain?.entities, DEFAULT_CONFIG.retain.entities),
|
|
454
|
+
queuePath: stringValue(config.retain?.queuePath, DEFAULT_CONFIG.retain.queuePath),
|
|
455
|
+
flushIntervalMs: Math.max(
|
|
456
|
+
0,
|
|
457
|
+
typeof config.retain?.flushIntervalMs === "number" &&
|
|
458
|
+
Number.isInteger(config.retain.flushIntervalMs)
|
|
459
|
+
? config.retain.flushIntervalMs
|
|
460
|
+
: DEFAULT_CONFIG.retain.flushIntervalMs,
|
|
461
|
+
),
|
|
462
|
+
periodicFlushMaxJobs: positiveInt(
|
|
463
|
+
config.retain?.periodicFlushMaxJobs,
|
|
464
|
+
DEFAULT_CONFIG.retain.periodicFlushMaxJobs,
|
|
465
|
+
),
|
|
466
|
+
periodicFlushTimeoutMs: positiveInt(
|
|
467
|
+
config.retain?.periodicFlushTimeoutMs,
|
|
468
|
+
DEFAULT_CONFIG.retain.periodicFlushTimeoutMs,
|
|
469
|
+
),
|
|
470
|
+
shutdownFlushMaxJobs: positiveInt(
|
|
471
|
+
config.retain?.shutdownFlushMaxJobs,
|
|
472
|
+
DEFAULT_CONFIG.retain.shutdownFlushMaxJobs,
|
|
473
|
+
),
|
|
474
|
+
shutdownFlushTimeoutMs: positiveInt(
|
|
475
|
+
config.retain?.shutdownFlushTimeoutMs,
|
|
476
|
+
DEFAULT_CONFIG.retain.shutdownFlushTimeoutMs,
|
|
477
|
+
),
|
|
478
|
+
postRetainReflect: bool(
|
|
479
|
+
config.retain?.postRetainReflect,
|
|
480
|
+
DEFAULT_CONFIG.retain.postRetainReflect,
|
|
481
|
+
),
|
|
482
|
+
},
|
|
483
|
+
import: {
|
|
484
|
+
mode: enumValue(
|
|
485
|
+
config.import?.mode,
|
|
486
|
+
["curated", "raw", "forensic"],
|
|
487
|
+
DEFAULT_CONFIG.import.mode,
|
|
488
|
+
),
|
|
489
|
+
qualityProfile: enumValue(
|
|
490
|
+
config.import?.qualityProfile,
|
|
491
|
+
["compatible", "strict"],
|
|
492
|
+
DEFAULT_CONFIG.import.qualityProfile,
|
|
493
|
+
),
|
|
494
|
+
turnsPerDocument: positiveInt(
|
|
495
|
+
config.import?.turnsPerDocument,
|
|
496
|
+
DEFAULT_CONFIG.import.turnsPerDocument,
|
|
497
|
+
),
|
|
498
|
+
maxDocumentBytes: positiveInt(
|
|
499
|
+
config.import?.maxDocumentBytes,
|
|
500
|
+
DEFAULT_CONFIG.import.maxDocumentBytes,
|
|
501
|
+
),
|
|
502
|
+
includeBranches: enumValue(
|
|
503
|
+
config.import?.includeBranches,
|
|
504
|
+
["current-only", "all-leaves"],
|
|
505
|
+
DEFAULT_CONFIG.import.includeBranches,
|
|
506
|
+
),
|
|
507
|
+
toolResults: enumValue(
|
|
508
|
+
config.import?.toolResults,
|
|
509
|
+
["errors-only", "summary", "content"],
|
|
510
|
+
DEFAULT_CONFIG.import.toolResults,
|
|
511
|
+
),
|
|
512
|
+
toolResultSummaryMaxChars: positiveInt(
|
|
513
|
+
config.import?.toolResultSummaryMaxChars,
|
|
514
|
+
DEFAULT_CONFIG.import.toolResultSummaryMaxChars,
|
|
515
|
+
),
|
|
516
|
+
replaceExistingImportedDocs: bool(
|
|
517
|
+
config.import?.replaceExistingImportedDocs,
|
|
518
|
+
DEFAULT_CONFIG.import.replaceExistingImportedDocs,
|
|
519
|
+
),
|
|
520
|
+
manifestPath: stringValue(config.import?.manifestPath, DEFAULT_CONFIG.import.manifestPath),
|
|
521
|
+
checkpointPath: stringValue(
|
|
522
|
+
config.import?.checkpointPath,
|
|
523
|
+
DEFAULT_CONFIG.import.checkpointPath,
|
|
524
|
+
),
|
|
525
|
+
resume: bool(config.import?.resume, DEFAULT_CONFIG.import.resume),
|
|
526
|
+
},
|
|
527
|
+
status: {
|
|
528
|
+
style: enumValue(
|
|
529
|
+
config.status?.style,
|
|
530
|
+
["off", "text", "emoji", "nerdfont"],
|
|
531
|
+
DEFAULT_CONFIG.status.style,
|
|
532
|
+
),
|
|
533
|
+
detail: enumValue(
|
|
534
|
+
config.status?.detail,
|
|
535
|
+
["minimal", "project", "activity", "verbose"],
|
|
536
|
+
DEFAULT_CONFIG.status.detail,
|
|
537
|
+
),
|
|
538
|
+
maxLength: positiveInt(config.status?.maxLength, DEFAULT_CONFIG.status.maxLength),
|
|
539
|
+
showActivity: bool(config.status?.showActivity, DEFAULT_CONFIG.status.showActivity),
|
|
540
|
+
},
|
|
541
|
+
notifications: {
|
|
542
|
+
startup: bool(config.notifications?.startup, DEFAULT_CONFIG.notifications.startup),
|
|
543
|
+
recall: bool(config.notifications?.recall, DEFAULT_CONFIG.notifications.recall),
|
|
544
|
+
retain: bool(config.notifications?.retain, DEFAULT_CONFIG.notifications.retain),
|
|
545
|
+
},
|
|
546
|
+
};
|
|
547
|
+
}
|