@polygraph/claude-plugin 0.4.49 → 0.4.51

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polygraph",
3
- "version": "0.4.49",
3
+ "version": "0.4.51",
4
4
  "description": "AI agent skills and subagents for Polygraph sessions, repository context, and coordination",
5
5
  "author": {
6
6
  "name": "Narwhal Technologies Inc",
package/README.md CHANGED
@@ -61,7 +61,7 @@ Neither is required — they are a throughput optimization, not a correctness fi
61
61
  ## Skills
62
62
 
63
63
  - **polygraph** — Comprehensive guidance for Polygraph sessions: shared context, repository graph visibility, PR/CI state, delegation, and session management.
64
- - **adversarial-review** — Second-opinion review of a session's work by independent reviewer agents, one per repo, running under a read-only `reviewer` role.
64
+ - **adversarial-review** — Second-opinion review by independent per-repo agents that presents and attaches one consolidated review artifact.
65
65
  - **await-polygraph-ci** — Wait for CI pipelines to settle across all repos in a session, investigate failures, and present fix options.
66
66
  - **get-latest-ci** — One-shot fetch of the latest CI pipeline execution for the current branch.
67
67
  - **session-debrief** — Analyze the raw logs of past Polygraph sessions and produce structured, rank-ordered debriefs for use in a different session.
@@ -82,6 +82,18 @@ npm install
82
82
  npm run sync-artifacts
83
83
  ```
84
84
 
85
+ Estimate the compiled prompt cost of every skill and subagent for Claude Code,
86
+ Codex, and OpenCode:
87
+
88
+ ```sh
89
+ npm run report:token-costs
90
+ ```
91
+
92
+ The report uses four characters per estimated token by default. Override the
93
+ ratio when needed with `npm run report:token-costs -- --characters-per-token 3.5`.
94
+ Pull requests run the same report when opened or updated and keep the latest
95
+ results in a single collapsible comment.
96
+
85
97
  ## Releasing
86
98
 
87
99
  Run the `Release PR` GitHub Actions workflow with a version bump (`patch`, `minor`, or `major`).
@@ -5,6 +5,7 @@ description: Waits for one Polygraph child agent (addressed by delegation id) to
5
5
  model: haiku
6
6
  tools:
7
7
  - mcp__plugin_polygraph_polygraph-mcp__show_agent
8
+ - Bash
8
9
 
9
10
  ---
10
11
 
@@ -21,19 +22,29 @@ The main agent already spawned the child via `spawn_agent` and received a delega
21
22
  | `sessionId` | The Polygraph session ID |
22
23
  | `id` | The delegation id returned by `spawn_agent` (e.g. `frontend-1`) |
23
24
 
25
+ ## Two ways to poll
26
+
27
+ | MCP tool | CLI equivalent |
28
+ | ------------ | ------------------------------------------------------------------------------------- |
29
+ | `show_agent` | `polygraph agent show --session <sessionId> --id <id> --wait-for-transition-ms 300000` |
30
+
31
+ Prefer the MCP tool. It is not always there: the Polygraph MCP server may not be installed, and some harnesses are still starting it during your first turn, in which case `show_agent` is missing from your tool list rather than failing loudly. Check your available tools before the first poll. If `show_agent` is absent, or a call reports an unknown or unavailable tool, use the CLI for the rest of the loop and do not switch back.
32
+
33
+ The CLI takes the same two identifiers, blocks the same way, and prints the same payload as JSON on stdout: `{ "success": true, "sessionId": "…", "children": [ … ] }`. Read `children[0]` from it exactly as you would from the tool response. Everything below applies to whichever one you are using.
34
+
24
35
  ## Loop
25
36
 
26
- Call the `show_agent` tool with exactly these arguments, repeatedly:
37
+ Call `show_agent` with exactly these arguments, repeatedly:
27
38
 
28
39
  - `sessionId`: the session ID
29
40
  - `id`: the delegation id
30
41
  - `waitForTransitionMs`: 300000
31
42
 
32
- Never pass `tail`. Never call any other tool. Never read files, transcripts, or logs.
43
+ Never pass `tail`. Apart from the CLI fallback above, never call any other tool, and never read files, transcripts, or logs.
33
44
 
34
45
  Each call blocks up to 5 minutes, then returns the child's `status` on `children[0]`:
35
46
 
36
- - `in-progress` or `created` → call `show_agent` again with the same arguments.
47
+ - `in-progress` or `created` → poll again with the same arguments.
37
48
  - `completed`, `failed`, `cancelled`, `input-required`, or `permission-required` → stop looping and exit with the message below.
38
49
 
39
50
  If a call errors, retry it once. If it errors again, exit with the error text plus the delegation id and stop.
@@ -2,6 +2,7 @@
2
2
 
3
3
  name: session-debrief
4
4
  description: Analyze the raw logs of one or more past Polygraph sessions and return a structured, rank-ordered debrief for the current task. Launch as a background agent with a ranked list of relevant Polygraph session IDs/lines and a one-paragraph statement of the current task; it invokes the session-debrief skill, pulls parent and child transcripts via the polygraph CLI, and returns one consolidated debrief. Read-only with respect to the inspected sessions.
5
+ model: haiku
5
6
 
6
7
  ---
7
8
 
@@ -5,7 +5,7 @@ import { spawnSync } from 'node:child_process';
5
5
 
6
6
  const HOOK_LOG_MAX_BYTES = 5 * 1024 * 1024;
7
7
 
8
- const AGENT_TYPES = new Set(['claude', 'codex', 'opencode']);
8
+ const AGENT_TYPES = new Set(['claude', 'codex', 'opencode', 'cursor']);
9
9
  const COMMAND_HOOK_TOOL = /^mcp__(?:plugin_polygraph_)?polygraph[-_]mcp__/;
10
10
  const OPENCODE_TOOL = /^polygraph(?:(?:-|_)mcp)?_/;
11
11
 
@@ -89,18 +89,30 @@ export function buildCommandHookLink(payload, agentType, env = process.env) {
89
89
  if (!payload || typeof payload !== 'object') return undefined;
90
90
  if (isManagedChildEnvironment(env)) return undefined;
91
91
 
92
- const agentSessionId = nonEmptyString(payload.session_id);
92
+ // Cursor payloads carry the id in both session_id and conversation_id;
93
+ // the fallback keeps the link working if one of them disappears.
94
+ const agentSessionId =
95
+ nonEmptyString(payload.session_id) ?? nonEmptyString(payload.conversation_id);
93
96
  if (!agentSessionId) return undefined;
94
97
 
98
+ // Cursor has no top-level cwd; workspace_roots[0] is the launch directory.
99
+ const workspaceRoot = Array.isArray(payload.workspace_roots)
100
+ ? nonEmptyString(payload.workspace_roots[0])
101
+ : undefined;
102
+
95
103
  const common = {
96
104
  agentType,
97
105
  agentSessionId,
98
- cwd: nonEmptyString(payload.cwd),
106
+ cwd: nonEmptyString(payload.cwd) ?? workspaceRoot,
99
107
  transcriptPath: nonEmptyString(payload.transcript_path),
100
108
  source: 'hook',
101
109
  };
102
110
 
103
- if (payload.hook_event_name === 'SessionStart') {
111
+ // Claude and Codex send PascalCase event names; cursor sends camelCase.
112
+ if (
113
+ payload.hook_event_name === 'SessionStart' ||
114
+ payload.hook_event_name === 'sessionStart'
115
+ ) {
104
116
  const polygraphSessionId = nonEmptyString(env.POLYGRAPH_SESSION_ID);
105
117
  if (polygraphSessionId) return { ...common, polygraphSessionId };
106
118
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polygraph/claude-plugin",
3
- "version": "0.4.49",
3
+ "version": "0.4.51",
4
4
  "description": "AI agent skills and subagents for Polygraph sessions, repository context, and coordination",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: adversarial-review
3
- description: Independent second-opinion review of a Polygraph session's work. USE WHEN user says "adversarial review", "review this session", or when the Polygraph CLI launches an agent with an instruction to load this skill.
3
+ description: Review a Polygraph session with independent per-repo reviewers and attach one consolidated review artifact.
4
4
 
5
5
  user-invocable: true
6
6
  allowed-tools:
@@ -14,10 +14,10 @@ allowed-tools:
14
14
 
15
15
  # Adversarial Review
16
16
 
17
- 1. **Pick the agent.** Ask whether Claude, Codex, or OpenCode should review `claude`, `codex`, or `opencode` for `spawn_agent`'s `agent` parameter. Skip if the user already named one.
17
+ 1. Skip this step entirely if a reviewer agent was already named — by the user, or in the instruction that launched you (e.g. from `polygraph session review --adversarial`); in that case use that agent and do not ask. Otherwise, **pick the agent**: Ask which should review—`claude`, `codex`, or `opencode` for `spawn_agent`'s `agent` parameter. If the user names a model, pass it via `spawn_agent`'s optional `model` parameter; don't ask about models.
18
18
  2. **Get the session description.**
19
- 3. **Get each repo's plan.** Ask each repo's agent to provide the plan.
20
- 4. **Delegate one reviewer per repo** in parallel, with `role: "reviewer"`. Pass the overall plan and that repo's plan, and ask it to review the code, identify issues, and return a summary. Do the delegation even for the "initiator" repo.
21
- 5. **Summarize.** Once every review is back, analyze them and present one summary to the user.
22
- 6. **Ask what next.** Address the feedback, upload the summary via `upload_artifact`, or continue with the session. Skip if the user already said.
19
+ 3. **Get each repo's plan.**
20
+ 4. **Delegate one reviewer per repo** in parallel, `role: "reviewer"`. Ask to review, identify issues. Do the delegation even for the "initiator" repo.
21
+ 5. **Summarize and attach.** Consolidate reviews into one consolidated Markdown review with per-repo sections and present it to the user. Then call `upload_artifact` once with `sessionId`, that review as `content`, `kind: "review"`, `format: "markdown"`, name `adversarial-review-YYYY-MM-DDTHH-mm-ssZ.md`. If the upload fails, report that separately without suppressing the review.
22
+ 6. **Ask what next.** Address feedback or continue. Skip if the user already said.
23
23
  7. If the user selects "address the feedback", pass each repo's feedback to the repo default agent (not the reviewer). The initiator should fix things itself without delegating.
@@ -20,10 +20,14 @@ spawn_agent(
20
20
  repo: "<org/repo-name>",
21
21
  instruction: "<the task instruction>",
22
22
  role: "<optional role>",
23
- context: "<optional context>"
23
+ context: "<optional context>",
24
+ agent: "<optional: claude | codex | opencode>",
25
+ model: "<optional model override>"
24
26
  )
25
27
  ```
26
28
 
29
+ `agent` picks the child's harness and `model` overrides its default model; include either only when the user named one.
30
+
27
31
  Write the instruction as if to a competent engineer who cannot see your conversation: state the goal, the constraints, and what "done" looks like. The child has its own repo and its own context; it inherits nothing from yours.
28
32
 
29
33
  Delegate to several repos in parallel by calling `spawn_agent` once per repo before waiting on any of them.