@cortexkit/opencode-magic-context 0.2.5 → 0.2.7
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 -4
- package/dist/cli/config-paths.d.ts.map +1 -1
- package/dist/cli/opencode-helpers.d.ts.map +1 -1
- package/dist/cli/setup.d.ts.map +1 -1
- package/dist/cli.js +96 -42
- package/dist/hooks/magic-context/note-nudger.d.ts +13 -4
- package/dist/hooks/magic-context/note-nudger.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/index.js +22 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
|
|
28
28
|
## What is Magic Context?
|
|
29
29
|
|
|
30
|
-
Your agent should never stop working to manage its own context. Magic Context is an OpenCode plugin that handles
|
|
30
|
+
Your agent should never stop working to manage its own context. Magic Context is an OpenCode plugin that handles context and memory management entirely in the background:
|
|
31
31
|
|
|
32
32
|
**1.** Transparent context compaction via a background historian — the main agent keeps working while a separate model compresses older conversation. All operations are **cache-aware** and deferred to avoid wasting cached prefixes.
|
|
33
33
|
|
|
@@ -99,9 +99,9 @@ Create `magic-context.jsonc` in your project root, `.opencode/`, or `~/.config/o
|
|
|
99
99
|
|
|
100
100
|
That's it. Everything else has sensible defaults. Project config merges on top of user-wide settings.
|
|
101
101
|
|
|
102
|
-
### Oh-My-OpenCode Users
|
|
102
|
+
### Oh-My-OpenCode / Oh-My-OpenAgent Users
|
|
103
103
|
|
|
104
|
-
If you use [oh-my-
|
|
104
|
+
If you use [oh-my-openagent](https://github.com/code-yeongyu/oh-my-openagent) (formerly oh-my-opencode), disable the hooks that conflict with Magic Context in your `oh-my-openagent.json`:
|
|
105
105
|
|
|
106
106
|
```json
|
|
107
107
|
{
|
|
@@ -113,7 +113,7 @@ If you use [oh-my-opencode](https://github.com/code-yeongyu/oh-my-opencode), dis
|
|
|
113
113
|
}
|
|
114
114
|
```
|
|
115
115
|
|
|
116
|
-
The setup wizard handles this automatically if it detects an oh-my-opencode config.
|
|
116
|
+
The setup wizard handles this automatically if it detects an oh-my-openagent or oh-my-opencode config.
|
|
117
117
|
|
|
118
118
|
---
|
|
119
119
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-paths.d.ts","sourceRoot":"","sources":["../../src/cli/config-paths.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,WAAW;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,oBAAoB,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;IAChD,kBAAkB,EAAE,MAAM,CAAC;IAC3B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;
|
|
1
|
+
{"version":3,"file":"config-paths.d.ts","sourceRoot":"","sources":["../../src/cli/config-paths.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,WAAW;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,oBAAoB,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;IAChD,kBAAkB,EAAE,MAAM,CAAC;IAC3B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAmCD,wBAAgB,iBAAiB,IAAI,WAAW,CA2B/C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"opencode-helpers.d.ts","sourceRoot":"","sources":["../../src/cli/opencode-helpers.ts"],"names":[],"mappings":"AAEA,wBAAgB,mBAAmB,IAAI,OAAO,CAO7C;AAED,wBAAgB,kBAAkB,IAAI,MAAM,GAAG,IAAI,CAMlD;AAED,wBAAgB,kBAAkB,IAAI,MAAM,EAAE,CAU7C;AAED,2CAA2C;AAC3C,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAU7E;AAED,2C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D3D"}
|
package/dist/cli/setup.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/cli/setup.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/cli/setup.ts"],"names":[],"mappings":"AAgMA,wBAAsB,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC,CAmKhD"}
|
package/dist/cli.js
CHANGED
|
@@ -116,6 +116,8 @@ function getConfigDir() {
|
|
|
116
116
|
}
|
|
117
117
|
function findOmoConfig(configDir) {
|
|
118
118
|
const locations = [
|
|
119
|
+
join(configDir, "oh-my-openagent.jsonc"),
|
|
120
|
+
join(configDir, "oh-my-openagent.json"),
|
|
119
121
|
join(configDir, "oh-my-opencode.jsonc"),
|
|
120
122
|
join(configDir, "oh-my-opencode.json")
|
|
121
123
|
];
|
|
@@ -179,64 +181,49 @@ function getAvailableModels() {
|
|
|
179
181
|
function buildModelSelection(allModels, role) {
|
|
180
182
|
const result = [];
|
|
181
183
|
const added = new Set;
|
|
182
|
-
const addIfAvailable = (pattern,
|
|
184
|
+
const addIfAvailable = (pattern, hint) => {
|
|
183
185
|
const matches = allModels.filter((m) => m === pattern || m.endsWith(`/${pattern}`));
|
|
184
186
|
for (const m of matches) {
|
|
185
187
|
if (!added.has(m)) {
|
|
186
188
|
added.add(m);
|
|
187
189
|
result.push({
|
|
188
|
-
label: m,
|
|
190
|
+
label: hint ? `${m} — ${hint}` : m,
|
|
189
191
|
value: m,
|
|
190
|
-
recommended:
|
|
192
|
+
recommended: result.length === 0
|
|
191
193
|
});
|
|
192
194
|
}
|
|
193
195
|
}
|
|
194
196
|
};
|
|
195
197
|
if (role === "historian") {
|
|
196
|
-
addIfAvailable("claude-sonnet-4
|
|
197
|
-
addIfAvailable("claude-sonnet-4-
|
|
198
|
-
addIfAvailable("
|
|
199
|
-
addIfAvailable("gpt-5.4");
|
|
200
|
-
addIfAvailable("
|
|
201
|
-
addIfAvailable("minimax-m2.7");
|
|
202
|
-
|
|
203
|
-
if (!added.has(m)) {
|
|
204
|
-
added.add(m);
|
|
205
|
-
result.push({ label: `${m} (free with Copilot)`, value: m });
|
|
206
|
-
}
|
|
207
|
-
}
|
|
198
|
+
addIfAvailable("github-copilot/claude-sonnet-4.6", "per-request billing");
|
|
199
|
+
addIfAvailable("anthropic/claude-sonnet-4-6");
|
|
200
|
+
addIfAvailable("github-copilot/gpt-5.4", "per-request billing");
|
|
201
|
+
addIfAvailable("openai/gpt-5.4");
|
|
202
|
+
addIfAvailable("github-copilot/gemini-3.1-pro-preview", "per-request billing");
|
|
203
|
+
addIfAvailable("opencode-go/minimax-m2.7");
|
|
204
|
+
addIfAvailable("opencode-go/glm-5");
|
|
208
205
|
} else if (role === "dreamer") {
|
|
209
206
|
for (const m of allModels.filter((m2) => m2.startsWith("ollama/"))) {
|
|
210
207
|
if (!added.has(m)) {
|
|
211
208
|
added.add(m);
|
|
212
|
-
result.push({ label: `${m}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
addIfAvailable("claude-sonnet-4-6", result.length === 0);
|
|
216
|
-
addIfAvailable("gemini-3-flash");
|
|
217
|
-
addIfAvailable("glm-5");
|
|
218
|
-
addIfAvailable("minimax-m2.7");
|
|
219
|
-
addIfAvailable("gpt-5.4-mini");
|
|
220
|
-
for (const m of allModels.filter((m2) => m2.startsWith("github-copilot/"))) {
|
|
221
|
-
if (!added.has(m)) {
|
|
222
|
-
added.add(m);
|
|
223
|
-
result.push({ label: `${m} (free with Copilot)`, value: m });
|
|
209
|
+
result.push({ label: `${m} — local`, value: m, recommended: result.length === 0 });
|
|
224
210
|
}
|
|
225
211
|
}
|
|
212
|
+
addIfAvailable("github-copilot/claude-sonnet-4.6", "per-request billing");
|
|
213
|
+
addIfAvailable("anthropic/claude-sonnet-4-6");
|
|
214
|
+
addIfAvailable("github-copilot/gemini-3-flash-preview", "per-request billing");
|
|
215
|
+
addIfAvailable("opencode-go/glm-5");
|
|
216
|
+
addIfAvailable("opencode-go/minimax-m2.7");
|
|
226
217
|
} else if (role === "sidekick") {
|
|
227
218
|
for (const m of allModels.filter((m2) => m2.startsWith("cerebras/"))) {
|
|
228
219
|
if (!added.has(m)) {
|
|
229
220
|
added.add(m);
|
|
230
|
-
result.push({
|
|
231
|
-
label: `${m} (fastest)`,
|
|
232
|
-
value: m,
|
|
233
|
-
recommended: result.length === 0
|
|
234
|
-
});
|
|
221
|
+
result.push({ label: m, value: m, recommended: result.length === 0 });
|
|
235
222
|
}
|
|
236
223
|
}
|
|
237
|
-
addIfAvailable("gpt-5-nano");
|
|
238
|
-
addIfAvailable("gemini-3-flash");
|
|
239
|
-
addIfAvailable("gpt-5
|
|
224
|
+
addIfAvailable("opencode/gpt-5-nano");
|
|
225
|
+
addIfAvailable("github-copilot/gemini-3-flash-preview");
|
|
226
|
+
addIfAvailable("github-copilot/gpt-5-mini");
|
|
240
227
|
}
|
|
241
228
|
return result;
|
|
242
229
|
}
|
|
@@ -1293,15 +1280,55 @@ function ensureDir(dir) {
|
|
|
1293
1280
|
mkdirSync(dir, { recursive: true });
|
|
1294
1281
|
}
|
|
1295
1282
|
}
|
|
1296
|
-
function
|
|
1297
|
-
|
|
1283
|
+
function stripJsoncToJson(text) {
|
|
1284
|
+
let result = "";
|
|
1285
|
+
let i = 0;
|
|
1286
|
+
let inString = false;
|
|
1287
|
+
let escaped = false;
|
|
1288
|
+
while (i < text.length) {
|
|
1289
|
+
const ch = text[i];
|
|
1290
|
+
if (escaped) {
|
|
1291
|
+
result += ch;
|
|
1292
|
+
escaped = false;
|
|
1293
|
+
i++;
|
|
1294
|
+
continue;
|
|
1295
|
+
}
|
|
1296
|
+
if (inString) {
|
|
1297
|
+
if (ch === "\\")
|
|
1298
|
+
escaped = true;
|
|
1299
|
+
else if (ch === '"')
|
|
1300
|
+
inString = false;
|
|
1301
|
+
result += ch;
|
|
1302
|
+
i++;
|
|
1303
|
+
continue;
|
|
1304
|
+
}
|
|
1305
|
+
if (ch === "/" && text[i + 1] === "/") {
|
|
1306
|
+
while (i < text.length && text[i] !== `
|
|
1307
|
+
`)
|
|
1308
|
+
i++;
|
|
1309
|
+
continue;
|
|
1310
|
+
}
|
|
1311
|
+
if (ch === "/" && text[i + 1] === "*") {
|
|
1312
|
+
i += 2;
|
|
1313
|
+
while (i < text.length && !(text[i] === "*" && text[i + 1] === "/"))
|
|
1314
|
+
i++;
|
|
1315
|
+
i += 2;
|
|
1316
|
+
continue;
|
|
1317
|
+
}
|
|
1318
|
+
if (ch === '"')
|
|
1319
|
+
inString = true;
|
|
1320
|
+
result += ch;
|
|
1321
|
+
i++;
|
|
1322
|
+
}
|
|
1323
|
+
return result.replace(/,(\s*[}\]])/g, "$1");
|
|
1298
1324
|
}
|
|
1299
1325
|
function readJsonc(path) {
|
|
1300
1326
|
const content = readFileSync(path, "utf-8");
|
|
1301
1327
|
try {
|
|
1302
|
-
return JSON.parse(
|
|
1303
|
-
} catch {
|
|
1304
|
-
|
|
1328
|
+
return JSON.parse(stripJsoncToJson(content));
|
|
1329
|
+
} catch (err) {
|
|
1330
|
+
console.error(` ⚠ Failed to parse ${path}: ${err instanceof Error ? err.message : err}`);
|
|
1331
|
+
return null;
|
|
1305
1332
|
}
|
|
1306
1333
|
}
|
|
1307
1334
|
function addPluginToOpenCodeConfig(configPath, format) {
|
|
@@ -1316,6 +1343,10 @@ function addPluginToOpenCodeConfig(configPath, format) {
|
|
|
1316
1343
|
return;
|
|
1317
1344
|
}
|
|
1318
1345
|
const existing = readJsonc(configPath);
|
|
1346
|
+
if (!existing) {
|
|
1347
|
+
R2.warn(`Could not parse ${configPath} — skipping to avoid data loss`);
|
|
1348
|
+
return;
|
|
1349
|
+
}
|
|
1319
1350
|
const plugins = existing.plugin ?? [];
|
|
1320
1351
|
const hasPlugin = plugins.some((p) => p === PLUGIN_NAME || p.startsWith(`${PLUGIN_NAME}@`));
|
|
1321
1352
|
if (!hasPlugin) {
|
|
@@ -1330,7 +1361,7 @@ function addPluginToOpenCodeConfig(configPath, format) {
|
|
|
1330
1361
|
`);
|
|
1331
1362
|
}
|
|
1332
1363
|
function writeMagicContextConfig(configPath, options) {
|
|
1333
|
-
const config = existsSync2(configPath) ? readJsonc(configPath) : {};
|
|
1364
|
+
const config = (existsSync2(configPath) ? readJsonc(configPath) : null) ?? {};
|
|
1334
1365
|
if (options.historianModel) {
|
|
1335
1366
|
const historian = config.historian ?? {};
|
|
1336
1367
|
historian.model = options.historianModel;
|
|
@@ -1356,11 +1387,23 @@ function writeMagicContextConfig(configPath, options) {
|
|
|
1356
1387
|
}
|
|
1357
1388
|
config.sidekick = sidekick;
|
|
1358
1389
|
}
|
|
1390
|
+
if (options.claudeMax) {
|
|
1391
|
+
const cacheTtl = config.cache_ttl ?? {};
|
|
1392
|
+
if (!cacheTtl.default)
|
|
1393
|
+
cacheTtl.default = "5m";
|
|
1394
|
+
cacheTtl["anthropic/claude-sonnet-4-6"] = "59m";
|
|
1395
|
+
cacheTtl["anthropic/claude-opus-4-6"] = "59m";
|
|
1396
|
+
config.cache_ttl = cacheTtl;
|
|
1397
|
+
}
|
|
1359
1398
|
writeFileSync(configPath, `${JSON.stringify(config, null, 2)}
|
|
1360
1399
|
`);
|
|
1361
1400
|
}
|
|
1362
1401
|
function disableOmoHooks(omoConfigPath) {
|
|
1363
1402
|
const config = readJsonc(omoConfigPath);
|
|
1403
|
+
if (!config) {
|
|
1404
|
+
R2.warn(`Could not parse ${omoConfigPath} — skipping to avoid data loss`);
|
|
1405
|
+
return;
|
|
1406
|
+
}
|
|
1364
1407
|
const disabledHooks = config.disabled_hooks ?? [];
|
|
1365
1408
|
const hooksToDisable = [
|
|
1366
1409
|
"context-window-monitor",
|
|
@@ -1446,12 +1489,23 @@ async function runSetup() {
|
|
|
1446
1489
|
} else if (sidekickEnabled) {
|
|
1447
1490
|
R2.info("Using built-in fallback chain for sidekick");
|
|
1448
1491
|
}
|
|
1492
|
+
const hasAnthropic = allModels.some((m) => m.startsWith("anthropic/"));
|
|
1493
|
+
let claudeMax = false;
|
|
1494
|
+
if (hasAnthropic) {
|
|
1495
|
+
R2.message(`Claude Max/Pro subscribers get extended prompt caching (up to 1 hour).
|
|
1496
|
+
` + "This lets Magic Context defer context operations much longer, saving money.");
|
|
1497
|
+
claudeMax = await confirm("Do you have a Claude Max or Pro subscription?", false);
|
|
1498
|
+
if (claudeMax) {
|
|
1499
|
+
R2.success("Cache TTL set to 59m for Anthropic models");
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1449
1502
|
writeMagicContextConfig(paths.magicContextConfig, {
|
|
1450
1503
|
historianModel,
|
|
1451
1504
|
dreamerEnabled,
|
|
1452
1505
|
dreamerModel,
|
|
1453
1506
|
sidekickEnabled,
|
|
1454
|
-
sidekickModel
|
|
1507
|
+
sidekickModel,
|
|
1508
|
+
claudeMax
|
|
1455
1509
|
});
|
|
1456
1510
|
R2.success(`Config written to ${paths.magicContextConfig}`);
|
|
1457
1511
|
if (paths.omoConfig) {
|
|
@@ -17,12 +17,21 @@ export type NoteNudgeTrigger = "historian_complete" | "commit_detected" | "todos
|
|
|
17
17
|
/**
|
|
18
18
|
* Signal that a trigger event occurred. Call from hook layer when any of the 3 triggers fire.
|
|
19
19
|
*/
|
|
20
|
-
export declare function onNoteTrigger(sessionId: string,
|
|
20
|
+
export declare function onNoteTrigger(sessionId: string, trigger: NoteNudgeTrigger): void;
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* Peek at whether a note nudge should be injected during this transform pass.
|
|
23
23
|
* Returns the nudge text if yes, null if no.
|
|
24
|
-
*
|
|
25
|
-
|
|
24
|
+
* Does NOT clear triggerPending — call markNoteNudgeDelivered() after successful placement.
|
|
25
|
+
*/
|
|
26
|
+
export declare function peekNoteNudgeText(db: Database, sessionId: string): string | null;
|
|
27
|
+
/**
|
|
28
|
+
* Mark the note nudge as delivered after successful placement.
|
|
29
|
+
* Only call after appendReminderToLatestUserMessage returns a truthy anchor.
|
|
30
|
+
*/
|
|
31
|
+
export declare function markNoteNudgeDelivered(sessionId: string): void;
|
|
32
|
+
/**
|
|
33
|
+
* Legacy wrapper — peek + mark in one call.
|
|
34
|
+
* Kept for existing tests; prefer peekNoteNudgeText + markNoteNudgeDelivered in production.
|
|
26
35
|
*/
|
|
27
36
|
export declare function getNoteNudgeText(db: Database, sessionId: string): string | null;
|
|
28
37
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"note-nudger.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/note-nudger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"note-nudger.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/note-nudger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAI3C,MAAM,MAAM,gBAAgB,GAAG,oBAAoB,GAAG,iBAAiB,GAAG,gBAAgB,CAAC;AAoB3F;;GAEG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAIhF;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAehF;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAK9D;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAI/E;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAE3D"}
|
|
@@ -1 +1 @@
|
|
|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CAAC;IACzB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,qBAAqB,EAAE,OAAO,CAAC;IAC/B,qBAAqB,EAAE,OAAO,CAAC;IAC/B,WAAW,EAAE,WAAW,CAAC;IACzB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,eAAe,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC7B,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,mBAAmB,CAAC;IACrC,MAAM,EAAE,CACJ,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,EACzD,EAAE,EAAE,eAAe,EACnB,MAAM,EAAE,OAAO,aAAa,EAC5B,aAAa,CAAC,EAAE,QAAQ,EAAE,EAC1B,qBAAqB,CAAC,EAAE,MAAM,EAC9B,oBAAoB,CAAC,EAAE,WAAW,KACjC,YAAY,GAAG,IAAI,CAAC;IACzB,2BAA2B,EAAE,4BAA4B,GAAG,IAAI,CAAC;IACjE,4BAA4B,EAAE,OAAO,CAAC;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,8BAA8B,EAAE,MAAM,CAAC;IACvC,mBAAmB,EAAE,OAAO,CAAC;CAChC;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,yBAAyB,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"transform-postprocess-phase.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/transform-postprocess-phase.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,eAAe,EAIpB,aAAa,EAGhB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAOhF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GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,mBAAmB,CAAC;IACrC,MAAM,EAAE,CACJ,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,EACzD,EAAE,EAAE,eAAe,EACnB,MAAM,EAAE,OAAO,aAAa,EAC5B,aAAa,CAAC,EAAE,QAAQ,EAAE,EAC1B,qBAAqB,CAAC,EAAE,MAAM,EAC9B,oBAAoB,CAAC,EAAE,WAAW,KACjC,YAAY,GAAG,IAAI,CAAC;IACzB,2BAA2B,EAAE,4BAA4B,GAAG,IAAI,CAAC;IACjE,4BAA4B,EAAE,OAAO,CAAC;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,8BAA8B,EAAE,MAAM,CAAC;IACvC,mBAAmB,EAAE,OAAO,CAAC;CAChC;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,yBAAyB,GAAG,IAAI,CAuT3E"}
|
package/dist/index.js
CHANGED
|
@@ -18323,22 +18323,30 @@ function getState(sessionId) {
|
|
|
18323
18323
|
}
|
|
18324
18324
|
return state;
|
|
18325
18325
|
}
|
|
18326
|
-
function onNoteTrigger(sessionId,
|
|
18326
|
+
function onNoteTrigger(sessionId, trigger) {
|
|
18327
18327
|
const state = getState(sessionId);
|
|
18328
18328
|
state.triggerPending = true;
|
|
18329
|
+
sessionLog(sessionId, `note-nudge: trigger fired (${trigger}), triggerPending=true`);
|
|
18329
18330
|
}
|
|
18330
|
-
function
|
|
18331
|
+
function peekNoteNudgeText(db, sessionId) {
|
|
18331
18332
|
const state = getState(sessionId);
|
|
18332
18333
|
if (!state.triggerPending)
|
|
18333
18334
|
return null;
|
|
18334
18335
|
const notes = getSessionNotes(db, sessionId);
|
|
18335
|
-
if (notes.length === 0)
|
|
18336
|
+
if (notes.length === 0) {
|
|
18337
|
+
sessionLog(sessionId, "note-nudge: triggerPending but no notes found, skipping");
|
|
18336
18338
|
return null;
|
|
18337
|
-
|
|
18338
|
-
|
|
18339
|
+
}
|
|
18340
|
+
sessionLog(sessionId, `note-nudge: delivering nudge for ${notes.length} notes`);
|
|
18339
18341
|
const plural = notes.length === 1 ? "note" : "notes";
|
|
18340
18342
|
return `You have ${notes.length} deferred ${plural}. Review with ctx_note read \u2014 some may be actionable now.`;
|
|
18341
18343
|
}
|
|
18344
|
+
function markNoteNudgeDelivered(sessionId) {
|
|
18345
|
+
const state = getState(sessionId);
|
|
18346
|
+
state.triggerPending = false;
|
|
18347
|
+
state.nudgeDelivered = true;
|
|
18348
|
+
sessionLog(sessionId, "note-nudge: marked delivered");
|
|
18349
|
+
}
|
|
18342
18350
|
function clearNoteNudgeState(sessionId) {
|
|
18343
18351
|
stateBySession.delete(sessionId);
|
|
18344
18352
|
}
|
|
@@ -21176,15 +21184,18 @@ function runPostTransformPhase(args) {
|
|
|
21176
21184
|
reinjectNudgeAtAnchor(args.messages, existing.nudgeText, args.nudgePlacements, args.sessionId);
|
|
21177
21185
|
}
|
|
21178
21186
|
}
|
|
21179
|
-
|
|
21180
|
-
|
|
21181
|
-
|
|
21187
|
+
} else {
|
|
21188
|
+
args.nudgePlacements.clear(args.sessionId);
|
|
21189
|
+
}
|
|
21190
|
+
const deferredNoteText = peekNoteNudgeText(args.db, args.sessionId);
|
|
21191
|
+
if (deferredNoteText) {
|
|
21192
|
+
const noteInstruction = `
|
|
21182
21193
|
|
|
21183
21194
|
<instruction name="deferred_notes">${deferredNoteText}</instruction>`;
|
|
21184
|
-
|
|
21195
|
+
const anchored = appendReminderToLatestUserMessage(args.messages, noteInstruction);
|
|
21196
|
+
if (anchored) {
|
|
21197
|
+
markNoteNudgeDelivered(args.sessionId);
|
|
21185
21198
|
}
|
|
21186
|
-
} else {
|
|
21187
|
-
args.nudgePlacements.clear(args.sessionId);
|
|
21188
21199
|
}
|
|
21189
21200
|
}
|
|
21190
21201
|
|
package/package.json
CHANGED