@pasko70/pibo 1.16.6 → 2.0.0

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 (145) hide show
  1. package/dist/agent-runtime/auth.js +28 -0
  2. package/dist/agent-runtime/capabilities.js +221 -0
  3. package/dist/agent-runtime/context-build.js +313 -0
  4. package/dist/agent-runtime/contract.js +45 -0
  5. package/dist/agent-runtime/errors.js +57 -0
  6. package/dist/agent-runtime/events.js +1 -0
  7. package/dist/agent-runtime/history.js +1 -0
  8. package/dist/agent-runtime/profile-validation.js +109 -0
  9. package/dist/agent-runtime/registry.js +608 -0
  10. package/dist/agent-runtime/resource-files.js +87 -0
  11. package/dist/agent-runtime/resource-service.js +635 -0
  12. package/dist/agent-runtime/resources.js +1 -0
  13. package/dist/agent-runtime/routed-session.js +931 -0
  14. package/dist/agent-runtime/testing/contract.js +51 -0
  15. package/dist/agent-runtime/testing/fake-adapter.js +192 -0
  16. package/dist/agent-runtime/types.js +3 -0
  17. package/dist/agent-runtimes/codex-native/adapter.js +905 -0
  18. package/dist/agent-runtimes/codex-native/auth.js +476 -0
  19. package/dist/agent-runtimes/codex-native/client.js +734 -0
  20. package/dist/agent-runtimes/codex-native/config.js +152 -0
  21. package/dist/agent-runtimes/codex-native/history.js +283 -0
  22. package/dist/agent-runtimes/codex-native/mcp-stdio-launcher.js +89 -0
  23. package/dist/agent-runtimes/codex-native/models.js +581 -0
  24. package/dist/agent-runtimes/codex-native/process.js +459 -0
  25. package/dist/agent-runtimes/codex-native/protocol-types.js +1 -0
  26. package/dist/agent-runtimes/codex-native/protocol-version.js +7 -0
  27. package/dist/agent-runtimes/codex-native/redaction.js +31 -0
  28. package/dist/agent-runtimes/codex-native/requests.js +378 -0
  29. package/dist/agent-runtimes/codex-native/resource-delivery.js +445 -0
  30. package/dist/agent-runtimes/codex-native/thread.js +388 -0
  31. package/dist/agent-runtimes/codex-native/turn.js +849 -0
  32. package/dist/agent-runtimes/pi/adapter.js +653 -0
  33. package/dist/agent-runtimes/pi/auth.js +455 -0
  34. package/dist/agent-runtimes/pi/history.js +640 -0
  35. package/dist/agent-runtimes/pi/model-catalog.js +87 -0
  36. package/dist/agent-runtimes/pi/routed-session.js +1464 -0
  37. package/dist/agent-runtimes/pi/runtime.js +534 -0
  38. package/dist/agent-runtimes/pi/tool-compiler.js +69 -0
  39. package/dist/apps/chat/agent-profiles.js +40 -23
  40. package/dist/apps/chat/agent-store.js +111 -64
  41. package/dist/apps/chat/chat-api-routes.js +1 -1
  42. package/dist/apps/chat/chat-request-normalizers.js +47 -0
  43. package/dist/apps/chat/data/chat-data-mappers.js +25 -9
  44. package/dist/apps/chat/data/history-query-service.js +108 -0
  45. package/dist/apps/chat/data/session-query-service.js +24 -3
  46. package/dist/apps/chat/data/timeline-query-service.js +3 -3
  47. package/dist/apps/chat/model-catalog.js +1 -55
  48. package/dist/apps/chat/provider-auth-actions.js +171 -23
  49. package/dist/apps/chat/stream.js +12 -0
  50. package/dist/apps/chat/trace-v2.js +1 -0
  51. package/dist/apps/chat/trace.js +126 -415
  52. package/dist/apps/chat/web-app.js +582 -157
  53. package/dist/apps/chat-ui/assets/{dist-BTLtT_Vf.js → dist-9v2ZXT6V.js} +1 -1
  54. package/dist/apps/chat-ui/assets/{dist-CMk1aPug.js → dist-B1LVAytl.js} +1 -1
  55. package/dist/apps/chat-ui/assets/{dist-CcwA_IWN.js → dist-C6LPDFXU.js} +1 -1
  56. package/dist/apps/chat-ui/assets/{dist-DKOthbxr.js → dist-DVtXxfHc.js} +1 -1
  57. package/dist/apps/chat-ui/assets/{dist-ls2I6BIw.js → dist-DW4Qrfbd.js} +1 -1
  58. package/dist/apps/chat-ui/assets/{dist-D1rAtRWs.js → dist-DmbsHdMC.js} +1 -1
  59. package/dist/apps/chat-ui/assets/{dist-C1JQRskW.js → dist-DyvwuSFO.js} +1 -1
  60. package/dist/apps/chat-ui/assets/{dist-DfpaylQ-.js → dist-I26VB0QO.js} +1 -1
  61. package/dist/apps/chat-ui/assets/{dist-D10bTFD5.js → dist-RtHbJRPV.js} +1 -1
  62. package/dist/apps/chat-ui/assets/{dist-5KpmmBBZ.js → dist-sZgJkWZb.js} +1 -1
  63. package/dist/apps/chat-ui/assets/index-BPbNvcZe.css +1 -0
  64. package/dist/apps/chat-ui/assets/index-CIOf2uL2.js +237 -0
  65. package/dist/apps/chat-ui/index.html +2 -2
  66. package/dist/apps/chat-vscode-web/assets/index-1ivRyjFs.js +41 -0
  67. package/dist/apps/chat-vscode-web/index.html +1 -1
  68. package/dist/apps/vscode-artifacts/latest.vsix +0 -0
  69. package/dist/apps/vscode-artifacts/pibo-vscode-ext-2.0.0.vsix +0 -0
  70. package/dist/auth/login-actions.js +5 -251
  71. package/dist/cli-session/localSessionSource.js +8 -1
  72. package/dist/core/context-build.js +124 -20
  73. package/dist/core/default-profile.js +8 -0
  74. package/dist/core/profiles.js +30 -3
  75. package/dist/core/routed-session.js +5 -1446
  76. package/dist/core/runtime.js +5 -561
  77. package/dist/core/session-router.js +637 -83
  78. package/dist/data/cli.js +20 -3
  79. package/dist/data/schema.js +104 -1
  80. package/dist/data/session-store.js +24 -1
  81. package/dist/debug/events.js +25 -10
  82. package/dist/debug/failures.js +23 -3
  83. package/dist/debug/index.js +24 -6
  84. package/dist/debug/messages.js +87 -7
  85. package/dist/debug/persisted-payloads.js +31 -0
  86. package/dist/debug/pty.js +7 -6
  87. package/dist/debug/runtime-binding.js +29 -0
  88. package/dist/debug/session.js +137 -0
  89. package/dist/debug/summary.js +12 -0
  90. package/dist/debug/telemetry.js +28 -0
  91. package/dist/debug/tools.js +12 -2
  92. package/dist/debug/trace.js +154 -76
  93. package/dist/gateway/server.js +87 -2
  94. package/dist/gateway/tool.js +5 -5
  95. package/dist/index.js +21 -2
  96. package/dist/loops/tools.js +13 -12
  97. package/dist/mcp/agent-context.js +13 -4
  98. package/dist/mcp/client.js +10 -6
  99. package/dist/mcp/config.js +5 -2
  100. package/dist/mcp/runtime-session.js +166 -0
  101. package/dist/plugins/builtin.js +191 -53
  102. package/dist/plugins/codex-native.js +29 -0
  103. package/dist/plugins/registry.js +66 -2
  104. package/dist/runs/tools.js +26 -25
  105. package/dist/session-ui/terminalRows.js +2 -2
  106. package/dist/sessions/pibo-data-store.js +125 -16
  107. package/dist/sessions/runtime-binding.js +107 -0
  108. package/dist/sessions/sqlite-store.js +239 -18
  109. package/dist/sessions/store.js +86 -7
  110. package/dist/shared/trace-engine.js +18 -9
  111. package/dist/shared/trace-event-projection.js +29 -11
  112. package/dist/shared/{trace-transcript.js → trace-history.js} +193 -195
  113. package/dist/shared/trace-order.js +9 -4
  114. package/dist/shared/trace-page-merge.js +1 -1
  115. package/dist/signals/projector.js +20 -2
  116. package/dist/signals/registry.js +11 -0
  117. package/dist/subagents/tool.js +8 -6
  118. package/dist/tools/codex-browser.js +20 -19
  119. package/dist/tools/codex-compat.js +10 -9
  120. package/dist/tools/codex-image-generation.js +8 -6
  121. package/dist/tools/contract.js +45 -0
  122. package/dist/tools/credential-registry.js +182 -0
  123. package/dist/tools/mcp-bridge.js +511 -0
  124. package/dist/tools/payload-writer.js +17 -0
  125. package/dist/tools/runtime/tool.js +10 -9
  126. package/dist/tools/schema.js +9 -0
  127. package/dist/tools/session-service.js +193 -0
  128. package/dist/tools/session-tool-set.js +85 -0
  129. package/dist/web-annotations/tools.js +17 -16
  130. package/docs/README.md +11 -0
  131. package/package.json +3 -2
  132. package/skills/builtin/pibo-agent-runtime-adapter/SKILL.md +183 -0
  133. package/skills/builtin/pibo-agent-runtime-adapter/evals/README.md +10 -0
  134. package/skills/builtin/pibo-agent-runtime-adapter/evals/evals.json +45 -0
  135. package/skills/builtin/pibo-agent-runtime-adapter/evals/fixtures/orion-full-harness.md +60 -0
  136. package/skills/builtin/pibo-agent-runtime-adapter/evals/fixtures/relay-partial-harness.md +52 -0
  137. package/skills/builtin/pibo-agent-runtime-adapter/references/capabilities-and-designer.md +194 -0
  138. package/skills/builtin/pibo-agent-runtime-adapter/references/history-debug-and-security.md +213 -0
  139. package/skills/builtin/pibo-agent-runtime-adapter/references/interfaces-and-registration.md +214 -0
  140. package/skills/builtin/pibo-agent-runtime-adapter/references/lifecycle-bindings-and-events.md +193 -0
  141. package/skills/builtin/pibo-agent-runtime-adapter/references/portable-delivery-and-native-behavior.md +226 -0
  142. package/skills/builtin/pibo-agent-runtime-adapter/references/testing-migration-and-validation.md +256 -0
  143. package/dist/apps/chat-ui/assets/index-C2YI0xfw.js +0 -237
  144. package/dist/apps/chat-ui/assets/index-E0RmuCkY.css +0 -1
  145. package/dist/apps/chat-vscode-web/assets/index-D-tSsXLG.js +0 -41
@@ -0,0 +1,214 @@
1
+ # Interfaces and Registration
2
+
3
+ Use this reference when creating the runtime driver, configured adapter instance, live session, plugin registration, or import-boundary plan.
4
+
5
+ ## Current source map
6
+
7
+ Read the implementation before copying a pattern:
8
+
9
+ - `src/agent-runtime/types.ts` — descriptor, driver, adapter, open input, session, controls, status, models/auth, diagnostics.
10
+ - `src/agent-runtime/capabilities.ts` — complete capability shape and consistency validation.
11
+ - `src/agent-runtime/registry.ts` — id/config/instance registration, diagnostics, model/auth inspection, history-provider enforcement, session contract enforcement.
12
+ - `src/agent-runtime/contract.ts` — live session methods implied by advertised capabilities.
13
+ - `src/agent-runtime/testing/fake-adapter.ts` — deterministic minimal adapter.
14
+ - `src/agent-runtime/testing/contract.ts` — reusable lifecycle/prompt/event/abort/disposal contract.
15
+ - `src/plugins/types.ts` and `src/plugins/registry.ts` — plugin-facing registration and capability catalog.
16
+ - `src/agent-runtimes/pi/adapter.ts` — compatibility-rich embedded adapter example, not a generic template.
17
+ - `test/agent-runtime-boundaries.test.mjs` — import rules.
18
+
19
+ ## Four distinct layers
20
+
21
+ ### Driver
22
+
23
+ The driver describes one adapter type and creates configured instances. It owns:
24
+
25
+ - stable adapter id;
26
+ - display name and transport;
27
+ - operator config JSON Schema;
28
+ - declared capabilities;
29
+ - protocol name/range;
30
+ - default config and config parsing;
31
+ - configured adapter construction.
32
+
33
+ The driver is registration-time state, not one live conversation.
34
+
35
+ ### Configured adapter instance
36
+
37
+ An `AgentRuntimeAdapter` represents one named operator configuration such as `codex-native`, `codex-work`, or `remote-orion`. It owns:
38
+
39
+ - parsed config;
40
+ - enabled state;
41
+ - availability/version diagnostics;
42
+ - profile validation;
43
+ - optional model/auth/profile/history/binding inspection;
44
+ - creation of isolated live sessions.
45
+
46
+ Do not put one session's process, subscription, current thread, credential, or generated directory in unkeyed adapter fields.
47
+
48
+ ### Live runtime session
49
+
50
+ An `AgentRuntimeSession` represents one active Pibo Session generation. It owns:
51
+
52
+ - native process/client/thread handle;
53
+ - current frozen binding;
54
+ - subscriptions and correlation maps;
55
+ - prompt/steer/abort behavior;
56
+ - pending approval/input requests;
57
+ - generated configuration and credentials supplied by Pibo services;
58
+ - idempotent disposal.
59
+
60
+ ### Pibo routed session
61
+
62
+ `RuntimeRoutedSession` is product orchestration. It owns queues, active-message correlation, Pibo event distribution, controls dispatch, continuation policy, and product actions. Do not move harness protocol code into it.
63
+
64
+ ## Driver skeleton
65
+
66
+ Adapt this shape; do not copy unsupported capabilities from another adapter.
67
+
68
+ ```ts
69
+ import type {
70
+ AgentRuntimeAdapter,
71
+ AgentRuntimeCapabilities,
72
+ AgentRuntimeDriver,
73
+ AgentRuntimeDriverCreateInput,
74
+ PiboJsonObject,
75
+ } from "@pasko70/pibo";
76
+
77
+ type OrionConfig = PiboJsonObject & {
78
+ executable: string;
79
+ startupTimeoutMs: number;
80
+ };
81
+
82
+ const capabilities: AgentRuntimeCapabilities = /* evidence-based matrix */;
83
+
84
+ export const ORION_RUNTIME_DRIVER: AgentRuntimeDriver<OrionConfig> = {
85
+ descriptor: {
86
+ id: "orion",
87
+ displayName: "Orion App Server",
88
+ transport: "stdio-rpc",
89
+ configSchema: {
90
+ type: "object",
91
+ additionalProperties: false,
92
+ properties: {
93
+ executable: { type: "string", minLength: 1 },
94
+ startupTimeoutMs: { type: "integer", minimum: 1000 },
95
+ },
96
+ required: ["executable", "startupTimeoutMs"],
97
+ },
98
+ capabilities,
99
+ protocol: { name: "orion-app-server", supportedRange: ">=2.4 <3" },
100
+ supportsMultipleInstances: true,
101
+ },
102
+ defaultConfig() {
103
+ return { executable: "orion", startupTimeoutMs: 15_000 };
104
+ },
105
+ parseConfig(value) {
106
+ // Validate every field and reject unknown/unsafe values.
107
+ return parseOrionConfig(value);
108
+ },
109
+ create(input: AgentRuntimeDriverCreateInput<OrionConfig>): AgentRuntimeAdapter {
110
+ return new OrionAgentRuntimeAdapter(input, capabilities);
111
+ },
112
+ };
113
+ ```
114
+
115
+ The registry validates descriptor ids and the capability object. It clones raw config, calls `parseConfig()`, and verifies that the created adapter reports the requested instance and adapter ids.
116
+
117
+ ## Plugin registration
118
+
119
+ Register the driver before instances:
120
+
121
+ ```ts
122
+ export const orionPlugin = definePiboPlugin({
123
+ id: "pibo.runtime.orion",
124
+ name: "Orion Runtime",
125
+ register(api) {
126
+ api.registerAgentRuntimeDriver(ORION_RUNTIME_DRIVER);
127
+ api.registerAgentRuntimeInstance({
128
+ id: "orion-native",
129
+ adapterId: "orion",
130
+ displayName: "Orion Native",
131
+ enabled: true,
132
+ config: { executable: "orion", startupTimeoutMs: 15_000 },
133
+ });
134
+ },
135
+ });
136
+ ```
137
+
138
+ A profile selects the configured instance id, not the adapter id. Existing sessions keep their frozen binding when a profile default changes.
139
+
140
+ Do not claim a compatibility alias owned by another profile. Native Codex, for example, uses `codex-native`; it does not reinterpret a persisted Pi-backed `codex` reference.
141
+
142
+ ## Adapter required methods
143
+
144
+ Every configured adapter implements:
145
+
146
+ - `diagnose()` — bounded availability/version/config diagnostics;
147
+ - `validateProfile()` — adapter-specific profile diagnostics;
148
+ - `openSession()` — creates one isolated live session.
149
+
150
+ Optional methods are capability-driven:
151
+
152
+ - `inspectProfile()` for delivery/fidelity inspection;
153
+ - `listModels()` when `models.catalog` is true;
154
+ - `getAuthStatus()` for safe auth presence/status;
155
+ - `inspectHistory()` and `readHistory()` together when `maintenance.history` is true;
156
+ - `resolveBinding()` when native state needs adapter-owned verification/repair.
157
+
158
+ Do not return raw stderr, process environment, token values, cookies, generated config contents, or locator values in general diagnostics.
159
+
160
+ ## Session required methods
161
+
162
+ Every live session implements:
163
+
164
+ - identity: `adapterId`, `runtimeInstanceId`, `cwd`;
165
+ - `capabilities` matching actual live behavior;
166
+ - `getBinding()`;
167
+ - `subscribe()` with unsubscribe;
168
+ - `prompt()`;
169
+ - `abort()`;
170
+ - `dispose()`;
171
+ - `getStatus()`.
172
+
173
+ `dispose()` must be safe to call twice. The registry's shared contract does this deliberately.
174
+
175
+ Optional `steer()` and `controls` methods must agree with capabilities. `assertAgentRuntimeSessionContract()` rejects mismatches.
176
+
177
+ ## Diagnostics
178
+
179
+ Use stable diagnostic codes and safe messages:
180
+
181
+ ```ts
182
+ {
183
+ severity: "error",
184
+ code: "orion_executable_not_found",
185
+ message: "Orion executable is not available for runtime instance \"orion-native\".",
186
+ path: "config.executable"
187
+ }
188
+ ```
189
+
190
+ Prefer diagnostics over throwing for inspectable availability/profile problems. Throw for impossible construction, malformed protocol state, or an operation that cannot continue safely.
191
+
192
+ ## Extension-point map
193
+
194
+ | Need | Extension point |
195
+ |---|---|
196
+ | New harness type | `AgentRuntimeDriver` |
197
+ | Operator-specific config | `AgentRuntimeInstanceDefinition` |
198
+ | Per-session native process/thread | `AgentRuntimeAdapter.openSession()` |
199
+ | Runtime event stream | `AgentRuntimeSession.subscribe()` |
200
+ | Optional controls | `AgentRuntimeControls` plus capability flags |
201
+ | Model catalog | `AgentRuntimeAdapter.listModels()` |
202
+ | Auth inspection | `AgentRuntimeAdapter.getAuthStatus()` |
203
+ | Native history | `inspectHistory()` and `readHistory()` |
204
+ | Binding verification | `resolveBinding()` |
205
+ | Profile delivery inspection | `inspectProfile()` / resource inspection |
206
+ | Pibo-managed tools | `input.services.portableTools` |
207
+ | Selected skills/context/MCP | `input.services.resources` |
208
+ | Contract fixtures | `src/agent-runtime/testing/` |
209
+
210
+ ## Import boundaries
211
+
212
+ Generic code under `src/agent-runtime/`, routing, sessions, tools, data, trace, and debug may depend on Pibo-owned contracts. It must not import an adapter SDK or protocol package.
213
+
214
+ Put harness code under `src/agent-runtimes/<adapter>/`. Compatibility facades must be narrow, documented, and allowlisted by architectural tests. Prefer dependency injection and capability dispatch over `if (adapterId === "...")`.
@@ -0,0 +1,193 @@
1
+ # Lifecycle, Bindings, and Events
2
+
3
+ Use this reference for native session creation/resume, persisted binding transitions, process ownership, event normalization, approvals, user input, abort, and cleanup.
4
+
5
+ ## Identity model
6
+
7
+ Keep these identities separate:
8
+
9
+ - **Pibo Session id** — stable `ps_...` product routing identity.
10
+ - **Runtime instance id** — configured adapter instance selected and frozen for the Pibo Session.
11
+ - **Adapter id** — harness integration type.
12
+ - **Native session/thread id** — optional opaque harness id, unique within the adapter scope.
13
+ - **Runtime session generation** — one live router lifecycle used for tool credentials and generated resources.
14
+ - **Turn/message/tool ids** — per-operation correlation identities.
15
+
16
+ Never route product APIs by a native id. Never assume a native id is a filesystem path.
17
+
18
+ ## Binding shape
19
+
20
+ `RuntimeSessionBinding` contains:
21
+
22
+ - `piboSessionId`;
23
+ - `runtimeInstanceId`;
24
+ - `adapterId`;
25
+ - optional `nativeSessionId`;
26
+ - state `unbound | bound | missing | error`;
27
+ - optional protocol, protocol version, adapter version;
28
+ - optional adapter-resolved locator and metadata;
29
+ - revision and timestamps when persisted.
30
+
31
+ Locator and metadata values are adapter/internal data. Product inspection should expose only safe fields, locator kind where explicitly needed, and metadata key names.
32
+
33
+ ## Binding states
34
+
35
+ ### `unbound`
36
+
37
+ The Pibo Session is frozen to a runtime instance, but no durable native conversation is established. Use this for lazy native creation or harnesses without a durable native id.
38
+
39
+ A live session contract rejects an `unbound` binding that exposes a native id.
40
+
41
+ ### `bound`
42
+
43
+ A native conversation exists and must use the recorded id. A bound binding requires `nativeSessionId`.
44
+
45
+ On resume, open that exact native state. Do not silently create a replacement if it is missing.
46
+
47
+ ### `missing`
48
+
49
+ The binding expects native state, but the adapter cannot find or attach to it. Keep the Pibo Session and product history visible. Return a diagnostic and require explicit repair/rebind decisions.
50
+
51
+ ### `error`
52
+
53
+ The native binding exists or was being established, but the adapter encountered a persistent binding/protocol error. Preserve diagnostic evidence without leaking secrets.
54
+
55
+ ## Transition and CAS rules
56
+
57
+ Use the store's revisioned transition helpers:
58
+
59
+ - initial bindings start at revision 1;
60
+ - `unbound -> bound` requires the expected revision;
61
+ - changing runtime instance or adapter requires `rebind` mode;
62
+ - `missing/error -> bound` requires `repair` or `rebind` mode;
63
+ - `bound -> unbound` requires `rebind` mode;
64
+ - changing a bound native id requires `rebind` mode;
65
+ - `bound` and `missing` require a native id.
66
+
67
+ The adapter session returns its current binding through `getBinding()`. The router/store owns persistence and conflict handling. Do not let two concurrent native creations overwrite each other.
68
+
69
+ ## Open/resume algorithm
70
+
71
+ A persistent adapter should follow this shape:
72
+
73
+ 1. Receive the frozen binding and workspace in `openSession()`.
74
+ 2. Validate binding adapter/instance identity.
75
+ 3. If `bound`, verify and resume the exact native id.
76
+ 4. If expected native state is absent, report `missing`; do not create a new native conversation.
77
+ 5. If `unbound` and lazy binding is supported, create native state at the documented point, usually open or first prompt.
78
+ 6. Produce the updated binding with protocol/version/locator metadata.
79
+ 7. Let the router persist it with the expected revision.
80
+ 8. Subscribe to native events only after correlation and cleanup structures exist.
81
+ 9. Return a session whose `getBinding()` always reflects current live state.
82
+
83
+ For an empty native artifact that the harness legitimately deletes, distinguish disposable reservation state from durable conversation history. Do not mark it permanently expected until the harness has meaningful native history.
84
+
85
+ ## Restart behavior
86
+
87
+ After gateway restart:
88
+
89
+ - configured instances are recreated from operator config;
90
+ - Pibo reloads the persisted binding;
91
+ - the adapter resumes the same native id when supported;
92
+ - generated tool/resource sessions receive a new live generation;
93
+ - old credentials and generated directories are invalid/removed;
94
+ - product history remains available even if native state is missing.
95
+
96
+ Prove restart behavior using the exact installed package and real server path. Queue acceptance or an auth failure is not proof of resumed model behavior.
97
+
98
+ ## Adapter-owned process/client lifecycle
99
+
100
+ For process-backed adapters:
101
+
102
+ - spawn one process per adapter or session only when the protocol supports that ownership model;
103
+ - keep stdout protocol and stderr diagnostics separate;
104
+ - bound startup time and initialize handshake;
105
+ - correlate every request/response id;
106
+ - serialize or backpressure writes;
107
+ - bound message sizes and pending requests;
108
+ - reject malformed notifications safely;
109
+ - handle process exit and protocol EOF exactly once;
110
+ - terminate child processes on failed startup, abort escalation, disposal, and gateway shutdown;
111
+ - avoid killing another session's shared process;
112
+ - remove listeners/timers and settle pending promises on shutdown.
113
+
114
+ Do not parse a human TUI stream as a protocol when an official app server exists.
115
+
116
+ ## Semantic event normalization
117
+
118
+ Map native protocol notifications into `AgentRuntimeSemanticEvent` values:
119
+
120
+ - turn lifecycle: `turn_started`, `turn_completed`, `turn_failed`;
121
+ - adapter lifecycle: `starting`, `ready`, `restarting`, `stopped`, `crashed`;
122
+ - assistant: `assistant_delta`, `assistant_message`;
123
+ - reasoning: `reasoning_started`, `reasoning_delta`, `reasoning_finished`;
124
+ - tools: call, execution start/update/finish;
125
+ - usage, plans, diffs;
126
+ - compaction start/end;
127
+ - approval and structured user-input requests;
128
+ - warnings/errors;
129
+ - optional redacted `native_event` diagnostics.
130
+
131
+ Preserve stable turn, content-index, tool-call, request, and native-entry identities. The routed session uses them to avoid duplicate output, nest trace nodes, persist product history, and route responses.
132
+
133
+ ## Event ordering rules
134
+
135
+ - Emit `turn_started` before turn-scoped assistant/reasoning/tool events.
136
+ - Emit one terminal `turn_completed` or `turn_failed` per accepted turn.
137
+ - Keep assistant content indexes stable across deltas and final content.
138
+ - Keep tool call ids stable across call/start/update/finish.
139
+ - Do not emit a successful turn completion after a terminal failure.
140
+ - Do not include credentials or unredacted provider bodies in `native_event`.
141
+ - Treat duplicate, late, or post-disposal native events deterministically.
142
+
143
+ Use deterministic protocol fixtures for out-of-order, duplicate, malformed, crash, and partial-stream cases.
144
+
145
+ ## Prompt and steering
146
+
147
+ `prompt()` accepts `AgentRuntimePromptInput` with text, source, and optional capability scope. Set streaming state before sending the native request and settle it after the terminal event.
148
+
149
+ Advertise `input.steering` only when the harness can modify an active turn through a supported operation. Implement `steer()` with the same correlation and cancellation rules. Queuing a second normal turn is not steering.
150
+
151
+ ## Approvals and structured user input
152
+
153
+ When the harness requests approval:
154
+
155
+ 1. emit `approval_requested` with a stable request id and bounded arguments;
156
+ 2. set `pendingApproval`;
157
+ 3. expose `respondToApproval()` only when the capability is true;
158
+ 4. validate decisions against the native protocol;
159
+ 5. clear pending state exactly once after response/cancellation/failure.
160
+
161
+ For structured input, preserve question ids, options, multi-select/freeform semantics, and request identity. Do not flatten a structured request into an uncorrelated chat message if the protocol expects a response method.
162
+
163
+ ## Errors
164
+
165
+ Normalize errors by layer:
166
+
167
+ - registration/config errors before instance creation;
168
+ - availability/profile diagnostics during inspection;
169
+ - binding missing/errors during open/resolve;
170
+ - protocol/startup errors during live creation;
171
+ - turn failures as semantic terminal events;
172
+ - capability-unavailable errors for unsupported controls.
173
+
174
+ Redact tokens, cookies, authorization headers, environment values, generated config contents, local locators, and raw provider request bodies. Preserve safe codes, phase, correlation id, exit status, and bounded stderr summaries.
175
+
176
+ ## Abort and disposal
177
+
178
+ `abort()` cancels active work without disposing the reusable session when the harness supports it. It should be safe when idle.
179
+
180
+ `dispose()` ends the live generation:
181
+
182
+ - unsubscribe native listeners;
183
+ - reject/settle pending requests;
184
+ - abort active turns as required;
185
+ - close native session/client/process according to ownership;
186
+ - revoke Pibo tool MCP credentials;
187
+ - dispose Pibo runtime resources;
188
+ - remove generated files;
189
+ - clear timers/maps;
190
+ - emit no later product events;
191
+ - succeed when called again.
192
+
193
+ Test abort and dispose separately. Process death may implement abort only if the process is session-owned and the resulting native-session semantics are explicit.
@@ -0,0 +1,226 @@
1
+ # Portable Delivery and Native Behavior
2
+
3
+ Use this reference when integrating Pibo-managed tools, external MCP, skills, context, subagents, models/auth/reasoning, or any harness configuration surface.
4
+
5
+ ## Preserve the harness first
6
+
7
+ The harness owns:
8
+
9
+ - native model loop;
10
+ - base system prompt;
11
+ - standard tools and their semantics;
12
+ - native session/thread state;
13
+ - native compaction, approvals, and user-input behavior where available;
14
+ - protocol-specific resource discovery.
15
+
16
+ Pibo owns product context, profile selections, Pibo-managed tools, subagents, jobs/loops/workflows, routing, data, debug, and UI.
17
+
18
+ Do not place Pibo's Pi base prompt over another harness. Do not disable native tools just to make the harness resemble Pi. Do not rewrite global harness config to inject one Pibo Session's resources.
19
+
20
+ ## Open-session services
21
+
22
+ `OpenAgentRuntimeSessionInput.services` may provide:
23
+
24
+ - `portableTools` — one Pibo-owned tool session for the live generation;
25
+ - `resources` — selected skills, ordered context, selected external MCP config, scoped environment, and delivery inspection;
26
+ - subagent/run/runtime controllers through Pibo's router;
27
+ - telemetry/compatibility services.
28
+
29
+ Consume these services; do not recreate their selection, credential, payload, filesystem, or cleanup logic inside the adapter.
30
+
31
+ The tool session and resource session share the same random runtime generation. Treat them as one disposable scope.
32
+
33
+ ## Pibo-managed tools
34
+
35
+ Pibo tools use the harness-neutral `PiboToolDefinition` contract in `src/tools/contract.ts`:
36
+
37
+ - TypeBox/JSON-Schema input;
38
+ - optional structured output schema;
39
+ - text/image content;
40
+ - structured content and details;
41
+ - cancellation and progress;
42
+ - correlation metadata;
43
+ - durable payload references for large results.
44
+
45
+ ### Direct delivery
46
+
47
+ Use `{ support: "direct" }` only when the adapter can compile/call Pibo definitions in-process without requiring harness-private context. Pi uses a direct compiler under `src/agent-runtimes/pi/tool-compiler.ts`.
48
+
49
+ Do not expose a legacy definition with `portable:false` outside its compatibility adapter.
50
+
51
+ ### MCP delivery
52
+
53
+ Use MCP when the external harness supports an official MCP configuration or runtime API. The adapter obtains access from `services.portableTools.issueMcpAccess()`.
54
+
55
+ The returned URL/token are sensitive session-owned process state:
56
+
57
+ - keep the raw token only in memory or scoped process configuration;
58
+ - never persist it in runtime bindings or Pibo data;
59
+ - never print it in logs, diagnostics, Context Build, screenshots, or errors;
60
+ - pass only the selected allowlisted tool names;
61
+ - renew only within the existing scope;
62
+ - revoke on disposal;
63
+ - do not reuse an MCP transport session with another credential/session.
64
+
65
+ Pibo's bridge is loopback Streamable HTTP, validates schemas, propagates cancellation/progress, supports text/images/structured content, and offloads large results. Do not build a second adapter-specific bridge.
66
+
67
+ Account for the harness's native MCP approval policy. A server that connects and lists tools is not usable if every model-initiated call is silently rejected. When the product has already selected a Pibo-owned tool set and the credential independently enforces that exact session/generation/allowlist, an adapter may mark only that generated Pibo MCP server as pre-approved through an official harness setting. Do not apply the same policy globally or automatically to unrelated external MCP servers. Prove a model-initiated call, not only a direct protocol call.
68
+
69
+ ### Native tool yielding
70
+
71
+ `tools.nativeToolYielding` is separate. `pibo_run_start` can yield Pibo-managed tool work. It cannot wrap a private native harness tool unless the adapter provides an explicit native-tool-yielding mechanism. Keep that limitation visible.
72
+
73
+ ## External MCP servers
74
+
75
+ `services.resources` provides selected external MCP server configs and a generated selected-only configuration when the adapter advertises delivery.
76
+
77
+ Use:
78
+
79
+ - `getMcpConfigPath()` for materialized config;
80
+ - `getExternalMcpServerConfigs()` only inside adapter-owned launch state;
81
+ - `getAdapterEnvironment()` for scoped secret environment variables;
82
+ - `getInspection()` for safe delivery and verified inventory.
83
+
84
+ Requirements:
85
+
86
+ - include only selected servers;
87
+ - preserve transport and official harness config semantics;
88
+ - bind secret-bearing literals/arguments through session-only environment references;
89
+ - verify actual protocol initialization and tool/resource/template inventory;
90
+ - report configured versus connected versus failed accurately;
91
+ - do not mutate source MCP config or user-global harness config;
92
+ - dispose child processes/config with the generation.
93
+
94
+ A written config file is not proof of connection.
95
+
96
+ ## Skills
97
+
98
+ `SKILL.md` remains Pibo's canonical skill format. The resource session exposes selected skill paths in source or materialized mode.
99
+
100
+ Use native delivery when the harness accepts additional skill roots through an official API/config. Use materialized delivery when isolated directories are supported.
101
+
102
+ Security/behavior rules:
103
+
104
+ - only selected built-in, plugin, and user skills are present;
105
+ - unselected skills never appear in adapter-visible roots;
106
+ - preserve each selected skill directory and bundled resources;
107
+ - reject escaping symlinks, cycles, excessive files, and excessive bytes;
108
+ - do not point the harness at Pibo's global skill catalog;
109
+ - report delivery mode, fidelity, target, status, and diagnostic.
110
+
111
+ Do not claim skill support merely because arbitrary prompt text can be appended. If that is the only path and genuinely useful, classify it as degraded context with a reason, not native skill support.
112
+
113
+ ## Context contributions
114
+
115
+ The resource session returns ordered context contributions with intent:
116
+
117
+ - developer;
118
+ - project;
119
+ - session;
120
+ - user-visible.
121
+
122
+ Contributions may come from Pibo product context, managed/plugin context files, automatic project discovery, or generated state.
123
+
124
+ Map them into documented harness channels without replacing the native base prompt. Preserve order and intended scope. Report fidelity:
125
+
126
+ - `exact` — content and scope preserved;
127
+ - `equivalent` — semantics preserved through an official but different channel;
128
+ - `lossy` — real delivery with a documented loss;
129
+ - `none` — unsupported or failed.
130
+
131
+ Automatic AGENTS.md/CLAUDE.md discovery may be claimed for materialized adapters only when the adapter declares `native-project-discovery` and proves the harness discovers it in the isolated workspace/config.
132
+
133
+ Never include resolved secret values in context or generated instructions.
134
+
135
+ ## Generated runtime paths
136
+
137
+ Materialized state lives under a private generation tree similar to:
138
+
139
+ ```text
140
+ $PIBO_HOME/agent-runtimes/<runtime-instance>/<pibo-session>/<generation>/
141
+ home/
142
+ skills/
143
+ context/
144
+ config/
145
+ protocol/
146
+ ```
147
+
148
+ Directories are private and disposable. The adapter may add protocol files under its generation, but must not write outside the provided root unless the official harness requires another isolated path and the design documents it.
149
+
150
+ Do not reuse a generation after session disposal or gateway restart.
151
+
152
+ ## Native prompt and tool checks
153
+
154
+ Before and after integration, capture:
155
+
156
+ - native system/developer prompt behavior;
157
+ - native standard tool inventory;
158
+ - native approval behavior;
159
+ - native project-instruction discovery;
160
+ - native session persistence.
161
+
162
+ Add tests that fail if Pibo injects Pi-specific prompt text or removes native tools. A successful answer is not enough; inspect the actual protocol/config/tool inventory when available.
163
+
164
+ ## Models, auth, reasoning, and adapter options
165
+
166
+ The selected configured runtime owns these surfaces:
167
+
168
+ - `listModels()` returns only models valid for that runtime instance;
169
+ - `models.optionsSchema` describes persisted adapter-native options;
170
+ - reasoning values match exact harness values;
171
+ - live model switching is advertised only when the native protocol supports it.
172
+
173
+ Provider auth is an explicit configured-instance capability, not a global Pi service. Declare `capabilities.auth` with:
174
+
175
+ - `status` support;
176
+ - Pibo method ids (`device_code`, `browser_oauth`, or `api_key`) and each method's `immediate`, `explicit`, or `notification` completion mode;
177
+ - cancellation and logout support;
178
+ - credential scope: `runtime-instance` or `adapter-shared`.
179
+
180
+ The capability declaration and methods must match exactly:
181
+
182
+ - `getAuthStatus()` returns every known provider with connected, disconnected, pending, partial, unsupported, or failed state;
183
+ - `startAuth()` starts only declared methods;
184
+ - `completeAuth()` reads explicit/notification flow progress and terminal outcome;
185
+ - `cancelAuth()` and `logoutAuth()` exist only when claimed;
186
+ - `disposeAuth()` is required for non-immediate methods, closes pending adapter-owned processes/transient state, and leaves the configured adapter reusable after router restart.
187
+
188
+ Use only Pibo-owned provider ids, method ids, status, flow, and result types at the boundary. Generate an opaque Pibo flow id and keep native login ids, separate OAuth state/verifier fields, account identifiers, and protocol payloads inside the adapter. An interactive flow may return only the bounded verification/authorization URL, optional one-time user code, bounded instructions, and Pibo flow metadata needed by the user; never persist that ephemeral URL/code in bindings, normalized product history, screenshots, or reports.
189
+
190
+ Pibo product settings require an explicit configured-runtime target. A legacy session-bound action may target the active session's frozen runtime binding, but a random Pibo Session id must never be ignored or treated as global auth scope. Multiple configured instances may intentionally use different accounts. If the harness uses one existing shared store, declare `adapter-shared`, prevent conflicting same-provider flows across that scope, cancel scoped pending flows on logout, and recycle cached sessions for every affected instance rather than pretending the instances are isolated.
191
+
192
+ Join model providers to auth status for the same runtime instance. If that runtime declares auth but status is missing or failed, never default models to authenticated. Keep models visible with disabled/missing-auth explanation when the product spec requires discoverability.
193
+
194
+ Validate adapter options at save and start boundaries. Do not pass unknown arbitrary JSON to a process without schema validation and filtering.
195
+
196
+ Never reuse Chat Web cookies, machine keys, Pibo tool tokens, another harness's auth, local OAuth files, or browser cookies as model-provider credentials. Never use unstable token-injection protocol variants merely because they appear in generated schemas. Tests must prove target routing, timeout/cancellation, restart persistence, same-adapter instance isolation where claimed, and redaction from events, bindings, logs, diagnostics, snapshots, and reports.
197
+
198
+ ## Pibo-managed subagents
199
+
200
+ Subagents remain Pibo product orchestration:
201
+
202
+ - a subagent tool creates or reuses a child Pibo Session using a bounded stable thread key;
203
+ - the child profile selects and freezes its own configured runtime instance and binding;
204
+ - parent and child may use different adapters;
205
+ - hierarchy/correlation remains in Pibo data and events;
206
+ - child tools/resources receive their own generation and credentials;
207
+ - parent interruption and tool cancellation abort active child work without deleting the reusable child session;
208
+ - `pibo_run_start` may yield selected Pibo subagent tools even when private harness-native tool yielding is unsupported.
209
+
210
+ An adapter does not need native harness subagents to support Pibo-managed subagents. It does need a working Pibo-managed tool delivery path, model-call approval semantics that actually permit the selected Pibo tool, and restart/resume evidence for the parent and child bindings.
211
+
212
+ Do not flatten a child session into an undocumented native tool call and then claim cross-runtime subagent support.
213
+
214
+ ## Context Build and inspection
215
+
216
+ Agent Designer and Context Build must show:
217
+
218
+ - selected runtime instance/adapter and diagnostics;
219
+ - effective capability modes;
220
+ - selected tool delivery and portability;
221
+ - skills/context/MCP delivery status, fidelity, target, and inventory;
222
+ - disabled reasons for unsupported selections;
223
+ - redacted secret environment key names, never values;
224
+ - native prompt preservation assumptions/evidence.
225
+
226
+ Inspection may create temporary generation state but must use non-strict mode, avoid delegated work, dispose before return, and not persist a harness conversation.