@cortexkit/opencode-magic-context 0.5.1 → 0.6.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/README.md +18 -2
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/setup.d.ts.map +1 -1
- package/dist/cli.js +23 -6
- package/dist/config/schema/magic-context.d.ts +21 -0
- package/dist/config/schema/magic-context.d.ts.map +1 -1
- package/dist/features/magic-context/compaction-marker.d.ts +72 -0
- package/dist/features/magic-context/compaction-marker.d.ts.map +1 -0
- package/dist/features/magic-context/dreamer/runner.d.ts +8 -0
- package/dist/features/magic-context/dreamer/runner.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/scheduler.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-local.d.ts.map +1 -1
- package/dist/features/magic-context/migrations.d.ts +8 -0
- package/dist/features/magic-context/migrations.d.ts.map +1 -0
- package/dist/features/magic-context/plugin-messages.d.ts +75 -0
- package/dist/features/magic-context/plugin-messages.d.ts.map +1 -0
- package/dist/features/magic-context/storage-db.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-persisted.d.ts +10 -0
- package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
- package/dist/features/magic-context/storage-notes.d.ts +51 -5
- package/dist/features/magic-context/storage-notes.d.ts.map +1 -1
- package/dist/features/magic-context/storage.d.ts +1 -2
- package/dist/features/magic-context/storage.d.ts.map +1 -1
- package/dist/features/magic-context/user-memory/review-user-memories.d.ts +20 -0
- package/dist/features/magic-context/user-memory/review-user-memories.d.ts.map +1 -0
- package/dist/features/magic-context/user-memory/storage-user-memory.d.ts +33 -0
- package/dist/features/magic-context/user-memory/storage-user-memory.d.ts.map +1 -0
- package/dist/hooks/magic-context/command-handler.d.ts +4 -0
- package/dist/hooks/magic-context/command-handler.d.ts.map +1 -1
- package/dist/hooks/magic-context/compaction-marker-manager.d.ts +27 -0
- package/dist/hooks/magic-context/compaction-marker-manager.d.ts.map +1 -0
- package/dist/hooks/magic-context/compartment-parser.d.ts +1 -0
- package/dist/hooks/magic-context/compartment-parser.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-prompt.d.ts +4 -1
- package/dist/hooks/magic-context/compartment-prompt.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-compressor.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-recomp.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-types.d.ts +5 -0
- package/dist/hooks/magic-context/compartment-runner-types.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-validation.d.ts.map +1 -1
- package/dist/hooks/magic-context/event-handler.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook.d.ts +7 -0
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
- package/dist/hooks/magic-context/note-nudger.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-raw.d.ts.map +1 -1
- package/dist/hooks/magic-context/system-prompt-hash.d.ts +2 -0
- package/dist/hooks/magic-context/system-prompt-hash.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts +4 -0
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts +2 -0
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1231 -151
- package/dist/plugin/dream-timer.d.ts +4 -0
- package/dist/plugin/dream-timer.d.ts.map +1 -1
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/plugin/tui-action-consumer.d.ts +13 -0
- package/dist/plugin/tui-action-consumer.d.ts.map +1 -0
- package/dist/shared/tui-config.d.ts.map +1 -1
- package/dist/tools/ctx-note/constants.d.ts +1 -1
- package/dist/tools/ctx-note/constants.d.ts.map +1 -1
- package/dist/tools/ctx-note/tools.d.ts.map +1 -1
- package/dist/tools/ctx-note/types.d.ts +3 -1
- package/dist/tools/ctx-note/types.d.ts.map +1 -1
- package/dist/tui/data/context-db.d.ts +20 -0
- package/dist/tui/data/context-db.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/shared/assistant-message-extractor.ts +74 -0
- package/src/shared/conflict-detector.ts +310 -0
- package/src/shared/conflict-fixer.ts +216 -0
- package/src/shared/data-path.ts +10 -0
- package/src/shared/error-message.ts +3 -0
- package/src/shared/format-bytes.ts +5 -0
- package/src/shared/index.ts +4 -0
- package/src/shared/internal-initiator-marker.ts +1 -0
- package/src/shared/jsonc-parser.ts +138 -0
- package/src/shared/logger.ts +63 -0
- package/src/shared/model-requirements.ts +84 -0
- package/src/shared/model-suggestion-retry.ts +160 -0
- package/src/shared/normalize-sdk-response.ts +40 -0
- package/src/shared/opencode-compaction-detector.test.ts +222 -0
- package/src/shared/opencode-compaction-detector.ts +81 -0
- package/src/shared/opencode-config-dir-types.ts +15 -0
- package/src/shared/opencode-config-dir.ts +38 -0
- package/src/shared/record-type-guard.ts +3 -0
- package/src/shared/system-directive.ts +9 -0
- package/src/shared/tui-config.ts +60 -0
- package/src/tui/data/context-db.ts +114 -6
- package/src/tui/index.tsx +77 -2
- package/src/tui/slots/sidebar-content.tsx +3 -2
- package/dist/features/magic-context/storage-smart-notes.d.ts +0 -24
- package/dist/features/magic-context/storage-smart-notes.d.ts.map +0 -1
package/src/tui/index.tsx
CHANGED
|
@@ -5,7 +5,8 @@ import { dirname, join } from "node:path"
|
|
|
5
5
|
import { createMemo } from "solid-js"
|
|
6
6
|
import type { TuiPlugin, TuiPluginApi, TuiThemeCurrent } from "@opencode-ai/plugin/tui"
|
|
7
7
|
import { createSidebarContentSlot } from "./slots/sidebar-content"
|
|
8
|
-
import
|
|
8
|
+
import packageJson from "../../package.json"
|
|
9
|
+
import { closeDb, consumeTuiMessages, getCompartmentCount, loadStatusDetail, sendMessageToServer, type StatusDetail } from "./data/context-db"
|
|
9
10
|
import { detectConflicts } from "../shared/conflict-detector"
|
|
10
11
|
import { fixConflicts } from "../shared/conflict-fixer"
|
|
11
12
|
import { readJsoncFile } from "../shared/jsonc-parser"
|
|
@@ -278,7 +279,7 @@ const StatusDialog = (props: { api: TuiPluginApi; s: StatusDetail }) => {
|
|
|
278
279
|
{/* Title */}
|
|
279
280
|
<box justifyContent="center" width="100%" marginBottom={1}>
|
|
280
281
|
<text fg={t().accent}>
|
|
281
|
-
<b>⚡ Magic Context Status</b>
|
|
282
|
+
<b>⚡ Magic Context Status</b> <text fg={t().textMuted}>v{packageJson.version}</text>
|
|
282
283
|
</text>
|
|
283
284
|
</box>
|
|
284
285
|
|
|
@@ -406,6 +407,36 @@ function getModelKeyFromMessages(api: TuiPluginApi, sessionId: string): string |
|
|
|
406
407
|
return undefined
|
|
407
408
|
}
|
|
408
409
|
|
|
410
|
+
function showRecompDialog(api: TuiPluginApi) {
|
|
411
|
+
const sessionId = getSessionId(api)
|
|
412
|
+
if (!sessionId) {
|
|
413
|
+
api.ui.toast({ message: "No active session", variant: "warning" })
|
|
414
|
+
return
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
const count = getCompartmentCount(sessionId)
|
|
418
|
+
api.ui.dialog.replace(() => (
|
|
419
|
+
<api.ui.DialogConfirm
|
|
420
|
+
title="⚠️ Recomp Confirmation"
|
|
421
|
+
message={[
|
|
422
|
+
`You have ${count} compartments.`,
|
|
423
|
+
"",
|
|
424
|
+
"Recomp will regenerate all compartments and facts from raw history.",
|
|
425
|
+
"This may take a long time and consume significant tokens.",
|
|
426
|
+
"",
|
|
427
|
+
"Proceed?",
|
|
428
|
+
].join("\n")}
|
|
429
|
+
onConfirm={() => {
|
|
430
|
+
sendMessageToServer("action", { command: "recomp" }, sessionId)
|
|
431
|
+
api.ui.toast({ message: "Recomp requested — historian will start shortly", variant: "info", duration: 5000 })
|
|
432
|
+
}}
|
|
433
|
+
onCancel={() => {
|
|
434
|
+
api.ui.toast({ message: "Recomp cancelled", variant: "info", duration: 3000 })
|
|
435
|
+
}}
|
|
436
|
+
/>
|
|
437
|
+
))
|
|
438
|
+
}
|
|
439
|
+
|
|
409
440
|
function showStatusDialog(api: TuiPluginApi) {
|
|
410
441
|
const sessionId = getSessionId(api)
|
|
411
442
|
if (!sessionId) {
|
|
@@ -435,10 +466,54 @@ const tui: TuiPlugin = async (api, _options, meta) => {
|
|
|
435
466
|
showStatusDialog(api)
|
|
436
467
|
},
|
|
437
468
|
},
|
|
469
|
+
{
|
|
470
|
+
title: "Magic Context: Recomp",
|
|
471
|
+
value: "magic-context.recomp",
|
|
472
|
+
category: "Magic Context",
|
|
473
|
+
slash: { name: "ctx-recomp" },
|
|
474
|
+
onSelect() {
|
|
475
|
+
showRecompDialog(api)
|
|
476
|
+
},
|
|
477
|
+
},
|
|
438
478
|
])
|
|
439
479
|
|
|
480
|
+
// Poll for server→TUI messages (toasts, dialogs) every 2 seconds
|
|
481
|
+
const messagePoller = setInterval(() => {
|
|
482
|
+
try {
|
|
483
|
+
const messages = consumeTuiMessages()
|
|
484
|
+
for (const msg of messages) {
|
|
485
|
+
if (msg.type === "toast") {
|
|
486
|
+
const p = msg.payload
|
|
487
|
+
api.ui.toast({
|
|
488
|
+
message: String(p.message ?? ""),
|
|
489
|
+
variant: (p.variant as "info" | "warning" | "error" | "success") ?? "info",
|
|
490
|
+
duration: typeof p.duration === "number" ? p.duration : 5000,
|
|
491
|
+
})
|
|
492
|
+
} else if (msg.type === "dialog_confirm") {
|
|
493
|
+
const p = msg.payload
|
|
494
|
+
const dialogId = String(p.id ?? "")
|
|
495
|
+
api.ui.dialog.replace(() => (
|
|
496
|
+
<api.ui.DialogConfirm
|
|
497
|
+
title={String(p.title ?? "Confirm")}
|
|
498
|
+
message={String(p.message ?? "")}
|
|
499
|
+
onConfirm={() => {
|
|
500
|
+
sendMessageToServer("dialog_result", { id: dialogId, confirmed: true }, msg.sessionId ?? undefined)
|
|
501
|
+
}}
|
|
502
|
+
onCancel={() => {
|
|
503
|
+
sendMessageToServer("dialog_result", { id: dialogId, confirmed: false }, msg.sessionId ?? undefined)
|
|
504
|
+
}}
|
|
505
|
+
/>
|
|
506
|
+
))
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
} catch {
|
|
510
|
+
// Intentional: message polling should never crash the TUI
|
|
511
|
+
}
|
|
512
|
+
}, 2000)
|
|
513
|
+
|
|
440
514
|
// Clean up on dispose
|
|
441
515
|
api.lifecycle.onDispose(() => {
|
|
516
|
+
clearInterval(messagePoller)
|
|
442
517
|
closeDb()
|
|
443
518
|
})
|
|
444
519
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** @jsxImportSource @opentui/solid */
|
|
2
2
|
import { createEffect, createMemo, createSignal, on, onCleanup } from "solid-js"
|
|
3
3
|
import type { TuiSlotPlugin, TuiPluginApi, TuiThemeCurrent } from "@opencode-ai/plugin/tui"
|
|
4
|
+
import packageJson from "../../../package.json"
|
|
4
5
|
import { loadSidebarSnapshot, type SidebarSnapshot } from "../data/context-db"
|
|
5
6
|
|
|
6
7
|
const SINGLE_BORDER = { type: "single" } as any
|
|
@@ -303,10 +304,10 @@ const SidebarContent = (props: {
|
|
|
303
304
|
<box flexDirection="row" justifyContent="space-between" alignItems="center">
|
|
304
305
|
<box paddingLeft={1} paddingRight={1} backgroundColor={props.theme.accent}>
|
|
305
306
|
<text fg={props.theme.background}>
|
|
306
|
-
<b>Magic
|
|
307
|
+
<b>Magic Context</b>
|
|
307
308
|
</text>
|
|
308
309
|
</box>
|
|
309
|
-
<text fg={props.theme.
|
|
310
|
+
<text fg={props.theme.textMuted}>v{packageJson.version}</text>
|
|
310
311
|
</box>
|
|
311
312
|
|
|
312
313
|
{/* Token breakdown bar */}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { Database } from "bun:sqlite";
|
|
2
|
-
export type SmartNoteStatus = "pending" | "ready" | "dismissed";
|
|
3
|
-
export interface SmartNote {
|
|
4
|
-
id: number;
|
|
5
|
-
projectPath: string;
|
|
6
|
-
content: string;
|
|
7
|
-
surfaceCondition: string;
|
|
8
|
-
status: SmartNoteStatus;
|
|
9
|
-
createdSessionId: string | null;
|
|
10
|
-
createdAt: number;
|
|
11
|
-
updatedAt: number;
|
|
12
|
-
lastCheckedAt: number | null;
|
|
13
|
-
readyAt: number | null;
|
|
14
|
-
readyReason: string | null;
|
|
15
|
-
}
|
|
16
|
-
export declare function addSmartNote(db: Database, projectPath: string, content: string, surfaceCondition: string, sessionId?: string): SmartNote;
|
|
17
|
-
export declare function getSmartNotes(db: Database, projectPath: string, status?: SmartNoteStatus): SmartNote[];
|
|
18
|
-
export declare function getPendingSmartNotes(db: Database, projectPath: string): SmartNote[];
|
|
19
|
-
export declare function getReadySmartNotes(db: Database, projectPath: string): SmartNote[];
|
|
20
|
-
export declare function markSmartNoteReady(db: Database, noteId: number, readyReason?: string): void;
|
|
21
|
-
export declare function markSmartNoteChecked(db: Database, noteId: number): void;
|
|
22
|
-
export declare function dismissSmartNote(db: Database, noteId: number): boolean;
|
|
23
|
-
export declare function deleteSmartNote(db: Database, noteId: number): boolean;
|
|
24
|
-
//# sourceMappingURL=storage-smart-notes.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"storage-smart-notes.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/storage-smart-notes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,OAAO,GAAG,WAAW,CAAC;AAEhE,MAAM,WAAW,SAAS;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,eAAe,CAAC;IACxB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