@wolfx/opencode-magic-context 0.27.2 → 0.30.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 (125) hide show
  1. package/dist/agents/language-directive.d.ts +27 -0
  2. package/dist/agents/language-directive.d.ts.map +1 -0
  3. package/dist/agents/magic-context-prompt.d.ts +1 -1
  4. package/dist/agents/magic-context-prompt.d.ts.map +1 -1
  5. package/dist/config/project-security.d.ts +1 -0
  6. package/dist/config/project-security.d.ts.map +1 -1
  7. package/dist/config/schema/magic-context.d.ts +15 -0
  8. package/dist/config/schema/magic-context.d.ts.map +1 -1
  9. package/dist/features/magic-context/dreamer/refresh-primers.d.ts +1 -0
  10. package/dist/features/magic-context/dreamer/refresh-primers.d.ts.map +1 -1
  11. package/dist/features/magic-context/dreamer/retrospective-raw-provider.d.ts +0 -1
  12. package/dist/features/magic-context/dreamer/retrospective-raw-provider.d.ts.map +1 -1
  13. package/dist/features/magic-context/dreamer/storage-task-schedule.d.ts +10 -0
  14. package/dist/features/magic-context/dreamer/storage-task-schedule.d.ts.map +1 -1
  15. package/dist/features/magic-context/dreamer/task-config.d.ts +1 -1
  16. package/dist/features/magic-context/dreamer/task-config.d.ts.map +1 -1
  17. package/dist/features/magic-context/dreamer/task-executor.d.ts +1 -3
  18. package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -1
  19. package/dist/features/magic-context/dreamer/task-prompts.d.ts +1 -1
  20. package/dist/features/magic-context/dreamer/task-prompts.d.ts.map +1 -1
  21. package/dist/features/magic-context/dreamer/task-registry.d.ts +0 -1
  22. package/dist/features/magic-context/dreamer/task-registry.d.ts.map +1 -1
  23. package/dist/features/magic-context/dreamer/task-scheduler.d.ts +1 -0
  24. package/dist/features/magic-context/dreamer/task-scheduler.d.ts.map +1 -1
  25. package/dist/features/magic-context/dreamer/verify.d.ts +1 -0
  26. package/dist/features/magic-context/dreamer/verify.d.ts.map +1 -1
  27. package/dist/features/magic-context/memory/memory-migration.d.ts +1 -0
  28. package/dist/features/magic-context/memory/memory-migration.d.ts.map +1 -1
  29. package/dist/features/magic-context/sidekick/agent.d.ts +1 -0
  30. package/dist/features/magic-context/sidekick/agent.d.ts.map +1 -1
  31. package/dist/features/magic-context/smart-notes/sandbox-runner.d.ts.map +1 -1
  32. package/dist/features/magic-context/storage-db.d.ts +2 -21
  33. package/dist/features/magic-context/storage-db.d.ts.map +1 -1
  34. package/dist/features/magic-context/storage-schema-helpers.d.ts +30 -0
  35. package/dist/features/magic-context/storage-schema-helpers.d.ts.map +1 -0
  36. package/dist/features/magic-context/storage-tags.d.ts +0 -5
  37. package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
  38. package/dist/features/magic-context/transform-decision-log.d.ts +1 -0
  39. package/dist/features/magic-context/transform-decision-log.d.ts.map +1 -1
  40. package/dist/features/magic-context/types.d.ts +12 -1
  41. package/dist/features/magic-context/types.d.ts.map +1 -1
  42. package/dist/features/magic-context/user-memory/review-user-memories.d.ts +1 -0
  43. package/dist/features/magic-context/user-memory/review-user-memories.d.ts.map +1 -1
  44. package/dist/hooks/magic-context/apply-operations.d.ts +8 -1
  45. package/dist/hooks/magic-context/apply-operations.d.ts.map +1 -1
  46. package/dist/hooks/magic-context/channel2-delivery.d.ts +9 -5
  47. package/dist/hooks/magic-context/channel2-delivery.d.ts.map +1 -1
  48. package/dist/hooks/magic-context/command-handler.d.ts +1 -0
  49. package/dist/hooks/magic-context/command-handler.d.ts.map +1 -1
  50. package/dist/hooks/magic-context/compartment-runner-historian.d.ts +1 -0
  51. package/dist/hooks/magic-context/compartment-runner-historian.d.ts.map +1 -1
  52. package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
  53. package/dist/hooks/magic-context/compartment-runner-partial-recomp.d.ts.map +1 -1
  54. package/dist/hooks/magic-context/compartment-runner-recomp.d.ts.map +1 -1
  55. package/dist/hooks/magic-context/compartment-runner-types.d.ts +1 -0
  56. package/dist/hooks/magic-context/compartment-runner-types.d.ts.map +1 -1
  57. package/dist/hooks/magic-context/compartment-runner-validation.d.ts +1 -1
  58. package/dist/hooks/magic-context/compartment-runner-validation.d.ts.map +1 -1
  59. package/dist/hooks/magic-context/ctx-reduce-nudge.d.ts +13 -3
  60. package/dist/hooks/magic-context/ctx-reduce-nudge.d.ts.map +1 -1
  61. package/dist/hooks/magic-context/edit-marker.d.ts +11 -0
  62. package/dist/hooks/magic-context/edit-marker.d.ts.map +1 -0
  63. package/dist/hooks/magic-context/event-handler.d.ts +1 -4
  64. package/dist/hooks/magic-context/event-handler.d.ts.map +1 -1
  65. package/dist/hooks/magic-context/hook-handlers.d.ts.map +1 -1
  66. package/dist/hooks/magic-context/hook.d.ts +2 -2
  67. package/dist/hooks/magic-context/hook.d.ts.map +1 -1
  68. package/dist/hooks/magic-context/read-session-formatting.d.ts.map +1 -1
  69. package/dist/hooks/magic-context/recomp-orchestrator.d.ts +1 -0
  70. package/dist/hooks/magic-context/recomp-orchestrator.d.ts.map +1 -1
  71. package/dist/hooks/magic-context/supersession-reclaim.d.ts +34 -0
  72. package/dist/hooks/magic-context/supersession-reclaim.d.ts.map +1 -0
  73. package/dist/hooks/magic-context/system-prompt-hash.d.ts +7 -0
  74. package/dist/hooks/magic-context/system-prompt-hash.d.ts.map +1 -1
  75. package/dist/hooks/magic-context/tag-messages.d.ts +8 -0
  76. package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
  77. package/dist/hooks/magic-context/tool-drop-target.d.ts +2 -0
  78. package/dist/hooks/magic-context/tool-drop-target.d.ts.map +1 -1
  79. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +8 -0
  80. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
  81. package/dist/hooks/magic-context/transform.d.ts +4 -0
  82. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +3911 -5483
  85. package/dist/plugin/conflict-warning-hook.d.ts.map +1 -1
  86. package/dist/plugin/dream-timer.d.ts +1 -0
  87. package/dist/plugin/dream-timer.d.ts.map +1 -1
  88. package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
  89. package/dist/plugin/rpc-handlers.d.ts.map +1 -1
  90. package/dist/plugin/tool-registry.d.ts.map +1 -1
  91. package/dist/shared/announcement.d.ts +1 -1
  92. package/dist/shared/announcement.d.ts.map +1 -1
  93. package/dist/shared/commit-detection.d.ts +29 -0
  94. package/dist/shared/commit-detection.d.ts.map +1 -0
  95. package/dist/shared/exit-abort-registry.d.ts +25 -0
  96. package/dist/shared/exit-abort-registry.d.ts.map +1 -0
  97. package/dist/shared/harness-provider-map.d.ts +30 -0
  98. package/dist/shared/harness-provider-map.d.ts.map +1 -0
  99. package/dist/shared/tag-transcript.d.ts.map +1 -1
  100. package/dist/shared/transcript.d.ts +15 -0
  101. package/dist/shared/transcript.d.ts.map +1 -1
  102. package/dist/shared/tui-preferences.d.ts +1 -1
  103. package/dist/tools/ctx-note/tools.d.ts.map +1 -1
  104. package/dist/tui/badge-contrast.d.ts +46 -0
  105. package/dist/tui/badge-contrast.d.ts.map +1 -0
  106. package/package.json +78 -77
  107. package/src/shared/announcement.ts +2 -6
  108. package/src/shared/commit-detection.test.ts +63 -0
  109. package/src/shared/commit-detection.ts +53 -0
  110. package/src/shared/exit-abort-registry.test.ts +50 -0
  111. package/src/shared/exit-abort-registry.ts +46 -0
  112. package/src/shared/harness-provider-map.test.ts +63 -0
  113. package/src/shared/harness-provider-map.ts +56 -0
  114. package/src/shared/tag-transcript.ts +32 -0
  115. package/src/shared/transcript-opencode.ts +33 -0
  116. package/src/shared/transcript.ts +17 -0
  117. package/src/shared/tui-preferences.ts +2 -2
  118. package/src/tui/badge-contrast.test.ts +83 -0
  119. package/src/tui/badge-contrast.ts +84 -0
  120. package/src/tui/slots/sidebar-content.tsx +2 -1
  121. package/dist/hooks/is-anthropic-provider.d.ts +0 -2
  122. package/dist/hooks/is-anthropic-provider.d.ts.map +0 -1
  123. package/dist/shared/live-server-client.d.ts +0 -50
  124. package/dist/shared/live-server-client.d.ts.map +0 -1
  125. package/src/shared/live-server-client.ts +0 -152
@@ -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
- }