@cortexkit/opencode-magic-context 0.33.1 → 0.34.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/README.md +20 -3
- package/dist/config/agent-disable.d.ts +22 -0
- package/dist/config/agent-disable.d.ts.map +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/migrate-experimental.d.ts +2 -1
- package/dist/config/migrate-experimental.d.ts.map +1 -1
- package/dist/config/project-security.d.ts +9 -0
- package/dist/config/project-security.d.ts.map +1 -1
- package/dist/config/schema/magic-context.d.ts +90 -17
- package/dist/config/schema/magic-context.d.ts.map +1 -1
- package/dist/config/transform-mode.d.ts +2 -0
- package/dist/config/transform-mode.d.ts.map +1 -1
- package/dist/{conflict-warning-hook-n48c783v.js → conflict-warning-hook-fvpfvt0w.js} +1 -1
- package/dist/{derive-budgets-e9j09sjr.js → derive-budgets-9crp0cvd.js} +1 -1
- package/dist/features/builtin-commands/commands.d.ts +1 -1
- package/dist/features/builtin-commands/commands.d.ts.map +1 -1
- package/dist/features/magic-context/compaction-marker.d.ts +57 -0
- package/dist/features/magic-context/compaction-marker.d.ts.map +1 -1
- package/dist/features/magic-context/compartment-chunk-embedding.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/classify.d.ts +1 -0
- package/dist/features/magic-context/dreamer/classify.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/evaluate-smart-notes.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/map-memories.d.ts +1 -0
- package/dist/features/magic-context/dreamer/map-memories.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/refresh-primers.d.ts +1 -0
- package/dist/features/magic-context/dreamer/refresh-primers.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/storage-dream-runs.d.ts +2 -0
- package/dist/features/magic-context/dreamer/storage-dream-runs.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-executor.d.ts +4 -1
- package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-gates.d.ts +19 -1
- package/dist/features/magic-context/dreamer/task-gates.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-registry.d.ts +28 -0
- package/dist/features/magic-context/dreamer/task-registry.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-scheduler.d.ts +7 -1
- package/dist/features/magic-context/dreamer/task-scheduler.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/verify.d.ts +1 -0
- package/dist/features/magic-context/dreamer/verify.d.ts.map +1 -1
- package/dist/features/magic-context/fail-closed-block.d.ts +10 -0
- package/dist/features/magic-context/fail-closed-block.d.ts.map +1 -1
- package/dist/features/magic-context/git-commits/storage-git-commit-embeddings.d.ts.map +1 -1
- package/dist/features/magic-context/git-commits/storage-git-commits.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-identity.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-local.d.ts +7 -1
- package/dist/features/magic-context/memory/embedding-local.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding.d.ts.map +1 -1
- package/dist/features/magic-context/memory/memory-migration.d.ts.map +1 -1
- package/dist/features/magic-context/memory/project-identity.d.ts +2 -6
- package/dist/features/magic-context/memory/project-identity.d.ts.map +1 -1
- package/dist/features/magic-context/memory/storage-memory-embeddings.d.ts.map +1 -1
- package/dist/features/magic-context/migrations.d.ts +23 -1
- package/dist/features/magic-context/migrations.d.ts.map +1 -1
- package/dist/features/magic-context/mural/compress-cues.d.ts +1 -0
- package/dist/features/magic-context/mural/compress-cues.d.ts.map +1 -1
- package/dist/features/magic-context/mural/render-mural.d.ts.map +1 -1
- package/dist/features/magic-context/overflow-detection.d.ts +8 -1
- package/dist/features/magic-context/overflow-detection.d.ts.map +1 -1
- package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
- package/dist/features/magic-context/scheduler.d.ts.map +1 -1
- package/dist/features/magic-context/schema-fence-probe.d.ts +28 -0
- package/dist/features/magic-context/schema-fence-probe.d.ts.map +1 -0
- package/dist/features/magic-context/sidekick/agent.d.ts.map +1 -1
- package/dist/features/magic-context/smart-notes/compiler.d.ts.map +1 -1
- package/dist/features/magic-context/storage-db.d.ts +37 -2
- package/dist/features/magic-context/storage-db.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-persisted.d.ts +38 -4
- package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta.d.ts +1 -1
- package/dist/features/magic-context/storage-meta.d.ts.map +1 -1
- package/dist/features/magic-context/storage.d.ts +2 -2
- package/dist/features/magic-context/storage.d.ts.map +1 -1
- package/dist/features/magic-context/user-memory/review-user-memories.d.ts.map +1 -1
- package/dist/hooks/magic-context/boundary-execution.d.ts +1 -1
- package/dist/hooks/magic-context/boundary-execution.d.ts.map +1 -1
- package/dist/hooks/magic-context/cache-busting-signals.d.ts +1 -0
- package/dist/hooks/magic-context/cache-busting-signals.d.ts.map +1 -1
- package/dist/hooks/magic-context/child-session-spawn.d.ts +26 -0
- package/dist/hooks/magic-context/child-session-spawn.d.ts.map +1 -0
- package/dist/hooks/magic-context/command-handler.d.ts +3 -0
- package/dist/hooks/magic-context/command-handler.d.ts.map +1 -1
- package/dist/hooks/magic-context/compaction-off-transition.d.ts +96 -0
- package/dist/hooks/magic-context/compaction-off-transition.d.ts.map +1 -0
- package/dist/hooks/magic-context/compartment-runner-historian.d.ts +2 -0
- package/dist/hooks/magic-context/compartment-runner-historian.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-mapping.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-partial-recomp.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-recomp.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-trigger.d.ts +12 -5
- package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -1
- package/dist/hooks/magic-context/ctx-reduce-availability.d.ts +47 -1
- package/dist/hooks/magic-context/ctx-reduce-availability.d.ts.map +1 -1
- package/dist/hooks/magic-context/emergency-drop.d.ts +2 -2
- package/dist/hooks/magic-context/event-handler.d.ts +7 -0
- package/dist/hooks/magic-context/event-handler.d.ts.map +1 -1
- package/dist/hooks/magic-context/event-resolvers.d.ts +13 -21
- package/dist/hooks/magic-context/event-resolvers.d.ts.map +1 -1
- package/dist/hooks/magic-context/execute-status.d.ts +5 -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 +1 -1
- package/dist/hooks/magic-context/hook-handlers.d.ts +1 -0
- package/dist/hooks/magic-context/hook-handlers.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook.d.ts +14 -6
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/inject-compartments.d.ts +10 -1
- package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
- package/dist/hooks/magic-context/live-session-state.d.ts +3 -0
- package/dist/hooks/magic-context/live-session-state.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-db.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/rust-mode-transform.d.ts +3 -0
- package/dist/hooks/magic-context/rust-mode-transform.d.ts.map +1 -1
- package/dist/hooks/magic-context/send-session-notification.d.ts +20 -1
- package/dist/hooks/magic-context/send-session-notification.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts +3 -0
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +31 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts +29 -2
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/{index-56yjaeb2.js → index-2y0ybv5x.js} +11 -1
- package/dist/{index-ey1bc14z.js → index-b563sga5.js} +7 -264
- package/dist/{index-y1c9tcm3.js → index-cn960ffd.js} +101 -20
- package/dist/{index-xyaekybw.js → index-dtas91s5.js} +6 -4
- package/dist/index-fcyvznch.js +279 -0
- package/dist/{index-63dq2g4d.js → index-ry8rh8cv.js} +138 -24
- package/dist/{index-c2gahrks.js → index-x8spt5wy.js} +1682 -893
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1677 -723
- package/dist/plugin/dream-timer.d.ts +4 -2
- package/dist/plugin/dream-timer.d.ts.map +1 -1
- package/dist/plugin/embedding-bootstrap.d.ts.map +1 -1
- package/dist/plugin/hooks/create-session-hooks.d.ts +12 -1
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/plugin/messages-transform.d.ts +10 -0
- package/dist/plugin/messages-transform.d.ts.map +1 -1
- package/dist/plugin/rpc-handlers.d.ts +3 -7
- package/dist/plugin/rpc-handlers.d.ts.map +1 -1
- package/dist/plugin/tool-registry.d.ts +8 -0
- package/dist/plugin/tool-registry.d.ts.map +1 -1
- package/dist/{recomp-orchestrator-2yb2hfh2.js → recomp-orchestrator-k72ejkkh.js} +6 -4
- package/dist/send-session-notification-6njqewzk.js +20 -0
- package/dist/shared/conflict-detector.d.ts +38 -1
- package/dist/shared/conflict-detector.d.ts.map +1 -1
- package/dist/shared/conflict-fixer.d.ts +18 -1
- package/dist/shared/conflict-fixer.d.ts.map +1 -1
- package/dist/shared/context-limit-provenance.d.ts +3 -0
- package/dist/shared/context-limit-provenance.d.ts.map +1 -0
- package/dist/shared/escalation-bands.d.ts +9 -0
- package/dist/shared/escalation-bands.d.ts.map +1 -0
- package/dist/shared/format-threshold.d.ts +1 -1
- package/dist/shared/models-dev-cache.d.ts +29 -3
- package/dist/shared/models-dev-cache.d.ts.map +1 -1
- package/dist/shared/rpc-server.d.ts.map +1 -1
- package/dist/shared/rpc-types.d.ts +51 -1
- package/dist/shared/rpc-types.d.ts.map +1 -1
- package/dist/shared/rpc-utils.d.ts +19 -0
- package/dist/shared/rpc-utils.d.ts.map +1 -1
- package/dist/shared/storage-permissions.d.ts +5 -0
- package/dist/shared/storage-permissions.d.ts.map +1 -0
- package/dist/shared/tui-runtime-specifiers.d.ts +20 -0
- package/dist/shared/tui-runtime-specifiers.d.ts.map +1 -0
- package/dist/{storage-meta-session-td6bwtky.js → storage-meta-session-xt41zbw4.js} +2 -1
- package/dist/{task-config-5nx3qfz8.js → task-config-gbp7r23g.js} +1 -1
- package/dist/tui/compaction-off.d.ts +13 -0
- package/dist/tui/compaction-off.d.ts.map +1 -0
- package/dist/tui/data/context-db.d.ts.map +1 -1
- package/dist/tui-compiled/compaction-off.d.ts +13 -0
- package/dist/tui-compiled/compaction-off.d.ts.map +1 -0
- package/dist/tui-compiled/data/context-db.d.ts.map +1 -1
- package/package.json +6 -1
- package/src/agents/dreamer.ts +68 -0
- package/src/agents/hidden-agent-registrations.ts +331 -0
- package/src/agents/historian.ts +3 -0
- package/src/agents/language-directive.test.ts +138 -0
- package/src/agents/language-directive.ts +121 -0
- package/src/agents/magic-context-prompt.language.test.ts +35 -0
- package/src/agents/magic-context-prompt.test.ts +292 -0
- package/src/agents/magic-context-prompt.ts +182 -0
- package/src/agents/permissions.test.ts +252 -0
- package/src/agents/permissions.ts +186 -0
- package/src/agents/sidekick.ts +1 -0
- package/src/agents/smart-note-compiler.ts +1 -0
- package/src/config/agent-disable.ts +106 -0
- package/src/config/compaction-accessor-guard.test.ts +82 -0
- package/src/config/compaction-backcompat.test.ts +52 -0
- package/src/config/index.test.ts +936 -0
- package/src/config/index.ts +601 -0
- package/src/config/migrate-config-location.test.ts +332 -0
- package/src/config/migrate-config-location.ts +635 -0
- package/src/config/migrate-dreamer-v2.test.ts +287 -0
- package/src/config/migrate-dreamer-v2.ts +336 -0
- package/src/config/migrate-experimental.test.ts +41 -0
- package/src/config/migrate-experimental.ts +185 -0
- package/src/config/project-security.test.ts +388 -0
- package/src/config/project-security.ts +611 -0
- package/src/config/prune-config-leaf.test.ts +78 -0
- package/src/config/prune-config-leaf.ts +68 -0
- package/src/config/removed-config-keys.test.ts +116 -0
- package/src/config/schema/agent-overrides.ts +45 -0
- package/src/config/schema/magic-context.test.ts +359 -0
- package/src/config/schema/magic-context.ts +991 -0
- package/src/config/transform-mode.test.ts +62 -0
- package/src/config/transform-mode.ts +34 -0
- package/src/config/variable.test.ts +323 -0
- package/src/config/variable.ts +192 -0
- package/src/features/magic-context/defaults.ts +1 -0
- package/src/features/magic-context/dreamer/cron.ts +243 -0
- package/src/features/magic-context/dreamer/task-registry.ts +151 -0
- package/src/shared/conflict-detector.test.ts +121 -0
- package/src/shared/conflict-detector.ts +50 -3
- package/src/shared/conflict-fixer.test.ts +309 -0
- package/src/shared/conflict-fixer.ts +82 -5
- package/src/shared/context-limit-provenance.ts +6 -0
- package/src/shared/escalation-bands.test.ts +23 -0
- package/src/shared/escalation-bands.ts +18 -0
- package/src/shared/format-threshold.ts +1 -1
- package/src/shared/models-dev-cache.test.ts +171 -0
- package/src/shared/models-dev-cache.ts +195 -38
- package/src/shared/rpc-server.ts +27 -18
- package/src/shared/rpc-types.ts +55 -1
- package/src/shared/rpc-utils.test.ts +157 -0
- package/src/shared/rpc-utils.ts +137 -0
- package/src/shared/storage-permissions.ts +20 -0
- package/src/shared/tui-runtime-specifiers.ts +32 -0
- package/src/tui/compaction-off.test.ts +56 -0
- package/src/tui/compaction-off.ts +29 -0
- package/src/tui/data/context-db.ts +6 -0
- package/src/tui/index.tsx +113 -65
- package/src/tui/slots/sidebar-content.tsx +189 -91
- package/src/tui/tui-compiled-runtime-imports.test.ts +151 -0
- package/src/tui-compiled/compaction-off.ts +29 -0
- package/src/tui-compiled/data/context-db.ts +6 -0
- package/src/tui-compiled/index.tsx +558 -455
- package/src/tui-compiled/slots/sidebar-content.tsx +334 -169
- package/dist/send-session-notification-tghq9gnh.js +0 -11
- /package/dist/{index-v7fmc1s2.js → index-ygcng9t8.js} +0 -0
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isMidTurn
|
|
3
|
+
} from "./index-fcyvznch.js";
|
|
1
4
|
import {
|
|
2
5
|
sessionLog
|
|
3
6
|
} from "./index-k1esqfwk.js";
|
|
@@ -82,6 +85,56 @@ function safeString(value) {
|
|
|
82
85
|
}
|
|
83
86
|
|
|
84
87
|
// src/hooks/magic-context/send-session-notification.ts
|
|
88
|
+
var MAX_QUEUED_IGNORED_NOTIFICATIONS = 16;
|
|
89
|
+
var queuedIgnoredNotifications = new Map;
|
|
90
|
+
var flushingIgnoredNotifications = new Set;
|
|
91
|
+
var midTurnDetector = (sessionId) => isMidTurn(undefined, sessionId);
|
|
92
|
+
function queueIgnoredNotification(notification) {
|
|
93
|
+
const queued = queuedIgnoredNotifications.get(notification.sessionId) ?? [];
|
|
94
|
+
queued.push(notification);
|
|
95
|
+
if (queued.length > MAX_QUEUED_IGNORED_NOTIFICATIONS) {
|
|
96
|
+
queued.splice(0, queued.length - MAX_QUEUED_IGNORED_NOTIFICATIONS);
|
|
97
|
+
sessionLog(notification.sessionId, `ignored notification queue full; dropped oldest entries (kept newest ${MAX_QUEUED_IGNORED_NOTIFICATIONS})`);
|
|
98
|
+
}
|
|
99
|
+
queuedIgnoredNotifications.set(notification.sessionId, queued);
|
|
100
|
+
}
|
|
101
|
+
async function trySendTuiToast(sessionId, text, params, forcePersist) {
|
|
102
|
+
if (forcePersist)
|
|
103
|
+
return false;
|
|
104
|
+
const title = extractToastTitle(text);
|
|
105
|
+
const message = text.length > 200 ? `${text.slice(0, 200)}…` : text;
|
|
106
|
+
const toastVariant = inferToastVariant(text);
|
|
107
|
+
const duration = params.toastDurationMs ?? 5000;
|
|
108
|
+
const { isTuiConnected: checkTui } = await import("./rpc-notifications-4d22ybn5.js");
|
|
109
|
+
if (!checkTui(sessionId))
|
|
110
|
+
return false;
|
|
111
|
+
try {
|
|
112
|
+
const { pushNotification } = await import("./rpc-notifications-4d22ybn5.js");
|
|
113
|
+
pushNotification("toast", {
|
|
114
|
+
title,
|
|
115
|
+
message,
|
|
116
|
+
variant: toastVariant,
|
|
117
|
+
duration
|
|
118
|
+
}, sessionId);
|
|
119
|
+
return true;
|
|
120
|
+
} catch {
|
|
121
|
+
sessionLog(sessionId, "TUI RPC toast enqueue failed, falling back to ignored message");
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
var __ignoredNotificationTest = {
|
|
126
|
+
pendingTexts(sessionId) {
|
|
127
|
+
return (queuedIgnoredNotifications.get(sessionId) ?? []).map((item) => item.text);
|
|
128
|
+
},
|
|
129
|
+
reset() {
|
|
130
|
+
queuedIgnoredNotifications.clear();
|
|
131
|
+
flushingIgnoredNotifications.clear();
|
|
132
|
+
midTurnDetector = (sessionId) => isMidTurn(undefined, sessionId);
|
|
133
|
+
},
|
|
134
|
+
setMidTurnDetector(detector) {
|
|
135
|
+
midTurnDetector = detector;
|
|
136
|
+
}
|
|
137
|
+
};
|
|
85
138
|
function hasNotificationSessionClient(client) {
|
|
86
139
|
if (client === null || typeof client !== "object")
|
|
87
140
|
return false;
|
|
@@ -113,31 +166,20 @@ function extractToastTitle(text) {
|
|
|
113
166
|
return firstLine;
|
|
114
167
|
return "Magic Context";
|
|
115
168
|
}
|
|
116
|
-
async function
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const duration = params.toastDurationMs ?? 5000;
|
|
121
|
-
const { isTuiConnected: checkTui } = await import("./rpc-notifications-4d22ybn5.js");
|
|
122
|
-
if (!forcePersist && checkTui(sessionId)) {
|
|
123
|
-
try {
|
|
124
|
-
const { pushNotification } = await import("./rpc-notifications-4d22ybn5.js");
|
|
125
|
-
pushNotification("toast", {
|
|
126
|
-
title,
|
|
127
|
-
message,
|
|
128
|
-
variant: toastVariant,
|
|
129
|
-
duration
|
|
130
|
-
}, sessionId);
|
|
131
|
-
return "sent";
|
|
132
|
-
} catch {
|
|
133
|
-
sessionLog(sessionId, "TUI RPC toast enqueue failed, falling back to ignored message");
|
|
134
|
-
}
|
|
169
|
+
async function sendIgnoredMessageNow(client, sessionId, text, params, forcePersist) {
|
|
170
|
+
if (midTurnDetector(sessionId)) {
|
|
171
|
+
queueIgnoredNotification({ client, sessionId, text, params, forcePersist });
|
|
172
|
+
return "queued";
|
|
135
173
|
}
|
|
136
174
|
const { waitForSafeNotificationTarget } = await import("./safe-notification-target-q9jk5n44.js");
|
|
137
175
|
if (await waitForSafeNotificationTarget(client, sessionId) === "skip") {
|
|
138
176
|
sessionLog(sessionId, "notification skipped (session not titled yet)");
|
|
139
177
|
return "skipped";
|
|
140
178
|
}
|
|
179
|
+
if (midTurnDetector(sessionId)) {
|
|
180
|
+
queueIgnoredNotification({ client, sessionId, text, params, forcePersist });
|
|
181
|
+
return "queued";
|
|
182
|
+
}
|
|
141
183
|
if (!hasNotificationSessionClient(client)) {
|
|
142
184
|
sessionLog(sessionId, "session prompt API unavailable for notification");
|
|
143
185
|
return "failed";
|
|
@@ -157,6 +199,10 @@ async function sendIgnoredMessage(client, sessionId, text, params, forcePersist
|
|
|
157
199
|
}
|
|
158
200
|
} catch {}
|
|
159
201
|
}
|
|
202
|
+
if (midTurnDetector(sessionId)) {
|
|
203
|
+
queueIgnoredNotification({ client, sessionId, text, params, forcePersist });
|
|
204
|
+
return "queued";
|
|
205
|
+
}
|
|
160
206
|
const input = {
|
|
161
207
|
path: { id: sessionId },
|
|
162
208
|
body: {
|
|
@@ -190,6 +236,41 @@ async function sendIgnoredMessage(client, sessionId, text, params, forcePersist
|
|
|
190
236
|
return "failed";
|
|
191
237
|
}
|
|
192
238
|
}
|
|
239
|
+
async function sendIgnoredMessage(client, sessionId, text, params, forcePersist = false) {
|
|
240
|
+
if (await trySendTuiToast(sessionId, text, params, forcePersist))
|
|
241
|
+
return "sent";
|
|
242
|
+
if (midTurnDetector(sessionId)) {
|
|
243
|
+
queueIgnoredNotification({ client, sessionId, text, params, forcePersist });
|
|
244
|
+
return "queued";
|
|
245
|
+
}
|
|
246
|
+
return sendIgnoredMessageNow(client, sessionId, text, params, forcePersist);
|
|
247
|
+
}
|
|
248
|
+
async function flushIgnoredMessages(sessionId) {
|
|
249
|
+
if (flushingIgnoredNotifications.has(sessionId) || midTurnDetector(sessionId))
|
|
250
|
+
return;
|
|
251
|
+
const queued = queuedIgnoredNotifications.get(sessionId);
|
|
252
|
+
if (!queued || queued.length === 0)
|
|
253
|
+
return;
|
|
254
|
+
queuedIgnoredNotifications.delete(sessionId);
|
|
255
|
+
flushingIgnoredNotifications.add(sessionId);
|
|
256
|
+
try {
|
|
257
|
+
for (const notification of queued) {
|
|
258
|
+
const disposition = await sendIgnoredMessage(notification.client, notification.sessionId, notification.text, notification.params, notification.forcePersist);
|
|
259
|
+
if (disposition === "queued") {
|
|
260
|
+
for (const remaining of queued.slice(queued.indexOf(notification) + 1)) {
|
|
261
|
+
queueIgnoredNotification(remaining);
|
|
262
|
+
}
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
} finally {
|
|
267
|
+
flushingIgnoredNotifications.delete(sessionId);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
function clearIgnoredMessages(sessionId) {
|
|
271
|
+
queuedIgnoredNotifications.delete(sessionId);
|
|
272
|
+
flushingIgnoredNotifications.delete(sessionId);
|
|
273
|
+
}
|
|
193
274
|
async function sendUserPrompt(client, sessionId, text) {
|
|
194
275
|
if (!hasNotificationSessionClient(client)) {
|
|
195
276
|
sessionLog(sessionId, "session prompt API unavailable for user prompt");
|
|
@@ -216,4 +297,4 @@ async function sendUserPrompt(client, sessionId, text) {
|
|
|
216
297
|
}
|
|
217
298
|
}
|
|
218
299
|
|
|
219
|
-
export { getErrorMessage, describeError, sendIgnoredMessage, sendUserPrompt };
|
|
300
|
+
export { getErrorMessage, describeError, MAX_QUEUED_IGNORED_NOTIFICATIONS, __ignoredNotificationTest, sendIgnoredMessage, flushIgnoredMessages, clearIgnoredMessages, sendUserPrompt };
|
|
@@ -160,7 +160,8 @@ function getOpenCodeConfigPaths(options) {
|
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
// src/shared/conflict-detector.ts
|
|
163
|
-
function detectConflicts(directory) {
|
|
163
|
+
function detectConflicts(directory, options) {
|
|
164
|
+
const compactionEnabled = options?.compactionEnabled ?? true;
|
|
164
165
|
const conflicts = {
|
|
165
166
|
compactionAuto: false,
|
|
166
167
|
compactionPrune: false,
|
|
@@ -171,11 +172,11 @@ function detectConflicts(directory) {
|
|
|
171
172
|
};
|
|
172
173
|
const reasons = [];
|
|
173
174
|
const compactionResult = checkCompaction(directory);
|
|
174
|
-
if (compactionResult.auto) {
|
|
175
|
+
if (compactionEnabled && compactionResult.auto) {
|
|
175
176
|
conflicts.compactionAuto = true;
|
|
176
177
|
reasons.push("OpenCode auto-compaction is enabled (compaction.auto=true)");
|
|
177
178
|
}
|
|
178
|
-
if (compactionResult.prune) {
|
|
179
|
+
if (compactionEnabled && compactionResult.prune) {
|
|
179
180
|
conflicts.compactionPrune = true;
|
|
180
181
|
reasons.push("OpenCode prune is enabled (compaction.prune=true)");
|
|
181
182
|
}
|
|
@@ -200,7 +201,8 @@ function detectConflicts(directory) {
|
|
|
200
201
|
return {
|
|
201
202
|
hasConflict: reasons.length > 0,
|
|
202
203
|
reasons,
|
|
203
|
-
conflicts
|
|
204
|
+
conflicts,
|
|
205
|
+
nativeCompaction: { auto: compactionResult.auto, prune: compactionResult.prune }
|
|
204
206
|
};
|
|
205
207
|
}
|
|
206
208
|
function checkCompaction(directory) {
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import {
|
|
2
|
+
log
|
|
3
|
+
} from "./index-k1esqfwk.js";
|
|
4
|
+
import {
|
|
5
|
+
getDataDir
|
|
6
|
+
} from "./index-kvrcg31b.js";
|
|
7
|
+
|
|
8
|
+
// src/shared/sqlite-helpers.ts
|
|
9
|
+
function closeQuietly(db) {
|
|
10
|
+
if (!db)
|
|
11
|
+
return;
|
|
12
|
+
try {
|
|
13
|
+
db.close();
|
|
14
|
+
} catch {}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// src/hooks/magic-context/read-session-db.ts
|
|
18
|
+
import { existsSync } from "node:fs";
|
|
19
|
+
import { join } from "node:path";
|
|
20
|
+
|
|
21
|
+
// src/shared/sqlite.ts
|
|
22
|
+
var isBun = typeof process !== "undefined" && typeof process.versions?.bun === "string";
|
|
23
|
+
var bunSpec = "bun:" + "sqlite";
|
|
24
|
+
var nodeSpec = "node:" + "sqlite";
|
|
25
|
+
var sqliteModule = isBun ? await import(bunSpec) : await import(nodeSpec);
|
|
26
|
+
var DatabaseImpl = isBun ? sqliteModule.Database : buildNodeSqliteDatabaseClass(sqliteModule.DatabaseSync);
|
|
27
|
+
function buildNodeSqliteDatabaseClass(DatabaseSync) {
|
|
28
|
+
const SAVEPOINT = "mc_tx_sp";
|
|
29
|
+
|
|
30
|
+
class NodeSqliteDatabase extends DatabaseSync {
|
|
31
|
+
constructor(filename, options) {
|
|
32
|
+
const translated = { ...options };
|
|
33
|
+
if (options && "readonly" in options) {
|
|
34
|
+
translated.readOnly = options.readonly;
|
|
35
|
+
delete translated.readonly;
|
|
36
|
+
}
|
|
37
|
+
super(typeof filename === "string" ? filename : ":memory:", translated);
|
|
38
|
+
}
|
|
39
|
+
prepare(sql) {
|
|
40
|
+
const stmt = super.prepare(sql);
|
|
41
|
+
for (const method of ["run", "get", "all"]) {
|
|
42
|
+
const original = stmt[method].bind(stmt);
|
|
43
|
+
stmt[method] = (...args) => args.length === 1 && Array.isArray(args[0]) ? original(...args[0]) : original(...args);
|
|
44
|
+
}
|
|
45
|
+
return stmt;
|
|
46
|
+
}
|
|
47
|
+
transaction(fn) {
|
|
48
|
+
const self = this;
|
|
49
|
+
const execute = (mode, receiver, args) => {
|
|
50
|
+
const nested = self.isTransaction === true;
|
|
51
|
+
self.exec(nested ? `SAVEPOINT ${SAVEPOINT}` : `BEGIN${mode ? ` ${mode}` : ""}`);
|
|
52
|
+
try {
|
|
53
|
+
const result = fn.apply(receiver, args);
|
|
54
|
+
self.exec(nested ? `RELEASE ${SAVEPOINT}` : "COMMIT");
|
|
55
|
+
return result;
|
|
56
|
+
} catch (error) {
|
|
57
|
+
if (nested) {
|
|
58
|
+
self.exec(`ROLLBACK TO ${SAVEPOINT}`);
|
|
59
|
+
self.exec(`RELEASE ${SAVEPOINT}`);
|
|
60
|
+
} else {
|
|
61
|
+
self.exec("ROLLBACK");
|
|
62
|
+
}
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const wrapped = function(...args) {
|
|
67
|
+
return execute("", this, args);
|
|
68
|
+
};
|
|
69
|
+
wrapped.default = function(...args) {
|
|
70
|
+
return execute("", this, args);
|
|
71
|
+
};
|
|
72
|
+
wrapped.deferred = function(...args) {
|
|
73
|
+
return execute("DEFERRED", this, args);
|
|
74
|
+
};
|
|
75
|
+
wrapped.immediate = function(...args) {
|
|
76
|
+
return execute("IMMEDIATE", this, args);
|
|
77
|
+
};
|
|
78
|
+
wrapped.exclusive = function(...args) {
|
|
79
|
+
return execute("EXCLUSIVE", this, args);
|
|
80
|
+
};
|
|
81
|
+
return wrapped;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return NodeSqliteDatabase;
|
|
85
|
+
}
|
|
86
|
+
var Database = DatabaseImpl;
|
|
87
|
+
var privilegeDepth = new WeakMap;
|
|
88
|
+
function isInTransaction(db) {
|
|
89
|
+
const candidate = db;
|
|
90
|
+
return candidate.inTransaction === true || candidate.isTransaction === true;
|
|
91
|
+
}
|
|
92
|
+
function withPrivilegedWriter(db, operation) {
|
|
93
|
+
const previousDepth = privilegeDepth.get(db) ?? 0;
|
|
94
|
+
const nested = isInTransaction(db);
|
|
95
|
+
const savepoint = "mc_privilege_scope";
|
|
96
|
+
if (nested) {
|
|
97
|
+
db.exec(`SAVEPOINT ${savepoint}`);
|
|
98
|
+
} else {
|
|
99
|
+
db.exec("BEGIN IMMEDIATE");
|
|
100
|
+
}
|
|
101
|
+
privilegeDepth.set(db, previousDepth + 1);
|
|
102
|
+
try {
|
|
103
|
+
db.prepare("INSERT INTO context_privilege_state(id, enabled) VALUES (1, 1) ON CONFLICT(id) DO UPDATE SET enabled = 1").run();
|
|
104
|
+
const result = operation();
|
|
105
|
+
if (previousDepth === 0) {
|
|
106
|
+
db.prepare("UPDATE context_privilege_state SET enabled = 0 WHERE id = 1").run();
|
|
107
|
+
}
|
|
108
|
+
if (nested) {
|
|
109
|
+
db.exec(`RELEASE ${savepoint}`);
|
|
110
|
+
} else {
|
|
111
|
+
db.exec("COMMIT");
|
|
112
|
+
}
|
|
113
|
+
if (previousDepth > 0)
|
|
114
|
+
privilegeDepth.set(db, previousDepth);
|
|
115
|
+
else
|
|
116
|
+
privilegeDepth.delete(db);
|
|
117
|
+
return result;
|
|
118
|
+
} catch (error) {
|
|
119
|
+
try {
|
|
120
|
+
if (nested) {
|
|
121
|
+
db.exec(`ROLLBACK TO ${savepoint}`);
|
|
122
|
+
db.exec(`RELEASE ${savepoint}`);
|
|
123
|
+
} else {
|
|
124
|
+
db.exec("ROLLBACK");
|
|
125
|
+
}
|
|
126
|
+
} finally {
|
|
127
|
+
if (previousDepth > 0)
|
|
128
|
+
privilegeDepth.set(db, previousDepth);
|
|
129
|
+
else
|
|
130
|
+
privilegeDepth.delete(db);
|
|
131
|
+
}
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// src/hooks/magic-context/read-session-db.ts
|
|
137
|
+
function getOpenCodeDbPath() {
|
|
138
|
+
return join(getDataDir(), "opencode", "opencode.db");
|
|
139
|
+
}
|
|
140
|
+
function openCodeDbExists() {
|
|
141
|
+
return existsSync(getOpenCodeDbPath());
|
|
142
|
+
}
|
|
143
|
+
var cachedReadOnlyDb = null;
|
|
144
|
+
function closeCachedReadOnlyDb() {
|
|
145
|
+
if (!cachedReadOnlyDb) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
closeQuietly(cachedReadOnlyDb.db);
|
|
150
|
+
} catch (error) {
|
|
151
|
+
log("[magic-context] failed to close cached OpenCode read-only DB:", error);
|
|
152
|
+
} finally {
|
|
153
|
+
cachedReadOnlyDb = null;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function getReadOnlySessionDb() {
|
|
157
|
+
const dbPath = getOpenCodeDbPath();
|
|
158
|
+
if (cachedReadOnlyDb?.path === dbPath) {
|
|
159
|
+
return cachedReadOnlyDb.db;
|
|
160
|
+
}
|
|
161
|
+
closeCachedReadOnlyDb();
|
|
162
|
+
const db = new Database(dbPath, { readonly: true });
|
|
163
|
+
cachedReadOnlyDb = { path: dbPath, db };
|
|
164
|
+
return db;
|
|
165
|
+
}
|
|
166
|
+
function withReadOnlySessionDb(fn) {
|
|
167
|
+
return fn(getReadOnlySessionDb());
|
|
168
|
+
}
|
|
169
|
+
function getRawSessionMessageCountFromDb(db, sessionId) {
|
|
170
|
+
const row = db.prepare(`SELECT COUNT(*) as count FROM message WHERE session_id = ?
|
|
171
|
+
AND NOT (COALESCE(json_extract(data, '$.summary'), 0) = 1
|
|
172
|
+
AND COALESCE(json_extract(data, '$.finish'), '') = 'stop')`).get(sessionId);
|
|
173
|
+
return typeof row?.count === "number" ? row.count : 0;
|
|
174
|
+
}
|
|
175
|
+
function isMidTurn(_deps, sessionId) {
|
|
176
|
+
try {
|
|
177
|
+
return withReadOnlySessionDb((db) => isMidTurnFromOpenCodeDb(db, sessionId));
|
|
178
|
+
} catch (error) {
|
|
179
|
+
log("[magic-context] failed to inspect OpenCode mid-turn state:", error);
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function isMidTurnFromOpenCodeDb(db, sessionId) {
|
|
184
|
+
const latestAssistant = db.prepare(`SELECT id,
|
|
185
|
+
json_extract(data, '$.finish') as finish,
|
|
186
|
+
time_created as timeCreated
|
|
187
|
+
FROM message
|
|
188
|
+
WHERE session_id = ?
|
|
189
|
+
AND json_extract(data, '$.role') = 'assistant'
|
|
190
|
+
ORDER BY time_created DESC
|
|
191
|
+
LIMIT 1`).get(sessionId);
|
|
192
|
+
if (typeof latestAssistant?.id !== "string")
|
|
193
|
+
return false;
|
|
194
|
+
if (hasNewerRealUserMessage(db, sessionId, latestAssistant.timeCreated))
|
|
195
|
+
return false;
|
|
196
|
+
if (latestAssistant.finish === "tool-calls")
|
|
197
|
+
return true;
|
|
198
|
+
const partRows = db.prepare("SELECT data FROM part WHERE session_id = ? AND message_id = ?").all(sessionId, latestAssistant.id);
|
|
199
|
+
return partRows.some((row) => {
|
|
200
|
+
if (typeof row.data !== "string" || row.data.length === 0)
|
|
201
|
+
return false;
|
|
202
|
+
try {
|
|
203
|
+
const part = JSON.parse(row.data);
|
|
204
|
+
return part.type === "tool" && part.providerExecuted !== true;
|
|
205
|
+
} catch {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
function hasNewerRealUserMessage(db, sessionId, latestAssistantTimeCreated) {
|
|
211
|
+
if (typeof latestAssistantTimeCreated !== "number")
|
|
212
|
+
return false;
|
|
213
|
+
const row = db.prepare(`SELECT 1 as one
|
|
214
|
+
FROM message m
|
|
215
|
+
WHERE m.session_id = ?
|
|
216
|
+
AND m.time_created > ?
|
|
217
|
+
AND json_extract(m.data, '$.role') = 'user'
|
|
218
|
+
AND NOT (
|
|
219
|
+
EXISTS (SELECT 1 FROM part p WHERE p.message_id = m.id)
|
|
220
|
+
AND NOT EXISTS (
|
|
221
|
+
SELECT 1 FROM part p
|
|
222
|
+
WHERE p.message_id = m.id
|
|
223
|
+
AND COALESCE(json_extract(p.data, '$.synthetic'), 0) NOT IN (1, 'true')
|
|
224
|
+
AND json_extract(p.data, '$.metadata.marker.kind') IS NULL
|
|
225
|
+
AND COALESCE(json_extract(p.data, '$.ignored'), 0) NOT IN (1, 'true')
|
|
226
|
+
)
|
|
227
|
+
)
|
|
228
|
+
LIMIT 1`).get(sessionId, latestAssistantTimeCreated);
|
|
229
|
+
return row?.one === 1;
|
|
230
|
+
}
|
|
231
|
+
function getMessageTimesFromOpenCodeDb(sessionId, messageIds) {
|
|
232
|
+
const result = new Map;
|
|
233
|
+
if (messageIds.length === 0)
|
|
234
|
+
return result;
|
|
235
|
+
try {
|
|
236
|
+
withReadOnlySessionDb((db) => {
|
|
237
|
+
const placeholders = messageIds.map(() => "?").join(",");
|
|
238
|
+
const rows = db.prepare(`SELECT id, time_created FROM message WHERE session_id = ? AND id IN (${placeholders})`).all(sessionId, ...messageIds);
|
|
239
|
+
for (const row of rows) {
|
|
240
|
+
if (typeof row.id === "string" && typeof row.time_created === "number") {
|
|
241
|
+
result.set(row.id, row.time_created);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
} catch (error) {
|
|
246
|
+
log("[magic-context] failed to resolve message times from OpenCode DB:", error);
|
|
247
|
+
}
|
|
248
|
+
return result;
|
|
249
|
+
}
|
|
250
|
+
function findLastAssistantModelFromOpenCodeDb(sessionId) {
|
|
251
|
+
try {
|
|
252
|
+
return withReadOnlySessionDb((db) => {
|
|
253
|
+
const row = db.prepare(`SELECT json_extract(data, '$.providerID') as providerID,
|
|
254
|
+
json_extract(data, '$.modelID') as modelID,
|
|
255
|
+
json_extract(data, '$.agent') as agent
|
|
256
|
+
FROM message
|
|
257
|
+
WHERE session_id = ?
|
|
258
|
+
AND json_extract(data, '$.role') = 'assistant'
|
|
259
|
+
AND json_extract(data, '$.providerID') IS NOT NULL
|
|
260
|
+
AND json_extract(data, '$.modelID') IS NOT NULL
|
|
261
|
+
ORDER BY time_created DESC
|
|
262
|
+
LIMIT 1`).get(sessionId);
|
|
263
|
+
if (!row || typeof row.providerID !== "string" || typeof row.modelID !== "string") {
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
const agent = typeof row.agent === "string" && row.agent.length > 0 ? row.agent : undefined;
|
|
267
|
+
return {
|
|
268
|
+
providerID: row.providerID,
|
|
269
|
+
modelID: row.modelID,
|
|
270
|
+
...agent ? { agent } : {}
|
|
271
|
+
};
|
|
272
|
+
});
|
|
273
|
+
} catch (error) {
|
|
274
|
+
log("[magic-context] failed to recover live model from OpenCode DB:", error);
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export { Database, withPrivilegedWriter, closeQuietly, openCodeDbExists, withReadOnlySessionDb, getRawSessionMessageCountFromDb, isMidTurn, getMessageTimesFromOpenCodeDb, findLastAssistantModelFromOpenCodeDb };
|