@cryptolibertus/pi-peer 0.4.0 → 0.4.1

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
@@ -17,7 +17,7 @@ pi install ./packages/pi-peer
17
17
  - Local peer discovery and transport using project `.pi/peers.json`
18
18
  - Repo-scoped discovery: only Pi sessions in the same git repo/project appear as local peers
19
19
  - Idle watcher daemon: idle peers nudge stuck inbound activations and proactively inspect open goal-board work
20
- - Persona-aware scout routing: goal-board suggestions include recommended lanes, preferred roles, claim mode, and rationale so proactive peers can choose work that fits their role/persona
20
+ - Persona-aware scout routing: goal-board suggestions include recommended lanes, preferred roles, claim mode, work keys, and rationale so proactive peers can self-select complementary work that fits their role/persona
21
21
  - Protocol compatibility metadata (`protocolVersion`, min/max compatible versions), peer manifests, capabilities, and trust summaries in descriptors/status/list output
22
22
  - `PI_PEER_ID` runtime override for running multiple local Pi sessions
23
23
  - `pi-peer-publish` skill for safe npm release checks, version bumping, tag push, publish, and verification
@@ -58,7 +58,7 @@ Useful commands (long form and short aliases):
58
58
 
59
59
  Short aliases keep common board updates terse: `/peer goals`/`/peer ls`, `/peer current`, `/peer scout`, `/peer fanout`, `/peer proposal`/`/peer propose`, `/peer take`/`/peer claim`, `/peer complete`/`/peer done`, `/peer objection`/`/peer block`, `/peer unblock`, `/peer note`, `/peer finding`, `/peer ping`/`/peer heartbeat`, `/peer drop`/`/peer release`, `/peer pass`, `/peer fail`, `/peer vote`, and `/peer close` map to the corresponding `/peer goal ...` actions.
60
60
 
61
- The board is stored locally at `.pi/peer-goals.json`; outbound message snapshots are stored in `.pi/peer-messages.json` so restarted planners can still inspect disconnected historical tasks. Mutating goal-board operations take a short local lock before load/modify/save so concurrent peer appends do not drop events. `/peer send --goal <goal-id> --claim <path[,path]>` and the `peer_send` tool's `goalId`/`claimedPaths` parameters link long-running peer tasks to the board: Symphony records a task, claims overlapping write paths before dispatch, injects goal/heartbeat instructions into the peer prompt, keeps the claim alive with local heartbeats, and releases the claim after the peer returns a final response. Each goal-linked dispatch also gets a semantic work key (`goalId | lane | objective | mode | paths`) so duplicate read/review/research lanes are leased just like write paths; pass `--key <work-key>` / `workKey` for an explicit fingerprint and `--duplicate-policy allow-parallel` only when independent second opinions are intentional. The default dispatch policy is `reuse`, so a matching active work key returns the existing claim/task handle instead of starting another peer. `/peer goal fanout` turns a goal into role-specific peer lanes, while `peer_progress` reports checkpoints from an inbound long-running task. Scout suggestions are persona-aware: they surface a recommended lane (`research`, `review`, `coordination`, etc.), preferred roles, a safe default claim mode, rationale, and suppress suggestions already covered by active work keys. Active write claims conflict on overlapping paths; active semantic claims conflict on matching work keys; released, stale, or expired claims are kept visible but inactive. Claims become stale after 45 minutes without a heartbeat unless the claim or heartbeat sets `--stale-after-ms`.
61
+ The board is stored locally at `.pi/peer-goals.json`; outbound message snapshots are stored in `.pi/peer-messages.json` so restarted planners can still inspect disconnected historical tasks. Mutating goal-board operations take a short local lock before load/modify/save so concurrent peer appends do not drop events. `/peer send --goal <goal-id> --claim <path[,path]>` and the `peer_send` tool's `goalId`/`claimedPaths` parameters link long-running peer tasks to the board: Symphony records a task, claims overlapping write paths before dispatch, injects goal/heartbeat instructions into the peer prompt, keeps the claim alive with local heartbeats, and releases the claim after the peer returns a final response. Each goal-linked dispatch also gets a semantic work key (`goalId | lane | objective | mode | paths`) so duplicate read/review/research lanes are leased just like write paths; pass `--key <work-key>` / `workKey` for an explicit fingerprint and `--duplicate-policy allow-parallel` only when independent second opinions are intentional. The default dispatch policy is `reuse`, so a matching active work key returns the existing claim/task handle instead of starting another peer. `/peer goal fanout` turns a goal into role-specific peer lanes, while `peer_progress` reports checkpoints from an inbound long-running task. Scout suggestions are persona-aware: they surface a recommended lane (`research`, `review`, `implementation`, `coordination`, etc.), preferred roles, a safe default claim mode, a stable work key, rationale, and suppress suggestions already covered by active work keys. Empty goals now emit multiple lane-specific read-only suggestions so idle peers can self-select research, review/QA, or implementation-planning work instead of waiting for a planner to assign lanes. Lane-tagged proposals (for example `/peer goal propose <goal> "Check package contents" --lane review`) also become matching scout suggestions, letting the next suitable peer claim or review that proposed lane. Active write claims conflict on overlapping paths; active semantic claims conflict on matching work keys; released, stale, or expired claims are kept visible but inactive. Claims become stale after 45 minutes without a heartbeat unless the claim or heartbeat sets `--stale-after-ms`.
62
62
 
63
63
  Normal goal closure requires at least one current passing vote, no current failed votes, no unresolved blocking objections, and no active write claims. Open proposals are intentionally non-blocking: they let peers show initiative without freezing closure. Stale write claims no longer block closure or new overlapping claims; use `/peer goal heartbeat` to revive work after a reconnect and `--force` only when intentionally overriding the readiness gate. Goal-linked tasks validate final handoff headings (`Status`, `Files changed`, `Verification`, `Blockers/risks`, `Safe for review`); missing sections create a blocking objection while still releasing the write claim. For multi-part work, use the fan-out gate: list peers, create/reuse a goal, delegate research/review/worker lanes, and include `Fan-out used: yes/no` plus peer handles in the final answer.
64
64
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cryptolibertus/pi-peer",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Pi package for local Pi-to-Pi peer messaging, slash commands, tools, and runtime transport.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -147,7 +147,7 @@ export function formatPeerHelp() {
147
147
  "- `/peer goal list|show [goal-id]` — inspect peer goals, active claims, blockers, proposals, and votes",
148
148
  "- `/peer goal fanout <goal-id> <objective> --peer <id[,id]> [--path <a,b>] [--send] [--no-await]` — plan or dispatch role-specific peer lanes",
149
149
  "- `/peer goal scout [goal-id] [--limit <n>] [--include-closed]` — read-only proactive suggestions for what peers could do next",
150
- "- `/peer goal task|finding|proposal|handoff|note <goal-id> <summary> [--path <a,b>] [--status done]` — post goal-board events",
150
+ "- `/peer goal task|finding|proposal|handoff|note <goal-id> <summary> [--path <a,b>] [--lane research|review|implementation] [--status done]` — post goal-board events; lane-tagged proposals become scout suggestions peers can self-select",
151
151
  "- `/peer goal claim <goal-id> <task> --mode read|write --path <a,b> [--key <work-key>] [--duplicate-policy error|allow-parallel] [--ttl-ms <ms>]` — lease work without hierarchy",
152
152
  "- `/peer goal heartbeat <goal-id> <claim-event-id> [summary] [--ttl-ms <ms>] [--stale-after-ms <ms>]` — refresh a live or stale claim",
153
153
  "- `/peer goal release <goal-id> <claim-event-id> [summary]` — release a claimed lane",
@@ -16,9 +16,14 @@ const SCOUT_LANES = Object.freeze({
16
16
  "stale-claim": { recommendedLane: "coordination", preferredRoles: ["planner", "coordinator"], claimMode: "read", suggestedIntent: "coordinate", rationale: "Stale claims need owner follow-up or release, not duplicate writes." },
17
17
  "open-proposal": { recommendedLane: "coordination", preferredRoles: ["planner", "coordinator", "reviewer"], claimMode: "read", suggestedIntent: "review", rationale: "Open proposals need triage into accept, defer, or resolve decisions." },
18
18
  close: { recommendedLane: "coordination", preferredRoles: ["planner", "coordinator", "reviewer"], claimMode: "read", suggestedIntent: "coordinate", rationale: "Ready goals need final closure checks and a concise handoff." },
19
- "next-step": { recommendedLane: "research", preferredRoles: ["researcher", "reviewer", "planner", "coordinator", "worker"], claimMode: "read", suggestedIntent: "review", rationale: "Empty goals benefit from a read-only lane before write claims." },
19
+ "next-step": { recommendedLane: "research", preferredRoles: ["researcher", "reviewer", "planner", "coordinator"], claimMode: "read", suggestedIntent: "review", rationale: "Empty goals benefit from peers self-selecting read-only lanes before write claims." },
20
20
  review: { recommendedLane: "review", preferredRoles: ["reviewer", "qa", "coordinator", "planner"], claimMode: "read", suggestedIntent: "review", rationale: "Goals without current votes need read-only validation before closure." },
21
21
  });
22
+ const STARTUP_SCOUT_LANES = Object.freeze([
23
+ { lane: "research", preferredRoles: ["researcher", "planner", "coordinator"], summary: "No active work yet; self-select a research lane to map risks, options, and next moves." },
24
+ { lane: "review", preferredRoles: ["reviewer", "qa", "planner", "coordinator"], summary: "No active work yet; self-select a read-only review/QA lane to validate the plan and risks." },
25
+ { lane: "implementation", preferredRoles: ["worker"], summary: "No active work yet; self-select an implementation-planning lane, then claim write paths only after naming them." },
26
+ ]);
22
27
  const GOAL_BOARD_LOCK_STALE_MS = 30_000;
23
28
  const GOAL_BOARD_LOCK_RETRY_MS = 10;
24
29
  const GOAL_BOARD_LOCK_TIMEOUT_MS = 5_000;
@@ -318,6 +323,17 @@ export function derivePeerGoalScoutSuggestions(board, options = {}) {
318
323
  push("P1", "stale-claim", `Ask owners to heartbeat or release ${state.staleClaims.length} stale claim${state.staleClaims.length === 1 ? "" : "s"}.`, { paths: uniqueEventPaths(state.staleClaims) });
319
324
  }
320
325
  if (state.openProposals.length) {
326
+ for (const proposal of state.openProposals.filter((item) => item.lane)) {
327
+ const lane = normalizeLaneName(proposal.lane);
328
+ push("P1", "open-proposal", `Self-select proposed ${lane} lane: ${proposal.summary}`, {
329
+ paths: proposal.paths,
330
+ recommendedLane: lane,
331
+ preferredRoles: preferredRolesForLane(lane),
332
+ claimMode: "read",
333
+ suggestedIntent: suggestedIntentForLane(lane),
334
+ rationale: "A peer proposed a lane; matching idle peers can claim or review it without planner assignment.",
335
+ });
336
+ }
321
337
  push("P1", "open-proposal", `Triage ${state.openProposals.length} open proposal${state.openProposals.length === 1 ? "" : "s"}; claim one or resolve it if obsolete.`, { paths: uniqueEventPaths(state.openProposals) });
322
338
  }
323
339
  if (state.readyToClose) {
@@ -325,7 +341,15 @@ export function derivePeerGoalScoutSuggestions(board, options = {}) {
325
341
  continue;
326
342
  }
327
343
  if (!state.activeClaims.length && !state.tasks.length && !state.openProposals.length) {
328
- push("P2", "next-step", "No active work yet; propose a research, review, or implementation lane.");
344
+ for (const lane of STARTUP_SCOUT_LANES) {
345
+ push("P2", "next-step", lane.summary, {
346
+ recommendedLane: lane.lane,
347
+ preferredRoles: lane.preferredRoles,
348
+ claimMode: "read",
349
+ suggestedIntent: suggestedIntentForLane(lane.lane),
350
+ rationale: "Multiple lane-specific suggestions let idle peers self-select complementary work and suppress duplicates by work key.",
351
+ });
352
+ }
329
353
  } else if (!state.currentVotes.length && !state.activeWriteClaims.length) {
330
354
  push("P2", "review", "No current peer vote; ask a peer for read-only review or record a pass/fail vote.");
331
355
  }
@@ -591,7 +615,7 @@ function normalizeDuplicatePolicy(value) {
591
615
 
592
616
  function enrichScoutSuggestion(suggestion = {}) {
593
617
  const lane = SCOUT_LANES[suggestion.kind] || {};
594
- const recommendedLane = suggestion.recommendedLane || lane.recommendedLane;
618
+ const recommendedLane = normalizeLaneName(suggestion.recommendedLane || lane.recommendedLane);
595
619
  const claimMode = cleanText(suggestion.claimMode || lane.claimMode);
596
620
  const enriched = stripEmpty({
597
621
  ...suggestion,
@@ -608,6 +632,27 @@ function enrichScoutSuggestion(suggestion = {}) {
608
632
  });
609
633
  }
610
634
 
635
+ function normalizeLaneName(value) {
636
+ const lane = cleanText(value).toLowerCase();
637
+ if (["qa", "quality", "test", "testing"].includes(lane)) return "review";
638
+ if (["implement", "implementation", "developer", "engineer", "worker", "code", "coding"].includes(lane)) return "implementation";
639
+ if (["coordinate", "coordinator", "planning", "planner", "orchestration"].includes(lane)) return "coordination";
640
+ if (["researcher", "scout", "investigation"].includes(lane)) return "research";
641
+ return lane || "review";
642
+ }
643
+
644
+ function preferredRolesForLane(lane) {
645
+ const normalized = normalizeLaneName(lane);
646
+ if (normalized === "implementation") return ["worker"];
647
+ if (normalized === "research") return ["researcher", "planner", "coordinator"];
648
+ if (normalized === "coordination") return ["planner", "coordinator", "reviewer"];
649
+ return ["reviewer", "qa", "planner", "coordinator"];
650
+ }
651
+
652
+ function suggestedIntentForLane(lane) {
653
+ return normalizeLaneName(lane) === "implementation" ? "task" : "review";
654
+ }
655
+
611
656
  function hasActiveClaimForScoutSuggestion(state, suggestion) {
612
657
  if (!suggestion?.workKey) return false;
613
658
  return state.activeClaims.some((claim) => claim.workKey === suggestion.workKey);
@@ -11,7 +11,7 @@ const PEER_SEND_GUIDANCE = "Use peer_send to send a prompt-first message to a pe
11
11
  const PEER_AWAIT_GUIDANCE = "Use peer_await with messageId values from queued or timed-out peer_send calls to read final assistant replies.";
12
12
  const PEER_GET_GUIDANCE = "Use peer_get to inspect a peer, message, conversation, runtime summary, active tasks via 'tasks', fan-out suggestions via 'fanout', or redacted audit state by id.";
13
13
  const PEER_PROGRESS_GUIDANCE = "Use peer_progress from inside an inbound long-running peer task to send structured checkpoint updates before the final handoff.";
14
- const PEER_FANOUT_GUIDANCE = "Fan-out gate: for multi-part, long-running, or implementation-plus-review work, call peer_list and delegate research/review/QA lanes with peer_send unless the user explicitly says to work solo; if you skip fan-out, state the reason in the final response.";
14
+ const PEER_FANOUT_GUIDANCE = "Fan-out gate: for multi-part, long-running, or implementation-plus-review work, call peer_list and use a goal board plus peer_send for research/review/QA lanes unless the user explicitly says to work solo. For emergent self-organization tests, create/reuse a peer goal and let peers inspect scout suggestions or claim lane-specific work keys instead of over-assigning every lane; if you skip fan-out, state the reason in the final response.";
15
15
 
16
16
  export const PEER_INBOUND_FINAL_RESPONSE_GUIDANCE = "For inbound peer asks, answer the inbound ask in your final assistant response; that final assistant response is returned to the requesting peer. For write-capable task intents, end with a concise handoff: status, files changed, verification commands with exit status, and blockers.";
17
17
 
@@ -139,13 +139,28 @@ export function buildPeerIdleActivationPrompt(activation, options = {}) {
139
139
  const peerId = options.localPeerId || "this-peer";
140
140
  const paths = activation.paths?.length ? `\nPaths: ${activation.paths.join(", ")}` : "";
141
141
  const lane = activation.recommendedLane ? `\nRecommended lane: ${activation.recommendedLane}${activation.claimMode ? ` (${activation.claimMode})` : ""}${activation.preferredRoles?.length ? ` · preferred roles: ${activation.preferredRoles.join(", ")}` : ""}` : "";
142
+ const workKey = activation.workKey ? `\nWork key: ${activation.workKey}` : "";
143
+ const suggestedClaim = buildSuggestedReadClaim(activation);
142
144
  const rationale = activation.rationale ? `\nRationale: ${activation.rationale}` : "";
143
145
  const fit = activation.personaFit?.matched?.length ? `\nPersona fit: matched ${activation.personaFit.matched.join(", ")}` : "";
144
- return `[Pi peer idle watcher]\nYou are local peer '${peerId}' and Pi is idle. A proactive goal-board scout suggestion is available.\n\nGoal: ${activation.goalId}\nSuggestion: ${activation.kind} (${activation.priority}) — ${activation.summary}${lane}${rationale}${fit}${paths}\n\nInstructions:\n- First inspect current state with peer_get id '${activation.goalId}'.\n- If useful, take one small safe action that fits the recommended lane: post a proposal/finding/vote, claim a read-only review lane, or claim write work only when you intend to edit and can name the paths.\n- Do not duplicate active claims or proposals. If the board is no longer actionable, say so briefly and stop.\n- For write work, respect goal-board claims and end with the required peer handoff sections.\n- Keep the response concise.`;
146
+ return `[Pi peer idle watcher]\nYou are local peer '${peerId}' and Pi is idle. A proactive goal-board scout suggestion is available.\n\nGoal: ${activation.goalId}\nSuggestion: ${activation.kind} (${activation.priority}) — ${activation.summary}${lane}${workKey}${rationale}${fit}${paths}${suggestedClaim}\n\nInstructions:\n- First inspect current state with peer_get id '${activation.goalId}'.\n- If useful, take one small safe action that fits the recommended lane: claim a read-only lane with the work key above, post a proposal/finding/vote, or claim write work only when you intend to edit and can name the paths.\n- If the suggested claim fails as duplicate, inspect the board and stop with a brief handoff instead of starting parallel work.\n- Do not duplicate active claims, work keys, or proposals. If the board is no longer actionable, say so briefly and stop.\n- For write work, respect goal-board claims and end with the required peer handoff sections.\n- Keep the response concise.`;
147
+ }
148
+
149
+ function buildSuggestedReadClaim(activation = {}) {
150
+ if (activation.claimMode !== "read" || !activation.workKey) return "";
151
+ const lane = activation.recommendedLane ? ` --lane ${shellQuote(activation.recommendedLane)}` : "";
152
+ const paths = activation.paths?.length ? activation.paths.map((path) => ` --path ${shellQuote(path)}`).join("") : "";
153
+ return `\nSuggested first action: /peer goal claim ${shellQuote(activation.goalId)} ${shellQuote(activation.summary)} --mode read${lane} --key ${shellQuote(activation.workKey)}${paths}`;
154
+ }
155
+
156
+ function shellQuote(value) {
157
+ const text = String(value || "");
158
+ if (/^[A-Za-z0-9_./:-]+$/.test(text)) return text;
159
+ return `'${text.replace(/'/g, `'"'"'`)}'`;
145
160
  }
146
161
 
147
162
  export function peerIdleActivationKey(activation = {}) {
148
- return [activation.goalId, activation.kind, activation.recommendedLane, activation.summary, ...(activation.paths || [])].join("|");
163
+ return [activation.goalId, activation.kind, activation.recommendedLane, activation.workKey, activation.summary, ...(activation.paths || [])].join("|");
149
164
  }
150
165
 
151
166
  function isActivationCoolingDown(state, activation, config, nowMs) {
@@ -167,6 +182,7 @@ function normalizeActivation(suggestion = {}, localPeerId, options = {}) {
167
182
  claimMode: cleanString(suggestion.claimMode),
168
183
  suggestedIntent: cleanString(suggestion.suggestedIntent),
169
184
  rationale: cleanString(suggestion.rationale),
185
+ workKey: cleanString(suggestion.workKey),
170
186
  personaFit,
171
187
  paths: Array.isArray(suggestion.paths) ? suggestion.paths.filter((item) => typeof item === "string" && item.trim()).map((item) => item.trim()) : [],
172
188
  peerId: localPeerId,
@@ -195,7 +195,7 @@ export async function getPeerRuntimeValue(runtime, id) {
195
195
  const peers = await runtime.comms.listPeers();
196
196
  const messages = await runtime.comms.listMessages();
197
197
  const suggestion = deriveFanoutSuggestion(peers, messages);
198
- return { type: "fanout", value: { ...suggestion, checklist: ["Run peer_list before multi-lane work", "Create or reuse /peer goal", "Use /peer goal fanout or peer_send goalId+claimedPaths", "Final response must include Fan-out used: yes/no and peer handles"] } };
198
+ return { type: "fanout", value: { ...suggestion, checklist: ["Run peer_list before multi-lane work", "Create or reuse /peer goal", "For emergent self-organization, ask peers to inspect /peer scout or claim lane-specific work keys before assigning every lane", "Use /peer goal fanout or peer_send goalId+claimedPaths when direct dispatch is needed", "Final response must include Fan-out used: yes/no and peer handles"] } };
199
199
  }
200
200
  if (id === "audit") return { type: "audit", value: await runtime.comms.getAuditEntries() };
201
201