Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
feat(context-link): install get-linked-context instructions for codex + gemini
enes99ad461bb827
diff --git a/src/main/context-link-core.test.ts b/src/main/context-link-core.test.tsindex 43f041de3..163e5d4d4 100644--- a/src/main/context-link-core.test.ts+++ b/src/main/context-link-core.test.ts@@ -1,5 +1,12 @@import { describe, it, expect } from 'vitest'-import { buildLinkDoc, resolveLinkTranscript, setNodeTranscript, transcriptPathOf } from './context-link-core'+import {+ buildLinkDoc,+ buildLinkedContextInstructions,+ mergeInstructionsBlock,+ resolveLinkTranscript,+ setNodeTranscript,+ transcriptPathOf+} from './context-link-core'describe('buildLinkDoc', () => {it('enriches each link with tmux name, injected transcript path, and cwd', () => {@@ -123,3 +130,36 @@ describe('setNodeTranscript / transcriptPathOf', () => {expect(transcriptPathOf('nope')).toBe('')})})++describe('mergeInstructionsBlock', () => {+ const block = 'Use the CLI: sh "/x/context.sh" list'+ it('appends the marker-delimited block to existing content', () => {+ const out = mergeInstructionsBlock('# My rules\n\nBe nice.\n', block)+ expect(out).toContain('# My rules')+ expect(out).toContain('<!-- nodeterm:get-linked-context:start -->')+ expect(out).toContain(block)+ expect(out).toContain('<!-- nodeterm:get-linked-context:end -->')+ })+ it('is idempotent: re-merging replaces the block in place', () => {+ const once = mergeInstructionsBlock('# My rules\n', block)+ const twice = mergeInstructionsBlock(once, 'UPDATED body')+ expect(twice.match(/nodeterm:get-linked-context:start/g)).toHaveLength(1)+ expect(twice).toContain('UPDATED body')+ expect(twice).not.toContain('sh "/x/context.sh" list')+ expect(twice).toContain('# My rules')+ })+ it('works on an empty file', () => {+ const out = mergeInstructionsBlock('', block)+ expect(out.startsWith('<!-- nodeterm:get-linked-context:start -->')).toBe(true)+ })+})++describe('buildLinkedContextInstructions', () => {+ it('embeds the shim path and the four commands', () => {+ const s = buildLinkedContextInstructions('/x/context.sh')+ expect(s).toContain('sh "/x/context.sh" list')+ expect(s).toContain('summary')+ expect(s).toContain('transcript')+ expect(s).toContain('terminal')+ })+})diff --git a/src/main/context-link-core.ts b/src/main/context-link-core.tsindex e130331cb..410087e46 100644--- a/src/main/context-link-core.ts+++ b/src/main/context-link-core.ts@@ -40,6 +40,43 @@ export async function resolveLinkTranscript(}}+const INSTR_START = '<!-- nodeterm:get-linked-context:start -->'+const INSTR_END = '<!-- nodeterm:get-linked-context:end -->'++/** Idempotently merge our marker-delimited block into a global instructions file+ * (~/.codex/AGENTS.md, ~/.gemini/GEMINI.md). Everything outside the markers is preserved. */+export function mergeInstructionsBlock(existing: string, block: string): string {+ const full = `${INSTR_START}\n${block.trim()}\n${INSTR_END}`+ const start = existing.indexOf(INSTR_START)+ const end = existing.indexOf(INSTR_END)+ if (start >= 0 && end > start) {+ return existing.slice(0, start) + full + existing.slice(end + INSTR_END.length)+ }+ const sep = existing.trim() ? (existing.endsWith('\n') ? '\n' : '\n\n') : ''+ return existing + sep + full + '\n'+}++/** The instructions body telling codex/gemini how to read linked-node context. */+export function buildLinkedContextInstructions(shimPath: string): string {+ return [+ '# Reading linked nodeterm nodes (get-linked-context)',+ '',+ 'When you run inside a nodeterm canvas session, this node may be linked to other agent',+ 'nodes (Claude, Codex or Gemini) or sticky notes by a context-link edge. You can READ a',+ "linked node's context on demand — nothing is pushed automatically:",+ '',+ '```sh',+ `sh "${shimPath}" list # nodes you are linked to (start here)`,+ `sh "${shimPath}" summary --node <id|title> # last lines of its conversation`,+ `sh "${shimPath}" transcript --node <id|title>`,+ `sh "${shimPath}" terminal --node <id|title> # its recent terminal output`,+ '```',+ '',+ 'Only meaningful inside nodeterm (NODETERM_NODE_ID set) with a linked edge. If the CLI',+ 'says "Not a nodeterm session" or "No linked nodes", there is nothing to read — do not retry.'+ ].join('\n')+}+export interface LinkDocEntry {id: stringtitle: string@@ -108,7 +145,7 @@ function loadLinks() {function pickNode(doc, want) {var links = doc.links- if (!links.length) { out('No linked nodes. Draw a context-link edge from this Claude node to another on the canvas.'); process.exit(0) }+ if (!links.length) { out('No linked nodes. Draw a context-link edge from this node to another on the canvas.'); process.exit(0) }if (want) {var q = String(want).toLowerCase()var m = links.find(function (n) { return String(n.id).toLowerCase() === q || String(n.title || '').toLowerCase() === q })diff --git a/src/main/context-link.ts b/src/main/context-link.tsindex 88f8b7a8d..22a39042c 100644--- a/src/main/context-link.ts+++ b/src/main/context-link.ts@@ -15,7 +15,14 @@ import { IPC } from '../shared/ipc'import type { ContextLinkMap } from '../shared/types'import { type PtyManager } from './pty-manager'import { TMUX_SOCKET } from './tmux-naming'-import { CLI_SCRIPT, buildLinkDoc, resolveLinkTranscript, transcriptPathOf } from './context-link-core'+import {+ CLI_SCRIPT,+ buildLinkDoc,+ buildLinkedContextInstructions,+ mergeInstructionsBlock,+ resolveLinkTranscript,+ transcriptPathOf+} from './context-link-core'import { locateClaude, locateCodex, locateGemini } from './handoff/locate'export { setNodeTranscript } from './context-link-core'@@ -54,12 +61,12 @@ ELECTRON_RUN_AS_NODE=1 exec "${process.execPath}" "${cliScriptPath()}" "$@"function installSkill(): void {const body = `---name: get-linked-context-description: Read the conversation/transcript, a recent summary, or the terminal output of another Claude node you are linked to on the nodeterm canvas. Use when you need to know what a connected node has been doing, hand off, or continue its work. Only meaningful inside a nodeterm session with a context-link edge. Also reads sticky notes linked to this node as context.+description: Read the conversation/transcript, a recent summary, or the terminal output of another agent node (Claude, Codex or Gemini) you are linked to on the nodeterm canvas. Use when you need to know what a connected node has been doing, hand off, or continue its work. Only meaningful inside a nodeterm session with a context-link edge. Also reads sticky notes linked to this node as context.---# Get linked context-On the nodeterm canvas, this Claude session may be connected to other Claude nodes by a+On the nodeterm canvas, this Claude session may be connected to other agent nodes (Claude, Codex or Gemini) by acontext-link edge. When you are linked, you can READ the other node's context on demand byrunning the local CLI shim below. Nothing is pushed to you automatically — pull what you need.@@ -91,6 +98,30 @@ to read — do not retry.}}+// Codex/Gemini have no skill system — merge an instructions block into their global+// instruction files instead (marker-delimited, idempotent, other content preserved).+function installAgentInstructions(): void {+ const block = buildLinkedContextInstructions(cliShimPath())+ const targets = [+ path.join(os.homedir(), '.codex', 'AGENTS.md'),+ path.join(os.homedir(), '.gemini', 'GEMINI.md')+ ]+ for (const p of targets) {+ try {+ let existing = ''+ try {+ existing = fs.readFileSync(p, 'utf8')+ } catch {+ /* new file */+ }+ fs.mkdirSync(path.dirname(p), { recursive: true })+ fs.writeFileSync(p, mergeInstructionsBlock(existing, block), 'utf8')+ } catch (e) {+ console.warn('[context-link] instructions install failed', p, e)+ }+ }+}+let pty: PtyManager | undefinedconst LINK_LOCATORS = { claude: locateClaude, codex: locateCodex, gemini: locateGemini }@@ -141,6 +172,7 @@ export function initContextLink(win: BrowserWindow, ptyManager: PtyManager): voi}writeCliFiles()installSkill()+ installAgentInstructions()} catch (e) {console.error('[context-link] setup failed', e)return