@cortexkit/opencode-magic-context 0.46.0 → 0.47.0
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/auto-search-worker.js +115 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/live-run-config.d.ts.map +1 -1
- package/dist/config/migrate-config-location.d.ts.map +1 -1
- package/dist/config/schema/magic-context.d.ts +15 -7
- package/dist/config/schema/magic-context.d.ts.map +1 -1
- package/dist/{conflict-warning-hook-7fj2b9jw.js → conflict-warning-hook-z44ynfz7.js} +5 -4
- package/dist/{context-8dkpszy5.js → context-wq4ffwyb.js} +164 -37
- package/dist/{derive-budgets-7nj7r1rv.js → derive-budgets-ke12jnnh.js} +1 -1
- package/dist/embedding-worker.js +2 -2
- package/dist/features/magic-context/compaction-marker.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-gates.d.ts.map +1 -1
- package/dist/features/magic-context/overflow-detection.d.ts +2 -0
- package/dist/features/magic-context/overflow-detection.d.ts.map +1 -1
- package/dist/features/magic-context/project-embedding-registry.d.ts +7 -0
- package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
- package/dist/features/magic-context/search.d.ts +2 -0
- package/dist/features/magic-context/search.d.ts.map +1 -1
- package/dist/features/magic-context/session-project-storage.d.ts +8 -2
- package/dist/features/magic-context/session-project-storage.d.ts.map +1 -1
- package/dist/features/magic-context/storage-historian-runs.d.ts +2 -5
- package/dist/features/magic-context/storage-historian-runs.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-persisted.d.ts +12 -0
- package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-session.d.ts.map +1 -1
- package/dist/features/magic-context/storage-tags.d.ts +7 -2
- package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
- package/dist/features/magic-context/storage.d.ts +1 -0
- package/dist/features/magic-context/storage.d.ts.map +1 -1
- package/dist/features/magic-context/transform-decision-log.d.ts +3 -1
- package/dist/features/magic-context/transform-decision-log.d.ts.map +1 -1
- package/dist/hooks/magic-context/active-anthropic-turn.d.ts +8 -0
- package/dist/hooks/magic-context/active-anthropic-turn.d.ts.map +1 -0
- package/dist/hooks/magic-context/apply-operations.d.ts.map +1 -1
- package/dist/hooks/magic-context/auto-search-blocking.fixture.d.ts +2 -0
- package/dist/hooks/magic-context/auto-search-blocking.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/auto-search-deadline.d.ts +7 -0
- package/dist/hooks/magic-context/auto-search-deadline.d.ts.map +1 -1
- package/dist/hooks/magic-context/auto-search-host-review.fixture.d.ts +3 -0
- package/dist/hooks/magic-context/auto-search-host-review.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/auto-search-lock-review.fixture.d.ts +2 -0
- package/dist/hooks/magic-context/auto-search-lock-review.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/auto-search-long-lock-review.fixture.d.ts +2 -0
- package/dist/hooks/magic-context/auto-search-long-lock-review.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/auto-search-omp-host-review.fixture.d.ts +4 -0
- package/dist/hooks/magic-context/auto-search-omp-host-review.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/auto-search-omp-loader.fixture.d.ts +3 -0
- package/dist/hooks/magic-context/auto-search-omp-loader.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/auto-search-runner.d.ts +1 -1
- package/dist/hooks/magic-context/auto-search-runner.d.ts.map +1 -1
- package/dist/hooks/magic-context/auto-search-snapshot.fixture.d.ts +4 -0
- package/dist/hooks/magic-context/auto-search-snapshot.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/auto-search-worker-client.d.ts +69 -0
- package/dist/hooks/magic-context/auto-search-worker-client.d.ts.map +1 -0
- package/dist/hooks/magic-context/auto-search-worker.d.ts +2 -0
- package/dist/hooks/magic-context/auto-search-worker.d.ts.map +1 -0
- package/dist/hooks/magic-context/caveman-cleanup.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-types.d.ts +3 -5
- package/dist/hooks/magic-context/compartment-runner-types.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner.d.ts +2 -1
- package/dist/hooks/magic-context/compartment-runner.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-trigger.d.ts +3 -1
- package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -1
- package/dist/hooks/magic-context/event-handler.d.ts +1 -1
- package/dist/hooks/magic-context/event-handler.d.ts.map +1 -1
- package/dist/hooks/magic-context/event-resolvers.d.ts.map +1 -1
- package/dist/hooks/magic-context/execute-status.d.ts.map +1 -1
- package/dist/hooks/magic-context/final-wire-token-estimate.d.ts +2 -0
- package/dist/hooks/magic-context/final-wire-token-estimate.d.ts.map +1 -1
- package/dist/hooks/magic-context/heuristic-cleanup.d.ts.map +1 -1
- package/dist/hooks/magic-context/historian-drain-gate.d.ts +11 -0
- package/dist/hooks/magic-context/historian-drain-gate.d.ts.map +1 -0
- package/dist/hooks/magic-context/hook.d.ts +2 -1
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/latest-assistant-turn.d.ts +25 -0
- package/dist/hooks/magic-context/latest-assistant-turn.d.ts.map +1 -0
- package/dist/hooks/magic-context/latest-thinking-recovery.d.ts +61 -0
- package/dist/hooks/magic-context/latest-thinking-recovery.d.ts.map +1 -0
- package/dist/hooks/magic-context/module-wire.d.ts.map +1 -1
- package/dist/hooks/magic-context/opencode-proven-floor.d.ts +6 -0
- package/dist/hooks/magic-context/opencode-proven-floor.d.ts.map +1 -0
- package/dist/hooks/magic-context/pass-outcome.d.ts.map +1 -1
- package/dist/hooks/magic-context/protected-tail-boundary.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-true-raw-tokens.d.ts.map +1 -1
- package/dist/hooks/magic-context/reasoning-budget-status.d.ts +15 -0
- package/dist/hooks/magic-context/reasoning-budget-status.d.ts.map +1 -0
- package/dist/hooks/magic-context/reasoning-budget.d.ts +40 -0
- package/dist/hooks/magic-context/reasoning-budget.d.ts.map +1 -0
- package/dist/hooks/magic-context/reasoning-removal.d.ts +6 -6
- package/dist/hooks/magic-context/reasoning-removal.d.ts.map +1 -1
- package/dist/hooks/magic-context/rust-mode-transform.d.ts.map +1 -1
- package/dist/hooks/magic-context/sentinel.d.ts +4 -0
- package/dist/hooks/magic-context/sentinel.d.ts.map +1 -1
- package/dist/hooks/magic-context/strip-content.d.ts +7 -3
- package/dist/hooks/magic-context/strip-content.d.ts.map +1 -1
- package/dist/hooks/magic-context/tag-messages.d.ts +13 -0
- package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
- package/dist/hooks/magic-context/tool-drop-target.d.ts +5 -0
- package/dist/hooks/magic-context/tool-drop-target.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts +3 -28
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +28 -6
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts +3 -1
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/{index-0d3g3461.js → index-0c82743p.js} +2 -1
- package/dist/{index-e2dtv0ra.js → index-5a2r0p9f.js} +3 -3
- package/dist/{index-p821bjdb.js → index-6d9e1m08.js} +4726 -11050
- package/dist/{index-majxda46.js → index-6wkcswft.js} +1 -1
- package/dist/index-92bp57hg.js +2063 -0
- package/dist/{index-sfnj6h8h.js → index-9pk9exrb.js} +3 -3
- package/dist/{index-7qw742ev.js → index-adwfkpex.js} +5 -24
- package/dist/{index-3h0ybwah.js → index-bb36vgr3.js} +80 -12
- package/dist/{index-k4404na5.js → index-cwf6s3ay.js} +1072 -2422
- package/dist/index-fnn5pjtt.js +6554 -0
- package/dist/{index-j7fvnjye.js → index-gg8j07zz.js} +1 -1
- package/dist/{index-yasgb8ej.js → index-m5fe6jch.js} +9 -3
- package/dist/{v2/server-g0fjrkta.js → index-rrbbspwh.js} +42 -27
- package/dist/index-rrrsepyw.js +3464 -0
- package/dist/{index-qr6r7akd.js → index-w2t4ah5j.js} +950 -502
- package/dist/{v2/server-fg34g6a5.js → index-wx8a6bw3.js} +48 -8
- package/dist/{index-r5hmbx3t.js → index-x3kwrmqk.js} +146 -3571
- package/dist/index-yr3zj7e7.js +23 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +624 -65
- package/dist/{message-time-backfill-68gj6t3e.js → message-time-backfill-r5epkzj3.js} +1 -1
- package/dist/migration-worker.js +7 -5
- package/dist/plugin/dream-timer.d.ts.map +1 -1
- package/dist/plugin/hooks/create-session-hooks.d.ts +2 -1
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/plugin/host-stall-profiler-report.d.ts +67 -0
- package/dist/plugin/host-stall-profiler-report.d.ts.map +1 -0
- package/dist/plugin/host-stall-profiler.d.ts +96 -0
- package/dist/plugin/host-stall-profiler.d.ts.map +1 -0
- package/dist/plugin/messages-transform.d.ts +21 -6
- package/dist/plugin/messages-transform.d.ts.map +1 -1
- package/dist/{read-session-chunk-egz7r68d.js → read-session-chunk-4jey7hpt.js} +4 -4
- package/dist/{recomp-orchestrator-ejq7ex5d.js → recomp-orchestrator-rervg6q4.js} +13 -10
- package/dist/{send-session-notification-dyw42dtr.js → send-session-notification-0m68ms3n.js} +4 -3
- package/dist/shared/auto-search-lifecycle.d.ts +7 -0
- package/dist/shared/auto-search-lifecycle.d.ts.map +1 -0
- package/dist/shared/historian-tool-expansions.d.ts +1 -1
- package/dist/shared/historian-tool-expansions.d.ts.map +1 -1
- package/dist/shared/historian-tool-template.d.ts +2 -2
- package/dist/shared/historian-tool-template.d.ts.map +1 -1
- package/dist/shared/sqlite.d.ts +16 -1
- package/dist/shared/sqlite.d.ts.map +1 -1
- package/dist/shared/status-view.d.ts.map +1 -1
- package/dist/shared/window-geometry.d.ts +4 -0
- package/dist/shared/window-geometry.d.ts.map +1 -1
- package/dist/tools/ctx-expand/render.d.ts.map +1 -1
- package/dist/{transform-postprocess-phase-tz3pat2p.js → transform-postprocess-phase-z5hzpsxv.js} +13 -10
- package/dist/v2/auto-search-worker.js +115 -0
- package/dist/v2/{context-8vgtb6sz.js → context-14v1hr8b.js} +4918 -5760
- package/dist/v2/{derive-budgets-kdgp4s3r.js → derive-budgets-nc9avxz8.js} +2 -2
- package/dist/v2/embedding-worker.js +3 -3
- package/dist/v2/hidden-child-native.d.ts +7 -0
- package/dist/v2/hidden-child-native.d.ts.map +1 -1
- package/dist/v2/hidden-child-record.d.ts +8 -0
- package/dist/v2/hidden-child-record.d.ts.map +1 -1
- package/dist/v2/hidden-completion.d.ts.map +1 -1
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/hooks/dream-trigger.d.ts +15 -1
- package/dist/v2/hooks/dream-trigger.d.ts.map +1 -1
- package/dist/v2/hooks/hidden-child.d.ts +54 -3
- package/dist/v2/hooks/hidden-child.d.ts.map +1 -1
- package/dist/v2/hooks/types.d.ts +12 -1
- package/dist/v2/hooks/types.d.ts.map +1 -1
- package/dist/v2/{message-time-backfill-r6qkem1x.js → message-time-backfill-1f9tzvcs.js} +1 -1
- package/dist/v2/migration-worker.js +7 -5
- package/dist/v2/{read-session-chunk-8vjp6581.js → read-session-chunk-gyyv7w2r.js} +4 -4
- package/dist/v2/{recomp-orchestrator-5xj0yzyk.js → recomp-orchestrator-42vjba7p.js} +17 -14
- package/dist/v2/{send-session-notification-qs0j78v6.js → send-session-notification-c0wtscea.js} +5 -4
- package/dist/v2/server-3trjk1hx.js +6360 -0
- package/dist/v2/{server-xtp687da.js → server-50hvkg3v.js} +9 -3
- package/dist/v2/{server-y8maxeft.js → server-cpepxy2q.js} +2 -1
- package/dist/v2/server-d0sraw7m.js +3403 -0
- package/dist/v2/server-e0c1b7a7.js +2063 -0
- package/dist/v2/{server-mcfawjgc.js → server-efhwzx05.js} +5 -24
- package/dist/v2/{server-3n4q9xme.js → server-fcdehk1s.js} +1 -1
- package/dist/{index-q4yp4b52.js → v2/server-fq7kq32k.js} +42 -27
- package/dist/v2/{server-vnh7r35f.js → server-nf82q6pt.js} +2459 -8603
- package/dist/v2/{server-frbm99q5.js → server-njt3np1k.js} +99 -3465
- package/dist/v2/{server-qp5hx1ad.js → server-nm9n3aqq.js} +107 -12
- package/dist/v2/{server-p2en78c8.js → server-rz514f14.js} +7 -2
- package/dist/v2/{server-wvjvfhck.js → server-vd4e7174.js} +1 -1
- package/dist/{index-fg34g6a5.js → v2/server-wx8a6bw3.js} +48 -8
- package/dist/v2/{server-4663ejam.js → server-y10vbq6y.js} +1 -1
- package/dist/v2/server-yr3zj7e7.js +23 -0
- package/dist/v2/server.js +5 -5
- package/dist/v2/{wrapup-orchestrator-r5t1pyj8.js → wrapup-orchestrator-nbz854vc.js} +16 -13
- package/dist/wrapup-orchestrator-b2dztrar.js +29 -0
- package/package.json +6 -5
- package/src/config/index.ts +6 -0
- package/src/config/live-run-config.test.ts +37 -1
- package/src/config/live-run-config.ts +28 -0
- package/src/config/migrate-config-location.ts +10 -3
- package/src/config/schema/magic-context.test.ts +4 -3
- package/src/config/schema/magic-context.ts +23 -6
- package/src/shared/auto-search-lifecycle.ts +27 -0
- package/src/shared/historian-tool-defaults.json +6 -6
- package/src/shared/historian-tool-expansions.ts +65 -8
- package/src/shared/historian-tool-preview-defaults.json +13 -0
- package/src/shared/historian-tool-template.ts +48 -14
- package/src/shared/sqlite-640-review-r2.test.ts +136 -0
- package/src/shared/sqlite-640-review.test.ts +183 -0
- package/src/shared/sqlite-acquisition-routing.test.ts +18 -0
- package/src/shared/sqlite.ts +84 -14
- package/src/shared/status-view.test.ts +6 -1
- package/src/shared/status-view.ts +15 -1
- package/src/shared/tag-transcript.ts +6 -0
- package/src/shared/window-geometry.ts +10 -0
- package/dist/wrapup-orchestrator-kw3x3myw.js +0 -26
- /package/dist/{index-en1k8h8m.js → index-5prbx026.js} +0 -0
- /package/dist/v2/{index-en1k8h8m.js → index-5prbx026.js} +0 -0
|
@@ -37,13 +37,13 @@ import {
|
|
|
37
37
|
DEFAULT_PROTECTED_TOOLS,
|
|
38
38
|
normalizeProtectedToolName,
|
|
39
39
|
mergeProtectedTools
|
|
40
|
-
} from "./server-
|
|
40
|
+
} from "./server-fq7kq32k.js";
|
|
41
41
|
import {
|
|
42
42
|
openCodeDbExists,
|
|
43
43
|
withReadOnlySessionDb,
|
|
44
44
|
getRawSessionMessageCountFromDb,
|
|
45
45
|
getMessageTimesFromOpenCodeDb
|
|
46
|
-
} from "./server-
|
|
46
|
+
} from "./server-vd4e7174.js";
|
|
47
47
|
import {
|
|
48
48
|
canonicalModelIdentity
|
|
49
49
|
} from "./server-avwt563y.js";
|
|
@@ -2160,6 +2160,17 @@ function getAllStatusTagTokenTotalsFlat(db, sessionId, floor = 0, calibration =
|
|
|
2160
2160
|
}
|
|
2161
2161
|
return { totals, nullMessageIds };
|
|
2162
2162
|
}
|
|
2163
|
+
function getReasoningTokenEstimatesByMessage(db, sessionId, proseRatio) {
|
|
2164
|
+
const rows = db.prepare(`SELECT type, message_id, tool_owner_message_id, reasoning_token_count FROM tags WHERE session_id = ? AND reasoning_token_count IS NOT NULL`).all(sessionId);
|
|
2165
|
+
const totals = new Map;
|
|
2166
|
+
for (const row of rows) {
|
|
2167
|
+
if (row.type !== "message")
|
|
2168
|
+
continue;
|
|
2169
|
+
const id = ownerMessageIdForTagRow(row);
|
|
2170
|
+
totals.set(id, Math.max(totals.get(id) ?? 0, row.reasoning_token_count * proseRatio));
|
|
2171
|
+
}
|
|
2172
|
+
return totals;
|
|
2173
|
+
}
|
|
2163
2174
|
function tagTokenCountIsNull(db, sessionId, tagNumber) {
|
|
2164
2175
|
const row = db.prepare("SELECT token_count FROM tags WHERE session_id = ? AND tag_number = ?").get(sessionId, tagNumber);
|
|
2165
2176
|
return row != null && row.token_count === null;
|
|
@@ -2622,6 +2633,10 @@ function deriveTagLoadFloor(db, sessionId, rawIds) {
|
|
|
2622
2633
|
return Math.max(0, min - margin);
|
|
2623
2634
|
}
|
|
2624
2635
|
var TAG_SELECT_COLUMNS = "id, message_id, type, status, drop_mode, tool_name, input_byte_size, byte_size, reasoning_byte_size, session_id, tag_number, caveman_depth, tool_owner_message_id, token_count";
|
|
2636
|
+
function getTagsBySession(db, sessionId) {
|
|
2637
|
+
const rows = db.prepare(`SELECT ${TAG_SELECT_COLUMNS} FROM tags WHERE session_id = ? ORDER BY tag_number ASC, id ASC`).all(sessionId).filter(isTagRow);
|
|
2638
|
+
return rows.map(toTagEntry);
|
|
2639
|
+
}
|
|
2625
2640
|
var getActiveTagsBySessionStatements = new WeakMap;
|
|
2626
2641
|
var getNullOwnerToolTagsBySessionStatements = new WeakMap;
|
|
2627
2642
|
var getDroppedTagsBySessionStatements = new WeakMap;
|
|
@@ -2853,6 +2868,20 @@ function pickNearestPriorOwner(candidates, currentMessageId, times) {
|
|
|
2853
2868
|
}
|
|
2854
2869
|
// src/shared/historian-tool-defaults.json
|
|
2855
2870
|
var historian_tool_defaults_default = {
|
|
2871
|
+
ctx_note: "Note ${input.action} ${input.note_ids}: ${input.content} → ${output.truncate(160)}",
|
|
2872
|
+
ctx_memory: "Memory ${input.action} ${input.category} ${input.ids}: ${input.content} → ${output.truncate(160)}",
|
|
2873
|
+
todowrite: 'Todos (${input.todos.count}): ${input.todos.each("${status}: ${content}")}',
|
|
2874
|
+
question: 'Asked user: ${input.questions[*].question.join(" / ")} → ${output}',
|
|
2875
|
+
task: "Task ${input.subagent_type}: ${input.prompt.truncate(600)} → ${output.truncate(200)}",
|
|
2876
|
+
ask: 'Asked: ${input.question} [options: ${input.options.join(" / ")}] ${input.text}${input.resolution} → ${output.truncate(300)}',
|
|
2877
|
+
peer_send: "PM ${input.recipient}: ${input.message}",
|
|
2878
|
+
board: 'Board ${input.verb}${input.board_lane}: ${input.ops.each("${op} ${lane_label} ${item}${props.text}${lane.items} ${state}${props.state}${lane.status}${id}${title}")}',
|
|
2879
|
+
room: "Room ${input.action} ${input.room_label}: ${input.room_detail}",
|
|
2880
|
+
work: "Work ${input.action} ${input.title}${input.id}: ${input.prompt.truncate(600)}${input.notes.truncate(600)} → ${output.truncate(160)}",
|
|
2881
|
+
knowhow: "Looked up how-to: ${input.query}${input.id}"
|
|
2882
|
+
};
|
|
2883
|
+
// src/shared/historian-tool-preview-defaults.json
|
|
2884
|
+
var historian_tool_preview_defaults_default = {
|
|
2856
2885
|
ctx_note: "Note ${input.action} ${input.note_ids}: ${input.content} → ${output.truncate(160)}",
|
|
2857
2886
|
ctx_memory: "Memory ${input.action} ${input.category} ${input.ids}: ${input.content} → ${output.truncate(160)}",
|
|
2858
2887
|
todowrite: 'Todos (${input.todos.count}): ${input.todos.each("${status}: ${content}")}',
|
|
@@ -2867,17 +2896,48 @@ var historian_tool_defaults_default = {
|
|
|
2867
2896
|
};
|
|
2868
2897
|
|
|
2869
2898
|
// src/shared/historian-tool-expansions.ts
|
|
2870
|
-
function
|
|
2899
|
+
function builtinInput(tool, input) {
|
|
2900
|
+
if (!input || typeof input !== "object")
|
|
2901
|
+
return input;
|
|
2902
|
+
const i = input;
|
|
2903
|
+
if (tool === "peer_send") {
|
|
2904
|
+
const external = i.external;
|
|
2905
|
+
const recipient = i.reply_to_pmid ? `reply to ${i.reply_to_pmid}` : i.agent || i.agent_id ? `to ${i.agent || i.agent_id}` : external?.session_id || i.session_id ? `to session ${external?.session_id || i.session_id}` : "to unknown recipient";
|
|
2906
|
+
return { ...i, recipient };
|
|
2907
|
+
}
|
|
2908
|
+
if (tool === "room") {
|
|
2909
|
+
return {
|
|
2910
|
+
...i,
|
|
2911
|
+
room_label: i.room_id || i.title,
|
|
2912
|
+
room_detail: i.action === "create" || i.action === "invite" ? `invitees: ${renderToolTemplate("${input.invitees}", i)}` : i.text
|
|
2913
|
+
};
|
|
2914
|
+
}
|
|
2915
|
+
if (tool === "board") {
|
|
2916
|
+
return {
|
|
2917
|
+
...i,
|
|
2918
|
+
board_lane: i.lane ? ` ${i.lane}` : "",
|
|
2919
|
+
ops: Array.isArray(i.ops) ? i.ops.map((op) => op && typeof op === "object" ? {
|
|
2920
|
+
...op,
|
|
2921
|
+
lane_label: typeof op.lane === "string" ? op.lane : op.lane?.title || op.lane?.id
|
|
2922
|
+
} : op) : i.ops
|
|
2923
|
+
};
|
|
2924
|
+
}
|
|
2925
|
+
return input;
|
|
2926
|
+
}
|
|
2927
|
+
function expandToolPart(part, overrides, legacyPreview = false) {
|
|
2871
2928
|
if (!part || typeof part !== "object")
|
|
2872
2929
|
return null;
|
|
2873
2930
|
const p = part;
|
|
2874
2931
|
if (p.type !== "tool" || typeof p.tool !== "string")
|
|
2875
2932
|
return null;
|
|
2876
|
-
const
|
|
2933
|
+
const builtinDefaults = legacyPreview ? historian_tool_preview_defaults_default : historian_tool_defaults_default;
|
|
2934
|
+
const overridden = overrides && Object.hasOwn(overrides, p.tool);
|
|
2935
|
+
const template = overridden ? overrides[p.tool] : Object.hasOwn(builtinDefaults, p.tool) ? builtinDefaults[p.tool] : undefined;
|
|
2877
2936
|
if (typeof template !== "string")
|
|
2878
2937
|
return null;
|
|
2879
2938
|
const state = p.state;
|
|
2880
|
-
|
|
2939
|
+
const input = overridden || legacyPreview ? state?.input : builtinInput(p.tool, state?.input);
|
|
2940
|
+
return renderToolTemplate(template, input, state?.output ?? state?.error, legacyPreview);
|
|
2881
2941
|
}
|
|
2882
2942
|
|
|
2883
2943
|
// src/hooks/magic-context/host-served-rows.ts
|
|
@@ -3833,20 +3893,22 @@ function fenceBoundaryForCompletedToolArcs(candidate, arcs, publicationFloorOrdi
|
|
|
3833
3893
|
return minInvocation < publicationFloorOrdinal ? maxResult + 1 : minInvocation;
|
|
3834
3894
|
}
|
|
3835
3895
|
function fenceBoundaryForToolArcs(candidate, arcs, lastCompartmentEndOrdinal, recentOpenArcCutoff) {
|
|
3836
|
-
|
|
3896
|
+
let boundary = fenceBoundaryForCompletedToolArcs(candidate, arcs, lastCompartmentEndOrdinal + 1);
|
|
3837
3897
|
for (const arc of arcs) {
|
|
3838
3898
|
if (arc.resOrdinal !== null)
|
|
3839
3899
|
continue;
|
|
3840
3900
|
if (arc.invOrdinal < recentOpenArcCutoff)
|
|
3841
3901
|
continue;
|
|
3842
3902
|
if (arc.invOrdinal >= lastCompartmentEndOrdinal + 1 && arc.invOrdinal < boundary) {
|
|
3843
|
-
|
|
3903
|
+
boundary = arc.invOrdinal;
|
|
3904
|
+
break;
|
|
3844
3905
|
}
|
|
3845
3906
|
if (arc.invOrdinal >= boundary) {
|
|
3846
|
-
|
|
3907
|
+
boundary = arc.invOrdinal;
|
|
3908
|
+
break;
|
|
3847
3909
|
}
|
|
3848
3910
|
}
|
|
3849
|
-
return boundary;
|
|
3911
|
+
return fenceBoundaryForCompletedToolArcs(boundary, arcs, 1);
|
|
3850
3912
|
}
|
|
3851
3913
|
function tokenForMessage(message, options) {
|
|
3852
3914
|
const key = messageCacheKey(message, options);
|
|
@@ -4598,7 +4660,7 @@ function estimateFinalWireInputTokens(input) {
|
|
|
4598
4660
|
total.toolCall += next.toolCall;
|
|
4599
4661
|
return total;
|
|
4600
4662
|
}, { conversation: 0, toolCall: 0 });
|
|
4601
|
-
const measuredToolDefinitions = input.providerID && input.modelID ? getMeasuredToolDefinitionTokens(input.providerID, input.modelID, input.agentName) : undefined;
|
|
4663
|
+
const measuredToolDefinitions = input.toolDefinitionTokens ?? (input.providerID && input.modelID ? getMeasuredToolDefinitionTokens(input.providerID, input.modelID, input.agentName) : undefined);
|
|
4602
4664
|
const calibration = resolveDecisionCalibration(input.providerID, input.modelID);
|
|
4603
4665
|
const largestToolDefinitions = measuredToolDefinitions === undefined ? getLargestMeasuredToolDefinitionTokens() : undefined;
|
|
4604
4666
|
const toolDefinitions = measuredToolDefinitions ?? (largestToolDefinitions === undefined ? undefined : Math.ceil(largestToolDefinitions * UNKNOWN_FIT_RATIO / (calibration.seeded ? calibration.toolsRatio : UNKNOWN_FIT_RATIO)));
|
|
@@ -4790,10 +4852,38 @@ function extractErrorMessage(error) {
|
|
|
4790
4852
|
}
|
|
4791
4853
|
return String(error);
|
|
4792
4854
|
}
|
|
4855
|
+
function extractExplicitHttpStatus(error) {
|
|
4856
|
+
if (!error || typeof error !== "object")
|
|
4857
|
+
return;
|
|
4858
|
+
const seen = new Set;
|
|
4859
|
+
const queue = [error];
|
|
4860
|
+
while (queue.length > 0) {
|
|
4861
|
+
const current = queue.shift();
|
|
4862
|
+
if (!current || seen.has(current))
|
|
4863
|
+
continue;
|
|
4864
|
+
seen.add(current);
|
|
4865
|
+
const record = current;
|
|
4866
|
+
for (const key of ["status", "statusCode", "status_code"]) {
|
|
4867
|
+
const value = record[key];
|
|
4868
|
+
if (typeof value === "number")
|
|
4869
|
+
return value;
|
|
4870
|
+
}
|
|
4871
|
+
for (const value of Object.values(record)) {
|
|
4872
|
+
if (value && typeof value === "object")
|
|
4873
|
+
queue.push(value);
|
|
4874
|
+
}
|
|
4875
|
+
}
|
|
4876
|
+
return;
|
|
4877
|
+
}
|
|
4878
|
+
function detectLatestTurnThinkingMismatch(error) {
|
|
4879
|
+
const status = extractExplicitHttpStatus(error);
|
|
4880
|
+
return (status === undefined || status === 400) && /(?:thinking|redacted_thinking)[\s\S]*latest assistant (?:message|turn)[\s\S]*cannot be modified/i.test(extractErrorMessage(error));
|
|
4881
|
+
}
|
|
4793
4882
|
var PREFIX_BOUND_THINKING_MODELS = [
|
|
4794
4883
|
["fable", 5, 1],
|
|
4795
4884
|
["opus", 5, 5],
|
|
4796
|
-
["sonnet", 5, 5]
|
|
4885
|
+
["sonnet", 5, 5],
|
|
4886
|
+
["haiku", 5, 5]
|
|
4797
4887
|
];
|
|
4798
4888
|
var PREFIX_BOUND_THINKING_PATTERN = new RegExp(`(?:^|[-_.:/])(?:${PREFIX_BOUND_THINKING_MODELS.map(([family, major, minor]) => `${family}[-_.]?${major}[-_.]${minor}`).join("|")})(?:$|[-_.:/@])`, "i");
|
|
4799
4889
|
function isPrefixBoundThinkingModel(_providerID, modelID) {
|
|
@@ -4930,6 +5020,9 @@ function restoreNeutralizedReasoningPart(part, legacyCleared) {
|
|
|
4930
5020
|
function isNeutralizedReasoningPart(part) {
|
|
4931
5021
|
return isRecord(part) && part[REMOVED_REASONING_MARK] === true;
|
|
4932
5022
|
}
|
|
5023
|
+
function neutralizedReasoningSource(part) {
|
|
5024
|
+
return isRecord(part) ? NEUTRALIZED_ORIGINALS.get(part) ?? part : part;
|
|
5025
|
+
}
|
|
4933
5026
|
var VARIANT_CACHE_PRESERVING_MODELS = {
|
|
4934
5027
|
"anthropic/claude-fable-5-1": "2026-09-02",
|
|
4935
5028
|
"openai/gpt-6-astra": "2026-09-05",
|
|
@@ -5382,6 +5475,8 @@ function createToolDropTarget(compositeKey, thinkingParts, index, batch, tagId)
|
|
|
5382
5475
|
return "truncated";
|
|
5383
5476
|
};
|
|
5384
5477
|
return {
|
|
5478
|
+
dropReasoningParts: thinkingParts,
|
|
5479
|
+
mutationParts: index.get(compositeKey)?.occurrences.map(({ message, part }) => ({ message, part })) ?? [],
|
|
5385
5480
|
measureReclaim: (skeleton) => {
|
|
5386
5481
|
const entry = index.get(compositeKey);
|
|
5387
5482
|
const parts = entry?.occurrences.map((occ) => occ.part) ?? [];
|
|
@@ -6363,4 +6458,4 @@ function readRawSessionSeedTail2(sessionId, boundaryId, onQuery) {
|
|
|
6363
6458
|
});
|
|
6364
6459
|
}
|
|
6365
6460
|
|
|
6366
|
-
export { isPrefixBoundThinkingModel, detectOverflow, protectedToolTagNumbers, protectedToolTokenCount, stripWellFormedLeadingTagPrefix, byteSize, stripTagPrefix, peelLeadingMcTagNotation, prependTag, isThinkingPart, isRecord, contentTagOwnerMessageId, estimateImageTokensFromDataUrl, estimateToolAttachmentImageTokens, normalizeTodoStateJson, buildSyntheticTodoPart, computeSyntheticCallId, isSyntheticTodoPart, countRealUserMessages, tailHygieneStructuralSignature, sameTailHygieneStructuralSignature, formatTailHygienePrefixMismatch, refreshTailHygieneBaseline, effectiveTailHygiene, assertTailHygieneContentUnchangedIfEnabled, CHANNEL1_SENTINEL, CHANNEL1_FLOOR_TOKENS, isDroppedToolOutput, toolOutputTokens, decideChannel1, evaluateChannel2, formatChannel1Evaluation, formatChannel2Evaluation, reclaimableToolOutputCount, buildChannel2Reminder, buildChannel1Reminder, estimateEmergencyDropReclaimTokens, planEmergencyDrop, measureEmergencyTag, queuePendingOp, queuePendingDropForUnchangedTag, getPendingOps, hasPendingDropOps, getPendingOpsCount, clearPendingOps, removePendingOp, getRecentTagOwnerMessageIds, AGE_RECLAIM_MIN_TOKENS, getOldestActiveUnprotectedToolTags, getActiveToolTagsForAgeReclaim, getTriggerTagTokenUpperBound, getActiveTagTokenTotalsByMessage, getAllStatusTagTokenTotalsFlat, tagTokenCountIsNull, backfillTagTokenCounts, insertTag, updateTagStatus, markWhitespaceAssistantTagInert, getInertWhitespaceAssistantTags, updateTagDropMode, updateCavemanDepth, updateTagMessageId, foldShrunkPartTags, markTagsCompactedByMessageIds, getMaxTagNumberBySession, getTagNumberByMessageId, getAssignableTagNumberByMessageId, deriveTagLoadFloor, TAG_SELECT_COLUMNS, getActiveTagsBySession, getTailHygieneTags, getDroppedTagsBySession, getTagsByNumbers, getNewestToolTagNumbers, getDroppedTagsByNumbers, getMaxDroppedTagNumber, getTagById, getToolTagNumberByOwner, getNullOwnerToolTag, adoptNullOwnerToolTag, getCandidateToolOwners, pickNearestPriorOwner, expandToolPart, markHostUnservedRow, retreatPastHostUnservedRows, snapTerminalCompartmentToServedRow, isHostRenderedSystemMessage, isStrictGapHealingMessage, isRawCompactionSummaryInfo, extractInMemoryMessageViews, buildInMemoryTailRawMessages, completedToolArcCrossesBoundary, estimateTrueRawMessageTokens, buildToolArcs, fenceBoundaryForCompletedToolArcs, fenceBoundaryForToolArcs, buildTrueRawTokenIndex, computeRawRangeFingerprint, stripSystemInjection, isTextPart, isToolPartWithOutput, isFilePart, buildFileSourceContent, toolPartHasUserAnswer, DreamTokenBudgetExceeded, TOKEN_BUDGET_FINALIZE_MESSAGE, registerBudgetFinalizeChild, releaseBudgetFinalizeChild, createDreamTokenBudget, recordToolParameters, createDroppedInputGuard, assertExecutableToolInput, isEditTool, describeFinalWireTail, estimateMessageTokens, wireContentBytes, createFinalWireUsageTracker, estimateFinalWireInputTokens, estimateAppendedWireTokens, modelAcceptsEmptyContent, isAnthropicFamilyRoute, neutralizeDroppedReasoningPart, restoreNeutralizedReasoningPart, isNeutralizedReasoningPart, variantChangeBustsProviderCache, makeSentinel, makeWholeMessageSentinel, isSentinel, replaySentinelByMessageIds, SKELETON_REAL_INPUT_MAX_BYTES, partHasCompletedResult, extractToolCallObservation, ToolMutationBatch, createToolDropTarget, resolveHostServedBoundaryId2, hasRawMessageProvider2, setRawMessageProvider2, setBoundedRawMessageProvider2, withRawMessageProvider2, cleanUserText2, withRawSessionMessageCache2, readRawSessionMessages2, readRawSessionMessagePage2, getRawSessionMessageOrdinalCount2, RAW_MESSAGE_VISIT_PAGE_SIZE2, visitRawSessionMessages2, readRawSessionMessageRange2, primeTailRawMessageCache2, getCachedAbsoluteMessageCount2, primeInMemoryTailRawMessageCache2, readRawSessionMessageOrdinalPage2, getRawSessionStoredMessageCount2, readRawSessionMessageIdOrdinalsForRange2, readRawSessionMessageIdOrdinals2, readRawSessionMessagePartsById2, hasRawSessionMessageById2, readRawSessionMessageOrdinalById2, compareRawSessionMessageOrder2, readRawSessionMessageById2, getRawSessionMessageCount2, RAW_SESSION_TAG_KEY_PAGE_SIZE2, getRawSessionTagKeysThrough2, getLegacyProtectedTailStartOrdinal2, getProtectedTailStartOrdinal2, readSessionChunk2, getRawSessionMessageIdsThrough2, readRawSessionSeedTail2 };
|
|
6461
|
+
export { detectLatestTurnThinkingMismatch, isPrefixBoundThinkingModel, detectOverflow, protectedToolTagNumbers, protectedToolTokenCount, stripWellFormedLeadingTagPrefix, byteSize, stripTagPrefix, peelLeadingMcTagNotation, prependTag, isThinkingPart, isRecord, contentTagOwnerMessageId, estimateImageTokensFromDataUrl, estimateToolAttachmentImageTokens, normalizeTodoStateJson, buildSyntheticTodoPart, computeSyntheticCallId, isSyntheticTodoPart, countRealUserMessages, tailHygieneStructuralSignature, sameTailHygieneStructuralSignature, formatTailHygienePrefixMismatch, refreshTailHygieneBaseline, effectiveTailHygiene, assertTailHygieneContentUnchangedIfEnabled, CHANNEL1_SENTINEL, CHANNEL1_FLOOR_TOKENS, isDroppedToolOutput, toolOutputTokens, decideChannel1, evaluateChannel2, formatChannel1Evaluation, formatChannel2Evaluation, reclaimableToolOutputCount, buildChannel2Reminder, buildChannel1Reminder, estimateEmergencyDropReclaimTokens, planEmergencyDrop, measureEmergencyTag, queuePendingOp, queuePendingDropForUnchangedTag, getPendingOps, hasPendingDropOps, getPendingOpsCount, clearPendingOps, removePendingOp, getRecentTagOwnerMessageIds, AGE_RECLAIM_MIN_TOKENS, getOldestActiveUnprotectedToolTags, getActiveToolTagsForAgeReclaim, getTriggerTagTokenUpperBound, getActiveTagTokenTotalsByMessage, getAllStatusTagTokenTotalsFlat, getReasoningTokenEstimatesByMessage, tagTokenCountIsNull, backfillTagTokenCounts, insertTag, updateTagStatus, markWhitespaceAssistantTagInert, getInertWhitespaceAssistantTags, updateTagDropMode, updateCavemanDepth, updateTagMessageId, foldShrunkPartTags, markTagsCompactedByMessageIds, getMaxTagNumberBySession, getTagNumberByMessageId, getAssignableTagNumberByMessageId, deriveTagLoadFloor, TAG_SELECT_COLUMNS, getTagsBySession, getActiveTagsBySession, getTailHygieneTags, getDroppedTagsBySession, getTagsByNumbers, getNewestToolTagNumbers, getDroppedTagsByNumbers, getMaxDroppedTagNumber, getTagById, getToolTagNumberByOwner, getNullOwnerToolTag, adoptNullOwnerToolTag, getCandidateToolOwners, pickNearestPriorOwner, expandToolPart, markHostUnservedRow, retreatPastHostUnservedRows, snapTerminalCompartmentToServedRow, isHostRenderedSystemMessage, isStrictGapHealingMessage, isRawCompactionSummaryInfo, extractInMemoryMessageViews, buildInMemoryTailRawMessages, completedToolArcCrossesBoundary, estimateTrueRawMessageTokens, buildToolArcs, fenceBoundaryForCompletedToolArcs, fenceBoundaryForToolArcs, buildTrueRawTokenIndex, computeRawRangeFingerprint, stripSystemInjection, isTextPart, isToolPartWithOutput, isFilePart, buildFileSourceContent, toolPartHasUserAnswer, DreamTokenBudgetExceeded, TOKEN_BUDGET_FINALIZE_MESSAGE, registerBudgetFinalizeChild, releaseBudgetFinalizeChild, createDreamTokenBudget, recordToolParameters, createDroppedInputGuard, assertExecutableToolInput, isEditTool, describeFinalWireTail, estimateMessageTokens, wireContentBytes, createFinalWireUsageTracker, estimateFinalWireInputTokens, estimateAppendedWireTokens, modelAcceptsEmptyContent, isAnthropicFamilyRoute, neutralizeDroppedReasoningPart, restoreNeutralizedReasoningPart, isNeutralizedReasoningPart, neutralizedReasoningSource, variantChangeBustsProviderCache, makeSentinel, makeWholeMessageSentinel, isSentinel, replaySentinelByMessageIds, SKELETON_REAL_INPUT_MAX_BYTES, partHasCompletedResult, extractToolCallObservation, ToolMutationBatch, createToolDropTarget, resolveHostServedBoundaryId2, hasRawMessageProvider2, setRawMessageProvider2, setBoundedRawMessageProvider2, withRawMessageProvider2, cleanUserText2, withRawSessionMessageCache2, readRawSessionMessages2, readRawSessionMessagePage2, getRawSessionMessageOrdinalCount2, RAW_MESSAGE_VISIT_PAGE_SIZE2, visitRawSessionMessages2, readRawSessionMessageRange2, primeTailRawMessageCache2, getCachedAbsoluteMessageCount2, primeInMemoryTailRawMessageCache2, readRawSessionMessageOrdinalPage2, getRawSessionStoredMessageCount2, readRawSessionMessageIdOrdinalsForRange2, readRawSessionMessageIdOrdinals2, readRawSessionMessagePartsById2, hasRawSessionMessageById2, readRawSessionMessageOrdinalById2, compareRawSessionMessageOrder2, readRawSessionMessageById2, getRawSessionMessageCount2, RAW_SESSION_TAG_KEY_PAGE_SIZE2, getRawSessionTagKeysThrough2, getLegacyProtectedTailStartOrdinal2, getProtectedTailStartOrdinal2, readSessionChunk2, getRawSessionMessageIdsThrough2, readRawSessionSeedTail2 };
|
|
@@ -5,14 +5,14 @@ import {
|
|
|
5
5
|
PER_HARNESS_MODEL_KEYS,
|
|
6
6
|
ConfigProfilesSchema,
|
|
7
7
|
MagicContextConfigSchema
|
|
8
|
-
} from "./server-
|
|
8
|
+
} from "./server-50hvkg3v.js";
|
|
9
9
|
import {
|
|
10
10
|
log
|
|
11
11
|
} from "./server-1qbnzc80.js";
|
|
12
12
|
import {
|
|
13
13
|
setWindowOverlayPath,
|
|
14
14
|
setOutputReserveConfig
|
|
15
|
-
} from "./server-
|
|
15
|
+
} from "./server-cpepxy2q.js";
|
|
16
16
|
|
|
17
17
|
// src/config/agent-disable.ts
|
|
18
18
|
var COMPACTION_ENABLED_PATH = `compaction${"."}enabled`;
|
|
@@ -3572,6 +3572,11 @@ function warnProtectedTagsDeprecationOnce() {
|
|
|
3572
3572
|
function parsePluginConfig(rawConfig, recoveredTopLevelKeys = []) {
|
|
3573
3573
|
const preMigrationWarnings = [];
|
|
3574
3574
|
const configWithoutRemovedAgent = stripRemovedAgentConfig(rawConfig, preMigrationWarnings);
|
|
3575
|
+
if (Object.hasOwn(rawConfig, "clear_reasoning_age")) {
|
|
3576
|
+
const warning = "clear_reasoning_age is deprecated and ignored. Magic Context now keeps reasoning up to a token budget, keep_reasoning_tokens (default 10,000). Remove the key, or set keep_reasoning_tokens to a token count.";
|
|
3577
|
+
preMigrationWarnings.push(warning);
|
|
3578
|
+
log(`[magic-context] ${warning}`);
|
|
3579
|
+
}
|
|
3575
3580
|
if (Object.hasOwn(rawConfig, "protected_tags")) {
|
|
3576
3581
|
warnProtectedTagsDeprecationOnce();
|
|
3577
3582
|
preMigrationWarnings.push("protected_tags is deprecated and ignored; use protected_tokens instead.");
|
|
@@ -70,6 +70,8 @@ function installTransactionRouting(db, readonly) {
|
|
|
70
70
|
configurable: true,
|
|
71
71
|
writable: true,
|
|
72
72
|
value: (sql) => {
|
|
73
|
+
if (/^\s*(?:COMMIT|END)\b/i.test(sql))
|
|
74
|
+
assertTransformWrite();
|
|
73
75
|
if (/^\s*BEGIN\s+(?:IMMEDIATE|EXCLUSIVE)(?:\s+TRANSACTION)?\s*;?\s*$/i.test(sql)) {
|
|
74
76
|
openWriterTransactions.delete(db);
|
|
75
77
|
if (transformPassScope.getStore()?.active || backgroundWriterScope.getStore())
|
|
@@ -206,6 +208,14 @@ function buildNodeSqliteDatabaseClass(DatabaseSync) {
|
|
|
206
208
|
return NodeSqliteDatabase;
|
|
207
209
|
}
|
|
208
210
|
var Database = TrackedDatabase;
|
|
211
|
+
function getSqliteDatabasePath(db) {
|
|
212
|
+
for (const connection of trackedSqliteConnections.values()) {
|
|
213
|
+
if (connection.reference.deref() === db) {
|
|
214
|
+
return connection.filename === ":memory:" || connection.filename === "<buffer>" ? null : connection.filename;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
209
219
|
function pragmaValue(db, name) {
|
|
210
220
|
const row = db.prepare(`PRAGMA ${name}`).get();
|
|
211
221
|
if (!row)
|
|
@@ -364,6 +374,10 @@ function withSqliteTransformPass(operation) {
|
|
|
364
374
|
function withoutSqliteTransformPass(operation) {
|
|
365
375
|
return transformPassScope.run(undefined, operation);
|
|
366
376
|
}
|
|
377
|
+
function assertTransformWrite() {
|
|
378
|
+
if (!backgroundWriterScope.getStore())
|
|
379
|
+
transformPassScope.getStore()?.guard?.assert();
|
|
380
|
+
}
|
|
367
381
|
function isTransientSqliteError(error) {
|
|
368
382
|
if (!error || typeof error !== "object")
|
|
369
383
|
return false;
|
|
@@ -392,6 +406,7 @@ function foregroundWaitLease() {
|
|
|
392
406
|
return lease?.active && !admissionScope.getStore() && !backgroundWriterScope.getStore() ? lease : undefined;
|
|
393
407
|
}
|
|
394
408
|
function withAutocommitTimeout(db, operation) {
|
|
409
|
+
assertTransformWrite();
|
|
395
410
|
const lease = foregroundWaitLease();
|
|
396
411
|
if (isInTransaction(db) || !lease && !backgroundWriterScope.getStore())
|
|
397
412
|
return operation();
|
|
@@ -412,6 +427,7 @@ function withAutocommitTimeout(db, operation) {
|
|
|
412
427
|
}
|
|
413
428
|
}
|
|
414
429
|
function acquireShort(db, acquire, site) {
|
|
430
|
+
assertTransformWrite();
|
|
415
431
|
const started = performance.now();
|
|
416
432
|
const previous = pragmaNumber(db, "busy_timeout");
|
|
417
433
|
const outer = writerAcquisitionScope.getStore();
|
|
@@ -423,7 +439,7 @@ function acquireShort(db, acquire, site) {
|
|
|
423
439
|
let acquiredAt;
|
|
424
440
|
try {
|
|
425
441
|
const lease = foregroundWaitLease();
|
|
426
|
-
const timeout =
|
|
442
|
+
const timeout = Math.floor(Math.min(lease ? lease.remainingWaitMs : SHORT_BUSY_TIMEOUT_MS, owner?.remainingMs?.() ?? lease?.guard?.remainingMs() ?? Infinity));
|
|
427
443
|
db.exec(`PRAGMA busy_timeout=${timeout}`);
|
|
428
444
|
acquire();
|
|
429
445
|
acquiredAt = performance.now();
|
|
@@ -496,29 +512,53 @@ async function beginSqliteWriterAsync(db, site) {
|
|
|
496
512
|
}
|
|
497
513
|
}
|
|
498
514
|
}
|
|
499
|
-
async function withAsyncPrivilegedWriter(db, operation) {
|
|
515
|
+
async function withAsyncPrivilegedWriter(db, operation, options = {}) {
|
|
500
516
|
const started = performance.now();
|
|
517
|
+
const budgetMs = Math.max(0, Math.min(FOREGROUND_ACQUISITION_BUDGET_MS, options.budgetMs ?? Infinity));
|
|
501
518
|
let attempts = 0;
|
|
502
519
|
for (;; ) {
|
|
520
|
+
options.signal?.throwIfAborted();
|
|
521
|
+
options.assertCurrentPass?.();
|
|
503
522
|
attempts++;
|
|
523
|
+
let entered = false;
|
|
504
524
|
try {
|
|
505
525
|
const acquisition = {
|
|
506
526
|
site: "privileged_writer",
|
|
507
527
|
lane: "foreground",
|
|
508
528
|
startedAt: started,
|
|
509
529
|
attempts,
|
|
510
|
-
claimed: false
|
|
530
|
+
claimed: false,
|
|
531
|
+
remainingMs: () => Math.max(0, budgetMs - (performance.now() - started))
|
|
511
532
|
};
|
|
512
|
-
return admissionScope.run(true, () => withSqliteTransformPass(() => writerAcquisitionScope.run(acquisition, () => withPrivilegedWriter(db,
|
|
533
|
+
return admissionScope.run(true, () => withSqliteTransformPass(() => writerAcquisitionScope.run(acquisition, () => withPrivilegedWriter(db, () => {
|
|
534
|
+
entered = true;
|
|
535
|
+
return operation();
|
|
536
|
+
}))));
|
|
513
537
|
} catch (error) {
|
|
514
|
-
if (!(error instanceof SqliteAcquisitionBusyError))
|
|
538
|
+
if (entered || !(error instanceof SqliteAcquisitionBusyError))
|
|
515
539
|
throw error;
|
|
540
|
+
options.beforeRetry?.(error);
|
|
516
541
|
const elapsed = performance.now() - started;
|
|
517
|
-
if (elapsed >=
|
|
542
|
+
if (elapsed >= budgetMs) {
|
|
518
543
|
reportSqliteDiagnostic(`sqlite writer site=privileged_writer lane=foreground acquire_ms=${Math.round(elapsed)} attempts=${attempts} outcome=busy`);
|
|
519
544
|
throw error;
|
|
520
545
|
}
|
|
521
|
-
|
|
546
|
+
const backoff = attempts === 1 ? 500 : 1000;
|
|
547
|
+
const delay = Math.min(options.jitter ? backoff * (0.8 + Math.random() * 0.4) : backoff, budgetMs - elapsed);
|
|
548
|
+
await new Promise((resolve, reject) => {
|
|
549
|
+
const abort = () => {
|
|
550
|
+
clearTimeout(timer);
|
|
551
|
+
options.signal?.removeEventListener("abort", abort);
|
|
552
|
+
reject(options.signal?.reason ?? new Error("Writer wait aborted"));
|
|
553
|
+
};
|
|
554
|
+
const timer = setTimeout(() => {
|
|
555
|
+
options.signal?.removeEventListener("abort", abort);
|
|
556
|
+
resolve();
|
|
557
|
+
}, delay);
|
|
558
|
+
options.signal?.addEventListener("abort", abort, { once: true });
|
|
559
|
+
if (options.signal?.aborted)
|
|
560
|
+
abort();
|
|
561
|
+
});
|
|
522
562
|
}
|
|
523
563
|
}
|
|
524
564
|
}
|
|
@@ -581,4 +621,4 @@ function withPrivilegedWriter(db, operation) {
|
|
|
581
621
|
}
|
|
582
622
|
}
|
|
583
623
|
|
|
584
|
-
export { registerSlowWriteReporter, registerSqliteDiagnosticSink, detectSqliteRuntime, Database, getSqliteMemoryStats, prepareCachedStatement, withSqliteBackgroundWriter, withSqliteTransformPass, withoutSqliteTransformPass, isTransientSqliteError, SqliteAcquisitionBusyError, beginSqliteWriterAsync, withAsyncPrivilegedWriter, withPrivilegedWriter };
|
|
624
|
+
export { registerSlowWriteReporter, registerSqliteDiagnosticSink, detectSqliteRuntime, Database, getSqliteDatabasePath, getSqliteMemoryStats, prepareCachedStatement, withSqliteBackgroundWriter, withSqliteTransformPass, withoutSqliteTransformPass, assertTransformWrite, isTransientSqliteError, SqliteAcquisitionBusyError, beginSqliteWriterAsync, withAsyncPrivilegedWriter, withPrivilegedWriter };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// src/shared/embedding-activity.ts
|
|
2
|
+
var busySessions = new Set;
|
|
3
|
+
function setEmbeddingSessionBusy(sessionId, busy) {
|
|
4
|
+
if (busy)
|
|
5
|
+
busySessions.add(sessionId);
|
|
6
|
+
else
|
|
7
|
+
busySessions.delete(sessionId);
|
|
8
|
+
}
|
|
9
|
+
function observeEmbeddingActivity(event) {
|
|
10
|
+
const props = event.properties;
|
|
11
|
+
if (!props || typeof props.sessionID !== "string")
|
|
12
|
+
return;
|
|
13
|
+
if (event.type === "session.idle" || event.type === "session.deleted" || event.type === "session.status" && props.status?.type === "idle") {
|
|
14
|
+
setEmbeddingSessionBusy(props.sessionID, false);
|
|
15
|
+
} else if (event.type === "session.status" && props.status?.type) {
|
|
16
|
+
setEmbeddingSessionBusy(props.sessionID, true);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function isEmbeddingHostBusy() {
|
|
20
|
+
return busySessions.size > 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { setEmbeddingSessionBusy, observeEmbeddingActivity, isEmbeddingHostBusy };
|
package/dist/v2/server.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
loadPluginConfigDetailed
|
|
3
|
-
} from "./server-
|
|
3
|
+
} from "./server-rz514f14.js";
|
|
4
4
|
import {
|
|
5
5
|
setHarness,
|
|
6
6
|
registerStalePluginBuildHost,
|
|
7
7
|
log,
|
|
8
8
|
flushLogger
|
|
9
9
|
} from "./server-1qbnzc80.js";
|
|
10
|
-
import"./server-
|
|
10
|
+
import"./server-cpepxy2q.js";
|
|
11
11
|
import {
|
|
12
12
|
string,
|
|
13
13
|
unknown,
|
|
@@ -16,8 +16,8 @@ import {
|
|
|
16
16
|
union,
|
|
17
17
|
tuple,
|
|
18
18
|
record
|
|
19
|
-
} from "./server-
|
|
20
|
-
import"./server-
|
|
19
|
+
} from "./server-50hvkg3v.js";
|
|
20
|
+
import"./server-fq7kq32k.js";
|
|
21
21
|
import {
|
|
22
22
|
pushNotification2
|
|
23
23
|
} from "./server-x8a7jmkh.js";
|
|
@@ -8040,7 +8040,7 @@ async function setup(context) {
|
|
|
8040
8040
|
log("v2 setup() called on a host without session.hook; v1 server lane owns this host, v2 lane inert");
|
|
8041
8041
|
return async () => {};
|
|
8042
8042
|
}
|
|
8043
|
-
const { registerContext } = await import("./context-
|
|
8043
|
+
const { registerContext } = await import("./context-14v1hr8b.js");
|
|
8044
8044
|
setHarness("opencode2");
|
|
8045
8045
|
bindStaleBuildNotice({}, import.meta.url, "opencode2");
|
|
8046
8046
|
const duties = await registerContext(context);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
sessionLog
|
|
3
3
|
} from "./server-1qbnzc80.js";
|
|
4
|
-
import"./server-
|
|
4
|
+
import"./server-d0sraw7m.js";
|
|
5
5
|
import {
|
|
6
6
|
COMPARTMENT_LEASE_RENEWAL_MS,
|
|
7
7
|
acquireCompartmentLease,
|
|
@@ -24,27 +24,30 @@ import {
|
|
|
24
24
|
registerActiveCompartmentRun,
|
|
25
25
|
setRecompStarting2,
|
|
26
26
|
setRecompTerminal2
|
|
27
|
-
} from "./server-
|
|
27
|
+
} from "./server-nf82q6pt.js";
|
|
28
28
|
import"./server-51dv1pr5.js";
|
|
29
|
-
import"./server-
|
|
30
|
-
import"./server-
|
|
29
|
+
import"./server-y10vbq6y.js";
|
|
30
|
+
import"./server-wx8a6bw3.js";
|
|
31
|
+
import"./server-njt3np1k.js";
|
|
32
|
+
import"./server-3trjk1hx.js";
|
|
31
33
|
import"./server-vs5gpnd4.js";
|
|
32
34
|
import"./server-1zx87sdm.js";
|
|
33
|
-
import"./server-
|
|
34
|
-
import"./server-
|
|
35
|
+
import"./server-nm9n3aqq.js";
|
|
36
|
+
import"./server-fq7kq32k.js";
|
|
35
37
|
import"./server-ajzeteqw.js";
|
|
36
|
-
import"./server-
|
|
37
|
-
import"./server-
|
|
38
|
+
import"./server-vd4e7174.js";
|
|
39
|
+
import"./server-50hvkg3v.js";
|
|
38
40
|
import {
|
|
39
41
|
pushNotification2
|
|
40
42
|
} from "./server-x8a7jmkh.js";
|
|
43
|
+
import"./server-yr3zj7e7.js";
|
|
44
|
+
import"./server-rz514f14.js";
|
|
45
|
+
import"./server-cpepxy2q.js";
|
|
46
|
+
import"./server-fcdehk1s.js";
|
|
47
|
+
import"./server-6r257mf5.js";
|
|
41
48
|
import {
|
|
42
49
|
sendStatusNotification2
|
|
43
|
-
} from "./server-
|
|
44
|
-
import"./server-p2en78c8.js";
|
|
45
|
-
import"./server-y8maxeft.js";
|
|
46
|
-
import"./server-3n4q9xme.js";
|
|
47
|
-
import"./server-6r257mf5.js";
|
|
50
|
+
} from "./server-efhwzx05.js";
|
|
48
51
|
import"./server-14vq4kpm.js";
|
|
49
52
|
|
|
50
53
|
// src/hooks/magic-context/wrapup-orchestrator.ts
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
runManagedWrapup2
|
|
3
|
+
} from "./index-5a2r0p9f.js";
|
|
4
|
+
import"./index-gg8j07zz.js";
|
|
5
|
+
import"./index-6d9e1m08.js";
|
|
6
|
+
import"./index-sd3egckz.js";
|
|
7
|
+
import"./index-adwfkpex.js";
|
|
8
|
+
import"./index-0c82743p.js";
|
|
9
|
+
import"./index-rrrsepyw.js";
|
|
10
|
+
import"./index-fnn5pjtt.js";
|
|
11
|
+
import"./index-yr3zj7e7.js";
|
|
12
|
+
import"./index-m5fe6jch.js";
|
|
13
|
+
import"./index-x3kwrmqk.js";
|
|
14
|
+
import"./index-bb36vgr3.js";
|
|
15
|
+
import"./index-6wkcswft.js";
|
|
16
|
+
import"./index-1zx87sdm.js";
|
|
17
|
+
import"./index-rrbbspwh.js";
|
|
18
|
+
import"./index-5gq3b2ya.js";
|
|
19
|
+
import"./index-b35pxds2.js";
|
|
20
|
+
import"./index-5eqk6z3s.js";
|
|
21
|
+
import"./index-sj29b3z2.js";
|
|
22
|
+
import"./index-wx8a6bw3.js";
|
|
23
|
+
import"./index-x8a7jmkh.js";
|
|
24
|
+
import"./index-fzbvakh0.js";
|
|
25
|
+
import"./index-hybnrwq0.js";
|
|
26
|
+
import"./index-q6hef7fh.js";
|
|
27
|
+
export {
|
|
28
|
+
runManagedWrapup2 as runManagedWrapup
|
|
29
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cortexkit/opencode-magic-context",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.47.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "OpenCode plugin for Magic Context — cross-session memory and context management",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"README.md"
|
|
38
38
|
],
|
|
39
39
|
"scripts": {
|
|
40
|
-
"build": "bun ../../scripts/check-bun.mjs && tsc -p ../retina-local-fs/tsconfig.build.json && bun run build:tui && bun ../../scripts/clean-dist-chunks.mjs dist index.js transformers-web.js transformers-node-wasm.js && bun build src/features/magic-context/memory/transformers-web-entry.ts --outfile dist/transformers-web.js --target browser --format esm --external onnxruntime-web && bun scripts/build-transformers-node-wasm.ts dist && bun build src/index.ts src/features/magic-context/memory/embedding-worker.ts src/features/magic-context/migration-worker.ts --outdir dist --entry-naming '[name].[ext]' --target node --format esm --splitting --external @opencode-ai/plugin --external onnxruntime-node --external onnxruntime-web --external sharp --external bun:sqlite --external node:sqlite && bun run build:v2 && tsc --emitDeclarationOnly",
|
|
41
|
-
"build:v2": "bun ../../scripts/clean-dist-chunks.mjs dist/v2 server.js embedding-worker.js migration-worker.js && bun build src/features/magic-context/memory/transformers-web-entry.ts --outfile dist/v2/transformers-web.js --target browser --format esm --external onnxruntime-web && bun scripts/build-transformers-node-wasm.ts dist/v2 && bun build src/v2/server.ts src/features/magic-context/memory/embedding-worker.ts src/features/magic-context/migration-worker.ts --outdir dist/v2 --entry-naming '[name].[ext]' --target node --format esm --splitting --external @opencode/plugin --external onnxruntime-node --external onnxruntime-web --external sharp --external bun:sqlite --external node:sqlite
|
|
40
|
+
"build": "bun ../../scripts/check-bun.mjs && tsc -p ../retina-local-fs/tsconfig.build.json && bun run build:tui && bun ../../scripts/clean-dist-chunks.mjs dist index.js transformers-web.js transformers-node-wasm.js && bun build src/features/magic-context/memory/transformers-web-entry.ts --outfile dist/transformers-web.js --target browser --format esm --external onnxruntime-web && bun scripts/build-transformers-node-wasm.ts dist && bun build src/index.ts src/features/magic-context/memory/embedding-worker.ts src/features/magic-context/migration-worker.ts src/hooks/magic-context/auto-search-worker.ts --outdir dist --entry-naming '[name].[ext]' --target node --format esm --splitting --external @opencode-ai/plugin --external onnxruntime-node --external onnxruntime-web --external sharp --external bun:sqlite --external node:sqlite && bun run build:v2 && tsc --emitDeclarationOnly",
|
|
41
|
+
"build:v2": "bun ../../scripts/clean-dist-chunks.mjs dist/v2 server.js embedding-worker.js migration-worker.js && bun build src/features/magic-context/memory/transformers-web-entry.ts --outfile dist/v2/transformers-web.js --target browser --format esm --external onnxruntime-web && bun scripts/build-transformers-node-wasm.ts dist/v2 && bun build src/v2/server.ts src/features/magic-context/memory/embedding-worker.ts src/features/magic-context/migration-worker.ts src/hooks/magic-context/auto-search-worker.ts --outdir dist/v2 --entry-naming '[name].[ext]' --target node --format esm --splitting --external @opencode/plugin --external onnxruntime-node --external onnxruntime-web --external sharp --external bun:sqlite --external node:sqlite",
|
|
42
42
|
"build:tui": "bun scripts/build-tui.ts",
|
|
43
|
-
"check:tui-compiled": "
|
|
43
|
+
"check:tui-compiled": "git diff --exit-code -- src/tui-compiled && test -z \"$(git status --porcelain -- src/tui-compiled)\"",
|
|
44
44
|
"check:transformers-node-wasm": "bun scripts/verify-transformers-node-wasm.ts",
|
|
45
45
|
"typecheck": "tsc -p ../retina-local-fs/tsconfig.build.json && tsc --noEmit && tsc -p tsconfig.scripts.json",
|
|
46
46
|
"test": "bun ../../scripts/check-bun.mjs && bun install --frozen-lockfile && BUN_JSC_useOMGJIT=0 bun test --parallel=4 --timeout 30000",
|
|
@@ -51,8 +51,9 @@
|
|
|
51
51
|
"format": "biome format --write .",
|
|
52
52
|
"format:check": "biome format .",
|
|
53
53
|
"clean": "bun ../../scripts/clean-dist-chunks.mjs dist index.js embedding-worker.js migration-worker.js transformers-web.js transformers-node-wasm.js && bun ../../scripts/clean-dist-chunks.mjs dist/v2 server.js embedding-worker.js migration-worker.js transformers-web.js transformers-node-wasm.js",
|
|
54
|
-
"prepublishOnly": "bun run build && bun run
|
|
54
|
+
"prepublishOnly": "bun run build && bun run check:tui-compiled"
|
|
55
55
|
},
|
|
56
|
+
"//check:tui-compiled": "Check drift on output already generated by build or build:tui; this check never regenerates files. CI and prepublishOnly build first.",
|
|
56
57
|
"//test": "Only test runs disable JSC's optimizing WebAssembly tier so per-file isolation does not pay its compilation cost on every file. This is not a production setting and does not change host process engine options.",
|
|
57
58
|
"dependencies": {
|
|
58
59
|
"@cortexkit/subc-client": "0.11.1",
|
package/src/config/index.ts
CHANGED
|
@@ -415,6 +415,12 @@ export function parsePluginConfig(
|
|
|
415
415
|
// opt-in/out state survives upgrades even when they never run `doctor`.
|
|
416
416
|
const preMigrationWarnings: string[] = [];
|
|
417
417
|
const configWithoutRemovedAgent = stripRemovedAgentConfig(rawConfig, preMigrationWarnings);
|
|
418
|
+
if (Object.hasOwn(rawConfig, "clear_reasoning_age")) {
|
|
419
|
+
const warning =
|
|
420
|
+
"clear_reasoning_age is deprecated and ignored. Magic Context now keeps reasoning up to a token budget, keep_reasoning_tokens (default 10,000). Remove the key, or set keep_reasoning_tokens to a token count.";
|
|
421
|
+
preMigrationWarnings.push(warning);
|
|
422
|
+
log(`[magic-context] ${warning}`);
|
|
423
|
+
}
|
|
418
424
|
if (Object.hasOwn(rawConfig, "protected_tags")) {
|
|
419
425
|
warnProtectedTagsDeprecationOnce();
|
|
420
426
|
preMigrationWarnings.push(
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
userMemoryCollectionEnabled,
|
|
8
8
|
} from "../features/magic-context/dreamer/task-config";
|
|
9
9
|
import { producerInputTokenLimit } from "../hooks/magic-context/producer-window-guard";
|
|
10
|
-
import { resolveHistorianModel } from "../shared/model-resolution";
|
|
10
|
+
import { resolveDreamerTaskModel, resolveHistorianModel } from "../shared/model-resolution";
|
|
11
11
|
import { createTestTempDirFromPath } from "../shared/test-temp-dir";
|
|
12
12
|
import { loadPluginConfigDetailed } from "./index";
|
|
13
13
|
import { dreamerRunConfig, historianRunConfig } from "./live-run-config";
|
|
@@ -248,3 +248,39 @@ test("malformed project config retains last good values and deduplicates the war
|
|
|
248
248
|
rmSync(root, { recursive: true, force: true });
|
|
249
249
|
}
|
|
250
250
|
});
|
|
251
|
+
|
|
252
|
+
test("OMP keeps the pi historian and dreamer models when the config has no omp block", () => {
|
|
253
|
+
// Live sampling used to create empty parent objects for every live path. An empty
|
|
254
|
+
// `omp` block then shadowed the `pi` block OMP falls back to, and OMP ran the
|
|
255
|
+
// historian and dreamer on its own default model.
|
|
256
|
+
const config = {
|
|
257
|
+
historian: { pi: { model: "anthropic/claude-sonnet-5-5" } },
|
|
258
|
+
dreamer: {
|
|
259
|
+
pi: {
|
|
260
|
+
model: "anthropic/claude-sonnet-5-5",
|
|
261
|
+
tasks: { curate: { model: "openai/gpt-6-luna" } },
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
} as unknown as Parameters<typeof historianRunConfig>[0];
|
|
265
|
+
for (const sampled of [historianRunConfig(config, config), dreamerRunConfig(config, config)]) {
|
|
266
|
+
expect((sampled as { historian?: Record<string, unknown> }).historian?.omp).toBeUndefined();
|
|
267
|
+
expect((sampled as { dreamer?: Record<string, unknown> }).dreamer?.omp).toBeUndefined();
|
|
268
|
+
expect(resolveHistorianModel(sampled, "omp").primary?.model).toBe(
|
|
269
|
+
"anthropic/claude-sonnet-5-5",
|
|
270
|
+
);
|
|
271
|
+
expect(
|
|
272
|
+
resolveDreamerTaskModel({ config: sampled, harness: "omp", task: "curate" }).primary
|
|
273
|
+
?.model,
|
|
274
|
+
).toBe("openai/gpt-6-luna");
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
test("live sampling clears a key removed from the fresh config without touching the boot object", () => {
|
|
279
|
+
const boot = {
|
|
280
|
+
historian: { pi: { model: "anthropic/claude-sonnet-5-5" } },
|
|
281
|
+
} as unknown as Parameters<typeof historianRunConfig>[0];
|
|
282
|
+
const fresh = { historian: { pi: {} } } as unknown as Parameters<typeof historianRunConfig>[0];
|
|
283
|
+
const sampled = historianRunConfig(boot, fresh);
|
|
284
|
+
expect(resolveHistorianModel(sampled, "pi").primary).toBeUndefined();
|
|
285
|
+
expect(resolveHistorianModel(boot, "pi").primary?.model).toBe("anthropic/claude-sonnet-5-5");
|
|
286
|
+
});
|