@cortexkit/opencode-magic-context 0.33.0 → 0.33.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/schema/magic-context.d.ts +62 -22
- package/dist/config/schema/magic-context.d.ts.map +1 -1
- package/dist/{conflict-warning-hook-bwa99a04.js → conflict-warning-hook-n48c783v.js} +1 -1
- package/dist/features/magic-context/compaction-marker.d.ts +49 -0
- package/dist/features/magic-context/compaction-marker.d.ts.map +1 -1
- package/dist/features/magic-context/compartment-chunk-embedding.d.ts +0 -2
- package/dist/features/magic-context/compartment-chunk-embedding.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-registry.d.ts +0 -1
- package/dist/features/magic-context/dreamer/task-registry.d.ts.map +1 -1
- package/dist/features/magic-context/git-commits/index.d.ts +2 -2
- package/dist/features/magic-context/git-commits/index.d.ts.map +1 -1
- package/dist/features/magic-context/git-commits/storage-git-commit-embeddings.d.ts +0 -2
- 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 +0 -13
- package/dist/features/magic-context/git-commits/storage-git-commits.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding.d.ts +1 -2
- package/dist/features/magic-context/memory/embedding.d.ts.map +1 -1
- package/dist/features/magic-context/memory/memory-migration.d.ts +0 -6
- package/dist/features/magic-context/memory/memory-migration.d.ts.map +1 -1
- package/dist/features/magic-context/memory/storage-memory-embeddings.d.ts +0 -1
- package/dist/features/magic-context/memory/storage-memory-embeddings.d.ts.map +1 -1
- package/dist/features/magic-context/memory/storage-memory.d.ts +1 -6
- package/dist/features/magic-context/memory/storage-memory.d.ts.map +1 -1
- package/dist/features/magic-context/memory/verification-paths.d.ts +0 -1
- package/dist/features/magic-context/memory/verification-paths.d.ts.map +1 -1
- package/dist/features/magic-context/migrations.d.ts.map +1 -1
- package/dist/features/magic-context/mural/storage-mural.d.ts +0 -1
- package/dist/features/magic-context/mural/storage-mural.d.ts.map +1 -1
- package/dist/features/magic-context/project-embedding-registry.d.ts +16 -2
- package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
- package/dist/features/magic-context/smart-notes/capabilities.d.ts +0 -2
- package/dist/features/magic-context/smart-notes/capabilities.d.ts.map +1 -1
- package/dist/features/magic-context/smart-notes/compiler.d.ts +0 -1
- package/dist/features/magic-context/smart-notes/compiler.d.ts.map +1 -1
- package/dist/features/magic-context/smart-notes/types.d.ts +0 -16
- package/dist/features/magic-context/smart-notes/types.d.ts.map +1 -1
- package/dist/features/magic-context/storage-db.d.ts +1 -1
- package/dist/features/magic-context/storage-db.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-persisted.d.ts +0 -1
- package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
- package/dist/features/magic-context/user-memory/storage-user-memory.d.ts +0 -2
- package/dist/features/magic-context/user-memory/storage-user-memory.d.ts.map +1 -1
- package/dist/hooks/auto-update-checker/types.d.ts +0 -3
- package/dist/hooks/auto-update-checker/types.d.ts.map +1 -1
- package/dist/hooks/magic-context/cache-busting-signals.d.ts +0 -1
- package/dist/hooks/magic-context/cache-busting-signals.d.ts.map +1 -1
- package/dist/hooks/magic-context/channel2-delivery.d.ts.map +1 -1
- package/dist/hooks/magic-context/compaction-marker-manager.d.ts +49 -0
- package/dist/hooks/magic-context/compaction-marker-manager.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-parser.d.ts +12 -0
- package/dist/hooks/magic-context/compartment-parser.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-mapping.d.ts +0 -12
- package/dist/hooks/magic-context/compartment-runner-mapping.d.ts.map +1 -1
- package/dist/hooks/magic-context/event-handler.d.ts.map +1 -1
- package/dist/hooks/magic-context/historian-prompt.generated.d.ts +1 -1
- package/dist/hooks/magic-context/historian-prompt.generated.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook-handlers.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/inject-compartments.d.ts +9 -0
- package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
- package/dist/hooks/magic-context/sentinel.d.ts +39 -0
- package/dist/hooks/magic-context/sentinel.d.ts.map +1 -1
- package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
- package/dist/hooks/magic-context/tool-drop-target.d.ts +19 -0
- package/dist/hooks/magic-context/tool-drop-target.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/{index-kxz4tn6m.js → index-56yjaeb2.js} +56 -4
- package/dist/{index-h86twgsp.js → index-c2gahrks.js} +516 -177
- package/dist/{index-bmkea2dq.js → index-ey1bc14z.js} +36 -26
- package/dist/{index-k5y60ymm.js → index-xyaekybw.js} +21 -2
- package/dist/index.js +83 -23
- package/dist/plugin/hooks/create-session-hooks.d.ts +8 -8
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/{recomp-orchestrator-yh7pepvx.js → recomp-orchestrator-2yb2hfh2.js} +2 -3
- package/dist/shared/conflict-detector.d.ts.map +1 -1
- package/dist/shared/sqlite.d.ts +9 -4
- package/dist/shared/sqlite.d.ts.map +1 -1
- package/dist/{storage-meta-session-1phy0b1z.js → storage-meta-session-td6bwtky.js} +1 -1
- package/dist/{task-config-dn9k9szr.js → task-config-5nx3qfz8.js} +1 -2
- package/package.json +2 -2
- package/src/shared/conflict-detector.test.ts +130 -1
- package/src/shared/conflict-detector.ts +34 -2
- package/src/shared/sqlite.ts +13 -33
- package/dist/config/schema.d.ts +0 -3
- package/dist/config/schema.d.ts.map +0 -1
- package/dist/features/magic-context/plugin-messages.d.ts +0 -75
- package/dist/features/magic-context/plugin-messages.d.ts.map +0 -1
- package/dist/hooks/magic-context/compartment-runner-state-xml.d.ts +0 -21
- package/dist/hooks/magic-context/compartment-runner-state-xml.d.ts.map +0 -1
- package/dist/index-anhrfygk.js +0 -57
- package/dist/shared/opencode-compaction-detector.d.ts +0 -2
- package/dist/shared/opencode-compaction-detector.d.ts.map +0 -1
- package/dist/shared/transcript-opencode.d.ts +0 -71
- package/dist/shared/transcript-opencode.d.ts.map +0 -1
- package/dist/tools/index.d.ts +0 -6
- package/dist/tools/index.d.ts.map +0 -1
- package/src/shared/opencode-compaction-detector.test.ts +0 -239
- package/src/shared/opencode-compaction-detector.ts +0 -81
- package/src/shared/transcript-opencode.ts +0 -302
|
@@ -15,6 +15,7 @@ import { detectConflicts } from "./conflict-detector";
|
|
|
15
15
|
describe("detectConflicts", () => {
|
|
16
16
|
let projectDir: string;
|
|
17
17
|
let userConfigDir: string;
|
|
18
|
+
let homeDir: string;
|
|
18
19
|
let originalEnv: Record<string, string | undefined>;
|
|
19
20
|
|
|
20
21
|
beforeEach(() => {
|
|
@@ -23,6 +24,8 @@ describe("detectConflicts", () => {
|
|
|
23
24
|
mkdirSync(projectDir, { recursive: true });
|
|
24
25
|
userConfigDir = join(root, "user-config", "opencode");
|
|
25
26
|
mkdirSync(userConfigDir, { recursive: true });
|
|
27
|
+
homeDir = join(root, "home");
|
|
28
|
+
mkdirSync(homeDir, { recursive: true });
|
|
26
29
|
|
|
27
30
|
// Save and override every env var that affects config-path resolution.
|
|
28
31
|
// OPENCODE_CONFIG_DIR takes precedence over XDG_CONFIG_HOME, so we set
|
|
@@ -32,8 +35,10 @@ describe("detectConflicts", () => {
|
|
|
32
35
|
OPENCODE_CONFIG_DIR: process.env.OPENCODE_CONFIG_DIR,
|
|
33
36
|
XDG_CONFIG_HOME: process.env.XDG_CONFIG_HOME,
|
|
34
37
|
OPENCODE_DISABLE_AUTOCOMPACT: process.env.OPENCODE_DISABLE_AUTOCOMPACT,
|
|
38
|
+
HOME: process.env.HOME,
|
|
35
39
|
};
|
|
36
40
|
process.env.OPENCODE_CONFIG_DIR = userConfigDir;
|
|
41
|
+
process.env.HOME = homeDir;
|
|
37
42
|
delete process.env.XDG_CONFIG_HOME;
|
|
38
43
|
// Disable auto-compaction default during tests so we isolate plugin
|
|
39
44
|
// detection from compaction detection.
|
|
@@ -166,7 +171,7 @@ describe("detectConflicts", () => {
|
|
|
166
171
|
expect(result.conflicts.omoPreemptiveCompaction).toBe(true);
|
|
167
172
|
});
|
|
168
173
|
|
|
169
|
-
it("respects disabled_hooks in project-level OMO config", () => {
|
|
174
|
+
it("respects disabled_hooks in project-level OMO config (old format)", () => {
|
|
170
175
|
writeProjectConfig(["oh-my-opencode"]);
|
|
171
176
|
// Use project-scoped OMO config to avoid relying on user
|
|
172
177
|
// config-path resolution, which can be leaked across files
|
|
@@ -184,6 +189,130 @@ describe("detectConflicts", () => {
|
|
|
184
189
|
const result = detectConflicts(projectDir);
|
|
185
190
|
expect(result.hasConflict).toBe(false);
|
|
186
191
|
});
|
|
192
|
+
|
|
193
|
+
// --- New unified omo.jsonc (oh-my-openagent >= 4.19.0) ---
|
|
194
|
+
|
|
195
|
+
it("detects disabled_hooks in new ~/.omo/omo.jsonc (user-level)", () => {
|
|
196
|
+
writeProjectConfig(["oh-my-opencode"]);
|
|
197
|
+
const omoDir = join(homeDir, ".omo");
|
|
198
|
+
mkdirSync(omoDir, { recursive: true });
|
|
199
|
+
writeFileSync(
|
|
200
|
+
join(omoDir, "omo.jsonc"),
|
|
201
|
+
JSON.stringify({
|
|
202
|
+
"[opencode]": {
|
|
203
|
+
disabled_hooks: [
|
|
204
|
+
"preemptive-compaction",
|
|
205
|
+
"context-window-monitor",
|
|
206
|
+
"anthropic-context-window-limit-recovery",
|
|
207
|
+
],
|
|
208
|
+
},
|
|
209
|
+
}),
|
|
210
|
+
);
|
|
211
|
+
const result = detectConflicts(projectDir);
|
|
212
|
+
expect(result.hasConflict).toBe(false);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it("detects disabled_hooks in new .omo/omo.jsonc (project-level)", () => {
|
|
216
|
+
writeProjectConfig(["oh-my-opencode"]);
|
|
217
|
+
const omoDir = join(projectDir, ".omo");
|
|
218
|
+
mkdirSync(omoDir, { recursive: true });
|
|
219
|
+
writeFileSync(
|
|
220
|
+
join(omoDir, "omo.jsonc"),
|
|
221
|
+
JSON.stringify({
|
|
222
|
+
"[opencode]": {
|
|
223
|
+
disabled_hooks: [
|
|
224
|
+
"preemptive-compaction",
|
|
225
|
+
"context-window-monitor",
|
|
226
|
+
"anthropic-context-window-limit-recovery",
|
|
227
|
+
],
|
|
228
|
+
},
|
|
229
|
+
}),
|
|
230
|
+
);
|
|
231
|
+
const result = detectConflicts(projectDir);
|
|
232
|
+
expect(result.hasConflict).toBe(false);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it("detects hooks as active when new omo.jsonc has no disabled_hooks", () => {
|
|
236
|
+
writeProjectConfig(["oh-my-opencode"]);
|
|
237
|
+
const omoDir = join(homeDir, ".omo");
|
|
238
|
+
mkdirSync(omoDir, { recursive: true });
|
|
239
|
+
writeFileSync(
|
|
240
|
+
join(omoDir, "omo.jsonc"),
|
|
241
|
+
JSON.stringify({
|
|
242
|
+
"[opencode]": {
|
|
243
|
+
// No disabled_hooks — hooks default ACTIVE
|
|
244
|
+
},
|
|
245
|
+
}),
|
|
246
|
+
);
|
|
247
|
+
const result = detectConflicts(projectDir);
|
|
248
|
+
expect(result.conflicts.omoPreemptiveCompaction).toBe(true);
|
|
249
|
+
expect(result.conflicts.omoContextWindowMonitor).toBe(true);
|
|
250
|
+
expect(result.conflicts.omoAnthropicRecovery).toBe(true);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it("reads disabled_hooks from both old and new config paths", () => {
|
|
254
|
+
writeProjectConfig(["oh-my-opencode"]);
|
|
255
|
+
// Old path: only disables preemptive-compaction
|
|
256
|
+
writeFileSync(
|
|
257
|
+
join(projectDir, "oh-my-opencode.json"),
|
|
258
|
+
JSON.stringify({
|
|
259
|
+
disabled_hooks: ["preemptive-compaction"],
|
|
260
|
+
}),
|
|
261
|
+
);
|
|
262
|
+
// New path: disables the other two
|
|
263
|
+
const omoDir = join(homeDir, ".omo");
|
|
264
|
+
mkdirSync(omoDir, { recursive: true });
|
|
265
|
+
writeFileSync(
|
|
266
|
+
join(omoDir, "omo.jsonc"),
|
|
267
|
+
JSON.stringify({
|
|
268
|
+
"[opencode]": {
|
|
269
|
+
disabled_hooks: [
|
|
270
|
+
"context-window-monitor",
|
|
271
|
+
"anthropic-context-window-limit-recovery",
|
|
272
|
+
],
|
|
273
|
+
},
|
|
274
|
+
}),
|
|
275
|
+
);
|
|
276
|
+
const result = detectConflicts(projectDir);
|
|
277
|
+
// All three are disabled across both configs
|
|
278
|
+
expect(result.hasConflict).toBe(false);
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it("reads omo.json (fallback) when omo.jsonc does not exist", () => {
|
|
282
|
+
writeProjectConfig(["oh-my-opencode"]);
|
|
283
|
+
const omoDir = join(homeDir, ".omo");
|
|
284
|
+
mkdirSync(omoDir, { recursive: true });
|
|
285
|
+
writeFileSync(
|
|
286
|
+
join(omoDir, "omo.json"),
|
|
287
|
+
JSON.stringify({
|
|
288
|
+
"[opencode]": {
|
|
289
|
+
disabled_hooks: [
|
|
290
|
+
"preemptive-compaction",
|
|
291
|
+
"context-window-monitor",
|
|
292
|
+
"anthropic-context-window-limit-recovery",
|
|
293
|
+
],
|
|
294
|
+
},
|
|
295
|
+
}),
|
|
296
|
+
);
|
|
297
|
+
const result = detectConflicts(projectDir);
|
|
298
|
+
expect(result.hasConflict).toBe(false);
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
it("ignores new omo.jsonc when OMO is not installed", () => {
|
|
302
|
+
writeProjectConfig([]);
|
|
303
|
+
const omoDir = join(homeDir, ".omo");
|
|
304
|
+
mkdirSync(omoDir, { recursive: true });
|
|
305
|
+
writeFileSync(
|
|
306
|
+
join(omoDir, "omo.jsonc"),
|
|
307
|
+
JSON.stringify({
|
|
308
|
+
"[opencode]": {
|
|
309
|
+
disabled_hooks: ["preemptive-compaction"],
|
|
310
|
+
},
|
|
311
|
+
}),
|
|
312
|
+
);
|
|
313
|
+
const result = detectConflicts(projectDir);
|
|
314
|
+
expect(result.hasConflict).toBe(false);
|
|
315
|
+
});
|
|
187
316
|
});
|
|
188
317
|
|
|
189
318
|
// --- Combined / control cases ---
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
1
2
|
import { join } from "node:path";
|
|
2
3
|
import { readJsoncFile } from "./jsonc-parser";
|
|
3
4
|
import { getOpenCodeConfigPaths } from "./opencode-config-dir";
|
|
@@ -15,6 +16,14 @@ interface OmoConfig {
|
|
|
15
16
|
disabled_hooks?: string[];
|
|
16
17
|
}
|
|
17
18
|
|
|
19
|
+
/** Shape of the new unified omo.jsonc (oh-my-openagent >= 4.19.0).
|
|
20
|
+
* Hook config lives inside the `[opencode]` harness block. */
|
|
21
|
+
interface OmoV2Config {
|
|
22
|
+
"[opencode]"?: {
|
|
23
|
+
disabled_hooks?: string[];
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
18
27
|
export interface ConflictResult {
|
|
19
28
|
/** Whether any blocking conflict was found */
|
|
20
29
|
hasConflict: boolean;
|
|
@@ -318,7 +327,7 @@ function checkOmoHooks(directory: string): {
|
|
|
318
327
|
function readOmoDisabledHooks(directory: string): Set<string> {
|
|
319
328
|
const disabled = new Set<string>();
|
|
320
329
|
|
|
321
|
-
// Check both old and new OMO config names
|
|
330
|
+
// Check both old and new OMO config names in the OpenCode config dir
|
|
322
331
|
const configNames = [
|
|
323
332
|
"oh-my-opencode.jsonc",
|
|
324
333
|
"oh-my-opencode.json",
|
|
@@ -341,7 +350,7 @@ function readOmoDisabledHooks(directory: string): Set<string> {
|
|
|
341
350
|
// best-effort
|
|
342
351
|
}
|
|
343
352
|
|
|
344
|
-
// Also check project-level OMO configs
|
|
353
|
+
// Also check project-level OMO configs (old format)
|
|
345
354
|
for (const name of configNames) {
|
|
346
355
|
const config = readJsoncFile<OmoConfig>(join(directory, name));
|
|
347
356
|
if (config?.disabled_hooks) {
|
|
@@ -351,6 +360,29 @@ function readOmoDisabledHooks(directory: string): Set<string> {
|
|
|
351
360
|
}
|
|
352
361
|
}
|
|
353
362
|
|
|
363
|
+
// --- New unified omo.jsonc (oh-my-openagent >= 4.19.0) ---
|
|
364
|
+
// User-level: ~/.omo/omo.jsonc (fallback ~/.omo/omo.json)
|
|
365
|
+
const homeDir = process.env.HOME || homedir();
|
|
366
|
+
const omoHomeDir = join(homeDir, ".omo");
|
|
367
|
+
for (const name of ["omo.jsonc", "omo.json"]) {
|
|
368
|
+
const config = readJsoncFile<OmoV2Config>(join(omoHomeDir, name));
|
|
369
|
+
if (config?.["[opencode]"]?.disabled_hooks) {
|
|
370
|
+
for (const hook of config["[opencode]"].disabled_hooks) {
|
|
371
|
+
disabled.add(hook);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// Project-level: .omo/omo.jsonc (fallback .omo/omo.json)
|
|
377
|
+
for (const name of ["omo.jsonc", "omo.json"]) {
|
|
378
|
+
const config = readJsoncFile<OmoV2Config>(join(directory, ".omo", name));
|
|
379
|
+
if (config?.["[opencode]"]?.disabled_hooks) {
|
|
380
|
+
for (const hook of config["[opencode]"].disabled_hooks) {
|
|
381
|
+
disabled.add(hook);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
354
386
|
return disabled;
|
|
355
387
|
}
|
|
356
388
|
|
package/src/shared/sqlite.ts
CHANGED
|
@@ -201,30 +201,6 @@ export type Database = BetterSqlite3.Database;
|
|
|
201
201
|
export type Statement = BetterSqlite3.Statement<unknown[], unknown>;
|
|
202
202
|
|
|
203
203
|
const privilegeDepth = new WeakMap<Database, number>();
|
|
204
|
-
const registeredPrivilegeFunctions = new WeakSet<Database>();
|
|
205
|
-
const privilegeUdfAvailable = new WeakSet<Database>();
|
|
206
|
-
|
|
207
|
-
/** Register the connection-local privilege predicate used by managed-write guards. */
|
|
208
|
-
export function registerPrivilegedWriter(db: Database): void {
|
|
209
|
-
if (registeredPrivilegeFunctions.has(db)) return;
|
|
210
|
-
const native = db as unknown as {
|
|
211
|
-
function?: (name: string, implementation: () => number) => void;
|
|
212
|
-
createFunction?: (name: string, implementation: () => number) => void;
|
|
213
|
-
};
|
|
214
|
-
const implementation = (): number => ((privilegeDepth.get(db) ?? 0) > 0 ? 1 : 0);
|
|
215
|
-
if (typeof native.function === "function") {
|
|
216
|
-
native.function("mc_privileged_writer", implementation);
|
|
217
|
-
} else if (typeof native.createFunction === "function") {
|
|
218
|
-
native.createFunction("mc_privileged_writer", implementation);
|
|
219
|
-
} else {
|
|
220
|
-
// Older Bun releases do not expose scalar UDF registration. Migration 55
|
|
221
|
-
// retains the pre-UDF state-table trigger on those runtimes.
|
|
222
|
-
registeredPrivilegeFunctions.add(db);
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
privilegeUdfAvailable.add(db);
|
|
226
|
-
registeredPrivilegeFunctions.add(db);
|
|
227
|
-
}
|
|
228
204
|
|
|
229
205
|
function isInTransaction(db: Database): boolean {
|
|
230
206
|
const candidate = db as unknown as { inTransaction?: unknown; isTransaction?: unknown };
|
|
@@ -232,11 +208,17 @@ function isInTransaction(db: Database): boolean {
|
|
|
232
208
|
}
|
|
233
209
|
|
|
234
210
|
/**
|
|
235
|
-
* Run a storage operation
|
|
236
|
-
*
|
|
211
|
+
* Run a storage operation with the managed-write privilege enabled.
|
|
212
|
+
*
|
|
213
|
+
* The privilege is recorded in the durable `context_privilege_state` table (row
|
|
214
|
+
* id=1, enabled=1) so the guard triggers — which reference that table, never a
|
|
215
|
+
* connection-local UDF — stand down for this connection's writes. The write happens
|
|
216
|
+
* inside a BEGIN IMMEDIATE transaction (single writer), and enabled is cleared back
|
|
217
|
+
* to 0 before commit, so no second connection can ever observe enabled=1. Nesting is
|
|
218
|
+
* tracked by privilegeDepth (outside SQLite): only the outermost scope clears the
|
|
219
|
+
* flag, so an inner scope releasing does not drop permission out from under its caller.
|
|
237
220
|
*/
|
|
238
221
|
export function withPrivilegedWriter<T>(db: Database, operation: () => T): T {
|
|
239
|
-
registerPrivilegedWriter(db);
|
|
240
222
|
const previousDepth = privilegeDepth.get(db) ?? 0;
|
|
241
223
|
const nested = isInTransaction(db);
|
|
242
224
|
const savepoint = "mc_privilege_scope";
|
|
@@ -247,13 +229,11 @@ export function withPrivilegedWriter<T>(db: Database, operation: () => T): T {
|
|
|
247
229
|
}
|
|
248
230
|
privilegeDepth.set(db, previousDepth + 1);
|
|
249
231
|
try {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
).run();
|
|
254
|
-
}
|
|
232
|
+
db.prepare(
|
|
233
|
+
"INSERT INTO context_privilege_state(id, enabled) VALUES (1, 1) ON CONFLICT(id) DO UPDATE SET enabled = 1",
|
|
234
|
+
).run();
|
|
255
235
|
const result = operation();
|
|
256
|
-
if (
|
|
236
|
+
if (previousDepth === 0) {
|
|
257
237
|
db.prepare("UPDATE context_privilege_state SET enabled = 0 WHERE id = 1").run();
|
|
258
238
|
}
|
|
259
239
|
if (nested) {
|
package/dist/config/schema.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/config/schema.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC"}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import type { Database } from "../../shared/sqlite";
|
|
2
|
-
/**
|
|
3
|
-
* SQLite-backed message bus for TUI ↔ server plugin communication.
|
|
4
|
-
*
|
|
5
|
-
* Both the server plugin and TUI plugin share the same `context.db`.
|
|
6
|
-
* Messages are written by one side and consumed by the other via polling.
|
|
7
|
-
*
|
|
8
|
-
* Directions:
|
|
9
|
-
* - "server_to_tui": Server sends toasts, dialogs, state updates to TUI
|
|
10
|
-
* - "tui_to_server": TUI sends dialog confirmations, action triggers to server
|
|
11
|
-
*
|
|
12
|
-
* Message types:
|
|
13
|
-
* - "toast": Show a toast notification { message, variant?, duration? }
|
|
14
|
-
* - "dialog_confirm": Show a confirmation dialog { id, title, message }
|
|
15
|
-
* - "dialog_result": TUI response to a dialog { id, confirmed }
|
|
16
|
-
* - "state_update": State change hint { key, value }
|
|
17
|
-
*
|
|
18
|
-
* Messages are auto-cleaned after 5 minutes to prevent table bloat.
|
|
19
|
-
*/
|
|
20
|
-
export type MessageDirection = "server_to_tui" | "tui_to_server";
|
|
21
|
-
export type MessageType = "toast" | "dialog_confirm" | "dialog_result" | "state_update" | "action";
|
|
22
|
-
export interface PluginMessage {
|
|
23
|
-
id: number;
|
|
24
|
-
direction: MessageDirection;
|
|
25
|
-
type: MessageType;
|
|
26
|
-
payload: Record<string, unknown>;
|
|
27
|
-
sessionId: string | null;
|
|
28
|
-
createdAt: number;
|
|
29
|
-
consumedAt: number | null;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Send a message from server to TUI.
|
|
33
|
-
*/
|
|
34
|
-
export declare function sendToTui(db: Database, type: MessageType, payload: Record<string, unknown>, sessionId?: string): number;
|
|
35
|
-
/**
|
|
36
|
-
* Send a message from TUI to server.
|
|
37
|
-
*/
|
|
38
|
-
export declare function sendToServer(db: Database, type: MessageType, payload: Record<string, unknown>, sessionId?: string): number;
|
|
39
|
-
/**
|
|
40
|
-
* Consume unconsumed messages for a given direction.
|
|
41
|
-
* Marks consumed messages and returns them.
|
|
42
|
-
* Also cleans up old messages (>5min) to prevent table bloat.
|
|
43
|
-
*/
|
|
44
|
-
export declare function consumeMessages(db: Database, direction: MessageDirection, options?: {
|
|
45
|
-
type?: MessageType;
|
|
46
|
-
sessionId?: string;
|
|
47
|
-
}): PluginMessage[];
|
|
48
|
-
/**
|
|
49
|
-
* Peek at unconsumed messages without consuming them.
|
|
50
|
-
*/
|
|
51
|
-
export declare function peekMessages(db: Database, direction: MessageDirection, options?: {
|
|
52
|
-
type?: MessageType;
|
|
53
|
-
sessionId?: string;
|
|
54
|
-
}): PluginMessage[];
|
|
55
|
-
/**
|
|
56
|
-
* Convenience: send a toast to TUI.
|
|
57
|
-
*/
|
|
58
|
-
export declare function sendTuiToast(db: Database, message: string, options?: {
|
|
59
|
-
variant?: "info" | "warning" | "error" | "success";
|
|
60
|
-
duration?: number;
|
|
61
|
-
sessionId?: string;
|
|
62
|
-
}): number;
|
|
63
|
-
/**
|
|
64
|
-
* Convenience: send a confirmation dialog request to TUI.
|
|
65
|
-
* Returns the message ID which the TUI will reference in its dialog_result response.
|
|
66
|
-
*/
|
|
67
|
-
export declare function sendTuiConfirmDialog(db: Database, id: string, title: string, message: string, sessionId?: string): number;
|
|
68
|
-
/**
|
|
69
|
-
* Convenience: check for a dialog result from TUI.
|
|
70
|
-
* Returns the confirmation result or null if not yet responded.
|
|
71
|
-
*/
|
|
72
|
-
export declare function checkDialogResult(db: Database, dialogId: string): {
|
|
73
|
-
confirmed: boolean;
|
|
74
|
-
} | null;
|
|
75
|
-
//# sourceMappingURL=plugin-messages.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-messages.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/plugin-messages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD;;;;;;;;;;;;;;;;;GAiBG;AAEH,MAAM,MAAM,gBAAgB,GAAG,eAAe,GAAG,eAAe,CAAC;AAEjE,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,gBAAgB,GAAG,eAAe,GAAG,cAAc,GAAG,QAAQ,CAAC;AAEnG,MAAM,WAAW,aAAa;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,gBAAgB,CAAC;IAC5B,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AA6CD;;GAEG;AACH,wBAAgB,SAAS,CACrB,EAAE,EAAE,QAAQ,EACZ,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,CAAC,EAAE,MAAM,GACnB,MAAM,CAOR;AAED;;GAEG;AACH,wBAAgB,YAAY,CACxB,EAAE,EAAE,QAAQ,EACZ,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,CAAC,EAAE,MAAM,GACnB,MAAM,CAOR;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC3B,EAAE,EAAE,QAAQ,EACZ,SAAS,EAAE,gBAAgB,EAC3B,OAAO,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,WAAW,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GACrD,aAAa,EAAE,CAsCjB;AAED;;GAEG;AACH,wBAAgB,YAAY,CACxB,EAAE,EAAE,QAAQ,EACZ,SAAS,EAAE,gBAAgB,EAC3B,OAAO,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,WAAW,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GACrD,aAAa,EAAE,CAmBjB;AAED;;GAEG;AACH,wBAAgB,YAAY,CACxB,EAAE,EAAE,QAAQ,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;IACN,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;IACnD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB,GACF,MAAM,CAWR;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAChC,EAAE,EAAE,QAAQ,EACZ,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,MAAM,GACnB,MAAM,CAER;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,GAAG;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAK/F"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { CandidateCompartment } from "./compartment-runner-types";
|
|
2
|
-
export declare function buildExistingStateXml(compartments: Array<{
|
|
3
|
-
startMessage: number;
|
|
4
|
-
endMessage: number;
|
|
5
|
-
startMessageId: string;
|
|
6
|
-
endMessageId: string;
|
|
7
|
-
title: string;
|
|
8
|
-
content: string;
|
|
9
|
-
}>, facts: Array<{
|
|
10
|
-
category: string;
|
|
11
|
-
content: string;
|
|
12
|
-
}>, memoryBlock?: string): string;
|
|
13
|
-
export declare function mergePriorCompartments(priorCompartments: Array<{
|
|
14
|
-
startMessage: number;
|
|
15
|
-
endMessage: number;
|
|
16
|
-
startMessageId: string;
|
|
17
|
-
endMessageId: string;
|
|
18
|
-
title: string;
|
|
19
|
-
content: string;
|
|
20
|
-
}>, newCompartments: CandidateCompartment[]): CandidateCompartment[];
|
|
21
|
-
//# sourceMappingURL=compartment-runner-state-xml.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compartment-runner-state-xml.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/compartment-runner-state-xml.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAEvE,wBAAgB,qBAAqB,CACjC,YAAY,EAAE,KAAK,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACnB,CAAC,EACF,KAAK,EAAE,KAAK,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,EACnD,WAAW,CAAC,EAAE,MAAM,GACrB,MAAM,CA2CR;AAED,wBAAgB,sBAAsB,CAClC,iBAAiB,EAAE,KAAK,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACnB,CAAC,EACF,eAAe,EAAE,oBAAoB,EAAE,GACxC,oBAAoB,EAAE,CAaxB"}
|
package/dist/index-anhrfygk.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
// src/features/magic-context/dreamer/task-registry.ts
|
|
2
|
-
var CANONICAL_DREAM_TASKS = [
|
|
3
|
-
"map-memories",
|
|
4
|
-
"verify",
|
|
5
|
-
"verify-broad",
|
|
6
|
-
"curate",
|
|
7
|
-
"compress-cues",
|
|
8
|
-
"classify-memories",
|
|
9
|
-
"retrospective",
|
|
10
|
-
"maintain-docs",
|
|
11
|
-
"evaluate-smart-notes",
|
|
12
|
-
"review-user-memories",
|
|
13
|
-
"promote-primers",
|
|
14
|
-
"refresh-primers"
|
|
15
|
-
];
|
|
16
|
-
var AGENTIC_DREAM_TASKS = ["curate", "maintain-docs"];
|
|
17
|
-
var MEMORY_DOMAIN_TASKS = [
|
|
18
|
-
"map-memories",
|
|
19
|
-
"verify",
|
|
20
|
-
"verify-broad",
|
|
21
|
-
"curate",
|
|
22
|
-
"compress-cues",
|
|
23
|
-
"classify-memories",
|
|
24
|
-
"retrospective",
|
|
25
|
-
"promote-primers",
|
|
26
|
-
"refresh-primers"
|
|
27
|
-
];
|
|
28
|
-
var MEMORY_DOMAIN_SET = new Set(MEMORY_DOMAIN_TASKS);
|
|
29
|
-
function leaseKindFor(task) {
|
|
30
|
-
if (MEMORY_DOMAIN_SET.has(task))
|
|
31
|
-
return "memory";
|
|
32
|
-
switch (task) {
|
|
33
|
-
case "review-user-memories":
|
|
34
|
-
return "user-memories";
|
|
35
|
-
case "promote-primers":
|
|
36
|
-
case "refresh-primers":
|
|
37
|
-
return "memory";
|
|
38
|
-
case "maintain-docs":
|
|
39
|
-
return "maintain-docs";
|
|
40
|
-
case "evaluate-smart-notes":
|
|
41
|
-
return "evaluate-smart-notes";
|
|
42
|
-
default:
|
|
43
|
-
return "memory";
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
function leaseKeyFor(task, projectIdentity) {
|
|
47
|
-
const kind = leaseKindFor(task);
|
|
48
|
-
return kind === "user-memories" ? "user-memories" : `${kind}:${projectIdentity}`;
|
|
49
|
-
}
|
|
50
|
-
function isCanonicalDreamTask(value) {
|
|
51
|
-
return CANONICAL_DREAM_TASKS.includes(value);
|
|
52
|
-
}
|
|
53
|
-
function compareTaskOrder(a, b) {
|
|
54
|
-
return CANONICAL_DREAM_TASKS.indexOf(a) - CANONICAL_DREAM_TASKS.indexOf(b);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export { CANONICAL_DREAM_TASKS, AGENTIC_DREAM_TASKS, leaseKindFor, leaseKeyFor, isCanonicalDreamTask, compareTaskOrder };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"opencode-compaction-detector.d.ts","sourceRoot":"","sources":["../../src/shared/opencode-compaction-detector.ts"],"names":[],"mappings":"AAqBA,wBAAgB,+BAA+B,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAsB1E"}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenCode adapter for the harness-agnostic transcript interface.
|
|
3
|
-
*
|
|
4
|
-
* This is a thin proxy over OpenCode's `MessageLike[]` (i.e. `{ info,
|
|
5
|
-
* parts: unknown[] }[]`) — it does NOT copy data. Mutations through
|
|
6
|
-
* `setText`/`setToolOutput`/`replaceWithSentinel` write directly into
|
|
7
|
-
* the source `parts[]` arrays, exactly as the existing OpenCode-only
|
|
8
|
-
* transform code does today. `commit()` is a no-op because OpenCode's
|
|
9
|
-
* AI SDK reads `parts[]` back from the same array we mutated.
|
|
10
|
-
*
|
|
11
|
-
* This module is the boundary that lets the rest of the transform code
|
|
12
|
-
* (which moves to use the Transcript interface in 4b.2) work both for
|
|
13
|
-
* OpenCode and Pi without branching on harness type. By the end of 4b
|
|
14
|
-
* the only OpenCode-aware code in the plugin is this file plus
|
|
15
|
-
* `messages-transform.ts`.
|
|
16
|
-
*
|
|
17
|
-
* ## Mutation contract recap
|
|
18
|
-
*
|
|
19
|
-
* Magic Context's transform mutates message parts in three ways:
|
|
20
|
-
*
|
|
21
|
-
* 1. **Tag prefix injection** — prepends `§N§ ` to text parts and
|
|
22
|
-
* tool result outputs. Repeated tagging is idempotent because
|
|
23
|
-
* `prependTag` strips any existing prefix first.
|
|
24
|
-
*
|
|
25
|
-
* 2. **Sentinel replacement** — when a queued drop fires, the part is
|
|
26
|
-
* replaced with a `[dropped §N§]` or `[truncated §N§]` placeholder.
|
|
27
|
-
* The original tag number is preserved so the agent's mental
|
|
28
|
-
* model of "what was here" survives.
|
|
29
|
-
*
|
|
30
|
-
* 3. **Structural noise stripping** — `step-start`/`step-finish`
|
|
31
|
-
* wrappers and similar structural metadata are replaced with empty
|
|
32
|
-
* sentinel parts so they don't consume tag numbers or get tagged
|
|
33
|
-
* themselves.
|
|
34
|
-
*
|
|
35
|
-
* The OpenCode adapter implements (1) and (2) by editing `part.text` /
|
|
36
|
-
* `part.state.output` in place. For (3), structural parts surface as
|
|
37
|
-
* `kind: "structural"` so callers can filter them out. Adapter does NOT
|
|
38
|
-
* itself perform stripping — that's the transform pipeline's job, called
|
|
39
|
-
* after the adapter wraps the messages.
|
|
40
|
-
*
|
|
41
|
-
* Step 4b.1 ships the adapter alone. The existing OpenCode transform
|
|
42
|
-
* code keeps using `MessageLike[]` directly until 4b.2 migrates the
|
|
43
|
-
* tagging+drops layer to use Transcript instances.
|
|
44
|
-
*/
|
|
45
|
-
import type { Transcript } from "./transcript";
|
|
46
|
-
/**
|
|
47
|
-
* The OpenCode `MessageLike` shape. Re-declared here to avoid a circular
|
|
48
|
-
* import with `tag-messages.ts` (which lives in the magic-context hooks
|
|
49
|
-
* tree and depends on storage). Keeping a local minimal type also makes
|
|
50
|
-
* the adapter trivially unit-testable without booting OpenCode SDK
|
|
51
|
-
* types.
|
|
52
|
-
*
|
|
53
|
-
* MUST stay structurally compatible with `tag-messages.ts MessageLike` —
|
|
54
|
-
* if that file's MessageLike adds a required field, this one needs to
|
|
55
|
-
* add it too. The build will fail loudly if the shapes diverge.
|
|
56
|
-
*/
|
|
57
|
-
export interface OpenCodeMessageLike {
|
|
58
|
-
info: {
|
|
59
|
-
id?: string;
|
|
60
|
-
role?: string;
|
|
61
|
-
sessionID?: string;
|
|
62
|
-
};
|
|
63
|
-
parts: unknown[];
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Wrap an existing `MessageLike[]` as a Transcript. Zero copies — every
|
|
67
|
-
* `TranscriptPart` returned proxies the matching entry in the source
|
|
68
|
-
* `parts` array, and mutations are reflected immediately.
|
|
69
|
-
*/
|
|
70
|
-
export declare function createOpenCodeTranscript(messages: OpenCodeMessageLike[]): Transcript;
|
|
71
|
-
//# sourceMappingURL=transcript-opencode.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transcript-opencode.d.ts","sourceRoot":"","sources":["../../src/shared/transcript-opencode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAIH,OAAO,KAAK,EACR,UAAU,EAIb,MAAM,cAAc,CAAC;AAEtB;;;;;;;;;;GAUG;AACH,MAAM,WAAW,mBAAmB;IAChC,IAAI,EAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACzD,KAAK,EAAE,OAAO,EAAE,CAAC;CACpB;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,mBAAmB,EAAE,GAAG,UAAU,CA2BpF"}
|
package/dist/tools/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
|