@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,30 @@
1
+ /**
2
+ * Shared provider-error recognition for the engine layer's `failureKind` classification.
3
+ *
4
+ * The fallback decorator (`fallback.ts`) reroutes ONLY `failureKind === "provider"`, so the
5
+ * classification decides whether a failure retries the same model id through another provider
6
+ * route or stops dead. Two producers need the SAME judgment:
7
+ * - the in-process engine classifies a THROWN error (a provider API rejection often throws
8
+ * before any stream event fires — but a throw is not automatically a provider fault);
9
+ * - the child engine classifies a pre-stream death (the provider rejected the request and
10
+ * `pi` exited non-zero before emitting a single assistant event — evidence lives in
11
+ * stderr/exit text, not in a stream `error` stop reason).
12
+ *
13
+ * Conservative by design: only patterns that essentially always mean "the provider rejected
14
+ * or broke" classify as provider. Anything ambiguous stays "agent" (terminal), because a
15
+ * wrong reroute burns tokens while a wrong terminal failure is at least honest. Pure.
16
+ */
17
+
18
+ const PROVIDER_PATTERNS: readonly RegExp[] = [
19
+ /\brate.?limit|\b429\b|too many requests/i,
20
+ /\bquota\b|billing|insufficient.?credits/i,
21
+ /\b401\b|\b403\b|unauthorized|invalid[\s_-]?api[\s_-]?key/i,
22
+ /\b5\d\d\b|internal server error|bad gateway|service unavailable|gateway timeout|overloaded|capacity/i,
23
+ /model.{0,24}(not.{0,8}(supported|found|exist)|does not exist)|unsupported.{0,12}model/i,
24
+ /\beconnreset\b|\betimedout\b|\beconnrefused\b|socket hang up|fetch failed/i,
25
+ ];
26
+
27
+ /** True when the text is evidence of a PROVIDER-side rejection/outage (not agent behavior). */
28
+ export function looksLikeProviderError(text: string): boolean {
29
+ return PROVIDER_PATTERNS.some((re) => re.test(text));
30
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Model provider-fallback decorator. Wraps a `StrategyEngine` so a run that fails with a
3
+ * PROVIDER error (the model's provider rejected or broke — auth, outage, 5xx, model-not-
4
+ * supported) may be retried on the SAME model id through a family-compatible provider route.
5
+ * An unpinned selection may reroute when its provider fails at call time. A provider-qualified
6
+ * `spec.model` is an explicit billing/provider pin and is strict by default; callers must opt it
7
+ * into cross-provider recovery.
8
+ *
9
+ * Only `failureKind === "provider"` retries. abort / timeout / contract / unknown-agent /
10
+ * unknown-model / agent failures pass straight through (a different provider can't fix
11
+ * them). The abort signal is honoured between attempts, so a user stop ends the chain.
12
+ *
13
+ * Engine-agnostic and pure over its injected deps (the model list + preferred provider),
14
+ * so it's testable with a stub engine and a fake registry — no live model.
15
+ */
16
+
17
+ import type { ModelLite, ModelRoutingPolicy } from "../core/models.ts";
18
+ import { DEFAULT_MODEL_ROUTING_POLICY, providerFallbacks } from "../core/models.ts";
19
+ import type { AgentRunSpec, StrategyEngine } from "../orchestration/sdk.ts";
20
+
21
+ export interface FallbackDeps {
22
+ /** The authenticated model list to draw alternates from (NOT every registry model). */
23
+ models: ModelLite[];
24
+ /** The session/loader provider — tried first among alternates (most likely authed). */
25
+ preferProvider?: string;
26
+ /** Optional deployment policy for automatic fallback; safe first-party defaults otherwise. */
27
+ routingPolicy?: ModelRoutingPolicy;
28
+ /** Explicitly opt a provider-qualified model into cross-provider recovery. */
29
+ allowCrossProviderFallback?: boolean;
30
+ /** Notified on each reroute, for transparency: the extension wires this to a warning toast, not
31
+ * a tree/log breadcrumb. */
32
+ onFallback?: (info: { from: string; to: string; agent: string }) => void;
33
+ }
34
+
35
+ export function withModelFallback(engine: StrategyEngine, deps: FallbackDeps): StrategyEngine {
36
+ return {
37
+ async run(spec, onProgress, signal, onSteerable) {
38
+ const tried = new Set<string>();
39
+ let result = await engine.run(spec, onProgress, signal, onSteerable);
40
+ if (result.modelUsed) tried.add(result.modelUsed);
41
+ const providerPinned = spec.model?.includes("/") === true;
42
+ const mayCrossProvider = !providerPinned || deps.allowCrossProviderFallback === true;
43
+ while (mayCrossProvider && result.failureKind === "provider" && !signal?.aborted) {
44
+ const from = result.modelUsed ?? spec.model;
45
+ if (!from) break;
46
+ const next = providerFallbacks(from, deps.models, deps.preferProvider, deps.routingPolicy ?? DEFAULT_MODEL_ROUTING_POLICY).find((r) => !tried.has(r));
47
+ if (!next) break;
48
+ tried.add(next);
49
+ deps.onFallback?.({ from, to: next, agent: spec.agent });
50
+ const attempt: AgentRunSpec = { ...spec, model: next };
51
+ result = await engine.run(attempt, onProgress, signal, onSteerable);
52
+ if (result.modelUsed) tried.add(result.modelUsed);
53
+ }
54
+ return result;
55
+ },
56
+ };
57
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Child bus-handle minting — ONE sequence shared by BOTH engines.
3
+ *
4
+ * The child engine (`adapter.ts`, via the broker host) and the in-process engine
5
+ * (`inproc.ts`) register their handles into the SAME session bus, so a counter per
6
+ * engine module is not enough: a mixed inproc + child pair of the same agent would
7
+ * mint the same `agent#n`, share one inbox, and the first to settle would unregister
8
+ * the other, still-running leg.
9
+ *
10
+ * Module-level (NOT per-engine): `buildEngine` makes a fresh engine per
11
+ * delegate/council/flow-phase/async-launch, so a per-closure counter would restart at 0
12
+ * and collide handles across concurrent runs.
13
+ */
14
+
15
+ let globalChildSeq = 0;
16
+
17
+ /** The next unique bus handle for a child of `agent` (e.g. `scout#3`). */
18
+ export function nextChildHandle(agent: string): string {
19
+ globalChildSeq += 1;
20
+ return `${agent}#${globalChildSeq}`;
21
+ }