@polygraph/opencode-plugin 0.4.35 → 0.4.37

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.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  <p align="center">
2
2
  <picture>
3
- <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nrwl/polygraph-skills/source/assets/polygraph-light.svg">
4
- <img src="https://raw.githubusercontent.com/nrwl/polygraph-skills/source/assets/polygraph.svg" alt="Polygraph Logo" width="140">
3
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nrwl/polygraph-skills/main/source/assets/polygraph-light.svg">
4
+ <img src="https://raw.githubusercontent.com/nrwl/polygraph-skills/main/source/assets/polygraph.svg" alt="Polygraph Logo" width="140">
5
5
  </picture>
6
6
  </p>
7
7
 
@@ -37,9 +37,10 @@ It detects your AI agent — Claude Code, Codex, OpenCode, and more — and inst
37
37
 
38
38
  ## Skills
39
39
 
40
- - **polygraph** — Comprehensive guidance for multi-repo coordination: session init, delegation, branch pushing, PR creation, and session management
40
+ - **polygraph** — Comprehensive guidance for Polygraph sessions: shared context, repository graph visibility, PR/CI state, delegation, and session management
41
41
  - **await-polygraph-ci** — Wait for CI pipelines to settle across all repos in a session, investigate failures, and present fix options
42
42
  - **get-latest-ci** — One-shot fetch of the latest CI pipeline execution for the current branch
43
+ - **session-debrief** — Analyze the raw logs of past Polygraph sessions and produce structured, rank-ordered debriefs for use in a different session
43
44
 
44
45
  ## Agents
45
46
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@polygraph/opencode-plugin",
3
- "version": "0.4.35",
4
- "description": "AI agent skills and subagents for Polygraph multi-repo coordination",
3
+ "version": "0.4.37",
4
+ "description": "AI agent skills and subagents for Polygraph sessions, repository context, and coordination",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
7
7
  "author": {
@@ -10,9 +10,30 @@ Wait for all CI pipelines in a Polygraph session to reach a stable state (succee
10
10
 
11
11
  Some Polygraph tools have both MCP and CLI equivalents — use whichever is available in your environment. See the polygraph skill's tool table for the full mapping.
12
12
 
13
+ ## CI status source
14
+
15
+ CI polling uses the polygraph-mcp `show_session` tool, which now carries per-PR CI status directly on each pull request:
16
+
17
+ ```
18
+ show_session(sessionId: "<session-id>")
19
+ ```
20
+
21
+ It returns the full session, including `repositories[]` (for repo display names) and `pullRequests[]`. Each `pullRequests[]` entry has `id`, `repositoryId`, `url`, `branch`, `status` (PR status: `DRAFT` / `OPEN` / `MERGED` / `CLOSED`), and a `ci` object — **`ci` may be absent if the PR has no CI**. When present, `ci` has `status`, `cipeUrl` (non-null ⇒ CIPE; null + `externalCIRuns` ⇒ external CI), `completedAt`, `selfHealingStatus`, and `externalCIRuns[]` (each with `runId`, `name`, `status`, `conclusion`, `url`, and `jobs[]`). Always read `ci` defensively (`pr.ci?.…`).
22
+
23
+ ## Prerequisite: Nx MCP server (CIPE deep-dive + self-healing)
24
+
25
+ CIPE failure investigation (`ci_information`) and applying/rejecting self-healing fixes (`update_self_healing_fix`) are **not** polygraph-mcp tools — they are provided by the **Nx MCP server** (`mcp__plugin_nx_nx-mcp`). Before relying on the Phase 4 CIPE deep-dive or the Phase 5 self-healing actions, install the Nx MCP server and verify it is available.
26
+
27
+ If the Nx MCP server is **not** available, this skill can still:
28
+
29
+ - Monitor CI to a terminal state (Phases 1–3) via `show_session`, and
30
+ - Download and inspect **external-CI** job logs via `get_ci_logs` (a polygraph-mcp tool).
31
+
32
+ But it **cannot** perform CIPE deep-dives (`ci_information`) or apply self-healing fixes (`update_self_healing_fix`) without the Nx MCP server. If nx-mcp is missing, state this limitation to the user explicitly.
33
+
13
34
  ## Phase 1: Session Setup
14
35
 
15
- Fetch the Polygraph session using `show_session`.
36
+ Fetch the session using `show_session` and read per-PR CI status from `pullRequests[]`.
16
37
 
17
38
  **Parameters:**
18
39
 
@@ -23,16 +44,18 @@ show_session(sessionId: "<session-id>")
23
44
  ```
24
45
 
25
46
  1. Record `monitorStartedAt` = current timestamp (epoch millis).
26
- 2. Build a tracking table of all repos with PRs. For each PR, record:
27
- - `repo`: repository name
28
- - `prUrl`: PR URL
29
- - `prStatus`: DRAFT / OPEN / MERGED / CLOSED
30
- - `ciStatus`: from session (may already be a terminal status from a previous run)
31
- - `cipeUrl`: CI pipeline URL (null if none)
32
- - `cipeCompletedAt`: `completedAt` from session (epoch millis, null if CIPE is active or absent)
33
- - `selfHealingStatus`: self-healing fix status (null if none)
47
+ 2. Build a tracking table from `pullRequests[]`. For each PR, map:
48
+ - `repo`: repository display name from the matching `repositories[]` entry by `pr.repositoryId` (fall back to `pr.branch` if not found)
49
+ - `repoId`: `pr.repositoryId` (pass straight to `get_ci_logs`)
50
+ - `prUrl`: `pr.url`
51
+ - `prStatus`: `pr.status` (DRAFT / OPEN / MERGED / CLOSED)
52
+ - `ciStatus`: `pr.ci?.status` (may already be a terminal status from a previous run)
53
+ - `cipeUrl`: `pr.ci?.cipeUrl` (null if none external CI or no CI)
54
+ - `cipeCompletedAt`: `pr.ci?.completedAt` (epoch millis, null if CIPE is active or absent)
55
+ - `selfHealingStatus`: `pr.ci?.selfHealingStatus` (null if none)
56
+ - `jobs`: `pr.ci?.externalCIRuns?.flatMap(r => r.jobs)` (external-CI job list, used in Phase 4)
34
57
  - `firstSeenAt`: current timestamp
35
- 3. If no PRs found, report "No PRs in session" and exit.
58
+ 3. If `pullRequests[]` is empty, report "No PRs in session" and exit.
36
59
  4. **Stale detection**: For each PR, determine if its CI status is **stale** — meaning it reflects a previous run, not a current one. A PR's CI status is stale if:
37
60
  - `cipeCompletedAt` is non-null AND `cipeCompletedAt < monitorStartedAt` (the CIPE finished before the monitor started)
38
61
  - Mark these PRs as `stale: true`
@@ -52,7 +75,7 @@ show_session(sessionId: "<session-id>")
52
75
  **Each poll iteration:**
53
76
 
54
77
  1. Call `show_session(sessionId: <session-id>)`
55
- 2. Update each tracked PR from the session response: `ciStatus`, `cipeUrl`, `cipeCompletedAt`, and `selfHealingStatus`
78
+ 2. Update each tracked PR from its matching `pullRequests[]` entry (by PR `id` / `repositoryId`): `ciStatus` ← `pr.ci?.status`, `cipeUrl` ← `pr.ci?.cipeUrl`, `cipeCompletedAt` ← `pr.ci?.completedAt`, `selfHealingStatus` `pr.ci?.selfHealingStatus`, `prStatus` ← `pr.status`, and `jobs` ← `pr.ci?.externalCIRuns?.flatMap(r => r.jobs)`
56
79
  3. **Clear stale flag**: If a PR was marked `stale: true` and its `cipeCompletedAt` has changed (or become null, meaning a new CIPE is active), clear the stale flag — this PR now has fresh CI data.
57
80
  4. Display status update:
58
81
  ```
@@ -100,18 +123,18 @@ Include self-healing status for any repo that has one.
100
123
 
101
124
  ## Phase 4: Failure Investigation (Child Agent Delegation)
102
125
 
103
- For each repo with `ciStatus: FAILED`, first check the CI data source from `ciStatus[prId]`:
126
+ For each repo with `ciStatus: FAILED`, branch on the PR's `ci` object from `show_session` (`pullRequests[]`):
104
127
 
105
- - **If `cipeUrl` is non-null** → CIPE is authoritative. Delegate investigation using `ci_information`.
106
- - **If `cipeUrl` is null but `externalCIRuns` exists** → external CI only. Examine failed jobs from `externalCIRuns` in the session data and use `get_ci_logs` for log retrieval.
128
+ - **If `pr.ci.cipeUrl` is non-null** → CIPE is authoritative. Delegate investigation using the Nx MCP `ci_information` tool (requires the Nx MCP server — see the prerequisite note above; if nx-mcp is unavailable, report the CIPE URL but note the deep-dive can't run).
129
+ - **If `pr.ci.cipeUrl` is null but `pr.ci.externalCIRuns` exists** → external CI only. Examine failed jobs from `pr.ci.externalCIRuns[].jobs` and use `get_ci_logs(sessionId, repositoryId, jobId)` (a polygraph-mcp tool) for log retrieval, passing `pr.repositoryId` and the failed job's `jobId` straight from the same PR object.
107
130
 
108
- 1. Display known info from the session data before delegating:
131
+ 1. Display known info from the PR's `ci` object before delegating:
109
132
 
110
133
  ```
111
134
  Repository: frontend
112
135
  CI Source: <CIPE or External CI (GitHub Actions)>
113
- CI Pipeline: <cipeUrl from session, or GitHub Actions run URL>
114
- Self-healing: <selfHealingStatus from session, or "None">
136
+ CI Pipeline: <pr.ci.cipeUrl, or GitHub Actions run URL>
137
+ Self-healing: <pr.ci.selfHealingStatus, or "None">
115
138
  Investigating failure details...
116
139
  ```
117
140
 
@@ -119,9 +142,9 @@ For each repo with `ciStatus: FAILED`, first check the CI data source from `ciSt
119
142
 
120
143
  - `sessionId`: the session ID
121
144
  - `repo`: the repository name
122
- - `instruction` (when CIPE exists): Use the `ci_information` tool to investigate the CI failure on this branch. Return a structured summary with: (1) list of failed task IDs with a one-line error summary each, (2) failure category (Build / Test / Lint / E2E / Infra / Other).
123
- - `instruction` (when no CIPE, external CI only): The session data shows external CI failures with these failed jobs: [list jobId + name from `externalCIRuns[].jobs` where `conclusion` is `failure`]. Use `get_ci_logs(sessionId, repoId, jobId)` to save the log for each failed job to a local file, then use the `Read` tool to examine the log file contents. Return a structured summary with: (1) one-line error summary per failed job, (2) failure category (Build / Test / Lint / E2E / Infra / Other), (3) relevant log excerpts.
124
- - `context`: Polygraph session monitoring — investigating CI failure for unified summary. The repository ID for this repo is available from the session data.
145
+ - `instruction` (when CIPE exists): Use the Nx MCP `ci_information` tool to investigate the CI failure on this branch (the Nx MCP server must be installed). Return a structured summary with: (1) list of failed task IDs with a one-line error summary each, (2) failure category (Build / Test / Lint / E2E / Infra / Other).
146
+ - `instruction` (when no CIPE, external CI only): The PR's `ci` object shows external CI failures with these failed jobs: [list `jobId` + `name` from `pr.ci.externalCIRuns[].jobs` where `conclusion` is `failure`]. Use `get_ci_logs(sessionId, repositoryId, jobId)` to save the log for each failed job to a local file, then use the `Read` tool to examine the log file contents. Return a structured summary with: (1) one-line error summary per failed job, (2) failure category (Build / Test / Lint / E2E / Infra / Other), (3) relevant log excerpts.
147
+ - `context`: Polygraph session monitoring — investigating CI failure for unified summary. The repository ID for this repo is the PR's `repositoryId`.
125
148
 
126
149
  Since `spawn_agent` is non-blocking, you can delegate to multiple failed repos in parallel.
127
150
 
@@ -156,7 +179,7 @@ For each repo with `ciStatus: FAILED`, first check the CI data source from `ciSt
156
179
  2. Identify cross-repo dependency issues (e.g., shared-lib build failure blocking frontend)
157
180
  3. Suggest fix order based on dependency graph (upstream repos first)
158
181
  4. Present next actions to the user based on self-healing status:
159
- - If any repo has `selfHealingStatus` with an available fix → offer to **apply self-healing** via `update_self_healing_fix(action: "APPLY")` or **reject** it
182
+ - If any repo has `selfHealingStatus` with an available fix → offer to **apply self-healing** via `update_self_healing_fix(action: "APPLY")` or **reject** it. `update_self_healing_fix` is an **Nx MCP** tool (`mcp__plugin_nx_nx-mcp`) — it requires the Nx MCP server. If nx-mcp is unavailable, report that a fix is available but cannot be applied from here.
160
183
  - If self-healing was already applied → offer to **resume monitoring** to watch the re-triggered CI
161
184
  - **Delegate fixes**: use Polygraph to send fix instructions to child agents (for repos without self-healing or where self-healing was rejected/failed)
162
185
  - **Get more details**: drill into a specific repo's failure
@@ -164,10 +187,10 @@ For each repo with `ciStatus: FAILED`, first check the CI data source from `ciSt
164
187
 
165
188
  ## Notes
166
189
 
167
- - This skill does NOT push code directly. The only write action it may take is applying/rejecting a self-healing fix via `update_self_healing_fix`, which is an Nx Cloud operation (not a local code change).
168
- - Both `ci_information` and `update_self_healing_fix` responses include a `hints` array with contextual guidance (e.g., disclaimers about which CI Attempt was retrieved). Always check and surface non-empty hints.
190
+ - This skill does NOT push code directly. The only write action it may take is applying/rejecting a self-healing fix via `update_self_healing_fix`, an **Nx MCP** tool that performs an Nx Cloud operation (not a local code change) and requires the Nx MCP server.
191
+ - Both `ci_information` and `update_self_healing_fix` are **Nx MCP** tools (`mcp__plugin_nx_nx-mcp`), not polygraph-mcp tools. Their responses include a `hints` array with contextual guidance (e.g., disclaimers about which CI Attempt was retrieved). Always check and surface non-empty hints.
169
192
  - All heavy CI data inspection happens in child agents via `spawn_agent` to keep this context window clean.
170
193
 
171
- - Child agents can use `get_ci_logs` to save CI job logs to local files, but ONLY when no CIPE exists for the PR (`ciStatus[prId].cipeUrl` is null). When a CIPE exists, logs come from the CIPE system via `ci_information`. Job IDs come from `ciStatus[prId].externalCIRuns[].jobs[].jobId` in the `show_session` response. The tool returns a file path (`logFile`) and size (`sizeBytes`) — use the `Read` tool to examine the log content. Logs can be large (100KB+), so only fetch logs for failed or relevant jobs.
194
+ - Child agents can use `get_ci_logs` to save CI job logs to local files, but ONLY when no CIPE exists for the PR (`pr.ci.cipeUrl` is null). When a CIPE exists, logs come from the CIPE system via the Nx MCP `ci_information` tool. Job IDs come from `pr.ci.externalCIRuns[].jobs[].jobId` in the `show_session` response. The tool returns a file path (`logFile`) and size (`sizeBytes`) — use the `Read` tool to examine the log content. Logs can be large (100KB+), so only fetch logs for failed or relevant jobs.
172
195
  - `spawn_agent` is **non-blocking** — it starts the child agent and returns immediately. Use `show_agent` to poll for results and `stop_agent` to terminate stuck agents.
173
196
  - The `show_session` response is compact and safe to poll from the main agent.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: polygraph
3
- description: Guidance for working with Polygraph — repositories, sessions, child agents, PRs, and CI. Use when discovering repositories or how code is consumed across them, starting, joining, resuming, or sharing a Polygraph session, handing off progress, coordinating changes/branches/PRs across repos, delegating tasks to child agents in different repos, or checking CI status and logs. TRIGGER when user mentions "polygraph", resuming or sharing a session, "other repos", "other repositories", "who uses this", "what uses this", "cross-repo", "multi-repo", "consuming this API/endpoint", "dependent repositories", or asks about what other repos are doing with shared code/APIs/endpoints.
3
+ description: Guidance for working with Polygraph sessions, shared/resumable agent context, repository graph visibility, linked PR/CI state, and cross-repo expansion when needed. Use when starting, joining, resuming, inspecting, or sharing a Polygraph session; handing off progress; discovering related repositories; coordinating changes/branches/PRs across repos; delegating tasks to child agents in different repos; or checking CI status and logs. TRIGGER when user mentions "polygraph", resuming or sharing a session, "other repos", "other repositories", "who uses this", "what uses this", "cross-repo", "multi-repo", "consuming this API/endpoint", "dependent repositories", or asks about what other repos are doing with shared code/APIs/endpoints.
4
4
 
5
5
  ---
6
6
 
@@ -52,10 +52,13 @@ Before using Polygraph tools, ensure the CLI is authenticated and an organizatio
52
52
 
53
53
  ### Check Authentication
54
54
 
55
- Use `polygraph whoami` (or the `whoami` MCP tool) to check if the user is currently logged in and which organization is active.
55
+ Use `polygraph whoami` (or the `whoami` MCP tool) before session work to check if the user is currently logged in and which organization is active.
56
56
 
57
57
  - If the user **is logged in** and an org is selected → proceed to the workflow.
58
- - If the user **is not logged in** → use `polygraph auth login` (or the `login` MCP tool) to authenticate. After login, an organization must be selected.
58
+ - If auth is **missing, expired, or no org is selected** → stop session work. Do not keep trying session creation, repository discovery, delegation, or CI checks.
59
+ - Facilitate user reauth through the browser-based login flow, such as `polygraph auth login` (or the `login` MCP tool). In interactive desktop clients, browser reauth is usually user-driven; surface the need clearly and wait for the user to complete it.
60
+ - After login, an organization must be selected. Use `polygraph account select` (or the MCP equivalent) when needed.
61
+ - Re-run `polygraph whoami` (or `whoami`) after reauth and org selection. Continue only after it confirms a valid login and selected organization.
59
62
 
60
63
  ### Select Organization
61
64
 
@@ -98,6 +101,8 @@ In case B, call `add_repo` yourself when exact repo refs were provided; otherwis
98
101
 
99
102
  - For a new session (case C), `start_session` auto-generates a unique session ID. You do NOT need to pass one.
100
103
  - For cases A and B, the session ID already exists; reuse it everywhere — never let `start_session` run in this conversation.
104
+ - The parent conversation is responsible for detecting an existing session ID from current context, the startup banner, or a user-provided session URL/ID, then passing it explicitly to `polygraph-init-subagent`. The init subagent cannot infer parent session context by itself.
105
+ - For a fresh Codex Desktop conversation started with `/polygraph:session-start`, no `sessionId` is expected; launch `polygraph-init-subagent` without `sessionId` so it creates a new session.
101
106
 
102
107
  **Launch the init subagent** using `@polygraph-init-subagent` (cases B and C — skip in case A):
103
108
 
@@ -657,3 +662,4 @@ If the session has a description timeline, also display:
657
662
 
658
663
  1. **Use `stop_agent` to clean up** — Stop child agents that are stuck or no longer needed. The child's session is preserved (`sessionPreserved: true`) so the context can be restored later, but after resuming you must wait for explicit user instructions before making changes.
659
664
  1. **Only archive sessions when asked** — Only call `archive_session` when the user explicitly requests it. Archiving hides the session from active lists; it can still be resumed later.
665
+
@@ -0,0 +1,46 @@
1
+ ---
2
+ name: session-debrief
3
+ description: Analyze the raw logs of past Polygraph sessions and produce structured, rank-ordered debriefs for use in a different session. Use when launched (typically as a background agent) with a ranked list of relevant Polygraph session IDs and a statement of the current task; pulls parent and child transcripts via the polygraph CLI and returns one consolidated debrief.
4
+ ---
5
+
6
+ # Session Debrief
7
+
8
+ You produce debriefs of PAST Polygraph sessions so a parent agent working on a NEW task can decide what context is relevant. You are read-only with respect to the inspected sessions: never resume them, never spawn agents into them, never push branches, create PRs, or update their descriptions.
9
+
10
+ ## Input
11
+
12
+ - A ranked list of sessions `{ sessionId, title?, url? }`, most relevant first (rank 1 = most relevant). If no explicit ranking is stated, the given order IS the ranking.
13
+ - A statement of the current task the parent is working on.
14
+
15
+ ## Procedure
16
+
17
+ For each session, in rank order:
18
+
19
+ 1. `polygraph session show --details <sessionId>` — metadata, description timeline, repositories, PRs.
20
+ 2. `polygraph session logs -s <sessionId> --json` — the full parent transcript (`--json` returns the full transcript by default).
21
+ 3. If the session delegated work to other repositories (child-agent steps exist), pull those transcripts too: `polygraph session logs -s <sessionId> --all --json`, or `--repo <org/repo> --json` for one repo.
22
+ 4. Write the debrief section (format below) before moving to the next session.
23
+
24
+ Large transcripts: if the full `--json` output is too large to hold, page with `--tail 200 --page <n>` and prioritize, in order: user prompts, assistant text and final messages, tool errors and failure events, task notifications. Routine tool-use noise (file reads, searches) is safe to skim.
25
+
26
+ ## Output
27
+
28
+ Return ONE consolidated debrief as your final message — it is consumed by the parent agent, not shown raw to a human. Sessions in rank order, each following this template. Target a tight page per session; do not pad.
29
+
30
+ ### Rank N — <session title> (<sessionId>)
31
+
32
+ **URL:** <session url>
33
+ **Goal:** what the session set out to do.
34
+ **What happened:** condensed narrative of the work performed.
35
+ **Outcome + artifacts:** PRs (URL + status), branches, key files touched.
36
+ **Key decisions:** one bullet per decision, with the recorded rationale.
37
+ **Gotchas / failed approaches:** what went wrong or was abandoned, and why.
38
+ **Unresolved:** open items or next steps the session left behind.
39
+ **Relevance to current task:** one or two sentences connecting this session to the stated task. The parent decides what to use — report the connection, do not overclaim.
40
+
41
+ ## Constraints
42
+
43
+ - Exact citations: session URLs, PR URLs, file paths, branch names.
44
+ - If a session's logs are hidden or unavailable, say which (`hidden: true` in the CLI output means hidden by the author; empty steps mean no logs uploaded) and debrief from `session show --details` metadata, description timeline, and PRs alone.
45
+ - No speculation: when the transcript does not show why a decision was made, write "rationale not recorded".
46
+ - Read-only: the inspected sessions must be byte-for-byte unaffected by your work.
@@ -0,0 +1,53 @@
1
+ ---
2
+ name: session-start
3
+ description: Start or reconnect a Polygraph session for shared, resumable agent context. Use when the user asks to start a Polygraph session, create session memory, share or resume work context, include related repositories, or inspect an existing session before continuing.
4
+
5
+ ---
6
+
7
+ # Start a Polygraph Session
8
+
9
+ Start or reconnect a Polygraph session so the current work has shared, resumable context: session URL, repository graph visibility, linked PR/CI state, and the option to expand across repository boundaries when needed.
10
+
11
+ ## Check Authentication First
12
+
13
+ Before session work, the parent conversation must check Polygraph auth with `whoami` or `polygraph whoami`.
14
+
15
+ - If auth is valid and an organization is selected, continue.
16
+ - If auth is missing, expired, or no organization is selected, stop session work. Do not keep trying session creation or discovery.
17
+ - Facilitate user reauth through the browser-based flow, such as `polygraph auth login` or the MCP `login` equivalent. After login, make sure an organization is selected with `polygraph account select` or the MCP equivalent when needed.
18
+ - Re-run `whoami` after reauth. Continue only after it confirms a valid login and selected organization.
19
+
20
+ Do not breeze past auth failures. In Codex Desktop, auth recovery usually requires the user to complete the browser login flow; surface that clearly and wait for it before continuing.
21
+
22
+ ## Parent Session Detection
23
+
24
+ The parent conversation is responsible for detecting an existing Polygraph session ID from the current context, startup banner, or user-provided session URL/ID, then passing that `sessionId` explicitly to `polygraph-init-subagent` when launching it. The init subagent cannot infer the parent's current session context by itself.
25
+
26
+ For a fresh Codex Desktop conversation started with `/polygraph:session-start`, no `sessionId` is expected. Launch `polygraph-init-subagent` without `sessionId` so it creates a new session.
27
+
28
+ ## Decide the Session Path
29
+
30
+ Pick one path before using tools.
31
+
32
+ 1. **Existing session with repos** - If a Polygraph session ID is already in scope and the user did not ask to add repositories, call `show_session` to inspect it and print the session details. Do not create a new session.
33
+ 2. **Existing session, adding exact repository refs** - If a session ID is in scope and the user provided exact refs by ID, short name, full name, GitHub `owner/repo` slug, URL-like slug, or MCP resource syntax, call `add_repo(sessionId, repoIds: [...])` directly. Do not run discovery.
34
+ 3. **Existing session, discovery needed** - If a session ID is in scope but repos need to be discovered or selected, launch `polygraph-init-subagent` with the existing `sessionId` and `userContext`. The subagent must use `add_repo`, not `start_session`.
35
+ 4. **No session in scope** - Launch `polygraph-init-subagent` with `userContext` and no `sessionId`. The subagent will discover related repositories when needed and call `start_session`.
36
+
37
+ Exact refs are not limited to organization repos. Public open-source repos can be added by `owner/repo` slug or URL even if they do not appear in repository discovery.
38
+
39
+ Invoke `@polygraph-init-subagent` for discovery or new-session creation. Use direct `add_repo` only for exact refs on an existing session.
40
+
41
+ ## Print the Result
42
+
43
+ When a brand-new session is created, render the session welcome card. Prefer the `session_intro` MCP tool when available; otherwise run `polygraph session intro -s <sessionId>` and print the returned markdown verbatim.
44
+
45
+ For an existing or reconnected session, print:
46
+
47
+ **Session:** POLYGRAPH_SESSION_URL
48
+
49
+ **Repositories in this session:**
50
+
51
+ - REPO_FULL_NAME
52
+
53
+ Use `polygraphSessionUrl` from the session response for `POLYGRAPH_SESSION_URL`, and use repository entries from the session response for `REPO_FULL_NAME`.