@cortexkit/pi-magic-context 0.43.0 → 0.43.1
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/dist/{index-y33j7m6y.js → index-17102c1m.js} +1 -1
- package/dist/index-5v60m046.js +40 -0
- package/dist/{index-vcjgpb6f.js → index-822b3fcs.js} +1 -1
- package/dist/{index-83wwtw1q.js → index-bfd52y8p.js} +7 -1
- package/dist/{index-5tw61yhp.js → index-kyrajahw.js} +25 -7
- package/dist/index.js +405 -215
- package/dist/{message-time-backfill-dah83bcz.js → message-time-backfill-f0v3yvza.js} +2 -2
- package/dist/{read-session-chunk-3zybnn0f.js → read-session-chunk-4s09z8f5.js} +2 -2
- package/dist/safe-notification-target-d7f3t5qk.js +9 -0
- package/dist/subagent-entry.js +4 -4
- package/package.json +1 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
log
|
|
3
|
+
} from "./index-bfd52y8p.js";
|
|
4
|
+
|
|
5
|
+
// ../plugin/src/shared/safe-notification-target.ts
|
|
6
|
+
var DEFAULT_TITLE_RE = /^(New session - |Child session - )\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
|
|
7
|
+
function isDefaultSessionTitle2(title) {
|
|
8
|
+
return DEFAULT_TITLE_RE.test(title);
|
|
9
|
+
}
|
|
10
|
+
async function readSessionTitle(client, sessionId) {
|
|
11
|
+
try {
|
|
12
|
+
const c = client;
|
|
13
|
+
if (typeof c.session?.get !== "function")
|
|
14
|
+
return null;
|
|
15
|
+
const raw = await Promise.resolve(c.session.get({ path: { id: sessionId } }));
|
|
16
|
+
const obj = raw;
|
|
17
|
+
const title = obj && typeof obj === "object" ? obj.data?.title ?? obj.title : undefined;
|
|
18
|
+
return typeof title === "string" ? title : null;
|
|
19
|
+
} catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
async function waitForSafeNotificationTarget2(client, sessionId, options) {
|
|
24
|
+
const attempts = Math.max(1, options?.attempts ?? 4);
|
|
25
|
+
const delayMs = options?.delayMs ?? 15000;
|
|
26
|
+
for (let attempt = 0;attempt < attempts; attempt += 1) {
|
|
27
|
+
const title = await readSessionTitle(client, sessionId);
|
|
28
|
+
if (title === null)
|
|
29
|
+
return "safe";
|
|
30
|
+
if (!isDefaultSessionTitle2(title))
|
|
31
|
+
return "safe";
|
|
32
|
+
if (attempt < attempts - 1) {
|
|
33
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
log(`[magic-context] notification skipped: session ${sessionId} still has its default title (would suppress title generation); will retry on a later startup`);
|
|
37
|
+
return "skip";
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { isDefaultSessionTitle2, waitForSafeNotificationTarget2 };
|
|
@@ -13,9 +13,15 @@ function getHarness() {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
// ../plugin/src/shared/data-path.ts
|
|
16
|
-
import { existsSync, mkdirSync,
|
|
16
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
17
17
|
import * as os from "node:os";
|
|
18
18
|
import * as path from "node:path";
|
|
19
|
+
|
|
20
|
+
// ../plugin/src/shared/test-temp-dir.ts
|
|
21
|
+
var STALE_TEMP_DIR_AGE_MS = 60 * 60 * 1000;
|
|
22
|
+
var registeredTempDirs = new Set;
|
|
23
|
+
|
|
24
|
+
// ../plugin/src/shared/data-path.ts
|
|
19
25
|
function getDataDir() {
|
|
20
26
|
return process.env.XDG_DATA_HOME ?? path.join(os.homedir(), ".local", "share");
|
|
21
27
|
}
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
sanitizeDiagnosticText,
|
|
7
7
|
log,
|
|
8
8
|
sessionLog
|
|
9
|
-
} from "./index-
|
|
9
|
+
} from "./index-bfd52y8p.js";
|
|
10
10
|
import {
|
|
11
11
|
removeSystemReminders,
|
|
12
12
|
hasMeaningfulUserText2,
|
|
@@ -41,10 +41,10 @@ import {
|
|
|
41
41
|
cleanUserText2,
|
|
42
42
|
readRawSessionMessages2,
|
|
43
43
|
readSessionChunk2
|
|
44
|
-
} from "./index-
|
|
44
|
+
} from "./index-822b3fcs.js";
|
|
45
45
|
import {
|
|
46
46
|
logSlowWriteTransaction
|
|
47
|
-
} from "./index-
|
|
47
|
+
} from "./index-17102c1m.js";
|
|
48
48
|
|
|
49
49
|
// ../plugin/src/config/agent-disable.ts
|
|
50
50
|
var COMPACTION_ENABLED_PATH = `compaction${"."}enabled`;
|
|
@@ -16898,8 +16898,8 @@ function finishDatabaseOpen(db, dbPath, explicitDbPath, latestSupportedVersion)
|
|
|
16898
16898
|
{ readRawSessionMessagePage, readRawSessionMessages },
|
|
16899
16899
|
{ startMessageTimeBackfill }
|
|
16900
16900
|
] = await Promise.all([
|
|
16901
|
-
import("./read-session-chunk-
|
|
16902
|
-
import("./message-time-backfill-
|
|
16901
|
+
import("./read-session-chunk-4s09z8f5.js"),
|
|
16902
|
+
import("./message-time-backfill-f0v3yvza.js")
|
|
16903
16903
|
]);
|
|
16904
16904
|
await startMessageTimeBackfill(db, Object.assign(readRawSessionMessages, {
|
|
16905
16905
|
readPage: readRawSessionMessagePage
|
|
@@ -19457,6 +19457,19 @@ function updateFnv1a32(hash, value) {
|
|
|
19457
19457
|
}
|
|
19458
19458
|
return next;
|
|
19459
19459
|
}
|
|
19460
|
+
function contentSnapshotValue(value) {
|
|
19461
|
+
if (!value || typeof value !== "object")
|
|
19462
|
+
return value;
|
|
19463
|
+
const message = value;
|
|
19464
|
+
const info = message.info;
|
|
19465
|
+
const summary = info?.summary;
|
|
19466
|
+
if (!Array.isArray(message.parts) || info?.role !== "user" || summary === null || typeof summary !== "object" || Array.isArray(summary) || Object.keys(summary).length !== 1 || !Array.isArray(summary.diffs) || summary.diffs.length !== 0)
|
|
19467
|
+
return value;
|
|
19468
|
+
return {
|
|
19469
|
+
...message,
|
|
19470
|
+
info: Object.fromEntries(Object.entries(info).filter(([key]) => key !== "summary"))
|
|
19471
|
+
};
|
|
19472
|
+
}
|
|
19460
19473
|
function signatureForFields(fields) {
|
|
19461
19474
|
let hash = FNV1A_32_OFFSET;
|
|
19462
19475
|
for (const field of fields) {
|
|
@@ -19504,7 +19517,7 @@ function lkgContentFields(value) {
|
|
|
19504
19517
|
fields.push(LKG_SNAPSHOT_UNDEFINED);
|
|
19505
19518
|
};
|
|
19506
19519
|
try {
|
|
19507
|
-
visit(value);
|
|
19520
|
+
visit(contentSnapshotValue(value));
|
|
19508
19521
|
return fields;
|
|
19509
19522
|
} catch {
|
|
19510
19523
|
return null;
|
|
@@ -33012,7 +33025,12 @@ async function runGit(cwd, args) {
|
|
|
33012
33025
|
encoding: "utf8"
|
|
33013
33026
|
});
|
|
33014
33027
|
return String(result.stdout);
|
|
33015
|
-
} catch {
|
|
33028
|
+
} catch (error) {
|
|
33029
|
+
if (error.killed || error.code === "ETIMEDOUT") {
|
|
33030
|
+
throw new Error(`Git verification command timed out after ${GIT_TIMEOUT_MS2}ms`, {
|
|
33031
|
+
cause: error
|
|
33032
|
+
});
|
|
33033
|
+
}
|
|
33016
33034
|
return null;
|
|
33017
33035
|
}
|
|
33018
33036
|
}
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
log,
|
|
10
10
|
sessionLog,
|
|
11
11
|
flushLogger
|
|
12
|
-
} from "./index-
|
|
12
|
+
} from "./index-bfd52y8p.js";
|
|
13
13
|
import {
|
|
14
14
|
COMPACTION_ENABLED_PATH,
|
|
15
15
|
isDreamerRunnable,
|
|
@@ -402,7 +402,7 @@ import {
|
|
|
402
402
|
registerTodoStateLifecycle,
|
|
403
403
|
syncCtxMemoryToolEnabled,
|
|
404
404
|
registerMagicContextTools
|
|
405
|
-
} from "./index-
|
|
405
|
+
} from "./index-kyrajahw.js";
|
|
406
406
|
import {
|
|
407
407
|
CTX_REDUCE_KEEP,
|
|
408
408
|
newestCtxReduceTagNumbers,
|
|
@@ -512,13 +512,14 @@ import {
|
|
|
512
512
|
getRawSessionTagKeysThrough2,
|
|
513
513
|
getLegacyProtectedTailStartOrdinal2,
|
|
514
514
|
readSessionChunk2
|
|
515
|
-
} from "./index-
|
|
515
|
+
} from "./index-822b3fcs.js";
|
|
516
516
|
import {
|
|
517
517
|
pushNotification2
|
|
518
518
|
} from "./index-b3eqj1g6.js";
|
|
519
|
+
import"./index-5v60m046.js";
|
|
519
520
|
import {
|
|
520
521
|
logSlowWriteTransaction
|
|
521
|
-
} from "./index-
|
|
522
|
+
} from "./index-17102c1m.js";
|
|
522
523
|
import {
|
|
523
524
|
__toESM
|
|
524
525
|
} from "./index-22jkk6wg.js";
|
|
@@ -842,7 +843,7 @@ var DREAM_TASK_CAPABILITIES = {
|
|
|
842
843
|
"maintain-docs": {
|
|
843
844
|
requiresTools: true,
|
|
844
845
|
transport: "tool-loop",
|
|
845
|
-
toolLoopPurpose: "needs
|
|
846
|
+
toolLoopPurpose: "needs read-only file tools to investigate documentation corrections"
|
|
846
847
|
},
|
|
847
848
|
"evaluate-smart-notes": { requiresTools: false, transport: "single-shot" },
|
|
848
849
|
"review-user-memories": { requiresTools: false, transport: "single-shot" },
|
|
@@ -3191,6 +3192,73 @@ class HiddenCompletionRefusal extends Error {
|
|
|
3191
3192
|
this.name = "HiddenCompletionRefusal";
|
|
3192
3193
|
}
|
|
3193
3194
|
}
|
|
3195
|
+
// ../plugin/src/shared/assistant-message-extractor.ts
|
|
3196
|
+
function asSessionMessage(value) {
|
|
3197
|
+
if (!isRecord(value))
|
|
3198
|
+
return null;
|
|
3199
|
+
const info = value.info;
|
|
3200
|
+
const parts = value.parts;
|
|
3201
|
+
return {
|
|
3202
|
+
info: isRecord(info) ? {
|
|
3203
|
+
role: typeof info.role === "string" ? info.role : undefined,
|
|
3204
|
+
time: isRecord(info.time) ? {
|
|
3205
|
+
created: typeof info.time.created === "number" ? info.time.created : undefined
|
|
3206
|
+
} : undefined,
|
|
3207
|
+
error: info.error,
|
|
3208
|
+
finish: typeof info.finish === "string" ? info.finish : typeof info.finish_reason === "string" ? info.finish_reason : typeof info.finishReason === "string" ? info.finishReason : undefined
|
|
3209
|
+
} : undefined,
|
|
3210
|
+
parts
|
|
3211
|
+
};
|
|
3212
|
+
}
|
|
3213
|
+
function getCreatedTime(message) {
|
|
3214
|
+
return message.info?.time?.created ?? 0;
|
|
3215
|
+
}
|
|
3216
|
+
function getTextParts(message) {
|
|
3217
|
+
if (!Array.isArray(message.parts))
|
|
3218
|
+
return [];
|
|
3219
|
+
return message.parts.filter((part) => isRecord(part)).map((part) => ({
|
|
3220
|
+
type: typeof part.type === "string" ? part.type : undefined,
|
|
3221
|
+
text: typeof part.text === "string" ? part.text : undefined
|
|
3222
|
+
})).filter((part) => part.type === "text" && Boolean(part.text));
|
|
3223
|
+
}
|
|
3224
|
+
function getLatestAssistantMessage(messages) {
|
|
3225
|
+
if (!Array.isArray(messages) || messages.length === 0)
|
|
3226
|
+
return null;
|
|
3227
|
+
return messages.map(asSessionMessage).filter((message) => message !== null).filter((message) => message.info?.role === "assistant").sort((a, b) => getCreatedTime(b) - getCreatedTime(a))[0] ?? null;
|
|
3228
|
+
}
|
|
3229
|
+
function extractLatestAssistantText(messages) {
|
|
3230
|
+
const latest = getLatestAssistantMessage(messages);
|
|
3231
|
+
if (!latest)
|
|
3232
|
+
return null;
|
|
3233
|
+
return getTextParts(latest).map((part) => part.text).join(`
|
|
3234
|
+
`) || null;
|
|
3235
|
+
}
|
|
3236
|
+
function extractLatestAssistantFailure(messages) {
|
|
3237
|
+
const latest = getLatestAssistantMessage(messages);
|
|
3238
|
+
if (!latest || latest.info?.error === undefined || latest.info.error === null)
|
|
3239
|
+
return null;
|
|
3240
|
+
return {
|
|
3241
|
+
error: latest.info.error,
|
|
3242
|
+
finish: latest.info.finish ?? null
|
|
3243
|
+
};
|
|
3244
|
+
}
|
|
3245
|
+
function hasLengthCappedOutput(value) {
|
|
3246
|
+
if (Array.isArray(value))
|
|
3247
|
+
return value.some((item) => hasLengthCappedOutput(item));
|
|
3248
|
+
if (!isRecord(value))
|
|
3249
|
+
return false;
|
|
3250
|
+
if (value.length_capped === true || value.lengthCapped === true)
|
|
3251
|
+
return true;
|
|
3252
|
+
const finishReason = value.finish_reason ?? value.finishReason ?? value.finish ?? (value.type === "step-finish" ? value.reason : undefined) ?? value.stopReason;
|
|
3253
|
+
if (typeof finishReason === "string") {
|
|
3254
|
+
const normalized = finishReason.toLowerCase();
|
|
3255
|
+
if (normalized === "length" || normalized === "max_tokens" || normalized === "max_output_tokens") {
|
|
3256
|
+
return true;
|
|
3257
|
+
}
|
|
3258
|
+
}
|
|
3259
|
+
return Object.values(value).some((item) => hasLengthCappedOutput(item));
|
|
3260
|
+
}
|
|
3261
|
+
|
|
3194
3262
|
// ../plugin/src/shared/resolve-fallbacks.ts
|
|
3195
3263
|
function parseProviderModel(spec) {
|
|
3196
3264
|
const slash = spec.indexOf("/");
|
|
@@ -3484,6 +3552,17 @@ async function attemptAndValidate(client, args, timeoutMs, signal, callContext,
|
|
|
3484
3552
|
};
|
|
3485
3553
|
}
|
|
3486
3554
|
try {
|
|
3555
|
+
if (!extractLatestAssistantText(output)) {
|
|
3556
|
+
const assistantFailure = extractLatestAssistantFailure(output);
|
|
3557
|
+
if (assistantFailure) {
|
|
3558
|
+
const error = new Error(`Host recorded assistant error: ${String(assistantFailure.error)}`);
|
|
3559
|
+
Object.assign(error, {
|
|
3560
|
+
name: "DreamerProviderOutputFailureError",
|
|
3561
|
+
transient: true
|
|
3562
|
+
});
|
|
3563
|
+
throw error;
|
|
3564
|
+
}
|
|
3565
|
+
}
|
|
3487
3566
|
const validated = await options.validateOutput(output, attempt);
|
|
3488
3567
|
return { output, validated, attempt };
|
|
3489
3568
|
} catch (error) {
|
|
@@ -3611,73 +3690,6 @@ function summarizeChildStderr(stderr) {
|
|
|
3611
3690
|
return excerptLines.join(`
|
|
3612
3691
|
`).slice(0, MAX_CHILD_STDERR_SUMMARY_LENGTH);
|
|
3613
3692
|
}
|
|
3614
|
-
// ../plugin/src/shared/assistant-message-extractor.ts
|
|
3615
|
-
function asSessionMessage(value) {
|
|
3616
|
-
if (!isRecord(value))
|
|
3617
|
-
return null;
|
|
3618
|
-
const info = value.info;
|
|
3619
|
-
const parts = value.parts;
|
|
3620
|
-
return {
|
|
3621
|
-
info: isRecord(info) ? {
|
|
3622
|
-
role: typeof info.role === "string" ? info.role : undefined,
|
|
3623
|
-
time: isRecord(info.time) ? {
|
|
3624
|
-
created: typeof info.time.created === "number" ? info.time.created : undefined
|
|
3625
|
-
} : undefined,
|
|
3626
|
-
error: info.error,
|
|
3627
|
-
finish: typeof info.finish === "string" ? info.finish : typeof info.finish_reason === "string" ? info.finish_reason : typeof info.finishReason === "string" ? info.finishReason : undefined
|
|
3628
|
-
} : undefined,
|
|
3629
|
-
parts
|
|
3630
|
-
};
|
|
3631
|
-
}
|
|
3632
|
-
function getCreatedTime(message) {
|
|
3633
|
-
return message.info?.time?.created ?? 0;
|
|
3634
|
-
}
|
|
3635
|
-
function getTextParts(message) {
|
|
3636
|
-
if (!Array.isArray(message.parts))
|
|
3637
|
-
return [];
|
|
3638
|
-
return message.parts.filter((part) => isRecord(part)).map((part) => ({
|
|
3639
|
-
type: typeof part.type === "string" ? part.type : undefined,
|
|
3640
|
-
text: typeof part.text === "string" ? part.text : undefined
|
|
3641
|
-
})).filter((part) => part.type === "text" && Boolean(part.text));
|
|
3642
|
-
}
|
|
3643
|
-
function getLatestAssistantMessage(messages) {
|
|
3644
|
-
if (!Array.isArray(messages) || messages.length === 0)
|
|
3645
|
-
return null;
|
|
3646
|
-
return messages.map(asSessionMessage).filter((message) => message !== null).filter((message) => message.info?.role === "assistant").sort((a, b) => getCreatedTime(b) - getCreatedTime(a))[0] ?? null;
|
|
3647
|
-
}
|
|
3648
|
-
function extractLatestAssistantText(messages) {
|
|
3649
|
-
const latest = getLatestAssistantMessage(messages);
|
|
3650
|
-
if (!latest)
|
|
3651
|
-
return null;
|
|
3652
|
-
return getTextParts(latest).map((part) => part.text).join(`
|
|
3653
|
-
`) || null;
|
|
3654
|
-
}
|
|
3655
|
-
function extractLatestAssistantFailure(messages) {
|
|
3656
|
-
const latest = getLatestAssistantMessage(messages);
|
|
3657
|
-
if (!latest || latest.info?.error === undefined || latest.info.error === null)
|
|
3658
|
-
return null;
|
|
3659
|
-
return {
|
|
3660
|
-
error: latest.info.error,
|
|
3661
|
-
finish: latest.info.finish ?? null
|
|
3662
|
-
};
|
|
3663
|
-
}
|
|
3664
|
-
function hasLengthCappedOutput(value) {
|
|
3665
|
-
if (Array.isArray(value))
|
|
3666
|
-
return value.some((item) => hasLengthCappedOutput(item));
|
|
3667
|
-
if (!isRecord(value))
|
|
3668
|
-
return false;
|
|
3669
|
-
if (value.length_capped === true || value.lengthCapped === true)
|
|
3670
|
-
return true;
|
|
3671
|
-
const finishReason = value.finish_reason ?? value.finishReason ?? value.finish ?? (value.type === "step-finish" ? value.reason : undefined) ?? value.stopReason;
|
|
3672
|
-
if (typeof finishReason === "string") {
|
|
3673
|
-
const normalized = finishReason.toLowerCase();
|
|
3674
|
-
if (normalized === "length" || normalized === "max_tokens" || normalized === "max_output_tokens") {
|
|
3675
|
-
return true;
|
|
3676
|
-
}
|
|
3677
|
-
}
|
|
3678
|
-
return Object.values(value).some((item) => hasLengthCappedOutput(item));
|
|
3679
|
-
}
|
|
3680
|
-
|
|
3681
3693
|
// ../plugin/src/shared/child-session-teardown.ts
|
|
3682
3694
|
async function teardownChildSession(args) {
|
|
3683
3695
|
const { client, sessionId, sessionDirectory, promptSettled, context, log } = args;
|
|
@@ -6526,13 +6538,13 @@ async function runHiddenSingleShotPrompt(args) {
|
|
|
6526
6538
|
throw new Error(`${args.callContext} returned length-capped output`);
|
|
6527
6539
|
}
|
|
6528
6540
|
const text = completion.text;
|
|
6529
|
-
if (!text)
|
|
6541
|
+
if (!text && !args.allowEmpty)
|
|
6530
6542
|
throw new Error(`${args.callContext} returned no output`);
|
|
6531
|
-
return args.parse(text);
|
|
6543
|
+
return args.parse(text ?? "", completion);
|
|
6532
6544
|
}
|
|
6533
6545
|
});
|
|
6534
6546
|
promptSettled = true;
|
|
6535
|
-
return { validated: run.validated, completion: run.output };
|
|
6547
|
+
return { validated: run.validated, completion: run.output, childSessionId: handle.id };
|
|
6536
6548
|
} finally {
|
|
6537
6549
|
await args.executor.close(handle, {
|
|
6538
6550
|
promptSettled,
|
|
@@ -9721,8 +9733,36 @@ async function mapOneBatch(args, batch, sliceMs, signal) {
|
|
|
9721
9733
|
let promptSettled = false;
|
|
9722
9734
|
const startedAt = Date.now();
|
|
9723
9735
|
try {
|
|
9736
|
+
const prompt = buildMapMemoriesPrompt(args.projectIdentity, batch);
|
|
9737
|
+
if (args.hiddenCompletionExecutor) {
|
|
9738
|
+
const run = await runHiddenSingleShotPrompt({
|
|
9739
|
+
executor: args.hiddenCompletionExecutor,
|
|
9740
|
+
parentSessionId: args.parentSessionId,
|
|
9741
|
+
sessionDirectory: args.sessionDirectory,
|
|
9742
|
+
agent: DREAMER_MEMORY_MAPPER_AGENT,
|
|
9743
|
+
system: MAP_MEMORIES_SYSTEM_PROMPT,
|
|
9744
|
+
prompt,
|
|
9745
|
+
title: "magic-context-dream-map-memories",
|
|
9746
|
+
callContext: "dreamer:map-memories",
|
|
9747
|
+
model: args.model,
|
|
9748
|
+
fallbackModels: args.fallbackModels,
|
|
9749
|
+
timeoutMs: sliceMs,
|
|
9750
|
+
signal,
|
|
9751
|
+
parse: (text) => validateMapMemoriesManifest(text, new Set(batch.map((memory) => memory.id)))
|
|
9752
|
+
});
|
|
9753
|
+
recordInvocation2(args, startedAt, {
|
|
9754
|
+
status: "completed",
|
|
9755
|
+
messages: run.completion.messages ?? []
|
|
9756
|
+
});
|
|
9757
|
+
const outcome = await applyParsedBatchMappings(args, batch, run.validated);
|
|
9758
|
+
const returnedIds = new Set(run.validated.map((entry) => entry.id));
|
|
9759
|
+
return { ...outcome, requeue: batch.filter((memory) => !returnedIds.has(memory.id)) };
|
|
9760
|
+
}
|
|
9761
|
+
const client = args.client;
|
|
9762
|
+
if (!client)
|
|
9763
|
+
throw new Error("map-memories requires a client or hidden completion executor");
|
|
9724
9764
|
const createResponse = await createChildSessionWithFence({
|
|
9725
|
-
client
|
|
9765
|
+
client,
|
|
9726
9766
|
db: args.db,
|
|
9727
9767
|
parentSessionId: args.parentSessionId,
|
|
9728
9768
|
title: "magic-context-dream-map-memories",
|
|
@@ -9734,8 +9774,7 @@ async function mapOneBatch(args, batch, sliceMs, signal) {
|
|
|
9734
9774
|
agentSessionId = typeof created?.id === "string" ? created.id : null;
|
|
9735
9775
|
if (!agentSessionId)
|
|
9736
9776
|
throw new Error("Could not create map-memories session.");
|
|
9737
|
-
const
|
|
9738
|
-
const run = await promptSyncWithValidatedOutputRetry(args.client, {
|
|
9777
|
+
const run = await promptSyncWithValidatedOutputRetry(client, {
|
|
9739
9778
|
path: { id: agentSessionId },
|
|
9740
9779
|
query: { directory: args.sessionDirectory },
|
|
9741
9780
|
body: {
|
|
@@ -9750,7 +9789,7 @@ async function mapOneBatch(args, batch, sliceMs, signal) {
|
|
|
9750
9789
|
fallbackModels: args.fallbackModels,
|
|
9751
9790
|
callContext: "dreamer:map-memories",
|
|
9752
9791
|
fetchOutput: async () => {
|
|
9753
|
-
const messagesResponse = await
|
|
9792
|
+
const messagesResponse = await client.session.messages({
|
|
9754
9793
|
path: { id: agentSessionId },
|
|
9755
9794
|
query: { directory: args.sessionDirectory, limit: 100 }
|
|
9756
9795
|
});
|
|
@@ -9793,15 +9832,16 @@ async function mapOneBatch(args, batch, sliceMs, signal) {
|
|
|
9793
9832
|
}
|
|
9794
9833
|
};
|
|
9795
9834
|
} finally {
|
|
9796
|
-
|
|
9797
|
-
|
|
9798
|
-
|
|
9799
|
-
|
|
9800
|
-
|
|
9801
|
-
|
|
9802
|
-
|
|
9803
|
-
|
|
9804
|
-
|
|
9835
|
+
if (agentSessionId && args.client)
|
|
9836
|
+
await teardownChildSession({
|
|
9837
|
+
client: args.client,
|
|
9838
|
+
sessionId: agentSessionId,
|
|
9839
|
+
sessionDirectory: args.sessionDirectory,
|
|
9840
|
+
promptSettled,
|
|
9841
|
+
privacySensitive: true,
|
|
9842
|
+
context: "[dreamer] map-memories",
|
|
9843
|
+
log
|
|
9844
|
+
});
|
|
9805
9845
|
}
|
|
9806
9846
|
}
|
|
9807
9847
|
async function applyParsedBatchMappings(args, batch, parsed) {
|
|
@@ -10394,8 +10434,41 @@ async function refreshOnePrimer(args, primer, sliceMs, signal) {
|
|
|
10394
10434
|
let promptSettled = false;
|
|
10395
10435
|
const startedAt = Date.now();
|
|
10396
10436
|
try {
|
|
10437
|
+
const prompt = buildInvestigationPrompt(primer, seed.kind, seed.orientation, seed.prePost);
|
|
10438
|
+
if (args.hiddenCompletionExecutor) {
|
|
10439
|
+
const run = await runHiddenSingleShotPrompt({
|
|
10440
|
+
executor: args.hiddenCompletionExecutor,
|
|
10441
|
+
parentSessionId: args.parentSessionId,
|
|
10442
|
+
sessionDirectory: args.sessionDirectory,
|
|
10443
|
+
agent: DREAMER_PRIMER_INVESTIGATOR_AGENT,
|
|
10444
|
+
system: PRIMER_INVESTIGATOR_SYSTEM_PROMPT,
|
|
10445
|
+
prompt,
|
|
10446
|
+
title: "magic-context-dream-refresh-primers",
|
|
10447
|
+
callContext: "dreamer:refresh-primers",
|
|
10448
|
+
model: args.model,
|
|
10449
|
+
fallbackModels: args.fallbackModels,
|
|
10450
|
+
language: args.language,
|
|
10451
|
+
timeoutMs: sliceMs,
|
|
10452
|
+
signal,
|
|
10453
|
+
parse: (text) => parseAnswer([{ info: { role: "assistant" }, parts: [{ type: "text", text }] }], primer.answer)
|
|
10454
|
+
});
|
|
10455
|
+
recordInvocation3(args, startedAt, {
|
|
10456
|
+
status: "completed",
|
|
10457
|
+
messages: run.completion.messages ?? []
|
|
10458
|
+
});
|
|
10459
|
+
const answer = run.validated.trim();
|
|
10460
|
+
if (!answer || investigationToolCallCount(run.completion.messages ?? []) === 0)
|
|
10461
|
+
return false;
|
|
10462
|
+
runLeaseGuardedWrite(args.db, args.holderId, args.leaseKey, () => {
|
|
10463
|
+
updatePrimerAnswer(args.db, primer.id, answer);
|
|
10464
|
+
});
|
|
10465
|
+
return true;
|
|
10466
|
+
}
|
|
10467
|
+
const client = args.client;
|
|
10468
|
+
if (!client)
|
|
10469
|
+
throw new Error("refresh-primers requires a client or hidden completion executor");
|
|
10397
10470
|
const createResponse = await createChildSessionWithFence({
|
|
10398
|
-
client
|
|
10471
|
+
client,
|
|
10399
10472
|
db: args.db,
|
|
10400
10473
|
parentSessionId: args.parentSessionId,
|
|
10401
10474
|
title: "magic-context-dream-refresh-primers",
|
|
@@ -10407,8 +10480,7 @@ async function refreshOnePrimer(args, primer, sliceMs, signal) {
|
|
|
10407
10480
|
agentSessionId = typeof created?.id === "string" ? created.id : null;
|
|
10408
10481
|
if (!agentSessionId)
|
|
10409
10482
|
throw new Error("Could not create primer refresh session.");
|
|
10410
|
-
const
|
|
10411
|
-
const run = await promptSyncWithValidatedOutputRetry(args.client, {
|
|
10483
|
+
const run = await promptSyncWithValidatedOutputRetry(client, {
|
|
10412
10484
|
path: { id: agentSessionId },
|
|
10413
10485
|
query: { directory: args.sessionDirectory },
|
|
10414
10486
|
body: {
|
|
@@ -10423,7 +10495,7 @@ async function refreshOnePrimer(args, primer, sliceMs, signal) {
|
|
|
10423
10495
|
fallbackModels: args.fallbackModels,
|
|
10424
10496
|
callContext: "dreamer:refresh-primers",
|
|
10425
10497
|
fetchOutput: async () => {
|
|
10426
|
-
const messagesResponse = await
|
|
10498
|
+
const messagesResponse = await client.session.messages({
|
|
10427
10499
|
path: { id: agentSessionId },
|
|
10428
10500
|
query: { directory: args.sessionDirectory, limit: 100 }
|
|
10429
10501
|
});
|
|
@@ -10452,15 +10524,16 @@ async function refreshOnePrimer(args, primer, sliceMs, signal) {
|
|
|
10452
10524
|
recordInvocation3(args, startedAt, { status: failedInvocationStatus(error), error });
|
|
10453
10525
|
throw error;
|
|
10454
10526
|
} finally {
|
|
10455
|
-
|
|
10456
|
-
|
|
10457
|
-
|
|
10458
|
-
|
|
10459
|
-
|
|
10460
|
-
|
|
10461
|
-
|
|
10462
|
-
|
|
10463
|
-
|
|
10527
|
+
if (agentSessionId && args.client)
|
|
10528
|
+
await teardownChildSession({
|
|
10529
|
+
client: args.client,
|
|
10530
|
+
sessionId: agentSessionId,
|
|
10531
|
+
sessionDirectory: args.sessionDirectory,
|
|
10532
|
+
promptSettled,
|
|
10533
|
+
privacySensitive: true,
|
|
10534
|
+
context: "[dreamer] refresh-primers",
|
|
10535
|
+
log
|
|
10536
|
+
});
|
|
10464
10537
|
}
|
|
10465
10538
|
}
|
|
10466
10539
|
function originSessionIdForPrimer(args, primer) {
|
|
@@ -11362,8 +11435,40 @@ async function verifyOneBatch(args, batch, sliceMs, signal) {
|
|
|
11362
11435
|
let promptSettled = false;
|
|
11363
11436
|
const startedAt = Date.now();
|
|
11364
11437
|
try {
|
|
11438
|
+
const prompt = buildVerifyPrompt(args.projectIdentity, batch);
|
|
11439
|
+
if (args.hiddenCompletionExecutor) {
|
|
11440
|
+
const run = await runHiddenSingleShotPrompt({
|
|
11441
|
+
executor: args.hiddenCompletionExecutor,
|
|
11442
|
+
parentSessionId: args.parentSessionId,
|
|
11443
|
+
sessionDirectory: args.sessionDirectory,
|
|
11444
|
+
agent: DREAMER_MEMORY_MAPPER_AGENT,
|
|
11445
|
+
system: VERIFY_SYSTEM_PROMPT,
|
|
11446
|
+
prompt,
|
|
11447
|
+
title: "magic-context-dream-verify",
|
|
11448
|
+
callContext: "dreamer:verify",
|
|
11449
|
+
model: args.model,
|
|
11450
|
+
fallbackModels: args.fallbackModels,
|
|
11451
|
+
language: args.language,
|
|
11452
|
+
timeoutMs: sliceMs,
|
|
11453
|
+
signal,
|
|
11454
|
+
parse: (text) => {
|
|
11455
|
+
const providerFailure = providerOutputFailureFromInvalidManifest([], text);
|
|
11456
|
+
if (providerFailure)
|
|
11457
|
+
throw providerFailure;
|
|
11458
|
+
return validateVerifyManifest(text, new Set(batch.map((memory) => memory.id)));
|
|
11459
|
+
}
|
|
11460
|
+
});
|
|
11461
|
+
recordInvocation4(args, startedAt, {
|
|
11462
|
+
status: "completed",
|
|
11463
|
+
messages: run.completion.messages ?? []
|
|
11464
|
+
});
|
|
11465
|
+
return applyParsedVerifyManifest(args, batch, run.validated);
|
|
11466
|
+
}
|
|
11467
|
+
const client = args.client;
|
|
11468
|
+
if (!client)
|
|
11469
|
+
throw new Error("verify requires a client or hidden completion executor");
|
|
11365
11470
|
const createResponse = await createChildSessionWithFence({
|
|
11366
|
-
client
|
|
11471
|
+
client,
|
|
11367
11472
|
db: args.db,
|
|
11368
11473
|
parentSessionId: args.parentSessionId,
|
|
11369
11474
|
title: "magic-context-dream-verify",
|
|
@@ -11375,8 +11480,7 @@ async function verifyOneBatch(args, batch, sliceMs, signal) {
|
|
|
11375
11480
|
agentSessionId = typeof created?.id === "string" ? created.id : null;
|
|
11376
11481
|
if (!agentSessionId)
|
|
11377
11482
|
throw new Error("Could not create verify session.");
|
|
11378
|
-
const
|
|
11379
|
-
const run = await promptSyncWithValidatedOutputRetry(args.client, {
|
|
11483
|
+
const run = await promptSyncWithValidatedOutputRetry(client, {
|
|
11380
11484
|
path: { id: agentSessionId },
|
|
11381
11485
|
query: { directory: args.sessionDirectory },
|
|
11382
11486
|
body: {
|
|
@@ -11391,7 +11495,7 @@ async function verifyOneBatch(args, batch, sliceMs, signal) {
|
|
|
11391
11495
|
fallbackModels: args.fallbackModels,
|
|
11392
11496
|
callContext: "dreamer:verify",
|
|
11393
11497
|
fetchOutput: async () => {
|
|
11394
|
-
const messagesResponse = await
|
|
11498
|
+
const messagesResponse = await client.session.messages({
|
|
11395
11499
|
path: { id: agentSessionId },
|
|
11396
11500
|
query: { directory: args.sessionDirectory, limit: 100 }
|
|
11397
11501
|
});
|
|
@@ -11432,15 +11536,16 @@ async function verifyOneBatch(args, batch, sliceMs, signal) {
|
|
|
11432
11536
|
providerFailure
|
|
11433
11537
|
};
|
|
11434
11538
|
} finally {
|
|
11435
|
-
|
|
11436
|
-
|
|
11437
|
-
|
|
11438
|
-
|
|
11439
|
-
|
|
11440
|
-
|
|
11441
|
-
|
|
11442
|
-
|
|
11443
|
-
|
|
11539
|
+
if (agentSessionId && args.client)
|
|
11540
|
+
await teardownChildSession({
|
|
11541
|
+
client: args.client,
|
|
11542
|
+
sessionId: agentSessionId,
|
|
11543
|
+
sessionDirectory: args.sessionDirectory,
|
|
11544
|
+
promptSettled,
|
|
11545
|
+
privacySensitive: true,
|
|
11546
|
+
context: "[dreamer] verify",
|
|
11547
|
+
log
|
|
11548
|
+
});
|
|
11444
11549
|
}
|
|
11445
11550
|
}
|
|
11446
11551
|
async function applyParsedVerifyManifest(args, batch, parsed) {
|
|
@@ -11608,6 +11713,8 @@ async function applyParsedVerifyManifest(args, batch, parsed) {
|
|
|
11608
11713
|
async function normalizeFiles(args, rawFiles) {
|
|
11609
11714
|
if (rawFiles.length === 0)
|
|
11610
11715
|
return [];
|
|
11716
|
+
if (args.normalizeFiles)
|
|
11717
|
+
return args.normalizeFiles(rawFiles);
|
|
11611
11718
|
const normalized = await normalizeVerificationFiles({
|
|
11612
11719
|
cwd: args.sessionDirectory,
|
|
11613
11720
|
files: rawFiles
|
|
@@ -11941,7 +12048,8 @@ function createDreamTaskExecutor(deps) {
|
|
|
11941
12048
|
if (config.task === "map-memories") {
|
|
11942
12049
|
const result = await mapMemories({
|
|
11943
12050
|
db,
|
|
11944
|
-
client:
|
|
12051
|
+
client: deps.client,
|
|
12052
|
+
hiddenCompletionExecutor: deps.hiddenCompletionExecutor,
|
|
11945
12053
|
projectIdentity,
|
|
11946
12054
|
parentSessionId: parent,
|
|
11947
12055
|
sessionDirectory: deps.sessionDirectory,
|
|
@@ -11978,7 +12086,8 @@ function createDreamTaskExecutor(deps) {
|
|
|
11978
12086
|
const memoryBefore = getMemoryCountsByStatus(db, projectIdentity);
|
|
11979
12087
|
const result = await runVerify({
|
|
11980
12088
|
db,
|
|
11981
|
-
client:
|
|
12089
|
+
client: deps.client,
|
|
12090
|
+
hiddenCompletionExecutor: deps.hiddenCompletionExecutor,
|
|
11982
12091
|
projectIdentity,
|
|
11983
12092
|
parentSessionId: parent,
|
|
11984
12093
|
sessionDirectory: deps.sessionDirectory,
|
|
@@ -12079,7 +12188,8 @@ function createDreamTaskExecutor(deps) {
|
|
|
12079
12188
|
if (config.task === "refresh-primers") {
|
|
12080
12189
|
const result = await refreshPrimers({
|
|
12081
12190
|
db,
|
|
12082
|
-
client:
|
|
12191
|
+
client: deps.client,
|
|
12192
|
+
hiddenCompletionExecutor: deps.hiddenCompletionExecutor,
|
|
12083
12193
|
projectIdentity,
|
|
12084
12194
|
parentSessionId: parent,
|
|
12085
12195
|
sessionDirectory: deps.sessionDirectory,
|
|
@@ -12347,24 +12457,45 @@ async function runRetrospectiveTask(config, ctx, helpers) {
|
|
|
12347
12457
|
abortController.abort();
|
|
12348
12458
|
}, ctx.leaseAcquisition);
|
|
12349
12459
|
let childSessionId = null;
|
|
12460
|
+
let hiddenHandle = null;
|
|
12350
12461
|
let promptSettled = false;
|
|
12351
12462
|
try {
|
|
12352
|
-
|
|
12353
|
-
|
|
12354
|
-
|
|
12355
|
-
|
|
12356
|
-
|
|
12357
|
-
|
|
12358
|
-
|
|
12359
|
-
|
|
12360
|
-
|
|
12361
|
-
|
|
12362
|
-
|
|
12463
|
+
if (deps.hiddenCompletionExecutor) {
|
|
12464
|
+
hiddenHandle = await deps.hiddenCompletionExecutor.open({
|
|
12465
|
+
parentSessionId: parent ?? undefined,
|
|
12466
|
+
agent: DREAMER_RETROSPECTIVE_AGENT,
|
|
12467
|
+
kind: "dreamer-task",
|
|
12468
|
+
system: FRICTION_GATE_SYSTEM_PROMPT,
|
|
12469
|
+
model: config.model,
|
|
12470
|
+
configuredModels: [
|
|
12471
|
+
...config.model ? [config.model] : [],
|
|
12472
|
+
...config.fallbackModels ?? []
|
|
12473
|
+
],
|
|
12474
|
+
timeoutMs: Math.max(1, deadline - Date.now()),
|
|
12475
|
+
title: "magic-context-dream-retrospective",
|
|
12476
|
+
directory: deps.sessionDirectory
|
|
12477
|
+
});
|
|
12478
|
+
childSessionId = hiddenHandle.id;
|
|
12479
|
+
} else {
|
|
12480
|
+
const createResponse = await createChildSessionWithFence({
|
|
12481
|
+
client: requireDreamClient(deps.client),
|
|
12482
|
+
db,
|
|
12483
|
+
parentSessionId: parent ?? undefined,
|
|
12484
|
+
title: "magic-context-dream-retrospective",
|
|
12485
|
+
directory: deps.sessionDirectory
|
|
12486
|
+
});
|
|
12487
|
+
const created = normalizeSDKResponse(createResponse, null, { preferResponseOnMissingData: true });
|
|
12488
|
+
childSessionId = typeof created?.id === "string" ? created.id : null;
|
|
12489
|
+
if (!childSessionId)
|
|
12490
|
+
throw new Error("Retrospective could not create its child session.");
|
|
12491
|
+
}
|
|
12363
12492
|
const sessionId = childSessionId;
|
|
12493
|
+
if (!sessionId)
|
|
12494
|
+
throw new Error("Retrospective could not create its child session.");
|
|
12364
12495
|
const runChildTurn = async (system, userText) => {
|
|
12365
12496
|
const remainingMs = Math.max(0, deadline - Date.now());
|
|
12366
12497
|
promptSettled = false;
|
|
12367
|
-
const run = await promptSyncWithValidatedOutputRetry(requireDreamClient(deps.client), {
|
|
12498
|
+
const run = await promptSyncWithValidatedOutputRetry(deps.hiddenCompletionExecutor ? undefined : requireDreamClient(deps.client), {
|
|
12368
12499
|
path: { id: sessionId },
|
|
12369
12500
|
query: { directory: deps.sessionDirectory },
|
|
12370
12501
|
body: {
|
|
@@ -12378,7 +12509,13 @@ async function runRetrospectiveTask(config, ctx, helpers) {
|
|
|
12378
12509
|
signal: abortController.signal,
|
|
12379
12510
|
fallbackModels: config.fallbackModels,
|
|
12380
12511
|
callContext: "dreamer:retrospective",
|
|
12512
|
+
...hiddenHandle && deps.hiddenCompletionExecutor ? {
|
|
12513
|
+
transport: Object.assign((request) => deps.hiddenCompletionExecutor?.attempt(hiddenHandle, request) ?? Promise.reject(new Error("Hidden transport unavailable")), { childSessionId: hiddenHandle.childSessionId })
|
|
12514
|
+
} : {},
|
|
12381
12515
|
fetchOutput: async () => {
|
|
12516
|
+
if (hiddenHandle && deps.hiddenCompletionExecutor) {
|
|
12517
|
+
return deps.hiddenCompletionExecutor.collect(hiddenHandle, 50);
|
|
12518
|
+
}
|
|
12382
12519
|
const messagesResponse = await requireDreamClient(deps.client).session.messages({
|
|
12383
12520
|
path: { id: sessionId },
|
|
12384
12521
|
query: { directory: deps.sessionDirectory, limit: 50 }
|
|
@@ -12388,14 +12525,15 @@ async function runRetrospectiveTask(config, ctx, helpers) {
|
|
|
12388
12525
|
});
|
|
12389
12526
|
},
|
|
12390
12527
|
validateOutput: (outputMessages) => {
|
|
12391
|
-
const text = extractLatestAssistantText(outputMessages);
|
|
12528
|
+
const text = hiddenHandle ? outputMessages.text : extractLatestAssistantText(outputMessages);
|
|
12392
12529
|
if (!text)
|
|
12393
12530
|
throw new Error("Retrospective child returned no output.");
|
|
12394
12531
|
return text;
|
|
12395
12532
|
}
|
|
12396
12533
|
});
|
|
12397
12534
|
promptSettled = true;
|
|
12398
|
-
|
|
12535
|
+
const output = hiddenHandle ? run.output.messages ?? [] : run.output;
|
|
12536
|
+
return { ...run, output };
|
|
12399
12537
|
};
|
|
12400
12538
|
const finish = (run, watermark) => {
|
|
12401
12539
|
if (parent && run) {
|
|
@@ -12525,15 +12663,23 @@ async function runRetrospectiveTask(config, ctx, helpers) {
|
|
|
12525
12663
|
});
|
|
12526
12664
|
} finally {
|
|
12527
12665
|
heartbeat.stop();
|
|
12528
|
-
|
|
12529
|
-
|
|
12530
|
-
|
|
12531
|
-
|
|
12532
|
-
|
|
12533
|
-
|
|
12534
|
-
|
|
12535
|
-
|
|
12536
|
-
|
|
12666
|
+
if (hiddenHandle && deps.hiddenCompletionExecutor) {
|
|
12667
|
+
await deps.hiddenCompletionExecutor.close(hiddenHandle, {
|
|
12668
|
+
promptSettled,
|
|
12669
|
+
privacySensitive: true,
|
|
12670
|
+
context: "[dreamer] retrospective",
|
|
12671
|
+
log
|
|
12672
|
+
});
|
|
12673
|
+
} else
|
|
12674
|
+
await teardownChildSession({
|
|
12675
|
+
client: requireDreamClient(deps.client),
|
|
12676
|
+
sessionId: childSessionId,
|
|
12677
|
+
sessionDirectory: deps.sessionDirectory,
|
|
12678
|
+
promptSettled,
|
|
12679
|
+
privacySensitive: true,
|
|
12680
|
+
context: "[dreamer] retrospective",
|
|
12681
|
+
log
|
|
12682
|
+
});
|
|
12537
12683
|
}
|
|
12538
12684
|
}
|
|
12539
12685
|
async function runAgenticTask(config, ctx, helpers) {
|
|
@@ -12607,72 +12753,107 @@ async function runAgenticTask(config, ctx, helpers) {
|
|
|
12607
12753
|
docsCurrentTokens: maintainDocsSnapshot ? Math.ceil([...maintainDocsSnapshot.values()].join("").length / 3.5) : 0,
|
|
12608
12754
|
curate: curateMemories && curateCategory ? { category: curateCategory, memories: curateMemories } : undefined
|
|
12609
12755
|
});
|
|
12610
|
-
|
|
12611
|
-
|
|
12612
|
-
|
|
12613
|
-
|
|
12614
|
-
|
|
12615
|
-
|
|
12616
|
-
});
|
|
12617
|
-
const created = normalizeSDKResponse(createResponse, null, {
|
|
12618
|
-
preferResponseOnMissingData: true
|
|
12619
|
-
});
|
|
12620
|
-
childSessionId = typeof created?.id === "string" ? created.id : null;
|
|
12621
|
-
if (!childSessionId)
|
|
12622
|
-
throw new Error("Dreamer could not create its child session.");
|
|
12623
|
-
const sessionId = childSessionId;
|
|
12624
|
-
const remainingMs = Math.max(0, deadline - Date.now());
|
|
12625
|
-
const run = await promptSyncWithValidatedOutputRetry(requireDreamClient(deps.client), {
|
|
12626
|
-
path: { id: sessionId },
|
|
12627
|
-
query: { directory: docsDir },
|
|
12628
|
-
body: {
|
|
12756
|
+
let run;
|
|
12757
|
+
if (deps.hiddenCompletionExecutor) {
|
|
12758
|
+
const hidden = await runHiddenSingleShotPrompt({
|
|
12759
|
+
executor: deps.hiddenCompletionExecutor,
|
|
12760
|
+
parentSessionId: parent ?? undefined,
|
|
12761
|
+
sessionDirectory: docsDir,
|
|
12629
12762
|
agent: task === "maintain-docs" ? DREAMER_DOCS_AGENT : DREAMER_AGENT,
|
|
12630
|
-
system: task === "maintain-docs" ? MAINTAIN_DOCS_SYSTEM_PROMPT :
|
|
12631
|
-
|
|
12632
|
-
|
|
12633
|
-
|
|
12634
|
-
|
|
12635
|
-
|
|
12636
|
-
|
|
12637
|
-
|
|
12638
|
-
|
|
12639
|
-
|
|
12640
|
-
|
|
12641
|
-
|
|
12642
|
-
|
|
12643
|
-
|
|
12644
|
-
|
|
12763
|
+
system: task === "maintain-docs" ? MAINTAIN_DOCS_SYSTEM_PROMPT : CURATE_SYSTEM_PROMPT,
|
|
12764
|
+
prompt: taskPrompt,
|
|
12765
|
+
title: `magic-context-dream-${task}`,
|
|
12766
|
+
callContext: `dreamer:${task}`,
|
|
12767
|
+
allowEmpty: task === "curate",
|
|
12768
|
+
model: config.model,
|
|
12769
|
+
fallbackModels: config.fallbackModels,
|
|
12770
|
+
language: task === "curate" ? config.language ?? deps.language : undefined,
|
|
12771
|
+
timeoutMs: Math.min(Math.max(0, deadline - Date.now()), config.timeoutMinutes * 60 * 1000),
|
|
12772
|
+
signal: abortController.signal,
|
|
12773
|
+
parse: (text, completion) => {
|
|
12774
|
+
if (task !== "curate")
|
|
12775
|
+
return text;
|
|
12776
|
+
const memoryOperations = inspectCurateMemoryOperations(completion.messages);
|
|
12777
|
+
if (text)
|
|
12778
|
+
validateCurateAssistantText(text);
|
|
12779
|
+
if (memoryOperations.totalCalls > 0 && memoryOperations.completedActions.length === 0)
|
|
12780
|
+
throw new Error("Curate returned no completed ctx_memory tool result.");
|
|
12781
|
+
if (!text && memoryOperations.completedActions.length === 0)
|
|
12782
|
+
throw new Error("Dreamer returned no assistant output.");
|
|
12783
|
+
return { text: text || null, memoryOperations };
|
|
12784
|
+
}
|
|
12785
|
+
});
|
|
12786
|
+
childSessionId = hidden.childSessionId;
|
|
12787
|
+
run = { output: hidden.completion.messages ?? [], validated: hidden.validated };
|
|
12788
|
+
promptSettled = true;
|
|
12789
|
+
} else {
|
|
12790
|
+
const createResponse = await createChildSessionWithFence({
|
|
12791
|
+
client: requireDreamClient(deps.client),
|
|
12792
|
+
db,
|
|
12793
|
+
parentSessionId: parent ?? undefined,
|
|
12794
|
+
title: `magic-context-dream-${task}`,
|
|
12795
|
+
directory: docsDir
|
|
12796
|
+
});
|
|
12797
|
+
const created = normalizeSDKResponse(createResponse, null, {
|
|
12798
|
+
preferResponseOnMissingData: true
|
|
12799
|
+
});
|
|
12800
|
+
childSessionId = typeof created?.id === "string" ? created.id : null;
|
|
12801
|
+
if (!childSessionId)
|
|
12802
|
+
throw new Error("Dreamer could not create its child session.");
|
|
12803
|
+
const sessionId = childSessionId;
|
|
12804
|
+
const remainingMs = Math.max(0, deadline - Date.now());
|
|
12805
|
+
run = await promptSyncWithValidatedOutputRetry(requireDreamClient(deps.client), {
|
|
12806
|
+
path: { id: sessionId },
|
|
12807
|
+
query: { directory: docsDir },
|
|
12808
|
+
body: {
|
|
12809
|
+
agent: task === "maintain-docs" ? DREAMER_DOCS_AGENT : DREAMER_AGENT,
|
|
12810
|
+
system: task === "maintain-docs" ? MAINTAIN_DOCS_SYSTEM_PROMPT : withContentLanguageDirective(CURATE_SYSTEM_PROMPT, config.language ?? deps.language),
|
|
12811
|
+
...modelBodyField(config.model),
|
|
12812
|
+
parts: [{ type: "text", text: taskPrompt, synthetic: true }]
|
|
12813
|
+
}
|
|
12814
|
+
}, {
|
|
12815
|
+
timeoutMs: Math.min(remainingMs, config.timeoutMinutes * 60 * 1000),
|
|
12816
|
+
signal: abortController.signal,
|
|
12817
|
+
fallbackModels: config.fallbackModels,
|
|
12818
|
+
callContext: `dreamer:${task}`,
|
|
12819
|
+
fetchOutput: async () => {
|
|
12820
|
+
const messagesResponse = await requireDreamClient(deps.client).session.messages({
|
|
12821
|
+
path: { id: sessionId },
|
|
12822
|
+
query: {
|
|
12823
|
+
directory: docsDir,
|
|
12824
|
+
...task === "curate" ? {} : { limit: 50 }
|
|
12825
|
+
}
|
|
12826
|
+
});
|
|
12827
|
+
return normalizeSDKResponse(messagesResponse, [], {
|
|
12828
|
+
preferResponseOnMissingData: true
|
|
12829
|
+
});
|
|
12830
|
+
},
|
|
12831
|
+
validateOutput: (messages) => {
|
|
12832
|
+
const text = extractLatestAssistantText(messages);
|
|
12833
|
+
if (task !== "curate") {
|
|
12834
|
+
if (!text)
|
|
12835
|
+
throw new Error("Dreamer returned no assistant output.");
|
|
12836
|
+
return text;
|
|
12837
|
+
}
|
|
12838
|
+
const memoryOperations = inspectCurateMemoryOperations(messages);
|
|
12839
|
+
if (text)
|
|
12840
|
+
validateCurateAssistantText(text);
|
|
12841
|
+
if (memoryOperations.completedActions.length > 0) {
|
|
12842
|
+
return { text, memoryOperations };
|
|
12645
12843
|
}
|
|
12646
|
-
});
|
|
12647
|
-
return normalizeSDKResponse(messagesResponse, [], {
|
|
12648
|
-
preferResponseOnMissingData: true
|
|
12649
|
-
});
|
|
12650
|
-
},
|
|
12651
|
-
validateOutput: (messages) => {
|
|
12652
|
-
const text = extractLatestAssistantText(messages);
|
|
12653
|
-
if (task !== "curate") {
|
|
12654
12844
|
if (!text)
|
|
12655
12845
|
throw new Error("Dreamer returned no assistant output.");
|
|
12656
|
-
|
|
12657
|
-
|
|
12658
|
-
|
|
12659
|
-
if (text)
|
|
12660
|
-
validateCurateAssistantText(text);
|
|
12661
|
-
if (memoryOperations.completedActions.length > 0) {
|
|
12846
|
+
if (memoryOperations.totalCalls > 0) {
|
|
12847
|
+
throw new Error("Curate returned no completed ctx_memory tool result.");
|
|
12848
|
+
}
|
|
12662
12849
|
return { text, memoryOperations };
|
|
12663
12850
|
}
|
|
12664
|
-
|
|
12665
|
-
|
|
12666
|
-
|
|
12667
|
-
throw new Error("Curate returned no completed ctx_memory tool result.");
|
|
12668
|
-
}
|
|
12669
|
-
return { text, memoryOperations };
|
|
12670
|
-
}
|
|
12671
|
-
});
|
|
12672
|
-
promptSettled = true;
|
|
12851
|
+
});
|
|
12852
|
+
promptSettled = true;
|
|
12853
|
+
}
|
|
12673
12854
|
if (leaseLost)
|
|
12674
12855
|
throw new Error("Dream lease lost during task");
|
|
12675
|
-
const curateRefused = task === "curate" ? takeCurateSafetyRefusalCount(
|
|
12856
|
+
const curateRefused = task === "curate" ? takeCurateSafetyRefusalCount(childSessionId ?? "") : 0;
|
|
12676
12857
|
if (curateRefused > 0) {
|
|
12677
12858
|
helpers.reportProgress(curateRefused, curateRefused);
|
|
12678
12859
|
log(`[dreamer] curate safety summary: refused=${curateRefused}`);
|
|
@@ -12742,15 +12923,16 @@ async function runAgenticTask(config, ctx, helpers) {
|
|
|
12742
12923
|
heartbeat.stop();
|
|
12743
12924
|
if (childSessionId)
|
|
12744
12925
|
takeCurateSafetyRefusalCount(childSessionId);
|
|
12745
|
-
|
|
12746
|
-
|
|
12747
|
-
|
|
12748
|
-
|
|
12749
|
-
|
|
12750
|
-
|
|
12751
|
-
|
|
12752
|
-
|
|
12753
|
-
|
|
12926
|
+
if (!deps.hiddenCompletionExecutor)
|
|
12927
|
+
await teardownChildSession({
|
|
12928
|
+
client: requireDreamClient(deps.client),
|
|
12929
|
+
sessionId: childSessionId,
|
|
12930
|
+
sessionDirectory: docsDir,
|
|
12931
|
+
promptSettled,
|
|
12932
|
+
privacySensitive: true,
|
|
12933
|
+
context: `[dreamer] ${task}`,
|
|
12934
|
+
log
|
|
12935
|
+
});
|
|
12754
12936
|
}
|
|
12755
12937
|
}
|
|
12756
12938
|
|
|
@@ -18328,7 +18510,7 @@ function getUnsummarizedTailInfo(db, sessionId, triggerBudget, usage, executeThr
|
|
|
18328
18510
|
function formatProjectedPostDropPercentage(value) {
|
|
18329
18511
|
return value === null ? "none" : `${value.toFixed(1)}%`;
|
|
18330
18512
|
}
|
|
18331
|
-
function checkCompartmentTrigger(db, sessionId, sessionMeta, usage, _previousPercentage, executeThresholdPercentage, triggerBudget, clearReasoningAge, commitClusterTrigger, preloadedActiveTags, contextLimit, inMemoryTail, taggerFloorOverride, reasoningProjection) {
|
|
18513
|
+
function checkCompartmentTrigger(db, sessionId, sessionMeta, usage, _previousPercentage, executeThresholdPercentage, triggerBudget, clearReasoningAge, commitClusterTrigger, preloadedActiveTags, contextLimit, inMemoryTail, taggerFloorOverride, reasoningProjection, reclaimRide) {
|
|
18332
18514
|
if (sessionMeta.compartmentInProgress) {
|
|
18333
18515
|
sessionLog(sessionId, `compartment trigger: skipped — historian already in progress (usage=${usage.percentage.toFixed(1)}%)`);
|
|
18334
18516
|
return { shouldFire: false };
|
|
@@ -18386,10 +18568,12 @@ function checkCompartmentTrigger(db, sessionId, sessionMeta, usage, _previousPer
|
|
|
18386
18568
|
const canClearReasoning = reasoningProjection?.canClearReasoning ?? modelAcceptsEmptyContent(reasoningProjection?.providerID);
|
|
18387
18569
|
const projectedPostDropPercentage = estimateProjectedPostDropPercentage(db, sessionId, usage, preloadedActiveTags ?? getActiveTagsBySession(db, sessionId), clearReasoningAge, sessionMeta.clearedReasoningThroughTag, canClearReasoning);
|
|
18388
18570
|
const relativePostDropTarget = executeThresholdPercentage * POST_DROP_TARGET_RATIO;
|
|
18571
|
+
const rideLabel = reclaimRide ? reclaimRideLabel(reclaimRide) : "ride=none";
|
|
18572
|
+
const dropsCanLand = reclaimRide !== undefined && hasReclaimRide(reclaimRide);
|
|
18389
18573
|
const forceMaterializationPercentage = escalationBands(executeThresholdPercentage).forceMaterializationPercentage;
|
|
18390
18574
|
if (usage.percentage >= forceMaterializationPercentage) {
|
|
18391
|
-
if (projectedPostDropPercentage !== null && projectedPostDropPercentage <= relativePostDropTarget) {
|
|
18392
|
-
sessionLog(sessionId, `historian redundancy skip: summarizer not needed this pass — force band is ${forceMaterializationPercentage}%; queued/automatic drops are projected to reclaim to ${projectedPostDropPercentage.toFixed(1)}% (target ${relativePostDropTarget.toFixed(1)}%) on
|
|
18575
|
+
if (dropsCanLand && projectedPostDropPercentage !== null && projectedPostDropPercentage <= relativePostDropTarget) {
|
|
18576
|
+
sessionLog(sessionId, `historian redundancy skip: summarizer not needed this pass — force band is ${forceMaterializationPercentage}%; queued/automatic drops are projected to reclaim to ${projectedPostDropPercentage.toFixed(1)}% (target ${relativePostDropTarget.toFixed(1)}%) on this pass (${rideLabel})`);
|
|
18393
18577
|
return { shouldFire: false };
|
|
18394
18578
|
}
|
|
18395
18579
|
sessionLog(sessionId, `compartment trigger: force-firing at ${usage.percentage.toFixed(1)}% (projected post-drop ${formatProjectedPostDropPercentage(projectedPostDropPercentage)})`);
|
|
@@ -18449,8 +18633,8 @@ function checkCompartmentTrigger(db, sessionId, sessionMeta, usage, _previousPer
|
|
|
18449
18633
|
sessionLog(sessionId, `compartment trigger: not firing at ${usage.percentage.toFixed(1)}% — below proactive floor (${proactiveTriggerPercentage}%)`);
|
|
18450
18634
|
return { shouldFire: false };
|
|
18451
18635
|
}
|
|
18452
|
-
if (projectedPostDropPercentage !== null && projectedPostDropPercentage <= relativePostDropTarget) {
|
|
18453
|
-
sessionLog(sessionId, `historian redundancy skip: summarizer not needed this pass — usage is ${usage.percentage.toFixed(1)}%; queued/automatic drops are projected to reclaim to ${projectedPostDropPercentage.toFixed(1)}% (target ${relativePostDropTarget.toFixed(1)}%) on
|
|
18636
|
+
if (dropsCanLand && projectedPostDropPercentage !== null && projectedPostDropPercentage <= relativePostDropTarget) {
|
|
18637
|
+
sessionLog(sessionId, `historian redundancy skip: summarizer not needed this pass — usage is ${usage.percentage.toFixed(1)}%; queued/automatic drops are projected to reclaim to ${projectedPostDropPercentage.toFixed(1)}% (target ${relativePostDropTarget.toFixed(1)}%) on this pass (${rideLabel})`);
|
|
18454
18638
|
return { shouldFire: false };
|
|
18455
18639
|
}
|
|
18456
18640
|
if (!tailInfo.hasProtectedEligibleHead || !tailInfo.isMeaningful) {
|
|
@@ -29862,7 +30046,8 @@ function registerPiContextHandler(pi, baseOptions) {
|
|
|
29862
30046
|
sessionMeta,
|
|
29863
30047
|
piUsage,
|
|
29864
30048
|
minimumPercentage: usagePercentage,
|
|
29865
|
-
historianStateSnapshot: historianStateForPass
|
|
30049
|
+
historianStateSnapshot: historianStateForPass,
|
|
30050
|
+
publishedHistoryRide: isCacheBusting
|
|
29866
30051
|
});
|
|
29867
30052
|
}
|
|
29868
30053
|
logTransformTiming(sessionId, "historianScheduling", tHistorianScheduling);
|
|
@@ -30502,7 +30687,12 @@ Historian previously failed ${failureCount} time(s), so Magic Context is retryin
|
|
|
30502
30687
|
const trigger = checkCompartmentTrigger(db, sessionId, sessionMeta, usage, 0, triggerInputs.executeThresholdPercentage, triggerInputs.triggerBudget, triggerInputs.clearReasoningAge, triggerInputs.commitClusterTrigger, args.activeTags, boundaryContextLimit, () => {
|
|
30503
30688
|
const messages = provider.readMessages();
|
|
30504
30689
|
return { messages, absoluteMessageCount: messages.length };
|
|
30505
|
-
}, args.taggerFloor, { canClearReasoning: true }
|
|
30690
|
+
}, args.taggerFloor, { canClearReasoning: true }, {
|
|
30691
|
+
hardFold: false,
|
|
30692
|
+
force: usage.percentage >= historianForceMaterializationPercentage && (usage.percentage >= 95 || getEmergencyInputSample(db, sessionId) === 0),
|
|
30693
|
+
explicitFlush: hasPendingMaterialization(sessionId),
|
|
30694
|
+
publishedHistory: args.publishedHistoryRide
|
|
30695
|
+
});
|
|
30506
30696
|
if (!trigger.shouldFire) {
|
|
30507
30697
|
sessionLog(sessionId, `historian trigger eval: shouldFire=false (no trigger condition met)`);
|
|
30508
30698
|
try {
|
|
@@ -33873,7 +34063,7 @@ function buildStatusView(source, options) {
|
|
|
33873
34063
|
// package.json
|
|
33874
34064
|
var package_default = {
|
|
33875
34065
|
name: "@cortexkit/pi-magic-context",
|
|
33876
|
-
version: "0.43.
|
|
34066
|
+
version: "0.43.1",
|
|
33877
34067
|
type: "module",
|
|
33878
34068
|
description: "Pi and OMP coding agent extension for Magic Context — cross-session memory and context management",
|
|
33879
34069
|
main: "dist/index.js",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import"./index-
|
|
1
|
+
import"./index-bfd52y8p.js";
|
|
2
2
|
import {
|
|
3
3
|
logSlowWriteTransaction
|
|
4
|
-
} from "./index-
|
|
4
|
+
} from "./index-17102c1m.js";
|
|
5
5
|
|
|
6
6
|
// ../plugin/src/features/magic-context/message-time-backfill.ts
|
|
7
7
|
var MESSAGE_TIME_BACKFILL_BATCH_SIZE = 500;
|
|
@@ -20,8 +20,8 @@ import {
|
|
|
20
20
|
getRawSessionTagKeysThrough2,
|
|
21
21
|
getLegacyProtectedTailStartOrdinal2,
|
|
22
22
|
readSessionChunk2
|
|
23
|
-
} from "./index-
|
|
24
|
-
import"./index-
|
|
23
|
+
} from "./index-822b3fcs.js";
|
|
24
|
+
import"./index-bfd52y8p.js";
|
|
25
25
|
export {
|
|
26
26
|
cleanUserText2 as cleanUserText,
|
|
27
27
|
extractTexts2 as extractTexts,
|
package/dist/subagent-entry.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
setHarness,
|
|
3
3
|
log
|
|
4
|
-
} from "./index-
|
|
4
|
+
} from "./index-bfd52y8p.js";
|
|
5
5
|
import {
|
|
6
6
|
setStoragePrivatePermissionEnforcement,
|
|
7
7
|
resolveProjectIdentityForSession,
|
|
@@ -10,9 +10,9 @@ import {
|
|
|
10
10
|
ensureProjectRegisteredFromPiDirectory,
|
|
11
11
|
resolvePiHarnessKind,
|
|
12
12
|
registerMagicContextTools
|
|
13
|
-
} from "./index-
|
|
14
|
-
import"./index-
|
|
15
|
-
import"./index-
|
|
13
|
+
} from "./index-kyrajahw.js";
|
|
14
|
+
import"./index-822b3fcs.js";
|
|
15
|
+
import"./index-17102c1m.js";
|
|
16
16
|
|
|
17
17
|
// src/subagent-entry.ts
|
|
18
18
|
var SUBAGENT_DREAMER_ACTIONS_FLAG = "magic-context-dreamer-actions";
|
package/package.json
CHANGED