|
5 | 5 | * It imports myelin's graph library directly — no subprocess spawning. |
6 | 6 | * |
7 | 7 | * Tools: myelin_query, myelin_boot, myelin_log, myelin_show, myelin_stats, myelin_sleep |
8 | | - * Hooks: Diagnostic-only (CLI v1.0.8 #2076 overwrites them in multi-extension setups) |
9 | | - * Events: session.on("user.message") for boot, session.on("session.task_complete") for |
10 | | - * auto-logging, session.on("session.shutdown") for session-end fallback |
| 8 | + * Hooks: onSessionStart returns { additionalContext } for boot context injection (CLI ≥v1.0.11) |
| 9 | + * Events: session.on("session.task_complete") for auto-logging, |
| 10 | + * session.on("session.shutdown") for session-end fallback |
11 | 11 | */ |
12 | 12 |
|
13 | 13 | import { homedir } from "node:os"; |
@@ -36,11 +36,7 @@ function hookLog(msg: string) { |
36 | 36 | // Session-level agent identity — set when myelin_boot is called |
37 | 37 | let sessionAgent: string | null = null; |
38 | 38 | let taskCompleteLogged = false; |
39 | | -// Build boot context eagerly at module load time. |
40 | | -// CLI v1.0.8 has a bug where multiple extensions with hooks overwrite each other |
41 | | -// (last extension to resume wins — updateOptions does this.hooks = e.hooks, not merge). |
42 | | -// So hooks are unreliable. Instead, we inject context via session.send() on first |
43 | | -// user.message event, which uses the event listener API and is not affected by the bug. |
| 39 | +// Build boot context eagerly at module load time for injection via onSessionStart hook. |
44 | 40 | let eagerBootContext: string | null = null; |
45 | 41 | try { |
46 | 42 | eagerBootContext = buildBootContext(); |
@@ -169,7 +165,17 @@ const session = await joinSession({ |
169 | 165 | onPermissionRequest: approveAll, |
170 | 166 |
|
171 | 167 | hooks: { |
172 | | - onSessionStart: async () => { hookLog(`onSessionStart fired — v${MYELIN_VERSION}`); }, |
| 168 | + onSessionStart: async () => { |
| 169 | + hookLog(`onSessionStart fired — v${MYELIN_VERSION}`); |
| 170 | + if (eagerBootContext) { |
| 171 | + const ctx = eagerBootContext; |
| 172 | + eagerBootContext = null; // One-shot — don't re-inject on resume |
| 173 | + hookLog(`onSessionStart returning additionalContext (${ctx.length} chars)`); |
| 174 | + return { |
| 175 | + additionalContext: `<myelin_boot_context>\n${ctx}\n</myelin_boot_context>\n\nContinue with the user's request. The above is injected context from myelin's knowledge graph — do not repeat it to the user.`, |
| 176 | + }; |
| 177 | + } |
| 178 | + }, |
173 | 179 | onUserPromptSubmitted: async () => {}, |
174 | 180 | onSessionEnd: async () => { hookLog('onSessionEnd fired'); }, |
175 | 181 | onPostToolUse: async () => { hookLog('onPostToolUse fired'); }, |
@@ -496,24 +502,7 @@ const session = await joinSession({ |
496 | 502 | ], |
497 | 503 | }); |
498 | 504 |
|
499 | | -// Inject boot context via session.send() on first user message. |
500 | | -// This bypasses the CLI hook overwrite bug where only the last |
501 | | -// extension's hooks survive (github/copilot-cli#2142). |
502 | | -if (eagerBootContext) { |
503 | | - const bootContext = eagerBootContext; |
504 | | - eagerBootContext = null; |
505 | | - |
506 | | - const unsub = session.on("user.message", () => { |
507 | | - unsub(); // One-shot — unsubscribe immediately |
508 | | - hookLog(`session.on("user.message") injecting boot context (${bootContext.length} chars)`); |
509 | | - session.send({ |
510 | | - prompt: `<myelin_boot_context>\n${bootContext}\n</myelin_boot_context>\n\nContinue with the user's request. The above is injected context from myelin's knowledge graph — do not repeat it to the user.`, |
511 | | - }); |
512 | | - }); |
513 | | -} |
514 | | - |
515 | 505 | // Auto-log task_complete summaries via event listener. |
516 | | -// Bypasses CLI hook overwrite bug — session.on() is per-connection. |
517 | 506 | session.on("session.task_complete", (event: any) => { |
518 | 507 | if (taskCompleteLogged) return; |
519 | 508 | taskCompleteLogged = true; |
|
0 commit comments