From 0a939a14dabb3d6afbf17d5da08c6d4b863bd99f Mon Sep 17 00:00:00 2001 From: Rhuan Barreto Date: Tue, 5 May 2026 21:59:03 +0200 Subject: [PATCH 1/2] feat: add session-context support for Copilot CLI and opencode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extend the `session-context` command with two new subcommands: - `session-context copilot` — reads Copilot CLI session transcripts from `~/.copilot/session-state/`, matching sessions by workspace `cwd` field via `workspace.yaml` + `events.jsonl` - `session-context opencode` — reads opencode session transcripts from `~/.local/share/opencode/storage/`, matching sessions by project `path` field in session metadata + individual message JSON files Both support `--max-entries` and `--session-id` options, following the existing Cursor subcommand pattern. Also: - Add `copilotSessionStateDir()` and `opencodeStorageDir()` path helpers - Export shared utilities (TranscriptEntry, getContentPreview, RELEVANT_ROLES) from session-context.ts for reuse by per-editor reader modules - Split new readers into separate files to stay under max-lines lint rule - Update EN and pt-br reference docs with new subcommand sections Signed-off-by: Rhuan Barreto --- .../agent-memory/archgate-developer/MEMORY.md | 1 + .../pt-br/reference/cli/session-context.mdx | 38 +++ .../docs/reference/cli/session-context.mdx | 38 +++ src/commands/session-context/copilot.ts | 41 +++ src/commands/session-context/index.ts | 4 + src/commands/session-context/opencode.ts | 41 +++ src/helpers/paths.ts | 31 +++ src/helpers/session-context-copilot.ts | 171 ++++++++++++ src/helpers/session-context-opencode.ts | 225 ++++++++++++++++ src/helpers/session-context.ts | 6 +- tests/commands/session-context.test.ts | 44 +++ .../commands/session-context/copilot.test.ts | 37 +++ .../commands/session-context/opencode.test.ts | 37 +++ tests/helpers/session-context-copilot.test.ts | 251 ++++++++++++++++++ .../helpers/session-context-opencode.test.ts | 241 +++++++++++++++++ 15 files changed, 1203 insertions(+), 3 deletions(-) create mode 100644 src/commands/session-context/copilot.ts create mode 100644 src/commands/session-context/opencode.ts create mode 100644 src/helpers/session-context-copilot.ts create mode 100644 src/helpers/session-context-opencode.ts create mode 100644 tests/commands/session-context/copilot.test.ts create mode 100644 tests/commands/session-context/opencode.test.ts create mode 100644 tests/helpers/session-context-copilot.test.ts create mode 100644 tests/helpers/session-context-opencode.test.ts diff --git a/.claude/agent-memory/archgate-developer/MEMORY.md b/.claude/agent-memory/archgate-developer/MEMORY.md index 6b1e1c0e..ddf269fb 100644 --- a/.claude/agent-memory/archgate-developer/MEMORY.md +++ b/.claude/agent-memory/archgate-developer/MEMORY.md @@ -30,6 +30,7 @@ Skipping steps 2 or 3 is a workflow violation. The user should NEVER have to inv ## Patterns & Fixes +- **YAML double-quoted strings require escaped backslashes for Windows paths in tests** — YAML interprets `\` as an escape character inside double-quoted strings. Writing `cwd: "E:\project"` silently corrupts the parsed value because `\p` is not a valid escape sequence. Fix: use `JSON.stringify(path)` to produce properly escaped YAML values (e.g., `cwd: ${JSON.stringify(cwd)}`). JSON and YAML double-quoted strings share the same escape syntax. Encountered in Copilot CLI session-context tests (`workspace.yaml` with Windows paths). - **`git commit` in temp repos requires local identity** — CI runners have no global `user.email`/`user.name` configured. Any test that runs `git commit` on a temp repo MUST call `git config user.email` and `git config user.name` locally after `git init`. Fails with a cryptic `ShellPromise` error in CI; passes locally. Also captured in ARCH-005 Do's. - **Never use `bunx prettier` directly** — Always use `bun run format` (to fix) or `bun run format:check` (to verify). Using `bunx prettier` can fail or use a different version than the project's devDependency. The same applies to all dev tools: prefer `bun run