@poncho-ai/harness 0.44.0 → 0.45.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/.turbo/turbo-build.log +5 -5
- package/CHANGELOG.md +43 -0
- package/dist/index.d.ts +45 -3
- package/dist/index.js +210 -6
- package/package.json +2 -2
- package/src/config.ts +20 -1
- package/src/harness.ts +83 -4
- package/src/index.ts +1 -1
- package/src/orchestrator/orchestrator.ts +46 -0
- package/src/orchestrator/run-conversation-turn.ts +46 -0
- package/src/orchestrator/turn.ts +3 -0
- package/src/state.ts +9 -0
- package/src/subagent-manager.ts +20 -0
- package/src/subagent-tools.ts +62 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @poncho-ai/harness@0.
|
|
2
|
+
> @poncho-ai/harness@0.45.0 build /home/runner/work/poncho-ai/poncho-ai/packages/harness
|
|
3
3
|
> node scripts/embed-docs.js && tsup src/index.ts --format esm --dts
|
|
4
4
|
|
|
5
5
|
[embed-docs] Generated poncho-docs.ts with 4 topics
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
[34mCLI[39m tsup v8.5.1
|
|
9
9
|
[34mCLI[39m Target: es2022
|
|
10
10
|
[34mESM[39m Build start
|
|
11
|
-
[32mESM[39m [1mdist/index.js [22m[32m516.00 KB[39m
|
|
12
11
|
[32mESM[39m [1mdist/isolate-VY35DGLM.js [22m[32m49.43 KB[39m
|
|
13
|
-
[32mESM[39m
|
|
12
|
+
[32mESM[39m [1mdist/index.js [22m[32m524.35 KB[39m
|
|
13
|
+
[32mESM[39m ⚡️ Build success in 230ms
|
|
14
14
|
[34mDTS[39m Build start
|
|
15
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
15
|
+
[32mDTS[39m ⚡️ Build success in 7575ms
|
|
16
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m85.07 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,48 @@
|
|
|
1
1
|
# @poncho-ai/harness
|
|
2
2
|
|
|
3
|
+
## 0.45.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`1adaae2`](https://github.com/cesr/poncho-ai/commit/1adaae2d4cc55800f01d602f2a7d6ecc65031443) Thanks [@cesr](https://github.com/cesr)! - harness: device-dispatch mode for tools that execute on a connected client
|
|
8
|
+
|
|
9
|
+
Tools can now be marked `dispatch: "device"` on `loadedConfig.tools`. When
|
|
10
|
+
the model calls such a tool the dispatcher pauses the run, emits a new
|
|
11
|
+
`tool:device:required` event, and checkpoints with the new
|
|
12
|
+
`kind: "device"` discriminator on `pendingApprovals` — same plumbing as
|
|
13
|
+
the approval flow, different trigger and different resume payload.
|
|
14
|
+
Consumers (e.g. PonchOS for iOS device tools) drive the external
|
|
15
|
+
execution and feed the result back via `continueFromToolResult`.
|
|
16
|
+
|
|
17
|
+
Approval can be combined: `{access: "approval", dispatch: "device"}`
|
|
18
|
+
yields the approval card first, then on resume falls through to the
|
|
19
|
+
device-required event. The wire vocabulary for approvals
|
|
20
|
+
(`approvalId` etc.) is unchanged; the `pendingApprovals` column /
|
|
21
|
+
field name stays.
|
|
22
|
+
|
|
23
|
+
`ToolAccess` is broadened to accept both the legacy string `"approval"`
|
|
24
|
+
and the new `{access?, dispatch?}` object form. Existing configs keep
|
|
25
|
+
working unchanged.
|
|
26
|
+
|
|
27
|
+
- [`6132601`](https://github.com/cesr/poncho-ai/commit/613260159cdd80fcc02d68aa58ad52d4465bcede) Thanks [@cesr](https://github.com/cesr)! - harness: add `read_subagent` tool for fetching subagent transcripts
|
|
28
|
+
|
|
29
|
+
Parent agents can now read a spawned subagent's conversation directly
|
|
30
|
+
instead of using `message_subagent` to ask it to repeat its work. The
|
|
31
|
+
new tool accepts a `mode` parameter — `"final"` (last assistant message,
|
|
32
|
+
default), `"assistant"` (assistant messages only), or `"full"` (every
|
|
33
|
+
message including tool calls and results) — plus optional `since_index`
|
|
34
|
+
and `max_messages` for paging long transcripts.
|
|
35
|
+
|
|
36
|
+
Access is restricted to direct children: a parent can only read
|
|
37
|
+
transcripts of subagents whose `parentConversationId` matches its own
|
|
38
|
+
conversation. The `SubagentManager` interface gains a corresponding
|
|
39
|
+
`getTranscript` method.
|
|
40
|
+
|
|
41
|
+
### Patch Changes
|
|
42
|
+
|
|
43
|
+
- Updated dependencies [[`1adaae2`](https://github.com/cesr/poncho-ai/commit/1adaae2d4cc55800f01d602f2a7d6ecc65031443)]:
|
|
44
|
+
- @poncho-ai/sdk@1.11.0
|
|
45
|
+
|
|
3
46
|
## 0.44.0
|
|
4
47
|
|
|
5
48
|
### Minor Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -167,6 +167,15 @@ interface Conversation {
|
|
|
167
167
|
input: Record<string, unknown>;
|
|
168
168
|
}>;
|
|
169
169
|
decision?: "approved" | "denied";
|
|
170
|
+
/**
|
|
171
|
+
* Checkpoint kind discriminator.
|
|
172
|
+
* - "approval" (default for legacy rows): user approve/deny gate.
|
|
173
|
+
* - "device": tool executes on a connected client device (e.g. iOS); the
|
|
174
|
+
* consumer of the harness POSTs a tool result back to resume.
|
|
175
|
+
* Treat `undefined` as "approval" for backward compatibility with rows
|
|
176
|
+
* persisted before this field existed.
|
|
177
|
+
*/
|
|
178
|
+
kind?: "approval" | "device";
|
|
170
179
|
}>;
|
|
171
180
|
runStatus?: "running" | "idle";
|
|
172
181
|
ownerId: string;
|
|
@@ -450,7 +459,20 @@ interface UploadsConfig {
|
|
|
450
459
|
region?: string;
|
|
451
460
|
endpoint?: string;
|
|
452
461
|
}
|
|
453
|
-
type ToolAccess = boolean | "approval"
|
|
462
|
+
type ToolAccess = boolean | "approval" | {
|
|
463
|
+
access?: "approval";
|
|
464
|
+
dispatch?: "device";
|
|
465
|
+
};
|
|
466
|
+
/**
|
|
467
|
+
* Normalize any ToolAccess value into a {access, dispatch} struct.
|
|
468
|
+
* `boolean` collapses to no special handling — the boolean only encodes
|
|
469
|
+
* enable/disable, not dispatch — callers gate behavior on `dispatch` and
|
|
470
|
+
* `access`.
|
|
471
|
+
*/
|
|
472
|
+
declare const normalizeToolAccess: (value: ToolAccess | undefined) => {
|
|
473
|
+
access?: "approval";
|
|
474
|
+
dispatch?: "device";
|
|
475
|
+
};
|
|
454
476
|
/** @deprecated Use flat tool keys on `tools` instead. Kept for backward compat. */
|
|
455
477
|
type BuiltInToolToggles = {
|
|
456
478
|
list_directory?: boolean;
|
|
@@ -1101,6 +1123,16 @@ interface SubagentSummary {
|
|
|
1101
1123
|
interface SubagentSpawnResult {
|
|
1102
1124
|
subagentId: string;
|
|
1103
1125
|
}
|
|
1126
|
+
type SubagentTranscriptMode = "final" | "assistant" | "full";
|
|
1127
|
+
interface SubagentTranscript {
|
|
1128
|
+
subagentId: string;
|
|
1129
|
+
task: string;
|
|
1130
|
+
status: string;
|
|
1131
|
+
totalMessages: number;
|
|
1132
|
+
startIndex: number;
|
|
1133
|
+
messages: Message[];
|
|
1134
|
+
truncated: boolean;
|
|
1135
|
+
}
|
|
1104
1136
|
interface SubagentManager {
|
|
1105
1137
|
spawn(opts: {
|
|
1106
1138
|
task: string;
|
|
@@ -1111,6 +1143,13 @@ interface SubagentManager {
|
|
|
1111
1143
|
sendMessage(subagentId: string, message: string): Promise<SubagentSpawnResult>;
|
|
1112
1144
|
stop(subagentId: string): Promise<void>;
|
|
1113
1145
|
list(parentConversationId: string): Promise<SubagentSummary[]>;
|
|
1146
|
+
getTranscript(opts: {
|
|
1147
|
+
subagentId: string;
|
|
1148
|
+
parentConversationId: string;
|
|
1149
|
+
mode: SubagentTranscriptMode;
|
|
1150
|
+
sinceIndex?: number;
|
|
1151
|
+
maxMessages?: number;
|
|
1152
|
+
}): Promise<SubagentTranscript>;
|
|
1114
1153
|
}
|
|
1115
1154
|
|
|
1116
1155
|
interface ToolCall {
|
|
@@ -1229,6 +1268,8 @@ declare class AgentHarness {
|
|
|
1229
1268
|
/** Read-only virtual mounts overlaid on the VFS. Empty by default. */
|
|
1230
1269
|
private virtualMounts;
|
|
1231
1270
|
private resolveToolAccess;
|
|
1271
|
+
/** Returns the normalized {access, dispatch} mode for the tool. */
|
|
1272
|
+
private resolveToolMode;
|
|
1232
1273
|
private isToolEnabled;
|
|
1233
1274
|
private registerIfMissing;
|
|
1234
1275
|
/**
|
|
@@ -1820,12 +1861,13 @@ declare const executeConversationTurn: ({ harness, runInput, events, initialCont
|
|
|
1820
1861
|
onEvent?: (event: AgentEvent, draft: TurnDraftState) => void | Promise<void>;
|
|
1821
1862
|
}) => Promise<ExecuteTurnResult>;
|
|
1822
1863
|
declare const normalizeApprovalCheckpoint: (approval: StoredApproval, fallbackMessages: Message[]) => StoredApproval;
|
|
1823
|
-
declare const buildApprovalCheckpoints: ({ approvals, runId, checkpointMessages, baseMessageCount, pendingToolCalls, }: {
|
|
1864
|
+
declare const buildApprovalCheckpoints: ({ approvals, runId, checkpointMessages, baseMessageCount, pendingToolCalls, kind, }: {
|
|
1824
1865
|
approvals: ApprovalEventItem[];
|
|
1825
1866
|
runId: string;
|
|
1826
1867
|
checkpointMessages: Message[];
|
|
1827
1868
|
baseMessageCount: number;
|
|
1828
1869
|
pendingToolCalls: PendingToolCall[];
|
|
1870
|
+
kind?: "approval" | "device";
|
|
1829
1871
|
}) => NonNullable<Conversation["pendingApprovals"]>;
|
|
1830
1872
|
declare const applyTurnMetadata: (conv: Conversation, meta: TurnResultMetadata, opts?: {
|
|
1831
1873
|
clearContinuation?: boolean;
|
|
@@ -2013,4 +2055,4 @@ interface RunConversationTurnResult {
|
|
|
2013
2055
|
}
|
|
2014
2056
|
declare const runConversationTurn: (opts: RunConversationTurnOpts) => Promise<RunConversationTurnResult>;
|
|
2015
2057
|
|
|
2016
|
-
export { type ActiveConversationRun, type ActiveSubagentRun, type AgentFrontmatter, AgentHarness, type AgentIdentity, type AgentLimitsConfig, type AgentModelConfig, AgentOrchestrator, type ApprovalEventItem, type ArchivedToolResult$1 as ArchivedToolResult, type BashConfig, BashEnvironmentManager, type BashExecutionLimits, type BuiltInToolToggles, CALLBACK_LOCK_STALE_MS, type CompactMessagesOptions, type CompactResult, type CompactionConfig, type ContinuationHooks, type Conversation, type ConversationCreateInit, type ConversationState, type ConversationStatusSnapshot, type ConversationStore, type ConversationSummary, type CreateSkillToolsOptions, type CronJobConfig, DEFAULT_AGENT_DESCRIPTION, DEFAULT_AGENT_NAME, DEFAULT_MAX_STEPS, DEFAULT_MODEL_NAME, DEFAULT_MODEL_PROVIDER, DEFAULT_TEMPERATURE, DEFAULT_TIMEOUT, type DefaultAgentDefinitionOptions, type EventSink, type ExecuteTurnResult, type HarnessOptions, type HarnessRunOutput, type HistorySource, InMemoryConversationStore, InMemoryEngine, InMemoryStateStore, type IsolateBinding, type IsolateConfig, LocalMcpBridge, LocalUploadStore, MAX_CONCURRENT_SUBAGENTS, MAX_CONTINUATION_COUNT, MAX_SUBAGENT_CALLBACK_COUNT, MAX_SUBAGENT_NESTING, type MainMemory, type McpConfig, type MemoryConfig, type MemoryStore, type MessagingChannelConfig, type ModelProviderFactory, type NetworkConfig, OPENAI_CODEX_CLIENT_ID, type OpenAICodexAuthConfig, type OpenAICodexDeviceAuthRequest, type OpenAICodexSession, type OrchestratorHooks, type OrchestratorOptions, type OtlpConfig, type OtlpOption, PONCHO_UPLOAD_SCHEME, type ParsedAgent, type PendingSubagentApproval, type PendingSubagentResult, type PendingToolCall, type PonchoConfig, PonchoFsAdapter, PostgresEngine, type ProviderConfig, type Recurrence, type RecurrenceType, type Reminder, type ReminderCreateInput, type ReminderStatus, type ReminderStore, type RemoteMcpServerConfig, type RunConversationTurnOpts, type RunConversationTurnResult, type RunOutcome, type RunRequest, type RuntimeRenderContext, S3UploadStore, STALE_SUBAGENT_THRESHOLD_MS, STORAGE_SCHEMA_VERSION, type SecretsStore, type SkillContextEntry, type SkillMetadata, type SkillSource, SqliteEngine, type StateConfig, type StateProviderName, type StateStore, type StorageConfig, type StorageEngine, type StorageFactoryOptions, type StorageProvider, type StoredApproval, type SubagentManager, type SubagentResult, type SubagentSpawnResult, type SubagentSummary, TOOL_RESULT_ARCHIVE_PARAM, type TelemetryConfig, TelemetryEmitter, type TenantTokenPayload, type ToolAccess, type ToolCall, ToolDispatcher, type ToolExecutionResult, type TurnDraftState, type TurnResultMetadata, type TurnSection, type UploadStore, type UploadsConfig, VFS_SCHEME, VercelBlobUploadStore, type VfsDirEntry, type VfsStat, type VirtualMount, applyTurnMetadata, buildAgentDirectoryName, buildApprovalCheckpoints, buildAssistantMetadata, buildSkillContextWindow, buildToolCompletedText, cloneSections, compactMessages, completeOpenAICodexDeviceAuth, computeNextOccurrence, createBashTool, createConversationStore, createConversationStoreFromEngine, createDefaultTools, createDeleteDirectoryTool, createDeleteTool, createEditTool, createMemoryStore, createMemoryStoreFromEngine, createMemoryTools, createModelProvider, createReminderStore, createReminderStoreFromEngine, createReminderTools, createSearchTools, createSecretsStore, createSkillTools, createStateStore, createStorageEngine, createSubagentTools, createTodoStoreFromEngine, createTurnDraftState, createUploadStore, createWriteTool, decodeFileInputData, defaultAgentDefinition, deleteOpenAICodexSession, deriveUploadKey, ensureAgentIdentity, estimateTokens, estimateTotalTokens, executeConversationTurn, findSafeSplitPoint, flushTurnDraft, generateAgentId, getAgentStoreDirectory, getModelContextWindow, getOpenAICodexAccessToken, getOpenAICodexAuthFilePath, getOpenAICodexRequiredScopes, getPonchoStoreRoot, isMessageArray, jsonSchemaToZod, loadCanonicalHistory, loadPonchoConfig, loadRunHistory, loadSkillContext, loadSkillInstructions, loadSkillMetadata, loadVfsSkillMetadata, mergeSkills, normalizeApprovalCheckpoint, normalizeOtlp, normalizeScriptPolicyPath, parseAgentFile, parseAgentMarkdown, parseSkillFrontmatter, ponchoDocsTool, readOpenAICodexSession, readSkillResource, recordStandardTurnEvent, renderAgentPrompt, resolveAgentIdentity, resolveCompactionConfig, resolveEnv, resolveMemoryConfig, resolveRunRequest, resolveSkillDirs, resolveStateConfig, runConversationTurn, slugifyStorageComponent, startOpenAICodexDeviceAuth, verifyTenantToken, withToolResultArchiveParam, writeOpenAICodexSession };
|
|
2058
|
+
export { type ActiveConversationRun, type ActiveSubagentRun, type AgentFrontmatter, AgentHarness, type AgentIdentity, type AgentLimitsConfig, type AgentModelConfig, AgentOrchestrator, type ApprovalEventItem, type ArchivedToolResult$1 as ArchivedToolResult, type BashConfig, BashEnvironmentManager, type BashExecutionLimits, type BuiltInToolToggles, CALLBACK_LOCK_STALE_MS, type CompactMessagesOptions, type CompactResult, type CompactionConfig, type ContinuationHooks, type Conversation, type ConversationCreateInit, type ConversationState, type ConversationStatusSnapshot, type ConversationStore, type ConversationSummary, type CreateSkillToolsOptions, type CronJobConfig, DEFAULT_AGENT_DESCRIPTION, DEFAULT_AGENT_NAME, DEFAULT_MAX_STEPS, DEFAULT_MODEL_NAME, DEFAULT_MODEL_PROVIDER, DEFAULT_TEMPERATURE, DEFAULT_TIMEOUT, type DefaultAgentDefinitionOptions, type EventSink, type ExecuteTurnResult, type HarnessOptions, type HarnessRunOutput, type HistorySource, InMemoryConversationStore, InMemoryEngine, InMemoryStateStore, type IsolateBinding, type IsolateConfig, LocalMcpBridge, LocalUploadStore, MAX_CONCURRENT_SUBAGENTS, MAX_CONTINUATION_COUNT, MAX_SUBAGENT_CALLBACK_COUNT, MAX_SUBAGENT_NESTING, type MainMemory, type McpConfig, type MemoryConfig, type MemoryStore, type MessagingChannelConfig, type ModelProviderFactory, type NetworkConfig, OPENAI_CODEX_CLIENT_ID, type OpenAICodexAuthConfig, type OpenAICodexDeviceAuthRequest, type OpenAICodexSession, type OrchestratorHooks, type OrchestratorOptions, type OtlpConfig, type OtlpOption, PONCHO_UPLOAD_SCHEME, type ParsedAgent, type PendingSubagentApproval, type PendingSubagentResult, type PendingToolCall, type PonchoConfig, PonchoFsAdapter, PostgresEngine, type ProviderConfig, type Recurrence, type RecurrenceType, type Reminder, type ReminderCreateInput, type ReminderStatus, type ReminderStore, type RemoteMcpServerConfig, type RunConversationTurnOpts, type RunConversationTurnResult, type RunOutcome, type RunRequest, type RuntimeRenderContext, S3UploadStore, STALE_SUBAGENT_THRESHOLD_MS, STORAGE_SCHEMA_VERSION, type SecretsStore, type SkillContextEntry, type SkillMetadata, type SkillSource, SqliteEngine, type StateConfig, type StateProviderName, type StateStore, type StorageConfig, type StorageEngine, type StorageFactoryOptions, type StorageProvider, type StoredApproval, type SubagentManager, type SubagentResult, type SubagentSpawnResult, type SubagentSummary, type SubagentTranscript, type SubagentTranscriptMode, TOOL_RESULT_ARCHIVE_PARAM, type TelemetryConfig, TelemetryEmitter, type TenantTokenPayload, type ToolAccess, type ToolCall, ToolDispatcher, type ToolExecutionResult, type TurnDraftState, type TurnResultMetadata, type TurnSection, type UploadStore, type UploadsConfig, VFS_SCHEME, VercelBlobUploadStore, type VfsDirEntry, type VfsStat, type VirtualMount, applyTurnMetadata, buildAgentDirectoryName, buildApprovalCheckpoints, buildAssistantMetadata, buildSkillContextWindow, buildToolCompletedText, cloneSections, compactMessages, completeOpenAICodexDeviceAuth, computeNextOccurrence, createBashTool, createConversationStore, createConversationStoreFromEngine, createDefaultTools, createDeleteDirectoryTool, createDeleteTool, createEditTool, createMemoryStore, createMemoryStoreFromEngine, createMemoryTools, createModelProvider, createReminderStore, createReminderStoreFromEngine, createReminderTools, createSearchTools, createSecretsStore, createSkillTools, createStateStore, createStorageEngine, createSubagentTools, createTodoStoreFromEngine, createTurnDraftState, createUploadStore, createWriteTool, decodeFileInputData, defaultAgentDefinition, deleteOpenAICodexSession, deriveUploadKey, ensureAgentIdentity, estimateTokens, estimateTotalTokens, executeConversationTurn, findSafeSplitPoint, flushTurnDraft, generateAgentId, getAgentStoreDirectory, getModelContextWindow, getOpenAICodexAccessToken, getOpenAICodexAuthFilePath, getOpenAICodexRequiredScopes, getPonchoStoreRoot, isMessageArray, jsonSchemaToZod, loadCanonicalHistory, loadPonchoConfig, loadRunHistory, loadSkillContext, loadSkillInstructions, loadSkillMetadata, loadVfsSkillMetadata, mergeSkills, normalizeApprovalCheckpoint, normalizeOtlp, normalizeScriptPolicyPath, normalizeToolAccess, parseAgentFile, parseAgentMarkdown, parseSkillFrontmatter, ponchoDocsTool, readOpenAICodexSession, readSkillResource, recordStandardTurnEvent, renderAgentPrompt, resolveAgentIdentity, resolveCompactionConfig, resolveEnv, resolveMemoryConfig, resolveRunRequest, resolveSkillDirs, resolveStateConfig, runConversationTurn, slugifyStorageComponent, startOpenAICodexDeviceAuth, verifyTenantToken, withToolResultArchiveParam, writeOpenAICodexSession };
|
package/dist/index.js
CHANGED
|
@@ -505,6 +505,13 @@ var compactMessages = async (model, messages, config, options) => {
|
|
|
505
505
|
import { access } from "fs/promises";
|
|
506
506
|
import { resolve as resolve3 } from "path";
|
|
507
507
|
import { createJiti } from "jiti";
|
|
508
|
+
var normalizeToolAccess = (value) => {
|
|
509
|
+
if (value === "approval") return { access: "approval" };
|
|
510
|
+
if (value && typeof value === "object") {
|
|
511
|
+
return { access: value.access, dispatch: value.dispatch };
|
|
512
|
+
}
|
|
513
|
+
return {};
|
|
514
|
+
};
|
|
508
515
|
var resolveTtl = (ttl, key) => {
|
|
509
516
|
if (typeof ttl === "number") {
|
|
510
517
|
return ttl;
|
|
@@ -8256,6 +8263,57 @@ var createSubagentTools = (manager) => [
|
|
|
8256
8263
|
}
|
|
8257
8264
|
return { subagents };
|
|
8258
8265
|
}
|
|
8266
|
+
}),
|
|
8267
|
+
defineTool11({
|
|
8268
|
+
name: "read_subagent",
|
|
8269
|
+
description: "Fetch the conversation transcript of a subagent you spawned. Use this to inspect a subagent's intermediate reasoning, tool calls, or full output -- instead of asking it to repeat its work via message_subagent.\n\nModes:\n- 'final' (default): just the last assistant message. Cheap.\n- 'assistant': all assistant messages, no tool calls/results.\n- 'full': every message including tool calls and results. Can be large.\n\nUse since_index / max_messages to page through long transcripts. Only works on subagents directly spawned by this conversation.",
|
|
8270
|
+
inputSchema: {
|
|
8271
|
+
type: "object",
|
|
8272
|
+
properties: {
|
|
8273
|
+
subagent_id: {
|
|
8274
|
+
type: "string",
|
|
8275
|
+
description: "The subagent ID (from spawn_subagent or list_subagents)."
|
|
8276
|
+
},
|
|
8277
|
+
mode: {
|
|
8278
|
+
type: "string",
|
|
8279
|
+
enum: ["final", "assistant", "full"],
|
|
8280
|
+
description: "How much of the transcript to return. Defaults to 'final'."
|
|
8281
|
+
},
|
|
8282
|
+
since_index: {
|
|
8283
|
+
type: "number",
|
|
8284
|
+
description: "Skip messages before this index (applied after mode filter)."
|
|
8285
|
+
},
|
|
8286
|
+
max_messages: {
|
|
8287
|
+
type: "number",
|
|
8288
|
+
description: "Cap the number of messages returned."
|
|
8289
|
+
}
|
|
8290
|
+
},
|
|
8291
|
+
required: ["subagent_id"],
|
|
8292
|
+
additionalProperties: false
|
|
8293
|
+
},
|
|
8294
|
+
handler: async (input, context) => {
|
|
8295
|
+
const subagentId = typeof input.subagent_id === "string" ? input.subagent_id : "";
|
|
8296
|
+
if (!subagentId) {
|
|
8297
|
+
return { error: "subagent_id is required" };
|
|
8298
|
+
}
|
|
8299
|
+
const parentConversationId = context.conversationId;
|
|
8300
|
+
if (!parentConversationId) {
|
|
8301
|
+
return { error: "no active conversation" };
|
|
8302
|
+
}
|
|
8303
|
+
const rawMode = typeof input.mode === "string" ? input.mode : "final";
|
|
8304
|
+
const mode = rawMode === "assistant" || rawMode === "full" ? rawMode : "final";
|
|
8305
|
+
try {
|
|
8306
|
+
return await manager.getTranscript({
|
|
8307
|
+
subagentId,
|
|
8308
|
+
parentConversationId,
|
|
8309
|
+
mode,
|
|
8310
|
+
sinceIndex: typeof input.since_index === "number" ? input.since_index : void 0,
|
|
8311
|
+
maxMessages: typeof input.max_messages === "number" ? input.max_messages : void 0
|
|
8312
|
+
});
|
|
8313
|
+
} catch (err) {
|
|
8314
|
+
return { error: err instanceof Error ? err.message : String(err) };
|
|
8315
|
+
}
|
|
8316
|
+
}
|
|
8259
8317
|
})
|
|
8260
8318
|
];
|
|
8261
8319
|
|
|
@@ -9044,11 +9102,20 @@ var AgentHarness = class _AgentHarness {
|
|
|
9044
9102
|
const envOverride = tools.byEnvironment?.[env]?.[toolName];
|
|
9045
9103
|
if (envOverride !== void 0) return envOverride;
|
|
9046
9104
|
const flatValue = tools[toolName];
|
|
9047
|
-
if (typeof flatValue === "boolean" || flatValue === "approval")
|
|
9105
|
+
if (typeof flatValue === "boolean" || flatValue === "approval" || flatValue !== null && typeof flatValue === "object" && !Array.isArray(flatValue) && // distinguish a ToolAccess object from the nested `defaults` /
|
|
9106
|
+
// `byEnvironment` sibling fields by checking it has only the
|
|
9107
|
+
// expected ToolAccess keys.
|
|
9108
|
+
Object.keys(flatValue).every((k) => k === "access" || k === "dispatch")) {
|
|
9109
|
+
return flatValue;
|
|
9110
|
+
}
|
|
9048
9111
|
const legacyValue = tools.defaults?.[toolName];
|
|
9049
9112
|
if (legacyValue !== void 0) return legacyValue;
|
|
9050
9113
|
return true;
|
|
9051
9114
|
}
|
|
9115
|
+
/** Returns the normalized {access, dispatch} mode for the tool. */
|
|
9116
|
+
resolveToolMode(toolName) {
|
|
9117
|
+
return normalizeToolAccess(this.resolveToolAccess(toolName));
|
|
9118
|
+
}
|
|
9052
9119
|
isToolEnabled(name) {
|
|
9053
9120
|
const access4 = this.resolveToolAccess(name);
|
|
9054
9121
|
if (access4 === false) return false;
|
|
@@ -9536,7 +9603,7 @@ var AgentHarness = class _AgentHarness {
|
|
|
9536
9603
|
);
|
|
9537
9604
|
}
|
|
9538
9605
|
requiresApprovalForToolCall(toolName, input) {
|
|
9539
|
-
if (this.
|
|
9606
|
+
if (this.resolveToolMode(toolName).access === "approval") {
|
|
9540
9607
|
return true;
|
|
9541
9608
|
}
|
|
9542
9609
|
if (toolName === "run_skill_script") {
|
|
@@ -10895,6 +10962,7 @@ ${textContent}` };
|
|
|
10895
10962
|
const richToolResults = [];
|
|
10896
10963
|
const approvedCalls = [];
|
|
10897
10964
|
const approvalNeeded = [];
|
|
10965
|
+
const deviceNeeded = [];
|
|
10898
10966
|
for (const call of toolCalls) {
|
|
10899
10967
|
if (isCancelled()) {
|
|
10900
10968
|
yield emitCancellation();
|
|
@@ -10909,6 +10977,13 @@ ${textContent}` };
|
|
|
10909
10977
|
name: runtimeToolName,
|
|
10910
10978
|
input: call.input
|
|
10911
10979
|
});
|
|
10980
|
+
} else if (this.resolveToolMode(runtimeToolName).dispatch === "device") {
|
|
10981
|
+
deviceNeeded.push({
|
|
10982
|
+
approvalId: `device_${randomUUID5()}`,
|
|
10983
|
+
id: call.id,
|
|
10984
|
+
name: runtimeToolName,
|
|
10985
|
+
input: call.input
|
|
10986
|
+
});
|
|
10912
10987
|
} else {
|
|
10913
10988
|
approvedCalls.push({
|
|
10914
10989
|
id: call.id,
|
|
@@ -10957,6 +11032,46 @@ ${textContent}` };
|
|
|
10957
11032
|
});
|
|
10958
11033
|
return;
|
|
10959
11034
|
}
|
|
11035
|
+
if (deviceNeeded.length > 0) {
|
|
11036
|
+
for (const dn of deviceNeeded) {
|
|
11037
|
+
yield pushEvent({
|
|
11038
|
+
type: "tool:device:required",
|
|
11039
|
+
tool: dn.name,
|
|
11040
|
+
input: dn.input,
|
|
11041
|
+
requestId: dn.approvalId
|
|
11042
|
+
});
|
|
11043
|
+
}
|
|
11044
|
+
const assistantContent2 = JSON.stringify({
|
|
11045
|
+
text: fullText,
|
|
11046
|
+
tool_calls: toolCalls.map((tc) => ({
|
|
11047
|
+
id: tc.id,
|
|
11048
|
+
name: exposedToolNames.get(tc.name) ?? tc.name,
|
|
11049
|
+
input: tc.input
|
|
11050
|
+
}))
|
|
11051
|
+
});
|
|
11052
|
+
const assistantMsg = {
|
|
11053
|
+
role: "assistant",
|
|
11054
|
+
content: assistantContent2,
|
|
11055
|
+
metadata: { timestamp: now(), id: randomUUID5(), step, runId }
|
|
11056
|
+
};
|
|
11057
|
+
const deltaMessages = [...messages.slice(inputMessageCount), assistantMsg];
|
|
11058
|
+
yield pushEvent({
|
|
11059
|
+
type: "tool:device:checkpoint",
|
|
11060
|
+
approvals: deviceNeeded.map((dn) => ({
|
|
11061
|
+
approvalId: dn.approvalId,
|
|
11062
|
+
tool: dn.name,
|
|
11063
|
+
toolCallId: dn.id,
|
|
11064
|
+
input: dn.input
|
|
11065
|
+
})),
|
|
11066
|
+
checkpointMessages: deltaMessages,
|
|
11067
|
+
pendingToolCalls: toolCalls.map((tc) => ({
|
|
11068
|
+
id: tc.id,
|
|
11069
|
+
name: exposedToolNames.get(tc.name) ?? tc.name,
|
|
11070
|
+
input: tc.input
|
|
11071
|
+
}))
|
|
11072
|
+
});
|
|
11073
|
+
return;
|
|
11074
|
+
}
|
|
10960
11075
|
const batchStart = now();
|
|
10961
11076
|
if (isCancelled()) {
|
|
10962
11077
|
yield emitCancellation();
|
|
@@ -11970,7 +12085,8 @@ var buildApprovalCheckpoints = ({
|
|
|
11970
12085
|
runId,
|
|
11971
12086
|
checkpointMessages,
|
|
11972
12087
|
baseMessageCount,
|
|
11973
|
-
pendingToolCalls
|
|
12088
|
+
pendingToolCalls,
|
|
12089
|
+
kind = "approval"
|
|
11974
12090
|
}) => approvals.map((approval) => ({
|
|
11975
12091
|
approvalId: approval.approvalId,
|
|
11976
12092
|
runId,
|
|
@@ -11979,7 +12095,8 @@ var buildApprovalCheckpoints = ({
|
|
|
11979
12095
|
input: approval.input,
|
|
11980
12096
|
checkpointMessages,
|
|
11981
12097
|
baseMessageCount,
|
|
11982
|
-
pendingToolCalls
|
|
12098
|
+
pendingToolCalls,
|
|
12099
|
+
kind
|
|
11983
12100
|
}));
|
|
11984
12101
|
var applyTurnMetadata = (conv, meta, opts = {}) => {
|
|
11985
12102
|
const {
|
|
@@ -13268,6 +13385,48 @@ ${resultBody}`,
|
|
|
13268
13385
|
}
|
|
13269
13386
|
}
|
|
13270
13387
|
return results;
|
|
13388
|
+
},
|
|
13389
|
+
getTranscript: async (opts) => {
|
|
13390
|
+
const conversation = await this.conversationStore.get(opts.subagentId);
|
|
13391
|
+
if (!conversation) {
|
|
13392
|
+
throw new Error(`Subagent "${opts.subagentId}" not found.`);
|
|
13393
|
+
}
|
|
13394
|
+
if (!conversation.parentConversationId) {
|
|
13395
|
+
throw new Error(`Conversation "${opts.subagentId}" is not a subagent.`);
|
|
13396
|
+
}
|
|
13397
|
+
if (conversation.parentConversationId !== opts.parentConversationId) {
|
|
13398
|
+
throw new Error(`Subagent "${opts.subagentId}" was not spawned by this conversation.`);
|
|
13399
|
+
}
|
|
13400
|
+
const all = conversation.messages;
|
|
13401
|
+
let filtered;
|
|
13402
|
+
if (opts.mode === "final") {
|
|
13403
|
+
let lastAssistant;
|
|
13404
|
+
for (let i = all.length - 1; i >= 0; i--) {
|
|
13405
|
+
if (all[i].role === "assistant") {
|
|
13406
|
+
lastAssistant = all[i];
|
|
13407
|
+
break;
|
|
13408
|
+
}
|
|
13409
|
+
}
|
|
13410
|
+
filtered = lastAssistant ? [lastAssistant] : [];
|
|
13411
|
+
} else if (opts.mode === "assistant") {
|
|
13412
|
+
filtered = all.filter((m) => m.role === "assistant");
|
|
13413
|
+
} else {
|
|
13414
|
+
filtered = all;
|
|
13415
|
+
}
|
|
13416
|
+
const startIndex = Math.max(0, opts.sinceIndex ?? 0);
|
|
13417
|
+
const sliced = filtered.slice(startIndex);
|
|
13418
|
+
const cap = opts.maxMessages !== void 0 && opts.maxMessages >= 0 ? opts.maxMessages : sliced.length;
|
|
13419
|
+
const messages = sliced.slice(0, cap);
|
|
13420
|
+
const truncated = startIndex + messages.length < filtered.length;
|
|
13421
|
+
return {
|
|
13422
|
+
subagentId: conversation.conversationId,
|
|
13423
|
+
task: conversation.subagentMeta?.task ?? conversation.title,
|
|
13424
|
+
status: conversation.subagentMeta?.status ?? "stopped",
|
|
13425
|
+
totalMessages: filtered.length,
|
|
13426
|
+
startIndex,
|
|
13427
|
+
messages,
|
|
13428
|
+
truncated
|
|
13429
|
+
};
|
|
13271
13430
|
}
|
|
13272
13431
|
};
|
|
13273
13432
|
}
|
|
@@ -13467,7 +13626,33 @@ var runConversationTurn = async (opts) => {
|
|
|
13467
13626
|
input: event.input ?? {},
|
|
13468
13627
|
checkpointMessages: void 0,
|
|
13469
13628
|
baseMessageCount: historyMessages.length,
|
|
13470
|
-
pendingToolCalls: []
|
|
13629
|
+
pendingToolCalls: [],
|
|
13630
|
+
kind: "approval"
|
|
13631
|
+
}
|
|
13632
|
+
];
|
|
13633
|
+
conversation.updatedAt = Date.now();
|
|
13634
|
+
await opts.conversationStore.update(conversation);
|
|
13635
|
+
}
|
|
13636
|
+
await persistDraft();
|
|
13637
|
+
}
|
|
13638
|
+
if (event.type === "tool:device:required") {
|
|
13639
|
+
const toolText = `- device dispatch \`${event.tool}\``;
|
|
13640
|
+
draft.toolTimeline.push(toolText);
|
|
13641
|
+
draft.currentTools.push(toolText);
|
|
13642
|
+
const existing = Array.isArray(conversation.pendingApprovals) ? conversation.pendingApprovals : [];
|
|
13643
|
+
if (!existing.some((a) => a.approvalId === event.requestId)) {
|
|
13644
|
+
conversation.pendingApprovals = [
|
|
13645
|
+
...existing,
|
|
13646
|
+
{
|
|
13647
|
+
approvalId: event.requestId,
|
|
13648
|
+
runId: latestRunId || conversation.runtimeRunId || "",
|
|
13649
|
+
tool: event.tool,
|
|
13650
|
+
toolCallId: void 0,
|
|
13651
|
+
input: event.input ?? {},
|
|
13652
|
+
checkpointMessages: void 0,
|
|
13653
|
+
baseMessageCount: historyMessages.length,
|
|
13654
|
+
pendingToolCalls: [],
|
|
13655
|
+
kind: "device"
|
|
13471
13656
|
}
|
|
13472
13657
|
];
|
|
13473
13658
|
conversation.updatedAt = Date.now();
|
|
@@ -13482,7 +13667,25 @@ var runConversationTurn = async (opts) => {
|
|
|
13482
13667
|
runId: latestRunId,
|
|
13483
13668
|
checkpointMessages: event.checkpointMessages,
|
|
13484
13669
|
baseMessageCount: historyMessages.length,
|
|
13485
|
-
pendingToolCalls: event.pendingToolCalls
|
|
13670
|
+
pendingToolCalls: event.pendingToolCalls,
|
|
13671
|
+
kind: "approval"
|
|
13672
|
+
});
|
|
13673
|
+
conversation._toolResultArchive = opts.harness.getToolResultArchive(
|
|
13674
|
+
opts.conversationId
|
|
13675
|
+
);
|
|
13676
|
+
conversation.updatedAt = Date.now();
|
|
13677
|
+
await opts.conversationStore.update(conversation);
|
|
13678
|
+
checkpointedRun = true;
|
|
13679
|
+
}
|
|
13680
|
+
if (event.type === "tool:device:checkpoint") {
|
|
13681
|
+
conversation.messages = buildMessages();
|
|
13682
|
+
conversation.pendingApprovals = buildApprovalCheckpoints({
|
|
13683
|
+
approvals: event.approvals,
|
|
13684
|
+
runId: latestRunId,
|
|
13685
|
+
checkpointMessages: event.checkpointMessages,
|
|
13686
|
+
baseMessageCount: historyMessages.length,
|
|
13687
|
+
pendingToolCalls: event.pendingToolCalls,
|
|
13688
|
+
kind: "device"
|
|
13486
13689
|
});
|
|
13487
13690
|
conversation._toolResultArchive = opts.harness.getToolResultArchive(
|
|
13488
13691
|
opts.conversationId
|
|
@@ -13716,6 +13919,7 @@ export {
|
|
|
13716
13919
|
normalizeApprovalCheckpoint,
|
|
13717
13920
|
normalizeOtlp,
|
|
13718
13921
|
normalizeScriptPolicyPath,
|
|
13922
|
+
normalizeToolAccess,
|
|
13719
13923
|
parseAgentFile,
|
|
13720
13924
|
parseAgentMarkdown,
|
|
13721
13925
|
parseSkillFrontmatter,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@poncho-ai/harness",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.45.0",
|
|
4
4
|
"description": "Agent execution runtime - conversation loop, tool dispatch, streaming",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"mustache": "^4.2.0",
|
|
35
35
|
"yaml": "^2.4.0",
|
|
36
36
|
"zod": "^3.22.0",
|
|
37
|
-
"@poncho-ai/sdk": "1.
|
|
37
|
+
"@poncho-ai/sdk": "1.11.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"esbuild": ">=0.17.0",
|
package/src/config.ts
CHANGED
|
@@ -37,7 +37,26 @@ export interface UploadsConfig {
|
|
|
37
37
|
endpoint?: string;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
export type ToolAccess =
|
|
40
|
+
export type ToolAccess =
|
|
41
|
+
| boolean
|
|
42
|
+
| "approval"
|
|
43
|
+
| { access?: "approval"; dispatch?: "device" };
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Normalize any ToolAccess value into a {access, dispatch} struct.
|
|
47
|
+
* `boolean` collapses to no special handling — the boolean only encodes
|
|
48
|
+
* enable/disable, not dispatch — callers gate behavior on `dispatch` and
|
|
49
|
+
* `access`.
|
|
50
|
+
*/
|
|
51
|
+
export const normalizeToolAccess = (
|
|
52
|
+
value: ToolAccess | undefined,
|
|
53
|
+
): { access?: "approval"; dispatch?: "device" } => {
|
|
54
|
+
if (value === "approval") return { access: "approval" };
|
|
55
|
+
if (value && typeof value === "object") {
|
|
56
|
+
return { access: value.access, dispatch: value.dispatch };
|
|
57
|
+
}
|
|
58
|
+
return {};
|
|
59
|
+
};
|
|
41
60
|
|
|
42
61
|
/** @deprecated Use flat tool keys on `tools` instead. Kept for backward compat. */
|
|
43
62
|
export type BuiltInToolToggles = {
|
package/src/harness.ts
CHANGED
|
@@ -38,7 +38,7 @@ import { createEditFileTool } from "./vfs/edit-file-tool.js";
|
|
|
38
38
|
import { createWriteFileTool } from "./vfs/write-file-tool.js";
|
|
39
39
|
import { PonchoFsAdapter } from "./vfs/poncho-fs-adapter.js";
|
|
40
40
|
import { parseAgentFile, parseAgentMarkdown, renderAgentPrompt, type ParsedAgent, type AgentFrontmatter } from "./agent-parser.js";
|
|
41
|
-
import { loadPonchoConfig, resolveMemoryConfig, resolveStateConfig, type PonchoConfig, type ToolAccess, type BuiltInToolToggles } from "./config.js";
|
|
41
|
+
import { loadPonchoConfig, normalizeToolAccess, resolveMemoryConfig, resolveStateConfig, type PonchoConfig, type ToolAccess, type BuiltInToolToggles } from "./config.js";
|
|
42
42
|
import { ponchoDocsTool } from "./default-tools.js";
|
|
43
43
|
import {
|
|
44
44
|
createMemoryStore,
|
|
@@ -878,7 +878,17 @@ export class AgentHarness {
|
|
|
878
878
|
if (envOverride !== undefined) return envOverride;
|
|
879
879
|
|
|
880
880
|
const flatValue = tools[toolName];
|
|
881
|
-
if (
|
|
881
|
+
if (
|
|
882
|
+
typeof flatValue === "boolean" ||
|
|
883
|
+
flatValue === "approval" ||
|
|
884
|
+
(flatValue !== null && typeof flatValue === "object" && !Array.isArray(flatValue) &&
|
|
885
|
+
// distinguish a ToolAccess object from the nested `defaults` /
|
|
886
|
+
// `byEnvironment` sibling fields by checking it has only the
|
|
887
|
+
// expected ToolAccess keys.
|
|
888
|
+
Object.keys(flatValue as object).every((k) => k === "access" || k === "dispatch"))
|
|
889
|
+
) {
|
|
890
|
+
return flatValue as ToolAccess;
|
|
891
|
+
}
|
|
882
892
|
|
|
883
893
|
const legacyValue = tools.defaults?.[toolName as keyof BuiltInToolToggles];
|
|
884
894
|
if (legacyValue !== undefined) return legacyValue;
|
|
@@ -886,6 +896,11 @@ export class AgentHarness {
|
|
|
886
896
|
return true;
|
|
887
897
|
}
|
|
888
898
|
|
|
899
|
+
/** Returns the normalized {access, dispatch} mode for the tool. */
|
|
900
|
+
private resolveToolMode(toolName: string): { access?: "approval"; dispatch?: "device" } {
|
|
901
|
+
return normalizeToolAccess(this.resolveToolAccess(toolName));
|
|
902
|
+
}
|
|
903
|
+
|
|
889
904
|
private isToolEnabled(name: string): boolean {
|
|
890
905
|
const access = this.resolveToolAccess(name);
|
|
891
906
|
if (access === false) return false;
|
|
@@ -1470,7 +1485,7 @@ export class AgentHarness {
|
|
|
1470
1485
|
toolName: string,
|
|
1471
1486
|
input: Record<string, unknown>,
|
|
1472
1487
|
): boolean {
|
|
1473
|
-
if (this.
|
|
1488
|
+
if (this.resolveToolMode(toolName).access === "approval") {
|
|
1474
1489
|
return true;
|
|
1475
1490
|
}
|
|
1476
1491
|
if (toolName === "run_skill_script") {
|
|
@@ -3119,8 +3134,19 @@ Code is wrapped in an async IIFE — use \`return\` to return a value to the too
|
|
|
3119
3134
|
name: string;
|
|
3120
3135
|
input: Record<string, unknown>;
|
|
3121
3136
|
}> = [];
|
|
3137
|
+
const deviceNeeded: Array<{
|
|
3138
|
+
approvalId: string;
|
|
3139
|
+
id: string;
|
|
3140
|
+
name: string;
|
|
3141
|
+
input: Record<string, unknown>;
|
|
3142
|
+
}> = [];
|
|
3122
3143
|
|
|
3123
|
-
// Phase 1: classify all tool calls
|
|
3144
|
+
// Phase 1: classify all tool calls.
|
|
3145
|
+
// Approval gates run first; device dispatch fires only after approval is
|
|
3146
|
+
// cleared. On a device+approval tool the first dispatch pass yields the
|
|
3147
|
+
// approval, and the post-resume pass (where access is no longer required
|
|
3148
|
+
// because the message stream has the approve decision baked in) sees
|
|
3149
|
+
// dispatch="device" still set and falls into deviceNeeded below.
|
|
3124
3150
|
for (const call of toolCalls) {
|
|
3125
3151
|
if (isCancelled()) {
|
|
3126
3152
|
yield emitCancellation();
|
|
@@ -3135,6 +3161,13 @@ Code is wrapped in an async IIFE — use \`return\` to return a value to the too
|
|
|
3135
3161
|
name: runtimeToolName,
|
|
3136
3162
|
input: call.input,
|
|
3137
3163
|
});
|
|
3164
|
+
} else if (this.resolveToolMode(runtimeToolName).dispatch === "device") {
|
|
3165
|
+
deviceNeeded.push({
|
|
3166
|
+
approvalId: `device_${randomUUID()}`,
|
|
3167
|
+
id: call.id,
|
|
3168
|
+
name: runtimeToolName,
|
|
3169
|
+
input: call.input,
|
|
3170
|
+
});
|
|
3138
3171
|
} else {
|
|
3139
3172
|
approvedCalls.push({
|
|
3140
3173
|
id: call.id,
|
|
@@ -3187,6 +3220,52 @@ Code is wrapped in an async IIFE — use \`return\` to return a value to the too
|
|
|
3187
3220
|
return;
|
|
3188
3221
|
}
|
|
3189
3222
|
|
|
3223
|
+
// Phase 2a': if any tools must dispatch to a connected device, emit
|
|
3224
|
+
// tool:device:required events for each and checkpoint with kind="device".
|
|
3225
|
+
// Consumers (e.g. PonchOS) route the events to the right WS and POST
|
|
3226
|
+
// the resulting tool output back through resumeRunFromCheckpoint.
|
|
3227
|
+
if (deviceNeeded.length > 0) {
|
|
3228
|
+
for (const dn of deviceNeeded) {
|
|
3229
|
+
yield pushEvent({
|
|
3230
|
+
type: "tool:device:required",
|
|
3231
|
+
tool: dn.name,
|
|
3232
|
+
input: dn.input,
|
|
3233
|
+
requestId: dn.approvalId,
|
|
3234
|
+
});
|
|
3235
|
+
}
|
|
3236
|
+
|
|
3237
|
+
const assistantContent = JSON.stringify({
|
|
3238
|
+
text: fullText,
|
|
3239
|
+
tool_calls: toolCalls.map(tc => ({
|
|
3240
|
+
id: tc.id,
|
|
3241
|
+
name: exposedToolNames.get(tc.name) ?? tc.name,
|
|
3242
|
+
input: tc.input,
|
|
3243
|
+
})),
|
|
3244
|
+
});
|
|
3245
|
+
const assistantMsg: Message = {
|
|
3246
|
+
role: "assistant",
|
|
3247
|
+
content: assistantContent,
|
|
3248
|
+
metadata: { timestamp: now(), id: randomUUID(), step, runId },
|
|
3249
|
+
};
|
|
3250
|
+
const deltaMessages = [...messages.slice(inputMessageCount), assistantMsg];
|
|
3251
|
+
yield pushEvent({
|
|
3252
|
+
type: "tool:device:checkpoint",
|
|
3253
|
+
approvals: deviceNeeded.map(dn => ({
|
|
3254
|
+
approvalId: dn.approvalId,
|
|
3255
|
+
tool: dn.name,
|
|
3256
|
+
toolCallId: dn.id,
|
|
3257
|
+
input: dn.input,
|
|
3258
|
+
})),
|
|
3259
|
+
checkpointMessages: deltaMessages,
|
|
3260
|
+
pendingToolCalls: toolCalls.map(tc => ({
|
|
3261
|
+
id: tc.id,
|
|
3262
|
+
name: exposedToolNames.get(tc.name) ?? tc.name,
|
|
3263
|
+
input: tc.input,
|
|
3264
|
+
})),
|
|
3265
|
+
});
|
|
3266
|
+
return;
|
|
3267
|
+
}
|
|
3268
|
+
|
|
3190
3269
|
// Phase 2b: no approvals needed — execute all auto-approved calls
|
|
3191
3270
|
const batchStart = now();
|
|
3192
3271
|
if (isCancelled()) {
|
package/src/index.ts
CHANGED
|
@@ -21,7 +21,7 @@ export * from "./telemetry.js";
|
|
|
21
21
|
export * from "./secrets-store.js";
|
|
22
22
|
export * from "./storage/index.js";
|
|
23
23
|
export * from "./storage/store-adapters.js";
|
|
24
|
-
export { PonchoFsAdapter } from "./vfs/poncho-fs-adapter.js";
|
|
24
|
+
export { PonchoFsAdapter, type VirtualMount } from "./vfs/poncho-fs-adapter.js";
|
|
25
25
|
export { BashEnvironmentManager } from "./vfs/bash-manager.js";
|
|
26
26
|
export { createBashTool } from "./vfs/bash-tool.js";
|
|
27
27
|
export * from "./tenant-token.js";
|
|
@@ -1511,6 +1511,52 @@ export class AgentOrchestrator {
|
|
|
1511
1511
|
}
|
|
1512
1512
|
return results;
|
|
1513
1513
|
},
|
|
1514
|
+
|
|
1515
|
+
getTranscript: async (opts) => {
|
|
1516
|
+
const conversation = await this.conversationStore.get(opts.subagentId);
|
|
1517
|
+
if (!conversation) {
|
|
1518
|
+
throw new Error(`Subagent "${opts.subagentId}" not found.`);
|
|
1519
|
+
}
|
|
1520
|
+
if (!conversation.parentConversationId) {
|
|
1521
|
+
throw new Error(`Conversation "${opts.subagentId}" is not a subagent.`);
|
|
1522
|
+
}
|
|
1523
|
+
if (conversation.parentConversationId !== opts.parentConversationId) {
|
|
1524
|
+
throw new Error(`Subagent "${opts.subagentId}" was not spawned by this conversation.`);
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
const all = conversation.messages;
|
|
1528
|
+
let filtered: Message[];
|
|
1529
|
+
if (opts.mode === "final") {
|
|
1530
|
+
let lastAssistant: Message | undefined;
|
|
1531
|
+
for (let i = all.length - 1; i >= 0; i--) {
|
|
1532
|
+
if (all[i]!.role === "assistant") {
|
|
1533
|
+
lastAssistant = all[i];
|
|
1534
|
+
break;
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
filtered = lastAssistant ? [lastAssistant] : [];
|
|
1538
|
+
} else if (opts.mode === "assistant") {
|
|
1539
|
+
filtered = all.filter((m) => m.role === "assistant");
|
|
1540
|
+
} else {
|
|
1541
|
+
filtered = all;
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
const startIndex = Math.max(0, opts.sinceIndex ?? 0);
|
|
1545
|
+
const sliced = filtered.slice(startIndex);
|
|
1546
|
+
const cap = opts.maxMessages !== undefined && opts.maxMessages >= 0 ? opts.maxMessages : sliced.length;
|
|
1547
|
+
const messages = sliced.slice(0, cap);
|
|
1548
|
+
const truncated = startIndex + messages.length < filtered.length;
|
|
1549
|
+
|
|
1550
|
+
return {
|
|
1551
|
+
subagentId: conversation.conversationId,
|
|
1552
|
+
task: conversation.subagentMeta?.task ?? conversation.title,
|
|
1553
|
+
status: conversation.subagentMeta?.status ?? "stopped",
|
|
1554
|
+
totalMessages: filtered.length,
|
|
1555
|
+
startIndex,
|
|
1556
|
+
messages,
|
|
1557
|
+
truncated,
|
|
1558
|
+
};
|
|
1559
|
+
},
|
|
1514
1560
|
};
|
|
1515
1561
|
}
|
|
1516
1562
|
|
|
@@ -257,6 +257,34 @@ export const runConversationTurn = async (
|
|
|
257
257
|
checkpointMessages: undefined,
|
|
258
258
|
baseMessageCount: historyMessages.length,
|
|
259
259
|
pendingToolCalls: [],
|
|
260
|
+
kind: "approval",
|
|
261
|
+
},
|
|
262
|
+
];
|
|
263
|
+
conversation.updatedAt = Date.now();
|
|
264
|
+
await opts.conversationStore.update(conversation);
|
|
265
|
+
}
|
|
266
|
+
await persistDraft();
|
|
267
|
+
}
|
|
268
|
+
if (event.type === "tool:device:required") {
|
|
269
|
+
const toolText = `- device dispatch \`${event.tool}\``;
|
|
270
|
+
draft.toolTimeline.push(toolText);
|
|
271
|
+
draft.currentTools.push(toolText);
|
|
272
|
+
const existing = Array.isArray(conversation.pendingApprovals)
|
|
273
|
+
? conversation.pendingApprovals
|
|
274
|
+
: [];
|
|
275
|
+
if (!existing.some((a) => a.approvalId === event.requestId)) {
|
|
276
|
+
conversation.pendingApprovals = [
|
|
277
|
+
...existing,
|
|
278
|
+
{
|
|
279
|
+
approvalId: event.requestId,
|
|
280
|
+
runId: latestRunId || conversation.runtimeRunId || "",
|
|
281
|
+
tool: event.tool,
|
|
282
|
+
toolCallId: undefined,
|
|
283
|
+
input: (event.input ?? {}) as Record<string, unknown>,
|
|
284
|
+
checkpointMessages: undefined,
|
|
285
|
+
baseMessageCount: historyMessages.length,
|
|
286
|
+
pendingToolCalls: [],
|
|
287
|
+
kind: "device",
|
|
260
288
|
},
|
|
261
289
|
];
|
|
262
290
|
conversation.updatedAt = Date.now();
|
|
@@ -272,6 +300,24 @@ export const runConversationTurn = async (
|
|
|
272
300
|
checkpointMessages: event.checkpointMessages,
|
|
273
301
|
baseMessageCount: historyMessages.length,
|
|
274
302
|
pendingToolCalls: event.pendingToolCalls,
|
|
303
|
+
kind: "approval",
|
|
304
|
+
});
|
|
305
|
+
conversation._toolResultArchive = opts.harness.getToolResultArchive(
|
|
306
|
+
opts.conversationId,
|
|
307
|
+
);
|
|
308
|
+
conversation.updatedAt = Date.now();
|
|
309
|
+
await opts.conversationStore.update(conversation);
|
|
310
|
+
checkpointedRun = true;
|
|
311
|
+
}
|
|
312
|
+
if (event.type === "tool:device:checkpoint") {
|
|
313
|
+
conversation.messages = buildMessages();
|
|
314
|
+
conversation.pendingApprovals = buildApprovalCheckpoints({
|
|
315
|
+
approvals: event.approvals,
|
|
316
|
+
runId: latestRunId,
|
|
317
|
+
checkpointMessages: event.checkpointMessages,
|
|
318
|
+
baseMessageCount: historyMessages.length,
|
|
319
|
+
pendingToolCalls: event.pendingToolCalls,
|
|
320
|
+
kind: "device",
|
|
275
321
|
});
|
|
276
322
|
conversation._toolResultArchive = opts.harness.getToolResultArchive(
|
|
277
323
|
opts.conversationId,
|
package/src/orchestrator/turn.ts
CHANGED
|
@@ -304,12 +304,14 @@ export const buildApprovalCheckpoints = ({
|
|
|
304
304
|
checkpointMessages,
|
|
305
305
|
baseMessageCount,
|
|
306
306
|
pendingToolCalls,
|
|
307
|
+
kind = "approval",
|
|
307
308
|
}: {
|
|
308
309
|
approvals: ApprovalEventItem[];
|
|
309
310
|
runId: string;
|
|
310
311
|
checkpointMessages: Message[];
|
|
311
312
|
baseMessageCount: number;
|
|
312
313
|
pendingToolCalls: PendingToolCall[];
|
|
314
|
+
kind?: "approval" | "device";
|
|
313
315
|
}): NonNullable<Conversation["pendingApprovals"]> =>
|
|
314
316
|
approvals.map((approval) => ({
|
|
315
317
|
approvalId: approval.approvalId,
|
|
@@ -320,6 +322,7 @@ export const buildApprovalCheckpoints = ({
|
|
|
320
322
|
checkpointMessages,
|
|
321
323
|
baseMessageCount,
|
|
322
324
|
pendingToolCalls,
|
|
325
|
+
kind,
|
|
323
326
|
}));
|
|
324
327
|
|
|
325
328
|
// ── Turn metadata persistence ──
|
package/src/state.ts
CHANGED
|
@@ -47,6 +47,15 @@ export interface Conversation {
|
|
|
47
47
|
baseMessageCount?: number;
|
|
48
48
|
pendingToolCalls?: Array<{ id: string; name: string; input: Record<string, unknown> }>;
|
|
49
49
|
decision?: "approved" | "denied";
|
|
50
|
+
/**
|
|
51
|
+
* Checkpoint kind discriminator.
|
|
52
|
+
* - "approval" (default for legacy rows): user approve/deny gate.
|
|
53
|
+
* - "device": tool executes on a connected client device (e.g. iOS); the
|
|
54
|
+
* consumer of the harness POSTs a tool result back to resume.
|
|
55
|
+
* Treat `undefined` as "approval" for backward compatibility with rows
|
|
56
|
+
* persisted before this field existed.
|
|
57
|
+
*/
|
|
58
|
+
kind?: "approval" | "device";
|
|
50
59
|
}>;
|
|
51
60
|
runStatus?: "running" | "idle";
|
|
52
61
|
ownerId: string;
|
package/src/subagent-manager.ts
CHANGED
|
@@ -19,6 +19,18 @@ export interface SubagentSpawnResult {
|
|
|
19
19
|
subagentId: string;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
export type SubagentTranscriptMode = "final" | "assistant" | "full";
|
|
23
|
+
|
|
24
|
+
export interface SubagentTranscript {
|
|
25
|
+
subagentId: string;
|
|
26
|
+
task: string;
|
|
27
|
+
status: string;
|
|
28
|
+
totalMessages: number;
|
|
29
|
+
startIndex: number;
|
|
30
|
+
messages: Message[];
|
|
31
|
+
truncated: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
22
34
|
export interface SubagentManager {
|
|
23
35
|
spawn(opts: {
|
|
24
36
|
task: string;
|
|
@@ -32,4 +44,12 @@ export interface SubagentManager {
|
|
|
32
44
|
stop(subagentId: string): Promise<void>;
|
|
33
45
|
|
|
34
46
|
list(parentConversationId: string): Promise<SubagentSummary[]>;
|
|
47
|
+
|
|
48
|
+
getTranscript(opts: {
|
|
49
|
+
subagentId: string;
|
|
50
|
+
parentConversationId: string;
|
|
51
|
+
mode: SubagentTranscriptMode;
|
|
52
|
+
sinceIndex?: number;
|
|
53
|
+
maxMessages?: number;
|
|
54
|
+
}): Promise<SubagentTranscript>;
|
|
35
55
|
}
|
package/src/subagent-tools.ts
CHANGED
|
@@ -131,4 +131,66 @@ export const createSubagentTools = (
|
|
|
131
131
|
return { subagents };
|
|
132
132
|
},
|
|
133
133
|
}),
|
|
134
|
+
|
|
135
|
+
defineTool({
|
|
136
|
+
name: "read_subagent",
|
|
137
|
+
description:
|
|
138
|
+
"Fetch the conversation transcript of a subagent you spawned. Use this to inspect a " +
|
|
139
|
+
"subagent's intermediate reasoning, tool calls, or full output -- instead of asking it " +
|
|
140
|
+
"to repeat its work via message_subagent.\n\n" +
|
|
141
|
+
"Modes:\n" +
|
|
142
|
+
"- 'final' (default): just the last assistant message. Cheap.\n" +
|
|
143
|
+
"- 'assistant': all assistant messages, no tool calls/results.\n" +
|
|
144
|
+
"- 'full': every message including tool calls and results. Can be large.\n\n" +
|
|
145
|
+
"Use since_index / max_messages to page through long transcripts. Only works on " +
|
|
146
|
+
"subagents directly spawned by this conversation.",
|
|
147
|
+
inputSchema: {
|
|
148
|
+
type: "object",
|
|
149
|
+
properties: {
|
|
150
|
+
subagent_id: {
|
|
151
|
+
type: "string",
|
|
152
|
+
description: "The subagent ID (from spawn_subagent or list_subagents).",
|
|
153
|
+
},
|
|
154
|
+
mode: {
|
|
155
|
+
type: "string",
|
|
156
|
+
enum: ["final", "assistant", "full"],
|
|
157
|
+
description: "How much of the transcript to return. Defaults to 'final'.",
|
|
158
|
+
},
|
|
159
|
+
since_index: {
|
|
160
|
+
type: "number",
|
|
161
|
+
description: "Skip messages before this index (applied after mode filter).",
|
|
162
|
+
},
|
|
163
|
+
max_messages: {
|
|
164
|
+
type: "number",
|
|
165
|
+
description: "Cap the number of messages returned.",
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
required: ["subagent_id"],
|
|
169
|
+
additionalProperties: false,
|
|
170
|
+
},
|
|
171
|
+
handler: async (input: Record<string, unknown>, context: ToolContext) => {
|
|
172
|
+
const subagentId = typeof input.subagent_id === "string" ? input.subagent_id : "";
|
|
173
|
+
if (!subagentId) {
|
|
174
|
+
return { error: "subagent_id is required" };
|
|
175
|
+
}
|
|
176
|
+
const parentConversationId = context.conversationId;
|
|
177
|
+
if (!parentConversationId) {
|
|
178
|
+
return { error: "no active conversation" };
|
|
179
|
+
}
|
|
180
|
+
const rawMode = typeof input.mode === "string" ? input.mode : "final";
|
|
181
|
+
const mode: "final" | "assistant" | "full" =
|
|
182
|
+
rawMode === "assistant" || rawMode === "full" ? rawMode : "final";
|
|
183
|
+
try {
|
|
184
|
+
return await manager.getTranscript({
|
|
185
|
+
subagentId,
|
|
186
|
+
parentConversationId,
|
|
187
|
+
mode,
|
|
188
|
+
sinceIndex: typeof input.since_index === "number" ? input.since_index : undefined,
|
|
189
|
+
maxMessages: typeof input.max_messages === "number" ? input.max_messages : undefined,
|
|
190
|
+
});
|
|
191
|
+
} catch (err) {
|
|
192
|
+
return { error: err instanceof Error ? err.message : String(err) };
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
}),
|
|
134
196
|
];
|