@cortexkit/opencode-magic-context 0.28.0 → 0.29.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.
Files changed (80) hide show
  1. package/README.md +26 -1
  2. package/dist/agents/magic-context-prompt.d.ts +1 -1
  3. package/dist/agents/magic-context-prompt.d.ts.map +1 -1
  4. package/dist/config/schema/magic-context.d.ts +11 -0
  5. package/dist/config/schema/magic-context.d.ts.map +1 -1
  6. package/dist/features/magic-context/dreamer/retrospective-raw-provider.d.ts +0 -1
  7. package/dist/features/magic-context/dreamer/retrospective-raw-provider.d.ts.map +1 -1
  8. package/dist/features/magic-context/dreamer/storage-task-schedule.d.ts +10 -0
  9. package/dist/features/magic-context/dreamer/storage-task-schedule.d.ts.map +1 -1
  10. package/dist/features/magic-context/dreamer/task-executor.d.ts +0 -3
  11. package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -1
  12. package/dist/features/magic-context/dreamer/task-prompts.d.ts +1 -1
  13. package/dist/features/magic-context/dreamer/task-prompts.d.ts.map +1 -1
  14. package/dist/features/magic-context/dreamer/task-registry.d.ts +0 -1
  15. package/dist/features/magic-context/dreamer/task-registry.d.ts.map +1 -1
  16. package/dist/features/magic-context/memory/embedding-local.d.ts +0 -3
  17. package/dist/features/magic-context/memory/embedding-local.d.ts.map +1 -1
  18. package/dist/features/magic-context/smart-notes/sandbox-runner.d.ts.map +1 -1
  19. package/dist/features/magic-context/storage-db.d.ts +2 -21
  20. package/dist/features/magic-context/storage-db.d.ts.map +1 -1
  21. package/dist/features/magic-context/storage-schema-helpers.d.ts +30 -0
  22. package/dist/features/magic-context/storage-schema-helpers.d.ts.map +1 -0
  23. package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
  24. package/dist/features/magic-context/types.d.ts +12 -1
  25. package/dist/features/magic-context/types.d.ts.map +1 -1
  26. package/dist/hooks/magic-context/apply-operations.d.ts +8 -1
  27. package/dist/hooks/magic-context/apply-operations.d.ts.map +1 -1
  28. package/dist/hooks/magic-context/channel2-delivery.d.ts +9 -5
  29. package/dist/hooks/magic-context/channel2-delivery.d.ts.map +1 -1
  30. package/dist/hooks/magic-context/edit-marker.d.ts +11 -0
  31. package/dist/hooks/magic-context/edit-marker.d.ts.map +1 -0
  32. package/dist/hooks/magic-context/event-handler.d.ts +1 -4
  33. package/dist/hooks/magic-context/event-handler.d.ts.map +1 -1
  34. package/dist/hooks/magic-context/hook.d.ts +1 -2
  35. package/dist/hooks/magic-context/hook.d.ts.map +1 -1
  36. package/dist/hooks/magic-context/read-session-formatting.d.ts.map +1 -1
  37. package/dist/hooks/magic-context/supersession-reclaim.d.ts +34 -0
  38. package/dist/hooks/magic-context/supersession-reclaim.d.ts.map +1 -0
  39. package/dist/hooks/magic-context/system-prompt-hash.d.ts +5 -0
  40. package/dist/hooks/magic-context/system-prompt-hash.d.ts.map +1 -1
  41. package/dist/hooks/magic-context/tag-messages.d.ts +8 -0
  42. package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
  43. package/dist/hooks/magic-context/tool-drop-target.d.ts +2 -0
  44. package/dist/hooks/magic-context/tool-drop-target.d.ts.map +1 -1
  45. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +8 -0
  46. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
  47. package/dist/hooks/magic-context/transform.d.ts +4 -0
  48. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +3709 -5436
  51. package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
  52. package/dist/plugin/rpc-handlers.d.ts.map +1 -1
  53. package/dist/plugin/tool-registry.d.ts.map +1 -1
  54. package/dist/shared/announcement.d.ts +1 -1
  55. package/dist/shared/commit-detection.d.ts +29 -0
  56. package/dist/shared/commit-detection.d.ts.map +1 -0
  57. package/dist/shared/exit-abort-registry.d.ts +25 -0
  58. package/dist/shared/exit-abort-registry.d.ts.map +1 -0
  59. package/dist/shared/harness-provider-map.d.ts +30 -0
  60. package/dist/shared/harness-provider-map.d.ts.map +1 -0
  61. package/dist/shared/tag-transcript.d.ts.map +1 -1
  62. package/dist/shared/transcript.d.ts +15 -0
  63. package/dist/shared/transcript.d.ts.map +1 -1
  64. package/dist/tools/ctx-note/tools.d.ts.map +1 -1
  65. package/package.json +1 -1
  66. package/src/shared/announcement.ts +3 -3
  67. package/src/shared/commit-detection.test.ts +63 -0
  68. package/src/shared/commit-detection.ts +53 -0
  69. package/src/shared/exit-abort-registry.test.ts +50 -0
  70. package/src/shared/exit-abort-registry.ts +46 -0
  71. package/src/shared/harness-provider-map.test.ts +63 -0
  72. package/src/shared/harness-provider-map.ts +56 -0
  73. package/src/shared/tag-transcript.ts +32 -0
  74. package/src/shared/transcript-opencode.ts +33 -0
  75. package/src/shared/transcript.ts +17 -0
  76. package/dist/hooks/is-anthropic-provider.d.ts +0 -2
  77. package/dist/hooks/is-anthropic-provider.d.ts.map +0 -1
  78. package/dist/shared/live-server-client.d.ts +0 -50
  79. package/dist/shared/live-server-client.d.ts.map +0 -1
  80. package/src/shared/live-server-client.ts +0 -152
@@ -133,6 +133,23 @@ export interface TranscriptPart {
133
133
  inputTokenCount: number;
134
134
  };
135
135
 
136
+ /**
137
+ * Non-mutating read of this tool invocation's input object, or null for
138
+ * non-tool parts / parts without an input. Used by smart-drops supersession
139
+ * selection (read `ctx_note`'s action, an edit's `filePath`) without
140
+ * touching the wire. Returns the live object reference; callers must NOT
141
+ * mutate it.
142
+ */
143
+ getToolInput?(): Record<string, unknown> | null;
144
+
145
+ /**
146
+ * Replace this tool invocation's input object with `input`. Used by the
147
+ * smart-drops edit_marker path to write back a filePath-preserving,
148
+ * region-hint-clamped copy of an edit's arguments. Returns true if the part
149
+ * carried a writable tool input. No-op (false) for non-tool parts.
150
+ */
151
+ setToolInput?(input: Record<string, unknown>): boolean;
152
+
136
153
  /**
137
154
  * Replace this part with a sentinel placeholder. Sentinels look like
138
155
  * `[dropped §N§]` or `[truncated §N§]` and survive cache-busting
@@ -1,2 +0,0 @@
1
- export declare function isAnthropicProvider(providerID: string): boolean;
2
- //# sourceMappingURL=is-anthropic-provider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"is-anthropic-provider.d.ts","sourceRoot":"","sources":["../../src/hooks/is-anthropic-provider.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAE/D"}
@@ -1,50 +0,0 @@
1
- /**
2
- * Live-server client for the Channel 2 ctx_reduce ceiling nudge (a synthetic
3
- * user `<system-reminder>` delivered via `promptAsync`).
4
- *
5
- * WHY a separate client instead of the plugin-provided `input.client`:
6
- * OpenCode's plugin `input.client` routes through `Server.Default().app.fetch`,
7
- * which uses a SEPARATE Effect `memoMap` from the live HTTP listener the UI
8
- * uses. `SessionRunState` lives per-memoMap, so a plugin-origin `promptAsync`
9
- * observes an "idle" runner while the live turn is still running, `ensureRunning`
10
- * fails to coalesce, and OpenCode persists duplicate assistant children
11
- * (upstream bug anomalyco/opencode#28202). Building a `createOpencodeClient`
12
- * aimed at `input.serverUrl` via `globalThis.fetch` enters the SAME live
13
- * listener, so `ensureRunning` sees the real run and coalesces — the synthetic
14
- * message lands at the tail after the current assistant step.
15
- *
16
- * The live listener is only reachable on OpenCode Desktop (Electron+Node) and
17
- * TUI launched with `--port 0`; plain TUI binds an internal listener that 404s
18
- * `/session/*`. We probe once at init and cache per `serverUrl`. When
19
- * unreachable, Channel 2 is DISABLED (Channel 1 + 85% force-materialization
20
- * remain the backstop) — MC deliberately does NOT fall back to the in-process
21
- * client because that would knowingly trigger #28202.
22
- */
23
- import { createOpencodeClient } from "@opencode-ai/sdk";
24
- export type LiveServerClient = ReturnType<typeof createOpencodeClient>;
25
- /**
26
- * Cached `createOpencodeClient` aimed at the live HTTP listener for the given
27
- * `(serverUrl, directory)`. One client is reused across deliveries.
28
- */
29
- export declare function getLiveServerClient(serverUrl: string, directory: string): LiveServerClient;
30
- /**
31
- * Probe whether `serverUrl` serves OpenCode's HTTP API within `timeoutMs`.
32
- * `true` only when `/session` proves the API is usable: any 2xx, or 401/403
33
- * (auth-protected listener still exists). `false` for 404 (plain TUI internal
34
- * listener), 5xx, connection refused, DNS failure, timeout, or malformed URL.
35
- * Records the result + timestamp in the per-serverUrl cache.
36
- */
37
- export declare function probeServerReachable(serverUrl: string | undefined, timeoutMs?: number): Promise<boolean>;
38
- /** Record a probe result directly (test helper / explicit override). */
39
- export declare function setLiveServerWakeAvailable(serverUrl: string | undefined, available: boolean): void;
40
- /**
41
- * Should Channel 2 deliver through the live-server client for `serverUrl`?
42
- * Returns false when never probed or the last probe failed. A stale decision
43
- * (older than the TTL) returns false so the caller re-probes before delivering.
44
- */
45
- export declare function useLiveServerWake(serverUrl?: string): boolean;
46
- /** True when a usable (non-stale) probe decision exists, regardless of outcome. */
47
- export declare function hasFreshProbe(serverUrl?: string): boolean;
48
- /** Test helper — reset both caches between cases. */
49
- export declare function __resetLiveServerClientForTests(): void;
50
- //# sourceMappingURL=live-server-client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"live-server-client.d.ts","sourceRoot":"","sources":["../../src/shared/live-server-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC;AA0BvE;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,gBAAgB,CAY1F;AAcD;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CACtC,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,SAAS,SAAO,GACjB,OAAO,CAAC,OAAO,CAAC,CAqBlB;AAED,wEAAwE;AACxE,wBAAgB,0BAA0B,CACtC,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,SAAS,EAAE,OAAO,GACnB,IAAI,CAMN;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAM7D;AAED,mFAAmF;AACnF,wBAAgB,aAAa,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAKzD;AAED,qDAAqD;AACrD,wBAAgB,+BAA+B,IAAI,IAAI,CAGtD"}
@@ -1,152 +0,0 @@
1
- /**
2
- * Live-server client for the Channel 2 ctx_reduce ceiling nudge (a synthetic
3
- * user `<system-reminder>` delivered via `promptAsync`).
4
- *
5
- * WHY a separate client instead of the plugin-provided `input.client`:
6
- * OpenCode's plugin `input.client` routes through `Server.Default().app.fetch`,
7
- * which uses a SEPARATE Effect `memoMap` from the live HTTP listener the UI
8
- * uses. `SessionRunState` lives per-memoMap, so a plugin-origin `promptAsync`
9
- * observes an "idle" runner while the live turn is still running, `ensureRunning`
10
- * fails to coalesce, and OpenCode persists duplicate assistant children
11
- * (upstream bug anomalyco/opencode#28202). Building a `createOpencodeClient`
12
- * aimed at `input.serverUrl` via `globalThis.fetch` enters the SAME live
13
- * listener, so `ensureRunning` sees the real run and coalesces — the synthetic
14
- * message lands at the tail after the current assistant step.
15
- *
16
- * The live listener is only reachable on OpenCode Desktop (Electron+Node) and
17
- * TUI launched with `--port 0`; plain TUI binds an internal listener that 404s
18
- * `/session/*`. We probe once at init and cache per `serverUrl`. When
19
- * unreachable, Channel 2 is DISABLED (Channel 1 + 85% force-materialization
20
- * remain the backstop) — MC deliberately does NOT fall back to the in-process
21
- * client because that would knowingly trigger #28202.
22
- */
23
-
24
- import { createOpencodeClient } from "@opencode-ai/sdk";
25
-
26
- export type LiveServerClient = ReturnType<typeof createOpencodeClient>;
27
-
28
- const clientCache = new Map<string, LiveServerClient>();
29
-
30
- function cacheKey(serverUrl: string, directory: string): string {
31
- return `${serverUrl}|${directory}`;
32
- }
33
-
34
- function normalizeServerUrl(serverUrl: string): string {
35
- try {
36
- return new URL(serverUrl).toString();
37
- } catch {
38
- return serverUrl;
39
- }
40
- }
41
-
42
- /** Basic-auth header OpenCode expects when `OPENCODE_SERVER_PASSWORD` is set. */
43
- function serverAuthHeaders(): Record<string, string> | undefined {
44
- const password = process.env.OPENCODE_SERVER_PASSWORD;
45
- if (!password) return undefined;
46
- const username = process.env.OPENCODE_SERVER_USERNAME ?? "opencode";
47
- return {
48
- Authorization: `Basic ${Buffer.from(`${username}:${password}`).toString("base64")}`,
49
- };
50
- }
51
-
52
- /**
53
- * Cached `createOpencodeClient` aimed at the live HTTP listener for the given
54
- * `(serverUrl, directory)`. One client is reused across deliveries.
55
- */
56
- export function getLiveServerClient(serverUrl: string, directory: string): LiveServerClient {
57
- const key = cacheKey(serverUrl, directory);
58
- const cached = clientCache.get(key);
59
- if (cached) return cached;
60
- const client = createOpencodeClient({
61
- baseUrl: serverUrl,
62
- directory,
63
- headers: serverAuthHeaders(),
64
- fetch: globalThis.fetch,
65
- });
66
- clientCache.set(key, client);
67
- return client;
68
- }
69
-
70
- // Per-serverUrl wake decision + probe TTL. One plugin process can host multiple
71
- // OpenCode windows with different listener URLs, so the decision must be keyed.
72
- interface ProbeDecision {
73
- reachable: boolean;
74
- probedAt: number;
75
- }
76
- const wakeDecisionByServerUrl = new Map<string, ProbeDecision>();
77
-
78
- // Re-probe window: a transient 404/timeout shouldn't permanently disable
79
- // Channel 2 for the whole session lifetime (per council-r3).
80
- const PROBE_TTL_MS = 10 * 60_000;
81
-
82
- /**
83
- * Probe whether `serverUrl` serves OpenCode's HTTP API within `timeoutMs`.
84
- * `true` only when `/session` proves the API is usable: any 2xx, or 401/403
85
- * (auth-protected listener still exists). `false` for 404 (plain TUI internal
86
- * listener), 5xx, connection refused, DNS failure, timeout, or malformed URL.
87
- * Records the result + timestamp in the per-serverUrl cache.
88
- */
89
- export async function probeServerReachable(
90
- serverUrl: string | undefined,
91
- timeoutMs = 1500,
92
- ): Promise<boolean> {
93
- if (!serverUrl) return false;
94
- const normalized = normalizeServerUrl(serverUrl);
95
- const controller = new AbortController();
96
- const timer = setTimeout(() => controller.abort(), timeoutMs);
97
- let reachable = false;
98
- try {
99
- const probeUrl = new URL("/session", serverUrl).toString();
100
- const res = await globalThis.fetch(probeUrl, {
101
- method: "GET",
102
- headers: serverAuthHeaders(),
103
- signal: controller.signal,
104
- });
105
- reachable = res.ok || res.status === 401 || res.status === 403;
106
- } catch {
107
- reachable = false;
108
- } finally {
109
- clearTimeout(timer);
110
- wakeDecisionByServerUrl.set(normalized, { reachable, probedAt: Date.now() });
111
- }
112
- return reachable;
113
- }
114
-
115
- /** Record a probe result directly (test helper / explicit override). */
116
- export function setLiveServerWakeAvailable(
117
- serverUrl: string | undefined,
118
- available: boolean,
119
- ): void {
120
- if (!serverUrl) return;
121
- wakeDecisionByServerUrl.set(normalizeServerUrl(serverUrl), {
122
- reachable: available,
123
- probedAt: Date.now(),
124
- });
125
- }
126
-
127
- /**
128
- * Should Channel 2 deliver through the live-server client for `serverUrl`?
129
- * Returns false when never probed or the last probe failed. A stale decision
130
- * (older than the TTL) returns false so the caller re-probes before delivering.
131
- */
132
- export function useLiveServerWake(serverUrl?: string): boolean {
133
- if (!serverUrl) return false;
134
- const decision = wakeDecisionByServerUrl.get(normalizeServerUrl(serverUrl));
135
- if (!decision) return false;
136
- if (Date.now() - decision.probedAt > PROBE_TTL_MS) return false;
137
- return decision.reachable;
138
- }
139
-
140
- /** True when a usable (non-stale) probe decision exists, regardless of outcome. */
141
- export function hasFreshProbe(serverUrl?: string): boolean {
142
- if (!serverUrl) return false;
143
- const decision = wakeDecisionByServerUrl.get(normalizeServerUrl(serverUrl));
144
- if (!decision) return false;
145
- return Date.now() - decision.probedAt <= PROBE_TTL_MS;
146
- }
147
-
148
- /** Test helper — reset both caches between cases. */
149
- export function __resetLiveServerClientForTests(): void {
150
- clientCache.clear();
151
- wakeDecisionByServerUrl.clear();
152
- }