@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.
- package/dist/agent-runtime/auth.js +28 -0
- package/dist/agent-runtime/capabilities.js +221 -0
- package/dist/agent-runtime/context-build.js +313 -0
- package/dist/agent-runtime/contract.js +45 -0
- package/dist/agent-runtime/errors.js +57 -0
- package/dist/agent-runtime/events.js +1 -0
- package/dist/agent-runtime/history.js +1 -0
- package/dist/agent-runtime/profile-validation.js +109 -0
- package/dist/agent-runtime/registry.js +608 -0
- package/dist/agent-runtime/resource-files.js +87 -0
- package/dist/agent-runtime/resource-service.js +635 -0
- package/dist/agent-runtime/resources.js +1 -0
- package/dist/agent-runtime/routed-session.js +931 -0
- package/dist/agent-runtime/testing/contract.js +51 -0
- package/dist/agent-runtime/testing/fake-adapter.js +192 -0
- package/dist/agent-runtime/types.js +3 -0
- package/dist/agent-runtimes/codex-native/adapter.js +905 -0
- package/dist/agent-runtimes/codex-native/auth.js +476 -0
- package/dist/agent-runtimes/codex-native/client.js +734 -0
- package/dist/agent-runtimes/codex-native/config.js +152 -0
- package/dist/agent-runtimes/codex-native/history.js +283 -0
- package/dist/agent-runtimes/codex-native/mcp-stdio-launcher.js +89 -0
- package/dist/agent-runtimes/codex-native/models.js +581 -0
- package/dist/agent-runtimes/codex-native/process.js +459 -0
- package/dist/agent-runtimes/codex-native/protocol-types.js +1 -0
- package/dist/agent-runtimes/codex-native/protocol-version.js +7 -0
- package/dist/agent-runtimes/codex-native/redaction.js +31 -0
- package/dist/agent-runtimes/codex-native/requests.js +378 -0
- package/dist/agent-runtimes/codex-native/resource-delivery.js +445 -0
- package/dist/agent-runtimes/codex-native/thread.js +388 -0
- package/dist/agent-runtimes/codex-native/turn.js +849 -0
- package/dist/agent-runtimes/pi/adapter.js +653 -0
- package/dist/agent-runtimes/pi/auth.js +455 -0
- package/dist/agent-runtimes/pi/history.js +640 -0
- package/dist/agent-runtimes/pi/model-catalog.js +87 -0
- package/dist/agent-runtimes/pi/routed-session.js +1464 -0
- package/dist/agent-runtimes/pi/runtime.js +534 -0
- package/dist/agent-runtimes/pi/tool-compiler.js +69 -0
- package/dist/apps/chat/agent-profiles.js +40 -23
- package/dist/apps/chat/agent-store.js +111 -64
- package/dist/apps/chat/chat-api-routes.js +1 -1
- package/dist/apps/chat/chat-request-normalizers.js +47 -0
- package/dist/apps/chat/data/chat-data-mappers.js +25 -9
- package/dist/apps/chat/data/history-query-service.js +108 -0
- package/dist/apps/chat/data/session-query-service.js +24 -3
- package/dist/apps/chat/data/timeline-query-service.js +3 -3
- package/dist/apps/chat/model-catalog.js +1 -55
- package/dist/apps/chat/provider-auth-actions.js +171 -23
- package/dist/apps/chat/stream.js +12 -0
- package/dist/apps/chat/trace-v2.js +1 -0
- package/dist/apps/chat/trace.js +126 -415
- package/dist/apps/chat/web-app.js +582 -157
- package/dist/apps/chat-ui/assets/{dist-BTLtT_Vf.js → dist-9v2ZXT6V.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-CMk1aPug.js → dist-B1LVAytl.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-CcwA_IWN.js → dist-C6LPDFXU.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-DKOthbxr.js → dist-DVtXxfHc.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-ls2I6BIw.js → dist-DW4Qrfbd.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-D1rAtRWs.js → dist-DmbsHdMC.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-C1JQRskW.js → dist-DyvwuSFO.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-DfpaylQ-.js → dist-I26VB0QO.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-D10bTFD5.js → dist-RtHbJRPV.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-5KpmmBBZ.js → dist-sZgJkWZb.js} +1 -1
- package/dist/apps/chat-ui/assets/index-BPbNvcZe.css +1 -0
- package/dist/apps/chat-ui/assets/index-CIOf2uL2.js +237 -0
- package/dist/apps/chat-ui/index.html +2 -2
- package/dist/apps/chat-vscode-web/assets/index-1ivRyjFs.js +41 -0
- package/dist/apps/chat-vscode-web/index.html +1 -1
- package/dist/apps/vscode-artifacts/latest.vsix +0 -0
- package/dist/apps/vscode-artifacts/pibo-vscode-ext-2.0.0.vsix +0 -0
- package/dist/auth/login-actions.js +5 -251
- package/dist/cli-session/localSessionSource.js +8 -1
- package/dist/core/context-build.js +124 -20
- package/dist/core/default-profile.js +8 -0
- package/dist/core/profiles.js +30 -3
- package/dist/core/routed-session.js +5 -1446
- package/dist/core/runtime.js +5 -561
- package/dist/core/session-router.js +637 -83
- package/dist/data/cli.js +20 -3
- package/dist/data/schema.js +104 -1
- package/dist/data/session-store.js +24 -1
- package/dist/debug/events.js +25 -10
- package/dist/debug/failures.js +23 -3
- package/dist/debug/index.js +24 -6
- package/dist/debug/messages.js +87 -7
- package/dist/debug/persisted-payloads.js +31 -0
- package/dist/debug/pty.js +7 -6
- package/dist/debug/runtime-binding.js +29 -0
- package/dist/debug/session.js +137 -0
- package/dist/debug/summary.js +12 -0
- package/dist/debug/telemetry.js +28 -0
- package/dist/debug/tools.js +12 -2
- package/dist/debug/trace.js +154 -76
- package/dist/gateway/server.js +87 -2
- package/dist/gateway/tool.js +5 -5
- package/dist/index.js +21 -2
- package/dist/loops/tools.js +13 -12
- package/dist/mcp/agent-context.js +13 -4
- package/dist/mcp/client.js +10 -6
- package/dist/mcp/config.js +5 -2
- package/dist/mcp/runtime-session.js +166 -0
- package/dist/plugins/builtin.js +191 -53
- package/dist/plugins/codex-native.js +29 -0
- package/dist/plugins/registry.js +66 -2
- package/dist/runs/tools.js +26 -25
- package/dist/session-ui/terminalRows.js +2 -2
- package/dist/sessions/pibo-data-store.js +125 -16
- package/dist/sessions/runtime-binding.js +107 -0
- package/dist/sessions/sqlite-store.js +239 -18
- package/dist/sessions/store.js +86 -7
- package/dist/shared/trace-engine.js +18 -9
- package/dist/shared/trace-event-projection.js +29 -11
- package/dist/shared/{trace-transcript.js → trace-history.js} +193 -195
- package/dist/shared/trace-order.js +9 -4
- package/dist/shared/trace-page-merge.js +1 -1
- package/dist/signals/projector.js +20 -2
- package/dist/signals/registry.js +11 -0
- package/dist/subagents/tool.js +8 -6
- package/dist/tools/codex-browser.js +20 -19
- package/dist/tools/codex-compat.js +10 -9
- package/dist/tools/codex-image-generation.js +8 -6
- package/dist/tools/contract.js +45 -0
- package/dist/tools/credential-registry.js +182 -0
- package/dist/tools/mcp-bridge.js +511 -0
- package/dist/tools/payload-writer.js +17 -0
- package/dist/tools/runtime/tool.js +10 -9
- package/dist/tools/schema.js +9 -0
- package/dist/tools/session-service.js +193 -0
- package/dist/tools/session-tool-set.js +85 -0
- package/dist/web-annotations/tools.js +17 -16
- package/docs/README.md +11 -0
- package/package.json +3 -2
- package/skills/builtin/pibo-agent-runtime-adapter/SKILL.md +183 -0
- package/skills/builtin/pibo-agent-runtime-adapter/evals/README.md +10 -0
- package/skills/builtin/pibo-agent-runtime-adapter/evals/evals.json +45 -0
- package/skills/builtin/pibo-agent-runtime-adapter/evals/fixtures/orion-full-harness.md +60 -0
- package/skills/builtin/pibo-agent-runtime-adapter/evals/fixtures/relay-partial-harness.md +52 -0
- package/skills/builtin/pibo-agent-runtime-adapter/references/capabilities-and-designer.md +194 -0
- package/skills/builtin/pibo-agent-runtime-adapter/references/history-debug-and-security.md +213 -0
- package/skills/builtin/pibo-agent-runtime-adapter/references/interfaces-and-registration.md +214 -0
- package/skills/builtin/pibo-agent-runtime-adapter/references/lifecycle-bindings-and-events.md +193 -0
- package/skills/builtin/pibo-agent-runtime-adapter/references/portable-delivery-and-native-behavior.md +226 -0
- package/skills/builtin/pibo-agent-runtime-adapter/references/testing-migration-and-validation.md +256 -0
- package/dist/apps/chat-ui/assets/index-C2YI0xfw.js +0 -237
- package/dist/apps/chat-ui/assets/index-E0RmuCkY.css +0 -1
- package/dist/apps/chat-vscode-web/assets/index-D-tSsXLG.js +0 -41
package/dist/debug/trace.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { dirname, join } from "node:path";
|
|
1
2
|
import { buildTraceView } from "../apps/chat/trace.js";
|
|
2
|
-
import {
|
|
3
|
+
import { storedPiboEventFromV2Row } from "../apps/chat/data/chat-data-mappers.js";
|
|
4
|
+
import { PayloadStore } from "../data/payload-store.js";
|
|
5
|
+
import { createDefaultPiboPluginRegistry } from "../plugins/builtin.js";
|
|
3
6
|
import { compareTraceNodes } from "../shared/trace-nodes.js";
|
|
4
7
|
import { openReadOnlyDebugDatabase, withStorePath } from "./sql.js";
|
|
5
8
|
import { formatNextCommands } from "./next-commands.js";
|
|
@@ -15,19 +18,50 @@ export async function inspectDebugTrace(piboSessionId, stores, options = {}) {
|
|
|
15
18
|
const sessionRow = sessionsDb.prepare("SELECT * FROM sessions WHERE id = ?").get(piboSessionId);
|
|
16
19
|
if (!sessionRow)
|
|
17
20
|
throw new Error(`Pibo session "${piboSessionId}" not found`);
|
|
18
|
-
const
|
|
19
|
-
const
|
|
21
|
+
const binding = readRuntimeBindingForTrace(sessionsDb, sessionRow);
|
|
22
|
+
const session = { ...sessionFromRow(sessionRow), runtimeBinding: binding };
|
|
23
|
+
const sessions = sessionsDb.prepare("SELECT * FROM sessions").all().map((row) => ({
|
|
24
|
+
...sessionFromRow(row),
|
|
25
|
+
runtimeBinding: readRuntimeBindingForTrace(sessionsDb, row),
|
|
26
|
+
}));
|
|
20
27
|
const adapterIssues = [];
|
|
21
|
-
const
|
|
22
|
-
? chatDb
|
|
23
|
-
|
|
24
|
-
|
|
28
|
+
const payloadStore = tableExists(chatDb, "payloads")
|
|
29
|
+
? new PayloadStore(chatDb, join(dirname(stores.chat.path), "payloads"))
|
|
30
|
+
: undefined;
|
|
31
|
+
const eventRows = tableExists(chatDb, "event_log")
|
|
32
|
+
? chatDb.prepare("SELECT * FROM event_log WHERE session_id = ? ORDER BY stream_id ASC").all(piboSessionId)
|
|
25
33
|
: [];
|
|
34
|
+
const events = eventRows.map((row) => {
|
|
35
|
+
const event = storedPiboEventFromV2Row(row, payloadStore);
|
|
36
|
+
if (event && (row.type === "assistant_delta" || row.type === "thinking_delta") && !nonEmptyEventText(event.payload)) {
|
|
37
|
+
adapterIssues.push({
|
|
38
|
+
severity: "warning",
|
|
39
|
+
code: "missing_delta_text",
|
|
40
|
+
nodeId: row.event_id ?? String(row.stream_id),
|
|
41
|
+
message: `Persisted ${row.type} event has no readable text payload.`,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return event;
|
|
45
|
+
}).filter((event) => event !== undefined);
|
|
46
|
+
const productHistory = readProductHistoryEntries(chatDb, payloadStore, piboSessionId);
|
|
47
|
+
let nativeHistoryEntries = [];
|
|
48
|
+
let nativeHistoryInspection;
|
|
49
|
+
if (options.nativeHistory || (events.length === 0 && productHistory.length === 0)) {
|
|
50
|
+
const native = await readDebugNativeHistory(binding, session.workspace ?? process.cwd(), adapterIssues);
|
|
51
|
+
nativeHistoryEntries = native?.entries ?? [];
|
|
52
|
+
nativeHistoryInspection = native?.inspection;
|
|
53
|
+
}
|
|
54
|
+
const historyEntries = nativeHistoryEntries.length ? nativeHistoryEntries : productHistory;
|
|
55
|
+
const historySource = nativeHistoryEntries.length
|
|
56
|
+
? "native"
|
|
57
|
+
: productHistory.length ? "product" : "events";
|
|
26
58
|
const sessionStatus = resolveDebugTraceSessionStatus(sessionRow.status, events.map((event) => event.type));
|
|
27
59
|
const view = await buildTraceView({
|
|
28
60
|
session,
|
|
29
61
|
sessions,
|
|
30
62
|
events,
|
|
63
|
+
historyEntries,
|
|
64
|
+
historyInspection: nativeHistoryInspection,
|
|
31
65
|
status: sessionStatus.status,
|
|
32
66
|
});
|
|
33
67
|
const rows = flattenTraceNodes(view.nodes);
|
|
@@ -36,6 +70,11 @@ export async function inspectDebugTrace(piboSessionId, stores, options = {}) {
|
|
|
36
70
|
return {
|
|
37
71
|
piboSessionId: view.piboSessionId,
|
|
38
72
|
piSessionId: view.piSessionId,
|
|
73
|
+
runtimeInstanceId: binding?.runtimeInstanceId,
|
|
74
|
+
runtimeAdapterId: binding?.adapterId,
|
|
75
|
+
nativeSessionId: binding?.nativeSessionId,
|
|
76
|
+
runtimeBindingState: binding?.state,
|
|
77
|
+
historySource,
|
|
39
78
|
title: view.title,
|
|
40
79
|
status: statusSummary.status,
|
|
41
80
|
statusSource: sessionStatus.source,
|
|
@@ -72,6 +111,11 @@ export function formatDebugTrace(result, options = {}) {
|
|
|
72
111
|
const lines = [
|
|
73
112
|
`piboSessionId: ${result.piboSessionId}`,
|
|
74
113
|
`piSessionId: ${result.piSessionId}`,
|
|
114
|
+
...(result.runtimeInstanceId ? [`runtimeInstanceId: ${result.runtimeInstanceId}`] : []),
|
|
115
|
+
...(result.runtimeAdapterId ? [`runtimeAdapterId: ${result.runtimeAdapterId}`] : []),
|
|
116
|
+
...(result.nativeSessionId ? [`nativeSessionId: ${result.nativeSessionId}`] : []),
|
|
117
|
+
...(result.runtimeBindingState ? [`runtimeBindingState: ${result.runtimeBindingState}`] : []),
|
|
118
|
+
`historySource: ${result.historySource}`,
|
|
75
119
|
`title: ${result.title}`,
|
|
76
120
|
`status: ${result.status}`,
|
|
77
121
|
`statusSource: ${result.statusSource}`,
|
|
@@ -290,7 +334,7 @@ function formatOrderKey(node) {
|
|
|
290
334
|
function sessionFromRow(row) {
|
|
291
335
|
return {
|
|
292
336
|
id: row.id,
|
|
293
|
-
piSessionId: row.pi_session_id,
|
|
337
|
+
piSessionId: row.pi_session_id ?? "",
|
|
294
338
|
channel: row.channel,
|
|
295
339
|
kind: row.kind,
|
|
296
340
|
profile: row.profile,
|
|
@@ -303,87 +347,121 @@ function sessionFromRow(row) {
|
|
|
303
347
|
updatedAt: row.updated_at,
|
|
304
348
|
};
|
|
305
349
|
}
|
|
306
|
-
function
|
|
307
|
-
|
|
308
|
-
|
|
350
|
+
function readProductHistoryEntries(db, payloadStore, piboSessionId) {
|
|
351
|
+
if (!tableExists(db, "chat_messages"))
|
|
352
|
+
return [];
|
|
353
|
+
const rows = db.prepare(`
|
|
354
|
+
SELECT m.*, e.session_sequence AS event_sequence
|
|
355
|
+
FROM chat_messages m
|
|
356
|
+
LEFT JOIN event_log e ON e.stream_id = m.source_stream_id
|
|
357
|
+
WHERE m.session_id = ? AND m.role IN ('user', 'assistant', 'system')
|
|
358
|
+
ORDER BY m.sequence ASC
|
|
359
|
+
LIMIT 2000
|
|
360
|
+
`).all(piboSessionId);
|
|
361
|
+
return rows.flatMap((row) => {
|
|
362
|
+
const role = row.role === "user" || row.role === "assistant" || row.role === "system" ? row.role : undefined;
|
|
363
|
+
if (!role)
|
|
364
|
+
return [];
|
|
365
|
+
const attributes = parseObject(row.attributes_json);
|
|
366
|
+
let content = typeof attributes.inlineText === "string" ? attributes.inlineText : row.content_preview ?? "";
|
|
367
|
+
if (row.content_payload_ref && payloadStore) {
|
|
368
|
+
try {
|
|
369
|
+
content = payloadStore.readPayloadText(row.content_payload_ref);
|
|
370
|
+
}
|
|
371
|
+
catch {
|
|
372
|
+
// Keep the bounded preview and let trace checks report any missing event payload separately.
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
return [{
|
|
376
|
+
id: `product:${row.id}`,
|
|
377
|
+
type: "message",
|
|
378
|
+
source: "product",
|
|
379
|
+
createdAt: row.created_at,
|
|
380
|
+
sequence: row.event_sequence ?? row.sequence,
|
|
381
|
+
turnId: row.turn_id ?? undefined,
|
|
382
|
+
role,
|
|
383
|
+
content,
|
|
384
|
+
assistantIndex: numberAttribute(attributes, "assistantIndex"),
|
|
385
|
+
contentIndex: numberAttribute(attributes, "contentIndex"),
|
|
386
|
+
status: row.status === "running" || row.status === "streaming"
|
|
387
|
+
? "running"
|
|
388
|
+
: row.status === "error" || row.status === "failed" ? "error" : "complete",
|
|
389
|
+
}];
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
async function readDebugNativeHistory(binding, workspace, issues) {
|
|
393
|
+
if (!binding)
|
|
309
394
|
return undefined;
|
|
310
|
-
|
|
395
|
+
const registry = createDefaultPiboPluginRegistry();
|
|
396
|
+
const adapter = registry.getAgentRuntimeAdapter(binding.runtimeInstanceId);
|
|
397
|
+
if (!adapter?.descriptor.capabilities.maintenance.history || !adapter.readHistory) {
|
|
311
398
|
issues.push({
|
|
312
399
|
severity: "warning",
|
|
313
|
-
code: "
|
|
314
|
-
|
|
315
|
-
message: `Persisted ${row.type} event has no readable text payload.`,
|
|
400
|
+
code: "runtime_history_provider_unavailable",
|
|
401
|
+
message: `Runtime instance "${binding.runtimeInstanceId}" has no locally registered history provider.`,
|
|
316
402
|
});
|
|
403
|
+
return undefined;
|
|
317
404
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
piboSessionId: row.session_id ?? undefined,
|
|
321
|
-
eventSequence: row.session_sequence ?? undefined,
|
|
322
|
-
eventId: row.event_id ?? undefined,
|
|
323
|
-
streamId: row.stream_id,
|
|
324
|
-
type: row.type,
|
|
325
|
-
createdAt: row.created_at,
|
|
326
|
-
payload,
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
function outputPayloadFromV2Row(row) {
|
|
330
|
-
const attributes = parseObject(row.attributes_json);
|
|
331
|
-
const inlinePayload = attributes.inlinePayload;
|
|
332
|
-
if (inlinePayload && typeof inlinePayload === "object" && !Array.isArray(inlinePayload) && typeof inlinePayload.type === "string") {
|
|
333
|
-
return inlinePayload;
|
|
405
|
+
try {
|
|
406
|
+
return await adapter.readHistory({ binding, workspace, limit: 500 });
|
|
334
407
|
}
|
|
335
|
-
|
|
336
|
-
|
|
408
|
+
catch (error) {
|
|
409
|
+
issues.push({
|
|
410
|
+
severity: "warning",
|
|
411
|
+
code: "runtime_history_read_failed",
|
|
412
|
+
message: redactRuntimeHistoryError(error),
|
|
413
|
+
});
|
|
337
414
|
return undefined;
|
|
338
|
-
const base = { piboSessionId, eventId: row.event_id ?? undefined };
|
|
339
|
-
if (row.type === "assistant_message")
|
|
340
|
-
return compactObject({ ...base, type: "assistant_message", text: row.preview_text ?? "" });
|
|
341
|
-
if (row.type === "assistant_delta")
|
|
342
|
-
return compactObject({ ...base, type: "assistant_delta", text: inlineTextPayload(inlinePayload) ?? row.preview_text ?? "" });
|
|
343
|
-
if (row.type === "message_started")
|
|
344
|
-
return compactObject({ ...base, type: "message_started", text: row.preview_text ?? "" });
|
|
345
|
-
if (row.type === "message_finished")
|
|
346
|
-
return compactObject({ ...base, type: "message_finished" });
|
|
347
|
-
if (row.type === "thinking_started")
|
|
348
|
-
return compactObject({ ...base, type: "thinking_started" });
|
|
349
|
-
if (row.type === "thinking_delta")
|
|
350
|
-
return compactObject({ ...base, type: "thinking_delta", text: inlineTextPayload(inlinePayload) ?? row.preview_text ?? "" });
|
|
351
|
-
if (row.type === "thinking_finished")
|
|
352
|
-
return compactObject({ ...base, type: "thinking_finished", text: row.preview_text ?? "" });
|
|
353
|
-
if (row.type === "tool_call")
|
|
354
|
-
return compactObject({ ...base, type: "tool_call", toolCallId: stringAttribute(attributes, "toolCallId") ?? row.event_id ?? `tool_${row.stream_id}`, toolName: row.preview_text ?? stringAttribute(attributes, "toolName") ?? "tool", args: inlinePayload ?? null, argsComplete: booleanAttribute(attributes, "argsComplete") ?? true });
|
|
355
|
-
if (row.type === "tool_execution_started")
|
|
356
|
-
return compactObject({ ...base, type: "tool_execution_started", toolCallId: stringAttribute(attributes, "toolCallId") ?? row.event_id ?? `tool_${row.stream_id}`, toolName: row.preview_text ?? stringAttribute(attributes, "toolName") ?? "tool", args: inlinePayload ?? null });
|
|
357
|
-
if (row.type === "tool_execution_updated")
|
|
358
|
-
return compactObject({ ...base, type: "tool_execution_updated", toolCallId: stringAttribute(attributes, "toolCallId") ?? row.event_id ?? `tool_${row.stream_id}`, toolName: row.preview_text ?? stringAttribute(attributes, "toolName") ?? "tool", args: null, partialResult: inlinePayload ?? null });
|
|
359
|
-
if (row.type === "tool_execution_finished")
|
|
360
|
-
return compactObject({ ...base, type: "tool_execution_finished", toolCallId: stringAttribute(attributes, "toolCallId") ?? row.event_id ?? `tool_${row.stream_id}`, toolName: row.preview_text ?? stringAttribute(attributes, "toolName") ?? "tool", result: inlinePayload ?? null, isError: booleanAttribute(attributes, "isError") ?? false });
|
|
361
|
-
if (row.type === "session_error") {
|
|
362
|
-
const error = stringAttribute(attributes, "error") ?? row.preview_text ?? "Error";
|
|
363
|
-
return compactObject({ ...base, type: "session_error", error, errorDetails: normalizeSessionErrorDetails(error, isRecord(attributes.errorDetails) ? attributes.errorDetails : undefined) });
|
|
364
415
|
}
|
|
365
|
-
return compactObject({ ...base, type: row.type });
|
|
366
|
-
}
|
|
367
|
-
function inlineTextPayload(value) {
|
|
368
|
-
return typeof value === "string" ? value : undefined;
|
|
369
|
-
}
|
|
370
|
-
function nonEmptyEventText(event) {
|
|
371
|
-
const text = event.text;
|
|
372
|
-
return typeof text === "string" && text.length > 0;
|
|
373
416
|
}
|
|
374
|
-
function
|
|
375
|
-
|
|
376
|
-
|
|
417
|
+
function readRuntimeBindingForTrace(db, session) {
|
|
418
|
+
if (!tableExists(db, "session_runtime_bindings")) {
|
|
419
|
+
return {
|
|
420
|
+
piboSessionId: session.id,
|
|
421
|
+
runtimeInstanceId: "pi",
|
|
422
|
+
adapterId: "pi",
|
|
423
|
+
nativeSessionId: session.pi_session_id ?? undefined,
|
|
424
|
+
state: session.pi_session_id ? "bound" : "unbound",
|
|
425
|
+
protocol: "pi-sdk",
|
|
426
|
+
metadata: { source: "legacy-synthesized" },
|
|
427
|
+
revision: 1,
|
|
428
|
+
createdAt: session.created_at,
|
|
429
|
+
updatedAt: session.updated_at,
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
const row = db.prepare("SELECT * FROM session_runtime_bindings WHERE pibo_session_id = ?").get(session.id);
|
|
433
|
+
if (!row)
|
|
434
|
+
return undefined;
|
|
435
|
+
const locator = parseObject(row.locator_json);
|
|
436
|
+
return {
|
|
437
|
+
piboSessionId: row.pibo_session_id,
|
|
438
|
+
runtimeInstanceId: row.runtime_instance_id,
|
|
439
|
+
adapterId: row.runtime_adapter_id,
|
|
440
|
+
nativeSessionId: row.native_session_id ?? undefined,
|
|
441
|
+
state: row.binding_state,
|
|
442
|
+
protocol: row.protocol ?? undefined,
|
|
443
|
+
protocolVersion: row.protocol_version ?? undefined,
|
|
444
|
+
adapterVersion: row.adapter_version ?? undefined,
|
|
445
|
+
locator: typeof locator.kind === "string" ? locator : undefined,
|
|
446
|
+
metadata: parseObject(row.metadata_json),
|
|
447
|
+
revision: row.revision,
|
|
448
|
+
createdAt: row.created_at,
|
|
449
|
+
updatedAt: row.updated_at,
|
|
450
|
+
};
|
|
377
451
|
}
|
|
378
|
-
function
|
|
452
|
+
function numberAttribute(attributes, key) {
|
|
379
453
|
const value = attributes[key];
|
|
380
|
-
return typeof value === "
|
|
454
|
+
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
381
455
|
}
|
|
382
|
-
function
|
|
383
|
-
|
|
456
|
+
function nonEmptyEventText(event) {
|
|
457
|
+
const text = event && typeof event === "object" ? event.text : undefined;
|
|
458
|
+
return typeof text === "string" && text.length > 0;
|
|
384
459
|
}
|
|
385
|
-
function
|
|
386
|
-
return
|
|
460
|
+
function redactRuntimeHistoryError(error) {
|
|
461
|
+
return (error instanceof Error ? error.message : String(error))
|
|
462
|
+
.replace(/(bearer|token|secret|password|api[_-]?key)\s*[:=]\s*[^\s,;]+/gi, "$1=[redacted]")
|
|
463
|
+
.replace(/\/\/[^\s/@:]+:[^\s/@]+@/g, "//[redacted]@")
|
|
464
|
+
.slice(0, 500);
|
|
387
465
|
}
|
|
388
466
|
function tableExists(db, table) {
|
|
389
467
|
const row = db.prepare("SELECT name FROM sqlite_schema WHERE type = 'table' AND name = ?").get(table);
|
package/dist/gateway/server.js
CHANGED
|
@@ -128,6 +128,7 @@ async function createGatewaySessionStore(options) {
|
|
|
128
128
|
export class PiboGatewayServer {
|
|
129
129
|
options;
|
|
130
130
|
pluginRegistry;
|
|
131
|
+
compatibilityRuntimeRegistry;
|
|
131
132
|
runtimeInstanceId;
|
|
132
133
|
sessionStore;
|
|
133
134
|
ownsSessionStore = false;
|
|
@@ -142,6 +143,7 @@ export class PiboGatewayServer {
|
|
|
142
143
|
constructor(options = {}) {
|
|
143
144
|
this.options = options;
|
|
144
145
|
this.pluginRegistry = options.pluginRegistry ?? createDefaultPiboPluginRegistry();
|
|
146
|
+
this.compatibilityRuntimeRegistry = options.pluginRegistry ? createDefaultPiboPluginRegistry() : undefined;
|
|
145
147
|
this.runtimeInstanceId = options.runtimeInstanceId ?? `gateway:${process.pid}:${randomUUID()}`;
|
|
146
148
|
}
|
|
147
149
|
async start() {
|
|
@@ -320,15 +322,91 @@ export class PiboGatewayServer {
|
|
|
320
322
|
createSession: (input) => {
|
|
321
323
|
const profile = resolvePiboProfileNameFromRegistryOrDefault(this.pluginRegistry, input.profile);
|
|
322
324
|
const profileContext = createPiboProfileFromRegistryOrDefault(this.pluginRegistry, profile);
|
|
325
|
+
const runtimeAdapter = this.pluginRegistry.getAgentRuntimeAdapter(profileContext.runtimeInstanceId)
|
|
326
|
+
?? this.compatibilityRuntimeRegistry?.getAgentRuntimeAdapter(profileContext.runtimeInstanceId);
|
|
327
|
+
if (!runtimeAdapter)
|
|
328
|
+
throw new Error(`Unknown agent runtime instance "${profileContext.runtimeInstanceId}".`);
|
|
323
329
|
const activeModel = input.activeModel ?? selectRequestedModelProfile(profileContext, loadPiboModelDefaults());
|
|
324
|
-
return this.requireSessionStore().create({
|
|
330
|
+
return this.requireSessionStore().create({
|
|
331
|
+
...input,
|
|
332
|
+
profile,
|
|
333
|
+
activeModel,
|
|
334
|
+
runtimeBinding: input.runtimeBinding ?? {
|
|
335
|
+
runtimeInstanceId: profileContext.runtimeInstanceId,
|
|
336
|
+
adapterId: runtimeAdapter.descriptor.id,
|
|
337
|
+
state: "unbound",
|
|
338
|
+
protocol: runtimeAdapter.descriptor.protocol?.name,
|
|
339
|
+
},
|
|
340
|
+
});
|
|
325
341
|
},
|
|
326
342
|
updateSession: (id, input) => this.requireSessionStore().update(id, input),
|
|
327
343
|
setLiveSessionActiveModel: (id, model) => this.requireRouter().setLiveSessionActiveModel(id, model),
|
|
328
344
|
reportSessionError: (id, error, options) => this.requireRouter().reportSessionError(id, error, options),
|
|
329
|
-
deleteSession: (id) =>
|
|
345
|
+
deleteSession: async (id) => {
|
|
346
|
+
await this.requireRouter().disposeSession(id, "session deleted");
|
|
347
|
+
return this.requireSessionStore().delete?.(id) ?? false;
|
|
348
|
+
},
|
|
330
349
|
findSessions: (input) => this.requireSessionStore().find(input),
|
|
331
350
|
listSessions: () => this.requireSessionStore().list?.() ?? [],
|
|
351
|
+
getSessionRuntimeBinding: (piboSessionId) => this.requireRouter().getSessionRuntimeBinding(piboSessionId),
|
|
352
|
+
inspectSessionRuntimeHistory: async (piboSessionId) => {
|
|
353
|
+
const session = this.requireSessionStore().get(piboSessionId);
|
|
354
|
+
if (!session)
|
|
355
|
+
throw new Error(`Pibo session "${piboSessionId}" was not found.`);
|
|
356
|
+
const binding = this.requireRouter().getSessionRuntimeBinding(piboSessionId) ?? session.runtimeBinding;
|
|
357
|
+
if (!binding)
|
|
358
|
+
throw new Error(`Pibo session "${piboSessionId}" has no runtime binding.`);
|
|
359
|
+
const adapter = this.pluginRegistry.getAgentRuntimeAdapter(binding.runtimeInstanceId)
|
|
360
|
+
?? this.compatibilityRuntimeRegistry?.getAgentRuntimeAdapter(binding.runtimeInstanceId);
|
|
361
|
+
if (!adapter) {
|
|
362
|
+
return {
|
|
363
|
+
runtimeInstanceId: binding.runtimeInstanceId,
|
|
364
|
+
adapterId: binding.adapterId,
|
|
365
|
+
bindingState: binding.state,
|
|
366
|
+
available: false,
|
|
367
|
+
diagnostics: [{
|
|
368
|
+
severity: "error",
|
|
369
|
+
code: "runtime_history_instance_unavailable",
|
|
370
|
+
message: `Agent runtime instance "${binding.runtimeInstanceId}" is not registered in this gateway.`,
|
|
371
|
+
}],
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
if (!adapter.descriptor.capabilities.maintenance.history || !adapter.inspectHistory) {
|
|
375
|
+
return {
|
|
376
|
+
runtimeInstanceId: binding.runtimeInstanceId,
|
|
377
|
+
adapterId: binding.adapterId,
|
|
378
|
+
bindingState: binding.state,
|
|
379
|
+
available: false,
|
|
380
|
+
diagnostics: [{
|
|
381
|
+
severity: "warning",
|
|
382
|
+
code: "runtime_history_unsupported",
|
|
383
|
+
message: `Agent runtime instance "${binding.runtimeInstanceId}" does not provide native history inspection.`,
|
|
384
|
+
}],
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
return await adapter.inspectHistory({ binding, workspace: session.workspace ?? process.cwd() });
|
|
388
|
+
},
|
|
389
|
+
readSessionRuntimeHistory: async (piboSessionId, input = {}) => {
|
|
390
|
+
const session = this.requireSessionStore().get(piboSessionId);
|
|
391
|
+
if (!session)
|
|
392
|
+
throw new Error(`Pibo session "${piboSessionId}" was not found.`);
|
|
393
|
+
const binding = this.requireRouter().getSessionRuntimeBinding(piboSessionId) ?? session.runtimeBinding;
|
|
394
|
+
if (!binding)
|
|
395
|
+
throw new Error(`Pibo session "${piboSessionId}" has no runtime binding.`);
|
|
396
|
+
const adapter = this.pluginRegistry.getAgentRuntimeAdapter(binding.runtimeInstanceId)
|
|
397
|
+
?? this.compatibilityRuntimeRegistry?.getAgentRuntimeAdapter(binding.runtimeInstanceId);
|
|
398
|
+
if (!adapter?.descriptor.capabilities.maintenance.history || !adapter.readHistory) {
|
|
399
|
+
throw new Error(`Agent runtime instance "${binding.runtimeInstanceId}" does not provide native history.`);
|
|
400
|
+
}
|
|
401
|
+
return await adapter.readHistory({
|
|
402
|
+
binding,
|
|
403
|
+
workspace: session.workspace ?? process.cwd(),
|
|
404
|
+
cursor: input.cursor,
|
|
405
|
+
beforeTimestamp: input.beforeTimestamp,
|
|
406
|
+
limit: input.limit,
|
|
407
|
+
});
|
|
408
|
+
},
|
|
409
|
+
rebindSessionRuntime: (piboSessionId, input) => this.requireRouter().rebindSessionRuntime(piboSessionId, input),
|
|
332
410
|
getSessionRuntimeStatus: (piboSessionId) => this.requireRouter().getSessionRuntimeStatus(piboSessionId),
|
|
333
411
|
getSessionStatusSnapshot: (piboSessionId) => this.requireRouter().getSessionStatusSnapshot(piboSessionId),
|
|
334
412
|
listSessionRuntimeStatuses: () => this.requireRouter().listSessionRuntimeStatuses(),
|
|
@@ -342,6 +420,13 @@ export class PiboGatewayServer {
|
|
|
342
420
|
getProfiles: () => this.pluginRegistry.getProfileInfos(),
|
|
343
421
|
createProfile: (name) => this.pluginRegistry.createProfile(name),
|
|
344
422
|
getCapabilityCatalog: () => this.pluginRegistry.getCapabilityCatalog(),
|
|
423
|
+
inspectAgentRuntimeInstances: () => this.pluginRegistry.inspectAgentRuntimeInstances(),
|
|
424
|
+
getAgentRuntimeAuthStatus: (runtimeInstanceId) => this.requireRouter().getAgentRuntimeAuthStatus(runtimeInstanceId),
|
|
425
|
+
startAgentRuntimeAuth: (runtimeInstanceId, input) => this.requireRouter().startAgentRuntimeAuth(runtimeInstanceId, input),
|
|
426
|
+
completeAgentRuntimeAuth: (runtimeInstanceId, input) => this.requireRouter().completeAgentRuntimeAuth(runtimeInstanceId, input),
|
|
427
|
+
cancelAgentRuntimeAuth: (runtimeInstanceId, input) => this.requireRouter().cancelAgentRuntimeAuth(runtimeInstanceId, input),
|
|
428
|
+
logoutAgentRuntimeAuth: (runtimeInstanceId, input) => this.requireRouter().logoutAgentRuntimeAuth(runtimeInstanceId, input),
|
|
429
|
+
validateAgentRuntimeProfile: (profile, workspace) => this.pluginRegistry.validateAgentRuntimeProfile(profile, workspace),
|
|
345
430
|
getLoopStopConditionDefinitions: () => this.pluginRegistry.getLoopStopConditionDefinitions(),
|
|
346
431
|
getLoopStopConditionInfos: () => this.pluginRegistry.getLoopStopConditionInfos(),
|
|
347
432
|
getRalphStopConditionDefinitions: () => this.pluginRegistry.getLoopStopConditionDefinitions(),
|
package/dist/gateway/tool.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Type } from "
|
|
2
|
-
import {
|
|
1
|
+
import { Type } from "typebox";
|
|
2
|
+
import { definePiboTool } from "../tools/contract.js";
|
|
3
3
|
import { sendGatewayMessageAndWaitForReply } from "./request.js";
|
|
4
4
|
export function createPiboGatewaySendTool(sendGatewayMessage = sendGatewayMessageAndWaitForReply) {
|
|
5
|
-
return
|
|
5
|
+
return definePiboTool({
|
|
6
6
|
name: "pibo_gateway_send",
|
|
7
|
-
|
|
7
|
+
title: "Pibo Gateway Send",
|
|
8
8
|
description: "Send a message through the local pibo gateway to a target session and return the target assistant reply.",
|
|
9
9
|
promptSnippet: "Send a message through the local pibo gateway to a target session and return the final assistant reply from that session.",
|
|
10
|
-
|
|
10
|
+
inputSchema: Type.Object({
|
|
11
11
|
piboSessionId: Type.String({ description: "Target Pibo gateway session id" }),
|
|
12
12
|
message: Type.String({ description: "Message to enqueue for the target session" }),
|
|
13
13
|
}),
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,29 @@
|
|
|
1
|
-
export { createDefaultPiboProfile, createDefaultPiboPluginRegistry, createDefaultPiboPlugins, createGatewayProducerPiboPluginRegistry, createGatewayProducerPiboProfile, piboCorePlugin, piboGatewayProducerPlugin, } from "./plugins/builtin.js";
|
|
1
|
+
export { createDefaultPiboProfile, createDefaultPiboPluginRegistry, createDefaultPiboPlugins, createGatewayProducerPiboPluginRegistry, createGatewayProducerPiboProfile, CODEX_NATIVE_PROFILE_NAME, CODEX_NATIVE_RUNTIME_INSTANCE_ID, piboCodexNativePlugin, piboCorePlugin, piboGatewayProducerPlugin, } from "./plugins/builtin.js";
|
|
2
2
|
export { createPiboBetterAuthPlugin } from "./plugins/better-auth.js";
|
|
3
3
|
export { createPiboChatWebPlugin } from "./plugins/chat-web.js";
|
|
4
4
|
export { createPiboContextFilesPlugin } from "./plugins/context-files.js";
|
|
5
5
|
export { createPiboWebHostPlugin } from "./plugins/web.js";
|
|
6
6
|
export { createChatWebApp } from "./apps/chat/web-app.js";
|
|
7
7
|
export { createBetterAuthService } from "./auth/better-auth.js";
|
|
8
|
-
export { InitialSessionContext, InitialSessionContextBuilder, } from "./core/profiles.js";
|
|
8
|
+
export { DEFAULT_AGENT_RUNTIME_INSTANCE_ID, InitialSessionContext, InitialSessionContextBuilder, normalizeToolProfile, } from "./core/profiles.js";
|
|
9
|
+
export { AgentRuntimeAdapterRegistry } from "./agent-runtime/registry.js";
|
|
10
|
+
export { validateAgentRuntimeProfileCapabilities } from "./agent-runtime/profile-validation.js";
|
|
11
|
+
export { buildPortableRuntimeContextSnapshot, profileWithRuntimeInstance, uniqueRuntimeDiagnostics, } from "./agent-runtime/context-build.js";
|
|
12
|
+
export { RuntimeRoutedSession } from "./agent-runtime/routed-session.js";
|
|
13
|
+
export { PiboRuntimeResourceError, PiboRuntimeResourceService, } from "./agent-runtime/resource-service.js";
|
|
14
|
+
export { assertAgentRuntimeSessionContract, validateAgentRuntimeSessionContract, } from "./agent-runtime/contract.js";
|
|
15
|
+
export { AgentRuntimeBindingMissingError, AgentRuntimeContractError, AgentRuntimeCapabilityUnavailableError, AgentRuntimeRegistrationError, AgentRuntimeUnavailableError, } from "./agent-runtime/errors.js";
|
|
16
|
+
export { createMinimalAgentRuntimeCapabilities, unsupportedAgentRuntimeCapability, validateAgentRuntimeCapabilities, } from "./agent-runtime/capabilities.js";
|
|
17
|
+
export { PI_AGENT_RUNTIME_DRIVER, PI_AGENT_RUNTIME_CAPABILITIES, getPiAgentRuntimeCompatibilityHandle } from "./agent-runtimes/pi/adapter.js";
|
|
18
|
+
export { inspectPiAgentRuntimeHistory, piSessionEntriesToAgentRuntimeHistoryEntries, readPiAgentRuntimeHistory, } from "./agent-runtimes/pi/history.js";
|
|
19
|
+
export { compilePiboToolForPi, piboToolResultToPi } from "./agent-runtimes/pi/tool-compiler.js";
|
|
20
|
+
export { definePiboTool, isPiboToolDefinition, normalizePiboToolDefinition, normalizePiboToolResult, } from "./tools/contract.js";
|
|
21
|
+
export { PiboToolCredentialError, PiboToolCredentialRegistry, } from "./tools/credential-registry.js";
|
|
22
|
+
export { PiboToolMcpBridge, PiboToolMcpBridgeAuthorizationError, } from "./tools/mcp-bridge.js";
|
|
23
|
+
export { createPiboToolPayloadWriter } from "./tools/payload-writer.js";
|
|
24
|
+
export { createPiboSessionToolDefinitions, isCodexBrowserToolProfile, isEnabledCodexBrowserToolProfile, isEnabledRuntimeToolProfile, isGeneratedPiboTool, isRuntimeToolProfile, } from "./tools/session-tool-set.js";
|
|
25
|
+
export { piboStringEnum } from "./tools/schema.js";
|
|
26
|
+
export { PiboPortableToolService } from "./tools/session-service.js";
|
|
9
27
|
export { definePiboPlugin, PiboPluginRegistry } from "./plugins/registry.js";
|
|
10
28
|
export { createPiboGatewayToolProfiles } from "./gateway/tool.js";
|
|
11
29
|
export { createPiboRuntime, inspectPiboProfile, runPiboTui } from "./core/runtime.js";
|
|
@@ -20,6 +38,7 @@ export { createWebHostChannel, DEFAULT_WEB_CHANNEL_HOST, DEFAULT_WEB_CHANNEL_POR
|
|
|
20
38
|
export { sendGatewayEvent, sendGatewayMessageAndWaitForReply } from "./gateway/request.js";
|
|
21
39
|
export { createSubagentToolDefinitions, createSubagentToolName, } from "./subagents/tool.js";
|
|
22
40
|
export { PiboSteeringUnavailableError } from "./core/events.js";
|
|
41
|
+
export { RuntimeSessionBindingConflictError, RuntimeSessionBindingTransitionError, assertRuntimeSessionBindingTransition, createInitialRuntimeSessionBinding, createLegacyPiRuntimeSessionBinding, nextRuntimeSessionBinding, } from "./sessions/runtime-binding.js";
|
|
23
42
|
export { InMemoryPiboSessionStore, createPiSessionId, createPiboSessionId, createPiboSession, } from "./sessions/store.js";
|
|
24
43
|
export { runPiboCli } from "./cli.js";
|
|
25
44
|
export { DEFAULT_PIBO_CONFIG_PATH, PIBO_CONFIG_KEYS, deletePiboConfigValue, getDefaultPiboConfigPath, getDisplayPiboConfigValue, getPiboConfigValue, isPiboConfigKeySecret, loadPiboConfig, redactPiboConfig, savePiboConfig, setPiboConfigValue, } from "./config/config.js";
|
package/dist/loops/tools.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Type } from "typebox";
|
|
2
|
+
import { piboStringEnum } from "../tools/schema.js";
|
|
3
|
+
import { definePiboTool } from "../tools/contract.js";
|
|
3
4
|
import { goalActiveTimeSeconds, goalCanStartNextTurn, goalElapsedWallClockSeconds, goalRemainingTokens } from './accounting.js';
|
|
4
5
|
import { createDefaultPiboLoopStore } from './store.js';
|
|
5
6
|
export const PIBO_GOAL_TOOL_NAMES = ['get_goal', 'create_goal', 'update_goal'];
|
|
@@ -101,12 +102,12 @@ async function withStore(options, action) {
|
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
104
|
function createGetGoalTool(context, options) {
|
|
104
|
-
return
|
|
105
|
+
return definePiboTool({
|
|
105
106
|
name: 'get_goal',
|
|
106
|
-
|
|
107
|
+
title: 'Get Goal',
|
|
107
108
|
description: 'Get the current goal for this Pibo Session, including soft-budget risk, per-turn reserve, active agent time, and wall-clock elapsed time.',
|
|
108
109
|
promptSnippet: 'Use get_goal when you need the authoritative persisted status or accounting for the current Pibo Session goal.',
|
|
109
|
-
|
|
110
|
+
inputSchema: Type.Object({}),
|
|
110
111
|
async execute() {
|
|
111
112
|
try {
|
|
112
113
|
const { piboSessionId } = requireSessionContext(context);
|
|
@@ -122,12 +123,12 @@ function createGetGoalTool(context, options) {
|
|
|
122
123
|
});
|
|
123
124
|
}
|
|
124
125
|
function createCreateGoalTool(context, options) {
|
|
125
|
-
return
|
|
126
|
+
return definePiboTool({
|
|
126
127
|
name: 'create_goal',
|
|
127
|
-
|
|
128
|
+
title: 'Create Goal',
|
|
128
129
|
description: 'Create an active persisted Goal Loop for this Pibo Session only when explicitly requested. Fails while this session already has an unfinished goal.',
|
|
129
130
|
promptSnippet: 'Call create_goal only when the user or system explicitly requests a persistent goal. Do not infer a goal from an ordinary task.',
|
|
130
|
-
|
|
131
|
+
inputSchema: Type.Object({
|
|
131
132
|
objective: Type.String({ description: 'Concrete objective to pursue across automatic continuations.' }),
|
|
132
133
|
token_budget: Type.Optional(Type.Number({ description: 'Optional soft token budget. Usage arrives after each model response, so the final turn can overshoot.' })),
|
|
133
134
|
token_reserve: Type.Optional(Type.Number({ description: 'Optional non-negative minimum remaining tokens required before Pibo starts another turn.' })),
|
|
@@ -160,13 +161,13 @@ function createCreateGoalTool(context, options) {
|
|
|
160
161
|
});
|
|
161
162
|
}
|
|
162
163
|
function createUpdateGoalTool(context, options) {
|
|
163
|
-
return
|
|
164
|
+
return definePiboTool({
|
|
164
165
|
name: 'update_goal',
|
|
165
|
-
|
|
166
|
+
title: 'Update Goal',
|
|
166
167
|
description: 'Mark the current goal complete or genuinely blocked. Complete requires verified achievement. Blocked requires the same impasse for at least three consecutive goal turns.',
|
|
167
168
|
promptSnippet: 'Use update_goal only with status complete after a requirement-by-requirement completion audit, or blocked after the strict repeated-blocker audit.',
|
|
168
|
-
|
|
169
|
-
status:
|
|
169
|
+
inputSchema: Type.Object({
|
|
170
|
+
status: piboStringEnum(['complete', 'blocked'], { description: 'Terminal status for the current goal.' }),
|
|
170
171
|
}),
|
|
171
172
|
async execute(_toolCallId, params) {
|
|
172
173
|
try {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { readFile, writeFile } from 'node:fs/promises';
|
|
2
|
-
import { ensureConfigExists, isHttpServer,
|
|
2
|
+
import { ensureConfigExists, isHttpServer, loadConfigUnresolved, } from './config.js';
|
|
3
3
|
import { ErrorCode, formatCliError } from './errors.js';
|
|
4
4
|
export const MCP_SERVER_DESCRIPTION_MAX_LENGTH = 480;
|
|
5
5
|
export const ENABLED_MCP_SERVERS_CONTEXT_PATH = '.pibo/context/enabled-mcp-servers.md';
|
|
@@ -23,7 +23,7 @@ export function normalizeMcpServerDescription(value) {
|
|
|
23
23
|
}
|
|
24
24
|
export async function listMcpServerInfos(configPath) {
|
|
25
25
|
try {
|
|
26
|
-
const config = await
|
|
26
|
+
const config = await loadConfigUnresolved(configPath);
|
|
27
27
|
return Object.entries(config.mcpServers).map(([name, server]) => mcpServerInfoFromConfig(name, server));
|
|
28
28
|
}
|
|
29
29
|
catch (error) {
|
|
@@ -56,8 +56,17 @@ export async function setMcpServerDescription(serverName, descriptionInput, conf
|
|
|
56
56
|
export async function getMcpAgentContextFile(selectedServerNames, configPath) {
|
|
57
57
|
if (selectedServerNames.length === 0)
|
|
58
58
|
return undefined;
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
try {
|
|
60
|
+
return getMcpAgentContextFileFromConfig(selectedServerNames, await loadConfigUnresolved(configPath));
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (error.message.includes('CONFIG_NOT_FOUND'))
|
|
64
|
+
return undefined;
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
export function getMcpAgentContextFileFromConfig(selectedServerNames, config) {
|
|
69
|
+
const infosByName = new Map(Object.entries(config.mcpServers).map(([name, server]) => [name, mcpServerInfoFromConfig(name, server)]));
|
|
61
70
|
const selected = selectedServerNames
|
|
62
71
|
.map((name) => infosByName.get(name))
|
|
63
72
|
.filter((info) => Boolean(info?.description));
|
package/dist/mcp/client.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* MCP Client - Connection management for MCP servers
|
|
3
3
|
*/
|
|
4
4
|
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
5
|
-
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
5
|
+
import { getDefaultEnvironment, StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
6
6
|
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
7
7
|
import { debug, filterTools, getConcurrencyLimit, getMaxRetries, getRetryDelayMs, getTimeoutMs, isDaemonEnabled, isHttpServer, isToolAllowed, } from './config.js';
|
|
8
8
|
import { cleanupOrphanedDaemons, getDaemonConnection, } from './daemon-client.js';
|
|
@@ -205,11 +205,15 @@ function createHttpTransport(config) {
|
|
|
205
205
|
* Uses stderr: 'pipe' to capture server output for debugging
|
|
206
206
|
*/
|
|
207
207
|
function createStdioTransport(config) {
|
|
208
|
-
//
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
208
|
+
// Runtime-generated MCP sessions inherit only the SDK's safe baseline plus
|
|
209
|
+
// explicit server env. Existing global CLI behavior remains compatible.
|
|
210
|
+
const mergedEnv = process.env.PIBO_MCP_ISOLATED_ENV === '1'
|
|
211
|
+
? getDefaultEnvironment()
|
|
212
|
+
: {};
|
|
213
|
+
if (process.env.PIBO_MCP_ISOLATED_ENV !== '1') {
|
|
214
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
215
|
+
if (value !== undefined)
|
|
216
|
+
mergedEnv[key] = value;
|
|
213
217
|
}
|
|
214
218
|
}
|
|
215
219
|
if (config.env) {
|
package/dist/mcp/config.js
CHANGED
|
@@ -401,7 +401,7 @@ function validateServerConfig(serverName, serverConfig) {
|
|
|
401
401
|
* Load and merge MCP servers configuration.
|
|
402
402
|
* More specific paths appear first and win server-name conflicts.
|
|
403
403
|
*/
|
|
404
|
-
export async function
|
|
404
|
+
export async function loadConfigUnresolved(explicitPath) {
|
|
405
405
|
const explicitOrEnvPath = explicitPath
|
|
406
406
|
? resolve(explicitPath)
|
|
407
407
|
: process.env.MCP_CONFIG_PATH
|
|
@@ -426,7 +426,10 @@ export async function loadConfig(explicitPath) {
|
|
|
426
426
|
for (const [serverName, serverConfig] of Object.entries(merged.mcpServers)) {
|
|
427
427
|
validateServerConfig(serverName, serverConfig);
|
|
428
428
|
}
|
|
429
|
-
return
|
|
429
|
+
return merged;
|
|
430
|
+
}
|
|
431
|
+
export async function loadConfig(explicitPath) {
|
|
432
|
+
return substituteEnvVarsInObject(await loadConfigUnresolved(explicitPath));
|
|
430
433
|
}
|
|
431
434
|
export async function getConfigSourceSummaries(explicitPath) {
|
|
432
435
|
const summaries = [];
|