@polygraph/claude-plugin 0.5.2 → 0.5.4

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.5.2",
3
+ "version": "0.5.4",
4
4
  "description": "AI agent skills and subagents for Polygraph sessions, repository context, and coordination",
5
5
  "author": {
6
6
  "name": "Narwhal Technologies Inc",
@@ -59,10 +59,8 @@ Child agent <id> is done.
59
59
  **Repo:** <repoFullName>
60
60
  **Delegation id:** <id>
61
61
  **Status:** <status>
62
-
63
- Read the result with show_agent (id: "<id>").
64
62
  ```
65
63
 
66
64
  For `input-required` or `permission-required`, replace "is done." with "needs attention." and keep everything else identical.
67
65
 
68
- Do not summarize, quote, or describe the child's work. Do not include log lines. The main agent reads the result itself via `show_agent`.
66
+ Do not summarize, quote, or describe the child's work. Do not include log lines. The main agent reads the result itself via `show_agent`, and chooses how to read it. Never tell it which call to make.
@@ -20,6 +20,8 @@
20
20
  // holds selectedUrl, used to build the session URL.
21
21
  //
22
22
  // Outside a Polygraph session (no matching sidecar) the hook is a silent no-op.
23
+ // Speculative captures (implicit session context, not explicit Polygraph sessions)
24
+ // are also treated as no-op and not injected as context.
23
25
 
24
26
  import {
25
27
  appendFileSync,
@@ -94,7 +96,9 @@ function sessionsRoot(root) {
94
96
 
95
97
  // Scan the immediate subdirectories of `baseDir`; for each, `candidatePath`
96
98
  // maps the subdirectory name to a candidate sidecar file. Returns the first
97
- // parsed match, or null.
99
+ // parsed match that is not a speculative sidecar, or null.
100
+ // Speculative sidecars (target === 'speculative') are skipped; only regular
101
+ // sidecars (target === 'regular' or missing target) are returned.
98
102
  function scanForSidecar(baseDir, candidatePath) {
99
103
  if (!existsSync(baseDir)) return null;
100
104
 
@@ -109,7 +113,13 @@ function scanForSidecar(baseDir, candidatePath) {
109
113
  if (!entry.isDirectory()) continue;
110
114
  const candidate = candidatePath(entry.name);
111
115
  if (existsSync(candidate)) {
112
- return readJson(candidate);
116
+ const sidecar = readJson(candidate);
117
+ if (sidecar) {
118
+ // Skip speculative sidecars; only return regular ones (missing or 'regular' target).
119
+ if (sidecar.target !== 'speculative') {
120
+ return sidecar;
121
+ }
122
+ }
113
123
  }
114
124
  }
115
125
  return null;
@@ -118,7 +128,7 @@ function scanForSidecar(baseDir, candidatePath) {
118
128
  // Find the sidecar that maps an agent session id to a Polygraph session.
119
129
  // Checks the new per-session layout first, then falls back to the legacy
120
130
  // shared sidecars directory. Returns the parsed sidecar object, or null when
121
- // none matches.
131
+ // none matches or only speculative sidecars are found.
122
132
  export function findSidecar(agentSessionId, root = polygraphRoot()) {
123
133
  if (!agentSessionId) return null;
124
134
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polygraph/claude-plugin",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "description": "AI agent skills and subagents for Polygraph sessions, repository context, and coordination",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
@@ -297,6 +297,7 @@ If the session has a description timeline, also display:
297
297
 
298
298
  1. **Read each result once** — when a poller exits, read that child with a single unwaited `show_agent(sessionId, id)`; `result.text` is the child's final message. Only reach for an explicit `tail` if that is not enough.
299
299
  1. **State the output in every brief** — children are told to be concise, so the instruction must say what to return: the shape, a cap where one makes sense, and the exact token for "nothing to report". See [`reference/delegation.md`](reference/delegation.md).
300
+ 1. **Batch the spawn and the read** — send several repos in one spawn call and collect their results in one read. Identical work rides a single instruction; differing work goes in a spec file with an entry per repo, sharing only what is genuinely shared. See [`reference/delegation.md`](reference/delegation.md).
300
301
  1. **Poll child status before proceeding** — Always verify child agents have reached a terminal `child.status` (`'completed'`, `'failed'`, or `'cancelled'`) before pushing branches or creating PRs
301
302
  1. **Link PRs in descriptions** - Reference related PRs in each PR body
302
303
  1. **Keep PRs as drafts** until all repos are ready
@@ -30,7 +30,29 @@ spawn_agent(
30
30
 
31
31
  Write the instruction as if to a competent engineer who cannot see your conversation: state the goal, the constraints, what "done" looks like, and what to report back. The child has its own repo and its own context; it inherits nothing from yours.
32
32
 
33
- Delegate to several repos in parallel by calling `spawn_agent` once per repo before waiting on any of them.
33
+ Delegate to several repos in parallel before waiting on any of them, and prefer one call over N. There are three shapes, the same three `polygraph agent spawn` takes:
34
+
35
+ - **One repo** — `repo` with an `instruction`.
36
+ - **Several repos, one task** — `repos` with one `instruction`, run verbatim in each.
37
+ - **Several repos, different tasks** — `specFile`, a JSON file you write, whose path you pass.
38
+
39
+ Batching pays because the shared text is transmitted once rather than once per repo, and every sibling starts from a byte-identical prompt prefix that can be served from cache. Each id still gets its own poller.
40
+
41
+ The spec file is the many-to-many form. Each entry names a repo and carries its own `instruction`, and optionally its own `context`, `role`, `agent`, and `model`. Whatever the entries share goes in `sharedInstruction` / `sharedContext`, which are prepended to each entry's own text with a blank line between — so the common brief stays one identical prefix and only the per-repo part varies. An entry may carry no `instruction` of its own and rely entirely on the shared one. Being a file, it also carries a brief too large to pass as an argument, and it is straightforward to generate programmatically.
42
+
43
+ ```jsonc
44
+ {
45
+ "sharedInstruction": "Brief every child gets, verbatim.",
46
+ "sharedContext": "Optional background every child gets.",
47
+ "agents": [
48
+ { "repo": "api", "instruction": "Add the expand parameter to the endpoint." },
49
+ { "repo": "people", "instruction": "Consume it in the client.", "context": "This repo still pins the old SDK." },
50
+ { "repo": "planets", "role": "reviewer", "agent": "codex", "instruction": "Review the change against the shared brief." }
51
+ ]
52
+ }
53
+ ```
54
+
55
+ One qualifier is load-bearing: share only what is genuinely shared. Flattening several different tasks into one `sharedInstruction` to look efficient produces worse work, and the round trips to repair it cost more than the batch saved. Work that differs belongs in each entry's own `instruction`, which is what the file is for.
34
56
 
35
57
  **Own-repo rule.** With the default role, `repo` must be a repository other than the one you are working in — never delegate into your own repo with the default role; work on it directly (ordinary local subagents are fine for that). Delegating into your own repo IS allowed with an explicit non-default `role`, because each (repo, role) pair is a separate agent slot and the child then runs alongside your own default-role work without colliding with it.
36
58
 
@@ -75,6 +97,8 @@ show_agent(sessionId: "<sessionId>", id: "<id>")
75
97
 
76
98
  One-off unwaited reads like this are cheap and expected inline. It is the *waiting* that belongs in a subagent, not the reading.
77
99
 
100
+ When several pollers have exited, a **batch read** collects their results in one unwaited call: pass the list of ids and correlate each result by its delegation id. Batch when you spawned children together and have nothing to do until they all finish. Read one at a time when you act on each result as it lands, or only one child is in flight.
101
+
78
102
  ## When the result is not enough
79
103
 
80
104
  Only if `result.text` is missing, truncated, or the child failed in a way you cannot explain from it: