@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/core/runtime.js
CHANGED
|
@@ -1,561 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { createDefaultPiboProfile } from "../plugins/builtin.js";
|
|
7
|
-
import { createSubagentToolDefinitions, createSubagentToolName, } from "../subagents/tool.js";
|
|
8
|
-
import { createRunToolDefinitions } from "../runs/tools.js";
|
|
9
|
-
import { getInstalledCliToolContextFile } from "../tools/registry.js";
|
|
10
|
-
import { createCodexCompatToolDefinitions } from "../tools/codex-compat.js";
|
|
11
|
-
import { createCodexCompatExtension } from "./codex-compat.js";
|
|
12
|
-
import { createWebSearchProviderExtension, isWebSearchProviderTool } from "../tools/web-search.js";
|
|
13
|
-
import { getMcpAgentContextFile } from "../mcp/agent-context.js";
|
|
14
|
-
import { createPiboSystemPromptTemplateExtension } from "./system-prompt-template.js";
|
|
15
|
-
import { getActivePiboBasePromptPath } from "./base-prompt.js";
|
|
16
|
-
import { createPiboCompactionPromptExtension } from "./compaction-prompt.js";
|
|
17
|
-
import { cancelPiboAssistantContextGuardRecovery, createPiboAssistantContextGuardExtension, createPiboAssistantContextGuardRecovery, isPiboAssistantContextGuardRecoveryPending, registerPiboAssistantContextGuardRecovery, } from "./context-guard.js";
|
|
18
|
-
import { getPiPackageRuntimeOptions } from "../pi-packages/runtime.js";
|
|
19
|
-
import { getDefaultPiboWorkspace } from "./workspace.js";
|
|
20
|
-
import { createPiboGoalToolDefinitions, PIBO_GOAL_TOOL_NAMES } from "../loops/tools.js";
|
|
21
|
-
import { DEFAULT_USER_TIMEZONE } from "./user-settings.js";
|
|
22
|
-
import { registerMiniMaxProvider } from "../providers/minimax.js";
|
|
23
|
-
import { registerGlmProvider } from "../providers/glm.js";
|
|
24
|
-
import { registerOpenAiGpt56Models } from "../providers/openai-gpt56.js";
|
|
25
|
-
import { registerQwenTokenPlanProvider } from "../providers/qwen-token-plan.js";
|
|
26
|
-
import { PIBO_APP_CONTEXT } from "../app-context.js";
|
|
27
|
-
import { createRuntimeToolDefinition } from "../tools/runtime/tool.js";
|
|
28
|
-
import { RuntimeSessionRegistry } from "../tools/runtime/registry.js";
|
|
29
|
-
import { CODEX_BROWSER_TOOL_NAMES, CodexBrowserSessionController, createCodexBrowserToolDefinitions, } from "../tools/codex-browser.js";
|
|
30
|
-
import { compactValidationToolResultForContext } from "./test-output-compaction.js";
|
|
31
|
-
import { installPiboTranscriptIntegrity } from "./transcript-integrity.js";
|
|
32
|
-
function hasOwnRetrySetting(settings, key) {
|
|
33
|
-
return settings !== undefined && settings !== null && Object.prototype.hasOwnProperty.call(settings, key);
|
|
34
|
-
}
|
|
35
|
-
export function applyPiboRuntimeRetryDefaults(settingsManager, defaults) {
|
|
36
|
-
if (!defaults)
|
|
37
|
-
return;
|
|
38
|
-
const globalRetry = settingsManager.getGlobalSettings().retry;
|
|
39
|
-
const projectRetry = settingsManager.getProjectSettings().retry;
|
|
40
|
-
const overrides = {};
|
|
41
|
-
if (!hasOwnRetrySetting(globalRetry, "enabled") && !hasOwnRetrySetting(projectRetry, "enabled") && defaults.enabled !== undefined) {
|
|
42
|
-
overrides.enabled = defaults.enabled;
|
|
43
|
-
}
|
|
44
|
-
if (!hasOwnRetrySetting(globalRetry, "maxRetries") && !hasOwnRetrySetting(projectRetry, "maxRetries") && defaults.maxRetries !== undefined) {
|
|
45
|
-
overrides.maxRetries = defaults.maxRetries;
|
|
46
|
-
}
|
|
47
|
-
if (!hasOwnRetrySetting(globalRetry, "baseDelayMs") && !hasOwnRetrySetting(projectRetry, "baseDelayMs") && defaults.baseDelayMs !== undefined) {
|
|
48
|
-
overrides.baseDelayMs = defaults.baseDelayMs;
|
|
49
|
-
}
|
|
50
|
-
if (Object.keys(overrides).length > 0)
|
|
51
|
-
settingsManager.applyOverrides({ retry: overrides });
|
|
52
|
-
}
|
|
53
|
-
function resolveProfilePath(cwd, path) {
|
|
54
|
-
return isAbsolute(path) ? path : resolve(cwd, path);
|
|
55
|
-
}
|
|
56
|
-
async function loadContextFiles(cwd, contextFiles) {
|
|
57
|
-
const loaded = [];
|
|
58
|
-
for (const contextFile of contextFiles) {
|
|
59
|
-
if (contextFile.enabled === false)
|
|
60
|
-
continue;
|
|
61
|
-
const path = resolveProfilePath(cwd, contextFile.path);
|
|
62
|
-
const content = await readFile(path, "utf-8");
|
|
63
|
-
loaded.push({ path, content });
|
|
64
|
-
}
|
|
65
|
-
return loaded;
|
|
66
|
-
}
|
|
67
|
-
function createSessionContextFile(context) {
|
|
68
|
-
const piboSessionId = context?.piboSessionId?.trim() || "unknown";
|
|
69
|
-
const piboRoomId = context?.piboRoomId?.trim() || "unknown";
|
|
70
|
-
const timezone = context?.timezone?.trim() || DEFAULT_USER_TIMEZONE;
|
|
71
|
-
return {
|
|
72
|
-
path: "pibo://runtime/session-context.md",
|
|
73
|
-
content: [
|
|
74
|
-
"# Pibo Runtime Context",
|
|
75
|
-
"",
|
|
76
|
-
`- App context: ${PIBO_APP_CONTEXT.id}`,
|
|
77
|
-
`- Pibo Session ID: ${piboSessionId}`,
|
|
78
|
-
`- Pibo Room ID: ${piboRoomId}`,
|
|
79
|
-
`- User timezone: ${timezone}`,
|
|
80
|
-
"",
|
|
81
|
-
"Login identity gates app access only. Use the Pibo Session ID or Room ID when scheduling jobs, correlating events, or referring to the current session or room.",
|
|
82
|
-
].join("\n"),
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
function mergeContextFiles(base, additional) {
|
|
86
|
-
const seen = new Set();
|
|
87
|
-
const merged = [];
|
|
88
|
-
for (const contextFile of [...base, ...additional]) {
|
|
89
|
-
if (seen.has(contextFile.path))
|
|
90
|
-
continue;
|
|
91
|
-
seen.add(contextFile.path);
|
|
92
|
-
merged.push(contextFile);
|
|
93
|
-
}
|
|
94
|
-
return merged;
|
|
95
|
-
}
|
|
96
|
-
function collectResourceDiagnostics(resourceDiagnostics) {
|
|
97
|
-
return resourceDiagnostics.map((diagnostic) => ({
|
|
98
|
-
type: diagnostic.type === "collision" ? "warning" : diagnostic.type,
|
|
99
|
-
message: diagnostic.path ? `${diagnostic.path}: ${diagnostic.message}` : diagnostic.message,
|
|
100
|
-
}));
|
|
101
|
-
}
|
|
102
|
-
function getEnabledSkillPaths(cwd, profile) {
|
|
103
|
-
return profile.skills
|
|
104
|
-
.filter((skill) => skill.enabled !== false)
|
|
105
|
-
.map((skill) => resolveProfilePath(cwd, skill.path));
|
|
106
|
-
}
|
|
107
|
-
function getEnabledToolDefinitions(profile, options, subagentRunner, runToolController, runtimeToolController, codexBrowserController) {
|
|
108
|
-
const runtimeProfileTool = profile.tools.find(isEnabledRuntimeTool);
|
|
109
|
-
const runtimeTool = runtimeProfileTool && runtimeToolController
|
|
110
|
-
? createRuntimeToolDefinition(runtimeToolController)
|
|
111
|
-
: undefined;
|
|
112
|
-
const selectedCodexBrowserToolNames = profile.tools
|
|
113
|
-
.filter(isEnabledCodexBrowserTool)
|
|
114
|
-
.map((tool) => tool.name);
|
|
115
|
-
const codexBrowserTools = codexBrowserController
|
|
116
|
-
? createCodexBrowserToolDefinitions(codexBrowserController, selectedCodexBrowserToolNames)
|
|
117
|
-
: [];
|
|
118
|
-
const profileTools = profile.tools.filter((tool) => !isRuntimeTool(tool) && !isCodexBrowserTool(tool)).filter(hasEnabledToolDefinition);
|
|
119
|
-
const profileToolDefinitions = profileTools.map((tool) => getToolDefinition(tool, options.toolContext));
|
|
120
|
-
const codexCompatEnabled = profile.toolPackages.codexCompat === true;
|
|
121
|
-
const runControlEnabled = profile.toolPackages.runControl === true;
|
|
122
|
-
const goalControlEnabled = profile.toolPackages.goalControl !== false;
|
|
123
|
-
const goalTools = goalControlEnabled ? createPiboGoalToolDefinitions(options.toolContext ?? {}) : [];
|
|
124
|
-
const runControlBashTool = runControlEnabled && runToolController
|
|
125
|
-
? createBashToolDefinition(options.runtimeCwd, {
|
|
126
|
-
commandPrefix: options.shellCommandPrefix,
|
|
127
|
-
shellPath: options.shellPath,
|
|
128
|
-
})
|
|
129
|
-
: undefined;
|
|
130
|
-
const subagentTools = subagentRunner
|
|
131
|
-
? createSubagentToolDefinitions(profile.subagents, subagentRunner)
|
|
132
|
-
: [];
|
|
133
|
-
const codexCompatTools = codexCompatEnabled
|
|
134
|
-
? createCodexCompatToolDefinitions()
|
|
135
|
-
: [];
|
|
136
|
-
const yieldableTools = [
|
|
137
|
-
...(runControlBashTool ? [runControlBashTool] : []),
|
|
138
|
-
...profileTools.filter((tool) => tool.yieldable !== false).map((tool) => getToolDefinition(tool, options.toolContext)),
|
|
139
|
-
...(runtimeTool && runtimeProfileTool?.yieldable !== false ? [runtimeTool] : []),
|
|
140
|
-
...codexBrowserTools.filter((definition) => profile.tools.find((tool) => tool.name === definition.name)?.yieldable !== false),
|
|
141
|
-
...subagentTools,
|
|
142
|
-
...codexCompatTools,
|
|
143
|
-
];
|
|
144
|
-
const runTools = runControlEnabled && runToolController && yieldableTools.length > 0
|
|
145
|
-
? createRunToolDefinitions(yieldableTools, runToolController)
|
|
146
|
-
: [];
|
|
147
|
-
return [
|
|
148
|
-
...(runControlBashTool ? [runControlBashTool] : []),
|
|
149
|
-
...profileToolDefinitions,
|
|
150
|
-
...(runtimeTool ? [runtimeTool] : []),
|
|
151
|
-
...codexBrowserTools,
|
|
152
|
-
...subagentTools,
|
|
153
|
-
...codexCompatTools,
|
|
154
|
-
...goalTools,
|
|
155
|
-
...runTools,
|
|
156
|
-
];
|
|
157
|
-
}
|
|
158
|
-
function hasEnabledToolDefinition(tool) {
|
|
159
|
-
return tool.enabled !== false && (tool.definition !== undefined || tool.createDefinition !== undefined);
|
|
160
|
-
}
|
|
161
|
-
function getToolDefinition(tool, context = {}) {
|
|
162
|
-
if (tool.definition)
|
|
163
|
-
return tool.definition;
|
|
164
|
-
return tool.createDefinition(context);
|
|
165
|
-
}
|
|
166
|
-
function isRuntimeTool(tool) {
|
|
167
|
-
return tool.builtInPiboTool === "runtime" || tool.name === "runtime";
|
|
168
|
-
}
|
|
169
|
-
function isEnabledRuntimeTool(tool) {
|
|
170
|
-
return tool.enabled !== false && isRuntimeTool(tool);
|
|
171
|
-
}
|
|
172
|
-
function isCodexBrowserTool(tool) {
|
|
173
|
-
return tool.builtInPiboTool === "codex_browser" || CODEX_BROWSER_TOOL_NAMES.includes(tool.name);
|
|
174
|
-
}
|
|
175
|
-
function isEnabledCodexBrowserTool(tool) {
|
|
176
|
-
return tool.enabled !== false && isCodexBrowserTool(tool);
|
|
177
|
-
}
|
|
178
|
-
function isGeneratedPiboTool(name) {
|
|
179
|
-
return name === "runtime" || name.startsWith("pibo_subagent_") || name.startsWith("pibo_run_") || PIBO_GOAL_TOOL_NAMES.includes(name);
|
|
180
|
-
}
|
|
181
|
-
function getBuiltinToolAllowlist(profile, customTools) {
|
|
182
|
-
if (profile.builtinTools === "disabled")
|
|
183
|
-
return undefined;
|
|
184
|
-
const defaultBuiltinTools = new Set(DEFAULT_BUILTIN_TOOL_NAMES);
|
|
185
|
-
const selectedBuiltinTools = profile.builtinToolNames.filter((name) => defaultBuiltinTools.has(name));
|
|
186
|
-
if (selectedBuiltinTools.length === DEFAULT_BUILTIN_TOOL_NAMES.length)
|
|
187
|
-
return undefined;
|
|
188
|
-
return [...selectedBuiltinTools, ...customTools.map((tool) => tool.name)];
|
|
189
|
-
}
|
|
190
|
-
function getProfileExtensionFactories(profile, extensionFactories, contextGuardRecovery, getSettingsManager) {
|
|
191
|
-
const piboPromptTemplateExtension = createPiboSystemPromptTemplateExtension();
|
|
192
|
-
const piboCompactionPromptExtension = createPiboCompactionPromptExtension({ getSettingsManager });
|
|
193
|
-
const piboContextGuardExtension = createPiboAssistantContextGuardExtension({}, contextGuardRecovery);
|
|
194
|
-
const providerToolExtensions = profile.tools
|
|
195
|
-
.filter((tool) => tool.enabled !== false)
|
|
196
|
-
.filter(isWebSearchProviderTool)
|
|
197
|
-
.map((tool) => createWebSearchProviderExtension(tool.providerTool));
|
|
198
|
-
if (profile.toolPackages.codexCompat !== true) {
|
|
199
|
-
return [
|
|
200
|
-
piboPromptTemplateExtension,
|
|
201
|
-
piboCompactionPromptExtension,
|
|
202
|
-
piboContextGuardExtension,
|
|
203
|
-
...providerToolExtensions,
|
|
204
|
-
...(extensionFactories ?? []),
|
|
205
|
-
];
|
|
206
|
-
}
|
|
207
|
-
return [
|
|
208
|
-
piboPromptTemplateExtension,
|
|
209
|
-
piboCompactionPromptExtension,
|
|
210
|
-
piboContextGuardExtension,
|
|
211
|
-
createCodexCompatExtension({
|
|
212
|
-
isChildSession: profile.parentSessionId !== undefined,
|
|
213
|
-
}),
|
|
214
|
-
...providerToolExtensions,
|
|
215
|
-
...(extensionFactories ?? []),
|
|
216
|
-
];
|
|
217
|
-
}
|
|
218
|
-
function createInspectionSubagentRunner() {
|
|
219
|
-
return {
|
|
220
|
-
async runSubagent() {
|
|
221
|
-
throw new Error("Profile inspection cannot execute subagents");
|
|
222
|
-
},
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
function createInspectionRunToolController() {
|
|
226
|
-
const fail = () => {
|
|
227
|
-
throw new Error("Profile inspection cannot execute run-control tools");
|
|
228
|
-
};
|
|
229
|
-
return {
|
|
230
|
-
startToolRun: fail,
|
|
231
|
-
listRuns: () => [],
|
|
232
|
-
getRunStatus: fail,
|
|
233
|
-
waitForRun: fail,
|
|
234
|
-
readRun: fail,
|
|
235
|
-
cancelRun: fail,
|
|
236
|
-
ackRun: fail,
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
async function createSessionManager(cwd, profile, persistSession) {
|
|
240
|
-
if (persistSession && profile.sessionId) {
|
|
241
|
-
const existing = (await SessionManager.list(cwd)).find((session) => session.id === profile.sessionId);
|
|
242
|
-
if (existing)
|
|
243
|
-
return SessionManager.open(existing.path, undefined, cwd);
|
|
244
|
-
}
|
|
245
|
-
const sessionManager = persistSession ? SessionManager.create(cwd) : SessionManager.inMemory(cwd);
|
|
246
|
-
if (profile.sessionId) {
|
|
247
|
-
sessionManager.newSession({ id: profile.sessionId, parentSession: profile.parentSessionId });
|
|
248
|
-
}
|
|
249
|
-
return sessionManager;
|
|
250
|
-
}
|
|
251
|
-
export async function createPiboRuntime(options = {}) {
|
|
252
|
-
const cwd = options.cwd ?? getDefaultPiboWorkspace();
|
|
253
|
-
const profile = options.profile ?? createDefaultPiboProfile();
|
|
254
|
-
const agentDir = getAgentDir();
|
|
255
|
-
const sessionManager = await createSessionManager(cwd, profile, options.persistSession !== false);
|
|
256
|
-
const authStorage = AuthStorage.create();
|
|
257
|
-
const createRuntime = async ({ cwd: runtimeCwd, agentDir: runtimeAgentDir, sessionManager: runtimeSessionManager, sessionStartEvent, }) => {
|
|
258
|
-
const contextGuardRecovery = createPiboAssistantContextGuardRecovery();
|
|
259
|
-
const contextFiles = await loadContextFiles(runtimeCwd, profile.contextFiles);
|
|
260
|
-
const sessionContextFile = createSessionContextFile({ piboSessionId: profile.sessionId, ...options.sessionContext });
|
|
261
|
-
const installedToolContextFile = getInstalledCliToolContextFile();
|
|
262
|
-
const mcpAgentContextFile = await getMcpAgentContextFile(profile.mcpServers);
|
|
263
|
-
const skillPaths = getEnabledSkillPaths(runtimeCwd, profile);
|
|
264
|
-
const piPackageOptions = getPiPackageRuntimeOptions(runtimeCwd, profile);
|
|
265
|
-
let runtimeSettingsManager;
|
|
266
|
-
const services = await createAgentSessionServices({
|
|
267
|
-
cwd: runtimeCwd,
|
|
268
|
-
agentDir: runtimeAgentDir,
|
|
269
|
-
authStorage,
|
|
270
|
-
resourceLoaderOptions: {
|
|
271
|
-
...piPackageOptions.resourceLoaderOptions,
|
|
272
|
-
additionalSkillPaths: skillPaths,
|
|
273
|
-
extensionFactories: getProfileExtensionFactories(profile, options.extensionFactories, contextGuardRecovery, () => runtimeSettingsManager),
|
|
274
|
-
noExtensions: true,
|
|
275
|
-
noSkills: true,
|
|
276
|
-
noPromptTemplates: true,
|
|
277
|
-
noThemes: true,
|
|
278
|
-
noContextFiles: profile.autoContextFiles === false,
|
|
279
|
-
systemPrompt: getActivePiboBasePromptPath(runtimeCwd),
|
|
280
|
-
agentsFilesOverride: (base) => ({
|
|
281
|
-
agentsFiles: mergeContextFiles(base.agentsFiles, [
|
|
282
|
-
sessionContextFile,
|
|
283
|
-
...contextFiles,
|
|
284
|
-
...(installedToolContextFile ? [installedToolContextFile] : []),
|
|
285
|
-
...(mcpAgentContextFile ? [mcpAgentContextFile] : []),
|
|
286
|
-
]),
|
|
287
|
-
}),
|
|
288
|
-
},
|
|
289
|
-
});
|
|
290
|
-
runtimeSettingsManager = services.settingsManager;
|
|
291
|
-
applyPiboRuntimeRetryDefaults(services.settingsManager, options.retryDefaults);
|
|
292
|
-
registerOpenAiGpt56Models(services.modelRegistry);
|
|
293
|
-
registerMiniMaxProvider(services.modelRegistry);
|
|
294
|
-
registerGlmProvider(services.modelRegistry);
|
|
295
|
-
registerQwenTokenPlanProvider(services.modelRegistry);
|
|
296
|
-
const ownsLocalRuntimeRegistry = options.runtimeToolController === undefined && profile.tools.some(isEnabledRuntimeTool);
|
|
297
|
-
const localRuntimeRegistry = ownsLocalRuntimeRegistry ? new RuntimeSessionRegistry({ cwd: runtimeCwd }) : undefined;
|
|
298
|
-
const runtimeToolController = options.runtimeToolController
|
|
299
|
-
?? localRuntimeRegistry?.createController(profile.sessionId ?? "local");
|
|
300
|
-
const codexBrowserController = profile.tools.some(isEnabledCodexBrowserTool)
|
|
301
|
-
? new CodexBrowserSessionController({
|
|
302
|
-
cwd: runtimeCwd,
|
|
303
|
-
piboSessionId: options.sessionContext?.piboSessionId ?? profile.sessionId ?? runtimeSessionManager.getSessionId(),
|
|
304
|
-
})
|
|
305
|
-
: undefined;
|
|
306
|
-
const customTools = getEnabledToolDefinitions(profile, {
|
|
307
|
-
runtimeCwd,
|
|
308
|
-
shellCommandPrefix: services.settingsManager.getShellCommandPrefix(),
|
|
309
|
-
shellPath: services.settingsManager.getShellPath(),
|
|
310
|
-
toolContext: {
|
|
311
|
-
piboSessionId: options.sessionContext?.piboSessionId ?? profile.sessionId,
|
|
312
|
-
piboRoomId: options.sessionContext?.piboRoomId,
|
|
313
|
-
profileName: profile.profileName,
|
|
314
|
-
getActiveMessage: options.sessionContext?.getActiveMessage,
|
|
315
|
-
},
|
|
316
|
-
}, options.subagentRunner, options.runToolController, runtimeToolController, codexBrowserController);
|
|
317
|
-
const modelDefaults = options.modelDefaults ?? loadPiboModelDefaults(runtimeCwd);
|
|
318
|
-
const created = await createAgentSessionFromServices({
|
|
319
|
-
services,
|
|
320
|
-
sessionManager: runtimeSessionManager,
|
|
321
|
-
sessionStartEvent,
|
|
322
|
-
model: resolveProfileModel(profile, services, runtimeCwd, modelDefaults, options.activeModel),
|
|
323
|
-
thinkingLevel: options.thinkingLevel ?? selectRequestedThinkingLevel(profile, modelDefaults),
|
|
324
|
-
customTools,
|
|
325
|
-
noTools: profile.builtinTools === "disabled" ? "builtin" : undefined,
|
|
326
|
-
tools: getBuiltinToolAllowlist(profile, customTools),
|
|
327
|
-
});
|
|
328
|
-
installPiboTranscriptIntegrity(created.session);
|
|
329
|
-
installValidationOutputCompaction(created.session.agent);
|
|
330
|
-
registerPiboAssistantContextGuardRecovery(created.session, contextGuardRecovery);
|
|
331
|
-
if (options.contextGuardTuiQueueOrdering === true) {
|
|
332
|
-
installPiboContextGuardTuiQueueOrdering(created.session);
|
|
333
|
-
}
|
|
334
|
-
const resourceLoader = services.resourceLoader;
|
|
335
|
-
const diagnostics = [
|
|
336
|
-
...piPackageOptions.diagnostics,
|
|
337
|
-
...services.diagnostics,
|
|
338
|
-
...collectResourceDiagnostics(resourceLoader.getSkills().diagnostics),
|
|
339
|
-
...resourceLoader.getExtensions().errors.map(({ path, error }) => ({
|
|
340
|
-
type: "error",
|
|
341
|
-
message: `Failed to load extension "${path}": ${error}`,
|
|
342
|
-
})),
|
|
343
|
-
];
|
|
344
|
-
const originalDispose = created.session.dispose.bind(created.session);
|
|
345
|
-
created.session.dispose = () => {
|
|
346
|
-
cancelPiboAssistantContextGuardRecovery(created.session, new Error("Context guard recovery cancelled because the Pi session was disposed"));
|
|
347
|
-
if (localRuntimeRegistry) {
|
|
348
|
-
void localRuntimeRegistry.closeControllerSessions(profile.sessionId ?? "local", { force: true });
|
|
349
|
-
}
|
|
350
|
-
void codexBrowserController?.dispose();
|
|
351
|
-
originalDispose();
|
|
352
|
-
};
|
|
353
|
-
return {
|
|
354
|
-
...created,
|
|
355
|
-
services,
|
|
356
|
-
diagnostics,
|
|
357
|
-
};
|
|
358
|
-
};
|
|
359
|
-
return createAgentSessionRuntime(createRuntime, {
|
|
360
|
-
cwd,
|
|
361
|
-
agentDir,
|
|
362
|
-
sessionManager,
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
function installValidationOutputCompaction(agent) {
|
|
366
|
-
const target = agent;
|
|
367
|
-
if (!target)
|
|
368
|
-
return;
|
|
369
|
-
const previous = target.afterToolCall;
|
|
370
|
-
target.afterToolCall = async (context, signal) => {
|
|
371
|
-
const prior = await previous?.(context, signal);
|
|
372
|
-
const mergedContext = mergePriorAfterToolCallResult(context, prior);
|
|
373
|
-
return compactValidationToolResultForContext(mergedContext) ?? prior;
|
|
374
|
-
};
|
|
375
|
-
}
|
|
376
|
-
function mergePriorAfterToolCallResult(context, prior) {
|
|
377
|
-
if (!prior || typeof prior !== "object" || Array.isArray(prior))
|
|
378
|
-
return context;
|
|
379
|
-
const replacement = prior;
|
|
380
|
-
return {
|
|
381
|
-
...context,
|
|
382
|
-
isError: typeof replacement.isError === "boolean" ? replacement.isError : context.isError,
|
|
383
|
-
result: {
|
|
384
|
-
...context.result,
|
|
385
|
-
content: Array.isArray(replacement.content) ? replacement.content : context.result.content,
|
|
386
|
-
details: replacement.details !== undefined ? replacement.details : context.result.details,
|
|
387
|
-
terminate: typeof replacement.terminate === "boolean" ? replacement.terminate : context.result.terminate,
|
|
388
|
-
},
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
function resolveProfileModel(profile, services, cwd, modelDefaults, activeModel) {
|
|
392
|
-
const requestedModel = activeModel ? { ...activeModel } : selectRequestedModelProfile(profile, modelDefaults ?? loadPiboModelDefaults(cwd));
|
|
393
|
-
if (!requestedModel)
|
|
394
|
-
return undefined;
|
|
395
|
-
const model = services.modelRegistry.find(requestedModel.provider, requestedModel.id);
|
|
396
|
-
if (!model) {
|
|
397
|
-
throw new Error(`Profile "${profile.profileName}" requests unknown model ${requestedModel.provider}/${requestedModel.id}.`);
|
|
398
|
-
}
|
|
399
|
-
if (!services.modelRegistry.hasConfiguredAuth(model)) {
|
|
400
|
-
throw new Error(`Profile "${profile.profileName}" requires configured auth for ${requestedModel.provider}/${requestedModel.id}.`);
|
|
401
|
-
}
|
|
402
|
-
return model;
|
|
403
|
-
}
|
|
404
|
-
export async function inspectPiboProfile(options = {}) {
|
|
405
|
-
const cwd = options.cwd ?? process.cwd();
|
|
406
|
-
const profile = options.profile ?? createDefaultPiboProfile();
|
|
407
|
-
const runtimeProfile = new InitialSessionContext({
|
|
408
|
-
profileName: profile.profileName,
|
|
409
|
-
sessionId: profile.sessionId,
|
|
410
|
-
parentSessionId: profile.parentSessionId,
|
|
411
|
-
skills: profile.skills,
|
|
412
|
-
tools: profile.tools,
|
|
413
|
-
subagents: profile.subagents,
|
|
414
|
-
mcpServers: profile.mcpServers,
|
|
415
|
-
piPackages: profile.piPackages,
|
|
416
|
-
contextFiles: profile.contextFiles,
|
|
417
|
-
builtinTools: profile.builtinTools,
|
|
418
|
-
builtinToolNames: profile.builtinToolNames,
|
|
419
|
-
autoContextFiles: profile.autoContextFiles,
|
|
420
|
-
toolPackages: profile.toolPackages,
|
|
421
|
-
});
|
|
422
|
-
const hasEnabledSubagents = profile.subagents.some((subagent) => subagent.enabled !== false);
|
|
423
|
-
const hasYieldableTools = profile.toolPackages.runControl === true ||
|
|
424
|
-
hasEnabledSubagents ||
|
|
425
|
-
profile.tools.some((tool) => tool.enabled !== false && (tool.definition !== undefined || tool.createDefinition !== undefined) && tool.yieldable !== false);
|
|
426
|
-
const runtime = await createPiboRuntime({
|
|
427
|
-
cwd,
|
|
428
|
-
...options,
|
|
429
|
-
profile: runtimeProfile,
|
|
430
|
-
persistSession: false,
|
|
431
|
-
modelDefaults: {},
|
|
432
|
-
activeModel: undefined,
|
|
433
|
-
subagentRunner: options.subagentRunner ?? (hasEnabledSubagents ? createInspectionSubagentRunner() : undefined),
|
|
434
|
-
runToolController: options.runToolController ?? (hasYieldableTools ? createInspectionRunToolController() : undefined),
|
|
435
|
-
});
|
|
436
|
-
try {
|
|
437
|
-
const resourceLoader = runtime.services.resourceLoader;
|
|
438
|
-
const activeToolNames = new Set(runtime.session.getActiveToolNames());
|
|
439
|
-
const registeredToolNames = new Set(runtime.session.getAllTools().map((tool) => tool.name));
|
|
440
|
-
const profileToolNames = new Set(profile.tools.map((tool) => tool.name));
|
|
441
|
-
const generatedTools = runtime.session
|
|
442
|
-
.getAllTools()
|
|
443
|
-
.filter((tool) => isGeneratedPiboTool(tool.name) && !profileToolNames.has(tool.name))
|
|
444
|
-
.map((tool) => ({
|
|
445
|
-
name: tool.name,
|
|
446
|
-
hasDefinition: true,
|
|
447
|
-
registered: true,
|
|
448
|
-
active: activeToolNames.has(tool.name),
|
|
449
|
-
}));
|
|
450
|
-
return {
|
|
451
|
-
profileName: profile.profileName,
|
|
452
|
-
...(profile.model ? { model: { ...profile.model } } : {}),
|
|
453
|
-
...(profile.mainModel ? { mainModel: { ...profile.mainModel } } : {}),
|
|
454
|
-
...(profile.subagentModel ? { subagentModel: { ...profile.subagentModel } } : {}),
|
|
455
|
-
...(profile.thinkingLevel ? { thinkingLevel: profile.thinkingLevel } : {}),
|
|
456
|
-
...(profile.mainThinkingLevel ? { mainThinkingLevel: profile.mainThinkingLevel } : {}),
|
|
457
|
-
...(profile.subagentThinkingLevel ? { subagentThinkingLevel: profile.subagentThinkingLevel } : {}),
|
|
458
|
-
...(profile.fast !== undefined ? { fast: profile.fast } : {}),
|
|
459
|
-
...(profile.mainFast !== undefined ? { mainFast: profile.mainFast } : {}),
|
|
460
|
-
...(profile.subagentFast !== undefined ? { subagentFast: profile.subagentFast } : {}),
|
|
461
|
-
builtinTools: profile.builtinTools,
|
|
462
|
-
builtinToolNames: [...profile.builtinToolNames],
|
|
463
|
-
autoContextFiles: profile.autoContextFiles,
|
|
464
|
-
toolPackages: { ...profile.toolPackages },
|
|
465
|
-
skills: resourceLoader.getSkills().skills.map((skill) => ({
|
|
466
|
-
name: skill.name,
|
|
467
|
-
path: skill.filePath,
|
|
468
|
-
})),
|
|
469
|
-
tools: profile.tools.map((tool) => ({
|
|
470
|
-
name: tool.name,
|
|
471
|
-
hasDefinition: Boolean(tool.definition) || Boolean(tool.createDefinition) || isRuntimeTool(tool) || isCodexBrowserTool(tool),
|
|
472
|
-
registered: registeredToolNames.has(tool.name) || tool.providerTool !== undefined || isRuntimeTool(tool) || isCodexBrowserTool(tool),
|
|
473
|
-
active: activeToolNames.has(tool.name) || tool.providerTool !== undefined,
|
|
474
|
-
})).concat(generatedTools),
|
|
475
|
-
subagents: profile.subagents.map((subagent) => {
|
|
476
|
-
const toolName = createSubagentToolName(subagent.name);
|
|
477
|
-
return {
|
|
478
|
-
name: subagent.name,
|
|
479
|
-
targetProfile: subagent.targetProfile,
|
|
480
|
-
active: activeToolNames.has(toolName),
|
|
481
|
-
};
|
|
482
|
-
}),
|
|
483
|
-
mcpServers: [...profile.mcpServers],
|
|
484
|
-
piPackages: profile.piPackages.map((pkg) => ({
|
|
485
|
-
id: pkg.id,
|
|
486
|
-
active: pkg.enabled !== false,
|
|
487
|
-
})),
|
|
488
|
-
contextFiles: resourceLoader.getAgentsFiles().agentsFiles.map((contextFile) => ({
|
|
489
|
-
path: contextFile.path,
|
|
490
|
-
bytes: Buffer.byteLength(contextFile.content, "utf-8"),
|
|
491
|
-
})),
|
|
492
|
-
diagnostics: [...runtime.diagnostics],
|
|
493
|
-
};
|
|
494
|
-
}
|
|
495
|
-
finally {
|
|
496
|
-
await runtime.dispose();
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
function installPiboContextGuardTuiQueueOrdering(session) {
|
|
500
|
-
const originalSubscribe = session.subscribe.bind(session);
|
|
501
|
-
const originalPrompt = session.prompt.bind(session);
|
|
502
|
-
const originalSteer = session.steer.bind(session);
|
|
503
|
-
session.subscribe = ((listener) => originalSubscribe((event) => {
|
|
504
|
-
if (event.type === "compaction_end"
|
|
505
|
-
&& event.result
|
|
506
|
-
&& isPiboAssistantContextGuardRecoveryPending(session)) {
|
|
507
|
-
listener({ ...event, willRetry: true });
|
|
508
|
-
return;
|
|
509
|
-
}
|
|
510
|
-
listener(event);
|
|
511
|
-
}));
|
|
512
|
-
session.prompt = async (text, options) => {
|
|
513
|
-
if (isPiboAssistantContextGuardRecoveryPending(session)) {
|
|
514
|
-
if (!session.isStreaming) {
|
|
515
|
-
await session.followUp(text, options?.images);
|
|
516
|
-
options?.preflightResult?.(true);
|
|
517
|
-
return;
|
|
518
|
-
}
|
|
519
|
-
await originalPrompt(text, { ...options, streamingBehavior: "followUp" });
|
|
520
|
-
return;
|
|
521
|
-
}
|
|
522
|
-
await originalPrompt(text, options);
|
|
523
|
-
};
|
|
524
|
-
session.steer = async (text, images) => {
|
|
525
|
-
if (isPiboAssistantContextGuardRecoveryPending(session)) {
|
|
526
|
-
await session.followUp(text, images);
|
|
527
|
-
return;
|
|
528
|
-
}
|
|
529
|
-
await originalSteer(text, images);
|
|
530
|
-
};
|
|
531
|
-
}
|
|
532
|
-
export async function runPiboTui(options = {}) {
|
|
533
|
-
const profile = options.profile ?? createDefaultPiboProfile();
|
|
534
|
-
const hasEnabledSubagents = profile.subagents.some((subagent) => subagent.enabled !== false);
|
|
535
|
-
if (hasEnabledSubagents && (!options.subagentRunner || !options.runToolController)) {
|
|
536
|
-
console.error(`Error: Profile "${profile.profileName}" uses subagents and requires the routed pibo runtime. ` +
|
|
537
|
-
`Use "npm run tui:routed -- ${profile.profileName}" for local TUI QA.`);
|
|
538
|
-
process.exitCode = 1;
|
|
539
|
-
return;
|
|
540
|
-
}
|
|
541
|
-
const runtime = await createPiboRuntime({ ...options, profile, contextGuardTuiQueueOrdering: true });
|
|
542
|
-
try {
|
|
543
|
-
const fatal = runtime.diagnostics.find((diagnostic) => diagnostic.type === "error");
|
|
544
|
-
for (const diagnostic of runtime.diagnostics) {
|
|
545
|
-
const prefix = diagnostic.type === "warning" ? "Warning" : diagnostic.type === "error" ? "Error" : "Info";
|
|
546
|
-
console.error(`${prefix}: ${diagnostic.message}`);
|
|
547
|
-
}
|
|
548
|
-
if (fatal) {
|
|
549
|
-
process.exitCode = 1;
|
|
550
|
-
return;
|
|
551
|
-
}
|
|
552
|
-
const interactiveMode = new InteractiveMode(runtime, {
|
|
553
|
-
verbose: true,
|
|
554
|
-
modelFallbackMessage: runtime.modelFallbackMessage,
|
|
555
|
-
});
|
|
556
|
-
await interactiveMode.run();
|
|
557
|
-
}
|
|
558
|
-
finally {
|
|
559
|
-
await runtime.dispose();
|
|
560
|
-
}
|
|
561
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated Pi runtime compatibility surface. Harness-neutral orchestration must use
|
|
3
|
+
* the Agent Runtime Adapter interfaces under `agent-runtime/`.
|
|
4
|
+
*/
|
|
5
|
+
export * from "../agent-runtimes/pi/runtime.js";
|