@aeondave/pi-persona 1.15.2

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.
Files changed (165) hide show
  1. package/AGENTS.md +249 -0
  2. package/CHANGELOG.md +260 -0
  3. package/LICENSE +21 -0
  4. package/README.md +172 -0
  5. package/agents/balthasar.md +32 -0
  6. package/agents/casper.md +33 -0
  7. package/agents/evidence-verifier.md +23 -0
  8. package/agents/melchior.md +32 -0
  9. package/agents/operator.md +63 -0
  10. package/agents/research.md +58 -0
  11. package/agents/reviewer.md +49 -0
  12. package/agents/scout.md +23 -0
  13. package/agents/verifier.md +21 -0
  14. package/assets/banner.png +0 -0
  15. package/assets/demo1.gif +0 -0
  16. package/assets/demo1.mp4 +0 -0
  17. package/assets/workflow.png +0 -0
  18. package/contracts/finding.contract.json +9 -0
  19. package/docs/ARCHITECTURE.md +727 -0
  20. package/docs/EXPERIENCE.md +96 -0
  21. package/docs/MONITORS.md +84 -0
  22. package/docs/README.md +53 -0
  23. package/docs/REFERENCE.md +408 -0
  24. package/docs/SPINE.md +152 -0
  25. package/docs/STRATEGIES.md +215 -0
  26. package/docs/TELEMETRY.md +9 -0
  27. package/flows/deep-review.flow.json +8 -0
  28. package/flows/gated-build.flow.json +9 -0
  29. package/package.json +106 -0
  30. package/personas/audit.md +29 -0
  31. package/personas/dev.md +52 -0
  32. package/personas/elite.md +256 -0
  33. package/personas/judge.md +32 -0
  34. package/personas/magi.md +41 -0
  35. package/personas/planner.md +37 -0
  36. package/personas/researcher.md +37 -0
  37. package/personas/swarm.md +38 -0
  38. package/personas/verify.md +31 -0
  39. package/presets/magi-rounds.preset.json +5 -0
  40. package/prompts/spine.md +11 -0
  41. package/prompts/spine.worker.md +9 -0
  42. package/src/agents/agent.ts +78 -0
  43. package/src/bridge.ts +209 -0
  44. package/src/bus/broker/client.ts +379 -0
  45. package/src/bus/broker/framing.ts +43 -0
  46. package/src/bus/broker/host.ts +407 -0
  47. package/src/bus/broker/messages.ts +87 -0
  48. package/src/bus/broker/paths.ts +31 -0
  49. package/src/bus/contact.ts +145 -0
  50. package/src/bus/inproc.ts +279 -0
  51. package/src/bus/peers.ts +114 -0
  52. package/src/core/brief.ts +356 -0
  53. package/src/core/capabilities.ts +114 -0
  54. package/src/core/config.ts +228 -0
  55. package/src/core/contract.ts +391 -0
  56. package/src/core/data-root.ts +260 -0
  57. package/src/core/discovery.ts +33 -0
  58. package/src/core/display-label.ts +47 -0
  59. package/src/core/fence.ts +151 -0
  60. package/src/core/format.ts +13 -0
  61. package/src/core/frontmatter.ts +202 -0
  62. package/src/core/models.ts +192 -0
  63. package/src/core/monitor.ts +415 -0
  64. package/src/core/naming.ts +42 -0
  65. package/src/core/nudge.ts +238 -0
  66. package/src/core/ownership.ts +102 -0
  67. package/src/core/permissions.ts +56 -0
  68. package/src/core/pi-compat.ts +50 -0
  69. package/src/core/seed.ts +770 -0
  70. package/src/core/session-identity.ts +89 -0
  71. package/src/core/time.ts +202 -0
  72. package/src/core/timer.ts +221 -0
  73. package/src/core/types.ts +28 -0
  74. package/src/engine/adapter.ts +257 -0
  75. package/src/engine/async.ts +898 -0
  76. package/src/engine/change-report.ts +143 -0
  77. package/src/engine/child.ts +532 -0
  78. package/src/engine/errors.ts +30 -0
  79. package/src/engine/fallback.ts +57 -0
  80. package/src/engine/handles.ts +21 -0
  81. package/src/engine/inproc.ts +857 -0
  82. package/src/engine/signals.ts +11 -0
  83. package/src/engine/spec-preflight.ts +33 -0
  84. package/src/engine/stream.ts +369 -0
  85. package/src/engine/worktree.ts +144 -0
  86. package/src/exocom/activation.ts +31 -0
  87. package/src/exocom/codes.ts +261 -0
  88. package/src/exocom/envelope.ts +180 -0
  89. package/src/exocom/gate.ts +6 -0
  90. package/src/exocom/guards.ts +45 -0
  91. package/src/exocom/inbound.ts +141 -0
  92. package/src/exocom/install.ts +970 -0
  93. package/src/exocom/ledger.ts +603 -0
  94. package/src/exocom/limits.ts +20 -0
  95. package/src/exocom/paths.ts +35 -0
  96. package/src/exocom/plane.ts +1116 -0
  97. package/src/exocom/registry.ts +307 -0
  98. package/src/exocom/scope.ts +42 -0
  99. package/src/exocom/status.ts +86 -0
  100. package/src/exocom/untrusted.ts +40 -0
  101. package/src/exocom/wait.ts +23 -0
  102. package/src/exocom/write-guard.ts +89 -0
  103. package/src/extension/broker-host.ts +181 -0
  104. package/src/extension/clock.ts +14 -0
  105. package/src/extension/engine.ts +321 -0
  106. package/src/extension/hooks.ts +796 -0
  107. package/src/extension/identity.ts +244 -0
  108. package/src/extension/shared.ts +175 -0
  109. package/src/extension.ts +2221 -0
  110. package/src/loader.ts +218 -0
  111. package/src/monitor/process.ts +116 -0
  112. package/src/monitor/session.ts +61 -0
  113. package/src/orchestration/flow-journal.ts +86 -0
  114. package/src/orchestration/flow-run.ts +301 -0
  115. package/src/orchestration/flow.ts +125 -0
  116. package/src/orchestration/judge.ts +78 -0
  117. package/src/orchestration/model-retry.ts +85 -0
  118. package/src/orchestration/parallel.ts +107 -0
  119. package/src/orchestration/params.ts +23 -0
  120. package/src/orchestration/reducers.ts +123 -0
  121. package/src/orchestration/render.ts +127 -0
  122. package/src/orchestration/roster.ts +133 -0
  123. package/src/orchestration/sdk.ts +326 -0
  124. package/src/orchestration/strategies/compete.ts +182 -0
  125. package/src/orchestration/strategies/council-rounds.ts +124 -0
  126. package/src/orchestration/strategies/critic-loop.ts +168 -0
  127. package/src/orchestration/strategies/debate.ts +126 -0
  128. package/src/orchestration/strategies/fanout.ts +20 -0
  129. package/src/orchestration/strategies/judge.ts +117 -0
  130. package/src/orchestration/strategies/magi.ts +239 -0
  131. package/src/orchestration/strategies/map.ts +327 -0
  132. package/src/orchestration/strategies/pair.ts +72 -0
  133. package/src/orchestration/strategies/pipeline.ts +91 -0
  134. package/src/orchestration/strategies/synthesize.ts +99 -0
  135. package/src/orchestration/strategy.ts +49 -0
  136. package/src/orchestration/types.ts +31 -0
  137. package/src/orchestration/voting.ts +126 -0
  138. package/src/persona/config-store.ts +215 -0
  139. package/src/persona/controller.ts +173 -0
  140. package/src/persona/gating.ts +82 -0
  141. package/src/persona/orchestrate.ts +83 -0
  142. package/src/persona/persona.ts +294 -0
  143. package/src/persona/spine.ts +221 -0
  144. package/src/persona/state.ts +28 -0
  145. package/src/telemetry/contract.ts +244 -0
  146. package/src/telemetry/paths.ts +14 -0
  147. package/src/telemetry/producer.ts +390 -0
  148. package/src/tools/council.ts +200 -0
  149. package/src/tools/delegate-tool.ts +637 -0
  150. package/src/tools/delegate.ts +661 -0
  151. package/src/tools/exocom-work.ts +328 -0
  152. package/src/tools/exocom.ts +476 -0
  153. package/src/tools/flow.ts +117 -0
  154. package/src/tools/intercom-tool.ts +292 -0
  155. package/src/tools/intercom.ts +181 -0
  156. package/src/tools/models.ts +39 -0
  157. package/src/tools/monitor.ts +66 -0
  158. package/src/tools/timer.ts +105 -0
  159. package/src/ui/agent-overlay.ts +526 -0
  160. package/src/ui/agent-tree.ts +307 -0
  161. package/src/ui/live-clock.ts +42 -0
  162. package/src/ui/model-picker.ts +160 -0
  163. package/src/ui/presentation.ts +170 -0
  164. package/src/ui/usage.ts +133 -0
  165. package/teams.yaml +27 -0
@@ -0,0 +1,133 @@
1
+ /**
2
+ * Compact token/cost formatting for sub-agent cards (pure). Shows uncached input
3
+ * (↑), output (↓), and — crucially — cache read/write (R/W) so the numbers read
4
+ * truthfully under prompt caching (where ↑ alone looks misleadingly tiny).
5
+ *
6
+ * Also the conversion + session ledger that make Pi's footer (and pi-theme-1337's
7
+ * frame, which walks the same entries) count sub-agent spend. Pi only sums the
8
+ * supervisor session: assistant usage, `toolResult.usage`, compaction, and
9
+ * branch summaries. Child sessions never appear there unless we attach a Pi
10
+ * `Usage` on the supervisor tool result, or publish leftover async cost on the
11
+ * `persona-cost` status key for a companion frame to add.
12
+ */
13
+
14
+ import type { Usage } from "@earendil-works/pi-ai";
15
+ import { emptyUsage, type ChildUsage } from "../engine/stream.ts";
16
+
17
+ /** Extension status key owned by pi-persona; pi-theme-1337 adds it to the frame $ . */
18
+ export const PERSONA_COST_STATUS_KEY = "persona-cost";
19
+
20
+ export function formatTokens(n: number): string {
21
+ if (n < 1000) return String(n);
22
+ if (n < 10000) return `${(n / 1000).toFixed(1)}k`;
23
+ if (n < 1_000_000) return `${Math.round(n / 1000)}k`;
24
+ return `${(n / 1_000_000).toFixed(1)}M`;
25
+ }
26
+
27
+ export function formatUsage(u: ChildUsage): string {
28
+ const parts: string[] = [];
29
+ if (u.input) parts.push(`↑${formatTokens(u.input)}`);
30
+ if (u.output) parts.push(`↓${formatTokens(u.output)}`);
31
+ if (u.cacheRead) parts.push(`R${formatTokens(u.cacheRead)}`);
32
+ if (u.cacheWrite) parts.push(`W${formatTokens(u.cacheWrite)}`);
33
+ if (u.cost) parts.push(`$${u.cost.toFixed(4)}`);
34
+ return parts.join(" ");
35
+ }
36
+
37
+ export function hasBillableUsage(u: ChildUsage): boolean {
38
+ return u.input > 0 || u.output > 0 || u.cacheRead > 0 || u.cacheWrite > 0 || u.cost > 0;
39
+ }
40
+
41
+ /** Pi's `Usage` shape — the footer / 1337 frame both read `cost.total`. */
42
+ export function toToolUsage(u: ChildUsage): Usage {
43
+ return {
44
+ input: u.input,
45
+ output: u.output,
46
+ cacheRead: u.cacheRead,
47
+ cacheWrite: u.cacheWrite,
48
+ totalTokens: u.input + u.output + u.cacheRead + u.cacheWrite,
49
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: u.cost },
50
+ };
51
+ }
52
+
53
+ /** Spread onto a tool result so Pi records it as `toolResult.usage`. */
54
+ export function toolUsageField(u: ChildUsage): { usage: Usage } | Record<string, never> {
55
+ return hasBillableUsage(u) ? { usage: toToolUsage(u) } : {};
56
+ }
57
+
58
+ /**
59
+ * Format leftover (not-yet-on-a-tool-result) child cost for `setStatus`. Matches
60
+ * pi-theme-1337's `$0.423` / `$2.50` convention so the frame can parse it.
61
+ * `undefined` clears the status.
62
+ */
63
+ export function formatPersonaCostStatus(u: ChildUsage): string | undefined {
64
+ if (!(u.cost > 0) || !Number.isFinite(u.cost)) return undefined;
65
+ return u.cost < 1 ? `$${u.cost.toFixed(3)}` : `$${u.cost.toFixed(2)}`;
66
+ }
67
+
68
+ function plus(a: ChildUsage, b: ChildUsage): ChildUsage {
69
+ return {
70
+ input: a.input + b.input,
71
+ output: a.output + b.output,
72
+ cacheRead: a.cacheRead + b.cacheRead,
73
+ cacheWrite: a.cacheWrite + b.cacheWrite,
74
+ cost: a.cost + b.cost,
75
+ contextTokens: 0,
76
+ turns: a.turns + b.turns,
77
+ };
78
+ }
79
+
80
+ function minus(a: ChildUsage, b: ChildUsage): ChildUsage {
81
+ return {
82
+ input: Math.max(0, a.input - b.input),
83
+ output: Math.max(0, a.output - b.output),
84
+ cacheRead: Math.max(0, a.cacheRead - b.cacheRead),
85
+ cacheWrite: Math.max(0, a.cacheWrite - b.cacheWrite),
86
+ cost: Math.max(0, a.cost - b.cost),
87
+ contextTokens: 0,
88
+ turns: Math.max(0, a.turns - b.turns),
89
+ };
90
+ }
91
+
92
+ /**
93
+ * Session-scoped child spend. `add` every engine run; `account` when that spend
94
+ * is written onto a supervisor tool result. `pending` is what the footer/frame
95
+ * would otherwise miss (background legs whose launch result had no usage yet).
96
+ */
97
+ export class ChildUsageLedger {
98
+ private total: ChildUsage = emptyUsage();
99
+ private billed: ChildUsage = emptyUsage();
100
+ private billedKeys = new Set<string>();
101
+
102
+ add(usage: ChildUsage): void {
103
+ this.total = plus(this.total, usage);
104
+ }
105
+
106
+ /** Returns false when `key` was already billed (don't attach the same spend twice). */
107
+ account(usage: ChildUsage, key?: string): boolean {
108
+ if (key !== undefined) {
109
+ if (this.billedKeys.has(key)) return false;
110
+ this.billedKeys.add(key);
111
+ }
112
+ this.billed = plus(this.billed, usage);
113
+ return true;
114
+ }
115
+
116
+ accountMany(items: Array<{ key: string; usage: ChildUsage }>): ChildUsage {
117
+ let fresh = emptyUsage();
118
+ for (const item of items) {
119
+ if (this.account(item.usage, item.key)) fresh = plus(fresh, item.usage);
120
+ }
121
+ return fresh;
122
+ }
123
+
124
+ pending(): ChildUsage {
125
+ return minus(this.total, this.billed);
126
+ }
127
+
128
+ reset(): void {
129
+ this.total = emptyUsage();
130
+ this.billed = emptyUsage();
131
+ this.billedKeys.clear();
132
+ }
133
+ }
package/teams.yaml ADDED
@@ -0,0 +1,27 @@
1
+ # Rosters: a team name → an ordered list of members.
2
+ # A member is a bare agent name, OR an inline `{ agent, role?, model?, skills? }` map that
3
+ # specialises ONE agent (so an ensemble of perspectives comes from a single agent + roles,
4
+ # not one .md per perspective). Referenced by a persona's `orchestration.roster` / `council.roster`.
5
+ # Project/user copies override.
6
+
7
+ # One `reviewer` agent, three complementary lenses — the role focuses each parallel pass
8
+ # (skills load the rest). Add `model: <provider/id>` to a member for cross-model diversity.
9
+ # Pin cheap models on WORKER members here; leave the SUPERVISOR on the session model (a weak
10
+ # supervisor is the least able to act on its delegation reflex).
11
+ review:
12
+ - { agent: reviewer, role: "Focus ONLY on the SECURITY lens: unsafe input flows, access control, sensitive data handling, unsafe sinks, input validation." }
13
+ - { agent: reviewer, role: "Focus ONLY on the PERFORMANCE lens: algorithmic cost on hot paths, needless allocations/copies, repeated or N+1 I/O, unbounded work." }
14
+ - { agent: reviewer, role: "Focus ONLY on the TESTS lens: untested branches and edge/error cases, brittle or mock-asserting tests, missing regression pins." }
15
+
16
+ repair: [operator, verifier]
17
+ # Evidence assurance: execute one bounded leg, then independently replay its proof. Used by Elite's
18
+ # on-demand critic-loop council; unlike the software verifier, this checks objective/scope/artifacts.
19
+ evidence-assurance: [operator, evidence-verifier]
20
+ magi: [melchior, balthasar, casper]
21
+
22
+ # compete: N implementers race the same task in isolated worktrees; a judge picks the winning diff.
23
+ # Two operator instances; give them different models for real diversity, e.g. model: <provider/id>.
24
+ build: [operator, operator]
25
+
26
+ # swarm (map strategy): a splitter enumerates the batch's items, a worker runs each in parallel.
27
+ swarm: [scout, operator]